After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 792434 - gstbasesink: Include segment.offset in the computation of position
gstbasesink: Include segment.offset in the computation of position
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 1.13.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-01-11 17:20 UTC by Alicia Boya García
Modified: 2018-02-16 13:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (1.91 KB, patch)
2018-01-11 17:20 UTC, Alicia Boya García
reviewed Details | Review
gstbasesink: Include segment.offset in the computation of position (3.68 KB, patch)
2018-02-13 19:47 UTC, Alicia Boya García
committed Details | Review

Description Alicia Boya García 2018-01-11 17:20:45 UTC
Created attachment 366674 [details] [review]
Patch

Position queries with GST_FORMAT_TIME are supposed to return stream
time.

gst_base_sink_get_position() estimates the current stream time on its
own instead of using gst_segment_to_stream_time(), but the algorithm
used was not taking segment.offset into account, resulting in invalid
values when this field was set to a non-zero value.
Comment 1 Thibault Saunier 2018-01-11 17:58:44 UTC
Review of attachment 366674 [details] [review]:

This actually looks correct to me and corresponds to what has been defined in the design doc[0] now I wonder why and how it has not been detected before!

I would rather have someone else review it to confirm.

[0] https://gstreamer.freedesktop.org/documentation/design/synchronisation.html#stream-time
Comment 2 Sebastian Dröge (slomo) 2018-01-11 18:08:46 UTC
It should basically be like gst_segment_to_stream_time(), which also does not seem to use the offset. Which IIRC also makes sense because offset is related to running time, not stream time.

Why do you think this is correct? Note that the calculations in the design docs seem to be all about running time, and how to get from there to the stream time.
Comment 3 Nicolas Dufresne (ndufresne) 2018-01-11 18:14:43 UTC
As the doc mention, offset is in the same scale as the buffer timestamp. But it still need to be scaled according tot he applied_rate.

"The amount (in buffer timestamps) that has already been elapsed in the segment"
Comment 4 Thibault Saunier 2018-01-11 20:23:06 UTC
(In reply to Sebastian Dröge (slomo) from comment #2)
> It should basically be like gst_segment_to_stream_time(), which also does
> not seem to use the offset. Which IIRC also makes sense because offset is
> related to running time, not stream time.

> Why do you think this is correct? Note that the calculations in the design docs seem to be all about running time, and how to get from there to the stream time.

My first understanding was also that `segment.offset` only applies to the running_time but then I read the design doc again and the final formula with the following statement: "This last formula is typically used in sinks to report the current position in an accurate and efficient way.". The formula:

    stream_time = (S.offset + (absolute_time - base_time - S.base) * ABS (S.rate)) * ABS (S.applied_rate) + S.time

From my reading and understanding of the code in `gst_basesink_get_position` we are using this exact formula modulo the addition of `S.offset`, thus my statement that this patch looks correct to me. Now afaiu, in `gst_segment_to_stream_time()` we use:

    stream_time = (position - S.start) * ABS (S.applied_rate) + S.time

which indeed does not take `S.offset` into account.

Afaiu from the design doc those formulas are equivalent.

Now I am confused and might be mistaking or have misunderstood the code :-)
Comment 5 Sebastian Dröge (slomo) 2018-01-12 09:41:03 UTC
Yes the offset seems to have to be taken into account when calculating the stream time from the running time like basesink does. I'm not sure why it does not cause problems nowadays when using a segment with offset!=0 (e.g. from pad offsets).

Can someone create a unit test for this that fails with the current behaviour and succeeds with the new patch?
Comment 6 Alicia Boya García 2018-02-09 12:00:14 UTC
(In reply to Sebastian Dröge (slomo) from comment #5)
> I'm not sure why it does not cause problems nowadays when using a segment with offset!=0 (e.g. from pad offsets).

Maybe it was too small to be noticed.
Comment 7 Alicia Boya García 2018-02-13 19:47:38 UTC
Created attachment 368325 [details] [review]
gstbasesink: Include segment.offset in the computation of position

Position queries with GST_FORMAT_TIME are supposed to return stream
time.

gst_base_sink_get_position() estimates the current stream time on its
own instead of using gst_segment_to_stream_time(), but the algorithm
used was not taking segment.offset into account, resulting in invalid
values when this field was set to a non-zero value.
Comment 8 Alicia Boya García 2018-02-13 19:49:23 UTC
(In reply to Sebastian Dröge (slomo) from comment #5)
>
> Can someone create a unit test for this that fails with the current
> behaviour and succeeds with the new patch?

You can find a unit test in the patch I just uploaded.
Comment 9 Thibault Saunier 2018-02-16 13:14:18 UTC
Review of attachment 368325 [details] [review]:

lgtm
Comment 10 Thibault Saunier 2018-02-16 13:37:16 UTC
Attachment 368325 [details] pushed as 65dcb2a - gstbasesink: Include segment.offset in the computation of position