Skip to content

Commit

Permalink
flvmux: only write full metadata at start
Browse files Browse the repository at this point in the history
... rather than having (potentially) unnecessary duplicates written all over,
or even contradictory varying filesize info, or duration info that will not
be rewritten upon header rewrite.
  • Loading branch information
Mark Nauwelaerts committed Dec 19, 2011
1 parent 8c32195 commit fa5c02b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions gst/flv/gstflvmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ gst_flv_mux_create_number_script_value (const gchar * name, gdouble value)
}

static GstBuffer *
gst_flv_mux_create_metadata (GstFlvMux * mux)
gst_flv_mux_create_metadata (GstFlvMux * mux, gboolean full)
{
const GstTagList *tags;
GstBuffer *script_tag, *tmp;
Expand Down Expand Up @@ -687,6 +687,9 @@ gst_flv_mux_create_metadata (GstFlvMux * mux)
GST_WRITE_UINT32_BE (data + 1, n_tags);
script_tag = gst_buffer_join (script_tag, tmp);

if (!full)
goto tags;

/* Some players expect the 'duration' to be always set. Fill it out later,
after querying the pads or after getting EOS */
if (!mux->streamable) {
Expand All @@ -707,6 +710,7 @@ gst_flv_mux_create_metadata (GstFlvMux * mux)
GST_DEBUG_OBJECT (mux, "not preallocating index, streamable mode");
}

tags:
for (i = 0; tags && i < n_tags; i++) {
const gchar *tag_name =
gst_structure_nth_field_name ((const GstStructure *) tags, i);
Expand Down Expand Up @@ -745,6 +749,9 @@ gst_flv_mux_create_metadata (GstFlvMux * mux)
}
}

if (!full)
goto end;

if (mux->duration == GST_CLOCK_TIME_NONE) {
GSList *l;

Expand Down Expand Up @@ -926,6 +933,13 @@ gst_flv_mux_create_metadata (GstFlvMux * mux)
tags_written++;
}

end:

if (!tags_written) {
gst_buffer_unref (script_tag);
goto exit;
}

tmp = gst_buffer_new_and_alloc (2 + 0 + 1);
data = GST_BUFFER_DATA (tmp);
data[0] = 0; /* 0 byte size */
Expand All @@ -946,6 +960,7 @@ gst_flv_mux_create_metadata (GstFlvMux * mux)

GST_WRITE_UINT32_BE (data + 11 + 13 + 1, tags_written);

exit:
return script_tag;
}

Expand Down Expand Up @@ -1089,7 +1104,7 @@ gst_flv_mux_write_header (GstFlvMux * mux)
GstFlowReturn ret;

header = gst_flv_mux_create_header (mux);
metadata = gst_flv_mux_create_metadata (mux);
metadata = gst_flv_mux_create_metadata (mux, TRUE);
video_codec_data = NULL;
audio_codec_data = NULL;

Expand Down Expand Up @@ -1407,8 +1422,9 @@ gst_flv_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * cdata,
}

if (mux->new_tags) {
GstBuffer *buf = gst_flv_mux_create_metadata (mux);
gst_flv_mux_push (mux, buf);
GstBuffer *buf = gst_flv_mux_create_metadata (mux, FALSE);
if (buf)
gst_flv_mux_push (mux, buf);
mux->new_tags = FALSE;
}

Expand Down

0 comments on commit fa5c02b

Please sign in to comment.