Skip to content

Fix the Opus parser failing on mono Ogg streams - #1021

Open
kwy404 wants to merge 1 commit into
google:mainfrom
kwy404:fix-opus-parser-mono
Open

kwy404 wants to merge 1 commit into
google:mainfrom
kwy404:fix-opus-parser-mono

Conversation

@kwy404

@kwy404 kwy404 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

bumble-player, and anything else that reads Ogg Opus files with a2dp.OpusParser, cannot use a mono file: parsing stops with ValueError: first packet is not OpusHead, so the mono branch in the player's opus_codec_capabilities is never reached.

Root cause

When OpusParser.packets reads the OpusHead packet, it stores the channel mode in packet_count instead of channel_mode:

packet_count = (
    OpusPacket.ChannelMode.MONO
    if packet[9] == 1
    else OpusPacket.ChannelMode.STEREO
)

For a mono stream this sets packet_count back to 0 (ChannelMode.MONO), so the next packet (OpusTags) is checked again as the identification header and the parser raises. Stereo streams only work because ChannelMode.STEREO happens to be 1, and channel_mode always keeps its initial STEREO value.

Fix

Assign the value to channel_mode.

Test

test_opus_parser_mono in tests/a2dp_test.py feeds a one page Ogg stream with a 1 channel OpusHead, an OpusTags packet and one audio packet, and checks that the parser yields a single MONO packet with the audio payload. It fails before the change with the ValueError above and passes after it. The existing stereo tests still pass, and black -S --check is clean on the changed files.

When reading the OpusHead packet, OpusParser stored the channel mode in
packet_count instead of channel_mode. For a mono stream this set
packet_count back to 0 (ChannelMode.MONO), so the OpusTags packet was
then checked as the identification header and the parser raised
"first packet is not OpusHead". Stereo streams only worked because
ChannelMode.STEREO happens to be 1, and channel_mode always stayed
STEREO.

This branch has not been deployed

No deployments
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.

1 participant