[Libdlo] Synchronous vs. asynchronous USB

Phil Endecott spam_from_libdlo at chezphil.org
Mon May 25 05:35:26 PDT 2009


Dear All,

At the bottom level, libdlo calls libusb's synchronous data transfer 
function, usb_bulk_write().  This waits for all the data to be 
transferred before returning, which is going to be non-optimal in some 
cases.  For example, a video player would want to decode a frame, queue 
the decoded data for transfer, and immediately start decoding the next 
frame.  With the current design it will waste time waiting for the 
first frame to be completely transferred to the device before starting 
to decode the second.

I think that the only way to use the current design efficiently is to 
have multiple threads.  Even then, the format conversion inside libdlo 
will run sequentially with the USB data transfers.

The "classical" solution to this sort of problem is to make the program 
revolve around a select() call.  Unfortunately the current design of 
the USB kernel API doesn't fit with select().  What it can support is 
async I/O with signals.  I have used this previously but not via 
libusb.  It is non-trivial but probably essential for high performance.

I'm not sure what libdlo should do about this.  Perhaps a useful first 
step is to make it possible for users to get at the format conversion 
stuff separately from the USB transport.  I.e. (pseudo-code) 
re-implement things like dlo_copy_host_bmp as follows:

dlo_copy_host_bmp(...) {
   buffer buf;
   dlo_make_copy_host_bmp_cmds(....,buf);
   usb_bulk_write(buf);
}

Then make the function that does the command generation / format 
conversion work (here dlo_make_copy_host_bmp_cmds) accessible via the 
public API.  A user who wants to use the async USB API can then get the 
data that they need to send and arrange to do that themselves.


Changing the subject slightly: one other reason for decoupling the 
format conversion from the transport is to use a different 
(intermediate) transport, e.g. sending the data over the network.  I 
have been looking at this thing for a while, wondering what I could do 
with it:

     http://oldwiki.openwrt.org/OpenWrtDocs(2f)Hardware(2f)Huawei(2f)D100.html

Basically it's WiFi + MIPS processor running Linux + 32 MBytes RAM + 1 
USB 2.0 host controller. Plug this in to your DisplayLink device and 
you have a wireless display.


Phil.






More information about the Libdlo mailing list