Repository navigation
Reject AudioFifo frames with a different channel layout - #2505
Merged
Merged
Conversation
AudioFifo.write() checked that later frames had the same sample format, sample rate and time base as the first, but not the same channel layout. The FIFO is allocated with the first frame's channel count, so writing a stereo frame into a FIFO started with mono read only half of the data and scrambled the samples without an error, and a frame with fewer channels read past the end of its buffers. The channel layout is now compared too, as AudioResampler already does.
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.
AudioFifo.write()checks that every later frame has the same sample format, sample rate and time base as the first one, but not the same channel layout. The FIFO is allocated with the first frame's channel count, so:s16frame into a FIFO that started with mono reads only half of the frame's data and scrambles the samples, with no error;data[1]is NULL).The channel layout is now compared with
av_channel_layout_compare, likeAudioResampler.resamplealready rejects frames whose layout differs from its template. The template keeps the first frame's layout via_copy_internal_attributes, so the comparison is against what the FIFO was allocated for.Added
test_layout_mismatchtotests/test_audiofifo.py.I ran the smoke workflow on my fork:
master):test_layout_mismatchfails withFailed: DID NOT RAISE ValueError(1 failed, 600 passed) on the Ubuntu and Windows jobs. https://github.com/ChandraChaan/PyAV/actions/runs/41539175134make lintpasses: https://github.com/ChandraChaan/PyAV/actions/runs/41539186508The macOS jobs were cancelled on my fork twice (with and without the fix) before running, and the RISC-V job never got a runner, so I have no macOS or RISC-V result.