fix(mod_shout): update handle->pos in shout_file_read() to fix backward seek for MP3 files#2996
Open
pinc444 wants to merge 11 commits intosignalwire:masterfrom
Open
fix(mod_shout): update handle->pos in shout_file_read() to fix backward seek for MP3 files#2996pinc444 wants to merge 11 commits intosignalwire:masterfrom
pinc444 wants to merge 11 commits intosignalwire:masterfrom
Conversation
Co-authored-by: pinc444 <148037078+pinc444@users.noreply.github.com>
Add mod_soundtouch: pitch-preserving tempo control for file playback
… MP3 files Co-authored-by: pinc444 <148037078+pinc444@users.noreply.github.com>
fix(mod_shout): update handle->pos in shout_file_read() to fix backward seek for MP3 files
Add handle->pos += *len in shout_file_read() to keep the file position counter in sync after backward seeks. Without this, mpg123_seek() correctly repositions the decoder but subsequent reads never update handle->pos, causing the position to drift and breaking backward seek behavior. This matches the pattern used by other format modules (mod_sndfile, mod_opusfile, mod_native_file) which all update handle->pos in their read functions. Co-authored-by: pinc444 <148037078+pinc444@users.noreply.github.com> Agent-Logs-Url: https://github.com/pinc444/freeswitch/sessions/3063de57-1880-4d2e-b422-c6dea22f6b7f
fix(mod_shout): update handle->pos in shout_file_read() to fix backward seek for MP3 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mod_shout'sshout_file_read()never updatedhandle->pos, causingswitch_core_file_seek()to always compute0 - sampsfor backward seeks — clamping to position 0 instead of the correct relative position.Change
Added
handle->pos += *leninshout_file_read(), matching the pattern already used bymod_sndfile:This ensures
fh->posaccurately reflects playback position so that callers doingfh->pos - samps(backward seek viaSEEK_SET) compute the correct target sample.Original prompt
Bug
When using
session.streamFile()with an MP3 file (handled bymod_shout), backward seek does not work correctly. The file always seeks to position 0 instead of the expected relative backward position.WAV files work correctly because
mod_sndfileproperly trackshandle->posin itsfile_read()function.mod_shoutdoes not updatehandle->posduring reads, which breaks the seek logic inswitch_core_file_seek().Root Cause
In
src/mod/formats/mod_shout/mod_shout.c, the functionshout_file_read()incrementshandle->sample_countbut never updateshandle->pos.Meanwhile, in
src/switch_core_file.c, theswitch_core_file_seek()function usesfh->offset_posforSEEK_CURoperations:And
fh->offset_posis set from*cur_poswhich comes from the file_seek return. But the first seek (to establish current position) relies onfh->offset_posbeing correct. Sincemod_shoutnever updateshandle->pos(andoffset_posis derived from it after seeks), the position is always 0, making backward seeks always go to position 0.For comparison,
mod_sndfileinsrc/mod/formats/mod_sndfile/mod_sndfile.ccorrectly updateshandle->posin its read function:Fix Required
In
src/mod/formats/mod_shout/mod_shout.c, find theshout_file_read()function. It currently has a line:Add the following line immediately before that existing line:
So the result looks like:
This is the only change needed. It matches the pattern used by
mod_sndfileand ensures thatswitch_core_file_seek()has the correct current position when computing relative seeks (both forward and backward viaSEEK_CUR).The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: