summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Zapata <jorgeluis.zapata@gmail.com>2013-05-17 16:29:09 +0200
committerJosep Torra <n770galaxy@gmail.com>2013-05-21 18:22:59 +0200
commit8176858690204c7017dfa007a3c6054f54bf84ae (patch)
treeab7e9bd6a144e5576d231167e70324bd75581187
parent2720105682681ef652ee42c1e5a59e20d8146f3d (diff)
qtdemux: Whenever a moov atom is found, reset the demuxer
Introduce the function gst_qtdemux_reset to initialize demuxer state and use it to reset it when a new moov atom is found.
-rw-r--r--gst/isomp4/qtdemux.c104
1 files changed, 53 insertions, 51 deletions
diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c
index ea94cb25b..fbf944a95 100644
--- a/gst/isomp4/qtdemux.c
+++ b/gst/isomp4/qtdemux.c
@@ -1817,6 +1817,36 @@ gst_qtdemux_stream_free (GstQTDemux * qtdemux, QtDemuxStream * stream)
g_free (stream);
}
+static void
+gst_qtdemux_reset (GstQTDemux * qtdemux)
+{
+ gint n;
+
+ qtdemux->mdatoffset = GST_CLOCK_TIME_NONE;
+ if (qtdemux->mdatbuffer)
+ gst_buffer_unref (qtdemux->mdatbuffer);
+ qtdemux->mdatbuffer = NULL;
+ if (qtdemux->tag_list)
+ gst_tag_list_free (qtdemux->tag_list);
+ qtdemux->tag_list = NULL;
+ if (qtdemux->element_index)
+ gst_object_unref (qtdemux->element_index);
+ qtdemux->element_index = NULL;
+ for (n = 0; n < qtdemux->n_streams; n++) {
+ gst_qtdemux_stream_free (qtdemux, qtdemux->streams[n]);
+ qtdemux->streams[n] = NULL;
+ }
+ qtdemux->n_streams = 0;
+ qtdemux->n_video_streams = 0;
+ qtdemux->n_audio_streams = 0;
+ qtdemux->n_sub_streams = 0;
+ gst_segment_init (&qtdemux->segment, GST_FORMAT_TIME);
+ qtdemux->requested_seek_time = GST_CLOCK_TIME_NONE;
+ qtdemux->seek_offset = 0;
+ qtdemux->upstream_seekable = FALSE;
+ qtdemux->upstream_size = 0;
+}
+
static GstStateChangeReturn
gst_qtdemux_change_state (GstElement * element, GstStateChange transition)
{
@@ -1833,9 +1863,7 @@ gst_qtdemux_change_state (GstElement * element, GstStateChange transition)
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:{
- gint n;
-
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
qtdemux->state = QTDEMUX_STATE_INITIAL;
qtdemux->neededbytes = 16;
qtdemux->todrop = 0;
@@ -1845,36 +1873,13 @@ gst_qtdemux_change_state (GstElement * element, GstStateChange transition)
qtdemux->first_mdat = -1;
qtdemux->header_size = 0;
qtdemux->got_moov = FALSE;
- qtdemux->mdatoffset = GST_CLOCK_TIME_NONE;
- if (qtdemux->mdatbuffer)
- gst_buffer_unref (qtdemux->mdatbuffer);
- qtdemux->mdatbuffer = NULL;
+ gst_adapter_clear (qtdemux->adapter);
+ gst_qtdemux_reset (qtdemux);
+ qtdemux->major_brand = 0;
if (qtdemux->comp_brands)
gst_buffer_unref (qtdemux->comp_brands);
qtdemux->comp_brands = NULL;
- if (qtdemux->tag_list)
- gst_tag_list_free (qtdemux->tag_list);
- qtdemux->tag_list = NULL;
- if (qtdemux->element_index)
- gst_object_unref (qtdemux->element_index);
- qtdemux->element_index = NULL;
- gst_adapter_clear (qtdemux->adapter);
- for (n = 0; n < qtdemux->n_streams; n++) {
- gst_qtdemux_stream_free (qtdemux, qtdemux->streams[n]);
- qtdemux->streams[n] = NULL;
- }
- qtdemux->major_brand = 0;
- qtdemux->n_streams = 0;
- qtdemux->n_video_streams = 0;
- qtdemux->n_audio_streams = 0;
- qtdemux->n_sub_streams = 0;
- gst_segment_init (&qtdemux->segment, GST_FORMAT_TIME);
- qtdemux->requested_seek_time = GST_CLOCK_TIME_NONE;
- qtdemux->seek_offset = 0;
- qtdemux->upstream_seekable = FALSE;
- qtdemux->upstream_size = 0;
break;
- }
default:
break;
}
@@ -4224,32 +4229,29 @@ gst_qtdemux_chain (GstPad * sinkpad, GstBuffer * inbuf)
extract_initial_length_and_fourcc (data, demux->neededbytes, NULL,
&fourcc);
if (fourcc == FOURCC_moov) {
- /* in usual fragmented setup we could try to scan for more
- * and end up at the the moov (after mdat) again */
- if (demux->got_moov && demux->n_streams > 0) {
- GST_DEBUG_OBJECT (demux,
- "Skipping moov atom as we have one already");
- } else {
- GST_DEBUG_OBJECT (demux, "Parsing [moov]");
-
- demux->got_moov = TRUE;
+ GST_DEBUG_OBJECT (demux, "Parsing [moov]");
- /* prepare newsegment to send when streaming actually starts */
- if (!demux->pending_newsegment) {
- demux->pending_newsegment =
- gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
- 0, GST_CLOCK_TIME_NONE, 0);
- }
+ if (demux->got_moov) {
+ gst_qtdemux_reset (demux);
+ }
- qtdemux_parse_moov (demux, data, demux->neededbytes);
- qtdemux_node_dump (demux, demux->moov_node);
- qtdemux_parse_tree (demux);
- qtdemux_expose_streams (demux);
+ demux->got_moov = TRUE;
- g_node_destroy (demux->moov_node);
- demux->moov_node = NULL;
- GST_DEBUG_OBJECT (demux, "Finished parsing the header");
+ /* prepare newsegment to send when streaming actually starts */
+ if (!demux->pending_newsegment) {
+ demux->pending_newsegment =
+ gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
+ 0, GST_CLOCK_TIME_NONE, 0);
}
+
+ qtdemux_parse_moov (demux, data, demux->neededbytes);
+ qtdemux_node_dump (demux, demux->moov_node);
+ qtdemux_parse_tree (demux);
+ qtdemux_expose_streams (demux);
+
+ g_node_destroy (demux->moov_node);
+ demux->moov_node = NULL;
+ GST_DEBUG_OBJECT (demux, "Finished parsing the header");
} else if (fourcc == FOURCC_moof) {
if (demux->got_moov && demux->fragmented) {
GST_DEBUG_OBJECT (demux, "Parsing [moof]");