From fecfeb62ba910c901c4bb225e333ae4d3a01be33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 28 Aug 2023 07:30:28 +0200 Subject: [PATCH] Fix zero samples in the beginning of FFmpeg m4a streams. Fixes #11878 --- src/sources/soundsourceffmpeg.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sources/soundsourceffmpeg.cpp b/src/sources/soundsourceffmpeg.cpp index 3db342f81a27..eb830e7ca40e 100644 --- a/src/sources/soundsourceffmpeg.cpp +++ b/src/sources/soundsourceffmpeg.cpp @@ -929,14 +929,13 @@ bool SoundSourceFFmpeg::adjustCurrentPosition(SINT startIndex) { // Need to seek to a new position before continue reading. For // sample accurate decoding the actual seek position must be // placed BEFORE the position where reading continues. - auto seekIndex = - math_max(static_cast(0), startIndex - m_seekPrerollFrameCount); + // At the beginning of the stream, this is a negative position. + auto seekIndex = startIndex - m_seekPrerollFrameCount; + // Seek to codec frame boundaries if the frame size is fixed and known if (m_pavStream->codecpar->frame_size > 0) { seekIndex -= seekIndex % m_pavCodecContext->frame_size; } - DEBUG_ASSERT(seekIndex >= 0); - DEBUG_ASSERT(seekIndex <= startIndex); if (m_frameBuffer.tryContinueReadingFrom(seekIndex)) { // No need to perform a costly seek operation. Just skip some buffered