[vlc-commits] mux: mp4: rewrite brands handling
Francois Cartegnie
git at videolan.org
Mon Oct 29 16:44:10 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Oct 29 16:19:45 2018 +0100| [c22f8badf047b843252b849c0536e54b11c3e591] | committer: Francois Cartegnie
mux: mp4: rewrite brands handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c22f8badf047b843252b849c0536e54b11c3e591
---
.../demux/smooth/playlist/ForgedInitSegment.cpp | 8 +++--
modules/mux/mp4/libmp4mux.c | 35 ++++++++++++++++++----
modules/mux/mp4/libmp4mux.h | 4 ++-
modules/mux/mp4/mp4.c | 30 +++++++++++--------
4 files changed, 56 insertions(+), 21 deletions(-)
diff --git a/modules/demux/smooth/playlist/ForgedInitSegment.cpp b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
index a4fa11e258..13f2b8bbed 100644
--- a/modules/demux/smooth/playlist/ForgedInitSegment.cpp
+++ b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
@@ -297,9 +297,13 @@ block_t * ForgedInitSegment::buildMoovBox()
block_t *moov = box->b;
free(box);
- vlc_fourcc_t extra[] = {MAJOR_isom, VLC_FOURCC('p','i','f','f'), VLC_FOURCC('i','s','o','2'), VLC_FOURCC('s','m','o','o')};
- box = mp4mux_GetFtyp(VLC_FOURCC('i','s','m','l'), 1, extra, ARRAY_SIZE(extra));
+ mp4mux_SetBrand(muxh, VLC_FOURCC('i','s','m','l'), 0x01);
+ mp4mux_AddExtraBrand(muxh, MAJOR_isom);
+ mp4mux_AddExtraBrand(muxh, VLC_FOURCC('p','i','f','f'));
+ mp4mux_AddExtraBrand(muxh, VLC_FOURCC('i','s','o','2'));
+ mp4mux_AddExtraBrand(muxh, VLC_FOURCC('s','m','o','o'));
+ box = mp4mux_GetFtyp(muxh);
if(box)
{
block_ChainAppend(&box->b, moov);
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index d4cc8218c1..0c27563f0f 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -75,6 +75,12 @@ struct mp4mux_handle_t
{
unsigned options;
vlc_array_t tracks;
+ struct
+ {
+ vlc_fourcc_t i_major;
+ uint32_t i_minor;
+ DECL_ARRAY(vlc_fourcc_t) extra;
+ } brands;
};
static bool mp4mux_trackinfo_Init(mp4mux_trackinfo_t *p_stream, unsigned i_id,
@@ -272,6 +278,9 @@ mp4mux_handle_t * mp4mux_New(enum mp4mux_options options)
{
mp4mux_handle_t *h = malloc(sizeof(*h));
vlc_array_init(&h->tracks);
+ ARRAY_INIT(h->brands.extra);
+ h->brands.i_major = 0;
+ h->brands.i_minor = 0;
h->options = options;
return h;
}
@@ -285,6 +294,7 @@ void mp4mux_Delete(mp4mux_handle_t *h)
free(t);
}
vlc_array_clear(&h->tracks);
+ ARRAY_RESET(h->brands.extra);
free(h);
}
@@ -303,6 +313,21 @@ bool mp4mux_Is(mp4mux_handle_t *h, enum mp4mux_options o)
return h->options & o;
}
+void mp4mux_SetBrand(mp4mux_handle_t *h, vlc_fourcc_t i_major, uint32_t i_minor)
+{
+ h->brands.i_major = i_major;
+ h->brands.i_minor = i_minor;
+ mp4mux_AddExtraBrand(h, i_major);
+}
+
+void mp4mux_AddExtraBrand(mp4mux_handle_t *h, vlc_fourcc_t b)
+{
+ for(int i=0; i<h->brands.extra.i_size; i++)
+ if(h->brands.extra.p_elems[i] == b)
+ return;
+ ARRAY_APPEND(h->brands.extra, b);
+}
+
bo_t *box_new(const char *fcc)
{
bo_t *box = malloc(sizeof(*box));
@@ -2132,15 +2157,15 @@ bo_t * mp4mux_GetMoov(mp4mux_handle_t *h, vlc_object_t *p_obj, vlc_tick_t i_dura
return moov;
}
-bo_t *mp4mux_GetFtyp(vlc_fourcc_t major, uint32_t minor, vlc_fourcc_t extra[], size_t i_fourcc)
+bo_t *mp4mux_GetFtyp(const mp4mux_handle_t *h)
{
bo_t *box = box_new("ftyp");
if(box)
{
- bo_add_fourcc(box, &major);
- bo_add_32be (box, minor);
- for(size_t i=0; i<i_fourcc; i++)
- bo_add_fourcc(box, &extra[i]);
+ bo_add_fourcc(box, &h->brands.i_major);
+ bo_add_32be (box, h->brands.i_minor);
+ for(int i=0; i<h->brands.extra.i_size; i++)
+ bo_add_fourcc(box, &h->brands.extra.p_elems[i]);
if(!box->b)
{
free(box);
diff --git a/modules/mux/mp4/libmp4mux.h b/modules/mux/mp4/libmp4mux.h
index 025bc8e8a8..8a58aa560b 100644
--- a/modules/mux/mp4/libmp4mux.h
+++ b/modules/mux/mp4/libmp4mux.h
@@ -38,6 +38,8 @@ mp4mux_handle_t * mp4mux_New(enum mp4mux_options);
void mp4mux_Delete(mp4mux_handle_t *);
void mp4mux_Set64BitExt(mp4mux_handle_t *);
bool mp4mux_Is(mp4mux_handle_t *, enum mp4mux_options);
+void mp4mux_SetBrand(mp4mux_handle_t *, vlc_fourcc_t, uint32_t);
+void mp4mux_AddExtraBrand(mp4mux_handle_t *, vlc_fourcc_t);
mp4mux_trackinfo_t * mp4mux_track_Add(mp4mux_handle_t *, unsigned id,
const es_format_t *fmt, uint32_t timescale);
@@ -79,6 +81,7 @@ const mp4mux_sample_t *mp4mux_track_GetLastSample(const mp4mux_trackinfo_t
unsigned mp4mux_track_GetSampleCount(const mp4mux_trackinfo_t *);
void mp4mux_track_UpdateLastSample(mp4mux_trackinfo_t *, const mp4mux_sample_t *);
+bo_t *mp4mux_GetFtyp(const mp4mux_handle_t *);
bo_t *mp4mux_GetMoov(mp4mux_handle_t *, vlc_object_t *, vlc_tick_t i_movie_duration);
void mp4mux_ShiftSamples(mp4mux_handle_t *, int64_t offset);
@@ -90,5 +93,4 @@ void box_fix (bo_t *box, uint32_t);
void box_gather (bo_t *box, bo_t *box2);
bool mp4mux_CanMux(vlc_object_t *, const es_format_t *, vlc_fourcc_t, bool);
-bo_t *mp4mux_GetFtyp(vlc_fourcc_t, uint32_t, vlc_fourcc_t[], size_t i_fourcc);
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index b64f430881..4f78255da2 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -186,19 +186,10 @@ static int WriteSlowStartHeader(sout_mux_t *p_mux)
sout_mux_sys_t *p_sys = p_mux->p_sys;
bo_t *box;
- if (!mp4mux_Is(p_sys->muxh, QUICKTIME)) {
+ if (!mp4mux_Is(p_sys->muxh, QUICKTIME))
+ {
/* Now add ftyp header */
- if(p_sys->b_3gp)
- {
- vlc_fourcc_t extra[] = {MAJOR_3gp4, MAJOR_avc1};
- box = mp4mux_GetFtyp(MAJOR_3gp6, 0, extra, ARRAY_SIZE(extra));
- }
- else
- {
- vlc_fourcc_t extra[] = {MAJOR_mp41, MAJOR_avc1};
- box = mp4mux_GetFtyp(MAJOR_isom, 0, extra, ARRAY_SIZE(extra));
- }
-
+ box = mp4mux_GetFtyp(p_sys->muxh);
if(!box)
return VLC_ENOMEM;
@@ -265,6 +256,19 @@ static int Open(vlc_object_t *p_this)
p_mux->pf_delstream = DelStream;
p_mux->pf_mux = (options & FRAGMENTED) ? MuxFrag : Mux;
+ if(p_sys->b_3gp)
+ {
+ mp4mux_SetBrand(p_sys->muxh, MAJOR_3gp6, 0x0);
+ mp4mux_AddExtraBrand(p_sys->muxh, MAJOR_3gp4);
+ mp4mux_AddExtraBrand(p_sys->muxh, MAJOR_avc1);
+ }
+ else
+ {
+ mp4mux_SetBrand(p_sys->muxh, MAJOR_isom, 0x0);
+ mp4mux_AddExtraBrand(p_sys->muxh, MAJOR_mp41);
+ mp4mux_AddExtraBrand(p_sys->muxh, MAJOR_avc1);
+ }
+
return VLC_SUCCESS;
}
@@ -1230,7 +1234,7 @@ static void FlushHeader(sout_mux_t *p_mux)
mp4mux_Set64BitExt(p_sys->muxh);
/* Now add ftyp header */
- bo_t *ftyp = mp4mux_GetFtyp(MAJOR_isom, 0, NULL, 0);
+ bo_t *ftyp = mp4mux_GetFtyp(p_sys->muxh);
if(!ftyp)
return;
More information about the vlc-commits
mailing list