[vlc-commits] mux: mp4: convert EAC3SpecificBox creation to extradata helper

Francois Cartegnie git at videolan.org
Fri Dec 21 16:13:33 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Dec 21 15:24:43 2018 +0100| [6fcb895f2766614de7bd188902c71f4f4952f5a3] | committer: Francois Cartegnie

mux: mp4: convert EAC3SpecificBox creation to extradata helper

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

 modules/mux/extradata.c     |  47 ++++++++++++++++
 modules/mux/mp4/libmp4mux.c | 127 +-------------------------------------------
 modules/mux/mp4/mp4.c       |   8 ---
 3 files changed, 49 insertions(+), 133 deletions(-)

diff --git a/modules/mux/extradata.c b/modules/mux/extradata.c
index b9152bf8cf..3d3631ccc7 100644
--- a/modules/mux/extradata.c
+++ b/modules/mux/extradata.c
@@ -80,6 +80,50 @@ const struct mux_extradata_builder_cb ac3_cb =
     NULL,
 };
 
+static void eac3_extradata_builder_Feed(mux_extradata_builder_t *m,
+                                        const uint8_t *p_data, size_t i_data)
+{
+    if(m->i_extra || i_data < VLC_A52_MIN_HEADER_SIZE ||
+       p_data[0] != 0x0B || p_data[1] != 0x77)
+        return;
+
+    struct vlc_a52_bitstream_info bsi;
+    if(vlc_a52_ParseEac3BitstreamInfo(&bsi, &p_data[2], /* start code */
+                                      i_data - 2) != VLC_SUCCESS)
+        return;
+
+    m->p_extra = malloc(5);
+    if(!m->p_extra)
+        return;
+    m->i_extra = 5;
+
+    bs_t s;
+    bs_write_init(&s, m->p_extra, m->i_extra);
+    const unsigned rgi_fscod_samplerates[] = { 48000, 44100, 32000 };
+    unsigned fs = rgi_fscod_samplerates[bsi.i_fscod];
+    unsigned numblks = bsi.eac3.i_numblkscod + 1;
+    if(numblks > 3)
+        numblks = 6;
+    unsigned data_rate = (bsi.eac3.i_frmsiz + 1) * fs / (numblks << 4); /* F.6.2.2 */
+    bs_write(&s, 13, data_rate);
+    bs_write(&s, 3, 0); // num_ind_sub - 1
+    bs_write(&s, 2, bsi.i_fscod);
+    bs_write(&s, 5, bsi.i_bsid);
+    bs_write(&s, 5, bsi.i_bsmod);
+    bs_write(&s, 3, bsi.i_acmod);
+    bs_write(&s, 1, bsi.i_lfeon);
+    bs_write(&s, 3, 0); // reserved
+    bs_write(&s, 4, 0); // num_dep_sub
+    bs_write(&s, 1, 0); // reserved
+}
+
+const struct mux_extradata_builder_cb eac3_cb =
+{
+    NULL,
+    eac3_extradata_builder_Feed,
+    NULL,
+};
+
 static void av1_extradata_builder_Feed(mux_extradata_builder_t *m,
                                        const uint8_t *p_data, size_t i_data)
 {
@@ -131,6 +175,9 @@ mux_extradata_builder_t * mux_extradata_builder_New(vlc_fourcc_t fcc)
         case VLC_CODEC_A52:
             cb = &ac3_cb;
             break;
+        case VLC_CODEC_EAC3:
+            cb = &eac3_cb;
+            break;
         default:
             return NULL;
     }
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 327397d3f8..480a87f859 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -668,129 +668,6 @@ static bo_t *GetWaveTag(mp4mux_trackinfo_t *p_track)
     return wave;
 }
 
-static bo_t *GetDec3Tag(es_format_t *p_fmt,
-                        const uint8_t *p_data, size_t i_data)
-{
-    if (!i_data)
-        return NULL;
-
-    bs_t s;
-    bs_init(&s, p_data, i_data);
-    bs_skip(&s, 16); // syncword
-
-    uint8_t fscod, bsid, bsmod, acmod, lfeon, strmtyp;
-
-    bsmod = 0;
-
-    strmtyp = bs_read(&s, 2);
-
-    if (strmtyp & 0x1) // dependent or reserved stream
-        return NULL;
-
-    if (bs_read(&s, 3) != 0x0) // substreamid: we don't support more than 1 stream
-        return NULL;
-
-    int numblkscod;
-    bs_skip(&s, 11); // frmsizecod
-    fscod = bs_read(&s, 2);
-    if (fscod == 0x03) {
-        bs_skip(&s, 2); // fscod2
-        numblkscod = 3;
-    } else {
-        numblkscod = bs_read(&s, 2);
-    }
-
-    acmod = bs_read(&s, 3);
-    lfeon = bs_read1(&s);
-
-    bsid = bs_read(&s, 5);
-
-    bs_skip(&s, 5); // dialnorm
-    if (bs_read1(&s)) // compre
-        bs_skip(&s, 5); // compr
-
-    if (acmod == 0) {
-        bs_skip(&s, 5); // dialnorm2
-        if (bs_read1(&s)) // compr2e
-            bs_skip(&s, 8); // compr2
-    }
-
-    if (strmtyp == 0x1) // dependent stream XXX: unsupported
-        if (bs_read1(&s)) // chanmape
-            bs_skip(&s, 16); // chanmap
-
-    /* we have to skip mixing info to read bsmod */
-    if (bs_read1(&s)) { // mixmdate
-        if (acmod > 0x2) // 2+ channels
-            bs_skip(&s, 2); // dmixmod
-        if ((acmod & 0x1) && (acmod > 0x2)) // 3 front channels
-            bs_skip(&s, 3 + 3); // ltrtcmixlev + lorocmixlev
-        if (acmod & 0x4) // surround channel
-            bs_skip(&s, 3 + 3); // ltrsurmixlev + lorosurmixlev
-        if (lfeon)
-            if (bs_read1(&s))
-                bs_skip(&s, 5); // lfemixlevcod
-        if (strmtyp == 0) { // independent stream
-            if (bs_read1(&s)) // pgmscle
-                bs_skip(&s, 6); // pgmscl
-            if (acmod == 0x0) // dual mono
-                if (bs_read1(&s)) // pgmscl2e
-                    bs_skip(&s, 6); // pgmscl2
-            if (bs_read1(&s)) // extpgmscle
-                bs_skip(&s, 6); // extpgmscl
-            uint8_t mixdef = bs_read(&s, 2);
-            if (mixdef == 0x1)
-                bs_skip(&s, 5);
-            else if (mixdef == 0x2)
-                bs_skip(&s, 12);
-            else if (mixdef == 0x3) {
-                uint8_t mixdeflen = bs_read(&s, 5);
-                bs_skip(&s, 8 * (mixdeflen + 2));
-            }
-            if (acmod < 0x2) { // mono or dual mono
-                if (bs_read1(&s)) // paninfoe
-                    bs_skip(&s, 14); // paninfo
-                if (acmod == 0) // dual mono
-                    if (bs_read1(&s)) // paninfo2e
-                        bs_skip(&s, 14); // paninfo2
-            }
-            if (bs_read1(&s)) { // frmmixcfginfoe
-                static const int blocks[4] = { 1, 2, 3, 6 };
-                int number_of_blocks = blocks[numblkscod];
-                if (number_of_blocks == 1)
-                    bs_skip(&s, 5); // blkmixcfginfo[0]
-                else for (int i = 0; i < number_of_blocks; i++)
-                    if (bs_read1(&s)) // blkmixcfginfoe
-                        bs_skip(&s, 5); // blkmixcfginfo[i]
-            }
-        }
-    }
-
-    if (bs_read1(&s)) // infomdate
-        bsmod = bs_read(&s, 3);
-
-    uint8_t mp4_eac3_header[5] = {0};
-    bs_write_init(&s, mp4_eac3_header, sizeof(mp4_eac3_header));
-
-    int data_rate = p_fmt->i_bitrate / 1000;
-    bs_write(&s, 13, data_rate);
-    bs_write(&s, 3, 0); // num_ind_sub - 1
-    bs_write(&s, 2, fscod);
-    bs_write(&s, 5, bsid);
-    bs_write(&s, 5, bsmod);
-    bs_write(&s, 3, acmod);
-    bs_write(&s, 1, lfeon);
-    bs_write(&s, 3, 0); // reserved
-    bs_write(&s, 4, 0); // num_dep_sub
-    bs_write(&s, 1, 0); // reserved
-
-    bo_t *dec3 = box_new("dec3");
-    if(dec3)
-        bo_add_mem(dec3, sizeof(mp4_eac3_header), mp4_eac3_header);
-
-    return dec3;
-}
-
 static bo_t *GetDamrTag(es_format_t *p_fmt)
 {
     bo_t *damr = box_new("damr");
@@ -1224,8 +1101,8 @@ static bo_t *GetSounBox(vlc_object_t *p_obj, mp4mux_trackinfo_t *p_track, bool b
             box = GetDamrTag(&p_track->fmt);
         else if (codec == VLC_CODEC_A52 && i_extradata >= 3)
             box = GetxxxxTag(p_extradata, i_extradata, "dac3");
-        else if (codec == VLC_CODEC_EAC3)
-            box = GetDec3Tag(&p_track->fmt, p_extradata, i_extradata);
+        else if (codec == VLC_CODEC_EAC3 && i_extradata >= 5)
+            box = GetxxxxTag(p_extradata, i_extradata, "dec3");
         else if (codec == VLC_CODEC_WMAP)
             box = GetWaveFormatExTag(&p_track->fmt, "wfex");
         else
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index 6b4eed5eed..2c496a7c12 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -632,14 +632,6 @@ static block_t * BlockDequeue(sout_input_t *p_input, mp4_stream_t *p_stream)
         case VLC_CODEC_SUBT:
             p_block = ConvertSUBT(p_block);
             break;
-        case VLC_CODEC_EAC3:
-            if(!mp4mux_track_HasSamplePriv(p_stream->tinfo) &&
-               p_block->i_buffer >= 8)
-            {
-                mp4mux_track_SetSamplePriv(p_stream->tinfo,
-                                           p_block->p_buffer, p_block->i_buffer);
-            }
-            break;
         default:
             break;
     }



More information about the vlc-commits mailing list