diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-05-13 18:07:24 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2011-05-16 11:37:52 +0200 |
commit | bdbc06934812481fce27c068081e2bbefcd887d0 (patch) | |
tree | cbc20f023a5218b9538cee89f015fea5cde3ed3a /libs | |
parent | ddf2489be446928f063e195d365071e8402ecc7a (diff) |
Rework GstSegment handlingsegment-rework
Improve GstSegment, rename some fields. The idea is to have the GstSegment
structure represent the timing structure of the buffers as they are generated by
the source or demuxer element.
gst_segment_set_seek() -> gst_segment_do_seek()
Rename the NEWSEGMENT event to SEGMENT.
Make parsing of the SEGMENT event into a GstSegment structure.
Pass a GstSegment structure when making a new SEGMENT event. This allows us to
pass the timing info directly to the next element. No accumulation is needed in
the receiving element, all the info is inside the element.
Remove gst_segment_set_newsegment(): This function as used to accumulate
segments received from upstream, which is now not needed anymore because the
segment event contains the complete timing information.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gst/base/gstbaseparse.c | 196 | ||||
-rw-r--r-- | libs/gst/base/gstbasesink.c | 203 | ||||
-rw-r--r-- | libs/gst/base/gstbasesrc.c | 134 | ||||
-rw-r--r-- | libs/gst/base/gstbasetransform.c | 75 | ||||
-rw-r--r-- | libs/gst/base/gstbasetransform.h | 2 | ||||
-rw-r--r-- | libs/gst/base/gstcollectpads.c | 21 | ||||
-rw-r--r-- | libs/gst/check/gstconsistencychecker.c | 16 | ||||
-rw-r--r-- | libs/gst/dataprotocol/dataprotocol.c | 2 |
8 files changed, 237 insertions, 412 deletions
diff --git a/libs/gst/base/gstbaseparse.c b/libs/gst/base/gstbaseparse.c index 6f70077f9..7c9507e4f 100644 --- a/libs/gst/base/gstbaseparse.c +++ b/libs/gst/base/gstbaseparse.c @@ -842,10 +842,10 @@ gst_base_parse_sink_event (GstPad * pad, GstEvent * event) GST_DEBUG_OBJECT (parse, "handling event %d, %s", GST_EVENT_TYPE (event), GST_EVENT_TYPE_NAME (event)); - /* Cache all events except EOS, NEWSEGMENT and FLUSH_STOP if we have a + /* Cache all events except EOS, SEGMENT and FLUSH_STOP if we have a * pending segment */ if (parse->priv->pending_segment && GST_EVENT_TYPE (event) != GST_EVENT_EOS - && GST_EVENT_TYPE (event) != GST_EVENT_NEWSEGMENT + && GST_EVENT_TYPE (event) != GST_EVENT_SEGMENT && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_START && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP) { @@ -897,36 +897,36 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event) GstEvent **eventp; switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: { + const GstSegment *in_segment; + GstSegment out_segment; + gint64 offset = 0, next_ts; + +#if 0 gdouble rate, applied_rate; GstFormat format; - gint64 start, stop, pos, next_ts, offset = 0; + gint64 start, stop, pos, next_ts; gboolean update; +#endif - gst_event_parse_new_segment (event, &update, &rate, &applied_rate, - &format, &start, &stop, &pos); + in_segment = gst_event_get_segment (event); + gst_segment_init (&out_segment, GST_FORMAT_TIME); - GST_DEBUG_OBJECT (parse, "newseg rate %g, applied rate %g, " - "format %d, start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT - ", pos = %" GST_TIME_FORMAT, rate, applied_rate, format, - GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (pos)); + GST_DEBUG_OBJECT (parse, "segment %" GST_SEGMENT_FORMAT, in_segment); - if (format == GST_FORMAT_BYTES) { - GstClockTime seg_start, seg_stop; + if (in_segment->format == GST_FORMAT_BYTES) { GstBaseParseSeek *seek = NULL; GSList *node; /* stop time is allowed to be open-ended, but not start & pos */ - seg_stop = GST_CLOCK_TIME_NONE; - seg_start = 0; - offset = pos; + offset = in_segment->time; GST_OBJECT_LOCK (parse); for (node = parse->priv->pending_seeks; node; node = node->next) { GstBaseParseSeek *tmp = node->data; - if (tmp->offset == pos) { + if (tmp->offset == offset) { seek = tmp; break; } @@ -939,8 +939,11 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event) GST_DEBUG_OBJECT (parse, "Matched newsegment to%s seek: %" GST_SEGMENT_FORMAT, seek->accurate ? " accurate" : "", &seek->segment); - seg_start = seek->segment.start; - seg_stop = seek->segment.stop; + + out_segment.start = seek->segment.start; + out_segment.stop = seek->segment.stop; + out_segment.time = seek->segment.start; + next_ts = seek->start_ts; parse->priv->exact_position = seek->accurate; g_free (seek); @@ -948,39 +951,48 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event) /* best attempt convert */ /* as these are only estimates, stop is kept open-ended to avoid * premature cutting */ - gst_base_parse_convert (parse, GST_FORMAT_BYTES, start, - GST_FORMAT_TIME, (gint64 *) & seg_start); - parse->priv->exact_position = (start == 0); - next_ts = seg_start; + gst_base_parse_convert (parse, GST_FORMAT_BYTES, in_segment->start, + GST_FORMAT_TIME, (gint64 *) & next_ts); + + out_segment.start = next_ts; + out_segment.stop = GST_CLOCK_TIME_NONE; + out_segment.time = next_ts; + + parse->priv->exact_position = (in_segment->start == 0); } gst_event_unref (event); - event = gst_event_new_new_segment (update, rate, applied_rate, - GST_FORMAT_TIME, seg_start, seg_stop, seg_start); - format = GST_FORMAT_TIME; - start = seg_start; - stop = seg_stop; + + event = gst_event_new_segment (&out_segment); + GST_DEBUG_OBJECT (parse, "Converted incoming segment to TIME. " - "start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT, - GST_TIME_ARGS (seg_start), GST_TIME_ARGS (seg_stop)); - } else if (format != GST_FORMAT_TIME) { + GST_SEGMENT_FORMAT, in_segment); + + } else if (in_segment->format != GST_FORMAT_TIME) { /* Unknown incoming segment format. Output a default open-ended * TIME segment */ gst_event_unref (event); - event = gst_event_new_new_segment (update, rate, applied_rate, - GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, 0); - format = GST_FORMAT_TIME; - next_ts = start = 0; - stop = GST_CLOCK_TIME_NONE; + + out_segment.start = 0; + out_segment.stop = GST_CLOCK_TIME_NONE;; + out_segment.time = 0;; + + event = gst_event_new_segment (&out_segment); + + next_ts = 0; } else { /* not considered BYTE seekable if it is talking to us in TIME, * whatever else it might claim */ parse->priv->upstream_seekable = FALSE; - next_ts = start; + next_ts = in_segment->start; } - gst_segment_set_newsegment (&parse->segment, update, rate, - applied_rate, format, start, stop, start); + memcpy (&parse->segment, &out_segment, sizeof (GstSegment)); + + /* + gst_segment_set_newsegment (&parse->segment, update, rate, + applied_rate, format, start, stop, start); + */ /* save the segment for later, right before we push a new buffer so that * the caps are fixed and the next linked element can receive @@ -992,11 +1004,12 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event) /* but finish the current segment */ GST_DEBUG_OBJECT (parse, "draining current segment"); - if (parse->segment.rate > 0.0) + if (in_segment->rate > 0.0) gst_base_parse_drain (parse); else gst_base_parse_process_fragment (parse, FALSE); gst_adapter_clear (parse->priv->adapter); + parse->priv->offset = offset; parse->priv->sync_offset = offset; parse->priv->next_ts = next_ts; @@ -1767,64 +1780,46 @@ gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame) gst_event_unref (parse->priv->pending_segment); parse->segment.start = MIN ((guint64) last_start, (guint64) parse->segment.stop); + GST_DEBUG_OBJECT (parse, "adjusting pending segment start to %" GST_TIME_FORMAT, GST_TIME_ARGS (parse->segment.start)); - parse->priv->pending_segment = - gst_event_new_new_segment (FALSE, parse->segment.rate, - parse->segment.applied_rate, - parse->segment.format, parse->segment.start, - parse->segment.stop, parse->segment.start); + + parse->priv->pending_segment = gst_event_new_segment (&parse->segment); } /* handle gaps, e.g. non-zero start-time, in as much not handled by above */ - if (GST_CLOCK_TIME_IS_VALID (parse->segment.last_stop) && + if (GST_CLOCK_TIME_IS_VALID (parse->segment.position) && GST_CLOCK_TIME_IS_VALID (last_start)) { GstClockTimeDiff diff; /* only send newsegments with increasing start times, * otherwise if these go back and forth downstream (sinks) increase * accumulated time and running_time */ - diff = GST_CLOCK_DIFF (parse->segment.last_stop, last_start); + diff = GST_CLOCK_DIFF (parse->segment.position, last_start); if (G_UNLIKELY (diff > 2 * GST_SECOND && last_start > parse->segment.start && (!GST_CLOCK_TIME_IS_VALID (parse->segment.stop) || last_start < parse->segment.stop))) { + GST_DEBUG_OBJECT (parse, "Gap of %" G_GINT64_FORMAT " ns detected in stream " "(%" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "). " "Sending updated NEWSEGMENT events", diff, - GST_TIME_ARGS (parse->segment.last_stop), + GST_TIME_ARGS (parse->segment.position), GST_TIME_ARGS (last_start)); + if (G_UNLIKELY (parse->priv->pending_segment)) { gst_event_unref (parse->priv->pending_segment); parse->segment.start = last_start; + parse->segment.time = last_start; parse->priv->pending_segment = - gst_event_new_new_segment (FALSE, parse->segment.rate, - parse->segment.applied_rate, - parse->segment.format, parse->segment.start, - parse->segment.stop, parse->segment.start); + gst_event_new_segment (&parse->segment); } else { - /* send newsegment events such that the gap is not accounted in - * accum time, hence running_time */ - /* close ahead of gap */ - gst_pad_push_event (parse->srcpad, - gst_event_new_new_segment (TRUE, parse->segment.rate, - parse->segment.applied_rate, - parse->segment.format, parse->segment.last_stop, - parse->segment.last_stop, parse->segment.last_stop)); - /* skip gap */ + /* skip gap FIXME */ gst_pad_push_event (parse->srcpad, - gst_event_new_new_segment (FALSE, parse->segment.rate, - parse->segment.applied_rate, - parse->segment.format, last_start, - parse->segment.stop, last_start)); + gst_event_new_segment (&parse->segment)); } - /* align segment view with downstream, - * prevents double-counting accum when closing segment */ - gst_segment_set_newsegment (&parse->segment, FALSE, - parse->segment.rate, parse->segment.applied_rate, - parse->segment.format, last_start, parse->segment.stop, last_start); - parse->segment.last_stop = last_start; + parse->segment.position = last_start; } } } @@ -1930,8 +1925,8 @@ gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame) /* Update current running segment position */ if (ret == GST_FLOW_OK && last_stop != GST_CLOCK_TIME_NONE && - parse->segment.last_stop < last_stop) - gst_segment_set_last_stop (&parse->segment, GST_FORMAT_TIME, last_stop); + parse->segment.position < last_stop) + parse->segment.position = last_stop; gst_base_parse_frame_free (frame); @@ -2048,7 +2043,7 @@ gst_base_parse_process_fragment (GstBaseParse * parse, gboolean push_only) * ok if taken from subclass or upstream */ parse->priv->next_ts = GST_CLOCK_TIME_NONE; /* prevent it hanging around stop all the time */ - parse->segment.last_stop = GST_CLOCK_TIME_NONE; + parse->segment.position = GST_CLOCK_TIME_NONE; /* mark next run */ parse->priv->discont = TRUE; @@ -2636,7 +2631,7 @@ gst_base_parse_loop (GstPad * pad) /* eat expected eos signalling past segment in reverse playback */ if (parse->segment.rate < 0.0 && ret == GST_FLOW_UNEXPECTED && - parse->segment.last_stop >= parse->segment.stop) { + parse->segment.position >= parse->segment.stop) { GST_DEBUG_OBJECT (parse, "downstream has reached end of segment"); /* push what was accumulated during loop run */ gst_base_parse_process_fragment (parse, TRUE); @@ -2797,10 +2792,7 @@ gst_base_parse_sink_activate_pull (GstPad * sinkpad, gboolean active) if (result) { if (active) { - parse->priv->pending_segment = gst_event_new_new_segment (FALSE, - parse->segment.rate, parse->segment.applied_rate, - parse->segment.format, parse->segment.start, parse->segment.stop, - parse->segment.last_stop); + parse->priv->pending_segment = gst_event_new_segment (&parse->segment); result &= gst_pad_start_task (sinkpad, (GstTaskFunction) gst_base_parse_loop, sinkpad); @@ -3090,8 +3082,8 @@ gst_base_parse_query (GstPad * pad, GstQuery ** query) dest_value = parse->priv->offset; res = TRUE; } else if (format == parse->segment.format && - GST_CLOCK_TIME_IS_VALID (parse->segment.last_stop)) { - dest_value = parse->segment.last_stop; + GST_CLOCK_TIME_IS_VALID (parse->segment.position)) { + dest_value = parse->segment.position; res = TRUE; } GST_OBJECT_UNLOCK (parse); @@ -3498,10 +3490,10 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) /* copy segment, we need this because we still need the old * segment when we close the current segment. */ - memcpy (&seeksegment, &parse->segment, sizeof (GstSegment)); + gst_segment_copy_into (&parse->segment, &seeksegment); GST_DEBUG_OBJECT (parse, "configuring seek"); - gst_segment_set_seek (&seeksegment, rate, format, flags, + gst_segment_do_seek (&seeksegment, rate, format, flags, cur_type, cur, stop_type, stop, &update); /* accurate seeking implies seek tables are used to obtain position, @@ -3509,13 +3501,13 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) accurate = flags & GST_SEEK_FLAG_ACCURATE; /* maybe we can be accurate for (almost) free */ - gst_base_parse_find_offset (parse, seeksegment.last_stop, TRUE, &start_ts); - if (seeksegment.last_stop <= start_ts + TARGET_DIFFERENCE) { + gst_base_parse_find_offset (parse, seeksegment.position, TRUE, &start_ts); + if (seeksegment.position <= start_ts + TARGET_DIFFERENCE) { GST_DEBUG_OBJECT (parse, "accurate seek possible"); accurate = TRUE; } if (accurate) { - GstClockTime startpos = seeksegment.last_stop; + GstClockTime startpos = seeksegment.position; /* accurate requested, so ... seek a bit before target */ if (startpos < parse->priv->lead_in_ts) @@ -3526,9 +3518,9 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) seekstop = gst_base_parse_find_offset (parse, seeksegment.stop, FALSE, NULL); } else { - start_ts = seeksegment.last_stop; + start_ts = seeksegment.position; dstformat = GST_FORMAT_BYTES; - if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.last_stop, + if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.position, &dstformat, &seekpos)) goto convert_failed; if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.stop, @@ -3564,7 +3556,7 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) GST_PAD_STREAM_LOCK (parse->sinkpad); /* save current position */ - last_stop = parse->segment.last_stop; + last_stop = parse->segment.position; GST_DEBUG_OBJECT (parse, "stopped streaming at %" G_GINT64_FORMAT, last_stop); @@ -3577,23 +3569,9 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) gst_pad_push_event (parse->sinkpad, gst_event_new_flush_stop ()); gst_base_parse_clear_queues (parse); } else { - if (parse->priv->close_segment) - gst_event_unref (parse->priv->close_segment); - - parse->priv->close_segment = gst_event_new_new_segment (TRUE, - parse->segment.rate, parse->segment.applied_rate, - parse->segment.format, parse->segment.accum, parse->segment.last_stop, - parse->segment.accum); - - /* keep track of our last_stop */ - seeksegment.accum = parse->segment.last_stop; - - GST_DEBUG_OBJECT (parse, "Created close seg format %d, " - "start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT - ", pos = %" GST_TIME_FORMAT, format, - GST_TIME_ARGS (parse->segment.accum), - GST_TIME_ARGS (parse->segment.last_stop), - GST_TIME_ARGS (parse->segment.accum)); + /* keep track of our position */ + seeksegment.base = gst_segment_to_running_time (&seeksegment, + seeksegment.format, parse->segment.position); } memcpy (&parse->segment, &seeksegment, sizeof (GstSegment)); @@ -3603,11 +3581,7 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) gst_event_unref (parse->priv->pending_segment); /* This will be sent later in _loop() */ - parse->priv->pending_segment = - gst_event_new_new_segment (FALSE, parse->segment.rate, - parse->segment.applied_rate, - parse->segment.format, parse->segment.start, - parse->segment.stop, parse->segment.start); + parse->priv->pending_segment = gst_event_new_segment (&parse->segment); GST_DEBUG_OBJECT (parse, "Created newseg format %d, " "start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT @@ -3620,7 +3594,7 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event) * maybe scan and subclass can find where to go */ if (!accurate) { gint64 scanpos; - GstClockTime ts = seeksegment.last_stop; + GstClockTime ts = seeksegment.position; gst_base_parse_locate_time (parse, &ts, &scanpos); if (scanpos >= 0) { diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 9fe4ea711..0f6d8234f 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -1439,43 +1439,15 @@ static void gst_base_sink_configure_segment (GstBaseSink * basesink, GstPad * pad, GstEvent * event, GstSegment * segment) { - gboolean update; - gdouble rate, arate; - GstFormat format; - gint64 start; - gint64 stop; - gint64 time; - - /* 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_new_segment (event, &update, &rate, &arate, &format, - &start, &stop, &time); - /* The segment is protected with both the STREAM_LOCK and the OBJECT_LOCK. * We protect with the OBJECT_LOCK so that we can use the values to * safely answer a POSITION query. */ GST_OBJECT_LOCK (basesink); - gst_segment_set_newsegment (segment, update, rate, arate, format, start, - stop, time); - - if (format == GST_FORMAT_TIME) { - GST_DEBUG_OBJECT (basesink, - "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, " - "format GST_FORMAT_TIME, " - "%" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT - ", time %" GST_TIME_FORMAT ", accum %" GST_TIME_FORMAT, - update, rate, arate, GST_TIME_ARGS (segment->start), - GST_TIME_ARGS (segment->stop), GST_TIME_ARGS (segment->time), - GST_TIME_ARGS (segment->accum)); - } else { - GST_DEBUG_OBJECT (basesink, - "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, " - "format %d, " - "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %" - G_GINT64_FORMAT ", accum %" G_GINT64_FORMAT, update, rate, arate, - segment->format, segment->start, segment->stop, segment->time, - segment->accum); - } + /* 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_DEBUG_OBJECT (basesink, "configured NEWSEGMENT %" GST_SEGMENT_FORMAT, + segment); GST_OBJECT_UNLOCK (basesink); } @@ -1642,27 +1614,19 @@ start_stepping (GstBaseSink * sink, GstSegment * segment, /* update the segment clipping regions for non-flushing seeks */ if (segment->rate > 0.0) { segment->stop = gst_segment_to_position (segment, GST_FORMAT_TIME, end); - segment->last_stop = segment->stop; + segment->position = segment->stop; } else { gint64 position; position = gst_segment_to_position (segment, GST_FORMAT_TIME, end); segment->time = position; segment->start = position; - segment->last_stop = position; + segment->position = position; } } } - GST_DEBUG_OBJECT (sink, - "segment now rate %lf, applied rate %lf, " - "format GST_FORMAT_TIME, " - "%" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT - ", time %" GST_TIME_FORMAT ", accum %" GST_TIME_FORMAT, - segment->rate, segment->applied_rate, GST_TIME_ARGS (segment->start), - GST_TIME_ARGS (segment->stop), GST_TIME_ARGS (segment->time), - GST_TIME_ARGS (segment->accum)); - + GST_DEBUG_OBJECT (sink, "segment now %" GST_SEGMENT_FORMAT, segment); GST_DEBUG_OBJECT (sink, "step started at running_time %" GST_TIME_FORMAT, GST_TIME_ARGS (current->start)); @@ -1707,8 +1671,8 @@ stop_stepping (GstBaseSink * sink, GstSegment * segment, gst_segment_set_running_time (segment, GST_FORMAT_TIME, position); if (current->flush) { - /* and remove the accumulated time we flushed, start time did not change */ - segment->accum = current->start; + /* and remove the time we flushed, start time did not change */ + segment->base = current->start; } else { /* start time is now the stepped position */ gst_element_set_start_time (GST_ELEMENT_CAST (sink), position); @@ -1723,7 +1687,7 @@ stop_stepping (GstBaseSink * sink, GstSegment * segment, segment->start = current->start_start; /* the clip segment is used for position report in paused... */ - memcpy (sink->clip_segment, segment, sizeof (GstSegment)); + gst_segment_copy_into (segment, sink->clip_segment); /* post the step done when we know the stepped duration in TIME */ message = @@ -1742,8 +1706,8 @@ stop_stepping (GstBaseSink * sink, GstSegment * segment, static gboolean handle_stepping (GstBaseSink * sink, GstSegment * segment, - GstStepInfo * current, gint64 * cstart, gint64 * cstop, gint64 * rstart, - gint64 * rstop) + GstStepInfo * current, guint64 * cstart, guint64 * cstop, guint64 * rstart, + guint64 * rstop) { gboolean step_end = FALSE; @@ -1752,7 +1716,7 @@ handle_stepping (GstBaseSink * sink, GstSegment * segment, case GST_FORMAT_TIME: { guint64 end; - gint64 first, last; + guint64 first, last; gdouble abs_rate; if (segment->rate > 0.0) { @@ -1844,8 +1808,8 @@ gst_base_sink_get_sync_times (GstBaseSink * basesink, GstMiniObject * obj, GstBaseSinkClass *bclass; GstBuffer *buffer; GstClockTime start, stop; /* raw start/stop timestamps */ - gint64 cstart, cstop; /* clipped raw timestamps */ - gint64 rstart, rstop; /* clipped timestamps converted to running time */ + guint64 cstart, cstop; /* clipped raw timestamps */ + guint64 rstart, rstop; /* clipped timestamps converted to running time */ GstClockTime sstart, sstop; /* clipped timestamps converted to stream time */ GstFormat format; GstBaseSinkPrivate *priv; @@ -1890,11 +1854,6 @@ gst_base_sink_get_sync_times (GstBaseSink * basesink, GstMiniObject * obj, } default: /* other events do not need syncing */ - /* FIXME, maybe NEWSEGMENT might need synchronisation - * since the POSITION query depends on accumulated times and - * we cannot accumulate the current segment before the previous - * one completed. - */ return FALSE; } } @@ -1940,7 +1899,7 @@ again: /* clip, only when we know about time */ if (G_UNLIKELY (!gst_segment_clip (segment, GST_FORMAT_TIME, - (gint64) start, (gint64) stop, &cstart, &cstop))) { + start, stop, &cstart, &cstop))) { if (step->valid) { GST_DEBUG_OBJECT (basesink, "step out of segment"); /* when we are stepping, pretend we're at the end of the segment */ @@ -1964,9 +1923,9 @@ again: /* set last stop position */ if (G_LIKELY (stop != GST_CLOCK_TIME_NONE && cstop != GST_CLOCK_TIME_NONE)) - gst_segment_set_last_stop (segment, GST_FORMAT_TIME, cstop); + segment->position = cstop; else - gst_segment_set_last_stop (segment, GST_FORMAT_TIME, cstart); + segment->position = cstart; do_times: rstart = gst_segment_to_running_time (segment, format, cstart); @@ -2735,7 +2694,7 @@ gst_base_sink_is_too_late (GstBaseSink * basesink, GstMiniObject * obj, GstClockReturn status, GstClockTimeDiff jitter) { gboolean late; - gint64 max_lateness; + guint64 max_lateness; GstBaseSinkPrivate *priv; priv = basesink->priv; @@ -2989,7 +2948,7 @@ again: gst_element_post_message (GST_ELEMENT_CAST (basesink), message); break; } - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: /* configure the segment */ gst_base_sink_configure_segment (basesink, pad, event, &basesink->segment); @@ -3387,41 +3346,31 @@ gst_base_sink_event (GstPad * pad, GstEvent * event) gst_event_unref (event); break; } - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: { GstFlowReturn ret; - gboolean update; - GST_DEBUG_OBJECT (basesink, "newsegment %p", event); + GST_DEBUG_OBJECT (basesink, "segment %p", event); GST_BASE_SINK_PREROLL_LOCK (basesink); if (G_UNLIKELY (basesink->flushing)) goto flushing; - gst_event_parse_new_segment (event, &update, NULL, NULL, NULL, NULL, - NULL, NULL); + /* the new segment is a non prerollable item and does not block anything, + * we need to configure the current clipping segment and insert the event + * in the queue to serialize it with the buffers for rendering. */ + gst_base_sink_configure_segment (basesink, pad, event, + basesink->clip_segment); - if (G_UNLIKELY (basesink->priv->received_eos && !update)) { - /* we can't accept anything when we are EOS */ + ret = + gst_base_sink_queue_object_unlocked (basesink, pad, + _PR_IS_EVENT, GST_MINI_OBJECT_CAST (event), FALSE); + if (G_UNLIKELY (ret != GST_FLOW_OK)) result = FALSE; - gst_event_unref (event); - } else { - /* the new segment is a non prerollable item and does not block anything, - * we need to configure the current clipping segment and insert the event - * in the queue to serialize it with the buffers for rendering. */ - gst_base_sink_configure_segment (basesink, pad, event, - basesink->clip_segment); - - ret = - gst_base_sink_queue_object_unlocked (basesink, pad, - _PR_IS_EVENT, GST_MINI_OBJECT_CAST (event), FALSE); - if (G_UNLIKELY (ret != GST_FLOW_OK)) - result = FALSE; - else { - GST_OBJECT_LOCK (basesink); - basesink->have_newsegment = TRUE; - GST_OBJECT_UNLOCK (basesink); - } + else { + GST_OBJECT_LOCK (basesink); + basesink->have_newsegment = TRUE; + GST_OBJECT_UNLOCK (basesink); } GST_BASE_SINK_PREROLL_UNLOCK (basesink); break; @@ -3589,7 +3538,7 @@ gst_base_sink_chain_unlocked (GstBaseSink * basesink, GstPad * pad, if (GST_CLOCK_TIME_IS_VALID (start) && (clip_segment->format == GST_FORMAT_TIME)) { if (G_UNLIKELY (!gst_segment_clip (clip_segment, - GST_FORMAT_TIME, (gint64) start, (gint64) end, NULL, NULL))) + GST_FORMAT_TIME, start, end, NULL, NULL))) goto out_of_segment; } @@ -3744,7 +3693,7 @@ gst_base_sink_default_prepare_seek_segment (GstBaseSink * sink, dest_format = segment->format; if (seek_format == dest_format) { - gst_segment_set_seek (segment, rate, seek_format, flags, + gst_segment_do_seek (segment, rate, seek_format, flags, cur_type, cur, stop_type, stop, &update); return TRUE; } @@ -3766,7 +3715,7 @@ gst_base_sink_default_prepare_seek_segment (GstBaseSink * sink, } /* And finally, configure our output segment in the desired format */ - gst_segment_set_seek (segment, rate, dest_format, flags, cur_type, cur, + gst_segment_do_seek (segment, rate, dest_format, flags, cur_type, cur, stop_type, stop, &update); if (!res) @@ -3839,7 +3788,7 @@ gst_base_sink_perform_seek (GstBaseSink * sink, GstPad * pad, GstEvent * event) } else { /* The seek format matches our processing format, no need to ask the * the subclass to configure the segment. */ - gst_segment_set_seek (&seeksegment, rate, seek_format, flags, + gst_segment_do_seek (&seeksegment, rate, seek_format, flags, cur_type, cur, stop_type, stop, &update); } } @@ -3850,9 +3799,9 @@ gst_base_sink_perform_seek (GstBaseSink * sink, GstPad * pad, GstEvent * event) if (res) { GST_DEBUG_OBJECT (sink, "segment configured from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT ", position %" G_GINT64_FORMAT, - seeksegment.start, seeksegment.stop, seeksegment.last_stop); + seeksegment.start, seeksegment.stop, seeksegment.position); - /* do the seek, segment.last_stop contains the new position. */ + /* do the seek, segment.position contains the new position. */ res = gst_base_sink_default_do_seek (sink, &seeksegment); } @@ -3863,9 +3812,9 @@ gst_base_sink_perform_seek (GstBaseSink * sink, GstPad * pad, GstEvent * event) gst_base_sink_flush_stop (sink, pad); } else if (res && sink->running) { /* we are running the current segment and doing a non-flushing seek, - * close the segment first based on the last_stop. */ + * close the segment first based on the position. */ GST_DEBUG_OBJECT (sink, "closing running segment %" G_GINT64_FORMAT - " to %" G_GINT64_FORMAT, sink->segment.start, sink->segment.last_stop); + " to %" G_GINT64_FORMAT, sink->segment.start, sink->segment.position); } /* The subclass must have converted the segment to the processing format @@ -3879,12 +3828,12 @@ gst_base_sink_perform_seek (GstBaseSink * sink, GstPad * pad, GstEvent * event) /* if successfull seek, we update our real segment and push * out the new segment. */ if (res) { - memcpy (&sink->segment, &seeksegment, sizeof (GstSegment)); + gst_segment_copy_into (&seeksegment, &sink->segment); if (sink->segment.flags & GST_SEEK_FLAG_SEGMENT) { gst_element_post_message (GST_ELEMENT (sink), gst_message_new_segment_start (GST_OBJECT (sink), - sink->segment.format, sink->segment.last_stop)); + sink->segment.format, sink->segment.position)); } } @@ -4016,7 +3965,7 @@ gst_base_sink_loop (GstPad * pad) if ((blocksize = basesink->priv->blocksize) == 0) blocksize = -1; - offset = basesink->segment.last_stop; + offset = basesink->segment.position; GST_DEBUG_OBJECT (basesink, "pulling %" G_GUINT64_FORMAT ", %u", offset, blocksize); @@ -4030,7 +3979,7 @@ gst_base_sink_loop (GstPad * pad) offset += gst_buffer_get_size (buf); - gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_BYTES, offset); + basesink->segment.position = offset; GST_BASE_SINK_PREROLL_LOCK (basesink); result = gst_base_sink_chain_unlocked (basesink, pad, _PR_IS_BUFFER, buf); @@ -4051,7 +4000,7 @@ paused: if (basesink->segment.flags & GST_SEEK_FLAG_SEGMENT) { gst_element_post_message (GST_ELEMENT_CAST (basesink), gst_message_new_segment_done (GST_OBJECT_CAST (basesink), - basesink->segment.format, basesink->segment.last_stop)); + basesink->segment.format, basesink->segment.position)); } else { gst_base_sink_event (pad, gst_event_new_eos ()); } @@ -4335,8 +4284,8 @@ gst_base_sink_pad_activate_pull (GstPad * pad, gboolean active) if (result) { GST_DEBUG_OBJECT (basesink, "setting duration in bytes to %" G_GINT64_FORMAT, duration); - gst_segment_set_duration (basesink->clip_segment, format, duration); - gst_segment_set_duration (&basesink->segment, format, duration); + basesink->clip_segment->duration = duration; + basesink->segment.duration = duration; } else { GST_DEBUG_OBJECT (basesink, "unknown duration"); } @@ -4455,8 +4404,8 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, GstFormat oformat, tformat; GstSegment *segment; GstClockTime now, latency; - GstClockTimeDiff base; - gint64 time, accum, duration; + GstClockTimeDiff base_time; + gint64 time, base, duration; gdouble rate; gint64 last; gboolean last_seen, with_clock, in_paused; @@ -4513,7 +4462,7 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, else duration = 0; - accum = segment->accum; + base = segment->base; rate = segment->rate * segment->applied_rate; latency = basesink->priv->latency; @@ -4538,28 +4487,28 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, } } else { /* convert last stop to stream time */ - last = gst_segment_to_stream_time (segment, oformat, segment->last_stop); + last = gst_segment_to_stream_time (segment, oformat, segment->position); } if (in_paused) { /* in paused, use start_time */ - base = GST_ELEMENT_START_TIME (basesink); + base_time = GST_ELEMENT_START_TIME (basesink); GST_DEBUG_OBJECT (basesink, "in paused, using start time %" GST_TIME_FORMAT, - GST_TIME_ARGS (base)); + GST_TIME_ARGS (base_time)); } else if (with_clock) { /* else use clock when needed */ - base = GST_ELEMENT_CAST (basesink)->base_time; + base_time = GST_ELEMENT_CAST (basesink)->base_time; GST_DEBUG_OBJECT (basesink, "using clock and base time %" GST_TIME_FORMAT, - GST_TIME_ARGS (base)); + GST_TIME_ARGS (base_time)); } else { /* else, no sync or clock -> no base time */ GST_DEBUG_OBJECT (basesink, "no sync or no clock"); - base = -1; + base_time = -1; } - /* no base, we can't calculate running_time, use last seem timestamp to report + /* no base_time, we can't calculate running_time, use last seem timestamp to report * time */ - if (base == -1) + if (base_time == -1) last_seen = TRUE; /* need to release the object lock before we can get the time, @@ -4582,9 +4531,9 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, *cur = last; } else { if (oformat != tformat) { - /* convert accum, time and duration to time */ - if (!gst_pad_query_convert (basesink->sinkpad, oformat, accum, &tformat, - &accum)) + /* convert base, time and duration to time */ + if (!gst_pad_query_convert (basesink->sinkpad, oformat, base, &tformat, + &base)) goto convert_failed; if (!gst_pad_query_convert (basesink->sinkpad, oformat, duration, &tformat, &duration)) @@ -4603,25 +4552,25 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, if (!in_paused && with_clock) { now = gst_clock_get_time (clock); } else { - now = base; - base = 0; + now = base_time; + base_time = 0; } - /* subtract base time and accumulated time from the clock time. + /* subtract base time and base time from the clock time. * Make sure we don't go negative. This is the current time in * the segment which we need to scale with the combined * rate and applied rate. */ - base += accum; - base += latency; - if (GST_CLOCK_DIFF (base, now) < 0) - base = now; + base_time += base; + base_time += latency; + if (GST_CLOCK_DIFF (base_time, now) < 0) + base_time = now; /* for negative rates we need to count back from the segment * duration. */ if (rate < 0.0) time += duration; - *cur = time + gst_guint64_to_gdouble (now - base) * rate; + *cur = time + gst_guint64_to_gdouble (now - base_time) * rate; if (in_paused) { /* never report less than segment values in paused */ @@ -4634,9 +4583,9 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format, } GST_DEBUG_OBJECT (basesink, - "now %" GST_TIME_FORMAT " - base %" GST_TIME_FORMAT " - accum %" + "now %" GST_TIME_FORMAT " - base_time %" GST_TIME_FORMAT " - base %" GST_TIME_FORMAT " + time %" GST_TIME_FORMAT " last %" GST_TIME_FORMAT, - GST_TIME_ARGS (now), GST_TIME_ARGS (base), GST_TIME_ARGS (accum), + GST_TIME_ARGS (now), GST_TIME_ARGS (base_time), GST_TIME_ARGS (base), GST_TIME_ARGS (time), GST_TIME_ARGS (last)); } @@ -4692,7 +4641,7 @@ gst_base_sink_get_duration (GstBaseSink * basesink, GstFormat format, * should be done at a higher level. */ res = gst_pad_query_peer_duration (basesink->sinkpad, &uformat, &uduration); if (res) { - gst_segment_set_duration (&basesink->segment, uformat, uduration); + basesink->segment.duration = uduration; if (format != uformat) { /* convert to the requested format */ res = gst_pad_query_convert (basesink->sinkpad, uformat, uduration, diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index 5ab1462ad..c0882c353 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -217,10 +217,8 @@ struct _GstBaseSrcPrivate gboolean discont; gboolean flushing; - /* two segments to be sent in the streaming thread with STREAM_LOCK */ - GstEvent *close_segment; - GstEvent *start_segment; - gboolean newsegment_pending; + /* if segment should be sent */ + gboolean segment_pending; /* if EOS is pending (atomic) */ gint pending_eos; @@ -754,33 +752,15 @@ gst_base_src_new_seamless_segment (GstBaseSrc * src, gint64 start, gint64 stop, GST_TIME_ARGS (stop), GST_TIME_ARGS (position)); GST_OBJECT_LOCK (src); - if (src->running && !src->priv->newsegment_pending) { - if (src->priv->close_segment) - gst_event_unref (src->priv->close_segment); - src->priv->close_segment = - gst_event_new_new_segment (TRUE, - src->segment.rate, src->segment.applied_rate, src->segment.format, - src->segment.start, src->segment.last_stop, src->segment.time); - } - - gst_segment_set_newsegment (&src->segment, FALSE, src->segment.rate, - src->segment.applied_rate, src->segment.format, start, stop, position); - - if (src->priv->start_segment) - gst_event_unref (src->priv->start_segment); - if (src->segment.rate >= 0.0) { - /* forward, we send data from last_stop to stop */ - src->priv->start_segment = - gst_event_new_new_segment (FALSE, - src->segment.rate, src->segment.applied_rate, src->segment.format, - src->segment.last_stop, stop, src->segment.time); - } else { - /* reverse, we send data from last_stop to start */ - src->priv->start_segment = - gst_event_new_new_segment (FALSE, - src->segment.rate, src->segment.applied_rate, src->segment.format, - src->segment.start, src->segment.last_stop, src->segment.time); - } + + src->segment.base = gst_segment_to_running_time (&src->segment, + src->segment.format, src->segment.position); + src->segment.start = start; + src->segment.stop = stop; + src->segment.position = position; + + /* forward, we send data from position to stop */ + src->priv->segment_pending = TRUE; GST_OBJECT_UNLOCK (src); src->priv->discont = TRUE; @@ -867,7 +847,7 @@ gst_base_src_default_query (GstBaseSrc * src, GstQuery ** query) gint64 duration; GST_OBJECT_LOCK (src); - position = src->segment.last_stop; + position = src->segment.position; duration = src->segment.duration; GST_OBJECT_UNLOCK (src); @@ -892,7 +872,7 @@ gst_base_src_default_query (GstBaseSrc * src, GstQuery ** query) GST_OBJECT_LOCK (src); position = gst_segment_to_stream_time (&src->segment, src->segment.format, - src->segment.last_stop); + src->segment.position); seg_format = src->segment.format; GST_OBJECT_UNLOCK (src); @@ -1184,7 +1164,7 @@ gst_base_src_default_prepare_seek_segment (GstBaseSrc * src, GstEvent * event, dest_format = segment->format; if (seek_format == dest_format) { - gst_segment_set_seek (segment, rate, seek_format, flags, + gst_segment_do_seek (segment, rate, seek_format, flags, cur_type, cur, stop_type, stop, &update); return TRUE; } @@ -1206,7 +1186,7 @@ gst_base_src_default_prepare_seek_segment (GstBaseSrc * src, GstEvent * event, } /* And finally, configure our output segment in the desired format */ - gst_segment_set_seek (segment, rate, dest_format, flags, cur_type, cur, + gst_segment_do_seek (segment, rate, dest_format, flags, cur_type, cur, stop_type, stop, &update); if (!res) @@ -1387,7 +1367,7 @@ gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock) } else { /* The seek format matches our processing format, no need to ask the * the subclass to configure the segment. */ - gst_segment_set_seek (&seeksegment, rate, seek_format, flags, + gst_segment_do_seek (&seeksegment, rate, seek_format, flags, cur_type, cur, stop_type, stop, &update); } } @@ -1398,9 +1378,9 @@ gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock) if (res) { GST_DEBUG_OBJECT (src, "segment configured from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT ", position %" G_GINT64_FORMAT, - seeksegment.start, seeksegment.stop, seeksegment.last_stop); + seeksegment.start, seeksegment.stop, seeksegment.position); - /* do the seek, segment.last_stop contains the new position. */ + /* do the seek, segment.position contains the new position. */ res = gst_base_src_do_seek (src, &seeksegment); } @@ -1411,20 +1391,6 @@ gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock) /* send flush stop, peer will accept data and events again. We * are not yet providing data as we still have the STREAM_LOCK. */ gst_pad_push_event (src->srcpad, tevent); - } else if (res && src->running) { - /* we are running the current segment and doing a non-flushing seek, - * close the segment first based on the last_stop. */ - GST_DEBUG_OBJECT (src, "closing running segment %" G_GINT64_FORMAT - " to %" G_GINT64_FORMAT, src->segment.start, src->segment.last_stop); - - /* queue the segment for sending in the stream thread */ - if (src->priv->close_segment) - gst_event_unref (src->priv->close_segment); - src->priv->close_segment = - gst_event_new_new_segment (TRUE, - src->segment.rate, src->segment.applied_rate, src->segment.format, - src->segment.start, src->segment.last_stop, src->segment.time); - gst_event_set_seqnum (src->priv->close_segment, seqnum); } /* The subclass must have converted the segment to the processing format @@ -1446,7 +1412,7 @@ gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock) GstMessage *message; message = gst_message_new_segment_start (GST_OBJECT (src), - seeksegment.format, seeksegment.last_stop); + seeksegment.format, seeksegment.position); gst_message_set_seqnum (message, seqnum); gst_element_post_message (GST_ELEMENT (src), message); @@ -1457,28 +1423,7 @@ gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock) if ((stop = seeksegment.stop) == -1) stop = seeksegment.duration; - GST_DEBUG_OBJECT (src, "Sending newsegment from %" G_GINT64_FORMAT - " to %" G_GINT64_FORMAT, seeksegment.start, stop); - - /* now replace the old segment so that we send it in the stream thread the - * next time it is scheduled. */ - if (src->priv->start_segment) - gst_event_unref (src->priv->start_segment); - if (seeksegment.rate >= 0.0) { - /* forward, we send data from last_stop to stop */ - src->priv->start_segment = - gst_event_new_new_segment (FALSE, - seeksegment.rate, seeksegment.applied_rate, seeksegment.format, - seeksegment.last_stop, stop, seeksegment.time); - } else { - /* reverse, we send data from last_stop to start */ - src->priv->start_segment = - gst_event_new_new_segment (FALSE, - seeksegment.rate, seeksegment.applied_rate, seeksegment.format, - seeksegment.start, seeksegment.last_stop, seeksegment.time); - } - gst_event_set_seqnum (src->priv->start_segment, seqnum); - src->priv->newsegment_pending = TRUE; + src->priv->segment_pending = TRUE; } src->priv->discont = TRUE; @@ -1584,8 +1529,8 @@ gst_base_src_send_event (GstElement * element, GstEvent * event) result = TRUE; break; } - case GST_EVENT_NEWSEGMENT: - /* sending random NEWSEGMENT downstream can break sync. */ + case GST_EVENT_SEGMENT: + /* sending random SEGMENT downstream can break sync. */ break; case GST_EVENT_TAG: case GST_EVENT_CUSTOM_DOWNSTREAM: @@ -2081,8 +2026,8 @@ gst_base_src_update_length (GstBaseSrc * src, guint64 offset, guint * length) /* keep track of current position and update duration. * segment is in bytes, we checked that above. */ GST_OBJECT_LOCK (src); - gst_segment_set_duration (&src->segment, GST_FORMAT_BYTES, size); - gst_segment_set_last_stop (&src->segment, GST_FORMAT_BYTES, offset); + src->segment.duration = size; + src->segment.position = offset; GST_OBJECT_UNLOCK (src); return TRUE; @@ -2384,7 +2329,7 @@ gst_base_src_loop (GstPad * pad) /* if we operate in bytes, we can calculate an offset */ if (src->segment.format == GST_FORMAT_BYTES) { - position = src->segment.last_stop; + position = src->segment.position; /* for negative rates, start with subtracting the blocksize */ if (src->segment.rate < 0.0) { /* we cannot go below segment.start */ @@ -2414,15 +2359,10 @@ gst_base_src_loop (GstPad * pad) goto null_buffer; /* push events to close/start our segment before we push the buffer. */ - if (G_UNLIKELY (src->priv->close_segment)) { - gst_pad_push_event (pad, src->priv->close_segment); - src->priv->close_segment = NULL; - } - if (G_UNLIKELY (src->priv->start_segment)) { - gst_pad_push_event (pad, src->priv->start_segment); - src->priv->start_segment = NULL; + if (G_UNLIKELY (src->priv->segment_pending)) { + gst_pad_push_event (pad, gst_event_new_segment (&src->segment)); + src->priv->segment_pending = FALSE; } - src->priv->newsegment_pending = FALSE; if (g_atomic_int_get (&src->priv->have_events)) { GST_OBJECT_LOCK (src); @@ -2463,7 +2403,7 @@ gst_base_src_loop (GstPad * pad) if (GST_CLOCK_TIME_IS_VALID (start)) position = start; else - position = src->segment.last_stop; + position = src->segment.position; if (GST_CLOCK_TIME_IS_VALID (duration)) { if (src->segment.rate >= 0.0) @@ -2505,7 +2445,7 @@ gst_base_src_loop (GstPad * pad) src->priv->discont = TRUE; } GST_OBJECT_LOCK (src); - gst_segment_set_last_stop (&src->segment, src->segment.format, position); + src->segment.position = position; GST_OBJECT_UNLOCK (src); } @@ -2551,18 +2491,18 @@ pause: if (ret == GST_FLOW_UNEXPECTED) { gboolean flag_segment; GstFormat format; - gint64 last_stop; + gint64 position; /* perform EOS logic */ flag_segment = (src->segment.flags & GST_SEEK_FLAG_SEGMENT) != 0; format = src->segment.format; - last_stop = src->segment.last_stop; + position = src->segment.position; if (flag_segment) { GstMessage *message; message = gst_message_new_segment_done (GST_OBJECT_CAST (src), - format, last_stop); + format, position); gst_message_set_seqnum (message, src->priv->seqnum); gst_element_post_message (GST_ELEMENT_CAST (src), message); } else { @@ -2714,7 +2654,7 @@ gst_base_src_start (GstBaseSrc * basesrc) GST_OBJECT_UNLOCK (basesrc); basesrc->running = FALSE; - basesrc->priv->newsegment_pending = FALSE; + basesrc->priv->segment_pending = FALSE; bclass = GST_BASE_SRC_GET_CLASS (basesrc); if (bclass->start) @@ -2742,7 +2682,7 @@ gst_base_src_start (GstBaseSrc * basesrc) /* only update the size when operating in bytes, subclass is supposed * to set duration in the start method for other formats */ GST_OBJECT_LOCK (basesrc); - gst_segment_set_duration (&basesrc->segment, GST_FORMAT_BYTES, size); + basesrc->segment.duration = size; GST_OBJECT_UNLOCK (basesrc); } else { size = -1; @@ -3133,10 +3073,6 @@ gst_base_src_change_state (GstElement * element, GstStateChange transition) g_atomic_int_set (&basesrc->priv->pending_eos, FALSE); event_p = &basesrc->pending_seek; gst_event_replace (event_p, NULL); - event_p = &basesrc->priv->close_segment; - gst_event_replace (event_p, NULL); - event_p = &basesrc->priv->start_segment; - gst_event_replace (event_p, NULL); break; } case GST_STATE_CHANGE_READY_TO_NULL: diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 27dc3f072..d43858090 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -250,7 +250,7 @@ struct _GstBaseTransformPrivate guint64 processed; guint64 dropped; - GstClockTime last_stop_out; + GstClockTime position_out; }; static GstElementClass *parent_class = NULL; @@ -1163,13 +1163,13 @@ gst_base_transform_query (GstPad * pad, GstQuery ** query) ret = TRUE; if ((pad == trans->sinkpad) - || (trans->priv->last_stop_out == GST_CLOCK_TIME_NONE)) { + || (trans->priv->position_out == GST_CLOCK_TIME_NONE)) { pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, - trans->segment.last_stop); + trans->segment.position); } else { pos = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, - trans->priv->last_stop_out); + trans->priv->position_out); } gst_query_set_position (*query, format, pos); } else { @@ -1515,9 +1515,9 @@ gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event) trans->priv->dropped = 0; GST_OBJECT_UNLOCK (trans); /* we need new segment info after the flush. */ - trans->have_newsegment = FALSE; + trans->have_segment = FALSE; gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED); - trans->priv->last_stop_out = GST_CLOCK_TIME_NONE; + trans->priv->position_out = GST_CLOCK_TIME_NONE; break; case GST_EVENT_EOS: break; @@ -1533,36 +1533,13 @@ gst_base_transform_sink_eventfunc (GstBaseTransform * trans, GstEvent * event) forward = FALSE; break; } - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: { - GstFormat format; - gdouble rate, arate; - gint64 start, stop, time; - gboolean update; - - gst_event_parse_new_segment (event, &update, &rate, &arate, &format, - &start, &stop, &time); - - trans->have_newsegment = TRUE; - - gst_segment_set_newsegment (&trans->segment, update, rate, arate, - format, start, stop, time); - - if (format == GST_FORMAT_TIME) { - GST_DEBUG_OBJECT (trans, "received TIME NEW_SEGMENT %" GST_TIME_FORMAT - " -- %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT - ", accum %" GST_TIME_FORMAT, - GST_TIME_ARGS (trans->segment.start), - GST_TIME_ARGS (trans->segment.stop), - GST_TIME_ARGS (trans->segment.time), - GST_TIME_ARGS (trans->segment.accum)); - } else { - GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" G_GINT64_FORMAT - " -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT - ", accum %" G_GINT64_FORMAT, - trans->segment.start, trans->segment.stop, - trans->segment.time, trans->segment.accum); - } + gst_event_parse_segment (event, &trans->segment); + trans->have_segment = TRUE; + + GST_DEBUG_OBJECT (trans, "received SEGMENT %" GST_SEGMENT_FORMAT, + &trans->segment); break; } default: @@ -1896,7 +1873,7 @@ gst_base_transform_chain (GstPad * pad, GstBuffer * buffer) GstBaseTransform *trans; GstBaseTransformClass *klass; GstFlowReturn ret; - GstClockTime last_stop = GST_CLOCK_TIME_NONE; + GstClockTime position = GST_CLOCK_TIME_NONE; GstClockTime timestamp, duration; GstBuffer *outbuf = NULL; @@ -1908,9 +1885,9 @@ gst_base_transform_chain (GstPad * pad, GstBuffer * buffer) /* calculate end position of the incoming buffer */ if (timestamp != GST_CLOCK_TIME_NONE) { if (duration != GST_CLOCK_TIME_NONE) - last_stop = timestamp + duration; + position = timestamp + duration; else - last_stop = timestamp; + position = timestamp; } klass = GST_BASE_TRANSFORM_GET_CLASS (trans); @@ -1926,23 +1903,23 @@ gst_base_transform_chain (GstPad * pad, GstBuffer * buffer) * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */ if (outbuf != NULL) { if ((ret == GST_FLOW_OK)) { - GstClockTime last_stop_out = GST_CLOCK_TIME_NONE; + GstClockTime position_out = GST_CLOCK_TIME_NONE; /* Remember last stop position */ - if (last_stop != GST_CLOCK_TIME_NONE && + if (position != GST_CLOCK_TIME_NONE && trans->segment.format == GST_FORMAT_TIME) - gst_segment_set_last_stop (&trans->segment, GST_FORMAT_TIME, last_stop); + trans->segment.position = position; if (GST_BUFFER_TIMESTAMP_IS_VALID (outbuf)) { - last_stop_out = GST_BUFFER_TIMESTAMP (outbuf); + position_out = GST_BUFFER_TIMESTAMP (outbuf); if (GST_BUFFER_DURATION_IS_VALID (outbuf)) - last_stop_out += GST_BUFFER_DURATION (outbuf); - } else if (last_stop != GST_CLOCK_TIME_NONE) { - last_stop_out = last_stop; + position_out += GST_BUFFER_DURATION (outbuf); + } else if (position != GST_CLOCK_TIME_NONE) { + position_out = position; } - if (last_stop_out != GST_CLOCK_TIME_NONE + if (position_out != GST_CLOCK_TIME_NONE && trans->segment.format == GST_FORMAT_TIME) - trans->priv->last_stop_out = last_stop_out; + trans->priv->position_out = position_out; /* apply DISCONT flag if the buffer is not yet marked as such */ if (trans->priv->discont) { @@ -2030,9 +2007,9 @@ gst_base_transform_activate (GstBaseTransform * trans, gboolean active) trans->have_same_caps = trans->passthrough; GST_DEBUG_OBJECT (trans, "have_same_caps %d", trans->have_same_caps); trans->negotiated = FALSE; - trans->have_newsegment = FALSE; + trans->have_segment = FALSE; gst_segment_init (&trans->segment, GST_FORMAT_UNDEFINED); - trans->priv->last_stop_out = GST_CLOCK_TIME_NONE; + trans->priv->position_out = GST_CLOCK_TIME_NONE; trans->priv->proportion = 1.0; trans->priv->earliest_time = -1; trans->priv->discont = FALSE; diff --git a/libs/gst/base/gstbasetransform.h b/libs/gst/base/gstbasetransform.h index cdab57042..457ca4e5e 100644 --- a/libs/gst/base/gstbasetransform.h +++ b/libs/gst/base/gstbasetransform.h @@ -128,7 +128,7 @@ struct _GstBaseTransform { gboolean pending_configure; gboolean negotiated; - gboolean have_newsegment; + gboolean have_segment; /* MT-protected (with STREAM_LOCK) */ GstSegment segment; diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c index 1e4498158..a218de849 100644 --- a/libs/gst/base/gstcollectpads.c +++ b/libs/gst/base/gstcollectpads.c @@ -1198,23 +1198,12 @@ gst_collect_pads_event (GstPad * pad, GstEvent * event) gst_event_unref (event); goto done; } - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: { - gint64 start, stop, time; - gdouble rate, arate; - GstFormat format; - gboolean update; - - gst_event_parse_new_segment (event, &update, &rate, &arate, &format, - &start, &stop, &time); - - GST_DEBUG_OBJECT (data->pad, "got newsegment, start %" GST_TIME_FORMAT - ", stop %" GST_TIME_FORMAT, GST_TIME_ARGS (start), - GST_TIME_ARGS (stop)); - - gst_segment_set_newsegment (&data->segment, update, rate, arate, - format, start, stop, time); + gst_event_parse_segment (event, &data->segment); + GST_DEBUG_OBJECT (data->pad, "got newsegment %" GST_SEGMENT_FORMAT, + &data->segment); data->abidata.ABI.new_segment = TRUE; /* we must not forward this event since multiple segments will be @@ -1317,7 +1306,7 @@ gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer) GstClockTime timestamp = GST_BUFFER_TIMESTAMP (data->buffer); if (GST_CLOCK_TIME_IS_VALID (timestamp)) - gst_segment_set_last_stop (&data->segment, GST_FORMAT_TIME, timestamp); + data->segment.position = timestamp; } /* While we have data queued on this pad try to collect stuff */ diff --git a/libs/gst/check/gstconsistencychecker.c b/libs/gst/check/gstconsistencychecker.c index f7408dd47..cd0598fd6 100644 --- a/libs/gst/check/gstconsistencychecker.c +++ b/libs/gst/check/gstconsistencychecker.c @@ -35,7 +35,7 @@ struct _GstStreamConsistency { gboolean flushing; - gboolean newsegment; + gboolean segment; gboolean eos; gulong probeid; GstPad *pad; @@ -50,8 +50,8 @@ source_pad_data_cb (GstPad * pad, GstMiniObject * data, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (GST_BUFFER (data)))); /* If an EOS went through, a buffer would be invalid */ fail_if (consist->eos, "Buffer received after EOS"); - /* Buffers need to be preceded by a newsegment event */ - fail_unless (consist->newsegment, "Buffer received without newsegment"); + /* Buffers need to be preceded by a segment event */ + fail_unless (consist->segment, "Buffer received without segment"); } else if (GST_IS_EVENT (data)) { GstEvent *event = (GstEvent *) data; @@ -67,15 +67,15 @@ source_pad_data_cb (GstPad * pad, GstMiniObject * data, fail_if (consist->eos, "Received a FLUSH_STOP after an EOS"); consist->flushing = FALSE; break; - case GST_EVENT_NEWSEGMENT: - consist->newsegment = TRUE; + case GST_EVENT_SEGMENT: + consist->segment = TRUE; consist->eos = FALSE; break; case GST_EVENT_EOS: /* FIXME : not 100% sure about whether two eos in a row is valid */ fail_if (consist->eos, "Received EOS just after another EOS"); consist->eos = TRUE; - consist->newsegment = FALSE; + consist->segment = FALSE; break; case GST_EVENT_TAG: GST_DEBUG_OBJECT (pad, "tag %" GST_PTR_FORMAT, @@ -84,7 +84,7 @@ source_pad_data_cb (GstPad * pad, GstMiniObject * data, default: if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_IS_DOWNSTREAM (event)) { fail_if (consist->eos, "Event received after EOS"); - fail_unless (consist->newsegment, "Event received before newsegment"); + fail_unless (consist->segment, "Event received before segment"); } /* FIXME : Figure out what to do for other events */ break; @@ -137,7 +137,7 @@ gst_consistency_checker_reset (GstStreamConsistency * consist) { consist->eos = FALSE; consist->flushing = FALSE; - consist->newsegment = FALSE; + consist->segment = FALSE; } /** diff --git a/libs/gst/dataprotocol/dataprotocol.c b/libs/gst/dataprotocol/dataprotocol.c index b1cda553d..8b32bb806 100644 --- a/libs/gst/dataprotocol/dataprotocol.c +++ b/libs/gst/dataprotocol/dataprotocol.c @@ -523,7 +523,7 @@ gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_STOP: - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: event = gst_event_new_custom (type, NULL); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); break; |