[vlc-devel] [RFC] audio: let VLC decode more than 9 audio channels

Emeric Grange egrange at gopro.com
Tue Oct 6 17:53:17 CEST 2015


VLC has an hardcoded limit (AOUT_CHAN_MAX=9) determining how many audio channels
can be decoded and processed.
Increasing this limit work well for some use cases, eg: using libvlc to decode PCM
files with 16 channels, getting the result through vlc_player_audiocallback()
and outputting it with third party libraries, but a lot of audio filters should
be impacted as well.
These channels doesn't have to correspond to "real" output speakers, so the code
related to new speakers from the WAVE_FORMAT_PCM is just here to avoid VLC
segfaulting when playing these files directly.

It would probably be better to introduce a new ADEC_CHAN_MAX with an higher value
than AOUT_CHAN_MAX, so decode can still be achieved but processing would be blocked.
What do you think?

---
 include/vlc_aout.h                    | 14 +++++++++++++-
 include/vlc_es.h                      | 26 +++++++++++++++++++++-----
 modules/codec/araw.c                  |  5 ++++-
 modules/demux/wav.c                   |  2 +-
 modules/demux/windows_audio_commons.h | 17 +++++++++++++++--
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 630be72..2d58792 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -177,7 +177,19 @@ static const uint32_t pi_vlc_chan_order_wg4[] =
     AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
     AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
     AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
-    AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0
+    AOUT_CHAN_CENTER, AOUT_CHAN_LFE,
+
+    AOUT_CHAN_SIDE_LEFT,
+    AOUT_CHAN_SIDE_RIGHT,
+    AOUT_CHAN_TOP_CENTER,
+    AOUT_CHAN_TOP_FRONT_CENTER,
+    AOUT_CHAN_TOP_FRONT_LEFT,
+    AOUT_CHAN_TOP_FRONT_RIGHT,
+    AOUT_CHAN_TOP_BACK_CENTER,
+    AOUT_CHAN_TOP_BACK_LEFT,
+    AOUT_CHAN_TOP_BACK_RIGHT,
+
+    0
 };

 #define AOUT_RESTART_FILTERS 1
diff --git a/include/vlc_es.h b/include/vlc_es.h
index 97cdb78..bf0bc11 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -108,13 +108,28 @@ struct audio_format_t
 #define AOUT_CHAN_REARRIGHT         0x40
 #define AOUT_CHAN_MIDDLELEFT        0x100
 #define AOUT_CHAN_MIDDLERIGHT       0x200
-#define AOUT_CHAN_LFE               0x1000
+
+#define AOUT_CHAN_SIDE_LEFT         0x100
+#define AOUT_CHAN_SIDE_RIGHT        0x200
+#define AOUT_CHAN_TOP_CENTER        0x400
+#define AOUT_CHAN_TOP_FRONT_CENTER  0x800
+#define AOUT_CHAN_TOP_FRONT_LEFT    0x1000
+#define AOUT_CHAN_TOP_FRONT_RIGHT   0x2000
+#define AOUT_CHAN_TOP_BACK_CENTER   0x4000
+#define AOUT_CHAN_TOP_BACK_LEFT     0x8000
+#define AOUT_CHAN_TOP_BACK_RIGHT    0x10000
+
+#define AOUT_CHAN_LFE               0x80000

 #define AOUT_CHANS_FRONT  (AOUT_CHAN_LEFT       | AOUT_CHAN_RIGHT)
 #define AOUT_CHANS_MIDDLE (AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT)
 #define AOUT_CHANS_REAR   (AOUT_CHAN_REARLEFT   | AOUT_CHAN_REARRIGHT)
 #define AOUT_CHANS_CENTER (AOUT_CHAN_CENTER     | AOUT_CHAN_REARCENTER)

+#define AOUT_CHANS_TOP_FRONT  (AOUT_CHAN_TOP_FRONT_LEFT | AOUT_CHAN_TOP_FRONT_RIGHT)
+#define AOUT_CHANS_TOP_REAR   (AOUT_CHAN_TOP_BACK_LEFT  | AOUT_CHAN_TOP_BACK_LEFT)
+#define AOUT_CHANS_TOP_CENTER (AOUT_CHAN_TOP_CENTER     | AOUT_CHAN_TOP_FRONT_CENTER | AOUT_CHAN_TOP_BACK_CENTER)
+
 #define AOUT_CHANS_STEREO AOUT_CHANS_2_0
 #define AOUT_CHANS_2_0    (AOUT_CHANS_FRONT)
 #define AOUT_CHANS_2_1    (AOUT_CHANS_FRONT | AOUT_CHAN_LFE)
@@ -128,6 +143,7 @@ struct audio_format_t
 #define AOUT_CHANS_7_0    (AOUT_CHANS_6_0   | AOUT_CHAN_CENTER)
 #define AOUT_CHANS_7_1    (AOUT_CHANS_5_1   | AOUT_CHANS_MIDDLE)
 #define AOUT_CHANS_8_1    (AOUT_CHANS_7_1   | AOUT_CHAN_REARCENTER)
+#define AOUT_CHANS_16_0   (AOUT_CHANS_8_1   | AOUT_CHANS_TOP_FRONT | AOUT_CHANS_TOP_REAR | AOUT_CHANS_TOP_CENTER)

 #define AOUT_CHANS_4_0_MIDDLE (AOUT_CHANS_FRONT | AOUT_CHANS_MIDDLE)
 #define AOUT_CHANS_4_CENTER_REAR (AOUT_CHANS_FRONT | AOUT_CHANS_CENTER)
@@ -135,12 +151,12 @@ struct audio_format_t
 #define AOUT_CHANS_6_1_MIDDLE (AOUT_CHANS_5_0_MIDDLE | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE)

 /* Values available for original channels only */
-#define AOUT_CHAN_DOLBYSTEREO       0x10000
-#define AOUT_CHAN_DUALMONO          0x20000
-#define AOUT_CHAN_REVERSESTEREO     0x40000
+#define AOUT_CHAN_DOLBYSTEREO       0x100000
+#define AOUT_CHAN_DUALMONO          0x200000
+#define AOUT_CHAN_REVERSESTEREO     0x400000

 #define AOUT_CHAN_PHYSMASK          0xFFFF
-#define AOUT_CHAN_MAX               9
+#define AOUT_CHAN_MAX               18

 /**
  * Picture orientation.
diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index 0746a5e..c85e121 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -81,6 +81,9 @@ static const uint16_t pi_channels_maps[] =
     AOUT_CHAN_CENTER, AOUT_CHANS_2_0, AOUT_CHANS_3_0,
     AOUT_CHANS_4_0,   AOUT_CHANS_5_0, AOUT_CHANS_5_1,
     AOUT_CHANS_7_0,   AOUT_CHANS_7_1, AOUT_CHANS_8_1,
+    0,                0,              0,
+    0,                0,              0,
+    AOUT_CHANS_16_0,  0,              0,
 };

 static void S8Decode( void *, const uint8_t *, unsigned );
@@ -246,7 +249,7 @@ static int DecoderOpen( vlc_object_t *p_this )
     if( p_dec->fmt_in.audio.i_channels <= 0 ||
         p_dec->fmt_in.audio.i_channels > AOUT_CHAN_MAX )
     {
-        msg_Err( p_dec, "bad channels count (1-9): %i",
+        msg_Err( p_dec, "bad channels count (1-18): %i",
                  p_dec->fmt_in.audio.i_channels );
         return VLC_EGENERIC;
     }
diff --git a/modules/demux/wav.c b/modules/demux/wav.c
index 827bf72..5a0fe79 100644
--- a/modules/demux/wav.c
+++ b/modules/demux/wav.c
@@ -272,7 +272,7 @@ static int Open( vlc_object_t * p_this )
         }
     }
     else if( GetWLE( &p_wf->wFormatTag ) == WAVE_FORMAT_PCM &&
-             p_sys->fmt.audio.i_channels > 2 && p_sys->fmt.audio.i_channels <= 9 )
+             p_sys->fmt.audio.i_channels > 2 && p_sys->fmt.audio.i_channels <= AOUT_CHAN_MAX )
     {
         for( int i = 0; i < p_sys->fmt.audio.i_channels; i++ )
             p_sys->i_channel_mask |= pi_channels_aout[i];
diff --git a/modules/demux/windows_audio_commons.h b/modules/demux/windows_audio_commons.h
index 80aa5cb..8cf069f 100644
--- a/modules/demux/windows_audio_commons.h
+++ b/modules/demux/windows_audio_commons.h
@@ -29,11 +29,24 @@
 static const uint32_t pi_channels_src[] = { WAVE_SPEAKER_FRONT_LEFT,
     WAVE_SPEAKER_FRONT_RIGHT, WAVE_SPEAKER_FRONT_CENTER,
     WAVE_SPEAKER_LOW_FREQUENCY, WAVE_SPEAKER_BACK_LEFT, WAVE_SPEAKER_BACK_RIGHT,
-    WAVE_SPEAKER_BACK_CENTER, WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT, 0 };
+    WAVE_SPEAKER_FRONT_LEFT_OF_CENTER, WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER,
+    WAVE_SPEAKER_BACK_CENTER, WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT,
+    WAVE_SPEAKER_TOP_CENTER,
+    WAVE_SPEAKER_TOP_FRONT_LEFT, WAVE_SPEAKER_TOP_FRONT_CENTER,  WAVE_SPEAKER_TOP_FRONT_RIGHT,
+    WAVE_SPEAKER_TOP_BACK_LEFT,  WAVE_SPEAKER_TOP_BACK_CENTER, WAVE_SPEAKER_TOP_BACK_RIGHT,
+    0,
+};

 static const uint32_t pi_channels_aout[] = { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
     AOUT_CHAN_CENTER, AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
-    AOUT_CHAN_REARCENTER, AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, 0 };
+    AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
+    AOUT_CHAN_REARCENTER,
+    AOUT_CHAN_SIDE_LEFT, AOUT_CHAN_SIDE_RIGHT,
+    AOUT_CHAN_TOP_CENTER,
+    AOUT_CHAN_TOP_FRONT_LEFT, AOUT_CHAN_TOP_FRONT_CENTER, AOUT_CHAN_TOP_FRONT_RIGHT,
+    AOUT_CHAN_TOP_BACK_LEFT, AOUT_CHAN_TOP_BACK_CENTER, AOUT_CHAN_TOP_BACK_RIGHT,
+    0,
+};

 static inline unsigned getChannelMask( uint32_t * wvfextChannelMask, int i_channels, int * i_match )
 {
--
2.3.8 (Apple Git-58)


More information about the vlc-devel mailing list