Do not create a SeekHeader, Cues, .. when doing live

This commit is contained in:
Xavier Queralt 2010-05-21 01:59:53 +02:00 committed by Zaheer Abbas Merali
parent 032d9b90ff
commit 40eda471a1

View File

@ -2020,16 +2020,21 @@ gst_matroska_mux_start (GstMatroskaMux * mux)
gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEGMENT); gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEGMENT);
mux->segment_master = ebml->pos; mux->segment_master = ebml->pos;
/* seekhead (table of contents) - we set the positions later */ /* the rest of the header is cached */
mux->seekhead_pos = ebml->pos; gst_ebml_write_set_cache (ebml, 0x1000);
master = gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEEKHEAD);
for (i = 0; seekhead_id[i] != 0; i++) { if (!mux->is_live) {
child = gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEEKENTRY); /* seekhead (table of contents) - we set the positions later */
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_SEEKID, seekhead_id[i]); mux->seekhead_pos = ebml->pos;
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_SEEKPOSITION, -1); master = gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEEKHEAD);
gst_ebml_write_master_finish (ebml, child); for (i = 0; seekhead_id[i] != 0; i++) {
child = gst_ebml_write_master_start (ebml, GST_MATROSKA_ID_SEEKENTRY);
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_SEEKID, seekhead_id[i]);
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_SEEKPOSITION, -1);
gst_ebml_write_master_finish (ebml, child);
}
gst_ebml_write_master_finish (ebml, master);
} }
gst_ebml_write_master_finish (ebml, master);
/* segment info */ /* segment info */
mux->info_pos = ebml->pos; mux->info_pos = ebml->pos;
@ -2182,7 +2187,7 @@ gst_matroska_mux_finish (GstMatroskaMux * mux)
} }
/* cues */ /* cues */
if (mux->index != NULL) { if (mux->index != NULL && !mux->is_live) {
guint n; guint n;
guint64 master, pointentry_master, trackpos_master; guint64 master, pointentry_master, trackpos_master;
@ -2213,7 +2218,7 @@ gst_matroska_mux_finish (GstMatroskaMux * mux)
/* tags */ /* tags */
tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (mux)); tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (mux));
if (tags != NULL && !gst_tag_list_is_empty (tags)) { if (tags != NULL && !gst_tag_list_is_empty (tags) && !mux->is_live) {
guint64 master_tags, master_tag; guint64 master_tags, master_tag;
GST_DEBUG ("Writing tags"); GST_DEBUG ("Writing tags");
@ -2237,81 +2242,84 @@ gst_matroska_mux_finish (GstMatroskaMux * mux)
* length pointer starts at 20. * length pointer starts at 20.
* - all entries are local to the segment (so pos - segment_master). * - all entries are local to the segment (so pos - segment_master).
* - so each entry is at 12 + 20 + num * 28. */ * - so each entry is at 12 + 20 + num * 28. */
gst_ebml_replace_uint (ebml, mux->seekhead_pos + 32, if (!mux->is_live) {
mux->info_pos - mux->segment_master); gst_ebml_replace_uint (ebml, mux->seekhead_pos + 32,
gst_ebml_replace_uint (ebml, mux->seekhead_pos + 60, mux->info_pos - mux->segment_master);
mux->tracks_pos - mux->segment_master); gst_ebml_replace_uint (ebml, mux->seekhead_pos + 60,
if (mux->index != NULL) { mux->tracks_pos - mux->segment_master);
gst_ebml_replace_uint (ebml, mux->seekhead_pos + 88, if (mux->index != NULL) {
mux->cues_pos - mux->segment_master); gst_ebml_replace_uint (ebml, mux->seekhead_pos + 88,
} else { mux->cues_pos - mux->segment_master);
/* void'ify */ } else {
guint64 my_pos = ebml->pos; /* void'ify */
guint64 my_pos = ebml->pos;
gst_ebml_write_seek (ebml, mux->seekhead_pos + 68); gst_ebml_write_seek (ebml, mux->seekhead_pos + 68);
gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 26); gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 26);
gst_ebml_write_seek (ebml, my_pos); gst_ebml_write_seek (ebml, my_pos);
} }
if (tags != NULL) { if (tags != NULL) {
gst_ebml_replace_uint (ebml, mux->seekhead_pos + 116, gst_ebml_replace_uint (ebml, mux->seekhead_pos + 116,
mux->tags_pos - mux->segment_master); mux->tags_pos - mux->segment_master);
} else { } else {
/* void'ify */ /* void'ify */
guint64 my_pos = ebml->pos; guint64 my_pos = ebml->pos;
gst_ebml_write_seek (ebml, mux->seekhead_pos + 96); gst_ebml_write_seek (ebml, mux->seekhead_pos + 96);
gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 26); gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 26);
gst_ebml_write_seek (ebml, my_pos); gst_ebml_write_seek (ebml, my_pos);
}
/* update duration */
/* first get the overall duration */
/* a released track may have left a duration in here */
duration = mux->duration;
for (collected = mux->collect->data; collected;
collected = g_slist_next (collected)) {
GstMatroskaPad *collect_pad;
GstClockTime min_duration; /* observed minimum duration */
collect_pad = (GstMatroskaPad *) collected->data;
GST_DEBUG_OBJECT (mux, "Pad %" GST_PTR_FORMAT " start ts %" GST_TIME_FORMAT
" end ts %" GST_TIME_FORMAT, collect_pad,
GST_TIME_ARGS (collect_pad->start_ts),
GST_TIME_ARGS (collect_pad->end_ts));
if (GST_CLOCK_TIME_IS_VALID (collect_pad->start_ts) &&
GST_CLOCK_TIME_IS_VALID (collect_pad->end_ts)) {
min_duration =
GST_CLOCK_DIFF (collect_pad->start_ts, collect_pad->end_ts);
if (collect_pad->duration < min_duration)
collect_pad->duration = min_duration;
GST_DEBUG_OBJECT (collect_pad, "final track duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (collect_pad->duration));
} }
if (GST_CLOCK_TIME_IS_VALID (collect_pad->duration) && /* update duration */
duration < collect_pad->duration) /* first get the overall duration */
duration = collect_pad->duration; /* a released track may have left a duration in here */
} duration = mux->duration;
if (duration != 0) { for (collected = mux->collect->data; collected;
GST_DEBUG_OBJECT (mux, "final total duration: %" GST_TIME_FORMAT, collected = g_slist_next (collected)) {
GST_TIME_ARGS (duration)); GstMatroskaPad *collect_pad;
pos = mux->ebml_write->pos; GstClockTime min_duration; /* observed minimum duration */
gst_ebml_write_seek (ebml, mux->duration_pos);
gst_ebml_write_float (ebml, GST_MATROSKA_ID_DURATION,
gst_guint64_to_gdouble (duration) /
gst_guint64_to_gdouble (mux->time_scale));
gst_ebml_write_seek (ebml, pos);
} else {
/* void'ify */
guint64 my_pos = ebml->pos;
gst_ebml_write_seek (ebml, mux->duration_pos); collect_pad = (GstMatroskaPad *) collected->data;
gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 8);
gst_ebml_write_seek (ebml, my_pos);
}
GST_DEBUG_OBJECT (mux,
"Pad %" GST_PTR_FORMAT " start ts %" GST_TIME_FORMAT
" end ts %" GST_TIME_FORMAT, collect_pad,
GST_TIME_ARGS (collect_pad->start_ts),
GST_TIME_ARGS (collect_pad->end_ts));
if (GST_CLOCK_TIME_IS_VALID (collect_pad->start_ts) &&
GST_CLOCK_TIME_IS_VALID (collect_pad->end_ts)) {
min_duration =
GST_CLOCK_DIFF (collect_pad->start_ts, collect_pad->end_ts);
if (collect_pad->duration < min_duration)
collect_pad->duration = min_duration;
GST_DEBUG_OBJECT (collect_pad,
"final track duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (collect_pad->duration));
}
if (GST_CLOCK_TIME_IS_VALID (collect_pad->duration) &&
duration < collect_pad->duration)
duration = collect_pad->duration;
}
if (duration != 0) {
GST_DEBUG_OBJECT (mux, "final total duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (duration));
pos = mux->ebml_write->pos;
gst_ebml_write_seek (ebml, mux->duration_pos);
gst_ebml_write_float (ebml, GST_MATROSKA_ID_DURATION,
gst_guint64_to_gdouble (duration) /
gst_guint64_to_gdouble (mux->time_scale));
gst_ebml_write_seek (ebml, pos);
} else {
/* void'ify */
guint64 my_pos = ebml->pos;
gst_ebml_write_seek (ebml, mux->duration_pos);
gst_ebml_write_buffer_header (ebml, GST_EBML_ID_VOID, 8);
gst_ebml_write_seek (ebml, my_pos);
}
}
/* finish segment - this also writes element length */ /* finish segment - this also writes element length */
gst_ebml_write_master_finish (ebml, mux->segment_pos); gst_ebml_write_master_finish (ebml, mux->segment_pos);
} }