From 07a90995c30ea1c0a4067afdfb7065c76ec30a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 23 Jul 2023 15:16:22 +0200 Subject: [PATCH] Apply missing Samples fix only to FFmpeg 4.4 and above --- src/sources/soundsourceffmpeg.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/sources/soundsourceffmpeg.cpp b/src/sources/soundsourceffmpeg.cpp index 3078166da6e..7375ae8aaa3 100644 --- a/src/sources/soundsourceffmpeg.cpp +++ b/src/sources/soundsourceffmpeg.cpp @@ -1159,24 +1159,27 @@ ReadableSampleFrames SoundSourceFFmpeg::readSampleFramesClamped( } const auto decodedFrameCount = m_pavDecodedFrame->nb_samples; DEBUG_ASSERT(decodedFrameCount > 0); - auto streamFrameIndex = + SINT streamFrameIndex = convertStreamTimeToFrameIndex( *m_pavStream, m_pavDecodedFrame->pts); - // Only audible samples are counted, i.e. any inaudible aka - // "priming" samples are not included in nb_samples! - // https://bugs.launchpad.net/mixxx/+bug/1934785 - if (streamFrameIndex < kMinFrameIndex) { + + if (m_avutilVersion >= AV_VERSION_INT(56, 52, 100)) { + // From ffmpeg 4.4 only audible samples are counted, i.e. any inaudible aka + // "priming" samples are not included in nb_samples! + // https://github.com/mixxxdj/mixxx/issues/10464 + if (streamFrameIndex < kMinFrameIndex) { #if VERBOSE_DEBUG_LOG - const auto inaudibleFrameCountUntilStartOfStream = - kMinFrameIndex - streamFrameIndex; - kLogger.debug() - << "Skipping" - << inaudibleFrameCountUntilStartOfStream - << "inaudible sample frames before the start of the stream"; + const auto inaudibleFrameCountUntilStartOfStream = + kMinFrameIndex - streamFrameIndex; + kLogger.debug() + << "Skipping" + << inaudibleFrameCountUntilStartOfStream + << "inaudible sample frames before the start of the stream"; #endif - streamFrameIndex = kMinFrameIndex; + streamFrameIndex = kMinFrameIndex; + } } - DEBUG_ASSERT(streamFrameIndex >= kMinFrameIndex); + decodedFrameRange = IndexRange::forward( streamFrameIndex, decodedFrameCount);