From 764877ae2b3548a18f459f06ce60bc286b8647f2 Mon Sep 17 00:00:00 2001 From: Torarin Date: Tue, 24 Jul 2012 16:39:46 +0200 Subject: [PATCH] Continue looping until packet buffers are empty --- OMXPlayerAudio.cpp | 11 +------- OMXPlayerAudio.h | 9 ++++++- OMXReader.cpp | 7 ++++- omxplayer.cpp | 66 ++++++++++++++++++++++++++-------------------- 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/OMXPlayerAudio.cpp b/OMXPlayerAudio.cpp index 3daf351c..79fc2770 100644 --- a/OMXPlayerAudio.cpp +++ b/OMXPlayerAudio.cpp @@ -452,7 +452,7 @@ void OMXPlayerAudio::Process() m_packets.pop_front(); } UnLock(); - + LockDecoder(); if(m_flush && omx_pkt) { @@ -679,17 +679,8 @@ void OMXPlayerAudio::WaitCompletion() if(!m_decoder) return; - struct timespec starttime, endtime; - while(true) { - clock_gettime(CLOCK_REALTIME, &endtime); - if((endtime.tv_sec - starttime.tv_sec) > 2) - { - CLog::Log(LOGERROR, "OMXPlayerAudio::WaitCompletion - wait for eos timed out\n"); - break; - } - Lock(); if(m_packets.empty()) { diff --git a/OMXPlayerAudio.h b/OMXPlayerAudio.h index 40c4dde1..9c46c485 100644 --- a/OMXPlayerAudio.h +++ b/OMXPlayerAudio.h @@ -123,7 +123,14 @@ class OMXPlayerAudio : public CThread double GetCacheTime(); double GetCurrentPTS() { return m_iCurrentPts; }; void WaitCompletion(); - unsigned int GetCached() { return m_cached_size; }; + unsigned int GetCached() + { + Lock(); + unsigned int cached_size = m_cached_size; + UnLock(); + return cached_size; + + }; void RegisterAudioCallback(IAudioCallback* pCallback); void UnRegisterAudioCallback(); void DoAudioWork(); diff --git a/OMXReader.cpp b/OMXReader.cpp index 217ef1e1..804f5fec 100644 --- a/OMXReader.cpp +++ b/OMXReader.cpp @@ -381,13 +381,16 @@ bool OMXReader::SeekTime(int64_t seek_ms, int seek_flags, double *startpts) { m_eof = true; UnLock(); - return false; + return true; } int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, seek_pts, seek_flags ? AVSEEK_FLAG_BACKWARD : 0); if(ret >= 0) + { UpdateCurrentPTS(); + m_eof = false; + } if(m_iCurrentPts == DVD_NOPTS_VALUE) { @@ -416,6 +419,8 @@ AVMediaType OMXReader::PacketType(OMXPacket *pkt) OMXPacket *OMXReader::Read() { + assert(!IsEof()); + AVPacket pkt; OMXPacket *m_omx_pkt = NULL; int result = -1; diff --git a/omxplayer.cpp b/omxplayer.cpp index 79c1b911..e463f18c 100644 --- a/omxplayer.cpp +++ b/omxplayer.cpp @@ -599,6 +599,44 @@ int main(int argc, char *argv[]) goto do_exit; } + /* player got in an error state */ + if(m_player_audio.Error()) + { + printf("audio player error. emergency exit!!!\n"); + goto do_exit; + } + + std::string strSubTitle = m_player_video.GetText(); + if(strSubTitle.length() && m_show_subtitle) + { + if(last_sub != strSubTitle) + { + last_sub = strSubTitle; + printf("Text : %s\n", strSubTitle.c_str()); + } + } + + if(m_stats) + { + printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r", + m_player_video.GetCurrentPTS() / DVD_TIME_BASE, m_player_video.GetDecoderBufferSize(), + m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE, + m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached()); + } + + if(m_omx_reader.IsEof() && !m_omx_pkt) + { + if (!m_player_audio.GetCached() && !m_player_video.GetCached()) + break; + + // Abort audio buffering, now we're on our own + if (m_buffer_empty) + m_av_clock->OMXResume(); + + OMXClock::OMXSleep(10); + continue; + } + /* when the audio buffer runs under 0.1 seconds we buffer up */ if(m_has_audio) { @@ -684,34 +722,6 @@ int main(int argc, char *argv[]) m_omx_pkt = NULL; } } - - /* player got in an error state */ - if(m_player_audio.Error()) - { - printf("audio player error. emergency exit!!!\n"); - goto do_exit; - } - - std::string strSubTitle = m_player_video.GetText(); - if(strSubTitle.length() && m_show_subtitle) - { - if(last_sub != strSubTitle) - { - last_sub = strSubTitle; - printf("Text : %s\n", strSubTitle.c_str()); - } - } - - if(m_stats) - { - printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r", - m_player_video.GetCurrentPTS() / DVD_TIME_BASE, m_player_video.GetDecoderBufferSize(), - m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE, - m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached()); - } - if(m_omx_reader.IsEof()) - break; - } do_exit: