vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Fri Dec 21 
15:24:03 2018 +0100| [a741ddff109be92ba8c2fdc93be9795e8fae9e34] | committer: 
Francois Cartegnie

mux: mp4: mov AC3SpecificBox to extradata builder

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

 modules/mux/extradata.c     | 39 ++++++++++++++++++++++++++++++++++
 modules/mux/mp4/libmp4mux.c | 52 ++-------------------------------------------
 modules/mux/mp4/mp4.c       |  1 -
 3 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/modules/mux/extradata.c b/modules/mux/extradata.c
index 79076cc23e..2ed5c0215a 100644
--- a/modules/mux/extradata.c
+++ b/modules/mux/extradata.c
@@ -26,6 +26,7 @@
 
 #include "extradata.h"
 #include "../packetizer/av1_obu.h"
+#include "../packetizer/a52.h"
 
 struct mux_extradata_builder_cb
 {
@@ -43,6 +44,41 @@ struct mux_extradata_builder_t
     vlc_fourcc_t fcc;
 };
 
+static void ac3_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_ParseAc3BitstreamInfo(&bsi, &p_data[4], /* start code + CRC */
+                                     VLC_A52_MIN_HEADER_SIZE - 4 ) != 
VLC_SUCCESS)
+        return;
+
+    m->p_extra = malloc(3);
+    if(!m->p_extra)
+        return;
+    m->i_extra = 3;
+
+    bs_t s;
+    bs_write_init(&s, m->p_extra, m->i_extra);
+    bs_write(&s, 2, bsi.i_fscod);
+    bs_write(&s, 5, bsi.i_bsid);
+    bs_write(&s, 3, bsi.i_bsmod);
+    bs_write(&s, 3, bsi.i_acmod);
+    bs_write(&s, 1, bsi.i_lfeon);
+    bs_write(&s, 5, bsi.i_frmsizcod >> 1); // bit_rate_code
+    bs_write(&s, 5, 0); // reserved
+}
+
+const struct mux_extradata_builder_cb ac3_cb =
+{
+    NULL,
+    ac3_extradata_builder_Feed,
+    NULL,
+};
+
 static void av1_extradata_builder_Feed(mux_extradata_builder_t *m,
                                        const uint8_t *p_data, size_t i_data)
 {
@@ -91,6 +127,9 @@ mux_extradata_builder_t * 
mux_extradata_builder_New(vlc_fourcc_t fcc)
         case VLC_CODEC_AV1:
             cb = &av1_cb;
             break;
+        case VLC_CODEC_A52:
+            cb = &ac3_cb;
+            break;
         default:
             return NULL;
     }
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 4581417799..327397d3f8 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -791,54 +791,6 @@ static bo_t *GetDec3Tag(es_format_t *p_fmt,
     return dec3;
 }
 
-static bo_t *GetDac3Tag(const uint8_t *p_data, size_t i_data)
-{
-    if (!i_data)
-        return NULL;
-
-    bo_t *dac3 = box_new("dac3");
-    if(!dac3)
-        return NULL;
-
-    bs_t s;
-    bs_init(&s, p_data, i_data);
-
-    uint8_t fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
-
-    bs_skip(&s, 16 + 16); // syncword + crc
-
-    fscod = bs_read(&s, 2);
-    frmsizecod = bs_read(&s, 6);
-    bsid = bs_read(&s, 5);
-    bsmod = bs_read(&s, 3);
-    acmod = bs_read(&s, 3);
-    if (acmod == 2)
-        bs_skip(&s, 2); // dsurmod
-    else {
-        if ((acmod & 1) && acmod != 1)
-            bs_skip(&s, 2); // cmixlev
-        if (acmod & 4)
-            bs_skip(&s, 2); // surmixlev
-    }
-
-    lfeon = bs_read1(&s);
-
-    uint8_t mp4_a52_header[3];
-    bs_write_init(&s, mp4_a52_header, sizeof(mp4_a52_header));
-
-    bs_write(&s, 2, fscod);
-    bs_write(&s, 5, bsid);
-    bs_write(&s, 3, bsmod);
-    bs_write(&s, 3, acmod);
-    bs_write(&s, 1, lfeon);
-    bs_write(&s, 5, frmsizecod >> 1); // bit_rate_code
-    bs_write(&s, 5, 0); // reserved
-
-    bo_add_mem(dac3, sizeof(mp4_a52_header), mp4_a52_header);
-
-    return dac3;
-}
-
 static bo_t *GetDamrTag(es_format_t *p_fmt)
 {
     bo_t *damr = box_new("damr");
@@ -1270,8 +1222,8 @@ static bo_t *GetSounBox(vlc_object_t *p_obj, 
mp4mux_trackinfo_t *p_track, bool b
             box = GetWaveTag(p_track);
         else if (codec == VLC_CODEC_AMR_NB)
             box = GetDamrTag(&p_track->fmt);
-        else if (codec == VLC_CODEC_A52)
-            box = GetDac3Tag(p_extradata, i_extradata);
+        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_WMAP)
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index 8413a393bf..6b4eed5eed 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -632,7 +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_A52:
         case VLC_CODEC_EAC3:
             if(!mp4mux_track_HasSamplePriv(p_stream->tinfo) &&
                p_block->i_buffer >= 8)

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to