From: Clemens Ladisch Date: Fri, 12 Aug 2005 06:28:27 +0000 (+0200) Subject: [ALSA] usb-audio: fix packets per URB calculation for playback X-Git-Tag: v2.6.14-rc1~1029^2~52 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6db392e9235c48bb945624798e9beede7b85b12;p=pandora-kernel.git [ALSA] usb-audio: fix packets per URB calculation for playback USB generic driver When determining how many packets are needed for one period, we cannot assume that all packets have their maximum size -- we always use the nominal sample rate when sending data, and could use an even lower rate when the endpoint uses frequency feedback. Signed-off-by: Clemens Ladisch --- diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index 9e38d3d1322a..d28106e390c4 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c @@ -938,7 +938,15 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by /* decide how many packets to be used */ if (is_playback) { - total_packs = (period_bytes + maxsize - 1) / maxsize; + unsigned int minsize; + /* determine how small a packet can be */ + minsize = (subs->freqn >> (16 - subs->datainterval)) + * (frame_bits >> 3); + /* with sync from device, assume it can be 25% lower */ + if (subs->syncpipe) + minsize -= minsize >> 2; + minsize = max(minsize, 1u); + total_packs = (period_bytes + minsize - 1) / minsize; if (total_packs < 2 * MIN_PACKS_URB) total_packs = 2 * MIN_PACKS_URB; } else {