[vlc-commits] [Git][videolan/vlc][master] 4 commits: flac: use defines for FLAC channel mapping
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Nov 25 15:01:03 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
5cf257a3 by Steve Lhomme at 2026-11-25T15:51:30+01:00
flac: use defines for FLAC channel mapping
It is more readable.
Checked with static_asserts on each value.
The mapping corresponds to the 8 first values in the FLAC RFC [^1].
[^1]: https://www.rfc-editor.org/rfc/rfc9639.html#name-channels-bits
- - - - -
3e918608 by Steve Lhomme at 2026-11-25T15:51:30+01:00
packetizer: flac: avoid multiplying values that fit in an unsigned
samplerate is an unsigned too.
- - - - -
77844f70 by Steve Lhomme at 2026-11-25T15:51:30+01:00
packetizer: flac: keep the channel mapping from the header
The values come from RFC9639 [^1].
Each channel was added individually and then checked against
existing defines with static_assert().
The values above 8 don't exist in the flac decoder module but
they correspond to stereo channels coded in different ways internally.
libflac probably reports them as stereo and we use the regular stereo layout.
The 7-channel layout was incorrectly set to
```
AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
| AOUT_CHAN_MIDDLERIGHT
```
Which was missing the LFE channel and rear center channels and doesn't include
the rear left/right channel.
[^1]: https://www.rfc-editor.org/rfc/rfc9639.html#section-9.1.3
- - - - -
865394f5 by Steve Lhomme at 2026-11-25T15:51:30+01:00
packetizer: flac: remove always false test
The number of channels-1 is read on 3 bits. So the value can never be above 8.
- - - - -
3 changed files:
- modules/codec/flac.c
- modules/packetizer/flac.c
- modules/packetizer/flac.h
Changes:
=====================================
modules/codec/flac.c
=====================================
@@ -80,20 +80,13 @@ static const int pi_channels_maps[FLAC__MAX_CHANNELS + 1] =
{
0,
AOUT_CHAN_CENTER,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
- AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
- | AOUT_CHAN_REARRIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT| AOUT_CHAN_MIDDLERIGHT
- | AOUT_CHAN_LFE,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
- | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
- | AOUT_CHAN_LFE
+ AOUT_CHANS_2_0,
+ AOUT_CHANS_3_0,
+ AOUT_CHANS_4_0,
+ AOUT_CHANS_5_0,
+ AOUT_CHANS_5_1,
+ AOUT_CHANS_6_1_MIDDLE,
+ AOUT_CHANS_7_1
};
/* XXX it supposes our internal format is WG4 */
=====================================
modules/packetizer/flac.c
=====================================
@@ -37,6 +37,8 @@
#include "packetizer_helper.h"
#include "flac.h"
+#include <stdbit.h>
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -84,26 +86,6 @@ typedef struct
int i_next_block_flags;
} decoder_sys_t;
-static const int pi_channels_maps[9] =
-{
- 0,
- AOUT_CHAN_CENTER,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
- AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
- | AOUT_CHAN_REARRIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
- | AOUT_CHAN_MIDDLERIGHT,
- AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
- | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
- | AOUT_CHAN_LFE
-};
-
/*****************************************************************************
* ProcessHeader: process Flac header.
@@ -325,15 +307,6 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
if (!p_sys->b_stream_info)
ProcessHeader(p_dec);
- if (p_sys->stream_info.channels > 8)
- {
- if(in)
- block_Release(in);
- msg_Err(p_dec, "This stream uses too many audio channels (%d > 8)",
- p_sys->stream_info.channels);
- return NULL;
- }
-
if ( in )
block_BytestreamPush(&p_sys->bytestream, in);
@@ -532,8 +505,8 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
case STATE_SEND_DATA:
p_dec->fmt_out.audio.i_rate = p_sys->headerinfo.i_rate;
- p_dec->fmt_out.audio.i_channels = p_sys->headerinfo.i_channels;
- p_dec->fmt_out.audio.i_physical_channels = pi_channels_maps[p_sys->stream_info.channels];
+ p_dec->fmt_out.audio.i_channels = stdc_count_ones(p_sys->headerinfo.channel_mask);
+ p_dec->fmt_out.audio.i_physical_channels = p_sys->headerinfo.channel_mask;
if( p_sys->bytestream.p_block &&
p_sys->bytestream.p_block->i_pts > date_Get( &p_sys->pts ) &&
=====================================
modules/packetizer/flac.h
=====================================
@@ -38,7 +38,7 @@ struct flac_header_info
{
vlc_tick_t i_pts;
unsigned i_rate;
- unsigned i_channels;
+ uint16_t channel_mask;
unsigned i_bits_per_sample;
unsigned i_frame_length;
};
@@ -197,25 +197,38 @@ static inline int FLAC_ParseSyncInfo(const uint8_t *p_buf, unsigned i_buf,
} else if (samplerate_hint == 15) {
return 0; /* invalid */
} else if (samplerate_hint < 12) {
- static const int16_t flac_samplerate[12] = {
- 0, 8820, 17640, 19200,
- 800, 1600, 2205, 2400,
- 3200, 4410, 4800, 9600,
+ static const unsigned flac_samplerate[12] = {
+ 0, 88200, 176400, 192000,
+ 8000, 16000, 22050, 24000,
+ 32000, 44100, 48000, 96000,
};
- samplerate = flac_samplerate[samplerate_hint] * 10;
+ samplerate = flac_samplerate[samplerate_hint];
} else {
samplerate = 0; /* at end of header */
}
/* Find channels */
unsigned channels = p_buf[3] >> 4;
- if (channels >= 8) {
- if (channels >= 11) /* reserved */
- return 0;
- channels = 2;
- } else
- channels++;
-
+ static const uint16_t flac_channel_mask[16] = { // RFC9639 9.1.3
+ AOUT_CHAN_CENTER, // mono
+ AOUT_CHANS_2_0,
+ AOUT_CHANS_3_0,
+ AOUT_CHANS_4_0,
+ AOUT_CHANS_5_0,
+ AOUT_CHANS_5_1,
+ AOUT_CHANS_6_1_MIDDLE,
+ AOUT_CHANS_7_1,
+ AOUT_CHANS_2_0, // left-side stereo
+ AOUT_CHANS_2_0, // side-right stereo
+ AOUT_CHANS_2_0, // mid-side stereo
+ 0, // Reserved
+ 0, // Reserved
+ 0, // Reserved
+ 0, // Reserved
+ 0, // Reserved
+ };
+ if (flac_channel_mask[channels] == 0)
+ return 0; // reserved
/* Find bits per sample */
static const int8_t flac_bits_per_sample[8] = {
@@ -306,7 +319,7 @@ static inline int FLAC_ParseSyncInfo(const uint8_t *p_buf, unsigned i_buf,
h->i_bits_per_sample = bits_per_sample;
h->i_rate = samplerate;
- h->i_channels = channels;
+ h->channel_mask = flac_channel_mask[channels];
h->i_frame_length = blocksize;
return b_guessing ? -1 : 1;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0741280a41b11fe4e1fdf52320be7f834eca6378...865394f5d5a8ee1a139ec07e8a08765a46c38c59
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0741280a41b11fe4e1fdf52320be7f834eca6378...865394f5d5a8ee1a139ec07e8a08765a46c38c59
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list