Commit a46c9c2a authored by Sebastian Dröge's avatar Sebastian Dröge

event: Make SEGMENT event parsing API more consistent with the others

parent ad0693f4
......@@ -632,49 +632,49 @@ gst_event_new_segment (GstSegment * segment)
}
/**
* gst_event_get_segment:
* @event: The event
*
* Get the segment from @event. The segment remains valid as long as @event remains
* valid.
* gst_event_parse_segment:
* @event: The event to parse
* @segment: (out) (transfer none): a pointer to a #GstSegment
*
* 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);
if (segment) {
structure = GST_EVENT_STRUCTURE (event);
segment = g_value_get_boxed (gst_structure_id_get_value (structure,
*segment = g_value_get_boxed (gst_structure_id_get_value (structure,
GST_QUARK (SEGMENT)));
return 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);
src = gst_event_get_segment (event);
g_return_if_fail (src != NULL);
g_return_if_fail (GST_IS_EVENT (event));
g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
if (segment) {
gst_event_parse_segment (event, &src);
gst_segment_copy_into (src, segment);
}
}
/**
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
}
}
}
......
......@@ -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);
......
......@@ -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. */
......
......@@ -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)) {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment