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

Daniel Griscom griscom at suitable.com
Sun Nov 25 23:23:20 CET 2012


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.

Here's the code I used in /usb/endpoint.c, prepare_outbound_urb():

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

...

>		if (ep->prepare_data_urb) {
>#if 1
>			ep->prepare_data_urb(ep->data_subs, urb);
>#else
>		  /* Fake constantly increasing samples */
>		  unsigned int offs = 0;
>		  for (i = 0; i < ctx->packets; ++i) {
>		      int counts;
>
>		      if (ctx->packet_size[i])
>			counts = ctx->packet_size[i];
>		      else
>			counts = snd_usb_endpoint_next_packet_size(ep);
>
>		      urb->iso_frame_desc[i].offset = offs * ep->stride;
>		      urb->iso_frame_desc[i].length = counts * ep->stride;
>		      offs += counts;
>		  }
>
>		  urb->number_of_packets = ctx->packets;
>		  urb->transfer_buffer_length = offs * ep->stride;
>		  for (i = 0, sp = (short *)(urb->transfer_buffer);
>		       i < offs * ep->stride; /* no increment */) {
>		    *sp++ = left++;
>		    i += sizeof(short);
>		    *sp++ = right++;
>		    i += sizeof(short);
>		  }
>#endif
>		} else {

With the "#if 1", the code is stock, and about 30% of my tests 
resulted in the stuttering USB packets (but with data from my 
application). With it changed to "#if 0", I generated and saw the 
incrementing data, but the USB packets never misbehaved (even after 
more than 20 tries). I switched back and forth, and the problem 
clearly appeared and disappeared.

I think I should give more information about my tests. This problem 
is very intermittent, and difficult to reproduce. However, I found a 
case where it often happens: at boot, where my app starts up right 
about when the USB devices are starting up. So, each of the "tests" 
above consisted of me rebooting my system and watching the Beagle's 
trace for good versus bad packet patterns.


Thanks again for the continuing help,
Dan

-- 
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