diff options
-rw-r--r-- | gst/gst.c | 2 | ||||
-rw-r--r-- | gst/gstsegment.c | 103 | ||||
-rw-r--r-- | gst/gstsegment.h | 27 | ||||
-rw-r--r-- | tests/check/gst/gstsegment.c | 24 | ||||
-rw-r--r-- | win32/common/libgstreamer.def | 1 |
5 files changed, 61 insertions, 96 deletions
@@ -669,7 +669,6 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, g_type_class_ref (gst_lock_flags_get_type ()); g_type_class_ref (gst_allocator_flags_get_type ()); g_type_class_ref (gst_stream_flags_get_type ()); - g_type_class_ref (gst_segment_result_get_type ()); _priv_gst_event_initialize (); _priv_gst_buffer_initialize (); @@ -1068,7 +1067,6 @@ gst_deinit (void) g_type_class_unref (g_type_class_peek (gst_allocator_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_stream_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_debug_color_mode_get_type ())); - g_type_class_unref (g_type_class_peek (gst_segment_result_get_type ())); gst_deinitialized = TRUE; GST_INFO ("deinitialized GStreamer"); diff --git a/gst/gstsegment.c b/gst/gstsegment.c index 78046e786..7cecf689e 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -457,95 +457,65 @@ gst_segment_to_stream_time (const GstSegment * segment, GstFormat format, * @segment: a #GstSegment structure. * @format: the format of the segment. * @position: the position in the segment - * @clip: clip against segment boundaries * @running_time: result running-time * * Translate @position to the total running time using the currently configured * segment. Compared to gst_segment_to_running_time() this function can return - * negative running-time and also check if a @position is before or after the - * segment. + * negative running-time. * * This function is typically used by elements that need to synchronize buffers * against the clock or eachother. * - * If clip is %TRUE, @position is a value between @segment start and stop. - * When @position is outside of the segment start and stop values, - * #GST_SEGMENT_RESULT_BEFORE or #GST_SEGMENT_RESULT_AFTER is returned depending - * if @position is respectively before or after the segment. + * @position can be any value and the result of this function for values outside + * of the segment is extrapolated. * - * If clip is %FALSE, @position can be any value and the result of this function - * for values outside of the segment is extrapolated. + * When 1 is returned, @position resulted in a positive running-time returned + * in @running_time. * - * When #GST_SEGMENT_RESULT_OK is returned, @position resulted in a positive - * running-time returned in @running_time. + * When this function returns -1, the returned @running_time should be negated + * to get the real negative running time. * - * When this function returns #GST_SEGMENT_RESULT_NEGATIVE, the returned - * @running_time should be negated to get the real negative running time. - * - * Returns: a #GstSegmentResult + * Returns: a 1 or -1 on success, 0 on failure. * * Since: 1.6 */ -GstSegmentResult +gint gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format, - guint64 position, gboolean clip, guint64 * running_time) + guint64 position, guint64 * running_time) { - GstSegmentResult res; + gint res = 0; guint64 result; guint64 start, stop, offset; gdouble abs_rate; if (G_UNLIKELY (position == -1)) { GST_DEBUG ("invalid position (-1)"); - res = GST_SEGMENT_RESULT_INVALID; - goto done; - } - - g_return_val_if_fail (segment != NULL, GST_SEGMENT_RESULT_INVALID); - g_return_val_if_fail (segment->format == format, GST_SEGMENT_RESULT_INVALID); - - start = segment->start; - /* before the segment boundary */ - if (clip && G_UNLIKELY (position < start)) { - GST_DEBUG ("position(%" G_GUINT64_FORMAT ") < start(%" G_GUINT64_FORMAT - ")", position, start); - if (G_LIKELY (segment->rate > 0.0)) - res = GST_SEGMENT_RESULT_BEFORE; - else - res = GST_SEGMENT_RESULT_AFTER; goto done; } - stop = segment->stop; - /* after the segment boundary */ - if (clip && G_UNLIKELY (stop != -1 && position > stop)) { - GST_DEBUG ("position(%" G_GUINT64_FORMAT ") > stop(%" G_GUINT64_FORMAT - ")", position, stop); - if (G_LIKELY (segment->rate > 0.0)) - res = GST_SEGMENT_RESULT_AFTER; - else - res = GST_SEGMENT_RESULT_BEFORE; - goto done; - } + g_return_val_if_fail (segment != NULL, 0); + g_return_val_if_fail (segment->format == format, 0); offset = segment->offset; if (G_LIKELY (segment->rate > 0.0)) { - start += offset; + start = segment->start + offset; /* bring to uncorrected position in segment */ if (position < start) { /* negative value */ result = start - position; - res = GST_SEGMENT_RESULT_NEGATIVE; + res = -1; } else { result = position - start; - res = GST_SEGMENT_RESULT_OK; + res = 1; } } else { + stop = segment->stop; + /* cannot continue if no stop position set or invalid offset */ - g_return_val_if_fail (stop != -1, GST_SEGMENT_RESULT_INVALID); - g_return_val_if_fail (stop >= segment->offset, GST_SEGMENT_RESULT_INVALID); + g_return_val_if_fail (stop != -1, 0); + g_return_val_if_fail (stop >= offset, 0); stop -= offset; @@ -553,10 +523,10 @@ gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format, if (position > stop) { /* negative value */ result = position - stop; - res = GST_SEGMENT_RESULT_NEGATIVE; + res = -1; } else { result = stop - position; - res = GST_SEGMENT_RESULT_OK; + res = 1; } } @@ -568,14 +538,14 @@ gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format, result /= abs_rate; /* correct for base of the segment */ - if (res == GST_SEGMENT_RESULT_OK) + if (res == 1) /* positive, add base */ *running_time = result + segment->base; else if (segment->base >= result) { /* negative and base is bigger, subtract from base and we have a * positive value again */ *running_time = segment->base - result; - res = GST_SEGMENT_RESULT_OK; + res = 1; } else { /* negative and base is smaller, subtract base and remainder is * negative */ @@ -588,7 +558,7 @@ done: { if (running_time) *running_time = -1; - return res; + return 0; } } @@ -616,12 +586,25 @@ gst_segment_to_running_time (const GstSegment * segment, GstFormat format, guint64 position) { guint64 result; - GstSegmentResult res; - res = - gst_segment_to_running_time_full (segment, format, position, TRUE, - &result); - if (res == GST_SEGMENT_RESULT_OK) + g_return_val_if_fail (segment != NULL, -1); + g_return_val_if_fail (segment->format == format, -1); + + /* before the segment boundary */ + if (G_UNLIKELY (position < segment->start)) { + GST_DEBUG ("position(%" G_GUINT64_FORMAT ") < start(%" G_GUINT64_FORMAT + ")", position, segment->start); + return -1; + } + /* after the segment boundary */ + if (G_UNLIKELY (segment->stop != -1 && position > segment->stop)) { + GST_DEBUG ("position(%" G_GUINT64_FORMAT ") > stop(%" G_GUINT64_FORMAT + ")", position, segment->stop); + return -1; + } + + if (gst_segment_to_running_time_full (segment, format, position, + &result) == 1) return result; return -1; diff --git a/gst/gstsegment.h b/gst/gstsegment.h index 8e9de6f01..d3c87c2ce 100644 --- a/gst/gstsegment.h +++ b/gst/gstsegment.h @@ -169,27 +169,6 @@ typedef enum { /*< flags >*/ } GstSegmentFlags; /** - * GstSegmentResult: - * @GST_SEGMENT_RESULT_INVALID: input value is invalid and no output value can - * be calculated. - * @GST_SEGMENT_RESULT_OK: value is within the segment and positive. - * @GST_SEGMENT_RESULT_NEGATIVE: value is within the segment but negative. - * @GST_SEGMENT_RESULT_BEFORE: value is outside before the segment. - * @GST_SEGMENT_RESULT_AFTER: value is outside after the segment. - * - * Possible return values from gst_segment_to_running_time_full(). - * - * Since: 1.6 - */ -typedef enum { - GST_SEGMENT_RESULT_INVALID = 0, - GST_SEGMENT_RESULT_OK = 1, - GST_SEGMENT_RESULT_NEGATIVE = -1, - GST_SEGMENT_RESULT_BEFORE = -2, - GST_SEGMENT_RESULT_AFTER = -3 -} GstSegmentResult; - -/** * GstSegment: * @flags: flags for this segment * @rate: the rate of the segment @@ -238,9 +217,9 @@ void gst_segment_init (GstSegment *segment, GstFormat for guint64 gst_segment_to_stream_time (const GstSegment *segment, GstFormat format, guint64 position); guint64 gst_segment_to_running_time (const GstSegment *segment, GstFormat format, guint64 position); -GstSegmentResult - gst_segment_to_running_time_full (const GstSegment *segment, GstFormat format, guint64 position, - gboolean clip, guint64 * running_time); + +gint gst_segment_to_running_time_full (const GstSegment *segment, GstFormat format, guint64 position, + guint64 * running_time); guint64 gst_segment_to_position (const GstSegment *segment, GstFormat format, guint64 running_time); gboolean gst_segment_set_running_time (GstSegment *segment, GstFormat format, guint64 running_time); diff --git a/tests/check/gst/gstsegment.c b/tests/check/gst/gstsegment.c index 1fc3ac9d6..867891590 100644 --- a/tests/check/gst/gstsegment.c +++ b/tests/check/gst/gstsegment.c @@ -762,24 +762,30 @@ GST_START_TEST (segment_full) check_times (&segment, 220, -1, -1); fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 50, TRUE, &rt) == GST_SEGMENT_RESULT_OK); + 50, &rt) == 1); fail_unless (rt == 0); fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 200, TRUE, &rt) == GST_SEGMENT_RESULT_OK); + 200, &rt) == 1); fail_unless (rt == 150); - fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 40, TRUE, &rt) == GST_SEGMENT_RESULT_BEFORE); - fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 49, TRUE, &rt) == GST_SEGMENT_RESULT_BEFORE); - fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 201, TRUE, &rt) == GST_SEGMENT_RESULT_AFTER); + fail_unless (!gst_segment_clip (&segment, GST_FORMAT_TIME, 40, 40, NULL, + NULL)); + fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, 40, + &rt) == -1); + fail_unless (!gst_segment_clip (&segment, GST_FORMAT_TIME, 49, 49, NULL, + NULL)); + fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, 49, + &rt) == -1); + fail_unless (!gst_segment_clip (&segment, GST_FORMAT_TIME, 201, 201, NULL, + NULL)); + fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, 201, + &rt) == 1); fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME, -50) == TRUE); fail_unless (segment.offset == 50); fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, - 50, TRUE, &rt) == GST_SEGMENT_RESULT_NEGATIVE); + 50, &rt) == -1); GST_DEBUG ("%" G_GUINT64_FORMAT, rt); fail_unless (rt == 50); } diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index e21f49800..3a45b47e9 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -1124,7 +1124,6 @@ EXPORTS gst_segment_init gst_segment_new gst_segment_offset_running_time - gst_segment_result_get_type gst_segment_set_running_time gst_segment_to_position gst_segment_to_running_time |