int id;
GstPad *pad;
- GstFlowReturn last_flow;
gboolean discont;
int timescale;
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_rmdemux_sink_template));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_rmdemux_videosrc_template));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_rmdemux_audiosrc_template));
+ gst_element_class_add_static_pad_template (element_class,
+ &gst_rmdemux_sink_template);
+ gst_element_class_add_static_pad_template (element_class,
+ &gst_rmdemux_videosrc_template);
+ gst_element_class_add_static_pad_template (element_class,
+ &gst_rmdemux_audiosrc_template);
gst_element_class_set_static_metadata (element_class, "RealMedia Demuxer",
"Codec/Demuxer",
"Demultiplex a RealMedia file into audio and video streams",
g_object_unref (rmdemux->adapter);
rmdemux->adapter = NULL;
}
+ if (rmdemux->flowcombiner) {
+ gst_flow_combiner_free (rmdemux->flowcombiner);
+ rmdemux->flowcombiner = NULL;
+ }
GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}
rmdemux->first_ts = GST_CLOCK_TIME_NONE;
rmdemux->base_ts = GST_CLOCK_TIME_NONE;
rmdemux->need_newsegment = TRUE;
+ rmdemux->have_group_id = FALSE;
+ rmdemux->group_id = G_MAXUINT;
+ rmdemux->flowcombiner = gst_flow_combiner_new ();
gst_rm_utils_run_tests ();
}
GST_LOG_OBJECT (rmdemux, "Took streamlock");
if (event) {
- gst_segment_do_seek (&rmdemux->segment, rate, format, flags,
- cur_type, cur, stop_type, stop, &update);
+ if (!gst_segment_do_seek (&rmdemux->segment, rate, format, flags,
+ cur_type, cur, stop_type, stop, &update)) {
+ ret = FALSE;
+ goto done;
+ }
}
GST_DEBUG_OBJECT (rmdemux, "segment positions set to %" GST_TIME_FORMAT "-%"
}
break;
}
+ case GST_QUERY_SEGMENT:
+ {
+ GstFormat format;
+ gint64 start, stop;
+
+ format = rmdemux->segment.format;
+
+ start =
+ gst_segment_to_stream_time (&rmdemux->segment, format,
+ rmdemux->segment.start);
+ if ((stop = rmdemux->segment.stop) == -1)
+ stop = rmdemux->segment.duration;
+ else
+ stop = gst_segment_to_stream_time (&rmdemux->segment, format, stop);
+
+ gst_query_set_segment (query, rmdemux->segment.rate, format, start, stop);
+ res = TRUE;
+ break;
+ }
default:
res = gst_pad_query_default (pad, parent, query);
break;
}
static void
+gst_rmdemux_free_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
+{
+ g_object_unref (stream->adapter);
+ gst_rmdemux_stream_clear_cached_subpackets (rmdemux, stream);
+ if (stream->pending_tags)
+ gst_tag_list_unref (stream->pending_tags);
+ if (stream->subpackets)
+ g_ptr_array_free (stream->subpackets, TRUE);
+ g_free (stream->index);
+ g_free (stream);
+}
+
+static void
gst_rmdemux_reset (GstRMDemux * rmdemux)
{
GSList *cur;
for (cur = rmdemux->streams; cur; cur = cur->next) {
GstRMDemuxStream *stream = cur->data;
- g_object_unref (stream->adapter);
- gst_rmdemux_stream_clear_cached_subpackets (rmdemux, stream);
+ gst_flow_combiner_remove_pad (rmdemux->flowcombiner, stream->pad);
gst_element_remove_pad (GST_ELEMENT (rmdemux), stream->pad);
- if (stream->pending_tags)
- gst_tag_list_unref (stream->pending_tags);
- if (stream->subpackets)
- g_ptr_array_free (stream->subpackets, TRUE);
- g_free (stream->index);
- g_free (stream);
+ gst_rmdemux_free_stream (rmdemux, stream);
}
g_slist_free (rmdemux->streams);
rmdemux->streams = NULL;
rmdemux->first_ts = GST_CLOCK_TIME_NONE;
rmdemux->base_ts = GST_CLOCK_TIME_NONE;
rmdemux->need_newsegment = TRUE;
+
+ rmdemux->have_group_id = FALSE;
+ rmdemux->group_id = G_MAXUINT;
}
static GstStateChangeReturn
switch (mode) {
case GST_PAD_MODE_PUSH:
demux->seekable = FALSE;
+ demux->running = active;
res = TRUE;
break;
case GST_PAD_MODE_PULL:
gst_rmdemux_send_event (rmdemux, gst_event_new_eos ());
}
} else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
- GST_ELEMENT_ERROR (rmdemux, STREAM, FAILED,
- (NULL), ("stream stopped, reason %s", reason));
+ GST_ELEMENT_FLOW_ERROR (rmdemux, ret);
gst_rmdemux_send_event (rmdemux, gst_event_new_eos ());
}
return;
stream->next_ts = -1;
stream->last_seq = -1;
stream->next_seq = -1;
- stream->last_flow = GST_FLOW_OK;
break;
default:
break;
if (stream->flavor > 3) {
GST_WARNING_OBJECT (rmdemux, "bad SIPR flavor %d, freeing it",
stream->flavor);
- g_free (stream);
+ g_object_unref (stream->pad);
+ gst_rmdemux_free_stream (rmdemux, stream);
goto beach;
}
} else {
GST_WARNING_OBJECT (rmdemux, "not adding stream of type %d, freeing it",
stream->subtype);
- g_free (stream);
+ gst_rmdemux_free_stream (rmdemux, stream);
goto beach;
}
stream_caps);
if (stream->pad && stream_caps) {
+ GstEvent *event;
GST_LOG_OBJECT (rmdemux, "%d bytes of extra data for stream %s",
stream->extra_data_size, GST_PAD_NAME (stream->pad));
stream_id =
gst_pad_create_stream_id_printf (stream->pad,
GST_ELEMENT_CAST (rmdemux), "%03u", stream->id);
- gst_pad_push_event (stream->pad, gst_event_new_stream_start (stream_id));
+
+ event =
+ gst_pad_get_sticky_event (rmdemux->sinkpad, GST_EVENT_STREAM_START, 0);
+ if (event) {
+ if (gst_event_parse_group_id (event, &rmdemux->group_id))
+ rmdemux->have_group_id = TRUE;
+ else
+ rmdemux->have_group_id = FALSE;
+ gst_event_unref (event);
+ } else if (!rmdemux->have_group_id) {
+ rmdemux->have_group_id = TRUE;
+ rmdemux->group_id = gst_util_group_id_next ();
+ }
+
+ event = gst_event_new_stream_start (stream_id);
+ if (rmdemux->have_group_id)
+ gst_event_set_group_id (event, rmdemux->group_id);
+
+ gst_pad_push_event (stream->pad, event);
g_free (stream_id);
gst_pad_set_caps (stream->pad, stream_caps);
g_free (codec_name);
}
gst_element_add_pad (GST_ELEMENT_CAST (rmdemux), stream->pad);
+ gst_flow_combiner_add_pad (rmdemux->flowcombiner, stream->pad);
}
beach:
stream->seek_offset = 0;
stream->last_ts = -1;
stream->next_ts = -1;
- stream->last_flow = GST_FLOW_OK;
stream->discont = TRUE;
stream->adapter = gst_adapter_new ();
GST_LOG_OBJECT (rmdemux, "stream_number=%d", stream->id);
tags = gst_rm_utils_read_tags (data, length, gst_rm_utils_read_string16);
- GST_LOG_OBJECT (rmdemux, "tags: %" GST_PTR_FORMAT, tags);
-
- rmdemux->pending_tags =
- gst_tag_list_merge (rmdemux->pending_tags, tags, GST_TAG_MERGE_APPEND);
-}
+ if (tags) {
+ GstTagList *old_tags = rmdemux->pending_tags;
-static GstFlowReturn
-gst_rmdemux_combine_flows (GstRMDemux * rmdemux, GstRMDemuxStream * stream,
- GstFlowReturn ret)
-{
- GSList *cur;
+ GST_LOG_OBJECT (rmdemux, "tags: %" GST_PTR_FORMAT, tags);
- /* store the value */
- stream->last_flow = ret;
+ rmdemux->pending_tags =
+ gst_tag_list_merge (old_tags, tags, GST_TAG_MERGE_APPEND);
- /* if it's success we can return the value right away */
- if (ret == GST_FLOW_OK)
- goto done;
+ gst_tag_list_unref (tags);
+ if (old_tags)
+ gst_tag_list_unref (old_tags);
- /* any other error that is not-linked can be returned right
- * away */
- if (ret != GST_FLOW_NOT_LINKED)
- goto done;
-
- for (cur = rmdemux->streams; cur; cur = cur->next) {
- GstRMDemuxStream *ostream = cur->data;
-
- ret = ostream->last_flow;
- /* some other return value (must be SUCCESS but we can return
- * other values as well) */
- if (ret != GST_FLOW_NOT_LINKED)
- goto done;
+ gst_tag_list_set_scope (rmdemux->pending_tags, GST_TAG_SCOPE_GLOBAL);
}
- /* if we get here, all other pads were unlinked and we return
- * NOT_LINKED then */
-done:
- return ret;
}
static void
gst_buffer_map (in, &map, GST_MAP_READ);
+ if (map.size < offset)
+ goto not_enough_data;
+
data = map.data + offset;
size = map.size - offset;
/* if size <= 2, we want this method to return the same GstFlowReturn as it
* was previously for that given stream. */
- ret = stream->last_flow;
+ ret = GST_PAD_LAST_FLOW_RETURN (stream->pad);
while (size > 2) {
guint8 pkg_header;
}
GST_DEBUG_OBJECT (rmdemux, "fragment size %d", fragment_size);
+ if (map.size < (data - map.data) + fragment_size)
+ goto not_enough_data;
+
/* get the fragment */
fragment =
gst_buffer_copy_region (in, GST_BUFFER_COPY_ALL, data - map.data,
}
ret = gst_pad_push (stream->pad, out);
- ret = gst_rmdemux_combine_flows (rmdemux, stream, ret);
+ ret = gst_flow_combiner_update_flow (rmdemux->flowcombiner, ret);
if (ret != GST_FLOW_OK)
break;
GstFlowReturn ret;
GstBuffer *buffer;
+ if (gst_buffer_get_size (in) < offset)
+ goto not_enough_data;
+
buffer = gst_buffer_copy_region (in, GST_BUFFER_COPY_MEMORY, offset, -1);
if (rmdemux->first_ts != -1 && timestamp > rmdemux->first_ts)
ret = gst_pad_push (stream->pad, buffer);
}
+done:
gst_buffer_unref (in);
return ret;
+
+ /* ERRORS */
+not_enough_data:
+ {
+ GST_ELEMENT_WARNING (rmdemux, STREAM, DECODE, ("Skipping bad packet."),
+ (NULL));
+ ret = GST_FLOW_OK;
+ goto done;
+ }
}
static GstFlowReturn
data = map.data;
size = map.size;
+ if (size < 4 + 6 + 1 + 2)
+ goto not_enough_data;
+
/* stream number */
id = RMDEMUX_GUINT16_GET (data);
/* version 1 has an extra byte */
if (version == 1) {
+ if (size < 1)
+ goto not_enough_data;
+
data += 1;
size -= 1;
}
ret = GST_FLOW_OK;
}
- cret = gst_rmdemux_combine_flows (rmdemux, stream, ret);
+ cret = gst_flow_combiner_update_pad_flow (rmdemux->flowcombiner, stream->pad,
+ ret);
beach:
return cret;
gst_buffer_unref (in);
return GST_FLOW_OK;
}
+
+ /* ERRORS */
+not_enough_data:
+ {
+ GST_ELEMENT_WARNING (rmdemux, STREAM, DECODE, ("Skipping bad packet."),
+ (NULL));
+ gst_buffer_unmap (in, &map);
+ gst_buffer_unref (in);
+ return GST_FLOW_OK;
+ }
}
gboolean