瀏覽代碼

Use helper function to set input in v4l2 input.

fryshorts 11 年之前
父節點
當前提交
8d95a7fb47
共有 3 個文件被更改,包括 30 次插入4 次删除
  1. 11 0
      plugins/linux-v4l2/v4l2-helpers.c
  2. 12 0
      plugins/linux-v4l2/v4l2-helpers.h
  3. 7 4
      plugins/linux-v4l2/v4l2-input.c

+ 11 - 0
plugins/linux-v4l2/v4l2-helpers.c

@@ -123,3 +123,14 @@ int_fast32_t v4l2_destroy_mmap(struct v4l2_buffer_data *buf)
 	return 0;
 }
 
+int_fast32_t v4l2_set_input(int_fast32_t dev, int *input)
+{
+	if (!dev || !input)
+		return -1;
+
+	return (*input == -1)
+		? v4l2_ioctl(dev, VIDIOC_G_INPUT, input)
+		: v4l2_ioctl(dev, VIDIOC_S_INPUT, input);
+}
+
+

+ 12 - 0
plugins/linux-v4l2/v4l2-helpers.h

@@ -175,6 +175,18 @@ int_fast32_t v4l2_create_mmap(int_fast32_t dev, struct v4l2_buffer_data *buf);
  */
 int_fast32_t v4l2_destroy_mmap(struct v4l2_buffer_data *buf);
 
+/**
+ * Set the video input on the device.
+ *
+ * If the action succeeds input is set to the currently selected input.
+ *
+ * @param dev handle for the v4l2 device
+ * @param input index of the input or -1 to leave it as is
+ *
+ * @return negative on failure
+ */
+int_fast32_t v4l2_set_input(int_fast32_t dev, int *input);
+
 #ifdef __cplusplus
 }
 #endif

+ 7 - 4
plugins/linux-v4l2/v4l2-input.c

@@ -61,7 +61,7 @@ struct v4l2_data {
 	os_event_t event;
 
 	char *set_device;
-	int_fast32_t set_input;
+	int set_input;
 	int_fast32_t set_pixfmt;
 	int_fast32_t set_res;
 	int_fast32_t set_fps;
@@ -305,7 +305,8 @@ static void v4l2_input_list(int_fast32_t dev, obs_property_t prop)
 		if (in.type & V4L2_INPUT_TYPE_CAMERA) {
 			obs_property_list_add_int(prop, (char *) in.name,
 					in.index);
-			blog(LOG_INFO, "Found input '%s'", in.name);
+			blog(LOG_INFO, "Found input '%s' (Index %d)", in.name,
+					in.index);
 		}
 		in.index++;
 	}
@@ -609,10 +610,12 @@ static void v4l2_init(struct v4l2_data *data)
 	}
 
 	/* set input */
-	if (v4l2_ioctl(data->dev, VIDIOC_S_INPUT, &data->set_input) < 0) {
-		blog(LOG_ERROR, "Unable to set input");
+	if (v4l2_set_input(data->dev, &data->set_input) < 0) {
+		blog(LOG_ERROR, "Unable to set input %d",
+				data->set_input);
 		goto fail;
 	}
+	blog(LOG_INFO, "Input: %d", data->set_input);
 
 	/* set pixel format and resolution */
 	unpack_tuple(&width, &height, data->set_res);