From 401b015ee709052b5f7c4892f4cdebf9f3465313 Mon Sep 17 00:00:00 2001 From: jehutting Date: Mon, 9 May 2016 18:59:56 +0200 Subject: [PATCH] Fix looping video issues, and white flicker upon end of video See several looping short video issues (e.g. #449) and white flicker #250 --- OMXAudio.cpp | 5 +++- OMXPlayerAudio.cpp | 60 ++++++++++++++++------------------------------ OMXPlayerAudio.h | 1 - OMXPlayerVideo.cpp | 39 +++++++++++++++--------------- 4 files changed, 44 insertions(+), 61 deletions(-) diff --git a/OMXAudio.cpp b/OMXAudio.cpp index e5d63653..ac5ee0ff 100644 --- a/OMXAudio.cpp +++ b/OMXAudio.cpp @@ -1205,7 +1205,10 @@ bool COMXAudio::IsEOS() unsigned int latency = GetAudioRenderingLatency(); CSingleLock lock (m_critSection); - if (!m_failed_eos && !(m_omx_decoder.IsEOS() && latency == 0)) + bool hdmi_eos = ( !m_omx_render_hdmi.IsInitialized() || m_omx_render_hdmi.IsEOS()); + bool analog_eos = ( !m_omx_render_analog.IsInitialized() || m_omx_render_analog.IsEOS()); + + if (!m_failed_eos && !(hdmi_eos && analog_eos && latency == 0)) return false; if (m_submitted_eos) diff --git a/OMXPlayerAudio.cpp b/OMXPlayerAudio.cpp index 44ab87a4..111f9716 100644 --- a/OMXPlayerAudio.cpp +++ b/OMXPlayerAudio.cpp @@ -281,7 +281,7 @@ void OMXPlayerAudio::Process() while(true) { Lock(); - if(!(m_bStop || m_bAbort) && m_packets.empty()) + if(!(m_bStop || m_bAbort) && !omx_pkt && m_packets.empty()) pthread_cond_wait(&m_packet_cond, &m_lock); if (m_bStop || m_bAbort) @@ -290,29 +290,28 @@ void OMXPlayerAudio::Process() break; } - if(m_flush && omx_pkt) + if(m_flush) { - OMXReader::FreePacket(omx_pkt); - omx_pkt = NULL; + if(omx_pkt) + { + OMXReader::FreePacket(omx_pkt); + omx_pkt = NULL; + } m_flush = false; } - else if(!omx_pkt && !m_packets.empty()) + + if(!omx_pkt && !m_packets.empty()) { omx_pkt = m_packets.front(); - m_cached_size -= omx_pkt->size; m_packets.pop_front(); } + UnLock(); LockDecoder(); - if(m_flush && omx_pkt) - { - OMXReader::FreePacket(omx_pkt); - omx_pkt = NULL; - m_flush = false; - } - else if(omx_pkt && Decode(omx_pkt)) + if(omx_pkt && Decode(omx_pkt)) { + m_cached_size -= omx_pkt->size; OMXReader::FreePacket(omx_pkt); omx_pkt = NULL; } @@ -359,8 +358,10 @@ bool OMXPlayerAudio::AddPacket(OMXPacket *pkt) if((m_cached_size + pkt->size) < m_config.queue_size * 1024 * 1024) { Lock(); + LockDecoder(); m_cached_size += pkt->size; m_packets.push_back(pkt); + UnLockDecoder(); UnLock(); ret = true; pthread_cond_broadcast(&m_packet_cond); @@ -492,36 +493,15 @@ double OMXPlayerAudio::GetCacheTotal() void OMXPlayerAudio::SubmitEOS() { - if(m_decoder) - m_decoder->SubmitEOS(); + assert(m_decoder); + assert(m_packets.empty()); + m_decoder->SubmitEOS(); } bool OMXPlayerAudio::IsEOS() { - return m_packets.empty() && (!m_decoder || m_decoder->IsEOS()); + assert(m_decoder); + assert(m_packets.empty()); + return m_decoder->IsEOS(); } -void OMXPlayerAudio::WaitCompletion() -{ - if(!m_decoder) - return; - - unsigned int nTimeOut = m_config.fifo_size * 1000; - while(nTimeOut) - { - if(IsEOS()) - { - CLog::Log(LOGDEBUG, "%s::%s - got eos\n", "OMXPlayerAudio", __func__); - break; - } - - if(nTimeOut == 0) - { - CLog::Log(LOGERROR, "%s::%s - wait for eos timed out\n", "OMXPlayerAudio", __func__); - break; - } - OMXClock::OMXSleep(50); - nTimeOut -= 50; - } -} - diff --git a/OMXPlayerAudio.h b/OMXPlayerAudio.h index f32bfefc..0be2621a 100644 --- a/OMXPlayerAudio.h +++ b/OMXPlayerAudio.h @@ -102,7 +102,6 @@ class OMXPlayerAudio : public OMXThread double GetCurrentPTS() { return m_iCurrentPts; }; void SubmitEOS(); bool IsEOS(); - void WaitCompletion(); unsigned int GetCached() { return m_cached_size; }; unsigned int GetMaxCached() { return m_config.queue_size * 1024 * 1024; }; unsigned int GetLevel() { return m_config.queue_size ? 100.0f * m_cached_size / (m_config.queue_size * 1024.0f * 1024.0f) : 0; }; diff --git a/OMXPlayerVideo.cpp b/OMXPlayerVideo.cpp index 42ca8a62..bd1d4542 100644 --- a/OMXPlayerVideo.cpp +++ b/OMXPlayerVideo.cpp @@ -212,7 +212,7 @@ bool OMXPlayerVideo::Decode(OMXPacket *pkt) if(m_flush_requested) return true; } - CLog::Log(LOGINFO, "CDVDPlayerVideo::Decode dts:%.0f pts:%.0f cur:%.0f, size:%d", pkt->dts, pkt->pts, m_iCurrentPts, pkt->size); + CLog::Log(LOGINFO, "OMXPlayerVideo::Decode dts:%.0f pts:%.0f cur:%.0f, size:%d", pkt->dts, pkt->pts, m_iCurrentPts, pkt->size); m_decoder->Decode(pkt->data, pkt->size, dts, pts); return true; } @@ -233,29 +233,27 @@ void OMXPlayerVideo::Process() break; } - if(m_flush && omx_pkt) + if(m_flush) { - OMXReader::FreePacket(omx_pkt); - omx_pkt = NULL; + if(omx_pkt) + { + OMXReader::FreePacket(omx_pkt); + omx_pkt = NULL; + } m_flush = false; } - else if(!omx_pkt && !m_packets.empty()) + + if(!omx_pkt && !m_packets.empty()) { omx_pkt = m_packets.front(); - m_cached_size -= omx_pkt->size; m_packets.pop_front(); } - UnLock(); + UnLock(); LockDecoder(); - if(m_flush && omx_pkt) - { - OMXReader::FreePacket(omx_pkt); - omx_pkt = NULL; - m_flush = false; - } - else if(omx_pkt && Decode(omx_pkt)) + if(omx_pkt && Decode(omx_pkt)) { + m_cached_size -= omx_pkt->size; OMXReader::FreePacket(omx_pkt); omx_pkt = NULL; } @@ -300,8 +298,10 @@ bool OMXPlayerVideo::AddPacket(OMXPacket *pkt) if((m_cached_size + pkt->size) < m_config.queue_size * 1024 * 1024) { Lock(); + LockDecoder(); m_cached_size += pkt->size; m_packets.push_back(pkt); + UnLockDecoder(); UnLock(); ret = true; pthread_cond_broadcast(&m_packet_cond); @@ -367,14 +367,15 @@ int OMXPlayerVideo::GetDecoderFreeSpace() void OMXPlayerVideo::SubmitEOS() { - if(m_decoder) - m_decoder->SubmitEOS(); + assert(m_decoder); + assert(m_packets.empty()); + m_decoder->SubmitEOS(); } bool OMXPlayerVideo::IsEOS() { - if(!m_decoder) - return false; - return m_packets.empty() && (!m_decoder || m_decoder->IsEOS()); + assert(m_decoder); + assert(m_packets.empty()); + return m_decoder->IsEOS(); }