]> git.sesse.net Git - vlc/commitdiff
mp4 demux: read dec3 box
authorRafaël Carré <funman@videolan.org>
Wed, 3 Sep 2014 11:03:17 +0000 (13:03 +0200)
committerRafaël Carré <funman@videolan.org>
Wed, 3 Sep 2014 11:06:29 +0000 (13:06 +0200)
modules/demux/mp4/libmp4.c
modules/demux/mp4/libmp4.h
modules/demux/mp4/mp4.c

index 66f5db239882cdc802b97f39614a5b2e651d3d65..f3c99cbf628b2027aa24f2a790ffabd4f36b9cff 100644 (file)
@@ -1498,6 +1498,47 @@ static void MP4_FreeBox_stsdext_chan( MP4_Box_t *p_box )
     free( p_chan->layout.p_descriptions );
 }
 
+static int MP4_ReadBox_dec3( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_dec3_t );
+
+    MP4_Box_data_dec3_t *p_dec3 = p_box->data.p_dec3;
+
+    unsigned i_header;
+    MP4_GET2BYTES( i_header );
+
+    p_dec3->i_data_rate = i_header >> 3;
+    p_dec3->i_num_ind_sub = (i_header & 0x7) + 1;
+    for (uint8_t i = 0; i < p_dec3->i_num_ind_sub; i++) {
+        MP4_GET3BYTES( i_header );
+        p_dec3->stream[i].i_fscod = ( i_header >> 22 ) & 0x03;
+        p_dec3->stream[i].i_bsid  = ( i_header >> 17 ) & 0x01f;
+        p_dec3->stream[i].i_bsmod = ( i_header >> 12 ) & 0x01f;
+        p_dec3->stream[i].i_acmod = ( i_header >> 9 ) & 0x07;
+        p_dec3->stream[i].i_lfeon = ( i_header >> 8 ) & 0x01;
+        p_dec3->stream[i].i_num_dep_sub = (i_header >> 1) & 0x0f;
+        if (p_dec3->stream[i].i_num_dep_sub) {
+            MP4_GET1BYTE( p_dec3->stream[i].i_chan_loc );
+            p_dec3->stream[i].i_chan_loc |= (i_header & 1) << 8;
+        } else
+            p_dec3->stream[i].i_chan_loc = 0;
+    }
+
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream,
+        "read box: \"dec3\" bitrate %dkbps %d independant substreams",
+            p_dec3->i_data_rate, p_dec3->i_num_ind_sub);
+
+    for (uint8_t i = 0; i < p_dec3->i_num_ind_sub; i++)
+        msg_Dbg( p_stream,
+                "\tstream %d: bsid=0x%x bsmod=0x%x acmod=0x%x lfeon=0x%x "
+                "num dependant subs=%d chan_loc=0x%x",
+                i, p_dec3->stream[i].i_bsid, p_dec3->stream[i].i_bsmod, p_dec3->stream[i].i_acmod,
+                p_dec3->stream[i].i_lfeon, p_dec3->stream[i].i_num_dep_sub, p_dec3->stream[i].i_chan_loc );
+#endif
+    MP4_READBOX_EXIT( 1 );
+}
+
 static int MP4_ReadBox_dac3( stream_t *p_stream, MP4_Box_t *p_box )
 {
     MP4_Box_data_dac3_t *p_dac3;
@@ -3376,6 +3417,7 @@ static const struct
     { ATOM_avcC,    MP4_ReadBox_avcC,         MP4_FreeBox_avcC, 0 },
     { ATOM_hvcC,    MP4_ReadBox_hvcC,         MP4_FreeBox_hvcC, 0 },
     { ATOM_dac3,    MP4_ReadBox_dac3,         MP4_FreeBox_Common, 0 },
+    { ATOM_dec3,    MP4_ReadBox_dec3,         MP4_FreeBox_Common, 0 },
     { ATOM_dvc1,    MP4_ReadBox_dvc1,         MP4_FreeBox_Common, 0 },
     { ATOM_enda,    MP4_ReadBox_enda,         MP4_FreeBox_Common, 0 },
     { ATOM_iods,    MP4_ReadBox_iods,         MP4_FreeBox_Common, 0 },
index b6c8fa4d4ea0b0fcf731ba0326169bd253be678f..d8ec684465988b47588ac2ea0f83d6fc8454c452 100644 (file)
@@ -1107,6 +1107,23 @@ typedef struct
     } layout;
 } MP4_Box_data_chan_t;
 
+typedef struct
+{
+    uint16_t i_data_rate;
+    uint8_t i_num_ind_sub;
+    struct
+    {
+        uint8_t i_fscod;
+        uint8_t i_bsid;
+        uint8_t i_bsmod;
+        uint8_t i_acmod;
+        uint8_t i_lfeon;
+        uint8_t i_num_dep_sub;
+        uint16_t i_chan_loc;
+    } stream[8];
+
+} MP4_Box_data_dec3_t;
+
 typedef struct
 {
     uint8_t i_fscod;
@@ -1291,6 +1308,7 @@ typedef union MP4_Box_data_s
     MP4_Box_data_esds_t *p_esds;
     MP4_Box_data_avcC_t *p_avcC;
     MP4_Box_data_dac3_t *p_dac3;
+    MP4_Box_data_dec3_t *p_dec3;
     MP4_Box_data_dvc1_t *p_dvc1;
     MP4_Box_data_chan_t *p_chan;
     MP4_Box_data_enda_t *p_enda;
index cef8be8e0b4ef56fa3caaf49b63a53b7ec831094..aad554c1eb1380af3356b42d1b1239b0c30cf914 100644 (file)
@@ -2424,6 +2424,20 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
             p_track->fmt.i_codec = VLC_CODEC_MPGA;
             break;
         }
+        case( VLC_FOURCC( 'e', 'c', '-', '3' ) ):
+        {
+            MP4_Box_t *p_dec3_box = MP4_BoxGet(  p_sample, "dec3", 0 );
+
+            p_track->fmt.i_codec = VLC_CODEC_EAC3;
+            if( p_dec3_box )
+            {
+                MP4_Box_data_dec3_t *p_dec3 = p_dec3_box->data.p_dec3;
+                p_track->fmt.audio.i_channels = 0;
+                p_track->fmt.i_bitrate = p_dec3->i_data_rate * 1000;
+                p_track->fmt.audio.i_bitspersample = 0;
+            }
+            break;
+        }
         case( VLC_FOURCC( 'a', 'c', '-', '3' ) ):
         {
             MP4_Box_t *p_dac3_box = MP4_BoxGet(  p_sample, "dac3", 0 );
@@ -2447,11 +2461,6 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
             }
             break;
         }
-        case( VLC_FOURCC( 'e', 'c', '-', '3' ) ):
-        {
-            p_track->fmt.i_codec = VLC_CODEC_EAC3;
-            break;
-        }
 
         case( VLC_FOURCC( 'r', 'a', 'w', ' ' ) ):
         case( VLC_FOURCC( 'N', 'O', 'N', 'E' ) ):