diff --git a/src/device.c b/src/device.c index 8c1355e..aa28c8f 100644 --- a/src/device.c +++ b/src/device.c @@ -185,6 +185,7 @@ void device_close(struct device_t *dev) { static int _device_open_check_cap(struct device_t *dev) { struct v4l2_capability cap; + int input = dev->input; // Needs pointer to int for ioctl() MEMSET_ZERO(cap); @@ -204,10 +205,16 @@ static int _device_open_check_cap(struct device_t *dev) { return -1; } + LOG_INFO("Using input channel: %d", input); + if (xioctl(dev->run->fd, VIDIOC_S_INPUT, &input) < 0) { + LOG_ERROR("Can't set input channel"); + return -1; + } + if (dev->standard != V4L2_STD_UNKNOWN) { LOG_INFO("Using TV standard: %s", _standard_to_string(dev->standard)); if (xioctl(dev->run->fd, VIDIOC_S_STD, &dev->standard) < 0) { - LOG_PERROR("Can't set video standard"); + LOG_ERROR("Can't set video standard"); return -1; } } else { diff --git a/src/device.h b/src/device.h index e3619b3..ee7ab75 100644 --- a/src/device.h +++ b/src/device.h @@ -64,6 +64,7 @@ struct device_runtime_t { struct device_t { char *path; + unsigned input; unsigned width; unsigned height; unsigned format; diff --git a/src/main.c b/src/main.c index a6cf78f..292de52 100644 --- a/src/main.c +++ b/src/main.c @@ -40,9 +40,10 @@ #include "http.h" -static const char _short_opts[] = "d:x:y:f:a:e:z:tn:w:q:c:s:p:r:h"; +static const char _short_opts[] = "d:i:x:y:f:a:e:z:tn:w:q:c:s:p:r:h"; static const struct option _long_opts[] = { {"device", required_argument, NULL, 'd'}, + {"input", required_argument, NULL, 'i'}, {"width", required_argument, NULL, 'x'}, {"height", required_argument, NULL, 'y'}, {"format", required_argument, NULL, 'f'}, @@ -83,9 +84,10 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s printf("Copyright (C) 2018 Maxim Devaev \n\n"); printf("Capturing options:\n"); printf("------------------\n"); - printf(" -d|--device -- Path to V4L2 device. Default: %s\n\n", dev->path); - printf(" -x|--width -- Initial image width. Default: %d\n\n", dev->width); - printf(" -y|--height -- Initial image height. Default: %d\n\n", dev->height); + printf(" -d|--device -- Path to V4L2 device. Default: %s.\n\n", dev->path); + printf(" -i|--input -- Input channel. Default: %u.\n\n", dev->input); + printf(" -x|--width -- Initial image width. Default: %d.\n\n", dev->width); + printf(" -y|--height -- Initial image height. Default: %d.\n\n", dev->height); printf(" -f|--format -- Image format.\n"); printf(" Available: %s; default: YUYV.\n\n", FORMATS_STR); printf(" -a|--tv-standard -- Force TV standard.\n"); @@ -156,6 +158,7 @@ static int _parse_options(int argc, char *argv[], struct device_t *dev, struct e while ((ch = getopt_long(argc, argv, _short_opts, _long_opts, &index)) >= 0) { switch (ch) { case 'd': OPT_SET(dev->path, optarg); + case 'i': OPT_UNSIGNED(dev->input, "--input", 0, 128); case 'x': OPT_UNSIGNED(dev->width, "--width", 320, 1920); case 'y': OPT_UNSIGNED(dev->height, "--height", 180, 1200); # pragma GCC diagnostic ignored "-Wsign-compare"