mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
segment: remove abs_rate from segment structure
Remove the abs_rate field from the segment structure, we can trivially compute it when needed.
This commit is contained in:
parent
b5456cc6f4
commit
d63829fc9a
4 changed files with 18 additions and 16 deletions
|
@ -170,7 +170,6 @@ gst_segment_init (GstSegment * segment, GstFormat format)
|
||||||
g_return_if_fail (segment != NULL);
|
g_return_if_fail (segment != NULL);
|
||||||
|
|
||||||
segment->rate = 1.0;
|
segment->rate = 1.0;
|
||||||
segment->abs_rate = 1.0;
|
|
||||||
segment->applied_rate = 1.0;
|
segment->applied_rate = 1.0;
|
||||||
segment->format = format;
|
segment->format = format;
|
||||||
segment->flags = 0;
|
segment->flags = 0;
|
||||||
|
@ -372,7 +371,6 @@ gst_segment_set_seek (GstSegment * segment, gdouble rate,
|
||||||
g_return_if_fail (start <= stop);
|
g_return_if_fail (start <= stop);
|
||||||
|
|
||||||
segment->rate = rate;
|
segment->rate = rate;
|
||||||
segment->abs_rate = ABS (rate);
|
|
||||||
segment->applied_rate = 1.0;
|
segment->applied_rate = 1.0;
|
||||||
segment->flags = flags;
|
segment->flags = flags;
|
||||||
segment->start = start;
|
segment->start = start;
|
||||||
|
@ -443,6 +441,7 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
|
||||||
gint64 stop, gint64 time)
|
gint64 stop, gint64 time)
|
||||||
{
|
{
|
||||||
gint64 duration, last_stop;
|
gint64 duration, last_stop;
|
||||||
|
gdouble abs_rate;
|
||||||
|
|
||||||
g_return_if_fail (rate != 0.0);
|
g_return_if_fail (rate != 0.0);
|
||||||
g_return_if_fail (applied_rate != 0.0);
|
g_return_if_fail (applied_rate != 0.0);
|
||||||
|
@ -516,15 +515,15 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
|
||||||
last_stop = stop;
|
last_stop = stop;
|
||||||
}
|
}
|
||||||
/* use previous rate to calculate duration */
|
/* use previous rate to calculate duration */
|
||||||
if (G_LIKELY (segment->abs_rate != 1.0))
|
abs_rate = ABS (segment->rate);
|
||||||
duration /= segment->abs_rate;
|
if (G_LIKELY (abs_rate != 1.0))
|
||||||
|
duration /= abs_rate;
|
||||||
|
|
||||||
/* accumulate duration */
|
/* accumulate duration */
|
||||||
segment->accum += duration;
|
segment->accum += duration;
|
||||||
|
|
||||||
/* then update the current segment */
|
/* then update the current segment */
|
||||||
segment->rate = rate;
|
segment->rate = rate;
|
||||||
segment->abs_rate = ABS (rate);
|
|
||||||
segment->applied_rate = applied_rate;
|
segment->applied_rate = applied_rate;
|
||||||
segment->start = start;
|
segment->start = start;
|
||||||
segment->last_stop = last_stop;
|
segment->last_stop = last_stop;
|
||||||
|
@ -644,6 +643,7 @@ gst_segment_to_running_time (GstSegment * segment, GstFormat format,
|
||||||
{
|
{
|
||||||
gint64 result;
|
gint64 result;
|
||||||
gint64 start, stop, accum;
|
gint64 start, stop, accum;
|
||||||
|
gdouble abs_rate;
|
||||||
|
|
||||||
if (G_UNLIKELY (position == -1))
|
if (G_UNLIKELY (position == -1))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -688,8 +688,9 @@ gst_segment_to_running_time (GstSegment * segment, GstFormat format,
|
||||||
|
|
||||||
/* scale based on the rate, avoid division by and conversion to
|
/* scale based on the rate, avoid division by and conversion to
|
||||||
* float when not needed */
|
* float when not needed */
|
||||||
if (G_UNLIKELY (segment->abs_rate != 1.0))
|
abs_rate = ABS (segment->rate);
|
||||||
result /= segment->abs_rate;
|
if (G_UNLIKELY (abs_rate != 1.0))
|
||||||
|
result /= abs_rate;
|
||||||
|
|
||||||
/* correct for accumulated segments */
|
/* correct for accumulated segments */
|
||||||
result += accum;
|
result += accum;
|
||||||
|
@ -790,6 +791,7 @@ gst_segment_to_position (GstSegment * segment, GstFormat format,
|
||||||
{
|
{
|
||||||
gint64 result;
|
gint64 result;
|
||||||
gint64 start, stop, accum;
|
gint64 start, stop, accum;
|
||||||
|
gdouble abs_rate;
|
||||||
|
|
||||||
g_return_val_if_fail (segment != NULL, -1);
|
g_return_val_if_fail (segment != NULL, -1);
|
||||||
|
|
||||||
|
@ -819,8 +821,9 @@ gst_segment_to_position (GstSegment * segment, GstFormat format,
|
||||||
result = running_time - accum;
|
result = running_time - accum;
|
||||||
|
|
||||||
/* move into the segment at the right rate */
|
/* move into the segment at the right rate */
|
||||||
if (G_UNLIKELY (segment->abs_rate != 1.0))
|
abs_rate = ABS (segment->rate);
|
||||||
result = ceil (result * segment->abs_rate);
|
if (G_UNLIKELY (abs_rate != 1.0))
|
||||||
|
result = ceil (result * abs_rate);
|
||||||
|
|
||||||
if (G_LIKELY (segment->rate > 0.0)) {
|
if (G_LIKELY (segment->rate > 0.0)) {
|
||||||
/* bring to corrected position in segment */
|
/* bring to corrected position in segment */
|
||||||
|
|
|
@ -35,7 +35,6 @@ typedef struct _GstSegment GstSegment;
|
||||||
/**
|
/**
|
||||||
* GstSegment:
|
* GstSegment:
|
||||||
* @rate: the rate of the segment
|
* @rate: the rate of the segment
|
||||||
* @abs_rate: absolute value of @rate
|
|
||||||
* @format: the format of the segment values
|
* @format: the format of the segment values
|
||||||
* @flags: flags for this segment
|
* @flags: flags for this segment
|
||||||
* @start: the start of the segment
|
* @start: the start of the segment
|
||||||
|
@ -52,7 +51,6 @@ typedef struct _GstSegment GstSegment;
|
||||||
struct _GstSegment {
|
struct _GstSegment {
|
||||||
/*< public >*/
|
/*< public >*/
|
||||||
gdouble rate;
|
gdouble rate;
|
||||||
gdouble abs_rate;
|
|
||||||
gdouble applied_rate;
|
gdouble applied_rate;
|
||||||
GstFormat format;
|
GstFormat format;
|
||||||
GstSeekFlags flags;
|
GstSeekFlags flags;
|
||||||
|
|
|
@ -1629,7 +1629,6 @@ start_stepping (GstBaseSink * sink, GstSegment * segment,
|
||||||
/* set the new rate for the remainder of the segment */
|
/* set the new rate for the remainder of the segment */
|
||||||
current->start_rate = segment->rate;
|
current->start_rate = segment->rate;
|
||||||
segment->rate *= current->rate;
|
segment->rate *= current->rate;
|
||||||
segment->abs_rate = ABS (segment->rate);
|
|
||||||
|
|
||||||
/* save values */
|
/* save values */
|
||||||
if (segment->rate > 0.0)
|
if (segment->rate > 0.0)
|
||||||
|
@ -1717,7 +1716,6 @@ stop_stepping (GstBaseSink * sink, GstSegment * segment,
|
||||||
|
|
||||||
/* restore the previous rate */
|
/* restore the previous rate */
|
||||||
segment->rate = current->start_rate;
|
segment->rate = current->start_rate;
|
||||||
segment->abs_rate = ABS (segment->rate);
|
|
||||||
|
|
||||||
if (segment->rate > 0.0)
|
if (segment->rate > 0.0)
|
||||||
segment->stop = current->start_stop;
|
segment->stop = current->start_stop;
|
||||||
|
@ -1755,6 +1753,7 @@ handle_stepping (GstBaseSink * sink, GstSegment * segment,
|
||||||
{
|
{
|
||||||
guint64 end;
|
guint64 end;
|
||||||
gint64 first, last;
|
gint64 first, last;
|
||||||
|
gdouble abs_rate;
|
||||||
|
|
||||||
if (segment->rate > 0.0) {
|
if (segment->rate > 0.0) {
|
||||||
if (segment->stop == *cstop)
|
if (segment->stop == *cstop)
|
||||||
|
@ -1773,8 +1772,9 @@ handle_stepping (GstBaseSink * sink, GstSegment * segment,
|
||||||
end = current->start + current->amount;
|
end = current->start + current->amount;
|
||||||
current->position = first - current->start;
|
current->position = first - current->start;
|
||||||
|
|
||||||
if (G_UNLIKELY (segment->abs_rate != 1.0))
|
abs_rate = ABS (segment->rate);
|
||||||
current->position /= segment->abs_rate;
|
if (G_UNLIKELY (abs_rate != 1.0))
|
||||||
|
current->position /= abs_rate;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (sink,
|
GST_DEBUG_OBJECT (sink,
|
||||||
"buffer: %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
|
"buffer: %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
|
||||||
|
|
|
@ -934,7 +934,8 @@ gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
|
||||||
if (running_time <= segment->accum)
|
if (running_time <= segment->accum)
|
||||||
return segment->start;
|
return segment->start;
|
||||||
else
|
else
|
||||||
return (running_time - segment->accum) * segment->abs_rate + segment->start;
|
return (running_time - segment->accum) * ABS (segment->rate) +
|
||||||
|
segment->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue