Commit 561b5a7a authored by Rafaël Carré's avatar Rafaël Carré

mp4 mux: merge box_fix call into box_gather

parent 24e89b7b
...@@ -689,8 +689,6 @@ static bo_t *GetESDS(mp4_stream_t *p_stream) ...@@ -689,8 +689,6 @@ static bo_t *GetESDS(mp4_stream_t *p_stream)
bo_add_descr(esds, 0x06, 1); bo_add_descr(esds, 0x06, 1);
bo_add_8 (esds, 0x02); // sl_predefined bo_add_8 (esds, 0x02); // sl_predefined
box_fix(esds);
return esds; return esds;
} }
...@@ -703,29 +701,23 @@ static bo_t *GetWaveTag(mp4_stream_t *p_stream) ...@@ -703,29 +701,23 @@ static bo_t *GetWaveTag(mp4_stream_t *p_stream)
box = box_new("frma"); box = box_new("frma");
bo_add_fourcc(box, "mp4a"); bo_add_fourcc(box, "mp4a");
box_fix(box);
box_gather(wave, box); box_gather(wave, box);
box = box_new("mp4a"); box = box_new("mp4a");
bo_add_32be(box, 0); bo_add_32be(box, 0);
box_fix(box);
box_gather(wave, box); box_gather(wave, box);
box = GetESDS(p_stream); box = GetESDS(p_stream);
box_fix(box);
box_gather(wave, box); box_gather(wave, box);
box = box_new("srcq"); box = box_new("srcq");
bo_add_32be(box, 0x40); bo_add_32be(box, 0x40);
box_fix(box);
box_gather(wave, box); box_gather(wave, box);
/* wazza ? */ /* wazza ? */
bo_add_32be(wave, 8); /* new empty box */ bo_add_32be(wave, 8); /* new empty box */
bo_add_32be(wave, 0); /* box label */ bo_add_32be(wave, 0); /* box label */
box_fix(wave);
return wave; return wave;
} }
...@@ -744,8 +736,6 @@ static bo_t *GetDamrTag(mp4_stream_t *p_stream) ...@@ -744,8 +736,6 @@ static bo_t *GetDamrTag(mp4_stream_t *p_stream)
bo_add_16be(damr, 0x83ff); /* Mode set (all modes for AMR_WB) */ bo_add_16be(damr, 0x83ff); /* Mode set (all modes for AMR_WB) */
bo_add_16be(damr, 0x1); /* Mode change period (no restriction) */ bo_add_16be(damr, 0x1); /* Mode change period (no restriction) */
box_fix(damr);
return damr; return damr;
} }
...@@ -759,8 +749,6 @@ static bo_t *GetD263Tag(void) ...@@ -759,8 +749,6 @@ static bo_t *GetD263Tag(void)
bo_add_16be(d263, 0xa); bo_add_16be(d263, 0xa);
bo_add_8(d263, 0); bo_add_8(d263, 0);
box_fix(d263);
return d263; return d263;
} }
...@@ -828,7 +816,6 @@ static bo_t *GetAvcCTag(mp4_stream_t *p_stream) ...@@ -828,7 +816,6 @@ static bo_t *GetAvcCTag(mp4_stream_t *p_stream)
bo_add_16be(avcC, i_pps_size); bo_add_16be(avcC, i_pps_size);
bo_add_mem(avcC, i_pps_size, p_pps); bo_add_mem(avcC, i_pps_size, p_pps);
} }
box_fix(avcC);
return avcC; return avcC;
} }
...@@ -859,7 +846,6 @@ static bo_t *GetSVQ3Tag(mp4_stream_t *p_stream) ...@@ -859,7 +846,6 @@ static bo_t *GetSVQ3Tag(mp4_stream_t *p_stream)
bo_add_32be(smi, 0x5); bo_add_32be(smi, 0x5);
bo_add_32be(smi, 0xe2c0211d); bo_add_32be(smi, 0xe2c0211d);
bo_add_8(smi, 0xc0); bo_add_8(smi, 0xc0);
box_fix(smi);
return smi; return smi;
} }
...@@ -881,7 +867,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux) ...@@ -881,7 +867,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux)
bo_add_16be(box, 0); bo_add_16be(box, 0);
bo_add_mem(box, sizeof("QuickTime 6.0 or greater") - 1, bo_add_mem(box, sizeof("QuickTime 6.0 or greater") - 1,
(uint8_t *)"QuickTime 6.0 or greater"); (uint8_t *)"QuickTime 6.0 or greater");
box_fix(box);
box_gather(udta, box); box_gather(udta, box);
break; break;
} }
...@@ -895,7 +880,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux) ...@@ -895,7 +880,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux)
bo_add_16be(box, 0); bo_add_16be(box, 0);
bo_add_mem(box, sizeof(PACKAGE_STRING " stream output") - 1, bo_add_mem(box, sizeof(PACKAGE_STRING " stream output") - 1,
(uint8_t*)PACKAGE_STRING " stream output"); (uint8_t*)PACKAGE_STRING " stream output");
box_fix(box);
box_gather(udta, box); box_gather(udta, box);
} }
#if 0 #if 0
...@@ -911,7 +895,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux) ...@@ -911,7 +895,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux)
bo_add_16be(box, 0); \ bo_add_16be(box, 0); \
bo_add_mem(box, strlen(vlc_meta_Get(p_meta, vlc_meta_##type)), \ bo_add_mem(box, strlen(vlc_meta_Get(p_meta, vlc_meta_##type)), \
(uint8_t*)(vlc_meta_Get(p_meta, vlc_meta_##type))); \ (uint8_t*)(vlc_meta_Get(p_meta, vlc_meta_##type))); \
box_fix(box); \
box_gather(udta, box); \ box_gather(udta, box); \
} } } }
...@@ -925,7 +908,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux) ...@@ -925,7 +908,6 @@ static bo_t *GetUdtaTag(sout_mux_t *p_mux)
#undef ADD_META_BOX #undef ADD_META_BOX
} }
#endif #endif
box_fix(udta);
return udta; return udta;
} }
...@@ -987,12 +969,9 @@ static bo_t *GetSounBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -987,12 +969,9 @@ static bo_t *GetSounBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
box = GetDamrTag(p_stream); box = GetDamrTag(p_stream);
else else
box = GetESDS(p_stream); box = GetESDS(p_stream);
box_fix(box);
box_gather(soun, box); box_gather(soun, box);
} }
box_fix(soun);
return soun; return soun;
} }
...@@ -1047,30 +1026,15 @@ static bo_t *GetVideBox(mp4_stream_t *p_stream) ...@@ -1047,30 +1026,15 @@ static bo_t *GetVideBox(mp4_stream_t *p_stream)
{ {
case VLC_CODEC_MP4V: case VLC_CODEC_MP4V:
case VLC_CODEC_MPGV: case VLC_CODEC_MPGV:
{ box_gather(vide, GetESDS(p_stream));
bo_t *esds = GetESDS(p_stream);
box_fix(esds);
box_gather(vide, esds);
}
break; break;
case VLC_CODEC_H263: case VLC_CODEC_H263:
{ box_gather(vide, GetD263Tag());
bo_t *d263 = GetD263Tag();
box_fix(d263);
box_gather(vide, d263);
}
break; break;
case VLC_CODEC_SVQ3: case VLC_CODEC_SVQ3:
{ box_gather(vide, GetSVQ3Tag(p_stream));
bo_t *esds = GetSVQ3Tag(p_stream);
box_fix(esds);
box_gather(vide, esds);
}
break; break;
case VLC_CODEC_H264: case VLC_CODEC_H264:
...@@ -1078,8 +1042,6 @@ static bo_t *GetVideBox(mp4_stream_t *p_stream) ...@@ -1078,8 +1042,6 @@ static bo_t *GetVideBox(mp4_stream_t *p_stream)
break; break;
} }
box_fix(vide);
return vide; return vide;
} }
...@@ -1108,8 +1070,6 @@ static bo_t *GetTextBox(void) ...@@ -1108,8 +1070,6 @@ static bo_t *GetTextBox(void)
bo_add_8 (text, 9); bo_add_8 (text, 9);
bo_add_mem(text, 9, (uint8_t*)"Helvetica"); bo_add_mem(text, 9, (uint8_t*)"Helvetica");
box_fix(text);
return text; return text;
} }
...@@ -1129,7 +1089,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1129,7 +1089,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
box_gather(stsd, GetVideBox(p_stream)); box_gather(stsd, GetVideBox(p_stream));
else if (p_stream->fmt.i_cat == SPU_ES) else if (p_stream->fmt.i_cat == SPU_ES)
box_gather(stsd, GetTextBox()); box_gather(stsd, GetTextBox());
box_fix(stsd);
/* chunk offset table */ /* chunk offset table */
if (p_sys->i_pos >= (((uint64_t)0x1) << 32)) { if (p_sys->i_pos >= (((uint64_t)0x1) << 32)) {
...@@ -1178,11 +1137,9 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1178,11 +1137,9 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
/* Fix stco entry count */ /* Fix stco entry count */
bo_fix_32be(stco, 12, i_chunk); bo_fix_32be(stco, 12, i_chunk);
msg_Dbg(p_mux, "created %d chunks (stco)", i_chunk); msg_Dbg(p_mux, "created %d chunks (stco)", i_chunk);
box_fix(stco);
/* Fix stsc entry count */ /* Fix stsc entry count */
bo_fix_32be(stsc, 12, i_stsc_entries ); bo_fix_32be(stsc, 12, i_stsc_entries );
box_fix(stsc);
/* add stts */ /* add stts */
stts = box_full_new("stts", 0, 0); stts = box_full_new("stts", 0, 0);
...@@ -1221,7 +1178,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1221,7 +1178,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
bo_add_32be(stts, i_delta); // sample-delta bo_add_32be(stts, i_delta); // sample-delta
} }
bo_fix_32be(stts, 12, i_index); bo_fix_32be(stts, 12, i_index);
box_fix(stts);
/* FIXME add ctts ?? FIXME */ /* FIXME add ctts ?? FIXME */
...@@ -1230,7 +1186,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1230,7 +1186,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
bo_add_32be(stsz, p_stream->i_entry_count); // sample-count bo_add_32be(stsz, p_stream->i_entry_count); // sample-count
for (unsigned i = 0; i < p_stream->i_entry_count; i++) for (unsigned i = 0; i < p_stream->i_entry_count; i++)
bo_add_32be(stsz, p_stream->entry[i].i_size); // sample-size bo_add_32be(stsz, p_stream->entry[i].i_size); // sample-size
box_fix(stsz);
/* create stss table */ /* create stss table */
stss = NULL; stss = NULL;
...@@ -1245,10 +1200,8 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1245,10 +1200,8 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
i_index++; i_index++;
} }
if (stss) { if (stss)
bo_fix_32be(stss, 12, i_index); bo_fix_32be(stss, 12, i_index);
box_fix(stss);
}
/* Now gather all boxes into stbl */ /* Now gather all boxes into stbl */
box_gather(stbl, stsd); box_gather(stbl, stsd);
...@@ -1260,9 +1213,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream) ...@@ -1260,9 +1213,6 @@ static bo_t *GetStblBox(sout_mux_t *p_mux, mp4_stream_t *p_stream)
p_stream->i_stco_pos = stbl->len + 16; p_stream->i_stco_pos = stbl->len + 16;
box_gather(stbl, stco); box_gather(stbl, stco);
/* finish stbl */
box_fix(stbl);
return stbl; return stbl;
} }
...@@ -1320,7 +1270,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1320,7 +1270,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
/* Next available track id */ /* Next available track id */
bo_add_32be(mvhd, p_sys->i_nb_streams + 1); // next-track-id bo_add_32be(mvhd, p_sys->i_nb_streams + 1); // next-track-id
box_fix(mvhd);
box_gather(moov, mvhd); box_gather(moov, mvhd);
for (int i_trak = 0; i_trak < p_sys->i_nb_streams; i_trak++) { for (int i_trak = 0; i_trak < p_sys->i_nb_streams; i_trak++) {
...@@ -1409,7 +1358,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1409,7 +1358,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
bo_add_32be(tkhd, i_height << 16); // height(presentation) bo_add_32be(tkhd, i_height << 16); // height(presentation)
} }
box_fix(tkhd);
box_gather(trak, tkhd); box_gather(trak, tkhd);
/* *** add /moov/trak/edts and elst */ /* *** add /moov/trak/edts and elst */
...@@ -1444,9 +1392,7 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1444,9 +1392,7 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
bo_add_16be(elst, 1); bo_add_16be(elst, 1);
bo_add_16be(elst, 0); bo_add_16be(elst, 0);
box_fix(elst);
box_gather(edts, elst); box_gather(edts, elst);
box_fix(edts);
box_gather(trak, edts); box_gather(trak, edts);
/* *** add /moov/trak/mdia *** */ /* *** add /moov/trak/mdia *** */
...@@ -1491,7 +1437,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1491,7 +1437,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
} else } else
bo_add_16be(mdhd, 0 ); // language bo_add_16be(mdhd, 0 ); // language
bo_add_16be(mdhd, 0 ); // predefined bo_add_16be(mdhd, 0 ); // predefined
box_fix(mdhd);
box_gather(mdia, mdhd); box_gather(mdia, mdhd);
/* handler reference */ /* handler reference */
...@@ -1526,7 +1471,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1526,7 +1471,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
if (!p_sys->b_mov) if (!p_sys->b_mov)
bo_add_8(hdlr, 0); /* asciiz string for .mp4, yes that's BRAIN DAMAGED F**K MP4 */ bo_add_8(hdlr, 0); /* asciiz string for .mp4, yes that's BRAIN DAMAGED F**K MP4 */
box_fix(hdlr);
box_gather(mdia, hdlr); box_gather(mdia, hdlr);
/* minf*/ /* minf*/
...@@ -1539,7 +1483,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1539,7 +1483,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
smhd = box_full_new("smhd", 0, 0); smhd = box_full_new("smhd", 0, 0);
bo_add_16be(smhd, 0); // balance bo_add_16be(smhd, 0); // balance
bo_add_16be(smhd, 0); // reserved bo_add_16be(smhd, 0); // reserved
box_fix(smhd);
box_gather(minf, smhd); box_gather(minf, smhd);
} else if (p_stream->fmt.i_cat == VIDEO_ES) { } else if (p_stream->fmt.i_cat == VIDEO_ES) {
...@@ -1549,7 +1492,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1549,7 +1492,6 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
bo_add_16be(vmhd, 0); // graphicsmode bo_add_16be(vmhd, 0); // graphicsmode
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
bo_add_16be(vmhd, 0); // opcolor bo_add_16be(vmhd, 0); // opcolor
box_fix(vmhd);
box_gather(minf, vmhd); box_gather(minf, vmhd);
} else if (p_stream->fmt.i_cat == SPU_ES) { } else if (p_stream->fmt.i_cat == SPU_ES) {
...@@ -1561,10 +1503,8 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1561,10 +1503,8 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
bo_add_16be(gmin, 0); // opcolor bo_add_16be(gmin, 0); // opcolor
bo_add_16be(gmin, 0); // balance bo_add_16be(gmin, 0); // balance
bo_add_16be(gmin, 0); // reserved bo_add_16be(gmin, 0); // reserved
box_fix(gmin);
box_gather(gmhd, gmin); box_gather(gmhd, gmin);
box_fix(gmhd);
box_gather(minf, gmhd); box_gather(minf, gmhd);
} }
...@@ -1574,13 +1514,10 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1574,13 +1514,10 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
bo_t *dref = box_full_new("dref", 0, 0); bo_t *dref = box_full_new("dref", 0, 0);
bo_add_32be(dref, 1); bo_add_32be(dref, 1);
bo_t *url = box_full_new("url ", 0, 0x01); bo_t *url = box_full_new("url ", 0, 0x01);
box_fix(url);
box_gather(dref, url); box_gather(dref, url);
box_fix(dref);
box_gather(dinf, dref); box_gather(dinf, dref);
/* append dinf to mdia */ /* append dinf to mdia */
box_fix(dinf);
box_gather(minf, dinf); box_gather(minf, dinf);
/* add stbl */ /* add stbl */
...@@ -1591,17 +1528,14 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux) ...@@ -1591,17 +1528,14 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
box_gather(minf, stbl); box_gather(minf, stbl);
/* append minf to mdia */ /* append minf to mdia */
box_fix(minf);
p_stream->i_stco_pos += mdia->len; p_stream->i_stco_pos += mdia->len;
box_gather(mdia, minf); box_gather(mdia, minf);
/* append mdia to trak */ /* append mdia to trak */
box_fix(mdia);
p_stream->i_stco_pos += trak->len; p_stream->i_stco_pos += trak->len;
box_gather(trak, mdia); box_gather(trak, mdia);
/* append trak to moov */ /* append trak to moov */
box_fix(trak);
p_stream->i_stco_pos += moov->len; p_stream->i_stco_pos += moov->len;
box_gather(moov, trak); box_gather(moov, trak);
} }
...@@ -1719,6 +1653,7 @@ static void box_fix(bo_t *box) ...@@ -1719,6 +1653,7 @@ static void box_fix(bo_t *box)
static void box_gather (bo_t *box, bo_t *box2) static void box_gather (bo_t *box, bo_t *box2)
{ {
box_fix(box2);
box->b = block_Realloc(box->b, 0, box->len + box2->len); box->b = block_Realloc(box->b, 0, box->len + box2->len);
memcpy(&box->b->p_buffer[box->len], box2->b->p_buffer, box2->len); memcpy(&box->b->p_buffer[box->len], box2->b->p_buffer, box2->len);
box->len += box2->len; box->len += box2->len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment