简体   繁体   中英

Linux V4L driver - Polling camera input format

I am unfamiliar with Linux kernel development but I'm tasked with updating a kernel driver so that it will return a status code that can be read by an application. This will require that the driver poll the hardware a couple of times a second to see what camera format is being sent (PAL, NTSC, or none).

However, I'm at a loss on how this would be accomplished. I understand how the driver communicates with the hardware, but I don't understand how to pass this data to the application. Does this type of behavior require the use of an ioctl() call or is this a read file operation? Also if the application is calling an IOCTL or read function and then needs to wait for the hardware to respond will this create a performance issue?

Also for added information, I am working on a 2.6 version of the kernel. I'm working my way through "Linux Device Drivers 3rd Ed", but nothing stands out on how to address this specific issue. LDD3 makes it sound like ioctl() only for sending commands to the driver. Since this is a V4L driver, open file will return image data, not the status information I want, I think.

I recommend checking the latest V4L2 API document, hosted on linuxtv.org: http://linuxtv.org/downloads/v4l-dvb-apis/

Userspace applications can call an IOCTL to query the current input format. The following userspace code can be used to query the kernel driver for the current video standard:

(quoting http://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html#standard )

Example 1.5. Information about the current video standard

v4l2_std_id std_id;
struct v4l2_standard standard;

if (-1 == ioctl (fd, VIDIOC_G_STD, &std_id)) {
    /* Note when VIDIOC_ENUMSTD always returns EINVAL this
       is no video device or it falls under the USB exception,
       and VIDIOC_G_STD returning EINVAL is no error. */

    perror ("VIDIOC_G_STD");
    exit (EXIT_FAILURE);
}

memset (&standard, 0, sizeof (standard));
standard.index = 0;

while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {
    if (standard.id & std_id) {
           printf ("Current video standard: %s\n", standard.name);
           exit (EXIT_SUCCESS);
    }

    standard.index++;
}

/* EINVAL indicates the end of the enumeration, which cannot be
   empty unless this device falls under the USB exception. */

if (errno == EINVAL || standard.index == 0) {
    perror ("VIDIOC_ENUMSTD");
    exit (EXIT_FAILURE);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM