[vlc-commits] demux: libmp4: split CoreAudio definitions

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Dec 18 10:00:38 2018 +0100| [f7b78e0e8d9ed7afd433a55e9636516d181e2220] | committer: Francois Cartegnie

demux: libmp4: split CoreAudio definitions

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

 modules/demux/Makefile.am     |   1 +
 modules/demux/mp4/coreaudio.h | 100 ++++++++++++++++++++++++++++++++++++++++++
 modules/demux/mp4/essetup.c   |  24 +++-------
 modules/demux/mp4/libmp4.h    |  50 +--------------------
 4 files changed, 109 insertions(+), 66 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 8fab97b525..8ea2e01683 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -210,6 +210,7 @@ libmp4_plugin_la_SOURCES = demux/mp4/mp4.c demux/mp4/mp4.h \
                            demux/mp4/heif.c demux/mp4/heif.h \
                            demux/mp4/avci.h \
                            demux/mp4/essetup.c demux/mp4/meta.c \
+                           demux/mp4/coreaudio.h \
                            demux/av1_unpack.h \
                            demux/asf/asfpacket.c demux/asf/asfpacket.h \
                            packetizer/iso_color_tables.h \
diff --git a/modules/demux/mp4/coreaudio.h b/modules/demux/mp4/coreaudio.h
new file mode 100644
index 0000000000..1852ffeca6
--- /dev/null
+++ b/modules/demux/mp4/coreaudio.h
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * coreaudio.h : CoreAudio definitions for vlc
+ *****************************************************************************
+ * Copyright (C) 2014-2018 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include <vlc_aout.h>
+
+/* According to Apple's CoreAudio_Bitmap/CoreAudio_BitmapTypes.h */
+enum
+{
+    CoreAudio_Bitmap_LEFT                 = (1<<0),
+    CoreAudio_Bitmap_RIGHT                = (1<<1),
+    CoreAudio_Bitmap_CENTER               = (1<<2),
+    CoreAudio_Bitmap_LFESCREEN            = (1<<3),
+    CoreAudio_Bitmap_BACKLEFT             = (1<<4),
+    CoreAudio_Bitmap_BACKRIGHT            = (1<<5),
+    CoreAudio_Bitmap_LEFTCENTER           = (1<<6),
+    CoreAudio_Bitmap_RIGHTCENTER          = (1<<7),
+    CoreAudio_Bitmap_BACKCENTER           = (1<<8),
+    CoreAudio_Bitmap_SIDELEFT             = (1<<9),
+    CoreAudio_Bitmap_SIDERIGHT            = (1<<10),
+    CoreAudio_Bitmap_TOPCENTER            = (1<<11),
+    CoreAudio_Bitmap_TOPFRONTLEFT         = (1<<12),
+    CoreAudio_Bitmap_TOPFRONTENTER        = (1<<13),
+    CoreAudio_Bitmap_TOPFRONTRIGHT        = (1<<14),
+    CoreAudio_Bitmap_TOPBACKLEFT          = (1<<15),
+    CoreAudio_Bitmap_TOPBACKCENTER        = (1<<16),
+    CoreAudio_Bitmap_TOPBACKRIGHT         = (1<<17),
+};
+
+static const struct
+{
+    uint32_t i_bitmap;
+    uint32_t i_vlc_bitmap;
+} CoreAudio_Bitmap_mapping[] = {
+    { CoreAudio_Bitmap_LEFT,         AOUT_CHAN_LEFT },
+    { CoreAudio_Bitmap_RIGHT,        AOUT_CHAN_RIGHT },
+    { CoreAudio_Bitmap_CENTER,       AOUT_CHAN_CENTER },
+    { CoreAudio_Bitmap_LFESCREEN,    AOUT_CHAN_LFE },
+    { CoreAudio_Bitmap_BACKLEFT,     AOUT_CHAN_REARLEFT },
+    { CoreAudio_Bitmap_BACKRIGHT,    AOUT_CHAN_REARRIGHT },
+    { CoreAudio_Bitmap_LEFTCENTER,   AOUT_CHAN_MIDDLELEFT },
+    { CoreAudio_Bitmap_RIGHTCENTER,  AOUT_CHAN_MIDDLERIGHT },
+    { CoreAudio_Bitmap_BACKCENTER,   AOUT_CHAN_REARCENTER },
+    { CoreAudio_Bitmap_SIDELEFT,     AOUT_CHAN_LEFT },
+    { CoreAudio_Bitmap_SIDERIGHT,    AOUT_CHAN_RIGHT },
+    { CoreAudio_Bitmap_TOPCENTER,    AOUT_CHAN_CENTER },
+    { CoreAudio_Bitmap_TOPFRONTLEFT, AOUT_CHAN_LEFT },
+    { CoreAudio_Bitmap_TOPFRONTENTER,AOUT_CHAN_CENTER },
+    { CoreAudio_Bitmap_TOPFRONTRIGHT,AOUT_CHAN_RIGHT },
+    { CoreAudio_Bitmap_TOPBACKLEFT,  AOUT_CHAN_REARLEFT },
+    { CoreAudio_Bitmap_TOPBACKCENTER,AOUT_CHAN_REARCENTER },
+    { CoreAudio_Bitmap_TOPBACKRIGHT, AOUT_CHAN_REARRIGHT },
+};
+
+enum CoreAudio_Layout
+{
+    CoreAudio_Layout_DESC                 = 0,
+    CoreAudio_Layout_BITMAP               = (1<<16),
+};
+
+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] )
+{
+    *pi_mapping = 0;
+    *pi_channels = 0;
+    for (uint8_t i=0;i<ARRAY_SIZE(CoreAudio_Bitmap_mapping);i++)
+    {
+        if ( CoreAudio_Bitmap_mapping[i].i_bitmap & i_corebitmap )
+        {
+            if ( (CoreAudio_Bitmap_mapping[i].i_vlc_bitmap & *pi_mapping) ||
+                 *pi_channels >= AOUT_CHAN_MAX )
+            {
+                /* double mapping or unsupported number of channels */
+                *pi_mapping = 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 bd864e1b8a..4bf8a9c8a4 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -1183,30 +1183,20 @@ 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 == MP4_CHAN_USE_CHANNELS_BITMAP )
+        if ( BOXDATA(p_chan)->layout.i_channels_layout_tag == CoreAudio_Layout_BITMAP )
         {
             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;
-            const uint32_t i_bitmap = BOXDATA(p_chan)->layout.i_channels_bitmap;
-            for (uint8_t i=0;i<MP4_CHAN_BITMAP_MAPPING_COUNT;i++)
+
+            if( CoreAudio_Bitmap_to_vlc_bitmap( BOXDATA(p_chan)->layout.i_channels_bitmap,
+                                               &i_vlc_mapping, &i_channels,
+                                                rgi_chans_sequence ) != VLC_SUCCESS )
             {
-                if ( chan_bitmap_mapping[i].i_bitmap & i_bitmap )
-                {
-                    if ( (chan_bitmap_mapping[i].i_vlc & i_vlc_mapping) ||
-                         i_channels >= AOUT_CHAN_MAX )
-                    {
-                        /* double mapping or unsupported number of channels */
-                        i_vlc_mapping = 0;
-                        msg_Warn( p_demux, "discarding chan mapping" );
-                        break;
-                    }
-                    i_vlc_mapping |= chan_bitmap_mapping[i].i_vlc;
-                    rgi_chans_sequence[i_channels++] = chan_bitmap_mapping[i].i_vlc;
-                }
+                msg_Warn( p_demux, "discarding chan mapping" );
             }
-            rgi_chans_sequence[i_channels] = 0;
+
             if( aout_CheckChannelReorder( rgi_chans_sequence, NULL, i_vlc_mapping,
                                           p_track->rgi_chans_reordering ) &&
                 aout_BitsPerSample( p_track->fmt.i_codec ) )
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 29de18c4ed..df545c83b2 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -24,6 +24,7 @@
 
 #include <vlc_es.h>
 #include <vlc_codecs.h>
+#include "coreaudio.h"
 
 /* Use alias for scaled time */
 typedef int64_t stime_t;
@@ -1374,55 +1375,6 @@ typedef struct
     } entries;
 } MP4_Box_data_sbgp_t;
 
-/* According to Apple's CoreAudio/CoreAudioTypes.h */
-#define MP4_CHAN_USE_CHANNELS_DESC           0
-#define MP4_CHAN_USE_CHANNELS_BITMAP         (1<<16)
-
-#define MP4_CHAN_BITMAP_LEFT                 (1<<0)
-#define MP4_CHAN_BITMAP_RIGHT                (1<<1)
-#define MP4_CHAN_BITMAP_CENTER               (1<<2)
-#define MP4_CHAN_BITMAP_LFESCREEN            (1<<3)
-#define MP4_CHAN_BITMAP_BACKLEFT             (1<<4)
-#define MP4_CHAN_BITMAP_BACKRIGHT            (1<<5)
-#define MP4_CHAN_BITMAP_LEFTCENTER           (1<<6)
-#define MP4_CHAN_BITMAP_RIGHTCENTER          (1<<7)
-#define MP4_CHAN_BITMAP_BACKCENTER           (1<<8)
-#define MP4_CHAN_BITMAP_SIDELEFT             (1<<9)
-#define MP4_CHAN_BITMAP_SIDERIGHT            (1<<10)
-#define MP4_CHAN_BITMAP_TOPCENTER            (1<<11)
-#define MP4_CHAN_BITMAP_TOPFRONTLEFT         (1<<12)
-#define MP4_CHAN_BITMAP_TOPFRONTENTER        (1<<13)
-#define MP4_CHAN_BITMAP_TOPFRONTRIGHT        (1<<14)
-#define MP4_CHAN_BITMAP_TOPBACKLEFT          (1<<15)
-#define MP4_CHAN_BITMAP_TOPBACKCENTER        (1<<16)
-#define MP4_CHAN_BITMAP_TOPBACKRIGHT         (1<<17)
-
-#define MP4_CHAN_BITMAP_MAPPING_COUNT 18
-static const struct
-{
-    uint32_t i_bitmap;
-    uint32_t i_vlc;
-} chan_bitmap_mapping[MP4_CHAN_BITMAP_MAPPING_COUNT] = {
-    { MP4_CHAN_BITMAP_LEFT,         AOUT_CHAN_LEFT },
-    { MP4_CHAN_BITMAP_RIGHT,        AOUT_CHAN_RIGHT },
-    { MP4_CHAN_BITMAP_CENTER,       AOUT_CHAN_CENTER },
-    { MP4_CHAN_BITMAP_LFESCREEN,    AOUT_CHAN_LFE },
-    { MP4_CHAN_BITMAP_BACKLEFT,     AOUT_CHAN_REARLEFT },
-    { MP4_CHAN_BITMAP_BACKRIGHT,    AOUT_CHAN_REARRIGHT },
-    { MP4_CHAN_BITMAP_LEFTCENTER,   AOUT_CHAN_MIDDLELEFT },
-    { MP4_CHAN_BITMAP_RIGHTCENTER,  AOUT_CHAN_MIDDLERIGHT },
-    { MP4_CHAN_BITMAP_BACKCENTER,   AOUT_CHAN_REARCENTER },
-    { MP4_CHAN_BITMAP_SIDELEFT,     AOUT_CHAN_LEFT },
-    { MP4_CHAN_BITMAP_SIDERIGHT,    AOUT_CHAN_RIGHT },
-    { MP4_CHAN_BITMAP_TOPCENTER,    AOUT_CHAN_CENTER },
-    { MP4_CHAN_BITMAP_TOPFRONTLEFT, AOUT_CHAN_LEFT },
-    { MP4_CHAN_BITMAP_TOPFRONTENTER,AOUT_CHAN_CENTER },
-    { MP4_CHAN_BITMAP_TOPFRONTRIGHT,AOUT_CHAN_RIGHT },
-    { MP4_CHAN_BITMAP_TOPBACKLEFT,  AOUT_CHAN_REARLEFT },
-    { MP4_CHAN_BITMAP_TOPBACKCENTER,AOUT_CHAN_REARCENTER },
-    { MP4_CHAN_BITMAP_TOPBACKRIGHT, AOUT_CHAN_REARRIGHT },
-};
-
 typedef struct
 {
     uint8_t i_version;



More information about the vlc-commits mailing list