[pulseaudio-discuss] source-sink loopback

pl bossart bossart.nospam at gmail.com
Mon Aug 17 09:19:52 PDT 2009


Howdy,
Since this was missing in PulseAudio, I created a loopback module
where input sound can be redirected to a sink. That removes the need
for the silly parec|pacat workaround.

Basically the module creates both a sink_input and source_output. When
there's data available from the source, a push callback is called by
the IO thead. Likewise when the sink has eaten the data a pop callback
is invoked. Since both callbacks are called from two different
threads, I pushed incoming data into a memblockq and read from there
in the pop callback. I figured it this would enable zero-copy
operations. Works fine with a USB mic and PC internal speakers, and
vice-versa. With a low-enough latency you can use it for karaoke apps,
but that was not the initial goal...

Since this was the first time I really looked into PulseAudio
internals, I have a number of questions:
0. is there a better way to do this loopback? I did not find any
module that relied on the push callback, and I only saw the pop
callback in very limited number of modules.
1. latency: I configured both sink and source to the same latency, yet
in the push callback I see the number of samples can vary. If I
program the source with a 10ms latency, I would expect to get a 10ms
buffer. Is this due to some kind of scheduling thingy?
Likewise when I configure the source to have a 20ms latency, I get a
buffer of ~10ms. Is this normal?
2. I assumed that the memblockq routines (push, peek and drop) are
thread-safe, is this a valid assumption?
3. For now the source and sink are synchronous but if they are not,
how can I enable a sample-rate converter to correct for clock drifts?
I see some code for SRC in both the input and output IO threads,
however I don't understand how the tracking would be done.
4. someone described a use case with BT, I would need to load the same
module twice, i.e.
load-module module-loopback source=bt-src sink=speakers
load-module module-loopback source=mic sink=bt-sink
Is there anything specific I need to do for this?
5. I started from the module-sine code, however I have no idea what to
do about some callbacks, specifically rewind and state-changed. Does
anyone have a description of what's expected here?

I am working through red tape to release this code. Will probably take
me more time than writing the code...
Thanks for your feedback.
Cheers
- Pierre



More information about the pulseaudio-discuss mailing list