linuxioctlv4l2

difference between v4l2_ioctl and ioctl


I am currently investigating how we can use v4l2 devices from python, and found that python has a binding for ioctl (https://docs.python.org/3/library/fcntl.html).

I done some implemntations in C, but i have a hard time understanding if ioctl is the same as v4l2_ioctl?

They seem to take the exact same arguments, in the official examples i see both wrapped in a function, that is used in the same way:

static void xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = v4l2_ioctl(fh, request, arg);
        } while (r == -1 && ((errno == EINTR) || (errno == EAGAIN)));

        if (r == -1) {
                fprintf(stderr, "error %d, %s\\n", errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
}

And for the normal ioctl:

static int xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = ioctl(fh, request, arg);
        } while (-1 == r && EINTR == errno);

        return r;
}

I looked in the linux repository, but could not figure out the exact difference between the two.

Can i use ioctl and v4l2_ioctl interchangeably?
If so why does both exist?
If not, what is the limitations of ioctl compared to v4l2_ioctl?


Solution

  • Can i use ioctl and v4l2_ioctl interchangeably?

    No.

    If so why does both exist?

    ioctl exists to do some special operations on devices.

    v4l2_ioctl is a wrapper from libv4l2 to simplify operations on v4l2 devices.

    From README:

    libv4l2

    This offers functions like v4l2_open, v4l2_ioctl, etc. which can by used to quickly make v4l2 applications work with v4l2 devices with weird formats. libv4l2 mostly passes calls directly through to the v4l2 driver. When the app does a TRY_FMT / S_FMT with a not supported format libv4l2 will get in the middle and emulate the format (if an app wants to know which formats the hardware can really do it should use ENUM_FMT, not randomly try a bunch of S_FMT's). For more details on the v4l2_ functions see libv4l2.h .

    And the source found in libv4l project is the ultimate code documentation.