[pulseaudio-discuss] Routing of audio to loudspeakers or headphones

Tanu Kaskinen tanuk at iki.fi
Wed Sep 15 09:52:35 PDT 2010

On Wed, 2010-09-15 at 15:37 +0100, Colin Guthrie wrote:
> > Most important to me is to figure out how you make the module
> > unload/load automatically as the headphone jack is plugged/unplugged.
> > Right now the module just fails to load if the master port is not the
> > one for the headphones.
> Ultimately you'll have to make the module listen to the
> PA_CORE_HOOK_SINK_STATE_CHANGED hook. The callback assigned to this hook
> will be called whenever a sink changes in the PA daemon (e.g. when it's
> port is changed). You can inspect the current active_port and either
> load, unload or noop as appropriate the actual sink object itself.

This is not entirely correct. PA_CORE_HOOK_SINK_STATE_CHANGED is fired
only when the pa_sink.state variable changes, not when the active port
changes. For monitoring port changes, either implement a new hook
(PA_CORE_HOOK_SINK_PORT_CHANGED) and use it, or use the asynchronous
subscription system (see src/pulsecore/core-subscribe.h for the API). I
would prefer the first alternative - the synchronous hook callbacks are
easier to get right than the asynchronous subscription callbacks.

Tanu Kaskinen

More information about the pulseaudio-discuss mailing list