Skip to content

Reject AudioFifo frames with a different channel layout - #2505

Merged
WyattBlue merged 3 commits into
PyAV-Org:masterfrom
ChandraChaan:fix/fifo-layout
Nov 3, 2026
Merged

WyattBlue merged 3 commits into
PyAV-Org:masterfrom
ChandraChaan:fix/fifo-layout

Conversation

@ChandraChaan

Copy link
Copy Markdown
Contributor

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:

  • writing a stereo s16 frame into a FIFO that started with mono reads only half of the frame's data and scrambles the samples, with no error;
  • writing a frame with fewer channels than the first reads past the end of the frame's buffers (for planar formats, data[1] is NULL).

The channel layout is now compared with av_channel_layout_compare, like AudioResampler.resample already 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_mismatch to tests/test_audiofifo.py.

I ran the smoke workflow on my fork:

The 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.

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.
@WyattBlue
WyattBlue merged commit b1328a3 into PyAV-Org:master Nov 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants