Skip to content

Commit 015eb0b

Browse files
cladischtiwai
authored andcommitted
ALSA: usb-audio: use a format bitmask per alternate setting
In preparation for USB audio 2.0 support, change the audioformat structure so that it uses a bitmask to specify possible formats. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent e11b4e0 commit 015eb0b

8 files changed

Lines changed: 34 additions & 22 deletions

File tree

‎sound/usb/card.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
struct audioformat {
1111
struct list_head list;
12-
snd_pcm_format_t format; /* format type */
12+
u64 formats; /* ALSA format bits */
1313
unsigned int channels; /* # channels */
1414
unsigned int fmt_type; /* USB audio format type (1-3) */
1515
unsigned int frame_size; /* samples per frame for non-audio */

‎sound/usb/endpoint.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct au
9494
if (subs->endpoint == fp->endpoint) {
9595
list_add_tail(&fp->list, &subs->fmt_list);
9696
subs->num_formats++;
97-
subs->formats |= 1ULL << fp->format;
97+
subs->formats |= fp->formats;
9898
return 0;
9999
}
100100
}
@@ -268,7 +268,7 @@ int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
268268
*/
269269
if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
270270
fp && fp->altsetting == 1 && fp->channels == 1 &&
271-
fp->format == SNDRV_PCM_FORMAT_S16_LE &&
271+
fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
272272
protocol == UAC_VERSION_1 &&
273273
le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
274274
fp->maxpacksize * 2)

‎sound/usb/format.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
323323
return -1;
324324
}
325325

326-
fp->format = pcm_format;
326+
fp->formats = 1uLL << pcm_format;
327327

328328
/* gather possible sample rates */
329329
/* audio class v1 reports possible sample rates as part of the
@@ -365,16 +365,16 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
365365
switch (format) {
366366
case UAC_FORMAT_TYPE_II_AC3:
367367
/* FIXME: there is no AC3 format defined yet */
368-
// fp->format = SNDRV_PCM_FORMAT_AC3;
369-
fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */
368+
// fp->formats = SNDRV_PCM_FMTBIT_AC3;
369+
fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */
370370
break;
371371
case UAC_FORMAT_TYPE_II_MPEG:
372-
fp->format = SNDRV_PCM_FORMAT_MPEG;
372+
fp->formats = SNDRV_PCM_FMTBIT_MPEG;
373373
break;
374374
default:
375375
snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n",
376376
chip->dev->devnum, fp->iface, fp->altsetting, format);
377-
fp->format = SNDRV_PCM_FORMAT_MPEG;
377+
fp->formats = SNDRV_PCM_FMTBIT_MPEG;
378378
break;
379379
}
380380

‎sound/usb/pcm.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned
5858
list_for_each(p, &subs->fmt_list) {
5959
struct audioformat *fp;
6060
fp = list_entry(p, struct audioformat, list);
61-
if (fp->format != format || fp->channels != channels)
61+
if (!(fp->formats & (1uLL << format)))
62+
continue;
63+
if (fp->channels != channels)
6264
continue;
6365
if (rate < fp->rate_min || rate > fp->rate_max)
6466
continue;
@@ -428,10 +430,15 @@ static int hw_check_valid_format(struct snd_usb_substream *subs,
428430
struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
429431
struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
430432
struct snd_interval *pt = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
433+
struct snd_mask check_fmts;
431434
unsigned int ptime;
432435

433436
/* check the format */
434-
if (!snd_mask_test(fmts, fp->format)) {
437+
snd_mask_none(&check_fmts);
438+
check_fmts.bits[0] = (u32)fp->formats;
439+
check_fmts.bits[1] = (u32)(fp->formats >> 32);
440+
snd_mask_intersect(&check_fmts, fmts);
441+
if (snd_mask_empty(&check_fmts)) {
435442
hwc_debug(" > check: no supported format %d\n", fp->format);
436443
return 0;
437444
}
@@ -584,7 +591,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
584591
fp = list_entry(p, struct audioformat, list);
585592
if (!hw_check_valid_format(subs, params, fp))
586593
continue;
587-
fbits |= (1ULL << fp->format);
594+
fbits |= fp->formats;
588595
}
589596

590597
oldbits[0] = fmt->bits[0];

‎sound/usb/proc.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
7979

8080
list_for_each(p, &subs->fmt_list) {
8181
struct audioformat *fp;
82+
snd_pcm_format_t fmt;
8283
fp = list_entry(p, struct audioformat, list);
8384
snd_iprintf(buffer, " Interface %d\n", fp->iface);
8485
snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
85-
snd_iprintf(buffer, " Format: %s\n",
86-
snd_pcm_format_name(fp->format));
86+
snd_iprintf(buffer, " Format:");
87+
for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
88+
if (fp->formats & (1uLL << fmt))
89+
snd_iprintf(buffer, " %s",
90+
snd_pcm_format_name(fmt));
91+
snd_iprintf(buffer, "\n");
8792
snd_iprintf(buffer, " Channels: %d\n", fp->channels);
8893
snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
8994
fp->endpoint & USB_ENDPOINT_NUMBER_MASK,

‎sound/usb/quirks-table.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
279279
.ifnum = 0,
280280
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
281281
.data = & (const struct audioformat) {
282-
.format = SNDRV_PCM_FORMAT_S16_LE,
282+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
283283
.channels = 4,
284284
.iface = 0,
285285
.altsetting = 1,
@@ -296,7 +296,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
296296
.ifnum = 1,
297297
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
298298
.data = & (const struct audioformat) {
299-
.format = SNDRV_PCM_FORMAT_S16_LE,
299+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
300300
.channels = 2,
301301
.iface = 1,
302302
.altsetting = 1,
@@ -580,7 +580,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
580580
.ifnum = 0,
581581
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
582582
.data = & (const struct audioformat) {
583-
.format = SNDRV_PCM_FORMAT_S24_3LE,
583+
.formats = SNDRV_PCM_FMTBIT_S24_3LE,
584584
.channels = 2,
585585
.iface = 0,
586586
.altsetting = 1,
@@ -597,7 +597,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
597597
.ifnum = 1,
598598
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
599599
.data = & (const struct audioformat) {
600-
.format = SNDRV_PCM_FORMAT_S24_3LE,
600+
.formats = SNDRV_PCM_FMTBIT_S24_3LE,
601601
.channels = 2,
602602
.iface = 1,
603603
.altsetting = 1,
@@ -793,7 +793,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
793793
.ifnum = 1,
794794
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
795795
.data = & (const struct audioformat) {
796-
.format = SNDRV_PCM_FORMAT_S24_3LE,
796+
.formats = SNDRV_PCM_FMTBIT_S24_3LE,
797797
.channels = 2,
798798
.iface = 1,
799799
.altsetting = 1,
@@ -810,7 +810,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
810810
.ifnum = 2,
811811
.type = QUIRK_AUDIO_FIXED_ENDPOINT,
812812
.data = & (const struct audioformat) {
813-
.format = SNDRV_PCM_FORMAT_S24_3LE,
813+
.formats = SNDRV_PCM_FMTBIT_S24_3LE,
814814
.channels = 2,
815815
.iface = 2,
816816
.altsetting = 1,

‎sound/usb/quirks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
174174
const struct snd_usb_audio_quirk *quirk)
175175
{
176176
static const struct audioformat ua_format = {
177-
.format = SNDRV_PCM_FORMAT_S24_3LE,
177+
.formats = SNDRV_PCM_FMTBIT_S24_3LE,
178178
.channels = 2,
179179
.fmt_type = UAC_FORMAT_TYPE_I,
180180
.altsetting = 1,

‎sound/usb/urb.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
662662
urb->number_of_packets = ctx->packets;
663663
urb->transfer_buffer_length = offs * stride;
664664
memset(urb->transfer_buffer,
665-
subs->cur_audiofmt->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
665+
runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
666666
offs * stride);
667667
return 0;
668668
}
@@ -924,7 +924,7 @@ void snd_usb_init_substream(struct snd_usb_stream *as,
924924
snd_usb_set_pcm_ops(as->pcm, stream);
925925

926926
list_add_tail(&fp->list, &subs->fmt_list);
927-
subs->formats |= 1ULL << fp->format;
927+
subs->formats |= fp->formats;
928928
subs->endpoint = fp->endpoint;
929929
subs->num_formats++;
930930
subs->fmt_type = fp->fmt_type;

0 commit comments

Comments
 (0)