[pulseaudio-discuss] sink/source automatic switching policy between different devices

Colin Guthrie gmane at colin.guthr.ie
Wed Oct 15 02:32:21 PDT 2008


Zhang, Xing Z wrote:
> Hi All:
>         I am thinking about how to implement sink/source automatic switching policy in PA. For mobile device, it may have several output devices such as speaker, wired headset, Bluetooth headset and so on.
>         People may want to audio stream automatically re-direct to new device they plug in. For example, while I play a MP3 with embedded speaker I want to the music automatically output through Bluetooth headset once I plug it in.
>         After a rough looking into the source, I think the mechanism used by module-hal-detect.so, module-bluetooth-discover.so and "move-sink-input" could help me to achieve the goal. That means a new module may be written.
>         But, the problem is different users may want different policies. For instance, somebody may want to speaker automatically muted when wired headset plugged in, while others may want speaker go on playing. So a new module is hard to provide dynamic policy for different people because once it complied all things are hard coding. A feasible way is the module reads in a configure file to decide to provide what policy. I am afraid the configure file may make things complicated so I consult you is there an easier way? Many thanks in advance :)

In recent releases the stream routing logic is performed by 
module-stream-restore and there is a way to inject "rules" into this 
module which can act on "properties" attached to the streams.

e.g. a VoIP class may attach a property to tell pulse that is is of 
class "voip" and a rule could be written that says when a device stream 
of class voip is played and a device of type headset is discovered, move 
the stream across.

I'm not sure if it handles the "moving after the stream has started" 
case yet, but certainly this is the right approach and the stream 
properties give the necessary meta-data to work with.

This properties system was only introduced in pulse 0.9.11 which is why 
Erik could not do this in the past and used a series of scripts.

The docs for stream-restore are a little light just now but the 
interface can be found here:
 
http://0pointer.de/lennart/projects/pulseaudio/doxygen/ext-stream-restore_8h.html

Pulse itself offers all the necessary hooks to know when a new device is 
added and you should certainly stay away from module-hal-detect and 
*-discover modules (there are also zeroconf-discover and, now, 
raop-discover too!) as these is not a mandatory modules and sinks/source 
could be added manually too. The hooks in pulse for when a new 
sink/source is added/disappears is sufficient to do this kind of routing.

I know this is a bit of a piecemeal reply as I don't fully know the ins 
and outs of using the stream restore system. I just know it's the right 
horse to back in the race rather than trying to do stuff at a lower level.

Hopefully Lennart can give a more complete answer on stream-restore :)

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
   Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
   Mandriva Linux Contributor [http://www.mandriva.com/]
   PulseAudio Hacker [http://www.pulseaudio.org/]
   Trac Hacker [http://trac.edgewall.org/]




More information about the pulseaudio-discuss mailing list