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 720692 - audioringbuffer: track last position across release/acquire
audioringbuffer: track last position across release/acquire
Status: RESOLVED INVALID
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
unspecified
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-12-18 17:38 UTC by Vincent Penquerc'h
Modified: 2016-08-02 14:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
audioringbuffer: track last position across release/acquire (3.47 KB, patch)
2013-12-18 17:38 UTC, Vincent Penquerc'h
needs-work Details | Review
track last position across release/acquire (3.47 KB, patch)
2014-01-03 10:51 UTC, Vincent Penquerc'h
needs-work Details | Review
track last position (5.49 KB, patch)
2014-01-03 11:31 UTC, Vincent Penquerc'h
none Details | Review
do not lose track of position on caps change (2.03 KB, patch)
2014-01-16 13:57 UTC, Vincent Penquerc'h
rejected Details | Review

Description Vincent Penquerc'h 2013-12-18 17:38:29 UTC
Created attachment 264494 [details] [review]
audioringbuffer: track last position across release/acquire

If releasing and reacquiring the ring buffer, such as can happen
when doing gapless playback with playbin, the ring buffer would
get its segone reset to 0, causing it to write as much data out
as was written previously to get back to the same point. Keeping
track of the last position fixes this. The position is tracked
in samples, converted to time, and reconverted to samples with
the new sample rate, in case it changes.

This fixes playbin gapless playback with alsasink.

I'm far from certain about this not breaking other stuff. It seems to work
fine here so far.

The breakage was introduced by https://bugzilla.gnome.org/show_bug.cgi?id=697723. Hopefully it doesn't reintroduce it...
Comment 1 Sebastian Dröge (slomo) 2014-01-03 09:41:32 UTC
Review of attachment 264494 [details] [review]:

This looks generally good but

::: gst-libs/gst/audio/gstaudioringbuffer.c
@@ +691,3 @@
+  /* keep track of where were are in time, in case we get re-acquired */
+  buf->x.x.sample_base = gst_util_uint64_scale_round (buf->x.x.sample_counter,
+      GST_SECOND, buf->spec.info.rate);

This contains time for some time, and samples the remaining time. Please use two different variables to make this clear and also mark the values as invalid when they should not be used anymore

@@ +1600,2 @@
 done:
+  buf->x.x.sample_counter = *sample;

You never use the value stored in sample_counter.
Comment 2 Vincent Penquerc'h 2014-01-03 10:50:23 UTC
Thanks for reviewing,

> This contains time for some time, and samples the remaining time. Please use
> two different variables to make this clear and also mark the values as invalid
> when they should not be used anymore

OK, fixed

>  done:
> +  buf->x.x.sample_counter = *sample;
> 
> You never use the value stored in sample_counter.

I do, it is used in gst_audio_ring_buffer_release (to convert to time).
Comment 3 Vincent Penquerc'h 2014-01-03 10:51:07 UTC
Created attachment 265212 [details] [review]
track last position across release/acquire
Comment 4 Vincent Penquerc'h 2014-01-03 10:55:43 UTC
> > This contains time for some time, and samples the remaining time. Please use
> > two different variables to make this clear and also mark the values as invalid
> > when they should not be used anymore
> 
> OK, fixed

It does eat 8 more bytes off the reserved space though. 24 bytes altogether.
I'm just thinking I could make the time and sample bases a union, since their scope do not overlap. This would make them still use the same storage, but be "logically" different for clarity. Would you be OK with that, or do you think it's not worth it ?
Comment 5 Sebastian Dröge (slomo) 2014-01-03 10:57:24 UTC
(In reply to comment #2)
> Thanks for reviewing,
> 
> > This contains time for some time, and samples the remaining time. Please use
> > two different variables to make this clear and also mark the values as invalid
> > when they should not be used anymore
> 
> OK, fixed

You still store time or samples in the same variable. Please don't and use two variables for that :) After acquire() it is samples, after release() it is time.
Comment 6 Sebastian Dröge (slomo) 2014-01-03 10:58:01 UTC
(In reply to comment #4)
> > > This contains time for some time, and samples the remaining time. Please use
> > > two different variables to make this clear and also mark the values as invalid
> > > when they should not be used anymore
> > 
> > OK, fixed
> 
> It does eat 8 more bytes off the reserved space though. 24 bytes altogether.
> I'm just thinking I could make the time and sample bases a union, since their
> scope do not overlap. This would make them still use the same storage, but be
> "logically" different for clarity. Would you be OK with that, or do you think
> it's not worth it ?

Just use the instance private data. I don't think this needs to be public?
Comment 7 Vincent Penquerc'h 2014-01-03 11:03:56 UTC
Hah, I uploaded the same old patch, sorry :)

Yes, good point about private data, I will add one and use that.
Comment 8 Jan Schmidt 2014-01-03 11:15:52 UTC
I'm not sure the ringbuffer is the right place to fix this. It seems reasonable that the ringbuffer resets to reading from 0 after a release/acquire and that it's equally valid to say that the problem is the consumer (baseaudiosink / baseaudiosrc) doesn't adjust their write/read pointers after a caps change.
Comment 9 Vincent Penquerc'h 2014-01-03 11:31:00 UTC
Created attachment 265213 [details] [review]
track last position

The updated patch, this time. With a new private data struct to store the new fields.

As for ringbuffer/audiosink location, this is how this worked before before another fix change this. I'm not familiar enough with the code to really have an opinion on where it's best fixed, though the "keeping track" patch doesn't feel as clean as I'd like it to be.

What do you think, slomo ? :)
Comment 10 Sebastian Dröge (slomo) 2014-01-03 13:00:33 UTC
I think Jan currently knows more about the details in that code than I do, it's too long since I last worked on that code :) Wim might also have some opinions on this.
Comment 11 Sebastian Dröge (slomo) 2014-01-15 14:19:05 UTC
Also related: https://bugzilla.gnome.org/show_bug.cgi?id=711816#c3

Maybe that helps?
Comment 12 Vincent Penquerc'h 2014-01-16 12:25:34 UTC
No, it does not.

I thought I could not reproduce my issue, but in fact it already does not happen when playing the same file (or, I guess, files with the same raw format).

When playing files with different formats, I get the pause, with or without Jan's patch.
Comment 13 Sebastian Dröge (slomo) 2014-01-16 12:40:10 UTC
Not Jan's patch, that's just doing something related :) But his comment. I think that explains quite good what the problem is and how it should be solved.
Comment 14 Vincent Penquerc'h 2014-01-16 12:42:41 UTC
Ah. I'm trying to fix it in baseaudiosink atm.
Comment 15 Vincent Penquerc'h 2014-01-16 13:57:52 UTC
Created attachment 266465 [details] [review]
do not lose track of position on caps change

Fixes the issue in alsasink, while not breaking it in pulsesink.

Note: I have no idea what I'm doing. I got it to work by poking repeatedly at what seemed vaguely relevant. This code is obscure to me. I hope I'm not breaking another particular case...
Comment 16 Sebastian Dröge (slomo) 2014-01-21 09:11:24 UTC
Comment on attachment 266465 [details] [review]
do not lose track of position on caps change

This was introduced by 98f41f1c390e22269f3042adda29d3d345699016 and/or 587b2721c876ca70b16f568c0ce12d8675d606ca btw. Which is fixing bug #697723.

It might also make sense to revert those commits and fix things differently. Otherwise this patch seems to make sense but please also discuss with Wim before pushing.
Comment 17 Sebastian Dröge (slomo) 2014-04-07 08:28:02 UTC
Vincent, what's the status here?
Comment 18 Vincent Penquerc'h 2014-04-07 08:34:51 UTC
Status is "the patches seem to work, they're being used in a client's product, but I don't know the surrounding code enough to be 100% sure it's all fine to push".
Comment 19 Sebastian Dröge (slomo) 2014-04-07 08:45:14 UTC
Did you ask Wim about his opinion already?
Comment 20 Vincent Penquerc'h 2014-04-07 09:00:48 UTC
Hmm, I can't recall. I'll ask now as I don't see him commenting here.
Comment 21 Vincent Penquerc'h 2014-04-07 10:42:34 UTC
wtay says the caps reset should be accompanied with a call to gst_audio_clock_reset. However, where to call this is not clear:

11:29 < wtay> v_, I think someone needs to call gst_audio_clock_reset() like what pulsesink does
11:33 < wtay> v_, not sure who.. maybe audio_sink ?
11:33 < wtay> v_, I don't want it to happen in baseaudiosink because some audio clocks don't reset in acquire/release (I 
              know some use the system time)
11:37 < wtay> v_, it's all a bit suboptimal.. any subclass can just plug in their own clock and you can't make any 
              assumptions about it in the base classes..

I'm really not clear on how to do that best/correctly, but this would be another fix altogether, making my patch moot.
Comment 22 Vincent Penquerc'h 2014-04-07 10:43:14 UTC
Comment on attachment 266465 [details] [review]
do not lose track of position on caps change

See wtay's comments from IRC about resetting the clock instead.
Comment 23 Sebastian Dröge (slomo) 2014-12-22 10:00:25 UTC
What's the status here?
Comment 24 Vincent Penquerc'h 2015-01-05 14:31:11 UTC
Re-reading, it looks like my patch is not the best way to fix this. The issue I originally had was on a previous client's hardware, where my patch fixed the issue. Maybe I should just reject my patch here.
Comment 25 Sebastian Dröge (slomo) 2015-01-08 12:44:27 UTC
What should happen with this bug then?
Comment 26 Vincent Penquerc'h 2016-08-02 14:49:34 UTC
I'll close it then.