Browse Source

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.
fryshorts 10 years ago
parent
commit
96b994afb2
2 changed files with 32 additions and 0 deletions
  1. 21 0
      plugins/linux-v4l2/v4l2-helpers.c
  2. 11 0
      plugins/linux-v4l2/v4l2-helpers.h

+ 21 - 0
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)
 {

+ 11 - 0
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.
  *