summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2011-07-12 14:53:22 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2013-09-13 16:33:03 +0200
commit36344ce15cadd72668f917ddb74ef771c62a69de (patch)
tree6a6d1a45c356fb1eb02b1fe6f7c91a0584fd7fa0
parent508e105d644bb17b6532caab6337b821085b847b (diff)
downloadgst-plugins-good-36344ce15cadd72668f917ddb74ef771c62a69de.tar.gz
gst-plugins-good-36344ce15cadd72668f917ddb74ef771c62a69de.tar.xz
v4l2: v4l2_calls: add gst_v4l2_clone
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--sys/v4l2/v4l2_calls.c79
-rw-r--r--sys/v4l2/v4l2_calls.h2
2 files changed, 50 insertions, 31 deletions
diff --git a/sys/v4l2/v4l2_calls.c b/sys/v4l2/v4l2_calls.c
index 4ace236ac..72a639580 100644
--- a/sys/v4l2/v4l2_calls.c
+++ b/sys/v4l2/v4l2_calls.c
@@ -470,12 +470,13 @@ gst_v4l2_empty_lists (GstV4l2Object * v4l2object)
}
/******************************************************
- * gst_v4l2_open():
- * open the video device (v4l2object->videodev)
+ * gst_v4l2_clone():
+ * clone the video device from the other object,
+ * or open a video device (v4l2object->videodev)
* return value: TRUE on success, FALSE on error
******************************************************/
gboolean
-gst_v4l2_open (GstV4l2Object * v4l2object)
+gst_v4l2_clone (GstV4l2Object * v4l2object, GstV4l2Object * other)
{
struct stat st;
int libv4l2_fd;
@@ -487,34 +488,39 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
GST_V4L2_CHECK_NOT_OPEN (v4l2object);
GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
- /* be sure we have a device */
- if (!v4l2object->videodev)
- v4l2object->videodev = g_strdup ("/dev/video");
-
- /* check if it is a device */
- if (stat (v4l2object->videodev, &st) == -1)
- goto stat_failed;
-
- if (!S_ISCHR (st.st_mode))
- goto no_device;
-
- /* open the device */
- v4l2object->video_fd =
- open (v4l2object->videodev, O_RDWR /* | O_NONBLOCK */ );
-
- if (!GST_V4L2_IS_OPEN (v4l2object))
- goto not_open;
-
- libv4l2_fd = v4l2_fd_open (v4l2object->video_fd,
- V4L2_ENABLE_ENUM_FMT_EMULATION);
- /* Note the v4l2_xxx functions are designed so that if they get passed an
- unknown fd, the will behave exactly as their regular xxx counterparts, so
- if v4l2_fd_open fails, we continue as normal (missing the libv4l2 custom
- cam format to normal formats conversion). Chances are big we will still
- fail then though, as normally v4l2_fd_open only fails if the device is not
- a v4l2 device. */
- if (libv4l2_fd != -1)
- v4l2object->video_fd = libv4l2_fd;
+ if (!other) {
+ /* be sure we have a device */
+ if (!v4l2object->videodev)
+ v4l2object->videodev = g_strdup ("/dev/video");
+
+ /* check if it is a device */
+ if (stat (v4l2object->videodev, &st) == -1)
+ goto stat_failed;
+
+ if (!S_ISCHR (st.st_mode))
+ goto no_device;
+
+ /* open the device */
+ v4l2object->video_fd =
+ open (v4l2object->videodev, O_RDWR /* | O_NONBLOCK */ );
+
+ if (!GST_V4L2_IS_OPEN (v4l2object))
+ goto not_open;
+
+ libv4l2_fd = v4l2_fd_open (v4l2object->video_fd,
+ V4L2_ENABLE_ENUM_FMT_EMULATION);
+ /* Note the v4l2_xxx functions are designed so that if they get passed an
+ unknown fd, the will behave exactly as their regular xxx counterparts, so
+ if v4l2_fd_open fails, we continue as normal (missing the libv4l2 custom
+ cam format to normal formats conversion). Chances are big we will still
+ fail then though, as normally v4l2_fd_open only fails if the device is not
+ a v4l2 device. */
+ if (libv4l2_fd != -1)
+ v4l2object->video_fd = libv4l2_fd;
+ } else {
+ v4l2object->video_fd = v4l2_dup (other->video_fd);
+ v4l2object->videodev = g_strdup (other->videodev);
+ }
v4l2object->can_poll_device = TRUE;
@@ -605,6 +611,17 @@ error:
/******************************************************
+ * gst_v4l2_open():
+ * open the video device (v4l2object->videodev)
+ * return value: TRUE on success, FALSE on error
+ ******************************************************/
+gboolean
+gst_v4l2_open (GstV4l2Object * v4l2object)
+{
+ return gst_v4l2_clone (v4l2object, NULL);
+}
+
+/******************************************************
* gst_v4l2_close():
* close the video device (v4l2object->video_fd)
* return value: TRUE on success, FALSE on error
diff --git a/sys/v4l2/v4l2_calls.h b/sys/v4l2/v4l2_calls.h
index 11d16b6ab..cac963bac 100644
--- a/sys/v4l2/v4l2_calls.h
+++ b/sys/v4l2/v4l2_calls.h
@@ -90,6 +90,8 @@
/* open/close the device */
+gboolean gst_v4l2_clone (GstV4l2Object *v4l2object,
+ GstV4l2Object *other);
gboolean gst_v4l2_open (GstV4l2Object *v4l2object);
gboolean gst_v4l2_close (GstV4l2Object *v4l2object);