From 99b6a018cc70f73d067e26f2c79b18b98f0f9b57 Mon Sep 17 00:00:00 2001 From: fryshorts Date: Tue, 24 Feb 2015 22:18:24 +0100 Subject: [PATCH] linux-v4l2: Add helper function to set dv timing Add a helper function to set the dv timing for the input. --- plugins/linux-v4l2/v4l2-helpers.c | 19 +++++++++++++++++++ plugins/linux-v4l2/v4l2-helpers.h | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/plugins/linux-v4l2/v4l2-helpers.c b/plugins/linux-v4l2/v4l2-helpers.c index 080a83fb1..5bed14c7c 100644 --- a/plugins/linux-v4l2/v4l2-helpers.c +++ b/plugins/linux-v4l2/v4l2-helpers.c @@ -254,3 +254,22 @@ int_fast32_t v4l2_enum_dv_timing(int_fast32_t dev, struct v4l2_dv_timings *dvt, return 0; } + +int_fast32_t v4l2_set_dv_timing(int_fast32_t dev, int *timing) +{ + if (!dev || !timing) + return -1; + + if (*timing == -1) + return 0; + + struct v4l2_dv_timings dvt; + + if (v4l2_enum_dv_timing(dev, &dvt, *timing) < 0) + return -1; + + if (v4l2_ioctl(dev, VIDIOC_S_DV_TIMINGS, &dvt) < 0) + return -1; + + return 0; +} diff --git a/plugins/linux-v4l2/v4l2-helpers.h b/plugins/linux-v4l2/v4l2-helpers.h index 390fac669..f3860d094 100644 --- a/plugins/linux-v4l2/v4l2-helpers.h +++ b/plugins/linux-v4l2/v4l2-helpers.h @@ -281,6 +281,17 @@ int_fast32_t v4l2_set_standard(int_fast32_t dev, int *standard); */ int_fast32_t v4l2_enum_dv_timing(int_fast32_t dev, struct v4l2_dv_timings *dvt, int index); +/** + * Set a dv timing on the device + * + * Currently standard will not be changed on success or error. + * + * @param dev handle to the v4l2 device + * @param timing index of the timing to use or -1 to leave as is + * + * @return negative on failure + */ +int_fast32_t v4l2_set_dv_timing(int_fast32_t dev, int *timing); #ifdef __cplusplus }