clients/simple-dmabuf-v4l: Convert to use getopt_long
Makes adding further flags/options/args much easier. Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
committed by
Pekka Paalanen
parent
baa1ef22e8
commit
3345452c1b
+38
-18
@@ -30,6 +30,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@@ -913,7 +914,7 @@ destroy_display(struct display *display)
|
|||||||
static void
|
static void
|
||||||
usage(const char *argv0)
|
usage(const char *argv0)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [V4L2 device] [V4L2 format] [DRM format]\n"
|
printf("Usage: %s [-v v4l2_device] [-f v4l2_format] [-d drm_format]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"The default V4L2 device is /dev/video0\n"
|
"The default V4L2 device is /dev/video0\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -934,7 +935,7 @@ usage(const char *argv0)
|
|||||||
"- set the pixel format:\n"
|
"- set the pixel format:\n"
|
||||||
" $ v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,pixelformat=XR24\n"
|
" $ v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,pixelformat=XR24\n"
|
||||||
"- launch the demo:\n"
|
"- launch the demo:\n"
|
||||||
" $ %s /dev/video0 XR24 XR24\n"
|
" $ %s -v /dev/video0 -f XR24 -d XR24\n"
|
||||||
"You should see a test pattern with color bars, and some text.\n"
|
"You should see a test pattern with color bars, and some text.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"More about vivid: https://www.kernel.org/doc/Documentation/video4linux/vivid.txt\n"
|
"More about vivid: https://www.kernel.org/doc/Documentation/video4linux/vivid.txt\n"
|
||||||
@@ -955,27 +956,46 @@ main(int argc, char **argv)
|
|||||||
struct sigaction sigint;
|
struct sigaction sigint;
|
||||||
struct display *display;
|
struct display *display;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
const char *v4l_device;
|
const char *v4l_device = NULL;
|
||||||
uint32_t v4l_format, drm_format;
|
uint32_t v4l_format = 0x0;
|
||||||
int ret = 0;
|
uint32_t drm_format = 0x0;
|
||||||
|
int c, opt_index, ret = 0;
|
||||||
|
|
||||||
if (argc < 2) {
|
static struct option long_options[] = {
|
||||||
v4l_device = "/dev/video0";
|
{ "v4l2-device", required_argument, NULL, 'v' },
|
||||||
} else if (!strcmp(argv[1], "--help")) {
|
{ "v4l2-format", required_argument, NULL, 'f' },
|
||||||
usage(argv[0]);
|
{ "drm-format", required_argument, NULL, 'd' },
|
||||||
} else {
|
{ "help", no_argument, NULL, 'h' },
|
||||||
v4l_device = argv[1];
|
{ 0, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
while ((c = getopt_long(argc, argv, "hv:d:f:", long_options,
|
||||||
|
&opt_index)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'v':
|
||||||
|
v4l_device = optarg;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
v4l_format = parse_format(optarg);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
drm_format = parse_format(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case 'h':
|
||||||
|
usage(argv[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3)
|
if (!v4l_device)
|
||||||
v4l_format = parse_format("YUYV");
|
v4l_device = "/dev/video0";
|
||||||
else
|
|
||||||
v4l_format = parse_format(argv[2]);
|
|
||||||
|
|
||||||
if (argc < 4)
|
if (v4l_format == 0x0)
|
||||||
|
v4l_format = parse_format("YUYV");
|
||||||
|
|
||||||
|
if (drm_format == 0x0)
|
||||||
drm_format = v4l_format;
|
drm_format = v4l_format;
|
||||||
else
|
|
||||||
drm_format = parse_format(argv[3]);
|
|
||||||
|
|
||||||
display = create_display(drm_format);
|
display = create_display(drm_format);
|
||||||
display->format.format = v4l_format;
|
display->format.format = v4l_format;
|
||||||
|
|||||||
Reference in New Issue
Block a user