On Fri, 31 Mar 2023 17:18:44 +0200, Jaroslav Kysela wrote: > > On 31. 03. 23 16:22, Takashi Iwai wrote: > > When a DRM driver turns on or off the screen with the audio > > capability, it notifies the ELD to HD-audio HDMI codec driver via > > component ops. HDMI codec driver, in turn, attaches or detaches the > > PCM stream for the given port on the fly. > > > > The problem is that, since the recent code change, the HDMI driver > > always treats the PCM stream assignment dynamically; this ended up the > > confusion of the PCM device appearance. e.g. when a screen goes once > > off and on again, it may appear on a different PCM device before the > > screen-off. Although the application should treat such a change, it > > doesn't seem working gracefully with the current pipewire (maybe > > PulseAudio, too). > > > > As a workaround, this patch changes the HDMI codec driver behavior > > slightly to be more consistent. Now it remembers the previous PCM > > slot for the given port and try to assign to it. That is, if a port > > is re-enabled, the driver tries to use the same PCM slot that was > > assigned to that port previously. If it conflicts, a new slot is > > searched and used like before, instead. > > I don't like this workaround so much, because the devices should be > assigned from the first PCM device. Normally the device is assigned to the first PCM slot. And, it'll be always so, as long as you connect a single device. In this change, we don't keep the old empty slot, but just tries to use the previous slot at first. So a single device connection always leads to the first PCM slot. That said, the slot preservation becomes effective only when multiple devices are connected and they are on/off at the same time. In such a case, the device order may be changed at each screen on/off with the current code, while this patch allows keeping the order. Maybe I should emphasize about the multiple devices in the patch description. > The sound server should combine the persistent path only from the ELD > information for the HDMI devices (if present). The problem may be when > multiple similar monitors are connected to the machine. It would be > probably nice to have an unique PCM device name for this usage with > the serial number of the connected monitor (but I don't think it's in > ELD? - it is in the EDID spec thought). The name string appears actually in the dialog. But the automatic switch doesn't happen. So we need some improvement / fix. > > @@ -1399,6 +1408,7 @@ static void hdmi_detach_hda_pcm(struct hdmi_spec *spec, > > idx = per_pin->pcm_idx; > > per_pin->pcm_idx = -1; > > per_pin->pcm = NULL; > > + per_pin->prev_pcm_idx = idx; > > Maybe this line should be moved up before 'pcm = NULL'. The pcm_idx > and prev_pcm_idx members are related. OK, I don't mind either position. > For now: > > Reviewed-by: Jaroslav Kysela <perex@xxxxxxxx> thanks, Takashi