From 72d50fb978e2357fdf922586b91342d1030f8f8f Mon Sep 17 00:00:00 2001 From: epbk Date: Fri, 27 Oct 2023 20:50:52 +0200 Subject: [PATCH 1/2] MP1-5177: Do not rise EC_STARVATION event while in paused state --- .../MPAudioRenderer/source/MpAudioRenderer.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/DirectShowFilters/MPAudioRenderer/source/MpAudioRenderer.cpp b/DirectShowFilters/MPAudioRenderer/source/MpAudioRenderer.cpp index e16d64a0252..57ffe04dcfc 100644 --- a/DirectShowFilters/MPAudioRenderer/source/MpAudioRenderer.cpp +++ b/DirectShowFilters/MPAudioRenderer/source/MpAudioRenderer.cpp @@ -310,7 +310,19 @@ STDMETHODIMP CMPAudioRenderer::GetState(DWORD dwMSecs, FILTER_STATE* State) if (m_State == State_Paused && (m_pRenderer->BufferredDataDuration() <= (m_pSettings->GetOutputBuffer() * 10000)) && (GetCurrentTimestamp() - m_lastSampleArrivalTime < SAMPLE_RECEIVE_TIMEOUT)) { - NotifyEvent(EC_STARVATION, 0, 0); + /* + EC_STARVATION + A filter is not receiving enough data. + The event is not sent to the application. + If the filter graph is running, the filter graph manager pauses the graph and waits for the pause to complete. Then it runs the graph again. + The filter sending the event should not complete its transition to paused until it has enough data to resume. + If the filter graph is not running, the filter graph manager ignores this event. + */ + + // We should not report this event while in paused state: it sometimes causes graph to pause/resume again right after the resume is complete, + // and it leads to issues in WASAPI renderer (early sample check) + //NotifyEvent(EC_STARVATION, 0, 0); + *State = State_Paused; return VFW_S_STATE_INTERMEDIATE; From 16aea069b059dbb195820faee4ea68826617a82a Mon Sep 17 00:00:00 2001 From: epbk Date: Fri, 27 Oct 2023 20:55:46 +0200 Subject: [PATCH 2/2] MP1-5177: WASAPI rendererer: Early sample check fix. --- .../MPAudioRenderer/source/WASAPIRenderFilter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DirectShowFilters/MPAudioRenderer/source/WASAPIRenderFilter.cpp b/DirectShowFilters/MPAudioRenderer/source/WASAPIRenderFilter.cpp index f1857c1c653..b940f1698f3 100644 --- a/DirectShowFilters/MPAudioRenderer/source/WASAPIRenderFilter.cpp +++ b/DirectShowFilters/MPAudioRenderer/source/WASAPIRenderFilter.cpp @@ -465,7 +465,7 @@ HRESULT CWASAPIRenderFilter::CheckStreamTimeline(IMediaSample* pSample, REFERENC return MPAR_S_DROP_SAMPLE; } - else if ((m_nSampleNum == 0 && *pDueTime > rtHWTime) || resync) + else if ((m_nSampleNum == 0 && *pDueTime > rtHWTime) || (m_nSampleNum <= 20 && (*pDueTime - rtHWTime) > 150000) || resync) { m_nSampleNum++; @@ -580,6 +580,8 @@ void CWASAPIRenderFilter::UpdateAudioClock() Log("UpdateAudioClock: prevPos: %6.3f > ullHwClock: %6.3f diff: %6.3f QPC diff: %6.3f m_llPosError: %6.3f correction: %6.3f", m_ullPrevPos / 10000000.0, ullHwClock / 10000000.0, (m_ullPrevPos - ullHwClock) / 10000000.0, (qpc - m_ullPrevQpc) / 10000000.0, m_llPosError / 10000000.0, correction / 10000000.0); + + m_nSampleNum = 0; } m_ullPrevPos = ullHwClock; @@ -841,6 +843,7 @@ DWORD CWASAPIRenderFilter::ThreadProc() { sampleProcessed = false; writeSilence = 0; + m_nSampleNum = 0; m_state = StateRunning; if (!m_pCurrentSample) {