- segment->last_stop = last_stop;
-}
-
-/**
- * gst_segment_set_newsegment:
- * @segment: a #GstSegment structure.
- * @update: flag indicating a new segment is started or updated
- * @rate: the rate of the segment.
- * @applied_rate: the applied rate of the segment.
- * @format: the format of the segment.
- * @start: the new start value
- * @stop: the new stop value
- * @time: the new stream time
- *
- * Update the segment structure with the field values of a new segment event.
- */
-void
-gst_segment_set_newsegment (GstSegment * segment, gboolean update,
- gdouble rate, gdouble applied_rate, GstFormat format, gint64 start,
- gint64 stop, gint64 time)
-{
- gint64 duration, last_stop;
- gdouble abs_rate;
-
- g_return_if_fail (rate != 0.0);
- g_return_if_fail (applied_rate != 0.0);
- g_return_if_fail (segment != NULL);
-
- GST_DEBUG ("configuring segment update %d, rate %lf, format %s, "
- "start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT ", position %"
- G_GINT64_FORMAT, update, rate, gst_format_get_name (format), start,
- stop, time);
- GST_DEBUG ("old segment was: %" GST_SEGMENT_FORMAT, segment);
-
- if (G_UNLIKELY (segment->format == GST_FORMAT_UNDEFINED))
- segment->format = format;
-
- /* any other format with 0 also gives time 0, the other values are
- * invalid in the format though. */
- if (format != segment->format && start == 0) {
- format = segment->format;
- if (stop != 0)
- stop = -1;
- if (time != 0)
- time = -1;
- }
-
- g_return_if_fail (segment->format == format);
-
- if (update) {
- if (G_LIKELY (segment->rate > 0.0)) {
- /* an update to the current segment is done, elapsed time is
- * difference between the old start and new start. */
- if (start > segment->start)
- duration = start - segment->start;
- else
- duration = 0;
- } else {
- /* for negative rates, the elapsed duration is the diff between the stop
- * positions */
- if (stop != -1 && stop < segment->stop)
- duration = segment->stop - stop;
- else
- duration = 0;
- }
- /* update last_stop to be a valid value in the updated segment */
- if (start > segment->last_stop)
- last_stop = start;
- else if (stop != -1 && stop < segment->last_stop)
- last_stop = stop;
- else
- last_stop = segment->last_stop;
- } else {
- /* the new segment has to be aligned with the old segment.
- * We first update the accumulated time of the previous
- * segment. the accumulated time is used when syncing to the
- * clock. */
- if (segment->stop != -1) {
- duration = segment->stop - segment->start;
- } else if (segment->last_stop != -1) {
- /* else use last seen timestamp as segment stop */
- duration = segment->last_stop - segment->start;
- } else {
- /* else we don't know and throw a warning.. really, this should
- * be fixed in the element. */
- g_warning ("closing segment of unknown duration, assuming duration of 0");
- duration = 0;
- }
- /* position the last_stop to the next expected position in the new segment,
- * which is the start or the stop of the segment */
- if (rate > 0.0)
- last_stop = start;
- else
- last_stop = stop;
- }
- /* use previous rate to calculate duration */
- abs_rate = ABS (segment->rate);
- if (G_LIKELY (abs_rate != 1.0))
- duration /= abs_rate;
-
- /* accumulate duration */
- segment->accum += duration;