]> git.sesse.net Git - vlc/commitdiff
demux: mp4: add chan atom
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 27 Aug 2014 11:00:09 +0000 (20:00 +0900)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sat, 30 Aug 2014 02:51:32 +0000 (11:51 +0900)
modules/demux/mp4/libmp4.c
modules/demux/mp4/libmp4.h

index 1bafd1329fbb09f7b87bd5f932f021eea504f15a..f51416ee96f4b5c9072edb1c14fb13df5a3a2212 100644 (file)
@@ -1452,6 +1452,52 @@ error:
     MP4_READBOX_EXIT( 0 );
 }
 
+static int MP4_ReadBox_stsdext_chan( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_chan_t );
+    MP4_Box_data_chan_t *p_chan = p_box->data.p_chan;
+
+    if ( i_read < 16 )
+        MP4_READBOX_EXIT( 0 );
+
+    MP4_GET1BYTE( p_chan->i_version );
+    MP4_GET3BYTES( p_chan->i_channels_flags );
+    MP4_GET4BYTES( p_chan->layout.i_channels_layout_tag );
+    MP4_GET4BYTES( p_chan->layout.i_channels_bitmap );
+    MP4_GET4BYTES( p_chan->layout.i_channels_description_count );
+    if ( i_read < p_chan->layout.i_channels_description_count * 24 )
+        MP4_READBOX_EXIT( 0 );
+
+    p_chan->layout.p_descriptions =
+        malloc( p_chan->layout.i_channels_description_count * 24 );
+
+    if ( !p_chan->layout.p_descriptions )
+        MP4_READBOX_EXIT( 0 );
+
+    for( uint32_t i=0; i<p_chan->layout.i_channels_description_count; i++ )
+    {
+        MP4_GET4BYTES( p_chan->layout.p_descriptions[i].i_channel_label );
+        MP4_GET4BYTES( p_chan->layout.p_descriptions[i].i_channel_flags );
+        MP4_GET4BYTES( p_chan->layout.p_descriptions[i].f_coordinates[0] );
+        MP4_GET4BYTES( p_chan->layout.p_descriptions[i].f_coordinates[1] );
+        MP4_GET4BYTES( p_chan->layout.p_descriptions[i].f_coordinates[2] );
+    }
+
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream,
+             "read box: \"chan\" flags=0x%x tag=0x%x bitmap=0x%x descriptions=%u",
+             p_chan->i_channels_flags, p_chan->layout.i_channels_layout_tag,
+             p_chan->layout.i_channels_bitmap, p_chan->layout.i_channels_description_count );
+#endif
+    MP4_READBOX_EXIT( 1 );
+}
+
+static void MP4_FreeBox_stsdext_chan( MP4_Box_t *p_box )
+{
+    MP4_Box_data_chan_t *p_chan = p_box->data.p_chan;
+    free( p_chan->layout.p_descriptions );
+}
+
 static int MP4_ReadBox_dac3( stream_t *p_stream, MP4_Box_t *p_box )
 {
     MP4_Box_data_dac3_t *p_dac3;
@@ -3371,6 +3417,8 @@ static const struct
     { ATOM_sawb,    MP4_ReadBox_sample_soun,  MP4_FreeBox_sample_soun, ATOM_stsd },
     { ATOM_OggS,    MP4_ReadBox_sample_soun,  MP4_FreeBox_sample_soun, ATOM_stsd },
     { ATOM_alac,    MP4_ReadBox_sample_soun,  MP4_FreeBox_sample_soun, ATOM_stsd },
+    /* Sound extensions */
+    { ATOM_chan,    MP4_ReadBox_stsdext_chan, MP4_FreeBox_stsdext_chan, 0 },
 
     { ATOM_drmi,    MP4_ReadBox_sample_vide,  MP4_FreeBox_sample_vide, ATOM_stsd },
     { ATOM_vide,    MP4_ReadBox_sample_vide,  MP4_FreeBox_sample_vide, ATOM_stsd },
index 17fc6821884ff3dda0f2d028535a8bea06b9ff40..1451ce9afc72ec43e366fc9cd47c315f09706497 100644 (file)
 #define ATOM_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
 #define ATOM_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
 #define ATOM_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
+#define ATOM_chan VLC_FOURCC( 'c', 'h', 'a', 'n' )
 
 #define ATOM_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
 #define ATOM_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
@@ -1037,6 +1038,24 @@ typedef struct
 
 } MP4_Box_data_avcC_t;
 
+typedef struct
+{
+    uint8_t i_version;
+    uint32_t i_channels_flags; /* 24 bits */
+    struct
+    {
+        uint32_t i_channels_layout_tag;
+        uint32_t i_channels_bitmap;
+        uint32_t i_channels_description_count;
+        struct
+        {
+            uint32_t i_channel_label;
+            uint32_t i_channel_flags;
+            float    f_coordinates[3];
+        } *p_descriptions;
+    } layout;
+} MP4_Box_data_chan_t;
+
 typedef struct
 {
     uint8_t i_fscod;
@@ -1222,6 +1241,7 @@ typedef union MP4_Box_data_s
     MP4_Box_data_avcC_t *p_avcC;
     MP4_Box_data_dac3_t *p_dac3;
     MP4_Box_data_dvc1_t *p_dvc1;
+    MP4_Box_data_chan_t *p_chan;
     MP4_Box_data_enda_t *p_enda;
     MP4_Box_data_gnre_t *p_gnre;
     MP4_Box_data_trkn_t *p_trkn;