Video Capture Initialization
IOCTLcalls:Input/Output control (system calls) for device specific input/output operations.
eg: volume control for an audio device, display configuration for video device etc...
Programming a V4L2 device consist of:
Opening the device
This set up uses the open function to return a file descriptor. The call to open as follows:
char* deviceName = "/dev/video*";
int deviceHandle = open(deviceName,O_RDONLY);
if call success , the deviceHandle will contain valid handler to the device.
Query the capabilities of the device
ioctl(device_handle,VIDIOC_QUERYCAP,v4l2_capability)
This provides information about the device such as whether device capture video, supports video overlay etc...
Initialize MemoryMap
Memory Mapped Input|Output(MIMO) interface:This method uses the MIMO interface to map video buffers into our process memory space. From here we can obtain pointers directly to the captured buffer to perform reading.
ioctl(device_handle,VIDIOC_REQBUFS,v4l2_requestbuffers)
Above ioctl call checks whether it supports memory mapping or not.
ioctl(device_handle,VIDIOC_QUERYBUF, v4l2_buffer)
It is used for streaming I/O methods.
mmap(NULL,v4l2_buffer.length,PROT_READ,MAP_SHARED,device_handle,v4l2_buffer.m.offset)
creates a new mapping in the virtual address space.if address is null kernel chooses the address. PROT_READ(to read pages), MAP_SHARED(share the mapping)
Closing the Device
Device is closed using the ioctl call .