v4l2-ctl: automatically detect single/multiplanar buffer type.
authorHans Verkuil <hans.verkuil@cisco.com>
Wed, 12 Feb 2014 17:38:48 +0000 (18:38 +0100)
committerHans Verkuil <hans.verkuil@cisco.com>
Wed, 12 Feb 2014 17:38:48 +0000 (18:38 +0100)
Instead of having both single and multiplanar variants of options it is
easier for everyone to just test for the multiplanar capabilities and, if
set, use multiplanar buffer types.

This was already done for the streaming options and now it is done elsewhere
as well.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-ctl/v4l2-ctl-streaming.cpp
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp
utils/v4l2-ctl/v4l2-ctl-vidout.cpp
utils/v4l2-ctl/v4l2-ctl.cpp
utils/v4l2-ctl/v4l2-ctl.h

index 4cb05a0..0dbe855 100644 (file)
@@ -234,17 +234,7 @@ class buffers {
 public:
        buffers(bool is_output, bool is_mmap)
        {
-               if (is_output) {
-                       is_mplane = capabilities &
-                               (V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_VIDEO_M2M_MPLANE);
-                       type = is_mplane ?
-                               V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT;
-               } else {
-                       is_mplane = capabilities &
-                               (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_M2M_MPLANE);
-                       type = is_mplane ?
-                               V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               }
+               type = is_output ? vidout_buftype : vidcap_buftype;
                memory = is_mmap ? V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
        }
 
@@ -959,21 +949,11 @@ void streaming_set(int fd)
 void streaming_list(int fd)
 {
        if (options[OptListBuffers]) {
-               bool is_mplane = capabilities &
-                       (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
-                        V4L2_CAP_VIDEO_M2M_MPLANE);
-               
-               list_buffers(fd, is_mplane ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :
-                                            V4L2_BUF_TYPE_VIDEO_CAPTURE);
+               list_buffers(fd, vidcap_buftype);
        }
 
        if (options[OptListBuffersOut]) {
-               bool is_mplane = capabilities &
-                       (V4L2_CAP_VIDEO_OUTPUT_MPLANE |
-                        V4L2_CAP_VIDEO_M2M_MPLANE);
-               
-               list_buffers(fd, is_mplane ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
-                                            V4L2_BUF_TYPE_VIDEO_OUTPUT);
+               list_buffers(fd, vidout_buftype);
        }
 
        if (options[OptListBuffersVbi]) {
index 8ba25dc..62fcaf8 100644 (file)
@@ -30,14 +30,8 @@ void vidcap_usage(void)
 {
        printf("\nVideo Capture Formats options:\n"
               "  --list-formats     display supported video formats [VIDIOC_ENUM_FMT]\n"
-              "  --list-formats-mplane\n"
-              "                     display supported video multi-planar formats\n"
-              "                     [VIDIOC_ENUM_FMT]\n"
               "  --list-formats-ext display supported video formats including frame sizes\n"
               "                     and intervals\n"
-              "  --list-formats-ext-mplane\n"
-              "                     display supported video multi-planar formats including\n"
-              "                     frame sizes and intervals\n"
               "  --list-framesizes=<f>\n"
               "                     list supported framesizes for pixelformat <f>\n"
               "                     [VIDIOC_ENUM_FRAMESIZES]\n"
@@ -63,18 +57,6 @@ void vidcap_usage(void)
               "                     <f> can be one of:\n"
               "                     any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
               "                     alternate, interlaced_tb, interlaced_bt\n"
-              "  --get-fmt-video-mplane\n"
-              "                     query the video capture format through the multi-planar API\n"
-              "                     [VIDIOC_G_FMT]\n"
-              "  --set-fmt-video-mplane\n"
-              "  --try-fmt-video-mplane=width=<w>,height=<h>,pixelformat=<pf>,field=<f>\n"
-              "                     set/try the video capture format using the multi-planar API\n"
-              "                     [VIDIOC_S/TRY_FMT]\n"
-              "                     pixelformat is either the format index as reported by\n"
-              "                     --list-formats-mplane, or the fourcc value as a string.\n"
-              "                     <f> can be one of:\n"
-              "                     any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
-              "                     alternate, interlaced_tb, interlaced_bt\n"
               );
 }
 
@@ -141,7 +123,7 @@ static void print_frmival(const struct v4l2_frmivalenum &frmival, const char *pr
        }
 }
 
-static void print_video_formats_ext(int fd, enum v4l2_buf_type type)
+static void print_video_formats_ext(int fd, __u32 type)
 {
        struct v4l2_fmtdesc fmt;
        struct v4l2_frmsizeenum frmsize;
@@ -182,12 +164,8 @@ static void print_video_fields(int fd)
 {
        struct v4l2_format fmt;
        struct v4l2_format tmp;
-       bool is_mplane = capabilities &
-               (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
-                V4L2_CAP_VIDEO_M2M_MPLANE);
 
-       fmt.type = is_mplane ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :
-                              V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       fmt.type = vidcap_buftype;
        if (test_ioctl(fd, VIDIOC_G_FMT, &fmt) < 0)
                return;
 
@@ -196,13 +174,13 @@ static void print_video_fields(int fd)
                bool ok;
 
                tmp = fmt;
-               if (is_mplane)
+               if (is_multiplanar)
                        tmp.fmt.pix_mp.field = f;
                else
                        tmp.fmt.pix.field = f;
                if (test_ioctl(fd, VIDIOC_TRY_FMT, &tmp) < 0)
                        continue;
-               if (is_mplane)
+               if (is_multiplanar)
                        ok = tmp.fmt.pix_mp.field == f;
                else
                        ok = tmp.fmt.pix.field == f;
@@ -217,19 +195,6 @@ void vidcap_cmd(int ch, char *optarg)
        char *value, *subs;
 
        switch (ch) {
-       case OptSetVideoMplaneFormat:
-       case OptTryVideoMplaneFormat:
-               set_fmts = parse_fmt(optarg, width, height, field, pixfmt);
-               if (!set_fmts) {
-                       vidcap_usage();
-                       exit(1);
-               }
-               vfmt.fmt.pix_mp.width = width;
-               vfmt.fmt.pix_mp.height = height;
-               vfmt.fmt.pix_mp.field = field;
-               vfmt.fmt.pix_mp.pixelformat = pixfmt;
-               break;
-
        case OptSetVideoFormat:
        case OptTryVideoFormat:
                set_fmts = parse_fmt(optarg, width, height, field, pixfmt);
@@ -237,10 +202,17 @@ void vidcap_cmd(int ch, char *optarg)
                        vidcap_usage();
                        exit(1);
                }
-               vfmt.fmt.pix.width = width;
-               vfmt.fmt.pix.height = height;
-               vfmt.fmt.pix.field = field;
-               vfmt.fmt.pix.pixelformat = pixfmt;
+               if (is_multiplanar) {
+                       vfmt.fmt.pix_mp.width = width;
+                       vfmt.fmt.pix_mp.height = height;
+                       vfmt.fmt.pix_mp.field = field;
+                       vfmt.fmt.pix_mp.pixelformat = pixfmt;
+               } else {
+                       vfmt.fmt.pix.width = width;
+                       vfmt.fmt.pix.height = height;
+                       vfmt.fmt.pix.field = field;
+                       vfmt.fmt.pix.pixelformat = pixfmt;
+               }
                break;
        case OptListFrameSizes:
                if (strlen(optarg) == 4)
@@ -288,63 +260,53 @@ void vidcap_set(int fd)
        int ret;
 
        if (options[OptSetVideoFormat] || options[OptTryVideoFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) {
-                       if (set_fmts & FmtWidth)
-                               in_vfmt.fmt.pix.width = vfmt.fmt.pix.width;
-                       if (set_fmts & FmtHeight)
-                               in_vfmt.fmt.pix.height = vfmt.fmt.pix.height;
-                       if (set_fmts & FmtPixelFormat) {
-                               in_vfmt.fmt.pix.pixelformat = vfmt.fmt.pix.pixelformat;
-                               if (in_vfmt.fmt.pix.pixelformat < 256) {
-                                       in_vfmt.fmt.pix.pixelformat =
-                                               find_pixel_format(fd, in_vfmt.fmt.pix.pixelformat,
-                                                                 false, false);
+               struct v4l2_format vfmt;
+
+               vfmt.type = vidcap_buftype;
+               if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0) {
+                       if (is_multiplanar) {
+                               if (set_fmts & FmtWidth)
+                                       vfmt.fmt.pix_mp.width = vfmt.fmt.pix_mp.width;
+                               if (set_fmts & FmtHeight)
+                                       vfmt.fmt.pix_mp.height = vfmt.fmt.pix_mp.height;
+                               if (set_fmts & FmtPixelFormat) {
+                                       vfmt.fmt.pix_mp.pixelformat = vfmt.fmt.pix_mp.pixelformat;
+                                       if (vfmt.fmt.pix_mp.pixelformat < 256) {
+                                               vfmt.fmt.pix_mp.pixelformat =
+                                                       find_pixel_format(fd, vfmt.fmt.pix_mp.pixelformat,
+                                                                       false, true);
+                                       }
+                               }
+                               /* G_FMT might return bytesperline values > width,
+                                * reset them to 0 to force the driver to update them
+                                * to the closest value for the new width. */
+                               for (unsigned i = 0; i < vfmt.fmt.pix_mp.num_planes; i++)
+                                       vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = 0;
+                       } else {
+                               if (set_fmts & FmtWidth)
+                                       vfmt.fmt.pix.width = vfmt.fmt.pix.width;
+                               if (set_fmts & FmtHeight)
+                                       vfmt.fmt.pix.height = vfmt.fmt.pix.height;
+                               if (set_fmts & FmtPixelFormat) {
+                                       vfmt.fmt.pix.pixelformat = vfmt.fmt.pix.pixelformat;
+                                       if (vfmt.fmt.pix.pixelformat < 256) {
+                                               vfmt.fmt.pix.pixelformat =
+                                                       find_pixel_format(fd, vfmt.fmt.pix.pixelformat,
+                                                                       false, false);
+                                       }
                                }
+                               /* G_FMT might return a bytesperline value > width,
+                                * reset this to 0 to force the driver to update it
+                                * to the closest value for the new width. */
+                               vfmt.fmt.pix.bytesperline = 0;
                        }
-                       /* G_FMT might return a bytesperline value > width,
-                        * reset this to 0 to force the driver to update it
-                        * to the closest value for the new width. */
-                       in_vfmt.fmt.pix.bytesperline = 0;
+
                        if (options[OptSetVideoFormat])
-                               ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
+                               ret = doioctl(fd, VIDIOC_S_FMT, &vfmt);
                        else
-                               ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
+                               ret = doioctl(fd, VIDIOC_TRY_FMT, &vfmt);
                        if (ret == 0 && (verbose || options[OptTryVideoFormat]))
-                               printfmt(in_vfmt);
-               }
-       }
-
-       if (options[OptSetVideoMplaneFormat] || options[OptTryVideoMplaneFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
-               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) {
-                       if (set_fmts & FmtWidth)
-                               in_vfmt.fmt.pix_mp.width = vfmt.fmt.pix_mp.width;
-                       if (set_fmts & FmtHeight)
-                               in_vfmt.fmt.pix_mp.height = vfmt.fmt.pix_mp.height;
-                       if (set_fmts & FmtPixelFormat) {
-                               in_vfmt.fmt.pix_mp.pixelformat = vfmt.fmt.pix_mp.pixelformat;
-                               if (in_vfmt.fmt.pix_mp.pixelformat < 256) {
-                                       in_vfmt.fmt.pix_mp.pixelformat =
-                                               find_pixel_format(fd, in_vfmt.fmt.pix_mp.pixelformat,
-                                                                 false, true);
-                               }
-                       }
-                       /* G_FMT might return bytesperline values > width,
-                        * reset them to 0 to force the driver to update them
-                        * to the closest value for the new width. */
-                       for (unsigned i = 0; i < in_vfmt.fmt.pix_mp.num_planes; i++)
-                               in_vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = 0;
-                       if (options[OptSetVideoMplaneFormat])
-                               ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
-                       else
-                               ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
-                       if (ret == 0 && (verbose || options[OptTryVideoMplaneFormat]))
-                               printfmt(in_vfmt);
+                               printfmt(vfmt);
                }
        }
 }
@@ -352,13 +314,7 @@ void vidcap_set(int fd)
 void vidcap_get(int fd)
 {
        if (options[OptGetVideoFormat]) {
-               vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0)
-                       printfmt(vfmt);
-       }
-
-       if (options[OptGetVideoMplaneFormat]) {
-               vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+               vfmt.type = vidcap_buftype;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0)
                        printfmt(vfmt);
        }
@@ -368,22 +324,12 @@ void vidcap_list(int fd)
 {
        if (options[OptListFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE);
-       }
-
-       if (options[OptListMplaneFormats]) {
-               printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+               print_video_formats(fd, vidcap_buftype);
        }
 
        if (options[OptListFormatsExt]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats_ext(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE);
-       }
-
-       if (options[OptListMplaneFormatsExt]) {
-               printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats_ext(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+               print_video_formats_ext(fd, vidcap_buftype);
        }
 
        if (options[OptListFields]) {
index 3e4fcb5..5ab05d1 100644 (file)
@@ -39,21 +39,6 @@ void vidout_usage(void)
               "                     <f> can be one of:\n"
               "                     any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
               "                     alternate, interlaced_tb, interlaced_bt\n"
-              "  --list-formats-out-mplane\n"
-              "                     display supported video output multi-planar formats\n"
-              "                     [VIDIOC_ENUM_FMT]\n"
-              "  --get-fmt-video-out-mplane\n"
-              "                     query the video output format using the multi-planar API\n"
-              "                     [VIDIOC_G_FMT]\n"
-              "  --set-fmt-video-out-mplane\n"
-              "  --try-fmt-video-out-mplane=width=<w>,height=<h>,pixelformat=<pf>,field=<f>\n"
-              "                     set/try the video output format with the multi-planar API\n"
-              "                     [VIDIOC_S/TRY_FMT]\n"
-              "                     pixelformat is either the format index as reported by\n"
-              "                     --list-formats-out-mplane, or the fourcc value as a string.\n"
-              "                     <f> can be one of:\n"
-              "                     any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
-              "                     alternate, interlaced_tb, interlaced_bt\n"
               );
 }
 
@@ -61,12 +46,8 @@ static void print_video_out_fields(int fd)
 {
        struct v4l2_format fmt;
        struct v4l2_format tmp;
-       bool is_mplane = capabilities &
-               (V4L2_CAP_VIDEO_OUTPUT_MPLANE |
-                V4L2_CAP_VIDEO_M2M_MPLANE);
 
-       fmt.type = is_mplane ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
-                              V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       fmt.type = vidout_buftype;
        if (test_ioctl(fd, VIDIOC_G_FMT, &fmt) < 0)
                return;
 
@@ -75,13 +56,13 @@ static void print_video_out_fields(int fd)
                bool ok;
 
                tmp = fmt;
-               if (is_mplane)
+               if (is_multiplanar)
                        tmp.fmt.pix_mp.field = f;
                else
                        tmp.fmt.pix.field = f;
                if (test_ioctl(fd, VIDIOC_TRY_FMT, &tmp) < 0)
                        continue;
-               if (is_mplane)
+               if (is_multiplanar)
                        ok = tmp.fmt.pix_mp.field == f;
                else
                        ok = tmp.fmt.pix.field == f;
@@ -95,19 +76,6 @@ void vidout_cmd(int ch, char *optarg)
        __u32 width, height, field, pixfmt;
 
        switch (ch) {
-       case OptSetVideoOutMplaneFormat:
-       case OptTryVideoOutMplaneFormat:
-               set_fmts_out = parse_fmt(optarg, width, height, field, pixfmt);
-               if (!set_fmts_out) {
-                       vidcap_usage();
-                       exit(1);
-               }
-               vfmt_out.fmt.pix_mp.width = width;
-               vfmt_out.fmt.pix_mp.height = height;
-               vfmt_out.fmt.pix_mp.field = field;
-               vfmt_out.fmt.pix_mp.pixelformat = pixfmt;
-               break;
-
        case OptSetVideoOutFormat:
        case OptTryVideoOutFormat:
                set_fmts_out = parse_fmt(optarg, width, height, field, pixfmt);
@@ -115,10 +83,17 @@ void vidout_cmd(int ch, char *optarg)
                        vidcap_usage();
                        exit(1);
                }
-               vfmt_out.fmt.pix.width = width;
-               vfmt_out.fmt.pix.height = height;
-               vfmt_out.fmt.pix.field = field;
-               vfmt_out.fmt.pix.pixelformat = pixfmt;
+               if (is_multiplanar) {
+                       vfmt_out.fmt.pix_mp.width = width;
+                       vfmt_out.fmt.pix_mp.height = height;
+                       vfmt_out.fmt.pix_mp.field = field;
+                       vfmt_out.fmt.pix_mp.pixelformat = pixfmt;
+               } else {
+                       vfmt_out.fmt.pix.width = width;
+                       vfmt_out.fmt.pix.height = height;
+                       vfmt_out.fmt.pix.field = field;
+                       vfmt_out.fmt.pix.pixelformat = pixfmt;
+               }
                break;
        }
 }
@@ -128,65 +103,53 @@ void vidout_set(int fd)
        int ret;
 
        if (options[OptSetVideoOutFormat] || options[OptTryVideoOutFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) {
-                       if (set_fmts_out & FmtWidth)
-                               in_vfmt.fmt.pix.width = vfmt_out.fmt.pix.width;
-                       if (set_fmts_out & FmtHeight)
-                               in_vfmt.fmt.pix.height = vfmt_out.fmt.pix.height;
-                       if (set_fmts_out & FmtPixelFormat) {
-                               in_vfmt.fmt.pix.pixelformat = vfmt_out.fmt.pix.pixelformat;
-                               if (in_vfmt.fmt.pix.pixelformat < 256) {
-                                       in_vfmt.fmt.pix.pixelformat =
-                                               find_pixel_format(fd, in_vfmt.fmt.pix.pixelformat,
-                                                                 true, false);
+               struct v4l2_format vfmt;
+
+               vfmt.type = vidout_buftype;
+               if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0) {
+                       if (is_multiplanar) {
+                               if (set_fmts_out & FmtWidth)
+                                       vfmt.fmt.pix_mp.width = vfmt_out.fmt.pix_mp.width;
+                               if (set_fmts_out & FmtHeight)
+                                       vfmt.fmt.pix_mp.height = vfmt_out.fmt.pix_mp.height;
+                               if (set_fmts_out & FmtPixelFormat) {
+                                       vfmt.fmt.pix_mp.pixelformat = vfmt_out.fmt.pix_mp.pixelformat;
+                                       if (vfmt.fmt.pix_mp.pixelformat < 256) {
+                                               vfmt.fmt.pix_mp.pixelformat =
+                                                       find_pixel_format(fd, vfmt.fmt.pix_mp.pixelformat,
+                                                                       true, true);
+                                       }
+                               }
+                               /* G_FMT might return bytesperline values > width,
+                                * reset them to 0 to force the driver to update them
+                                * to the closest value for the new width. */
+                               for (unsigned i = 0; i < vfmt.fmt.pix_mp.num_planes; i++)
+                                       vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = 0;
+                       } else {
+                               if (set_fmts_out & FmtWidth)
+                                       vfmt.fmt.pix.width = vfmt_out.fmt.pix.width;
+                               if (set_fmts_out & FmtHeight)
+                                       vfmt.fmt.pix.height = vfmt_out.fmt.pix.height;
+                               if (set_fmts_out & FmtPixelFormat) {
+                                       vfmt.fmt.pix.pixelformat = vfmt_out.fmt.pix.pixelformat;
+                                       if (vfmt.fmt.pix.pixelformat < 256) {
+                                               vfmt.fmt.pix.pixelformat =
+                                                       find_pixel_format(fd, vfmt.fmt.pix.pixelformat,
+                                                                       true, false);
+                                       }
                                }
+                               /* G_FMT might return a bytesperline value > width,
+                                * reset this to 0 to force the driver to update it
+                                * to the closest value for the new width. */
+                               vfmt.fmt.pix.bytesperline = 0;
                        }
-                       /* G_FMT might return a bytesperline value > width,
-                        * reset this to 0 to force the driver to update it
-                        * to the closest value for the new width. */
-                       in_vfmt.fmt.pix.bytesperline = 0;
 
                        if (options[OptSetVideoOutFormat])
-                               ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
+                               ret = doioctl(fd, VIDIOC_S_FMT, &vfmt);
                        else
-                               ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
+                               ret = doioctl(fd, VIDIOC_TRY_FMT, &vfmt);
                        if (ret == 0 && (verbose || options[OptTryVideoOutFormat]))
-                               printfmt(in_vfmt);
-               }
-       }
-
-       if (options[OptSetVideoOutMplaneFormat] || options[OptTryVideoOutMplaneFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
-               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt) == 0) {
-                       if (set_fmts_out & FmtWidth)
-                               in_vfmt.fmt.pix_mp.width = vfmt_out.fmt.pix_mp.width;
-                       if (set_fmts_out & FmtHeight)
-                               in_vfmt.fmt.pix_mp.height = vfmt_out.fmt.pix_mp.height;
-                       if (set_fmts_out & FmtPixelFormat) {
-                               in_vfmt.fmt.pix_mp.pixelformat = vfmt_out.fmt.pix_mp.pixelformat;
-                               if (in_vfmt.fmt.pix_mp.pixelformat < 256) {
-                                       in_vfmt.fmt.pix_mp.pixelformat =
-                                               find_pixel_format(fd, in_vfmt.fmt.pix_mp.pixelformat,
-                                                                 true, true);
-                               }
-                       }
-                       /* G_FMT might return bytesperline values > width,
-                        * reset them to 0 to force the driver to update them
-                        * to the closest value for the new width. */
-                       for (unsigned i = 0; i < in_vfmt.fmt.pix_mp.num_planes; i++)
-                               in_vfmt.fmt.pix_mp.plane_fmt[i].bytesperline = 0;
-
-                       if (options[OptSetVideoOutMplaneFormat])
-                               ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
-                       else
-                               ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
-                       if (ret == 0 && (verbose || options[OptTryVideoOutMplaneFormat]))
-                               printfmt(in_vfmt);
+                               printfmt(vfmt);
                }
        }
 }
@@ -194,13 +157,7 @@ void vidout_set(int fd)
 void vidout_get(int fd)
 {
        if (options[OptGetVideoOutFormat]) {
-               vfmt_out.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-               if (doioctl(fd, VIDIOC_G_FMT, &vfmt_out) == 0)
-                       printfmt(vfmt_out);
-       }
-
-       if (options[OptGetVideoOutMplaneFormat]) {
-               vfmt_out.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+               vfmt_out.type = vidout_buftype;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt_out) == 0)
                        printfmt(vfmt_out);
        }
@@ -210,12 +167,7 @@ void vidout_list(int fd)
 {
        if (options[OptListOutFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT);
-       }
-
-       if (options[OptListOutMplaneFormats]) {
-               printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
+               print_video_formats(fd, vidout_buftype);
        }
 
        if (options[OptListOutFields]) {
index 5cfafa7..f8a925d 100644 (file)
@@ -59,6 +59,9 @@ static int app_result;
 int verbose;
 
 unsigned capabilities;
+bool is_multiplanar;
+__u32 vidcap_buftype;
+__u32 vidout_buftype;
 
 static struct option long_options[] = {
        {"list-audio-inputs", no_argument, 0, OptListAudioInputs},
@@ -68,15 +71,9 @@ static struct option long_options[] = {
        {"get-fmt-video", no_argument, 0, OptGetVideoFormat},
        {"set-fmt-video", required_argument, 0, OptSetVideoFormat},
        {"try-fmt-video", required_argument, 0, OptTryVideoFormat},
-       {"get-fmt-video-mplane", no_argument, 0, OptGetVideoMplaneFormat},
-       {"set-fmt-video-mplane", required_argument, 0, OptSetVideoMplaneFormat},
-       {"try-fmt-video-mplane", required_argument, 0, OptTryVideoMplaneFormat},
        {"get-fmt-video-out", no_argument, 0, OptGetVideoOutFormat},
        {"set-fmt-video-out", required_argument, 0, OptSetVideoOutFormat},
        {"try-fmt-video-out", required_argument, 0, OptTryVideoOutFormat},
-       {"get-fmt-video-out-mplane", no_argument, 0, OptGetVideoOutMplaneFormat},
-       {"set-fmt-video-out-mplane", required_argument, 0, OptSetVideoOutMplaneFormat},
-       {"try-fmt-video-out-mplane", required_argument, 0, OptTryVideoOutMplaneFormat},
        {"help", no_argument, 0, OptHelp},
        {"help-tuner", no_argument, 0, OptHelpTuner},
        {"help-io", no_argument, 0, OptHelpIO},
@@ -105,15 +102,12 @@ static struct option long_options[] = {
        {"set-freq", required_argument, 0, OptSetFreq},
        {"list-standards", no_argument, 0, OptListStandards},
        {"list-formats", no_argument, 0, OptListFormats},
-       {"list-formats-mplane", no_argument, 0, OptListMplaneFormats},
        {"list-formats-ext", no_argument, 0, OptListFormatsExt},
-       {"list-formats-ext-mplane", no_argument, 0, OptListMplaneFormatsExt},
        {"list-fields", no_argument, 0, OptListFields},
        {"list-framesizes", required_argument, 0, OptListFrameSizes},
        {"list-frameintervals", required_argument, 0, OptListFrameIntervals},
        {"list-formats-overlay", no_argument, 0, OptListOverlayFormats},
        {"list-formats-out", no_argument, 0, OptListOutFormats},
-       {"list-formats-out-mplane", no_argument, 0, OptListOutMplaneFormats},
        {"list-fields-out", no_argument, 0, OptListOutFields},
        {"get-standard", no_argument, 0, OptGetStandard},
        {"set-standard", required_argument, 0, OptSetStandard},
@@ -474,7 +468,7 @@ std::string fmtdesc2s(unsigned flags)
        return flags2s(flags, fmtdesc_def);
 }
 
-void print_video_formats(int fd, enum v4l2_buf_type type)
+void print_video_formats(int fd, __u32 type)
 {
        struct v4l2_fmtdesc fmt;
 
@@ -910,6 +904,15 @@ int main(int argc, char **argv)
        if (capabilities & V4L2_CAP_DEVICE_CAPS)
                capabilities = vcap.device_caps;
 
+       is_multiplanar = capabilities & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
+                                        V4L2_CAP_VIDEO_M2M_MPLANE |
+                                        V4L2_CAP_VIDEO_OUTPUT_MPLANE);
+
+       vidcap_buftype = is_multiplanar ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :
+                                         V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       vidout_buftype = is_multiplanar ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
+                                         V4L2_BUF_TYPE_VIDEO_OUTPUT;
+
        common_process_controls(fd);
 
        if (wait_for_event == V4L2_EVENT_CTRL && wait_event_id)
@@ -925,10 +928,8 @@ int main(int argc, char **argv)
 
        if (options[OptAll]) {
                options[OptGetVideoFormat] = 1;
-               options[OptGetVideoMplaneFormat] = 1;
                options[OptGetCrop] = 1;
                options[OptGetVideoOutFormat] = 1;
-               options[OptGetVideoOutMplaneFormat] = 1;
                options[OptGetDriverInfo] = 1;
                options[OptGetInput] = 1;
                options[OptGetOutput] = 1;
index 5161808..6abcd38 100644 (file)
@@ -37,28 +37,22 @@ enum Option {
        OptSetVideoFormat = 'v',
        OptUseWrapper = 'w',
 
-       OptGetVideoMplaneFormat = 128,
-       OptSetVideoMplaneFormat,
-       OptGetSlicedVbiOutFormat,
+       OptGetSlicedVbiOutFormat = 128,
        OptGetOverlayFormat,
        OptGetOutputOverlayFormat,
        OptGetVbiFormat,
        OptGetVbiOutFormat,
        OptGetVideoOutFormat,
-       OptGetVideoOutMplaneFormat,
        OptSetSlicedVbiOutFormat,
        OptSetOutputOverlayFormat,
        OptSetOverlayFormat,
        //OptSetVbiFormat, TODO
        //OptSetVbiOutFormat, TODO
        OptSetVideoOutFormat,
-       OptSetVideoOutMplaneFormat,
        OptTryVideoOutFormat,
-       OptTryVideoOutMplaneFormat,
        OptTrySlicedVbiOutFormat,
        OptTrySlicedVbiFormat,
        OptTryVideoFormat,
-       OptTryVideoMplaneFormat,
        OptTryOutputOverlayFormat,
        OptTryOverlayFormat,
        //OptTryVbiFormat, TODO
@@ -66,15 +60,12 @@ enum Option {
        OptAll,
        OptListStandards,
        OptListFormats,
-       OptListMplaneFormats,
        OptListFormatsExt,
-       OptListMplaneFormatsExt,
        OptListFields,
        OptListFrameSizes,
        OptListFrameIntervals,
        OptListOverlayFormats,
        OptListOutFormats,
-       OptListOutMplaneFormats,
        OptListOutFields,
        OptLogStatus,
        OptVerbose,
@@ -164,6 +155,9 @@ enum Option {
 
 extern char options[OptLast];
 extern unsigned capabilities;
+extern bool is_multiplanar;
+extern __u32 vidcap_buftype;
+extern __u32 vidout_buftype;
 extern int verbose;
 
 typedef struct {
@@ -198,7 +192,7 @@ __u32 parse_field(const char *s);
 int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &field, __u32 &pixelformat);
 __u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane);
 void printfmt(const struct v4l2_format &vfmt);
-void print_video_formats(int fd, enum v4l2_buf_type type);
+void print_video_formats(int fd, __u32 type);
 
 #define doioctl(n, r, p) doioctl_name(n, r, p, #r)