[pulseaudio-discuss] Getting the pollfds from the PA mainloop

Stephan Soller stephan.soller at helionweb.de
Mon Mar 31 09:12:01 PDT 2014


On 03/30/2014 07:48 PM, Stephan Soller wrote:
> On 03/30/2014 07:08 PM, Thomas Martitz wrote:
>> Am 30.03.2014 17:04, schrieb Stephan Soller:
>>> Hi,
>>>
>>> is there a way to get the pollfds out of the poll() based Pulse Audio
>>> mainloop? Basically I want to do the poll() myself so I can poll for
>>> other stuff as well (some v4l2 devices and UNIX domain sockets).
>>>
>>> In ALSA there is the snd_pcm_poll_descriptors*() family of functions
>>> to get the required pollfds. But I haven't found an equivalent Pulse
>>> Audio function for that kind of stuff.
>>>
>>> I looked at the PA mainloop source code and found no matching
>>> functions
>>> (http://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/pulse/mainloop.c).
>>>
>>> I found the pollfds and n_pollfds members in the pa_mainloop struct
>>> but no way to access them from the outside. Does that mean I'm stuck
>>> with ALSA?
>>>
>>> A little background: I'm currently building an audio/video live mixing
>>> program. It combines several video and audio streams (webcams, frame
>>> grabber, mics, ...) into one live stream and sends it to an encoder
>>> process (ffmpeg).
>>>
>>> One big poll() loop fechtes video and audio data and manages some UNIX
>>> domain sockets to send the result onwards. OpenGL is used to combine
>>> the different video streams. The program only shuffles data around and
>>> if possible I want to keep everything in one single threaded poll()
>>> loop.
>>>
>>> Any ideas are welcome.
>>
>> Alternatively you can add your FDs to the pa mainloop using
>> mainloop_io_new(). The end result (all FDs are covered with a single
>> poll() call) is the same.
>>
>> Best regards
>
> Thanks for the quick reply Thomas. :)
>
> This looks like a possibility. I'll give it a try tomorrow. But I have
> to admit that it feels like the wrong way around (PA handling video and
> socket server events...). But what works works I guess.

Tested it with a signalfd and it works quite well. Thanks for your quick 
help Thomas. :)

Still have to test recording and playback latency and CPU usage but the 
experiments look promising (way better than using the ALSA API).

Back to the root cause: Are there any plans to make the pollfds publicly 
available? Or can I post a feature request or patch somewhere?

The trick to stuff everything into the Pulse Audio mainloop works only 
once. If another API with its own private event management comes into 
play this won't work (e.g. SDL...).

Happy programming
Stephan


More information about the pulseaudio-discuss mailing list