From 96b994afb2d492aefd50c620663a6659444c6865 Mon Sep 17 00:00:00 2001 From: fryshorts Date: Mon, 16 Feb 2015 22:29:39 +0100 Subject: [PATCH] linux-v4l2: Add helper function to get input caps Add a helper function to get the capabilities of a specific or the currently selected input of the device. --- plugins/linux-v4l2/v4l2-helpers.c | 21 +++++++++++++++++++++ plugins/linux-v4l2/v4l2-helpers.h | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/linux-v4l2/v4l2-helpers.c b/plugins/linux-v4l2/v4l2-helpers.c index 657b221b9..ffb8eedf0 100644 --- a/plugins/linux-v4l2/v4l2-helpers.c +++ b/plugins/linux-v4l2/v4l2-helpers.c @@ -133,6 +133,27 @@ int_fast32_t v4l2_set_input(int_fast32_t dev, int *input) : v4l2_ioctl(dev, VIDIOC_S_INPUT, input); } +int_fast32_t v4l2_get_input_caps(int_fast32_t dev, int input, uint32_t *caps) +{ + if (!dev || !caps) + return -1; + + if (input == -1) { + if (v4l2_ioctl(dev, VIDIOC_G_INPUT, &input) < 0) + return -1; + } + + struct v4l2_input in; + memset(&in, 0, sizeof(in)); + in.index = input; + + if (v4l2_ioctl(dev, VIDIOC_ENUMINPUT, &in) < 0) + return -1; + + *caps = in.capabilities; + return 0; +} + int_fast32_t v4l2_set_format(int_fast32_t dev, int *resolution, int *pixelformat, int *bytesperline) { diff --git a/plugins/linux-v4l2/v4l2-helpers.h b/plugins/linux-v4l2/v4l2-helpers.h index 6b5d862e7..79facf1cd 100644 --- a/plugins/linux-v4l2/v4l2-helpers.h +++ b/plugins/linux-v4l2/v4l2-helpers.h @@ -219,6 +219,17 @@ int_fast32_t v4l2_destroy_mmap(struct v4l2_buffer_data *buf); */ int_fast32_t v4l2_set_input(int_fast32_t dev, int *input); +/** + * Get capabilities for an input. + * + * @param dev handle for the v4l2 device + * @param input index of the input or -1 to use the currently selected + * @param caps capabilities for the input + * + * @return negative on failure + */ +int_fast32_t v4l2_get_input_caps(int_fast32_t dev, int input, uint32_t *caps); + /** * Set the video format on the device. *