segment: handle wraparound better

Now that we use unsigned values for the segment, handle wraparound when seeking
better.
This commit is contained in:
Wim Taymans 2011-05-17 17:51:58 +02:00
parent 189980ec56
commit 82cc487776

View file

@ -265,12 +265,17 @@ gst_segment_do_seek (GstSegment * segment, gdouble rate,
/* start holds desired position, map -1 to the start */ /* start holds desired position, map -1 to the start */
if (start == -1) if (start == -1)
start = 0; start = 0;
/* start must be 0 or the formats must match */
break; break;
case GST_SEEK_TYPE_CUR: case GST_SEEK_TYPE_CUR:
{
gint64 sstart = (gint64) start;
/* add start to currently configured segment */ /* add start to currently configured segment */
if (sstart > 0 || segment->start > -sstart)
start = segment->start + start; start = segment->start + start;
else
start = 0;
break; break;
}
case GST_SEEK_TYPE_END: case GST_SEEK_TYPE_END:
if (segment->duration != -1) { if (segment->duration != -1) {
/* add start to total length */ /* add start to total length */
@ -284,7 +289,7 @@ gst_segment_do_seek (GstSegment * segment, gdouble rate,
} }
/* bring in sane range */ /* bring in sane range */
if (segment->duration != -1) if (segment->duration != -1)
start = CLAMP (start, 0, segment->duration); start = MIN (start, segment->duration);
else else
start = MAX (start, 0); start = MAX (start, 0);
@ -295,19 +300,20 @@ gst_segment_do_seek (GstSegment * segment, gdouble rate,
update_stop = FALSE; update_stop = FALSE;
break; break;
case GST_SEEK_TYPE_SET: case GST_SEEK_TYPE_SET:
/* stop holds required value, if it's not -1, it must be of the same /* stop holds required value */
* format as the segment. */
break; break;
case GST_SEEK_TYPE_CUR: case GST_SEEK_TYPE_CUR:
if (segment->stop != -1) { if (segment->stop != -1) {
/* only add compatible formats or 0 */ gint64 sstop = (gint64) stop;
if (sstop > 0 || segment->stop > -sstop)
stop = segment->stop + stop; stop = segment->stop + stop;
else
stop = 0;
} else } else
stop = -1; stop = -1;
break; break;
case GST_SEEK_TYPE_END: case GST_SEEK_TYPE_END:
if (segment->duration != -1) { if (segment->duration != -1) {
/* only add compatible formats or 0 */
stop = segment->duration + stop; stop = segment->duration + stop;
} else { } else {
stop = segment->stop; stop = segment->stop;