Commit 8ab355d6 authored by Takashi Iwai's avatar Takashi Iwai Committed by Greg Kroah-Hartman
Browse files

ALSA: usb-audio: Work around for XRUN with low latency playback

commit 4267c5a8 upstream.

The recent change for low latency playback works in most of test cases
but it turned out still to hit errors on some use cases, most notably
with JACK with small buffer sizes.  This is because USB-audio driver
fills up and submits full URBs at the beginning, while the URBs would
return immediately and try to fill more -- that can easily trigger
XRUN.  It was more or less expected, but in the small buffer size, the
problem became pretty obvious.

Fixing this behavior properly would require the change of the
fundamental driver design, so it's no trivial task, unfortunately.
Instead, here we work around the problem just by switching back to the
old method when the given configuration is too fragile with the low
latency stream handling.  As a threshold, we calculate the total
buffer bytes in all plus one URBs, and check whether it's beyond the
PCM buffer bytes.  The one extra URB is needed because XRUN happens at
the next submission after the first round.

Fixes: 307cc9ba ("ALSA: usb-audio: Reduce latency at playback start, take#2")
Cc: <>

Signed-off-by: default avatarTakashi Iwai <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent d789944b
......@@ -94,6 +94,7 @@ struct snd_usb_endpoint {
struct list_head ready_playback_urbs; /* playback URB FIFO for implicit fb */
unsigned int nurbs; /* # urbs */
unsigned int nominal_queue_size; /* total buffer sizes in URBs */
unsigned long active_mask; /* bitmask of active urbs */
unsigned long unlink_mask; /* bitmask of unlinked urbs */
char *syncbuf; /* sync buffer for all sync URBs */
......@@ -187,6 +188,7 @@ struct snd_usb_substream {
} dsd_dop;
bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
bool early_playback_start; /* early start needed for playback? */
struct media_ctl *media_ctl;
......@@ -1126,6 +1126,10 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep)
/* total buffer bytes of all URBs plus the next queue;
* referred in pcm.c
ep->nominal_queue_size = maxsize * urb_packs * (ep->nurbs + 1);
return 0;
......@@ -614,6 +614,14 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
subs->period_elapsed_pending = 0;
runtime->delay = 0;
/* check whether early start is needed for playback stream */
subs->early_playback_start =
subs->direction == SNDRV_PCM_STREAM_PLAYBACK &&
subs->data_endpoint->nominal_queue_size >= subs->buffer_bytes;
if (subs->early_playback_start)
ret = start_endpoints(subs);
return ret;
......@@ -1394,7 +1402,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
subs->trigger_tstamp_pending_update = false;
if (period_elapsed && !subs->running) {
if (period_elapsed && !subs->running && !subs->early_playback_start) {
subs->period_elapsed_pending = 1;
period_elapsed = 0;
......@@ -1448,7 +1456,8 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea
if (!subs->early_playback_start &&
err = start_endpoints(subs);
if (err < 0) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment