segment: remove redundant checks
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 27 Jul 2012 11:02:52 +0000 (13:02 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 27 Jul 2012 11:02:52 +0000 (13:02 +0200)
We don't need to check the segment format anymore because we asserted on them
being equal before.

gst/gstsegment.c

index 7ae8e60..cc4931d 100644 (file)
@@ -383,26 +383,20 @@ gst_segment_to_stream_time (const GstSegment * segment, GstFormat format,
   g_return_val_if_fail (segment != NULL, -1);
   g_return_val_if_fail (segment->format == format, -1);
 
-  /* if we have the position for the same format as the segment, we can compare
-   * the start and stop values, otherwise we assume 0 and -1 */
-  if (G_LIKELY (segment->format == format)) {
-    start = segment->start;
-    stop = segment->stop;
-    time = segment->time;
-  } else {
-    start = 0;
-    stop = -1;
-    time = 0;
-  }
+  stop = segment->stop;
 
   /* outside of the segment boundary stop */
   if (G_UNLIKELY (stop != -1 && position > stop))
     return -1;
 
+  start = segment->start;
+
   /* before the segment boundary */
   if (G_UNLIKELY (position < start))
     return -1;
 
+  time = segment->time;
+
   /* time must be known */
   if (G_UNLIKELY (time == -1))
     return -1;
@@ -457,7 +451,7 @@ gst_segment_to_running_time (const GstSegment * segment, GstFormat format,
     guint64 position)
 {
   guint64 result;
-  guint64 start, stop, base;
+  guint64 start, stop;
   gdouble abs_rate;
 
   if (G_UNLIKELY (position == -1))
@@ -466,22 +460,14 @@ gst_segment_to_running_time (const GstSegment * segment, GstFormat format,
   g_return_val_if_fail (segment != NULL, -1);
   g_return_val_if_fail (segment->format == format, -1);
 
-  /* if we have the position for the same format as the segment, we can compare
-   * the start and stop values, otherwise we assume 0 and -1 */
-  if (G_LIKELY (segment->format == format)) {
-    start = segment->start;
-    stop = segment->stop;
-    base = segment->base;
-  } else {
-    start = 0;
-    stop = -1;
-    base = 0;
-  }
+  start = segment->start;
 
   /* before the segment boundary */
   if (G_UNLIKELY (position < start))
     return -1;
 
+  stop = segment->stop;
+
   if (G_LIKELY (segment->rate > 0.0)) {
     /* outside of the segment boundary stop */
     if (G_UNLIKELY (stop != -1 && position > stop))
@@ -506,7 +492,7 @@ gst_segment_to_running_time (const GstSegment * segment, GstFormat format,
     result /= abs_rate;
 
   /* correct for base of the segment */
-  result += base;
+  result += segment->base;
 
   return result;
 }
@@ -603,17 +589,7 @@ gst_segment_to_position (const GstSegment * segment, GstFormat format,
   g_return_val_if_fail (segment != NULL, -1);
   g_return_val_if_fail (segment->format == format, FALSE);
 
-  /* if we have the position for the same format as the segment, we can compare
-   * the start and stop values, otherwise we assume 0 and -1 */
-  if (G_LIKELY (segment->format == format)) {
-    start = segment->start;
-    stop = segment->stop;
-    base = segment->base;
-  } else {
-    start = 0;
-    stop = -1;
-    base = 0;
-  }
+  base = segment->base;
 
   /* this running_time was for a previous segment */
   if (running_time < base)
@@ -627,6 +603,9 @@ gst_segment_to_position (const GstSegment * segment, GstFormat format,
   if (G_UNLIKELY (abs_rate != 1.0))
     result = ceil (result * abs_rate);
 
+  start = segment->start;
+  stop = segment->stop;
+
   if (G_LIKELY (segment->rate > 0.0)) {
     /* bring to corrected position in segment */
     result += start;