Thx Tanu. Will heed the advise.<div><br></div><div>Conor</div><div><br><br><div class="gmail_quote">On Wed, Jan 13, 2010 at 4:45 AM, Tanu Kaskinen <span dir="ltr"><<a href="mailto:tanuk@iki.fi">tanuk@iki.fi</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">ti, 2010-01-12 kello 11:48 +0000, Forwind info kirjoitti:<br>
<div class="im">> Hi all,<br>
><br>
><br>
> I have some notes below I made about using the Pulse Audio<br>
> asynchronous API. If you have a minute would you mind casting your<br>
> eyes over my proposed strategy. Any comments are very welcome.<br>
><br>
><br>
> thx,<br>
> Conor<br>
><br>
><br>
><br>
><br>
> 1. To obtain the volume of primary Output Device.<br>
> ans: Fetch the sink info via pa_context_get_sink_info_by_index().<br>
> The return value will contain volume data type (pa_cvolume).<br>
<br>
</div>I don't know what you mean by "primary output device". But if you<br>
somehow already know the index for the primary sink, whatever that<br>
means, then yes, use that function. In case you think pulseaudio<br>
recognizes a "primary sink" concept, please read<br>
<a href="http://pulseaudio.org/wiki/DefaultDevice" target="_blank">http://pulseaudio.org/wiki/DefaultDevice</a><br>
<div class="im"><br>
> 2.Differentiate between headphone volume if plugged in and speaker<br>
> volume<br>
> ans: Detect headphone connection - PulseAudio intend to expose<br>
> jack-sensing once it becomes available to them from below. Its in the<br>
> pipeline apparently. I need to do some more investigation around this.<br>
> Some devices expose individual headphone volumes as opposed to speaker<br>
> volumes others don't.<br>
<br>
</div>It's not clear why you need to differentiate between headphone volume<br>
and the speaker volume - are you writing a volume control app that<br>
should be able to change the volume independently for headphones and<br>
speakers? You don't need jack sensing for this. Jack sensing is for<br>
switching the mode automatically when eg. the headphones are plugged in.<br>
<br>
The mode can already be switched manually with current pulseaudio - the<br>
concept is called "device ports". Sinks and sources can have multiple<br>
ports, and one port is always active (but some devices don't have ports<br>
at all!). There are functions in the client API for getting a list of<br>
available ports for a device, and for switching the port.<br>
<br>
When the port is switched, pulseaudio will control the correct alsa<br>
mixer element regardless whether the headphones and the speakers use the<br>
same or different mixer elements.<br>
<div class="im"><br>
> 3. Detect no output devices(sinks)<br>
> ans: pa_context_get_sink_info_list - if the returned array is empty<br>
> then there are no output devices.<br>
<br>
</div>The function doesn't return an array. It calls your callback multiple<br>
times, and the last call has the eol parameter set to a positive value<br>
and the info struct pointer set to NULL. But yes, in principle that's<br>
how you do it. Note, though, that the default configuration loads<br>
module-always-sink, which loads a null sink if no other sinks are<br>
present, so usually the sink list won't be empty. If you want to treat<br>
the lone null sink as equal to having no sinks at all (which may or may<br>
not be sensible), you should probably check whether there is only one<br>
sink present, and if that's the case, check whether the only sink's<br>
module is "module-null-sink".<br>
<div class="im"><br>
> 4. If the sound is muted and some exterior application attempts to<br>
> play sound then flag it<br>
> ans: Subscribe to the PA_SUBSCRIPTION_EVENT_SINK_INPUT event and<br>
> on the callback check to see if that sink is muted (boolean). Note if<br>
> the client application is paused, the sink is then muted and the<br>
> client app is restart the event will not be triggered. This might be<br>
> not satisfy UI spec requirements. Check with MPT.<br>
<br>
</div>This is correct, including the note about problems with unpausing. You<br>
don't get any kind of a notification when a stream is unpaused (uncorked<br>
in pulseaudio terminology). Maybe the cork status should be exposed in<br>
the sink input and source output info structs, and events should be sent<br>
whenever the status changes.<br>
<br>
This would still not work for applications that implement muting by<br>
sending silence. I don't know how usual common that is. Rhythmbox seems<br>
to use proper corking.<br>
<div class="im"><br>
> 5. Ability to mute all output sinks.<br>
> ans: pa_context_set_sink_mute_by_index()- iterate through all<br>
> sinks returned via pa_context_get_sink_info_list(). Maybe<br>
> there is a mute all switch - could not see it in the docs right now -<br>
> will ask on #pa on freenode.<br>
<br>
</div>Correct. There is no mute all function. Personally, I think there should<br>
be (perhaps not in the core API, but provided by an extension module).<br>
<div class="im"><br>
> 6. Unmute all outputs and return to previous volumes.<br>
> ans: PA's module-stream-restore - more investigation. Apparently<br>
> this will store previous volumes of all sinks and restore them when<br>
> required.<br>
<br>
</div>Sink volumes are restored by module-device-restore.<br>
module-stream-restore restores stream volumes. But your objective sounds<br>
misguided: muting a sink doesn't change the sink volume. Therefore<br>
unmuting the sink restores the previous volume even without any helper<br>
modules.<br>
<div class="im"><br>
> 7. Set individual output volumes to 0 (distinct from mute)<br>
> pa_context_set_sink_volume_by_index() or by name.<br>
<br>
</div>Yes.<br>
<div class="im"><br>
> 8. Set individual outputs volumes to max.<br>
> ans: Set the sink (output device) in question to PA_VOLUME_NORM.<br>
> pa_cvolume_reset() - should do this for the sink in question.<br>
> PA_VOLUME_NORM roughly corresponds to 0DB => MAX volume without<br>
> clipping.<br>
<br>
</div>Use the base volume value that is stored in the sink info struct. That's<br>
the level that the sound card reports as 0dB. Higher values may or may<br>
not clip, depending whether the mixer element controls a digital or<br>
analog amplifier.<br>
<br>
HTH.<br>
<font color="#888888"><br>
--<br>
Tanu Kaskinen<br>
<br>
_______________________________________________<br>
pulseaudio-discuss mailing list<br>
<a href="mailto:pulseaudio-discuss@mail.0pointer.de">pulseaudio-discuss@mail.0pointer.de</a><br>
<a href="https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss" target="_blank">https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss</a><br>
</font></blockquote></div><br></div>