[pulseaudio-discuss] [PATCH 1/3] alsa: fix infinite loop with Intel HDMI LPE

Hui Wang hui.wang at canonical.com
Wed Mar 27 01:13:49 UTC 2019


On 2019/3/27 上午1:44, Tanu Kaskinen wrote:
> On Tue, 2019-03-26 at 13:17 +0800, Hui Wang wrote:
>> On 2017/12/28 下午6:09, Tanu Kaskinen wrote:
>>> The Intel HDMI LPE driver works in a peculiar way when the HDMI cable is
>>> not plugged in: any written audio is immediately discarded and underrun
>>> is reported. That resulted in an infinite loop, because PulseAudio tried
>>> to keep the buffer filled, which was futile since the written audio was
>>> immediately consumed/discarded.
>>>
>>> This patch adds special handling for the LPE driver: if the active port
>>> of the sink is unavailable, the sink suspends itself. A new suspend
>>> cause is added: PA_SUSPEND_UNAVAILABLE.
>>>
>>> BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100488
>>> ---
>>>  src/modules/alsa/alsa-mixer.h       |  1 +
>>>  src/modules/alsa/alsa-sink.c        | 22 ++++++++++++++++++++++
>>>  src/modules/alsa/module-alsa-card.c | 34 ++++++++++++++++++++++++++++++++++
>>>  src/pulsecore/core.h                |  1 +
>>>  4 files changed, 58 insertions(+)
>>>
>>> diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
>>> index 4ebf1922b..3577f435f 100644
>>> --- a/src/modules/alsa/alsa-mixer.h
>>> +++ b/src/modules/alsa/alsa-mixer.h
>>> @@ -364,6 +364,7 @@ int pa_alsa_set_mixer_rtpoll(struct pa_alsa_mixer_pdata *pd, snd_mixer_t *mixer,
>>>  struct pa_alsa_port_data {
>>>      pa_alsa_path *path;
>>>      pa_alsa_setting *setting;
>>> +    bool suspend_when_unavailable;
>>>  };
>>>  
>>>  void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card);
>>> diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
>>> index 7936cfaca..a80caab2e 100644
>>> --- a/src/modules/alsa/alsa-sink.c
>>> +++ b/src/modules/alsa/alsa-sink.c
>>> @@ -1527,6 +1527,11 @@ static int sink_set_port_cb(pa_sink *s, pa_device_port *p) {
>>>              s->set_volume(s);
>>>      }
>>>  
>>> +    if (data->suspend_when_unavailable && p->available == PA_AVAILABLE_NO)
>>> +        pa_sink_suspend(s, true, PA_SUSPEND_UNAVAILABLE);
>>> +    else
>> Hi Tanu,
>>
>> We tried to backport this patch to pulseaudio-8.0 (for ubuntu linux
>> 16.04),  but after applying this patch, all audio jacks (like headphone,
>> line-in/line-out) can't work anymore. If we change the above line as
>> below, the problem will disappear.
>>
>> else (data->suspend_when_unavailable)
>>
>> In theory, if a port is not set suspend_when_unavailable, the port
>> should not be changed by this patch. I don't know if it is correct or
>> not,  could you please take a look at it?
> I don't think your change is correct. This code is run when the sink
> changes its port, so there are two ports involved: the old port and the
> new one. If the old port caused the sink to be suspended with the
> UNAVAILABLE cause, and the new port doesn't require suspending when
> it's unavailable, then with your change the sink doesn't get
> unsuspended when it should.
>
> In practice your change should be harmless, though, because all ports
> on a Intel HDMI LPE card will have the suspend_when_unavailable flag
> set, and on other cards the flag is never set.
>
> You didn't specify what the exact problem with headphones etc. is. Is
> there an assertion error? I would guess that you're running into this
> bug that was introduced by the HDMI LPE fixes:
> https://bugs.freedesktop.org/show_bug.cgi?id=104761
>
> Fixing that bug involved rewriting much of the device suspending and
> state changing code. I don't know if you want to backport those patches
> if your small change seems to make things work well enough, but here's
> a list of relevant commits (oldest first, I'm not 100% that this is a
> complete list):
>
> 3da0de5418b29c90974d0d3e2198c471c39d229f
> 6ed37aeef28708f8da34a16c7035fa1331fa13cb
> d6e39b5e891c767dd42c369d9f118560b8bb24ae
> 7f201b1fd419b91a226d23ee1e216661ae082dcf
> 2dff0d6a6a4df2aab6f36212b705489d5af42835
> 7f09164ed7979210adcdb7674b9d6217fd44ed66
> f6fe411b32c0cf5932fb4f169f5288c76bc6923d
> 0fad369ceb18a8e275e8f74f10f784e0d7476dfb
> 73b8a57078b94033edf84de2fc0cfbe344c10dcd
> b2537a8f38ad71e4dee57263310235abdf2b95a4
> ad0616d4c91de52b7cb69e6222efe96961755482
> ad15e6e50e737fb55a87bb7def22332f774abce9

Ok, got it. I will investigate these commits.

Thanks,

Hui.





More information about the pulseaudio-discuss mailing list