[vlc-commits] demux: mp4: use static mapping table per layout

Francois Cartegnie git at videolan.org
Wed Dec 19 15:14:16 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Dec 18 16:21:02 2018 +0100| [4ee261a441c645849caeae9a5cc3c6df9fa834af] | committer: Francois Cartegnie

demux: mp4: use static mapping table per layout

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4ee261a441c645849caeae9a5cc3c6df9fa834af
---

 modules/demux/mp4/coreaudio.h | 16 +++++++++++++---
 modules/demux/mp4/essetup.c   | 38 +++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/modules/demux/mp4/coreaudio.h b/modules/demux/mp4/coreaudio.h
index 1852ffeca6..e77dfcc3e0 100644
--- a/modules/demux/mp4/coreaudio.h
+++ b/modules/demux/mp4/coreaudio.h
@@ -42,6 +42,16 @@ enum
     CoreAudio_Bitmap_TOPBACKRIGHT         = (1<<17),
 };
 
+static const uint32_t pi_vlc_chan_order_CoreAudio[] =
+{
+    AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER,
+    AOUT_CHAN_LFE,
+    AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
+    AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARCENTER,
+    AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
+    0
+};
+
 static const struct
 {
     uint32_t i_bitmap;
@@ -76,8 +86,9 @@ enum CoreAudio_Layout
 static inline int CoreAudio_Bitmap_to_vlc_bitmap( uint32_t i_corebitmap,
                                                   uint16_t *pi_mapping,
                                                   uint8_t *pi_channels,
-                                                  uint32_t p_chans[AOUT_CHAN_MAX + 1] )
+                                                  const uint32_t **pp_chans_order )
 {
+    *pp_chans_order = pi_vlc_chan_order_CoreAudio;
     *pi_mapping = 0;
     *pi_channels = 0;
     for (uint8_t i=0;i<ARRAY_SIZE(CoreAudio_Bitmap_mapping);i++)
@@ -89,12 +100,11 @@ static inline int CoreAudio_Bitmap_to_vlc_bitmap( uint32_t i_corebitmap,
             {
                 /* double mapping or unsupported number of channels */
                 *pi_mapping = 0;
+                *pi_channels = 0;
                 return VLC_EGENERIC;
             }
             *pi_mapping |= CoreAudio_Bitmap_mapping[i].i_vlc_bitmap;
-            p_chans[(*pi_channels)++] = CoreAudio_Bitmap_mapping[i].i_vlc_bitmap;
         }
     }
-    p_chans[*pi_channels] = 0;
     return VLC_SUCCESS;
 }
diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index 4bf8a9c8a4..07d9407f74 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -1183,29 +1183,25 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
     const MP4_Box_t *p_chan = MP4_BoxGet( p_sample, "chan" );
     if ( p_chan )
     {
-        if ( BOXDATA(p_chan)->layout.i_channels_layout_tag == CoreAudio_Layout_BITMAP )
+        uint16_t i_vlc_mapping = 0;
+        uint8_t i_channels = 0;
+        const uint32_t *p_rg_chans_order = NULL;
+
+        if ( BOXDATA(p_chan)->layout.i_channels_layout_tag == CoreAudio_Layout_BITMAP &&
+             CoreAudio_Bitmap_to_vlc_bitmap( BOXDATA(p_chan)->layout.i_channels_bitmap,
+                                            &i_vlc_mapping, &i_channels,
+                                            &p_rg_chans_order ) != VLC_SUCCESS )
         {
-            uint32_t rgi_chans_sequence[AOUT_CHAN_MAX + 1];
-            memset(rgi_chans_sequence, 0, sizeof(rgi_chans_sequence));
-            uint16_t i_vlc_mapping = 0;
-            uint8_t i_channels = 0;
-
-            if( CoreAudio_Bitmap_to_vlc_bitmap( BOXDATA(p_chan)->layout.i_channels_bitmap,
-                                               &i_vlc_mapping, &i_channels,
-                                                rgi_chans_sequence ) != VLC_SUCCESS )
-            {
-                msg_Warn( p_demux, "discarding chan mapping" );
-            }
-
-            if( aout_CheckChannelReorder( rgi_chans_sequence, NULL, i_vlc_mapping,
-                                          p_track->rgi_chans_reordering ) &&
-                aout_BitsPerSample( p_track->fmt.i_codec ) )
-            {
-                p_track->b_chans_reorder = true;
-                p_track->fmt.audio.i_channels = i_channels;
-                p_track->fmt.audio.i_physical_channels = i_vlc_mapping;
-            }
+            msg_Warn( p_demux, "discarding chan mapping" );
+        }
 
+        if( aout_BitsPerSample( p_track->fmt.i_codec ) && i_vlc_mapping > 0 &&
+            aout_CheckChannelReorder( p_rg_chans_order, NULL, i_vlc_mapping,
+                                      p_track->rgi_chans_reordering ) )
+        {
+            p_track->b_chans_reorder = true;
+            p_track->fmt.audio.i_channels = i_channels;
+            p_track->fmt.audio.i_physical_channels = i_vlc_mapping;
         }
     }
 



More information about the vlc-commits mailing list