Skip to content

Commit

Permalink
Fix zero samples in the beginning of FFmpeg m4a streams. Fixes #11878
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Aug 28, 2023
1 parent eed961a commit fecfeb6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/sources/soundsourceffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SINT>(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
Expand Down

0 comments on commit fecfeb6

Please sign in to comment.