[haiku-development] [USB] What is the right way to feed queue_isochronous with audio data?

  • From: Siarzhuk Zharski <zharik@xxxxxx>
  • To: <haiku-development@xxxxxxxxxxxxx>
  • Date: Fri, 22 Jan 2010 14:11:05 +0100

Hallo All!

I have some questions about using isochronous USB transfers with Haiku USB
interface version 3. There are some problems and I have seen no samples of
using such transfers under Haiku. :-( Looks like my usb_audio driver will
be the first one. ;-) 

At the moment I'm stopped on calling queue_isochronous for some audio
data. As you know, the function prototype looks like this:

status_t (*queue_isochronous)(usb_pipe pipe, void *data, size_t
dataLength, usb_iso_packet_descriptor *packetDesc, uint32 packetCount,
                                 uint32 *startingFrameNumber, uint32
flags, usb_callback_func callback, void *callbackCookie);

First of all some words about allocating buffers used simultaneously both
to multi-audio buffers exchange and submitting with queue_isochronous.
Every audio stream logically connected to isochronous interface allocate
the memory area. This area is big enought to contains both audio data
buffers and array of usb_iso_packet_descriptor's:
http://dev.haiku-os.org/browser/haiku/branches/developer/siarzhuk/usb_audio/Stream.cpp#L125
The layout of this area begins with descriptors array and continues with
audio data buffers. There are typically 2 audio data buffers for every usb
audio stream. Note that I have also initialized those descriptors in some
way (see line #154). May be it is significant.

On first call of multi-buffer-exchange ioctl I'm perform the "start of
stream operation" - I submit first buffer of audio data into
queue_isochronous call. Please look on function Stream::_QueueNextTransfer
at line 234 for details. The "data" argument points to start of audio data
buffer, "dataLength" is the size of this buffer, "packetDesc" points to
start of descriptors array, "packetCount" is the count of descriptors used
in this transfer, "callback" points to static Stream::_TransferCallback
function, "callbackCookie" is a "this" pointer for the current Stream
object. Note that "MaxFrameSize requirement" for this endpoint is satisfied
by adjusted count of descriptors. But the meaning of "flags" and
"startingFrameNumber" is still unclear for me. :-( 

After submitting this buffer I receive "_TransferCallback" notification
with the "status" B_OK and "actualLength" equal to 0. Looks like the length
should be not zero in case of successful transfer. I think that indicate
some problems either with my call or isochronous handling in the
corresponding USB bus manager. I have activated extra tracing in USB
modules and found that my transfer was submitted correctly - both messages
at line 1047
http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp#L1074
and line 1127 were displayed with correct data I have submitted. Looks
like the FinishIsochronousTransfers thread was waked up too. But there are
no more traces about this transfer. :-(

Note that I have tried this on the system with UHCI USB HW controller and
both with "ehci" and "uhci" modules. The device I have tested is USB 1.1
audio. 

The Questions:
 #1: Is it correct to provide descriptors array and audio data buffer from
the same memory area in the way I have described above? Note that they are
not overlapped.
 #2: What is the meaning of "startingFrameNumber" parameter in the
queue_isochronous call? 
 #3: Should _TransferCallback provide me a real length of transferred data
in "actualLength" parameter?
 #4: Are there any suggestions to trace anything else? :-)

Thank you!

-- 
Kind Regards,
   S.Zharski

Other related posts: