Saturday, June 8, 2013

V4L2 Tutorial




V4L2 - video for linux 2 is a set of APIs and standards for handling video devices on Linux. Video devices could be camera sensors providing streams, video encoder , video decoder and apart from these there could be analog radio and any output drivers as device. So mainly all the v4l2 devices would be char type device and each devices get represented by its names in the /dev tree like /dev/video. If there is multiple device or video related data, streams then there can be multiple video device names like /dev/video0 , /dev/video1 , basically /dev/videoX. 

Since it provides set of APIs to handle these devices which lies in physical memory region of the system and get juice from kernel. So v4l2 gets integrated with media framework and resides in kernel as v4l2 driver ,helps to integrate the device/sub-device kernel driver with the media framework. 
V4L2 API includes a very long list of driver callbacks to respond to the many ioctl() commands made available to user space.









     


Kernel Side V4L2 Operations : -
a)Opening V4L2 device using v4l2_open()
b) Controlling V4L2 device using v4l2_ioctl()
c) Reading from V4L2 device using v4l2_read()
d) Writing onto V4L2 device using v4l2_write()
e) Polling onto V4L2 device using v4l2_poll()
f) Mmaping v4L2 device using v4l2_mmap()
g) Closing V4L2 device using v4l2_release()

for ex:
fd = open("/dev/video0", O_RDWR);
close(fd)

V4L2 ioctl : 
a)VIDIOC_S_FORMAT
b)VIDIOC_S_CTRL
c)VIDIOC_REQBUFS
d)VIDIOC_QUERYBUF
e)VIDIOC_QBUF
f)VIDIOC_STREAMON
g)VIDIOC_DQBUF
h)VIDIOC_STREAMOFF


Video Buffer :

In video4linux , we have a video buffer layer which acts as medium between v4l2 driver and app(user side). There is video device which will be streaming data(video frames) into video buffers (vb) . So that said it will require to implement calls like buffer allocation , queuing , dequeuing, streaming I/O and other streaming controls like start/stop. Its not just only reduces only driver code but also provides an uniform and standard APIs for app/user side.

To know more in detail : please follow the kernel documentation
https://www.kernel.org/doc/Documentation/video4linux/videobuf








1 comment:

  1. I am trying to send a frame to SDI out can anyone send a sample code to send frames to SDI out in a streaming output.

    ReplyDelete