[pulseaudio-discuss] [PATCH] switch-on-port-available: check and change default sink or source
Tanu Kaskinen
tanuk at iki.fi
Wed May 17 20:34:42 UTC 2017
On Tue, 2017-05-16 at 16:29 +0800, Hui Wang wrote:
> On 05/03/2017 06:51 PM, Tanu Kaskinen wrote:
> > On Wed, 2017-05-03 at 11:23 +0800, Hui Wang wrote:
> > > Today I tested the latest master branch (already including your two
> > > patches), seems it did not fix the problem. Below is my testing detail:
> > >
> > > Install ubuntu 16.04 on my laptop.
> > > clone the latest pulseaudio source code, checkout master branch
> > > build the source code: ./autogen.sh;make
> > > kill the existing pulseaudio and run the latest pulseaudio: pulseaudio
> > > --kill && ./src/pulseaudio -vvvnF ./src/default.pa -p $(pwd)/src
> > >
> > > On this machine, we have sound cards, sinks and ports like below:
> > >
> > > Card#0(HDA INTEL HDMI)-> Sink#0(hdmi-stereo)->hdmi-output(priority: 5900)
> > > Card#1(HDA INTEL PCH)->Sink#1(analog-stereo)->headphones(priority: 9000)
> >
> > No speaker port at all on the PCH card?
>
> Sorry for late response, just came back from a vacation.
>
> I removed the speaker from the kernel driver intentionally for debugging
> another audio bug.
>
> But it does not matter, if I don't remove the speaker, the Sink#1 has
> the speaker on it, and the default sink is Sink#1, after plugging the
> HDMI cable, the default sink is still Sink#1, it is expected since
> Sink#1 has an available port which has higher priority than HDMI port,
> then I select the HDMI to be the default sink manually, now the default
> sink is Sink#0. After that I unplug the HDMI cable, the Sink#1 is
> expected to be the default sink since the Sink#0 has no available ports
> on it, but the default sink doesn't switch back to Sink#1.
>
>
> > > with the new pulseaudio, I can only see one sink (analog-stereo)
> > > through pactl list sinks at the beginning.
> > >
> > > After I plug the HDMI cable (headphone is not plugged), I can see two
> > > sinks via pactl list sinks, but the default sink is still the analog-
> > > stereo, here I expect the default sink is hdmi-stereo since the
> > > headphone is not plugged yet.
> >
> > That's what I'd expect too. Is the headphone port marked as unavailable
> > as it should?
>
> Yes, it is marked "not available".
> > > Then I plug the headphone, and I select the hdmi (hdmi is also
> > > plugged in) as the default sink, after a while I unplug the hdmi
> > > cable, here I expect the default sink is back to analog-stereo since
> > > headphone is still plugged, but the default sink did not switch to
> > > analog-stereo. BTW after I unplug the hdmi cable, I can still see two
> > > sinks.
> >
> > The default sink is set in pa_core_update_default_sink() in
> > src/pulsecore/core.c. That function uses the compare_sinks() function,
> > and the first thing compare_sinks() does is to check if one of the
> > compared sinks has an unavailable port active. Can you figure out what
> > goes wrong? Is pa_core_update_default_sink() not called when you plug
> > in or unplug things, or does pa_core_update_default_sink() really
> > choose a sink whose active port is unavailable?
>
> Through debugging, I found the function pa_core_update_default_sink() is
> not called when unplug the HDMI cable in the situation above.
>
>
> The good news is after applying your new patch "[PATCH] sink, source:
> update the default sink/source on port switches", the issue is fixed.
> The function pa_core_update_default_sink() is called when
> plugging/unplugging some audio output devices, and the default_sink is
> changed as expected.
Good to know. I expected that my patch wouldn't fix your problem, but I
guess I didn't think through the case properly. I pushed the patch to
master, so the fix will be in the upcoming release.
--
Tanu
https://www.patreon.com/tanuk
More information about the pulseaudio-discuss
mailing list