[alsa-devel] Missing exactly 3 of 8 audio packets?

Daniel Griscom griscom at suitable.com
Mon Nov 26 22:23:18 CET 2012

At 8:19 AM +0100 11/26/12, Daniel Mack wrote:
>On 25.11.2012 23:23, Daniel Griscom wrote:
>>  At 1:43 PM +0100 11/25/12, Daniel Mack wrote:
>>>  Please do another test and change prepare_outbound_urb() so that instead
>>>  of calling ep->prepare_data_urb() to fill the URB, fill it directly with
>>>  some sort of easily recognizable test pattern (you can take the code
>>>from "silence" case to access the buffers). Some kind of 16-bit counter
>>>  should do. And then check the payload with the Beagle and see whether
>>>  the pattern has gaps.
>>>  This test will tell us whether data is in fact lost before it hits the
>>>  usb audio driver, or if it's dropped by the USB HCD.
>>  I did the test, and expected to either a) see the incrementing data
>>  be contiguous even though the USB packet transmission was stuttering,
>>  or b) see the incrementing data have gaps where the "missing" packets
>  > were. However, what I saw was c): the USB packets never misbehaved.
>Note that this is a potential difference between your two cases.
>prepare_playback_urb() from pcm.c will not always set
>urb->number_of_packets to the maximum value but cut packets short at PCM
>period boundaries.
>Could you move your pattern generating code down to that function? Just
>look for the memcpy() calls there.

OK, this time I got some real results. I can still get the USB packet 
stream to misbehave, and indeed the synthesized data is being lost. 
The output data present on the USB bus smoothly increments during 
each packet, continuing smoothly in adjacent packets. But, when one 
or two packets are missed, the next output data is numbered as if the 
packets (6 stereo frames each) had been generated but lost.

Here's my code in linux-3.6.6/sound/usb/pcm.c, prepare_playback_urb():

>	static short left = 0;
>	static short right = 0x0404;
>	short *sp;


>	bytes = frames * stride;
>#define FAKE_DATA
>#ifdef FAKE_DATA
>	for (i = 0, sp = (short *)(urb->transfer_buffer);
>	   i < bytes; /* no increment */) {
>		*sp++ = left++;
>		i += sizeof(*sp);
>		*sp++ = right++;
>		i += sizeof(*sp);
>	}
>	if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
>		/* err, the transferred area goes over buffer boundary. */
>		unsigned int bytes1 =
>			runtime->buffer_size * stride - subs->hwptr_done;
>		memcpy(urb->transfer_buffer,
>		       runtime->dma_area + subs->hwptr_done, bytes1);
>		memcpy(urb->transfer_buffer + bytes1,
>		       runtime->dma_area, bytes - bytes1);
>	} else {
>		memcpy(urb->transfer_buffer,
>		       runtime->dma_area + subs->hwptr_done, bytes);
>	}
>	subs->hwptr_done += bytes;

Did I place the generation code in the correct location?

And, what should I look at next?

Thanks again,

Daniel T. Griscom             griscom at suitable.com
Suitable Systems              http://www.suitable.com/
1 Centre Street, Suite 204    (781) 665-0053
Wakefield, MA  01880-2400

More information about the Alsa-devel mailing list