Video device opening and property management
Drivers expose node entries in the /dev/
directory corresponding to the video interfaces they are responsible for. These file nodes correspond to the /dev/videoX
special files for capture devices (in our case). The application must open the appropriate file node prior to any interaction with the video device. It uses the open()
system call for that, which will return a file descriptor that will be the entry point for any command sent to the device, as in the following example:
static const char *dev_name = "/dev/video0"; fd = open (dev_name, O_RDWR); if (fd == -1) { Â Â Â Â perror("Failed to open capture device\n"); Â Â Â Â return -1; }
The preceding snippet is an opening in blocking mode. Passing O_NONBLOCK
to open()
would prevent the application from being blocked if there is no ready buffer while trying to dequeue. Once you're done with the video device, it should be closed...