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

Arun Raghavan arun at accosted.net
Mon Mar 31 09:26:18 PDT 2014


On 31 March 2014 21:42, Stephan Soller <stephan.soller at helionweb.de> wrote:
> 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...).

There are a few ways to integrate PA with your application event loop:

1. As Thomas pointed out, you can use PA's mainloop as your "main"
loop as it seems you're doing above, and there are APIs to integrate
various types of events there (fds, timers, execute-in-next-iteration)

2. You can have PA use an existing loop, but providing a
pa_mainloop_api implementation on top of whatever implementation you
have. For example, we ship a Glib mainloop wrapper that does this.

3. Use a PA threaded mainloop and manually synchronise between PA
events and your event loop

Between these three, I think we cover what most applications would
want to do. Do you see some case that would not work within these
options?

Cheers,
Arun


More information about the pulseaudio-discuss mailing list