Re: [Fx2lib-devel] Isochronous Streaming Using LibUSB from FPGA
Status: Beta
Brought to you by:
mulicheng
|
From: Vincent P. <plr...@gm...> - 2012-01-22 11:10:55
|
Hi.
<offtopic>
Sorry, this message is not properly threaded: I just happened to find the
original thread in archives, and I cannot find a way to get relevant mail
headers.
I hope this mail will catch original poster's attention.
</offtopic>
Nice to see someone using my python-libusb1 for isochronous with (some)
success ! I must admit I haven't tested isochronous transfers support properly
myself.
I have some comments on the python script from original post which might help
improving the situation, if that's still relevant:
- You are creating one transfer object per actual transfer. You should
probably reuse them instead by calling "newxfer.submit()" in
SubmitThread.createDataThread. In turn, you should remove the infinite loop
in SubmitThread.run, so that you only create a fixed amount of transfers,
submit them, and do nothing (actually just looping over handleEvents()).
In turn, this means you don't need to have 2 threads for creating transfers
and handling events: just do that sequentially.
- You are creating one throw-away thread per completed transfer. I'm afraid
this has quite some overhead, with little benefit because of the python GIL.
I would instead immediately handle data in transfer callback (if processing
is fast enough and you have enough submited transfers to always have some
still submited) or otherwise pipe them to another thread/process.
Resulting code would look like:
import usb1
def handleData(transfer):
# Fetch data from transfer here, check status to see if you should really
# re-submit (you probably don't want to if status shows an error).
transfer.submit()
# Do some data handling/piping here.
print "We phoned home."
def main():
context=usb1.LibUSBContext()
context.setDebug(3)
fx2=self.context.openByVendorIDAndProductID(0x04b4,0x1004)
fx2.claimInterface(0)
for _ in xrange(10): # Tweak this magic "10"
transfer_object1=fx2.getTransfer(500)
transfer_object1.setIsochronous(endpoint=0x82,buffer_or_len=(1024*500),
callback=handleData)
transfer_object1.submit()
while True:
context.handleEvents()
if __name__ == '__main__':
main()
Regards,
--
Vincent Pelletier
|