X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstsegment.c;h=958b39f737f83eb85cdc8109afca4a82f0a8a591;hb=0c6f5b3e4c3dc55e684bca1e3fc9a2a9b74407b9;hp=f355d4aa755256296416560d638025bedacbfca5;hpb=39664da1f07bda3032ea867fc695450b689b9d8f;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstsegment.c b/gst/gstsegment.c index f355d4a..958b39f 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -81,6 +81,12 @@ * info to stream time (which is always between 0 and the duration of the stream). */ +/* FIXME 2.0: remove unused format parameter. + * Most of the methods in gstsegment.c take and extra GstFormat format, just to + * verify segment->format == format. + * See https://bugzilla.gnome.org/show_bug.cgi?id=788979 + */ + /** * gst_segment_copy: * @segment: (transfer none): a #GstSegment @@ -386,7 +392,7 @@ gst_segment_do_seek (GstSegment * segment, gdouble rate, * negative stream-time. * * This function is typically used by elements that need to synchronize buffers - * against the clock or eachother. + * against the clock or each other. * * @position can be any value and the result of this function for values outside * of the segment is extrapolated. @@ -703,7 +709,7 @@ gst_segment_position_from_stream_time (const GstSegment * segment, * negative running-time. * * This function is typically used by elements that need to synchronize buffers - * against the clock or eachother. + * against the clock or each other. * * @position can be any value and the result of this function for values outside * of the segment is extrapolated. @@ -752,6 +758,9 @@ gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format, } else { stop = segment->stop; + if (stop == -1 && segment->duration != -1) + stop = segment->start + segment->duration; + /* cannot continue if no stop position set or invalid offset */ g_return_val_if_fail (stop != -1, 0); g_return_val_if_fail (stop >= offset, 0); @@ -986,8 +995,9 @@ gst_segment_position_from_running_time (const GstSegment * segment, * When 1 is returned, @running_time resulted in a positive position returned * in @position. * - * When this function returns -1, the returned @position should be negated - * to get the real negative segment position. + * When this function returns -1, the returned @position was < 0, and the value + * in the position variable should be negated to get the real negative segment + * position. * * Returns: a 1 or -1 on success, 0 on failure. * @@ -1030,12 +1040,15 @@ gst_segment_position_from_running_time_full (const GstSegment * segment, *position = base - running_time; if (G_UNLIKELY (abs_rate != 1.0)) *position = ceil (*position * abs_rate); - if (start + segment->offset > *position) { - *position -= start + segment->offset; - res = -1; - } else { + if (start + segment->offset >= *position) { + /* The TS is before the segment, but the result is >= 0 */ *position = start + segment->offset - *position; res = 1; + } else { + /* The TS is before the segment, and the result is < 0 + * so negate the return result */ + *position = *position - (start + segment->offset); + res = -1; } } } else { @@ -1051,15 +1064,24 @@ gst_segment_position_from_running_time_full (const GstSegment * segment, res = 1; } } else { + /* This case is tricky. Requested running time precedes the + * segment base, so in a reversed segment where rate < 0, that + * means it's before the alignment point of (stop - offset). + * Before = always bigger than (stop-offset), which is usually +ve, + * but could be -ve is offset is big enough. -ve position implies + * that the offset has clipped away the entire segment anyway */ *position = base - running_time; if (G_UNLIKELY (abs_rate != 1.0)) *position = ceil (*position * abs_rate); - if (G_UNLIKELY (stop < segment->offset - *position)) { - *position -= segment->offset - stop; - res = -1; - } else { + + if (G_LIKELY (stop + *position >= segment->offset)) { *position = stop + *position - segment->offset; res = 1; + } else { + /* Requested position is still negative because offset is big, + * so negate the result */ + *position = segment->offset - *position - stop; + res = -1; } } } @@ -1078,7 +1100,7 @@ gst_segment_position_from_running_time_full (const GstSegment * segment, * Returns: the position in the segment for @running_time. This function returns * -1 when @running_time is -1 or when it is not inside @segment. * - * Deprecated. Use gst_segment_position_from_running_time() instead. + * Deprecated: Use gst_segment_position_from_running_time() instead. */ #ifndef GST_REMOVE_DEPRECATED guint64