From f830f6f4ace775ee2caaba0800bbec8a9eb253b8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Nov 2006 10:27:49 +0000 Subject: [PATCH] gst/gstsegment.c: Fix boundary checking in to_running_time() and to_stream_time(). Original commit message from CVS: * gst/gstsegment.c: (gst_segment_set_seek), (gst_segment_set_newsegment_full), (gst_segment_to_stream_time), (gst_segment_to_running_time): Fix boundary checking in to_running_time() and to_stream_time(). Fixes #377183. * tests/check/gst/gstsegment.c: (GST_START_TEST): stream and running time can now be calculated for the complete clipped segment. --- ChangeLog | 12 ++++++++ gst/gstsegment.c | 6 ++-- tests/check/gst/gstsegment.c | 73 ++++++++++++++++++++++---------------------- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98c4683..3469af6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-11-20 Wim Taymans + + * gst/gstsegment.c: (gst_segment_set_seek), + (gst_segment_set_newsegment_full), (gst_segment_to_stream_time), + (gst_segment_to_running_time): + Fix boundary checking in to_running_time() and to_stream_time(). + Fixes #377183. + + * tests/check/gst/gstsegment.c: (GST_START_TEST): + stream and running time can now be calculated for the complete + clipped segment. + 2006-11-15 Tim-Philipp Müller * gst/gstpad.c: (gst_pad_push_event): diff --git a/gst/gstsegment.c b/gst/gstsegment.c index 5c32ccf..05b0d07 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -512,7 +512,7 @@ gst_segment_to_stream_time (GstSegment * segment, GstFormat format, g_return_val_if_fail (segment->format == format, -1); /* outside of the segment boundary stop */ - if (G_UNLIKELY (segment->stop != -1 && position >= segment->stop)) + if (G_UNLIKELY (segment->stop != -1 && position > segment->stop)) return -1; /* before the segment boundary */ @@ -589,7 +589,7 @@ gst_segment_to_running_time (GstSegment * segment, GstFormat format, if (segment->rate > 0.0) { /* outside of the segment boundary stop */ - if (G_UNLIKELY (segment->stop != -1 && position >= segment->stop)) + if (G_UNLIKELY (segment->stop != -1 && position > segment->stop)) return -1; /* bring to uncorrected position in segment */ @@ -597,7 +597,7 @@ gst_segment_to_running_time (GstSegment * segment, GstFormat format, } else { /* cannot continue if no stop position set or outside of * the segment. */ - if (G_UNLIKELY (segment->stop == -1 || position >= segment->stop)) + if (G_UNLIKELY (segment->stop == -1 || position > segment->stop)) return -1; /* bring to uncorrected position in segment */ diff --git a/tests/check/gst/gstsegment.c b/tests/check/gst/gstsegment.c index e3c4e0c..7dcec33 100644 --- a/tests/check/gst/gstsegment.c +++ b/tests/check/gst/gstsegment.c @@ -581,10 +581,10 @@ GST_START_TEST (segment_newsegment_streamtime) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); fail_unless (result == 100); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 200); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -635,10 +635,10 @@ GST_START_TEST (segment_newsegment_streamtime) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600); fail_unless (result == 100); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700); - fail_unless (result == -1); + fail_unless (result == 200); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800); fail_unless (result == -1); @@ -664,10 +664,10 @@ GST_START_TEST (segment_newsegment_streamtime) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600); fail_unless (result == 300); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700); - fail_unless (result == -1); + fail_unless (result == 400); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800); fail_unless (result == -1); } @@ -712,10 +712,10 @@ GST_START_TEST (segment_newsegment_streamtime_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 150); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 200); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -740,10 +740,10 @@ GST_START_TEST (segment_newsegment_streamtime_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 250); fail_unless (result == 150); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); - fail_unless (result == -1); + fail_unless (result == 200); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); fail_unless (result == -1); @@ -784,10 +784,10 @@ GST_START_TEST (segment_newsegment_streamtime_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); fail_unless (result == 300); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); - fail_unless (result == -1); + fail_unless (result == 400); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); fail_unless (result == -1); } @@ -835,10 +835,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 50); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 0); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -876,10 +876,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 300); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 400); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -917,10 +917,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 100); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 0); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -959,10 +959,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 0); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 0); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); } @@ -1011,10 +1011,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 300); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 400); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -1052,10 +1052,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 50); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 0); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -1093,10 +1093,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 50); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 0); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -1133,10 +1133,10 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate) result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); fail_unless (result == 300); - /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 400); + /* outside of the segment */ result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); } @@ -1178,10 +1178,11 @@ GST_START_TEST (segment_newsegment_runningtime) result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100); fail_unless (result == 100); - /* outside of the segment */ + /* at edge is exactly the segment duration */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200); - fail_unless (result == -1); + fail_unless (result == 200); + /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 300); fail_unless (result == -1); @@ -1236,10 +1237,10 @@ GST_START_TEST (segment_newsegment_runningtime) result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); fail_unless (result == 400); - /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); - fail_unless (result == -1); + fail_unless (result == 500); + /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); fail_unless (result == -1); @@ -1268,10 +1269,10 @@ GST_START_TEST (segment_newsegment_runningtime) result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); fail_unless (result == 600); - /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); - fail_unless (result == -1); + fail_unless (result == 500); + /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); fail_unless (result == -1); @@ -1301,10 +1302,10 @@ GST_START_TEST (segment_newsegment_runningtime) result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); fail_unless (result == 750); - /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); - fail_unless (result == -1); + fail_unless (result == 700); + /* outside of the segment */ result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); fail_unless (result == -1); -- 2.7.4