segment: Modifiy inside segment condition
authorSeungha Yang <sh.yang@lge.com>
Fri, 15 Apr 2016 11:54:42 +0000 (20:54 +0900)
committerEdward Hervey <bilboed@bilboed.com>
Tue, 31 Jan 2017 14:55:12 +0000 (15:55 +0100)
There is a special case that segment_start == segment_stop == start.
It's inside of segment

https://bugzilla.gnome.org/show_bug.cgi?id=764707

gst/gstsegment.c
tests/check/gst/gstsegment.c

index 8d4183e..8db09df 100644 (file)
@@ -884,8 +884,11 @@ gst_segment_clip (const GstSegment * segment, GstFormat format, guint64 start,
   g_return_val_if_fail (segment->format == format, FALSE);
 
   /* if we have a stop position and a valid start and start is bigger,
-   * we're outside of the segment */
-  if (G_UNLIKELY (segment->stop != -1 && start != -1 && start >= segment->stop))
+   * we're outside of the segment. (Special case) segment start and
+   * segment stop can be identical. In this case, if start is also identical,
+   * it's inside of segment */
+  if (G_UNLIKELY (segment->stop != -1 && start != -1 && (start > segment->stop
+              || (segment->start != segment->stop && start == segment->stop))))
     return FALSE;
 
   /* if a stop position is given and is before the segment start,
index f3433e8..60a0d6f 100644 (file)
@@ -345,6 +345,62 @@ GST_START_TEST (segment_seek_size)
   fail_unless (update == FALSE);
   check_times (&segment, 200, 200, 0);
 
+  /* special case, segment's start and stop are identical */
+  /* completely outside */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
+  fail_unless (res == FALSE);
+
+  /* completely outside also */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
+      250, 300, &cstart, &cstop);
+  fail_unless (res == FALSE);
+
+  /* stop at boundary point. it's outside because stop is exclusive */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
+      100, 200, &cstart, &cstop);
+  fail_unless (res == FALSE);
+
+  /* touching boundary point. it's inside because start at segment start */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
+      200, 300, &cstart, &cstop);
+  fail_unless (res == TRUE);
+  fail_unless (cstart == 200);
+  fail_unless (cstop == 200);
+
+  /* completely inside */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
+      200, 200, &cstart, &cstop);
+  fail_unless (res == TRUE);
+  fail_unless (cstart == 200);
+  fail_unless (cstop == 200);
+
+  /* exclusively cover boundary point */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
+      150, 250, &cstart, &cstop);
+  fail_unless (res == TRUE);
+  fail_unless (cstart == 200);
+  fail_unless (cstop == 200);
+
+  /* invalid start */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 200, &cstart, &cstop);
+  fail_unless (res == FALSE);
+
+  /* start outside */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
+  fail_unless (res == TRUE);
+  fail_unless (cstart == 200);
+  fail_unless (cstop == 200);
+
+  /* start on boundary point */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop);
+  fail_unless (res == TRUE);
+  fail_unless (cstart == 200);
+  fail_unless (cstop == 200);
+
+  /* start completely outside */
+  res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
+  fail_unless (res == FALSE);
+
   /* seek relative to end */
   gst_segment_do_seek (&segment, 1.0,
       GST_FORMAT_BYTES,