From a46c9c2a62fee1a7e2f9ab61e9d83d191a98c072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 May 2011 16:56:13 +0200 Subject: [PATCH] event: Make SEGMENT event parsing API more consistent with the others --- gst/gstevent.c | 52 ++++++++++++++-------------- gst/gstevent.h | 5 ++- libs/gst/base/gstbaseparse.c | 2 +- libs/gst/base/gstbasesink.c | 2 +- libs/gst/base/gstbasetransform.c | 2 +- libs/gst/base/gstcollectpads.c | 2 +- plugins/elements/gstfdsink.c | 12 +++---- plugins/elements/gstfilesink.c | 12 +++---- plugins/elements/gstfunnel.c | 2 +- plugins/elements/gstidentity.c | 2 +- plugins/elements/gstinputselector.c | 2 +- plugins/elements/gstmultiqueue.c | 10 +++--- plugins/elements/gstoutputselector.c | 2 +- plugins/elements/gstqueue.c | 2 +- plugins/elements/gstqueue2.c | 2 +- tests/check/gst/gstevent.c | 2 +- tests/check/libs/basesrc.c | 4 +-- win32/common/libgstbase.def | 1 + win32/common/libgstreamer.def | 3 +- 19 files changed, 61 insertions(+), 60 deletions(-) diff --git a/gst/gstevent.c b/gst/gstevent.c index ca066a38ad..bb861d4b7c 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -632,49 +632,49 @@ gst_event_new_segment (GstSegment * segment) } /** - * gst_event_get_segment: - * @event: The event + * gst_event_parse_segment: + * @event: The event to parse + * @segment: (out) (transfer none): a pointer to a #GstSegment * - * Get the segment from @event. The segment remains valid as long as @event remains - * valid. - * - * Returns: the #GstSegment. The segment stays valid for as long as @event is - * valid. + * Parses a segment @event and stores the result in the given @segment location. + * @segment remains valid only until the @event is freed. Don't modify the segment + * and make a copy if you want to modify it or store it for later use. */ -const GstSegment * -gst_event_get_segment (GstEvent * event) +void +gst_event_parse_segment (GstEvent * event, const GstSegment ** segment) { GstStructure *structure; - GstSegment *segment; - g_return_val_if_fail (GST_IS_EVENT (event), NULL); - g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT, NULL); + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT); - structure = GST_EVENT_STRUCTURE (event); - segment = g_value_get_boxed (gst_structure_id_get_value (structure, - GST_QUARK (SEGMENT))); - - return segment; + if (segment) { + structure = GST_EVENT_STRUCTURE (event); + *segment = g_value_get_boxed (gst_structure_id_get_value (structure, + GST_QUARK (SEGMENT))); + } } /** - * gst_event_parse_segment: + * gst_event_copy_segment: * @event: The event to parse - * @segment: a #GstSegment + * @segment: a pointer to a #GstSegment * - * Copy the segment values from @event into @segment. + * Parses a segment @event and copies the #GstSegment into the location + * given by @segment. */ void -gst_event_parse_segment (GstEvent * event, GstSegment * segment) +gst_event_copy_segment (GstEvent * event, GstSegment * segment) { const GstSegment *src; - g_return_if_fail (segment != NULL); + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT); - src = gst_event_get_segment (event); - g_return_if_fail (src != NULL); - - gst_segment_copy_into (src, segment); + if (segment) { + gst_event_parse_segment (event, &src); + gst_segment_copy_into (src, segment); + } } /** diff --git a/gst/gstevent.h b/gst/gstevent.h index 0019b38f00..46bac885f0 100644 --- a/gst/gstevent.h +++ b/gst/gstevent.h @@ -410,9 +410,8 @@ void gst_event_parse_caps (GstEvent *event, GstCaps **caps /* segment event */ GstEvent* gst_event_new_segment (GstSegment *segment); -const GstSegment * - gst_event_get_segment (GstEvent *event); -void gst_event_parse_segment (GstEvent *event, GstSegment *segment); +void gst_event_parse_segment (GstEvent *event, const GstSegment **segment); +void gst_event_copy_segment (GstEvent *event, GstSegment *segment); /* tag event */ GstEvent* gst_event_new_tag (GstTagList *taglist); diff --git a/libs/gst/base/gstbaseparse.c b/libs/gst/base/gstbaseparse.c index c07a9018f5..15a0b06f4c 100644 --- a/libs/gst/base/gstbaseparse.c +++ b/libs/gst/base/gstbaseparse.c @@ -926,7 +926,7 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event) gboolean update; #endif - in_segment = gst_event_get_segment (event); + gst_event_parse_segment (event, &in_segment); gst_segment_init (&out_segment, GST_FORMAT_TIME); GST_DEBUG_OBJECT (parse, "segment %" GST_SEGMENT_FORMAT, in_segment); diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index f5472d49d6..8d17c2c37a 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -1454,7 +1454,7 @@ gst_base_sink_configure_segment (GstBaseSink * basesink, GstPad * pad, GST_OBJECT_LOCK (basesink); /* the newsegment event is needed to bring the buffer timestamps to the * stream time and to drop samples outside of the playback segment. */ - gst_event_parse_segment (event, segment); + gst_event_copy_segment (event, segment); GST_DEBUG_OBJECT (basesink, "configured SEGMENT %" GST_SEGMENT_FORMAT, segment); GST_OBJECT_UNLOCK (basesink); diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index e76d79eac5..1f45cb625b 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -1583,7 +1583,7 @@ gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event) } case GST_EVENT_SEGMENT: { - gst_event_parse_segment (event, &trans->segment); + gst_event_copy_segment (event, &trans->segment); trans->have_segment = TRUE; GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT, diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c index a218de849e..fccb52c9f2 100644 --- a/libs/gst/base/gstcollectpads.c +++ b/libs/gst/base/gstcollectpads.c @@ -1200,7 +1200,7 @@ gst_collect_pads_event (GstPad * pad, GstEvent * event) } case GST_EVENT_SEGMENT: { - gst_event_parse_segment (event, &data->segment); + gst_event_copy_segment (event, &data->segment); GST_DEBUG_OBJECT (data->pad, "got newsegment %" GST_SEGMENT_FORMAT, &data->segment); diff --git a/plugins/elements/gstfdsink.c b/plugins/elements/gstfdsink.c index f5d3584fa6..b0109295fd 100644 --- a/plugins/elements/gstfdsink.c +++ b/plugins/elements/gstfdsink.c @@ -540,25 +540,25 @@ gst_fd_sink_event (GstBaseSink * sink, GstEvent * event) switch (type) { case GST_EVENT_SEGMENT: { - GstSegment segment; + const GstSegment *segment; gst_event_parse_segment (event, &segment); - if (segment.format == GST_FORMAT_BYTES) { + if (segment->format == GST_FORMAT_BYTES) { /* only try to seek and fail when we are going to a different * position */ - if (fdsink->current_pos != segment.start) { + if (fdsink->current_pos != segment->start) { /* FIXME, the seek should be performed on the pos field, start/stop are * just boundaries for valid bytes offsets. We should also fill the file * with zeroes if the new position extends the current EOF (sparse streams * and segment accumulation). */ - if (!gst_fd_sink_do_seek (fdsink, (guint64) segment.start)) + if (!gst_fd_sink_do_seek (fdsink, (guint64) segment->start)) goto seek_failed; } } else { GST_DEBUG_OBJECT (fdsink, - "Ignored SEGMENT event of format %u (%s)", (guint) segment.format, - gst_format_get_name (segment.format)); + "Ignored SEGMENT event of format %u (%s)", (guint) segment->format, + gst_format_get_name (segment->format)); } break; } diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index af31b2556e..98ba6e2405 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -543,27 +543,27 @@ gst_file_sink_event (GstBaseSink * sink, GstEvent * event) switch (type) { case GST_EVENT_SEGMENT: { - GstSegment segment; + const GstSegment *segment; gst_event_parse_segment (event, &segment); - if (segment.format == GST_FORMAT_BYTES) { + if (segment->format == GST_FORMAT_BYTES) { /* only try to seek and fail when we are going to a different * position */ - if (filesink->current_pos != segment.start) { + if (filesink->current_pos != segment->start) { /* FIXME, the seek should be performed on the pos field, start/stop are * just boundaries for valid bytes offsets. We should also fill the file * with zeroes if the new position extends the current EOF (sparse streams * and segment accumulation). */ - if (!gst_file_sink_do_seek (filesink, (guint64) segment.start)) + if (!gst_file_sink_do_seek (filesink, (guint64) segment->start)) goto seek_failed; } else { GST_DEBUG_OBJECT (filesink, "Ignored SEGMENT, no seek needed"); } } else { GST_DEBUG_OBJECT (filesink, - "Ignored SEGMENT event of format %u (%s)", (guint) segment.format, - gst_format_get_name (segment.format)); + "Ignored SEGMENT event of format %u (%s)", (guint) segment->format, + gst_format_get_name (segment->format)); } break; } diff --git a/plugins/elements/gstfunnel.c b/plugins/elements/gstfunnel.c index 6aa9eed758..5b37e72f6d 100644 --- a/plugins/elements/gstfunnel.c +++ b/plugins/elements/gstfunnel.c @@ -315,7 +315,7 @@ gst_funnel_sink_event (GstPad * pad, GstEvent * event) case GST_EVENT_SEGMENT: { GST_OBJECT_LOCK (funnel); - gst_event_parse_segment (event, &fpad->segment); + gst_event_copy_segment (event, &fpad->segment); GST_OBJECT_UNLOCK (funnel); forward = FALSE; diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index 00e3a6b08d..c06f384292 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -353,7 +353,7 @@ gst_identity_event (GstBaseTransform * trans, GstEvent * event) GstEvent *news; GstSegment segment; - gst_event_parse_segment (event, &segment); + gst_event_copy_segment (event, &segment); /* This is the first segment, send out a (0, -1) segment */ gst_segment_init (&segment, segment.format); diff --git a/plugins/elements/gstinputselector.c b/plugins/elements/gstinputselector.c index 4ab10453d4..585022e046 100644 --- a/plugins/elements/gstinputselector.c +++ b/plugins/elements/gstinputselector.c @@ -400,7 +400,7 @@ gst_selector_pad_event (GstPad * pad, GstEvent * event) { GST_INPUT_SELECTOR_LOCK (sel); GST_OBJECT_LOCK (selpad); - gst_event_parse_segment (event, &selpad->segment); + gst_event_copy_segment (event, &selpad->segment); GST_DEBUG_OBJECT (pad, "configured SEGMENT %" GST_SEGMENT_FORMAT, &selpad->segment); GST_OBJECT_UNLOCK (selpad); diff --git a/plugins/elements/gstmultiqueue.c b/plugins/elements/gstmultiqueue.c index fae88c9ac5..0fc16c1d7a 100644 --- a/plugins/elements/gstmultiqueue.c +++ b/plugins/elements/gstmultiqueue.c @@ -910,7 +910,7 @@ static void apply_segment (GstMultiQueue * mq, GstSingleQueue * sq, GstEvent * event, GstSegment * segment) { - gst_event_parse_segment (event, segment); + gst_event_copy_segment (event, segment); /* now configure the values, we use these to track timestamps on the * sinkpad. */ @@ -1011,13 +1011,13 @@ get_running_time (GstSegment * segment, GstMiniObject * object, gboolean end) /* For newsegment events return the running time of the start position */ if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { - GstSegment new_segment = *segment; + const GstSegment *new_segment; gst_event_parse_segment (event, &new_segment); - if (new_segment.format == GST_FORMAT_TIME) { + if (new_segment->format == GST_FORMAT_TIME) { time = - gst_segment_to_running_time (&new_segment, GST_FORMAT_TIME, - new_segment.start); + gst_segment_to_running_time (new_segment, GST_FORMAT_TIME, + new_segment->start); } } } diff --git a/plugins/elements/gstoutputselector.c b/plugins/elements/gstoutputselector.c index 7d22f9d826..56f0f6921b 100644 --- a/plugins/elements/gstoutputselector.c +++ b/plugins/elements/gstoutputselector.c @@ -546,7 +546,7 @@ gst_output_selector_handle_sink_event (GstPad * pad, GstEvent * event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_SEGMENT: { - gst_event_parse_segment (event, &sel->segment); + gst_event_copy_segment (event, &sel->segment); GST_DEBUG_OBJECT (sel, "configured SEGMENT update %" GST_SEGMENT_FORMAT, &sel->segment); diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index 7dc81395b0..feeaf5402e 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -570,7 +570,7 @@ static void apply_segment (GstQueue * queue, GstEvent * event, GstSegment * segment, gboolean sink) { - gst_event_parse_segment (event, segment); + gst_event_copy_segment (event, segment); /* now configure the values, we use these to track timestamps on the * sinkpad. */ diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index 9ff1719e3f..65f3613f66 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -686,7 +686,7 @@ static void apply_segment (GstQueue2 * queue, GstEvent * event, GstSegment * segment, gboolean is_sink) { - gst_event_parse_segment (event, segment); + gst_event_copy_segment (event, segment); if (segment->format == GST_FORMAT_BYTES) { if (QUEUE_IS_USING_TEMP_FILE (queue)) { diff --git a/tests/check/gst/gstevent.c b/tests/check/gst/gstevent.c index ac09c288bb..4579317a60 100644 --- a/tests/check/gst/gstevent.c +++ b/tests/check/gst/gstevent.c @@ -75,7 +75,7 @@ GST_START_TEST (create_events) fail_unless (GST_EVENT_IS_DOWNSTREAM (event)); fail_unless (GST_EVENT_IS_SERIALIZED (event)); - gst_event_parse_segment (event, &parsed); + gst_event_copy_segment (event, &parsed); fail_unless (parsed.rate == 0.5); fail_unless (parsed.applied_rate == 1.0); fail_unless (parsed.format == GST_FORMAT_TIME); diff --git a/tests/check/libs/basesrc.c b/tests/check/libs/basesrc.c index a6aa1e868d..750d9babbf 100644 --- a/tests/check/libs/basesrc.c +++ b/tests/check/libs/basesrc.c @@ -514,7 +514,7 @@ GST_START_TEST (basesrc_seek_events_rate_update) GstEvent *seg_event = NULL; GstEvent *rate_seek; gboolean event_ret; - GstSegment segment; + const GstSegment *segment; pipe = gst_pipeline_new ("pipeline"); sink = gst_element_factory_make ("fakesink", "sink"); @@ -581,7 +581,7 @@ GST_START_TEST (basesrc_seek_events_rate_update) fail_unless (seg_event != NULL); gst_event_parse_segment (seg_event, &segment); - fail_unless (segment.rate == 0.5); + fail_unless (segment->rate == 0.5); gst_pad_remove_event_probe (probe_pad, probe); gst_object_unref (probe_pad); diff --git a/win32/common/libgstbase.def b/win32/common/libgstbase.def index 2b5992689a..5599490598 100644 --- a/win32/common/libgstbase.def +++ b/win32/common/libgstbase.def @@ -27,6 +27,7 @@ EXPORTS gst_base_parse_set_duration gst_base_parse_set_frame_rate gst_base_parse_set_has_timing_info + gst_base_parse_set_latency gst_base_parse_set_min_frame_size gst_base_parse_set_passthrough gst_base_parse_set_syncable diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 6eb71d71e3..99c247f8ea 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -381,7 +381,7 @@ EXPORTS gst_element_unlink_many gst_element_unlink_pads gst_error_get_message - gst_event_get_segment + gst_event_copy_segment gst_event_get_seqnum gst_event_get_structure gst_event_has_name @@ -667,6 +667,7 @@ EXPORTS gst_pad_get_query_types gst_pad_get_query_types_default gst_pad_get_range + gst_pad_get_sticky_event gst_pad_get_type gst_pad_has_current_caps gst_pad_is_active