<pstyle='text-align: justify;'>I was recently working on an application where streams from four multiplexed analog video channels had to be displayed in four windows. I was trying to do this using OpenCV while the analog video decoder/multiplexer in question was the ADV7180. For switching the channels, I was using an ioctl() call to switch the channels in a while loop with a certain time interval, while capturing the frames and putting them in a separate queues as per the channel selected. This was done in the main thread, while separate threads pulled the frames from the queue and rendered them. The capturing and rendering part was being done with OpenCV. I was not able to achieve a decent enough frame rate with this. I had put delays in certain places to avoid frame glitches in the multiple windows displaying the frames.</p>
<pstyle='text-align: justify;'>Thinking that may be the ioctl() call and the context switch is the reason I have to use delays and this is going slow, I decided to look into ways of transferring data faster between the user and kernel space, instead of using an ioctl() call. An mmap() implementation in a driver or a memory mapping between user and kernel space is the fastest way to transfer data. This approach doesn't incur a context switch nor a memory buffer copying. Below is a sample code showing how a mmap() implementation for a driver is done.</p>
<pstyle='text-align: justify;'>The above code should run well for both desktop or embedded Linux. For learning more, refer to Chapter 15 of the Linux Device Drivers book.</p>
<pstyle='text-align: justify;'>Ultimately though, I didn't do a mmap() but decided to do the switching channel work in the driver itself using kernel timers and workqueues. Not that this improved the frame rate much either, may be a 1 frame per second improvement. May be someone will give me some feedback some day with this task. Till then, hope you find this post useful.</p>