USB streaming buffers

USB streaming buffers

DVB USB allocates rather big chunks of coherent memory buffers for the USB streaming at the start and frees those on disconnect. One buffer is reserved for each used USB URB, which is around 5-7 buffers as there is that many URBs used generally. After the multi-frontend (MFE) implementation own USB streaming buffers were allocated for every frontend. Currently there is three frontends registered for the single adapter in worst case. And what is the problem: only one frontend can be used at the same time and we allocate buffers for all the three!

I resolved problem allocating biggest needed buffer at the start and changed all frontends in given adapter to use that. URB configuration is performed dynamically to fit needed stream. Quite lightweight solution. Maybe there is still room for the improvement as it allocs and frees URBs every time when streaming configuration is changed. Allocating and freeing few URBs is very cheap operation but it could be avoided unless USB endpoint type is changed (bulk or isochronous). And after all use case where frontend is changed all the time is very unusual. User just choose one frontend, which offer needed television standard, and uses that. So it must be fine :)

What is expensive in whole subject is coherent USB transfer buffer and now it is used 2/3 less than earlier. Someone would like to ask why not to alloc and frees all the memory, URBs and buffers, every time when streaming is started and stopped. There is very good reason to avoid continuous allocs and frees as memory goes fragmented and finally allocation of big coherent chunks of buffer memory will fail. That is realized few times in the recent future as some other DVB devices are stopped working. Limited memory is especially problem of embedded devices.  Believe or not, it is very common DVB sticks are used on embedded routers or STBs.

Related links

[PATCH] em28xx: pre-allocate DVB isoc transfer buffers

DVB USB: change USB stream settings dynamically

No comments:

Post a Comment