Skip to content

Commit 04b49b9

Browse files
HiassofTtiwai
authored andcommitted
ALSA: pcm: fix ELD constraints for (E)AC3, DTS(-HD) and MLP formats
The SADs of compressed formats contain the channel and sample rate info of the audio data inside the compressed stream, but when building constraints we must use the rates and channels used to transport the compressed streams. eg 48kHz 6ch EAC3 needs to be transmitted as a 2ch 192kHz stream. This patch fixes the constraints for the common AC3 and DTS formats, the constraints for the less common MPEG, DSD etc formats are copied directly from the info in the SADs as before as I don't have the specs and equipment to test those. Signed-off-by: Matthias Reichl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 4a1b5ba commit 04b49b9

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

sound/core/pcm_drm_eld.c

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
/*
33
* PCM DRM helpers
44
*/
5+
#include <linux/bitfield.h>
56
#include <linux/export.h>
7+
#include <linux/hdmi.h>
68
#include <drm/drm_edid.h>
79
#include <sound/pcm.h>
810
#include <sound/pcm_drm_eld.h>
911

12+
#define SAD0_CHANNELS_MASK GENMASK(2, 0) /* max number of channels - 1 */
13+
#define SAD0_FORMAT_MASK GENMASK(6, 3) /* audio format */
14+
15+
#define SAD1_RATE_MASK GENMASK(6, 0) /* bitfield of supported rates */
16+
#define SAD1_RATE_32000_MASK BIT(0)
17+
#define SAD1_RATE_44100_MASK BIT(1)
18+
#define SAD1_RATE_48000_MASK BIT(2)
19+
#define SAD1_RATE_88200_MASK BIT(3)
20+
#define SAD1_RATE_96000_MASK BIT(4)
21+
#define SAD1_RATE_176400_MASK BIT(5)
22+
#define SAD1_RATE_192000_MASK BIT(6)
23+
1024
static const unsigned int eld_rates[] = {
1125
32000,
1226
44100,
@@ -17,9 +31,62 @@ static const unsigned int eld_rates[] = {
1731
192000,
1832
};
1933

34+
static unsigned int map_rate_families(const u8 *sad,
35+
unsigned int mask_32000,
36+
unsigned int mask_44100,
37+
unsigned int mask_48000)
38+
{
39+
unsigned int rate_mask = 0;
40+
41+
if (sad[1] & SAD1_RATE_32000_MASK)
42+
rate_mask |= mask_32000;
43+
if (sad[1] & (SAD1_RATE_44100_MASK | SAD1_RATE_88200_MASK | SAD1_RATE_176400_MASK))
44+
rate_mask |= mask_44100;
45+
if (sad[1] & (SAD1_RATE_48000_MASK | SAD1_RATE_96000_MASK | SAD1_RATE_192000_MASK))
46+
rate_mask |= mask_48000;
47+
return rate_mask;
48+
}
49+
50+
static unsigned int sad_rate_mask(const u8 *sad)
51+
{
52+
switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) {
53+
case HDMI_AUDIO_CODING_TYPE_PCM:
54+
return sad[1] & SAD1_RATE_MASK;
55+
case HDMI_AUDIO_CODING_TYPE_AC3:
56+
case HDMI_AUDIO_CODING_TYPE_DTS:
57+
return map_rate_families(sad,
58+
SAD1_RATE_32000_MASK,
59+
SAD1_RATE_44100_MASK,
60+
SAD1_RATE_48000_MASK);
61+
case HDMI_AUDIO_CODING_TYPE_EAC3:
62+
case HDMI_AUDIO_CODING_TYPE_DTS_HD:
63+
case HDMI_AUDIO_CODING_TYPE_MLP:
64+
return map_rate_families(sad,
65+
0,
66+
SAD1_RATE_176400_MASK,
67+
SAD1_RATE_192000_MASK);
68+
default:
69+
/* TODO adjust for other compressed formats as well */
70+
return sad[1] & SAD1_RATE_MASK;
71+
}
72+
}
73+
2074
static unsigned int sad_max_channels(const u8 *sad)
2175
{
22-
return 1 + (sad[0] & 7);
76+
switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) {
77+
case HDMI_AUDIO_CODING_TYPE_PCM:
78+
return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]);
79+
case HDMI_AUDIO_CODING_TYPE_AC3:
80+
case HDMI_AUDIO_CODING_TYPE_DTS:
81+
case HDMI_AUDIO_CODING_TYPE_EAC3:
82+
return 2;
83+
case HDMI_AUDIO_CODING_TYPE_DTS_HD:
84+
case HDMI_AUDIO_CODING_TYPE_MLP:
85+
return 8;
86+
default:
87+
/* TODO adjust for other compressed formats as well */
88+
return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]);
89+
}
2390
}
2491

2592
static int eld_limit_rates(struct snd_pcm_hw_params *params,
@@ -42,7 +109,7 @@ static int eld_limit_rates(struct snd_pcm_hw_params *params,
42109
* requested number of channels.
43110
*/
44111
if (c->min <= max_channels)
45-
rate_mask |= sad[1];
112+
rate_mask |= sad_rate_mask(sad);
46113
}
47114
}
48115

@@ -70,7 +137,7 @@ static int eld_limit_channels(struct snd_pcm_hw_params *params,
70137
rate_mask |= BIT(i);
71138

72139
for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3)
73-
if (rate_mask & sad[1])
140+
if (rate_mask & sad_rate_mask(sad))
74141
t.max = max(t.max, sad_max_channels(sad));
75142
}
76143

0 commit comments

Comments
 (0)