qtdemux: improve reset of internal status

Reset different variables on state changes to ready and when
handling a flush-stop. For handling flush stops we should check
if there is an upstream adaptive demuxer driving the pipeline as this
means that qtdemux will get a new moov atom. For 'standard' isomedia
streams this isn't true and qtdemux should keep the previous moov
information around.

Conflicts:
	gst/isomp4/qtdemux.c
This commit is contained in:
Thiago Santos 2013-05-07 10:16:18 -03:00
parent 6c69e59677
commit cca2f555d1

View file

@ -445,6 +445,7 @@ static gboolean qtdemux_parse_samples (GstQTDemux * qtdemux,
static GstFlowReturn qtdemux_expose_streams (GstQTDemux * qtdemux); static GstFlowReturn qtdemux_expose_streams (GstQTDemux * qtdemux);
static void gst_qtdemux_stream_free (GstQTDemux * qtdemux, static void gst_qtdemux_stream_free (GstQTDemux * qtdemux,
QtDemuxStream * stream); QtDemuxStream * stream);
static void gst_qtdemux_stream_clear (QtDemuxStream * stream);
static GstFlowReturn qtdemux_prepare_streams (GstQTDemux * qtdemux); static GstFlowReturn qtdemux_prepare_streams (GstQTDemux * qtdemux);
static void static void
@ -1723,26 +1724,33 @@ gst_qtdemux_setcaps (GstQTDemux * demux, GstCaps * caps)
} }
static void static void
gst_qtdemux_reset (GstQTDemux * qtdemux) gst_qtdemux_reset (GstQTDemux * qtdemux, gboolean hard)
{ {
gint n; gint n;
GST_DEBUG_OBJECT (qtdemux, "Resetting demux");
gst_pad_stop_task (qtdemux->sinkpad);
if (hard || qtdemux->mss_mode) {
qtdemux->state = QTDEMUX_STATE_INITIAL; qtdemux->state = QTDEMUX_STATE_INITIAL;
qtdemux->neededbytes = 16; qtdemux->neededbytes = 16;
qtdemux->todrop = 0; qtdemux->todrop = 0;
qtdemux->pullbased = FALSE; qtdemux->pullbased = FALSE;
qtdemux->posted_redirect = FALSE; qtdemux->posted_redirect = FALSE;
qtdemux->offset = 0;
qtdemux->first_mdat = -1; qtdemux->first_mdat = -1;
qtdemux->header_size = 0; qtdemux->header_size = 0;
qtdemux->got_moov = FALSE;
qtdemux->mdatoffset = GST_CLOCK_TIME_NONE; qtdemux->mdatoffset = GST_CLOCK_TIME_NONE;
if (qtdemux->mdatbuffer) if (qtdemux->mdatbuffer)
gst_buffer_unref (qtdemux->mdatbuffer); gst_buffer_unref (qtdemux->mdatbuffer);
qtdemux->mdatbuffer = NULL; qtdemux->mdatbuffer = NULL;
qtdemux->mdatleft = 0;
if (qtdemux->comp_brands) if (qtdemux->comp_brands)
gst_buffer_unref (qtdemux->comp_brands); gst_buffer_unref (qtdemux->comp_brands);
qtdemux->comp_brands = NULL; qtdemux->comp_brands = NULL;
if (qtdemux->moov_node)
g_node_destroy (qtdemux->moov_node);
qtdemux->moov_node = NULL;
qtdemux->moov_node_compressed = NULL;
if (qtdemux->tag_list) if (qtdemux->tag_list)
gst_mini_object_unref (GST_MINI_OBJECT_CAST (qtdemux->tag_list)); gst_mini_object_unref (GST_MINI_OBJECT_CAST (qtdemux->tag_list));
qtdemux->tag_list = NULL; qtdemux->tag_list = NULL;
@ -1751,26 +1759,52 @@ gst_qtdemux_reset (GstQTDemux * qtdemux)
gst_object_unref (qtdemux->element_index); gst_object_unref (qtdemux->element_index);
qtdemux->element_index = NULL; qtdemux->element_index = NULL;
#endif #endif
}
qtdemux->offset = 0;
gst_adapter_clear (qtdemux->adapter); gst_adapter_clear (qtdemux->adapter);
if (hard) {
for (n = 0; n < qtdemux->n_streams; n++) { for (n = 0; n < qtdemux->n_streams; n++) {
gst_qtdemux_stream_free (qtdemux, qtdemux->streams[n]); gst_qtdemux_stream_free (qtdemux, qtdemux->streams[n]);
qtdemux->streams[n] = NULL; qtdemux->streams[n] = NULL;
} }
qtdemux->major_brand = 0;
qtdemux->n_streams = 0; qtdemux->n_streams = 0;
qtdemux->n_video_streams = 0; qtdemux->n_video_streams = 0;
qtdemux->n_audio_streams = 0; qtdemux->n_audio_streams = 0;
qtdemux->n_sub_streams = 0; qtdemux->n_sub_streams = 0;
qtdemux->exposed = FALSE;
qtdemux->fragmented = FALSE;
qtdemux->mss_mode = FALSE;
gst_caps_replace (&qtdemux->media_caps, NULL);
qtdemux->timescale = 0;
qtdemux->got_moov = FALSE;
} else if (qtdemux->mss_mode) {
for (n = 0; n < qtdemux->n_streams; n++)
gst_qtdemux_stream_clear (qtdemux->streams[n]);
} else {
for (n = 0; n < qtdemux->n_streams; n++) {
qtdemux->streams[n]->last_ret = GST_FLOW_OK;
qtdemux->streams[n]->sent_eos = FALSE;
}
}
if (hard || qtdemux->mss_mode) {
qtdemux->major_brand = 0;
gst_segment_init (&qtdemux->segment, GST_FORMAT_TIME); gst_segment_init (&qtdemux->segment, GST_FORMAT_TIME);
if (qtdemux->pending_newsegment)
gst_object_unref (qtdemux->pending_newsegment);
qtdemux->pending_newsegment = NULL;
qtdemux->upstream_newsegment = TRUE;
qtdemux->requested_seek_time = GST_CLOCK_TIME_NONE; qtdemux->requested_seek_time = GST_CLOCK_TIME_NONE;
qtdemux->seek_offset = 0; qtdemux->seek_offset = 0;
qtdemux->upstream_seekable = FALSE; qtdemux->upstream_seekable = FALSE;
qtdemux->upstream_size = 0; qtdemux->upstream_size = 0;
gst_caps_replace (&qtdemux->media_caps, NULL);
qtdemux->mss_mode = FALSE;
qtdemux->exposed = FALSE;
qtdemux->base_timestamp = GST_CLOCK_TIME_NONE; qtdemux->base_timestamp = GST_CLOCK_TIME_NONE;
qtdemux->duration = 0;
qtdemux->mfra_offset = 0;
qtdemux->moof_offset = 0;
}
} }
static gboolean static gboolean
@ -1885,7 +1919,7 @@ gst_qtdemux_handle_sink_event (GstPad * sinkpad, GstObject * parent,
} }
case GST_EVENT_FLUSH_STOP: case GST_EVENT_FLUSH_STOP:
{ {
gst_qtdemux_reset (demux); gst_qtdemux_reset (demux, FALSE);
break; break;
} }
case GST_EVENT_EOS: case GST_EVENT_EOS:
@ -1983,7 +2017,7 @@ gst_qtdemux_stbl_free (QtDemuxStream * stream)
} }
static void static void
gst_qtdemux_stream_free (GstQTDemux * qtdemux, QtDemuxStream * stream) gst_qtdemux_stream_clear (QtDemuxStream * stream)
{ {
if (stream->allocator) if (stream->allocator)
gst_object_unref (stream->allocator); gst_object_unref (stream->allocator);
@ -1991,17 +2025,36 @@ gst_qtdemux_stream_free (GstQTDemux * qtdemux, QtDemuxStream * stream)
gst_buffer_unref (GST_BUFFER_CAST (stream->buffers->data)); gst_buffer_unref (GST_BUFFER_CAST (stream->buffers->data));
stream->buffers = g_slist_delete_link (stream->buffers, stream->buffers); stream->buffers = g_slist_delete_link (stream->buffers, stream->buffers);
} }
if (stream->pad)
gst_element_remove_pad (GST_ELEMENT_CAST (qtdemux), stream->pad);
g_free (stream->samples); g_free (stream->samples);
if (stream->caps) stream->samples = NULL;
gst_caps_unref (stream->caps);
g_free (stream->segments); g_free (stream->segments);
stream->segments = NULL;
if (stream->pending_tags) if (stream->pending_tags)
gst_tag_list_unref (stream->pending_tags); gst_tag_list_unref (stream->pending_tags);
stream->pending_tags = NULL;
g_free (stream->redirect_uri); g_free (stream->redirect_uri);
stream->redirect_uri = NULL;
/* free stbl sub-atoms */ /* free stbl sub-atoms */
gst_qtdemux_stbl_free (stream); gst_qtdemux_stbl_free (stream);
stream->last_ret = GST_FLOW_OK;
stream->sent_eos = FALSE;
stream->segment_index = -1;
stream->time_position = 0;
stream->sample_index = -1;
stream->stbl_index = -1;
stream->n_samples = 0;
}
static void
gst_qtdemux_stream_free (GstQTDemux * qtdemux, QtDemuxStream * stream)
{
gst_qtdemux_stream_clear (stream);
if (stream->caps)
gst_caps_unref (stream->caps);
stream->caps = NULL;
if (stream->pad)
gst_element_remove_pad (GST_ELEMENT_CAST (qtdemux), stream->pad);
g_free (stream); g_free (stream);
} }
@ -2022,7 +2075,7 @@ gst_qtdemux_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:{ case GST_STATE_CHANGE_PAUSED_TO_READY:{
gst_qtdemux_reset (qtdemux); gst_qtdemux_reset (qtdemux, TRUE);
break; break;
} }
default: default:
@ -4668,9 +4721,7 @@ gst_qtdemux_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * inbuf)
/* initial newsegment sent here after having added pads, /* initial newsegment sent here after having added pads,
* possible others in sink_event */ * possible others in sink_event */
if (G_UNLIKELY (demux->pending_newsegment)) { if (G_UNLIKELY (demux->pending_newsegment)) {
gst_qtdemux_push_event (demux, demux->pending_newsegment); gst_qtdemux_push_pending_newsegment (demux);
demux->pending_newsegment = NULL;
demux->upstream_newsegment = FALSE;
/* clear to send tags on all streams */ /* clear to send tags on all streams */
for (i = 0; i < demux->n_streams; i++) { for (i = 0; i < demux->n_streams; i++) {
gst_qtdemux_push_tags (demux, demux->streams[i]); gst_qtdemux_push_tags (demux, demux->streams[i]);