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 617339 - pulsesink doesn't make use of pa_stream_begin_write
pulsesink doesn't make use of pa_stream_begin_write
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other Linux
: Normal normal
: 0.10.24
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks: 620540
 
 
Reported: 2010-04-30 23:53 UTC by Pierre Bossart
Modified: 2010-06-09 14:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch against git master (5.84 KB, patch)
2010-04-30 23:53 UTC, Pierre Bossart
none Details | Review
2nd patch- limits internal buffering (2.66 KB, patch)
2010-05-06 01:46 UTC, Pierre Bossart
none Details | Review
3rd patch- test for NULL buffer (921 bytes, patch)
2010-05-06 01:55 UTC, Pierre Bossart
none Details | Review
4th patch - reset variables (819 bytes, patch)
2010-05-06 01:56 UTC, Pierre Bossart
none Details | Review
combined patch, limits buffering to latency-time and uses PA_SEEK_ABSOLUTE mode (7.41 KB, patch)
2010-06-02 00:01 UTC, Pierre Bossart
committed Details | Review

Description Pierre Bossart 2010-04-30 23:53:42 UTC
Created attachment 160029 [details] [review]
patch against git master

The current version of pulsesink creates a lot of overhead. For example, when decoding mp3, it'll send 4608 bytes at once, even when the latency was specified as 'don't care' with a large buffer-time/tlength value.

The proposed solution (patch attached) relies on a shm buffer provided by pulse audio. PCM samples are copied into this buffer, and it's flushed when there's no space left. This saves a lots of useless overhead and helps reduce power consumption. On a Menlow platform this help go from 12% C0 to 9%. We use this patch for all power/performance measurements at Intel, and we might as well contribute it to the community.

This solution works only with PulseAudio >0.9.16 (about a year old). The patch has not been tested for the case where the 'toy resampler' is used, mainly since I don't know how to test it.

An additional improvement could be to flush the buffer when the latency-time value was reached. Flushing the buffer when it is full could be an issue for low-latency apps.

Feedback welcome.
Comment 1 Stefan Sauer (gstreamer, gtkdoc dev) 2010-05-05 12:53:26 UTC
Review of attachment 160029 [details] [review]:

The patch looks quite good to me. I wonder if thinks could be refactored somewhat to reduce the copy and paste between the the two branches of the #ifdef HAVE_PULSE_0_9_16 in gst_pulseringbuffer_commit(). Maybe some static inline functions. Should a similar change also be made for the source?

::: ext/pulse/pulsesink.c
@@ +1257,3 @@
+    GST_LOG_OBJECT (psink,
+        "need to write %d samples at offset %" G_GINT64_FORMAT, *toprocess,
+        offset);

the log statement could stay out of the ifdef (its the same in #else)
Comment 2 Sebastian Dröge (slomo) 2010-05-05 12:56:19 UTC
One thing I noticed is, that you should a) reset m_data, m_writable and m_towrite when canceling a write and b) should check if m_data is non-NULL before flushing the buffer.

I think, before this can get in we should make sure, that never more than latency_time samples are pending.
Comment 3 Pierre Bossart 2010-05-05 15:38:06 UTC
Agree that the code is a bit thick with the ifdef. I wanted functionality first...

Yes, clamping the writable size to latency_time would make sense. This was one of the options I indicated.

I will do some additional tests, edits and resubmit the patch based on these comments.
Comment 4 Pierre Bossart 2010-05-06 01:46:36 UTC
Created attachment 160390 [details] [review]
2nd patch- limits internal buffering

to be applied on top of first patch.
changed from PA_SEEK_ABSOLUTE to PA_SEEK_RELATIVE to simplify offset management
Comment 5 Pierre Bossart 2010-05-06 01:55:18 UTC
Created attachment 160391 [details] [review]
3rd patch- test for NULL buffer

to be applied on top of 2 first patches
Comment 6 Pierre Bossart 2010-05-06 01:56:25 UTC
Created attachment 160392 [details] [review]
4th patch - reset variables

forgot to add this one
Comment 7 Sebastian Dröge (slomo) 2010-05-06 05:57:10 UTC
(In reply to comment #4)
> Created an attachment (id=160390) [details] [review]
> 2nd patch- limits internal buffering
> 
> to be applied on top of first patch.
> changed from PA_SEEK_ABSOLUTE to PA_SEEK_RELATIVE to simplify offset management

What's the advantage of doing this? The non shm variant still needs to do the offset management anyway

And you're only flushing the buffer for latency-time the next try, wouldn't it be better to flush it immediately if latency-time is reached?
Comment 8 Stefan Sauer (gstreamer, gtkdoc dev) 2010-05-06 12:10:36 UTC
I also think we had problems with PA_SEEK_RELATIVE in the past:

commit abee4f1d644dd79fe8a74884a513872ec17b5047
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Tue Aug 25 16:53:29 2009 +0200

    pulsesink: don't use relative seeks
    
    Don't use relative seeks, it's too hard to track where we are after a flush
    etc.
    
    fixes #593015


I'd also prefer to have a cumulative patch for the topic.
Comment 9 Pierre Bossart 2010-05-27 23:43:50 UTC
Good points.
Honestly I used SEEK_RELATIVE because I didn't understand why this is was an ABSOLUTE_SEEK in the first place, and it made my life simpler. What's unclear to me is whether the offset can have discontinuities between two calls to ringbuffer-commit, and how I could test this. If jumps in the offset parameters are possible then I probably need to do some additional work.
Comment 10 Alessandro Decina 2010-05-28 09:02:44 UTC
It can. You can test with a live pipeline or you can go PLAYING -> PAUSED -> PLAYING and the offset should be unaligned.
Comment 11 Pierre Bossart 2010-06-02 00:01:35 UTC
Created attachment 162508 [details] [review]
combined patch, limits buffering to latency-time and uses PA_SEEK_ABSOLUTE mode

here's a combined patch aginst git master that hopefully addresses all concerns on buffering limitation, use of SEEK_ABSOLUTE and initializations.
Comment 12 Sebastian Dröge (slomo) 2010-06-02 12:07:23 UTC
commit 66a76d1f65141ec1180809d2fc258b1e4ecb9768
Author: Pierre-Louis Bossart <pierre-louis.bossart@intel.com>
Date:   Tue Jun 1 18:54:41 2010 -0500

    pulsesink: optimize communication with PulseAudio using pa_stream_begin_writ
Comment 13 Edward Hervey 2010-06-07 18:30:26 UTC
This introduces a regression when playing back asf files.

See #620540