diff options
author | Rainer Hochecker <fernetmenta@online.de> | 2014-12-28 18:32:07 +0100 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2014-12-30 16:39:10 +0100 |
commit | 96872c33ae6f1385d20be845926d065a1b39913c (patch) | |
tree | d1a0d5349084a42aafc04674d11e71473058551a | |
parent | e8b707af7f4a1f2564c4d9f4cb857c7da0fa9066 (diff) |
dvdplayer: simplify calculation of playing pts for audio
-rw-r--r-- | xbmc/cores/dvdplayer/DVDAudio.cpp | 90 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDAudio.h | 18 | ||||
-rw-r--r-- | xbmc/cores/dvdplayer/DVDPlayerAudio.h | 1 |
3 files changed, 17 insertions, 92 deletions
diff --git a/xbmc/cores/dvdplayer/DVDAudio.cpp b/xbmc/cores/dvdplayer/DVDAudio.cpp index 6514030357..e1f8474915 100644 --- a/xbmc/cores/dvdplayer/DVDAudio.cpp +++ b/xbmc/cores/dvdplayer/DVDAudio.cpp @@ -31,66 +31,6 @@ using namespace std; -CPTSOutputQueue::CPTSOutputQueue() -{ - Flush(); -} - -void CPTSOutputQueue::Add(double pts, double delay, double duration, double timestamp) -{ - CSingleLock lock(m_sync); - - // don't accept a re-add, since that would cause time moving back - double last = m_queue.empty() ? m_current.pts : m_queue.back().pts; - if(last == pts) - return; - - TPTSItem item; - item.pts = pts; - item.timestamp = timestamp + delay; - item.duration = duration; - - // first one is applied directly - if(m_queue.empty() && m_current.pts == DVD_NOPTS_VALUE) - m_current = item; - else - m_queue.push(item); - - // call function to make sure the queue - // doesn't grow should nobody call it - Current(timestamp); -} -void CPTSOutputQueue::Flush() -{ - CSingleLock lock(m_sync); - - while( !m_queue.empty() ) m_queue.pop(); - m_current.pts = DVD_NOPTS_VALUE; - m_current.timestamp = 0.0; - m_current.duration = 0.0; -} - -double CPTSOutputQueue::Current(double timestamp) -{ - CSingleLock lock(m_sync); - - if(!m_queue.empty() && m_current.pts == DVD_NOPTS_VALUE) - { - m_current = m_queue.front(); - m_queue.pop(); - } - - while( !m_queue.empty() && timestamp >= m_queue.front().timestamp ) - { - m_current = m_queue.front(); - m_queue.pop(); - } - - if( m_current.timestamp == 0 ) return m_current.pts; - - return m_current.pts + min(m_current.duration, (timestamp - m_current.timestamp)); -} - CDVDAudio::CDVDAudio(volatile bool &bStop) : m_bStop(bStop) { @@ -160,13 +100,16 @@ void CDVDAudio::Destroy() m_iBitsPerSample = 0; m_bPassthrough = false; m_bPaused = true; - m_time.Flush(); + m_playingPts = DVD_NOPTS_VALUE; } unsigned int CDVDAudio::AddPackets(const DVDAudioFrame &audioframe) { CSingleLock lock (m_critSection); + m_playingPts = audioframe.pts - GetDelay(); + m_timeOfPts = CDVDClock::GetAbsoluteClock(); + if(!m_pAudioStream) return 0; @@ -198,11 +141,6 @@ unsigned int CDVDAudio::AddPackets(const DVDAudioFrame &audioframe) lock.Enter(); } while (!m_bStop); - double time_added = DVD_SEC_TO_TIME(m_SecondsPerByte * audioframe.nb_frames * audioframe.framesize); - double delay = GetDelay(); - double timestamp = CDVDClock::GetAbsoluteClock(); - m_time.Add(audioframe.pts, delay - time_added, audioframe.duration, timestamp); - return total - frames; } @@ -246,8 +184,9 @@ float CDVDAudio::GetCurrentAttenuation() void CDVDAudio::Pause() { CSingleLock lock (m_critSection); - if (m_pAudioStream) m_pAudioStream->Pause(); - m_time.Flush(); + if (m_pAudioStream) + m_pAudioStream->Pause(); + m_playingPts = DVD_NOPTS_VALUE; } void CDVDAudio::Resume() @@ -275,7 +214,7 @@ void CDVDAudio::Flush() { m_pAudioStream->Flush(); } - m_time.Flush(); + m_playingPts = DVD_NOPTS_VALUE; } bool CDVDAudio::IsValidFormat(const DVDAudioFrame &audioframe) @@ -325,14 +264,15 @@ double CDVDAudio::GetCacheTotal() void CDVDAudio::SetPlayingPts(double pts) { - CSingleLock lock (m_critSection); - m_time.Flush(); - double delay = GetDelay(); - double timestamp = CDVDClock::GetAbsoluteClock(); - m_time.Add(pts, delay, 0, timestamp); + CSingleLock lock(m_critSection); + m_playingPts = pts - GetDelay(); + m_timeOfPts = CDVDClock::GetAbsoluteClock(); } double CDVDAudio::GetPlayingPts() { - return m_time.Current(CDVDClock::GetAbsoluteClock()); + if (m_playingPts == DVD_NOPTS_VALUE) + return 0.0; + + return m_playingPts + CDVDClock::GetAbsoluteClock() - m_timeOfPts; } diff --git a/xbmc/cores/dvdplayer/DVDAudio.h b/xbmc/cores/dvdplayer/DVDAudio.h index 629fb3237e..057a40a1f4 100644 --- a/xbmc/cores/dvdplayer/DVDAudio.h +++ b/xbmc/cores/dvdplayer/DVDAudio.h @@ -36,21 +36,6 @@ extern "C" { typedef struct stDVDAudioFrame DVDAudioFrame; -class CPTSOutputQueue -{ -private: - typedef struct {double pts; double timestamp; double duration;} TPTSItem; - TPTSItem m_current; - std::queue<TPTSItem> m_queue; - CCriticalSection m_sync; - -public: - CPTSOutputQueue(); - void Add(double pts, double delay, double duration, double timestamp); - void Flush(); - double Current(double timestamp); -}; - class CSingleLock; class CDVDAudio @@ -82,7 +67,8 @@ public: IAEStream *m_pAudioStream; protected: - CPTSOutputQueue m_time; + double m_playingPts; + double m_timeOfPts; CCriticalSection m_critSection; int m_iBitrate; diff --git a/xbmc/cores/dvdplayer/DVDPlayerAudio.h b/xbmc/cores/dvdplayer/DVDPlayerAudio.h index e8b2ab6086..5db89f6683 100644 --- a/xbmc/cores/dvdplayer/DVDPlayerAudio.h +++ b/xbmc/cores/dvdplayer/DVDPlayerAudio.h @@ -134,7 +134,6 @@ public: // holds stream information for current playing stream CDVDStreamInfo m_streaminfo; - CPTSOutputQueue m_ptsOutput; CPTSInputQueue m_ptsInput; double GetCurrentPts() { CSingleLock lock(m_info_section); return m_info.pts; } |