v4l2-ctl: add support for new extended format flags field.
authorHans Verkuil <hans.verkuil@cisco.com>
Thu, 17 Jul 2014 21:36:15 +0000 (23:36 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Thu, 17 Jul 2014 21:36:15 +0000 (23:36 +0200)
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 2112573..24559e9 100644 (file)
@@ -595,6 +595,7 @@ static int do_setup_out_buffers(int fd, buffers &b, FILE *fin, bool qbuf)
        bool can_fill;
 
        memset(&fmt, 0, sizeof(fmt));
+       fmt.fmt.pix.priv = out_priv_magic;
        fmt.type = b.type;
        doioctl(fd, VIDIOC_G_FMT, &fmt);
        if (test_ioctl(fd, VIDIOC_G_STD, &stream_out_std)) {
@@ -1564,6 +1565,7 @@ void streaming_set(int fd, int out_fd)
        if (out_fd < 0) {
                out_fd = fd;
                out_capabilities = capabilities;
+               out_priv_magic = priv_magic;
        }
 
        if (do_cap > 1) {
index a8cf837..63f93e0 100644 (file)
@@ -162,6 +162,8 @@ static void print_video_fields(int fd)
        struct v4l2_format fmt;
        struct v4l2_format tmp;
 
+       memset(&fmt, 0, sizeof(fmt));
+       fmt.fmt.pix.priv = priv_magic;
        fmt.type = vidcap_buftype;
        if (test_ioctl(fd, VIDIOC_G_FMT, &fmt) < 0)
                return;
@@ -248,6 +250,8 @@ void vidcap_set(int fd)
        if (options[OptSetVideoFormat] || options[OptTryVideoFormat]) {
                struct v4l2_format vfmt;
 
+               memset(&vfmt, 0, sizeof(vfmt));
+               vfmt.fmt.pix.priv = priv_magic;
                vfmt.type = vidcap_buftype;
 
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0) {
@@ -317,6 +321,8 @@ void vidcap_get(int fd)
        if (options[OptGetVideoFormat]) {
                struct v4l2_format vfmt;
 
+               memset(&vfmt, 0, sizeof(vfmt));
+               vfmt.fmt.pix.priv = priv_magic;
                vfmt.type = vidcap_buftype;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0)
                        printfmt(vfmt);
index 8882b0e..ca884ae 100644 (file)
@@ -46,6 +46,8 @@ static void print_video_out_fields(int fd)
        struct v4l2_format fmt;
        struct v4l2_format tmp;
 
+       memset(&fmt, 0, sizeof(fmt));
+       fmt.fmt.pix.priv = priv_magic;
        fmt.type = vidout_buftype;
        if (test_ioctl(fd, VIDIOC_G_FMT, &fmt) < 0)
                return;
@@ -91,6 +93,8 @@ void vidout_set(int fd)
        if (options[OptSetVideoOutFormat] || options[OptTryVideoOutFormat]) {
                struct v4l2_format vfmt;
 
+               memset(&vfmt, 0, sizeof(vfmt));
+               vfmt.fmt.pix.priv = priv_magic;
                vfmt.type = vidout_buftype;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0) {
                        if (is_multiplanar) {
@@ -163,6 +167,8 @@ void vidout_get(int fd)
        if (options[OptGetVideoOutFormat]) {
                struct v4l2_format vfmt;
 
+               memset(&vfmt, 0, sizeof(vfmt));
+               vfmt.fmt.pix.priv = priv_magic;
                vfmt.type = vidout_buftype;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt) == 0)
                        printfmt(vfmt);
index e5add30..79930b1 100644 (file)
@@ -54,6 +54,8 @@ int verbose;
 
 unsigned capabilities;
 unsigned out_capabilities;
+unsigned priv_magic;
+unsigned out_priv_magic;
 bool is_multiplanar;
 __u32 vidcap_buftype;
 __u32 vidout_buftype;
@@ -403,6 +405,16 @@ std::string flags2s(unsigned val, const flag_def *def)
 }
 
 
+static const flag_def pixflags_def[] = {
+       { V4L2_PIX_FMT_FLAG_PREMUL_ALPHA,  "premultiplied-alpha" },
+       { 0, NULL }
+};
+
+std::string pixflags2s(unsigned flags)
+{
+       return flags2s(flags, pixflags_def);
+}
+
 static const flag_def service_def[] = {
        { V4L2_SLICED_TELETEXT_B,  "teletext" },
        { V4L2_SLICED_VPS,         "vps" },
@@ -434,8 +446,8 @@ void printfmt(const struct v4l2_format &vfmt)
                printf("\tBytes per Line: %u\n", vfmt.fmt.pix.bytesperline);
                printf("\tSize Image    : %u\n", vfmt.fmt.pix.sizeimage);
                printf("\tColorspace    : %s\n", colorspace2s(vfmt.fmt.pix.colorspace).c_str());
-               if (vfmt.fmt.pix.priv)
-                       printf("\tCustom Info   : %08x\n", vfmt.fmt.pix.priv);
+               if (vfmt.fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
+                       printf("\tFlags         : %s\n", pixflags2s(vfmt.fmt.pix.flags).c_str());
                break;
        case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
        case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
@@ -443,6 +455,7 @@ void printfmt(const struct v4l2_format &vfmt)
                printf("\tPixel Format      : '%s'\n", fcc2s(vfmt.fmt.pix_mp.pixelformat).c_str());
                printf("\tField             : %s\n", field2s(vfmt.fmt.pix_mp.field).c_str());
                printf("\tNumber of planes  : %u\n", vfmt.fmt.pix_mp.num_planes);
+               printf("\tFlags             : %s\n", pixflags2s(vfmt.fmt.pix_mp.flags).c_str());
                printf("\tColorspace        : %s\n", colorspace2s(vfmt.fmt.pix_mp.colorspace).c_str());
                for (int i = 0; i < vfmt.fmt.pix_mp.num_planes && i < VIDEO_MAX_PLANES; i++) {
                        printf("\tPlane %d           :\n", i);
@@ -1041,6 +1054,8 @@ int main(int argc, char **argv)
        if (capabilities & V4L2_CAP_DEVICE_CAPS)
                capabilities = vcap.device_caps;
 
+       priv_magic = (capabilities & V4L2_CAP_EXT_PIX_FORMAT) ?
+                       V4L2_PIX_FMT_PRIV_MAGIC : 0;
        is_multiplanar = capabilities & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
                                         V4L2_CAP_VIDEO_M2M_MPLANE |
                                         V4L2_CAP_VIDEO_OUTPUT_MPLANE);
@@ -1063,6 +1078,8 @@ int main(int argc, char **argv)
                out_capabilities = vcap.capabilities;
                if (out_capabilities & V4L2_CAP_DEVICE_CAPS)
                        out_capabilities = vcap.device_caps;
+               out_priv_magic = (out_capabilities & V4L2_CAP_EXT_PIX_FORMAT) ?
+                               V4L2_PIX_FMT_PRIV_MAGIC : 0;
        }
 
        common_process_controls(fd);
index 3da77fd..1586599 100644 (file)
@@ -205,6 +205,8 @@ enum Option {
 extern char options[OptLast];
 extern unsigned capabilities;
 extern unsigned out_capabilities;
+extern unsigned priv_magic;
+extern unsigned out_priv_magic;
 extern bool is_multiplanar;
 extern __u32 vidcap_buftype;
 extern __u32 vidout_buftype;