V4L2命令之 VIDIOC_ENUM_FMT VIDIOC_ENUM_FRAMESIZES VIDIOC_ENUM_FRAMEINTERVALS

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-enum-frameintervals.html

VIDIOC_ENUM_FMT

Name

VIDIOC_ENUM_FMT — Enumerate image formats  // 列举设备所支持的格式

Synopsis

int ioctl(int fd,

int request,

struct v4l2_fmtdesc*argp);
 

Arguments

fd

File descriptor returned by open().

request

VIDIOC_ENUM_FMT

argp

Description

To enumerate image formats applications initialize thetype and index field of struct v4l2_fmtdesc and call theVIDIOC_ENUM_FMT ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an EINVAL error code. All formats are enumerable by beginning at index zero and incrementing by one until EINVAL is returned.

Note that after switching input or output the list of enumerated image formats may be different.

Table A.24. struct v4l2_fmtdesc

__u32indexNumber of the format in the enumeration, set by the application. This is in no way related to the pixelformat field.
__u32typeType of the data stream, set by the application.Only these types are valid here:V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_OUTPUT, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE  and V4L2_BUF_TYPE_VIDEO_OVERLAY. See Table 3.3, “enum v4l2_buf_type”.
__u32flagsSee Table A.25, “Image Format Description Flags”
__u8description[32]Description of the format, a NUL-terminated ASCII string. This information is intended for the user, for example: "YUV4:2:2".
__u32pixelformatThe image format identifier. This is a four character code as computed by the v4l2_fourcc() macro:
#define v4l2_fourcc(a,b,c,d) (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))

Several image formats are already defined by this specification in Chapter 2, Image Formats. Note these codes are not the same as those used in the Windows world.

__u32reserved[4]Reserved for future extensions. Drivers must setthe array to zero.

Table A.25. Image Format Description Flags

V4L2_FMT_FLAG_COMPRESSED0x0001This is a compressed format.
V4L2_FMT_FLAG_EMULATED0x0002This format is not native to the device but emulated through software (usually libv4l2), where possible try to use a native format instead for better performance.

Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.

EINVAL

The struct v4l2_fmtdesc typeis not supported or the index is out ofbounds.

例子:

int enum_frame_formats(int dev) // dev是利用open打开的设备文件描述符
{
    int ret;
    struct v4l2_fmtdesc fmt;

    memset(&fmt, 0, sizeof(fmt));
    fmt.index = 0;
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    while ((ret = ioctl(dev, VIDIOC_ENUM_FMT, &fmt)) == 0) {
        fmt.index++;
        printf("{ pixelformat = '%c%c%c%c', description = '%s' }\n",
                fmt.pixelformat & 0xFF, (fmt.pixelformat >> 8) & 0xFF,
                (fmt.pixelformat >> 16) & 0xFF, (fmt.pixelformat >> 24) & 0xFF,
                fmt.description);
        ret = enum_frame_sizes(dev, fmt.pixelformat); // 列举该格式下的帧大小
        if (ret != 0)
            printf("  Unable to enumerate frame sizes.\n");
    }
    if (errno != EINVAL) {
        printf("ERROR enumerating frame formats: %d\n", errno);
        return errno;
    }

    return 0;
}



VIDIOC_ENUM_FRAMESIZES

Name

VIDIOC_ENUM_FRAMESIZES — Enumerate frame sizes

Synopsis

int ioctl(int fd,

int request,

struct v4l2_frmsizeenum *argp);
 

Arguments

fd

File descriptor returned by open().

request

VIDIOC_ENUM_FRAMESIZES

argp

Pointer to a struct v4l2_frmsizeenum that contains an index and pixel format and receives a frame width and height.

Description

This ioctl allows applications to enumerate all frame sizes(i. e. width and height in pixels) that the device supports for the given pixel format.

The supported pixel formats can be obtained by using theVIDIOC_ENUM_FMT function.

The return value and the content of thev4l2_frmsizeenum.type  field depend on the type of frame sizes the device supports. Here are the semantics of thefunction for the different cases:

// 一般在调用这个命令后,通过v4l2_frmsizeenumtype  域来决定后续的操作,

  • Discrete: The function returns success if the given index value (zero-based) is valid. The application should increase the index by one for each call until EINVAL is returned. The v4l2_frmsizeenum.type field is set to V4L2_FRMSIZE_TYPE_DISCRETE by the driver. Of the union only the discrete member isvalid.

  • Step-wise: The function returns success if the given index value is zero and EINVAL for any other index value. The v4l2_frmsizeenum.type field is set to V4L2_FRMSIZE_TYPE_STEPWISE by the driver. Of the union only the stepwise member isvalid.

  • Continuous: This is a special case of the step-wise type above. The function returns success if the given index value is zero and EINVAL for any other index value. The v4l2_frmsizeenum.type field is set to V4L2_FRMSIZE_TYPE_CONTINUOUS by the driver. Of the union only the stepwise member is valid and the step_width  and step_height values are set to 1.

When the application calls the function with index zero, it must check the type field to determine the type of frame size enumeration the device supports. Only for the V4L2_FRMSIZE_TYPE_DISCRETE type does it make sense to increase the index value to receive more frame sizes.

Note that the order in which the frame sizes are returned has no special meaning. In particular does it not say anything about potential default format sizes.

Applications can assume that the enumeration data does not change without any inter action from the application itself. This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame size enumeration.

Structs

In the structs below, IN denotes avalue that has to be filled in by the application,OUT denotes values that the driver fills in. The application should zero out all members except for theIN fields.

Table A.26. struct v4l2_frmsize_discrete

__u32widthWidth of the frame [pixel].
__u32heightHeight of the frame [pixel].

Table A.27. struct v4l2_frmsize_stepwise

__u32min_widthMinimum frame width [pixel].
__u32max_widthMaximum frame width [pixel].
__u32step_widthFrame width step size [pixel].
__u32min_heightMinimum frame height [pixel].
__u32max_heightMaximum frame height [pixel].
__u32step_heightFrame height step size [pixel].

Table A.28. struct v4l2_frmsizeenum

__u32index
IN: Index of the given frame size in the enumeration.
__u32pixel_format
IN: Pixel format for which the frame sizes are enumerated.
__u32type
OUT: Frame size type the device supports.
union

OUT: Frame size with the given index.

struct v4l2_frmsize_discretediscrete

struct v4l2_frmsize_stepwisestepwise
__u32reserved[2]
Reserved space for future use.

Enums

Table A.29. enum v4l2_frmsizetypes

V4L2_FRMSIZE_TYPE_DISCRETE1Discrete frame size.
V4L2_FRMSIZE_TYPE_CONTINUOUS2Continuous frame size.
V4L2_FRMSIZE_TYPE_STEPWISE3Step-wise defined frame size.

Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.

例子:

int enum_frame_sizes(int dev, __u32 pixfmt)
{
    int ret;
    struct v4l2_frmsizeenum fsize;

    memset(&fsize, 0, sizeof(fsize));
    fsize.index = 0;
    fsize.pixel_format = pixfmt;
    while ((ret = ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &fsize)) == 0) {
        if (fsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
            printf("{ discrete: width = %u, height = %u }\n",
                    fsize.discrete.width, fsize.discrete.height);
            ret = enum_frame_intervals(dev, pixfmt,
                    fsize.discrete.width, fsize.discrete.height);  //查找设备支持的 帧的间隔时间

            if (ret != 0)
                printf("  Unable to enumerate frame sizes.\n");
        } else if (fsize.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
            printf("{ continuous: min { width = %u, height = %u } .. "
                    "max { width = %u, height = %u } }\n",
                    fsize.stepwise.min_width, fsize.stepwise.min_height,
                    fsize.stepwise.max_width, fsize.stepwise.max_height);
            printf("  Refusing to enumerate frame intervals.\n");
            break;
        } else if (fsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
            printf("{ stepwise: min { width = %u, height = %u } .. "
                    "max { width = %u, height = %u } / "
                    "stepsize { width = %u, height = %u } }\n",
                    fsize.stepwise.min_width, fsize.stepwise.min_height,
                    fsize.stepwise.max_width, fsize.stepwise.max_height,
                    fsize.stepwise.step_width, fsize.stepwise.step_height);
            printf("  Refusing to enumerate frame intervals.\n");
            break;
        }
        fsize.index++;
    }
    if (ret != 0 && errno != EINVAL) {
        printf("ERROR enumerating frame sizes: %d\n", errno);
        return errno;
    }

    return 0;
}


VIDIOC_ENUM_FRAMEINTERVALS

Name

VIDIOC_ENUM_FRAMEINTERVALS — Enumerate frame intervals

Synopsis

int ioctl(int fd,

int request,

struct v4l2_frmivalenum *argp);
 

Arguments

fd

File descriptor returned by open().

request

VIDIOC_ENUM_FRAMEINTERVALS

argp

Pointer to a struct v4l2_frmivalenum structure that contains a pixel format and size and receives a frame interval.

Description

This ioctl allows applications to enumerate all frame intervals that the device supports for the given pixel format and frame size.

The supported pixel formats and frame sizes can be obtained by using the VIDIOC_ENUM_FMT and VIDIOC_ENUM_FRAMESIZES functions.

The return value and the content of thev4l2_frmivalenum.type field depend on thetype of frame intervals the device supports. Here are the semantics ofthe function for the different cases:

  • Discrete: The function returns success if the given index value (zero-based) is valid. The application should increase the index by one for each call until EINVAL is returned. The `v4l2_frmivalenum.type`field is set to `V4L2_FRMIVAL_TYPE_DISCRETE` by the driver. Of theunion only the `discrete` member is valid.

  • Step-wise: The function returns success if the given index value is zero and EINVAL for any other index value. The v4l2_frmivalenum.type  field is set to V4L2_FRMIVAL_TYPE_STEPWISE by the driver. Of the union only the stepwise member isvalid.

  • Continuous: This is a special case of the step-wise type above. The function returns success if the given index value is zero and EINVAL for any other index value. The v4l2_frmivalenum.type  field is set to V4L2_FRMIVAL_TYPE_CONTINUOUS by the driver. Of the union only the stepwise member is valid and the step value is set to 1.

When the application calls the function with index zero, it must check the type field to determine the type of frame interval enumeration the device supports. Only for the V4L2_FRMIVAL_TYPE_DISCRETE type does it make sense to increase the index value to receive more frame intervals.

Note that the order in which the frame intervals are returned has no special meaning. In particular does it not say anything about potential default frame intervals.

Applications can assume that the enumeration data does not change without any inter action from the application itself. This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame interval enumeration.

Notes

  • Frame intervals and framerates: The V4L2 API uses frame intervals instead of framerates. Given the frame interval the frame rate can be computed asfollows:

    frame_rate = 1 / frame_interval
  • frame intervals 用分数表示

Structs

In the structs below, IN denotes avalue that has to be filled in by the application,OUT denotes values that the driver fills in. The application should zero out all members except for theIN fields.

Table A.30. struct v4l2_frmival_stepwise

struct v4l2_fractminMinimum frame interval [s].
struct v4l2_fractmaxMaximum frame interval [s].
struct v4l2_fractstepFrame interval step size [s].

Table A.31. struct v4l2_frmivalenum

__u32index
IN: Index of the given frame interval in theenumeration.
__u32pixel_format
IN: Pixel format for which the frame intervals areenumerated.
__u32width
IN: Frame width for which the frame intervals areenumerated.
__u32height
IN: Frame height for which the frame intervals areenumerated.
__u32type
OUT: Frame interval type the device supports.
union

OUT: Frame interval with the given index.

struct v4l2_fractdiscreteFrame interval [s].

struct v4l2_frmival_stepwisestepwise
__u32reserved[2]
Reserved space for future use.

Enums

Table A.32. enum v4l2_frmivaltypes

V4L2_FRMIVAL_TYPE_DISCRETE1Discrete frame interval.
V4L2_FRMIVAL_TYPE_CONTINUOUS2Continuous frame interval.
V4L2_FRMIVAL_TYPE_STEPWISE3Step-wise defined frame interval.

Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.


例子:

int enum_frame_intervals(int dev, __u32 pixfmt, __u32 width, __u32 height)
{
    int ret;
    struct v4l2_frmivalenum fival;

    memset(&fival, 0, sizeof(fival));
    fival.index = 0;
    fival.pixel_format = pixfmt;
    fival.width = width;
    fival.height = height;
    printf("\tTime interval between frame: ");
    while ((ret = ioctl(dev, VIDIOC_ENUM_FRAMEINTERVALS, &fival)) == 0) {
        if (fival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
                printf("%u/%u, ",
                        fival.discrete.numerator, fival.discrete.denominator); //输出分数
        } else if (fival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
                printf("{min { %u/%u } .. max { %u/%u } }, ",
                        fival.stepwise.min.numerator, fival.stepwise.min.numerator,
                        fival.stepwise.max.denominator, fival.stepwise.max.denominator);
                break;
        } else if (fival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
                printf("{min { %u/%u } .. max { %u/%u } / "
                        "stepsize { %u/%u } }, ",
                        fival.stepwise.min.numerator, fival.stepwise.min.denominator,
                        fival.stepwise.max.numerator, fival.stepwise.max.denominator,
                        fival.stepwise.step.numerator, fival.stepwise.step.denominator);
                break;
        }
        fival.index++;
    }
    printf("\n");
    if (ret != 0 && errno != EINVAL) {
        printf("ERROR enumerating frame intervals: %d\n", errno);
        return errno;
    }

    return 0;
}


上面的全部例子程序运行结果如下:

{ pixelformat = 'YUYV', description = 'YUV 4:2:2 (YUYV)' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30,
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30,
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30,
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30,
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30,




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值