ALSA: hdmi: expose ELD control
PATCH v2 1/1 ALSA: hdmi: expose ELD control
Applications may want to read ELD information to understand what codecs are supported on the HDMI receiver and handle the a-v delay for better lip-sync.
ELD information is exposed in a device-specific IFACE_PCM kcontrol. Tested both with amixer and PulseAudio.
--- sound/pci/hda/hda_eld.c | 9 ++-- sound/pci/hda/hda_local.h | 2 + sound/pci/hda/patch_hdmi.c | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 5 deletions(-)
sound/pci/hda/hda_eld.c +4 -5
@@ -327,14 +327,14 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,snd_printd (KERN_INFO "HDMI: ELD buf size is 0, force 128\n" ); size =128 ; } -if (size <ELD_FIXED_BYTES || size >PAGE_SIZE ) { +if (size <ELD_FIXED_BYTES || size >ELD_MAX_SIZE || size >PAGE_SIZE ) {snd_printd (KERN_INFO "HDMI: invalid ELD buf size %d\n" , size);return -ERANGE ; } - buf =kmalloc (size,GFP_KERNEL ); -if (!buf) -return -ENOMEM ; +/* update info */ + eld->eld_size = size; + buf = eld->eld_buffer;for (i =0 ; i < size; i++) {unsigned int val =hdmi_get_eld_data (codec, nid, i);
@@ -356,7 +356,6 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld, ret =hdmi_update_eld (eld, buf, size); error: -kfree (buf);return ret; }
sound/pci/hda/hda_local.h +2 -0
@@ -621,6 +621,7 @@ struct cea_sad { };#define ELD_FIXED_BYTES 20 +#define ELD_MAX_SIZE 256#define ELD_MAX_MNL 16#define ELD_MAX_SAD 16
@@ -645,6 +646,7 @@ struct hdmi_eld {int spk_alloc;int sad_count;struct cea_sad sad[ELD_MAX_SAD ]; +char eld_buffer[ELD_MAX_SIZE ];#ifdef CONFIG_PROC_FS struct snd_info_entry *proc_entry;#endif
sound/pci/hda/patch_hdmi.c +88 -0
100 lines not on this page · raw message
--
1.7.6.2
At Mon, 26 Sep 2011 17:48:43 -0500,
Quoted 21 lines · Pierre-Louis Bossart
Applications may want to read ELD information to understand what codecs are supported on the HDMI receiver and handle the a-v delay for better lip-sync.
ELD information is exposed in a device-specific
IFACE_PCMkcontrol. Tested both with amixer and PulseAudio.Signed-off-by Pierre-Louis Bossart <[email protected]>--- sound/pci/hda/hda_eld.c | 9 ++-- sound/pci/hda/hda_local.h | 2 + sound/pci/hda/patch_hdmi.c | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 5 deletions(-)sound/pci/hda/hda_eld.c +0
-0
sound/pci/hda/hda_eld.c int snd_hdmi_get_eld(struct hdmi_eld *eld, · line 330
Quoted 5 lines
sound/pci/hda/hda_eld.c +1
-1@@ -327,14 +327,14 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,snd_printd (KERN_INFO "HDMI: ELD buf size is 0, force 128\n" ); size =128 ; } -if (size <ELD_FIXED_BYTES || size >PAGE_SIZE ) { +if (size <ELD_FIXED_BYTES || size >ELD_MAX_SIZE || size >PAGE_SIZE ) {
The check of size > PAGE_SIZE is meaningless now. Let's drop.
Quoted 14 lines
sound/pci/hda/hda_eld.c +3
-3snd_printd (KERN_INFO "HDMI: invalid ELD buf size %d\n" , size);return -ERANGE ; } - buf =kmalloc (size,GFP_KERNEL ); -if (!buf) -return -ENOMEM ; +/* update info */ + eld->eld_size = size; + buf = eld->eld_buffer;for (i =0 ; i < size; i++) {unsigned int val =hdmi_get_eld_data (codec, nid, i);
sound/pci/hda/hda_eld.c int snd_hdmi_get_eld(struct hdmi_eld *eld, · line 360
Quoted 6 lines
sound/pci/hda/hda_eld.c +0
-1@@ -356,7 +356,6 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld, ret =hdmi_update_eld (eld, buf, size); error: -kfree (buf);return ret; }
Wouldn't it be better to strip the buffer data and size in the error case? For example, radeon driver gives often size=0. Then it's translated as size=128 for a workaround, then again handled as an error by checking the version.
Quoted 32 lines
sound/pci/hda/hda_local.h +2
-0@@ -621,6 +621,7 @@ struct cea_sad { };#define ELD_FIXED_BYTES 20 +#define ELD_MAX_SIZE 256#define ELD_MAX_MNL 16#define ELD_MAX_SAD 16@@ -645,6 +646,7 @@ struct hdmi_eld {int spk_alloc;int sad_count;struct cea_sad sad[ELD_MAX_SAD ]; +char eld_buffer[ELD_MAX_SIZE ];#ifdef CONFIG_PROC_FS struct snd_info_entry *proc_entry;#endif sound/pci/hda/patch_hdmi.c +4
-0@@ -324,6 +324,86 @@ static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)return -EINVAL ; } +static int hdmi_eld_ctl_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +struct hda_codec *codec =snd_kcontrol_chip (kcontrol);
sound/pci/hda/patch_hdmi.c static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) · line 340
Quoted 10 lines
sound/pci/hda/patch_hdmi.c +10
-0+struct hdmi_spec *spec; +struct hdmi_spec_per_pin *per_pin; +struct hdmi_eld *eld; +int pin_idx; + + spec = codec->spec; + uinfo->type =SNDRV_CTL_ELEM_TYPE_BYTES ; + + pin_idx = kcontrol->private_value; +snd_BUG_ON (pin_idx <0 );
snd_BUG_ON() is essentially a WARN_ON(), so you should return an error here like:
if (snd_BUG_ON(pin_idx < 0)) return -EINVAL;
Quoted 12 lines
sound/pci/hda/patch_hdmi.c +12
-0+ + per_pin = &spec->pins[pin_idx]; + eld = &per_pin->sink_eld; + uinfo->count = eld->eld_size; + +return 0 ; +} + +static int hdmi_eld_ctl_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct hda_codec *codec =snd_kcontrol_chip (kcontrol);
sound/pci/hda/patch_hdmi.c static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) · line 362
Quoted 10 lines
sound/pci/hda/patch_hdmi.c +10
-0+struct hdmi_spec *spec; +struct hdmi_spec_per_pin *per_pin; +struct hdmi_eld *eld; +int pin_idx; +int size; + + spec = codec->spec; + pin_idx = kcontrol->private_value; + +snd_BUG_ON (pin_idx <0 );
Ditto.
sound/pci/hda/patch_hdmi.c static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) · line 372
Quoted 9 lines
sound/pci/hda/patch_hdmi.c +9
-0+memset (ucontrol->value.bytes.data,0 ,ELD_MAX_SIZE ); + per_pin = &spec->pins[pin_idx]; + eld = &per_pin->sink_eld; + size = eld->eld_size; + +memcpy (ucontrol->value.bytes.data, eld->eld_buffer, size); + +/* reset rest of control */ +memset (&ucontrol->value.bytes.data[size],0 ,ELD_MAX_SIZE -size);
This is superfluous.
sound/pci/hda/patch_hdmi.c static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) · line 381
Quoted 8 lines
sound/pci/hda/patch_hdmi.c +8
-0+return 0 ; +} + +static struct snd_kcontrol_new eld_bytes_ctl = { + .iface =SNDRV_CTL_ELEM_IFACE_PCM , + .name ="ELD" , + .info = hdmi_eld_ctl_info, + .get = hdmi_eld_ctl_get,
Set the access field to SNDRV_CTL_ELEM_ACCESS_READ. Also, unless we implement a notification, better to set SNDRV_CTL_ELEM_ACCESS_VOLATILE flag, too.
thanks,
Takashi
Thanks for your review Takashi!
Quoted 4 lines
Wouldn't it be better to strip the buffer data and size in the error case? For example, radeon driver gives often size=0. Then it's translated as size=128 for a workaround, then again handled as an error by checking the version.
Yes, I wasn't sure what to do here and expected some comments. Should the strategy be that if there's a single error we discard the entire ELD by setting the size to zero?
No issues for the other changes.
Quoted 3 lines
Set the access field to
SNDRV_CTL_ELEM_ACCESS_READ. Also, unless we implement a notification, better to setSNDRV_CTL_ELEM_ACCESS_VOLATILEflag, too.
The intent was to read the ELD after the device is opened, I don't think the ELD can change during playback, the updates can only happen on a pin-sensing event. I can't think of a good reason why a notification would be needed? -Pierre
A message that is not in the archive (sent off-list or not yet received): 000301cc7d2c$ee224c80$ca66e580$@[email protected]
At Tue, 27 Sep 2011 10:48:39 -0500,
Quoted 8 lines · Pierre-Louis Bossart
Thanks for your review Takashi!
Quoted 4 lines
Wouldn't it be better to strip the buffer data and size in the error case? For example, radeon driver gives often size=0. Then it's translated as size=128 for a workaround, then again handled as an error by checking the version.
Quoted 4 lines
Yes, I wasn't sure what to do here and expected some comments. Should the strategy be that if there's a single error we discard the entire ELD by setting the size to zero?
No issues for the other changes.
It's a good question. I'm inclined to discard all for any errors, in the case of ELD. AFAIK, most of errors are really broken ELD, and no need to care the rest of bits.
Quoted 7 lines
Quoted 3 lines
Set the access field to
SNDRV_CTL_ELEM_ACCESS_READ. Also, unless we implement a notification, better to setSNDRV_CTL_ELEM_ACCESS_VOLATILEflag, too.The intent was to read the ELD after the device is opened, I don't think the ELD can change during playback, the updates can only happen on a pin-sensing event. I can't think of a good reason why a notification would be needed?
It's just a matter of definition. If the data may be changed without notification, the element should set VOLATILE flag. You don't have to implement the notification mechanism if you don't want :)
thanks,
Takashi
Pierre-Louis Bossart wrote at Tuesday, September 27, 2011 9:49 AM:
...
Quoted 7 lines
Quoted 3 lines
Set the access field to
SNDRV_CTL_ELEM_ACCESS_READ. Also, unless we implement a notification, better to setSNDRV_CTL_ELEM_ACCESS_VOLATILEflag, too.The intent was to read the ELD after the device is opened, I don't think the ELD can change during playback, the updates can only happen on a pin-sensing event. I can't think of a good reason why a notification would be needed?
If the user unplugs an HDMI monitor and plugs a different one in, and hence the X server turns off the output and re-enables it to cater for any required new display mode, would that force the audio client to close/re-open the audio device? I don't /think/ so. As such, I guess the ELD can change dynamically, so notification would be a good idea.
Signature · 1 line
nvpublic
Quoted 7 lines
If the user unplugs an HDMI monitor and plugs a different one in, and hence the X server turns off the output and re-enables it to cater for any required new display mode, would that force the audio client to close/re-open the audio device? I don't /think/ so. As such, I guess the ELD can change dynamically, so notification would be a good idea.
Hmm, if the user plugs/unplugs the cable, my understanding is that David Henningson's patches for jack detection would trap these events, and that would trigger reconfigurations of the audio server.
If notifications are needed, that's fine with me, we can add them at a later stage. I don't have multiple monitors and would not be able to contribute anything on this anyway...I wanted to start small and make use the existing information is used properly by PulseAudio/others first.
-Pierre
Pierre-Louis Bossart wrote at Tuesday, September 27, 2011 2:02 PM:
Quoted 9 lines
Quoted 5 lines
If the user unplugs an HDMI monitor and plugs a different one in, and hence the X server turns off the output and re-enables it to cater for any required new display mode, would that force the audio client to close/re-open the audio device? I don't /think/ so. As such, I guess the ELD can change dynamically, so notification would be a good idea.
Hmm, if the user plugs/unplugs the cable, my understanding is that David Henningson's patches for jack detection would trap these events, and that would trigger reconfigurations of the audio server.
Ah yes, that'd make sense. Thanks.
Signature · 1 line
nvpublic