Pārlūkot izejas kodu

linux-v4l2: Add helper function to set dv timing

Add a helper function to set the dv timing for the input.
fryshorts 10 gadi atpakaļ
vecāks
revīzija
99b6a018cc
2 mainītis faili ar 30 papildinājumiem un 0 dzēšanām
  1. 19 0
      plugins/linux-v4l2/v4l2-helpers.c
  2. 11 0
      plugins/linux-v4l2/v4l2-helpers.h

+ 19 - 0
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;
+}

+ 11 - 0
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
 }