v4l2-ctl: add streaming options.
authorHans Verkuil <hans.verkuil@cisco.com>
Thu, 26 Jul 2012 13:16:56 +0000 (15:16 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 27 Jul 2012 06:30:18 +0000 (08:30 +0200)
Currently the only available options query the buffers.
But this will be extended over time.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-ctl/Makefile.am
utils/v4l2-ctl/v4l2-ctl-streaming.cpp [new file with mode: 0644]
utils/v4l2-ctl/v4l2-ctl.cpp
utils/v4l2-ctl/v4l2-ctl.h

index b0109a0..a868177 100644 (file)
@@ -7,5 +7,6 @@ ivtv_ctl_LDFLAGS = -lm
 
 v4l2_ctl_SOURCES = v4l2-ctl.cpp v4l2-ctl.h v4l2-ctl-common.cpp v4l2-ctl-tuner.cpp \
        v4l2-ctl-io.cpp v4l2-ctl-stds.cpp v4l2-ctl-vidcap.cpp v4l2-ctl-vidout.cpp \
-       v4l2-ctl-overlay.cpp v4l2-ctl-vbi.cpp v4l2-ctl-selection.cpp v4l2-ctl-misc.cpp
+       v4l2-ctl-overlay.cpp v4l2-ctl-vbi.cpp v4l2-ctl-selection.cpp v4l2-ctl-misc.cpp \
+       v4l2-ctl-streaming.cpp
 v4l2_ctl_LDADD = ../../lib/libv4l2/libv4l2.la
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
new file mode 100644 (file)
index 0000000..85e823a
--- /dev/null
@@ -0,0 +1,178 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <dirent.h>
+#include <math.h>
+#include <config.h>
+
+#include <linux/videodev2.h>
+#include <libv4l2.h>
+#include <string>
+
+#include "v4l2-ctl.h"
+
+void streaming_usage(void)
+{
+       printf("\nVideo Streaming options:\n"
+              "  --list-buffers     list all video buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-mplane\n"
+              "                     list all multi-planar video buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-out list all video output buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-out-mplane\n"
+              "                     list all multi-planar video output buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-vbi list all VBI buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-vbi-out\n"
+              "                     list all VBI output buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-sliced-vbi\n"
+              "                     list all sliced VBI buffers [VIDIOC_QUERYBUF]\n"
+              "  --list-buffers-sliced-vbi-out\n"
+              "                     list all sliced VBI output buffers [VIDIOC_QUERYBUF]\n"
+              );
+}
+
+static const flag_def flags_def[] = {
+       { V4L2_BUF_FLAG_MAPPED, "mapped" },
+       { V4L2_BUF_FLAG_QUEUED, "queued" },
+       { V4L2_BUF_FLAG_DONE, "done" },
+       { V4L2_BUF_FLAG_KEYFRAME, "keyframe" },
+       { V4L2_BUF_FLAG_PFRAME, "P-frame" },
+       { V4L2_BUF_FLAG_BFRAME, "B-frame" },
+       { V4L2_BUF_FLAG_ERROR, "error" },
+       { V4L2_BUF_FLAG_TIMECODE, "timecode" },
+       { V4L2_BUF_FLAG_INPUT, "input" },
+       { V4L2_BUF_FLAG_PREPARED, "prepared" },
+       { V4L2_BUF_FLAG_NO_CACHE_INVALIDATE, "no-cache-invalidate" },
+       { V4L2_BUF_FLAG_NO_CACHE_CLEAN, "no-cache-clean" },
+       { 0, NULL }
+};
+
+static const flag_def tc_flags_def[] = {
+       { V4L2_TC_FLAG_DROPFRAME, "dropframe" },
+       { V4L2_TC_FLAG_COLORFRAME, "colorframe" },
+       { V4L2_TC_USERBITS_field, "userbits-field" },
+       { V4L2_TC_USERBITS_USERDEFINED, "userbits-userdefined" },
+       { V4L2_TC_USERBITS_8BITCHARS, "userbits-8bitchars" },
+       { 0, NULL }
+};
+
+static void print_buffer(struct v4l2_buffer &buf)
+{
+       printf("\tIndex    : %d\n", buf.index);
+       printf("\tType     : %s\n", buftype2s(buf.type).c_str());
+       printf("\tFlags    : %s\n", flags2s(buf.flags, flags_def).c_str());
+       printf("\tField    : %s\n", field2s(buf.field).c_str());
+       printf("\tSequence : %u\n", buf.sequence);
+       printf("\tLength   : %u\n", buf.length);
+       printf("\tBytesused: %u\n", buf.bytesused);
+       printf("\tTimestamp: %lu.%06lus\n", buf.timestamp.tv_sec, buf.timestamp.tv_usec);
+       if (buf.flags & V4L2_BUF_FLAG_TIMECODE) {
+               static const int fps_types[] = { 0, 24, 25, 30, 50, 60 };
+               int fps = buf.timecode.type;
+
+               if (fps > 5)
+                       fps = 0;
+               printf("\tTimecode : %dfps %s %dh %dm %ds %df (0x%02x 0x%02x 0x%02x 0x%02x)\n",
+                       fps_types[fps],
+                       flags2s(buf.timecode.flags, tc_flags_def).c_str(),
+                       buf.timecode.hours, buf.timecode.minutes,
+                       buf.timecode.seconds, buf.timecode.frames,
+                       buf.timecode.userbits[0], buf.timecode.userbits[1],
+                       buf.timecode.userbits[2], buf.timecode.userbits[3]);
+       }
+       if (buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
+           buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+               for (unsigned i = 0; i < buf.length; i++) {
+                       struct v4l2_plane *p = buf.m.planes + i;
+
+                       printf("\tPlane    : %d\n", i);
+                       printf("\t\tLength     : %u\n", p->length);
+                       printf("\t\tBytesused  : %u\n", p->bytesused);
+                       printf("\t\tData Offset: %u\n", p->data_offset);
+               }
+       }
+                       
+       printf("\n");
+}
+
+static void list_buffers(int fd, unsigned buftype)
+{
+       int i;
+
+       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+               struct v4l2_plane planes[VIDEO_MAX_PLANES];
+               struct v4l2_buffer buf;
+
+               buf.type = buftype;
+               buf.index = i;
+               buf.reserved = 0;
+               if (buftype == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
+                   buftype == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+                       buf.m.planes = planes;
+                       memset(planes, 0, sizeof(planes));
+               }
+               if (ioctl(fd, VIDIOC_QUERYBUF, &buf))
+                       break;
+               if (i == 0)
+                       printf("VIDIOC_QUERYBUF:\n");
+               print_buffer(buf);
+       }
+}
+
+void streaming_cmd(int ch, char *optarg)
+{
+       switch (ch) {
+       }
+}
+
+void streaming_set(int fd)
+{
+}
+
+void streaming_get(int fd)
+{
+}
+
+void streaming_list(int fd)
+{
+       if (options[OptListBuffers]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+       }
+
+       if (options[OptListBuffersMplane]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+       }
+
+       if (options[OptListBuffersOut]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+       }
+
+       if (options[OptListBuffersMplaneOut]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
+       }
+
+       if (options[OptListBuffersVbi]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VBI_CAPTURE);
+       }
+
+       if (options[OptListBuffersSlicedVbi]) {
+               list_buffers(fd, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
+       }
+
+       if (options[OptListBuffersVbiOut]) {
+               list_buffers(fd, V4L2_BUF_TYPE_VBI_OUTPUT);
+       }
+
+       if (options[OptListBuffersSlicedVbiOut]) {
+               list_buffers(fd, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT);
+       }
+}
index 9bd8fe8..ee5ff93 100644 (file)
@@ -187,6 +187,14 @@ static struct option long_options[] = {
        {"decoder-cmd", required_argument, 0, OptDecoderCmd},
        {"try-decoder-cmd", required_argument, 0, OptTryDecoderCmd},
        {"tuner-index", required_argument, 0, OptTunerIndex},
+       {"list-buffers", no_argument, 0, OptListBuffers},
+       {"list-buffers-mplane", no_argument, 0, OptListBuffersMplane},
+       {"list-buffers-out", no_argument, 0, OptListBuffersOut},
+       {"list-buffers-mplane-out", no_argument, 0, OptListBuffersMplaneOut},
+       {"list-buffers-vbi", no_argument, 0, OptListBuffersVbi},
+       {"list-buffers-sliced-vbi", no_argument, 0, OptListBuffersSlicedVbi},
+       {"list-buffers-vbi-out", no_argument, 0, OptListBuffersVbiOut},
+       {"list-buffers-sliced-vbi-out", no_argument, 0, OptListBuffersSlicedVbiOut},
        {0, 0, 0, 0}
 };
 
@@ -202,6 +210,7 @@ static void usage_all(void)
        vbi_usage();
        selection_usage();
        misc_usage();
+       streaming_usage();
 }
 
 static int test_open(const char *file, int oflag)
@@ -286,7 +295,7 @@ std::string fcc2s(unsigned int val)
        return s;
 }
 
-static std::string field2s(int val)
+std::string field2s(int val)
 {
        switch (val) {
        case V4L2_FIELD_ANY:
@@ -841,6 +850,7 @@ int main(int argc, char **argv)
                        vbi_cmd(ch, optarg);
                        selection_cmd(ch, optarg);
                        misc_cmd(ch, optarg);
+                       streaming_cmd(ch, optarg);
                        break;
                }
        }
@@ -966,6 +976,7 @@ int main(int argc, char **argv)
        vidout_list(fd);
        overlay_list(fd);
        vbi_list(fd);
+       streaming_list(fd);
 
        if (options[OptWaitForEvent]) {
                struct v4l2_event_subscription sub;
index 6928b76..4d0fc4f 100644 (file)
@@ -131,6 +131,14 @@ enum Option {
        OptDecoderCmd,
        OptTryDecoderCmd,
        OptTunerIndex,
+       OptListBuffers,
+       OptListBuffersMplane,
+       OptListBuffersOut,
+       OptListBuffersMplaneOut,
+       OptListBuffersVbi,
+       OptListBuffersSlicedVbi,
+       OptListBuffersVbiOut,
+       OptListBuffersSlicedVbiOut,
        OptHelpTuner,
        OptHelpIO,
        OptHelpStds,
@@ -174,6 +182,7 @@ std::string fcc2s(unsigned int val);
 std::string fmtdesc2s(unsigned flags);
 std::string colorspace2s(int val);
 std::string service2s(unsigned service);
+std::string field2s(int val);
 void print_v4lstd(v4l2_std_id std);
 int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat);
 __u32 find_pixel_format(int fd, unsigned index, bool mplane);
@@ -252,5 +261,11 @@ void misc_cmd(int ch, char *optarg);
 void misc_set(int fd);
 void misc_get(int fd);
 
+// v4l2-ctl-streaming.cpp
+void streaming_usage(void);
+void streaming_cmd(int ch, char *optarg);
+void streaming_set(int fd);
+void streaming_get(int fd);
+void streaming_list(int fd);
 
 #endif