mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
segment: remove the bounds check from _to_running_time_full()
Do not do any checks for the start/stop in the new gst_segment_to_running_time_full() method, we can let this be done by the more capable gst_segment_clip() method. This allows us to remove the enum of results and only return the sign of the calculated running-time. We need to put the old clipping checks in the old gst_segment_to_running_time() still because they work slightly differently than the _clip methods. See https://bugzilla.gnome.org/show_bug.cgi?id=740575
This commit is contained in:
parent
edf484ab6b
commit
bc282da83c
5 changed files with 61 additions and 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_lock_flags_get_type ());
|
||||||
g_type_class_ref (gst_allocator_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_stream_flags_get_type ());
|
||||||
g_type_class_ref (gst_segment_result_get_type ());
|
|
||||||
|
|
||||||
_priv_gst_event_initialize ();
|
_priv_gst_event_initialize ();
|
||||||
_priv_gst_buffer_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_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_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_debug_color_mode_get_type ()));
|
||||||
g_type_class_unref (g_type_class_peek (gst_segment_result_get_type ()));
|
|
||||||
|
|
||||||
gst_deinitialized = TRUE;
|
gst_deinitialized = TRUE;
|
||||||
GST_INFO ("deinitialized GStreamer");
|
GST_INFO ("deinitialized GStreamer");
|
||||||
|
|
103
gst/gstsegment.c
103
gst/gstsegment.c
|
@ -457,95 +457,65 @@ gst_segment_to_stream_time (const GstSegment * segment, GstFormat format,
|
||||||
* @segment: a #GstSegment structure.
|
* @segment: a #GstSegment structure.
|
||||||
* @format: the format of the segment.
|
* @format: the format of the segment.
|
||||||
* @position: the position in the segment
|
* @position: the position in the segment
|
||||||
* @clip: clip against segment boundaries
|
|
||||||
* @running_time: result running-time
|
* @running_time: result running-time
|
||||||
*
|
*
|
||||||
* Translate @position to the total running time using the currently configured
|
* Translate @position to the total running time using the currently configured
|
||||||
* segment. Compared to gst_segment_to_running_time() this function can return
|
* 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
|
* negative running-time.
|
||||||
* segment.
|
|
||||||
*
|
*
|
||||||
* This function is typically used by elements that need to synchronize buffers
|
* This function is typically used by elements that need to synchronize buffers
|
||||||
* against the clock or eachother.
|
* against the clock or eachother.
|
||||||
*
|
*
|
||||||
* If clip is %TRUE, @position is a value between @segment start and stop.
|
* @position can be any value and the result of this function for values outside
|
||||||
* When @position is outside of the segment start and stop values,
|
* of the segment is extrapolated.
|
||||||
* #GST_SEGMENT_RESULT_BEFORE or #GST_SEGMENT_RESULT_AFTER is returned depending
|
|
||||||
* if @position is respectively before or after the segment.
|
|
||||||
*
|
*
|
||||||
* If clip is %FALSE, @position can be any value and the result of this function
|
* When 1 is returned, @position resulted in a positive running-time returned
|
||||||
* for values outside of the segment is extrapolated.
|
* in @running_time.
|
||||||
*
|
*
|
||||||
* When #GST_SEGMENT_RESULT_OK is returned, @position resulted in a positive
|
* When this function returns -1, the returned @running_time should be negated
|
||||||
* running-time returned in @running_time.
|
* to get the real negative running time.
|
||||||
*
|
*
|
||||||
* When this function returns #GST_SEGMENT_RESULT_NEGATIVE, the returned
|
* Returns: a 1 or -1 on success, 0 on failure.
|
||||||
* @running_time should be negated to get the real negative running time.
|
|
||||||
*
|
|
||||||
* Returns: a #GstSegmentResult
|
|
||||||
*
|
*
|
||||||
* Since: 1.6
|
* Since: 1.6
|
||||||
*/
|
*/
|
||||||
GstSegmentResult
|
gint
|
||||||
gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format,
|
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 result;
|
||||||
guint64 start, stop, offset;
|
guint64 start, stop, offset;
|
||||||
gdouble abs_rate;
|
gdouble abs_rate;
|
||||||
|
|
||||||
if (G_UNLIKELY (position == -1)) {
|
if (G_UNLIKELY (position == -1)) {
|
||||||
GST_DEBUG ("invalid position (-1)");
|
GST_DEBUG ("invalid position (-1)");
|
||||||
res = GST_SEGMENT_RESULT_INVALID;
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (segment != NULL, GST_SEGMENT_RESULT_INVALID);
|
g_return_val_if_fail (segment != NULL, 0);
|
||||||
g_return_val_if_fail (segment->format == format, GST_SEGMENT_RESULT_INVALID);
|
g_return_val_if_fail (segment->format == format, 0);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = segment->offset;
|
offset = segment->offset;
|
||||||
|
|
||||||
if (G_LIKELY (segment->rate > 0.0)) {
|
if (G_LIKELY (segment->rate > 0.0)) {
|
||||||
start += offset;
|
start = segment->start + offset;
|
||||||
|
|
||||||
/* bring to uncorrected position in segment */
|
/* bring to uncorrected position in segment */
|
||||||
if (position < start) {
|
if (position < start) {
|
||||||
/* negative value */
|
/* negative value */
|
||||||
result = start - position;
|
result = start - position;
|
||||||
res = GST_SEGMENT_RESULT_NEGATIVE;
|
res = -1;
|
||||||
} else {
|
} else {
|
||||||
result = position - start;
|
result = position - start;
|
||||||
res = GST_SEGMENT_RESULT_OK;
|
res = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
stop = segment->stop;
|
||||||
|
|
||||||
/* cannot continue if no stop position set or invalid offset */
|
/* 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 != -1, 0);
|
||||||
g_return_val_if_fail (stop >= segment->offset, GST_SEGMENT_RESULT_INVALID);
|
g_return_val_if_fail (stop >= offset, 0);
|
||||||
|
|
||||||
stop -= offset;
|
stop -= offset;
|
||||||
|
|
||||||
|
@ -553,10 +523,10 @@ gst_segment_to_running_time_full (const GstSegment * segment, GstFormat format,
|
||||||
if (position > stop) {
|
if (position > stop) {
|
||||||
/* negative value */
|
/* negative value */
|
||||||
result = position - stop;
|
result = position - stop;
|
||||||
res = GST_SEGMENT_RESULT_NEGATIVE;
|
res = -1;
|
||||||
} else {
|
} else {
|
||||||
result = stop - position;
|
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;
|
result /= abs_rate;
|
||||||
|
|
||||||
/* correct for base of the segment */
|
/* correct for base of the segment */
|
||||||
if (res == GST_SEGMENT_RESULT_OK)
|
if (res == 1)
|
||||||
/* positive, add base */
|
/* positive, add base */
|
||||||
*running_time = result + segment->base;
|
*running_time = result + segment->base;
|
||||||
else if (segment->base >= result) {
|
else if (segment->base >= result) {
|
||||||
/* negative and base is bigger, subtract from base and we have a
|
/* negative and base is bigger, subtract from base and we have a
|
||||||
* positive value again */
|
* positive value again */
|
||||||
*running_time = segment->base - result;
|
*running_time = segment->base - result;
|
||||||
res = GST_SEGMENT_RESULT_OK;
|
res = 1;
|
||||||
} else {
|
} else {
|
||||||
/* negative and base is smaller, subtract base and remainder is
|
/* negative and base is smaller, subtract base and remainder is
|
||||||
* negative */
|
* negative */
|
||||||
|
@ -588,7 +558,7 @@ done:
|
||||||
{
|
{
|
||||||
if (running_time)
|
if (running_time)
|
||||||
*running_time = -1;
|
*running_time = -1;
|
||||||
return res;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,12 +586,25 @@ gst_segment_to_running_time (const GstSegment * segment, GstFormat format,
|
||||||
guint64 position)
|
guint64 position)
|
||||||
{
|
{
|
||||||
guint64 result;
|
guint64 result;
|
||||||
GstSegmentResult res;
|
|
||||||
|
|
||||||
res =
|
g_return_val_if_fail (segment != NULL, -1);
|
||||||
gst_segment_to_running_time_full (segment, format, position, TRUE,
|
g_return_val_if_fail (segment->format == format, -1);
|
||||||
&result);
|
|
||||||
if (res == GST_SEGMENT_RESULT_OK)
|
/* 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 result;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -168,27 +168,6 @@ typedef enum { /*< flags >*/
|
||||||
GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO = GST_SEEK_FLAG_TRICKMODE_NO_AUDIO
|
GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO = GST_SEEK_FLAG_TRICKMODE_NO_AUDIO
|
||||||
} GstSegmentFlags;
|
} 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:
|
* GstSegment:
|
||||||
* @flags: flags for this segment
|
* @flags: flags for this 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_stream_time (const GstSegment *segment, GstFormat format, guint64 position);
|
||||||
guint64 gst_segment_to_running_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,
|
gint gst_segment_to_running_time_full (const GstSegment *segment, GstFormat format, guint64 position,
|
||||||
gboolean clip, guint64 * running_time);
|
guint64 * running_time);
|
||||||
guint64 gst_segment_to_position (const GstSegment *segment, GstFormat format, 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);
|
gboolean gst_segment_set_running_time (GstSegment *segment, GstFormat format, guint64 running_time);
|
||||||
|
|
|
@ -762,24 +762,30 @@ GST_START_TEST (segment_full)
|
||||||
check_times (&segment, 220, -1, -1);
|
check_times (&segment, 220, -1, -1);
|
||||||
|
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
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 (rt == 0);
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
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 (rt == 150);
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
fail_unless (!gst_segment_clip (&segment, GST_FORMAT_TIME, 40, 40, NULL,
|
||||||
40, TRUE, &rt) == GST_SEGMENT_RESULT_BEFORE);
|
NULL));
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME, 40,
|
||||||
49, TRUE, &rt) == GST_SEGMENT_RESULT_BEFORE);
|
&rt) == -1);
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
fail_unless (!gst_segment_clip (&segment, GST_FORMAT_TIME, 49, 49, NULL,
|
||||||
201, TRUE, &rt) == GST_SEGMENT_RESULT_AFTER);
|
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,
|
fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME,
|
||||||
-50) == TRUE);
|
-50) == TRUE);
|
||||||
fail_unless (segment.offset == 50);
|
fail_unless (segment.offset == 50);
|
||||||
|
|
||||||
fail_unless (gst_segment_to_running_time_full (&segment, GST_FORMAT_TIME,
|
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);
|
GST_DEBUG ("%" G_GUINT64_FORMAT, rt);
|
||||||
fail_unless (rt == 50);
|
fail_unless (rt == 50);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1124,7 +1124,6 @@ EXPORTS
|
||||||
gst_segment_init
|
gst_segment_init
|
||||||
gst_segment_new
|
gst_segment_new
|
||||||
gst_segment_offset_running_time
|
gst_segment_offset_running_time
|
||||||
gst_segment_result_get_type
|
|
||||||
gst_segment_set_running_time
|
gst_segment_set_running_time
|
||||||
gst_segment_to_position
|
gst_segment_to_position
|
||||||
gst_segment_to_running_time
|
gst_segment_to_running_time
|
||||||
|
|
Loading…
Reference in a new issue