3 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@indt.org.br>
6 * gstv4l2src.c: Video4Linux2 source element
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:element-v4l2src
27 * v4l2src can be used to capture video from v4l2 devices, like webcams and tv
31 * <title>Example launch lines</title>
33 * gst-launch-1.0 v4l2src ! xvimagesink
34 * ]| This pipeline shows the video captured from /dev/video0 tv card and for
37 * gst-launch-1.0 v4l2src ! jpegdec ! xvimagesink
38 * ]| This pipeline shows the video captured from a webcam that delivers jpeg
51 #include <gst/video/gstvideometa.h>
52 #include <gst/video/gstvideopool.h>
54 #include "gstv4l2src.h"
56 #include "gstv4l2colorbalance.h"
57 #include "gstv4l2tuner.h"
58 #include "gstv4l2vidorient.h"
60 #include "gst/gst-i18n-plugin.h"
62 GST_DEBUG_CATEGORY (v4l2src_debug);
63 #define GST_CAT_DEFAULT v4l2src_debug
65 #define DEFAULT_PROP_DEVICE "/dev/video0"
70 V4L2_STD_OBJECT_PROPS,
74 /* signals and args */
77 SIGNAL_PRE_SET_FORMAT,
81 static guint gst_v4l2_signals[LAST_SIGNAL] = { 0 };
83 GST_IMPLEMENT_V4L2_COLOR_BALANCE_METHODS (GstV4l2Src, gst_v4l2src);
84 GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Src, gst_v4l2src);
85 GST_IMPLEMENT_V4L2_VIDORIENT_METHODS (GstV4l2Src, gst_v4l2src);
87 static void gst_v4l2src_uri_handler_init (gpointer g_iface,
90 #define gst_v4l2src_parent_class parent_class
91 G_DEFINE_TYPE_WITH_CODE (GstV4l2Src, gst_v4l2src, GST_TYPE_PUSH_SRC,
92 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_v4l2src_uri_handler_init);
93 G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER, gst_v4l2src_tuner_interface_init);
94 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
95 gst_v4l2src_color_balance_interface_init);
96 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
97 gst_v4l2src_video_orientation_interface_init));
99 static void gst_v4l2src_finalize (GstV4l2Src * v4l2src);
101 /* element methods */
102 static GstStateChangeReturn gst_v4l2src_change_state (GstElement * element,
103 GstStateChange transition);
105 /* basesrc methods */
106 static gboolean gst_v4l2src_start (GstBaseSrc * src);
107 static gboolean gst_v4l2src_unlock (GstBaseSrc * src);
108 static gboolean gst_v4l2src_unlock_stop (GstBaseSrc * src);
109 static gboolean gst_v4l2src_stop (GstBaseSrc * src);
110 static gboolean gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps);
111 static GstCaps *gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter);
112 static gboolean gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query);
113 static gboolean gst_v4l2src_decide_allocation (GstBaseSrc * src,
115 static GstFlowReturn gst_v4l2src_create (GstPushSrc * src, GstBuffer ** out);
116 static GstCaps *gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps);
117 static gboolean gst_v4l2src_negotiate (GstBaseSrc * basesrc);
119 static void gst_v4l2src_set_property (GObject * object, guint prop_id,
120 const GValue * value, GParamSpec * pspec);
121 static void gst_v4l2src_get_property (GObject * object, guint prop_id,
122 GValue * value, GParamSpec * pspec);
125 gst_v4l2src_class_init (GstV4l2SrcClass * klass)
127 GObjectClass *gobject_class;
128 GstElementClass *element_class;
129 GstBaseSrcClass *basesrc_class;
130 GstPushSrcClass *pushsrc_class;
132 gobject_class = G_OBJECT_CLASS (klass);
133 element_class = GST_ELEMENT_CLASS (klass);
134 basesrc_class = GST_BASE_SRC_CLASS (klass);
135 pushsrc_class = GST_PUSH_SRC_CLASS (klass);
137 gobject_class->finalize = (GObjectFinalizeFunc) gst_v4l2src_finalize;
138 gobject_class->set_property = gst_v4l2src_set_property;
139 gobject_class->get_property = gst_v4l2src_get_property;
141 element_class->change_state = gst_v4l2src_change_state;
143 gst_v4l2_object_install_properties_helper (gobject_class,
144 DEFAULT_PROP_DEVICE);
147 * GstV4l2Src::prepare-format:
148 * @v4l2src: the v4l2src instance
149 * @fd: the file descriptor of the current device
150 * @caps: the caps of the format being set
152 * This signal gets emitted before calling the v4l2 VIDIOC_S_FMT ioctl
153 * (set format). This allows for any custom configuration of the device to
154 * happen prior to the format being set.
155 * This is mostly useful for UVC H264 encoding cameras which need the H264
156 * Probe & Commit to happen prior to the normal Probe & Commit.
160 gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT] = g_signal_new ("prepare-format",
161 G_TYPE_FROM_CLASS (klass),
163 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_INT, GST_TYPE_CAPS);
165 gst_element_class_set_static_metadata (element_class,
166 "Video (video4linux2) Source", "Source/Video",
167 "Reads frames from a Video4Linux2 device",
168 "Edgard Lima <edgard.lima@indt.org.br>, "
169 "Stefan Kost <ensonic@users.sf.net>");
171 gst_element_class_add_pad_template
173 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
174 gst_v4l2_object_get_all_caps ()));
176 basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_get_caps);
177 basesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_set_caps);
178 basesrc_class->start = GST_DEBUG_FUNCPTR (gst_v4l2src_start);
179 basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock);
180 basesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock_stop);
181 basesrc_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2src_stop);
182 basesrc_class->query = GST_DEBUG_FUNCPTR (gst_v4l2src_query);
183 basesrc_class->fixate = GST_DEBUG_FUNCPTR (gst_v4l2src_fixate);
184 basesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_v4l2src_negotiate);
185 basesrc_class->decide_allocation =
186 GST_DEBUG_FUNCPTR (gst_v4l2src_decide_allocation);
188 pushsrc_class->create = GST_DEBUG_FUNCPTR (gst_v4l2src_create);
190 klass->v4l2_class_devices = NULL;
192 GST_DEBUG_CATEGORY_INIT (v4l2src_debug, "v4l2src", 0, "V4L2 source element");
196 gst_v4l2src_init (GstV4l2Src * v4l2src)
198 /* fixme: give an update_fps_function */
199 v4l2src->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2src),
200 V4L2_BUF_TYPE_VIDEO_CAPTURE, DEFAULT_PROP_DEVICE,
201 gst_v4l2_get_input, gst_v4l2_set_input, NULL);
203 gst_base_src_set_format (GST_BASE_SRC (v4l2src), GST_FORMAT_TIME);
204 gst_base_src_set_live (GST_BASE_SRC (v4l2src), TRUE);
209 gst_v4l2src_finalize (GstV4l2Src * v4l2src)
211 gst_v4l2_object_destroy (v4l2src->v4l2object);
213 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (v4l2src));
218 gst_v4l2src_set_property (GObject * object,
219 guint prop_id, const GValue * value, GParamSpec * pspec)
221 GstV4l2Src *v4l2src = GST_V4L2SRC (object);
223 if (!gst_v4l2_object_set_property_helper (v4l2src->v4l2object,
224 prop_id, value, pspec)) {
227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234 gst_v4l2src_get_property (GObject * object,
235 guint prop_id, GValue * value, GParamSpec * pspec)
237 GstV4l2Src *v4l2src = GST_V4L2SRC (object);
239 if (!gst_v4l2_object_get_property_helper (v4l2src->v4l2object,
240 prop_id, value, pspec)) {
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 /* this function is a bit of a last resort */
251 gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps)
253 GstStructure *structure;
256 GST_DEBUG_OBJECT (basesrc, "fixating caps %" GST_PTR_FORMAT, caps);
258 caps = gst_caps_make_writable (caps);
260 for (i = 0; i < gst_caps_get_size (caps); ++i) {
261 structure = gst_caps_get_structure (caps, i);
263 /* We are fixating to a reasonable 320x200 resolution
264 and the maximum framerate resolution for that size */
265 if (gst_structure_has_field (structure, "width"))
266 gst_structure_fixate_field_nearest_int (structure, "width", 320);
268 if (gst_structure_has_field (structure, "height"))
269 gst_structure_fixate_field_nearest_int (structure, "height", 200);
271 if (gst_structure_has_field (structure, "framerate"))
272 gst_structure_fixate_field_nearest_fraction (structure, "framerate",
275 if (gst_structure_has_field (structure, "format"))
276 gst_structure_fixate_field (structure, "format");
279 GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, caps);
281 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (basesrc, caps);
288 gst_v4l2src_negotiate (GstBaseSrc * basesrc)
293 GstCaps *caps = NULL;
294 GstCaps *peercaps = NULL;
295 gboolean result = FALSE;
297 v4l2src = GST_V4L2SRC (basesrc);
298 obj = v4l2src->v4l2object;
300 /* We don't allow renegotiation, just return TRUE in that case */
301 if (GST_V4L2_IS_ACTIVE (obj))
304 /* first see what is possible on our source pad */
305 thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
306 GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
307 LOG_CAPS (basesrc, thiscaps);
309 /* nothing or anything is allowed, we're done */
310 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
313 /* get the peer caps without a filter as we'll filter ourselves later on */
314 peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
315 GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
316 LOG_CAPS (basesrc, peercaps);
317 if (peercaps && !gst_caps_is_any (peercaps)) {
318 GstCaps *icaps = NULL;
321 /* Prefer the first caps we are compatible with that the peer proposed */
322 for (i = 0; i < gst_caps_get_size (peercaps); i++) {
323 /* get intersection */
324 GstCaps *ipcaps = gst_caps_copy_nth (peercaps, i);
326 GST_DEBUG_OBJECT (basesrc, "peer: %" GST_PTR_FORMAT, ipcaps);
327 LOG_CAPS (basesrc, ipcaps);
329 icaps = gst_caps_intersect (thiscaps, ipcaps);
330 gst_caps_unref (ipcaps);
332 if (!gst_caps_is_empty (icaps))
335 gst_caps_unref (icaps);
339 GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, icaps);
340 LOG_CAPS (basesrc, icaps);
342 /* If there are multiple intersections pick the one with the smallest
343 * resolution strictly bigger then the first peer caps */
344 if (gst_caps_get_size (icaps) > 1) {
345 GstStructure *s = gst_caps_get_structure (peercaps, 0);
348 int width = G_MAXINT, height = G_MAXINT;
350 if (gst_structure_get_int (s, "width", &twidth)
351 && gst_structure_get_int (s, "height", &theight)) {
353 /* Walk the structure backwards to get the first entry of the
354 * smallest resolution bigger (or equal to) the preferred resolution)
356 for (i = gst_caps_get_size (icaps) - 1; i >= 0; i--) {
357 GstStructure *is = gst_caps_get_structure (icaps, i);
360 if (gst_structure_get_int (is, "width", &w)
361 && gst_structure_get_int (is, "height", &h)) {
362 if (w >= twidth && w <= width && h >= theight && h <= height) {
371 caps = gst_caps_copy_nth (icaps, best);
372 gst_caps_unref (icaps);
377 gst_caps_unref (thiscaps);
379 /* no peer or peer have ANY caps, work with our own caps then */
383 gst_caps_unref (peercaps);
385 caps = gst_caps_truncate (caps);
388 if (!gst_caps_is_empty (caps)) {
389 caps = gst_v4l2src_fixate (basesrc, caps);
390 GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
391 LOG_CAPS (basesrc, caps);
393 if (gst_caps_is_any (caps)) {
394 /* hmm, still anything, so element can do anything and
395 * nego is not needed */
397 } else if (gst_caps_is_fixed (caps)) {
398 /* yay, fixed caps, use those then */
399 result = gst_base_src_set_caps (basesrc, caps);
402 gst_caps_unref (caps);
408 GST_DEBUG_OBJECT (basesrc, "no negotiation needed");
410 gst_caps_unref (thiscaps);
416 gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter)
421 v4l2src = GST_V4L2SRC (src);
422 obj = v4l2src->v4l2object;
424 if (!GST_V4L2_IS_OPEN (obj)) {
425 return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (v4l2src));
428 return gst_v4l2_object_get_caps (obj, filter);
432 gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps)
437 v4l2src = GST_V4L2SRC (src);
438 obj = v4l2src->v4l2object;
440 /* make sure the caps changed before doing anything */
441 if (gst_v4l2_object_caps_equal (obj, caps))
444 /* make sure we stop capturing and dealloc buffers */
445 if (!gst_v4l2_object_stop (obj))
448 g_signal_emit (v4l2src, gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT], 0,
449 v4l2src->v4l2object->video_fd, caps);
451 if (!gst_v4l2_object_set_format (obj, caps))
452 /* error already posted */
459 gst_v4l2src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
461 GstV4l2Src *src = GST_V4L2SRC (bsrc);
462 gboolean ret = FALSE;
464 if (gst_v4l2_object_decide_allocation (src->v4l2object, query))
465 ret = GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
471 gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
475 gboolean res = FALSE;
477 src = GST_V4L2SRC (bsrc);
478 obj = src->v4l2object;
480 switch (GST_QUERY_TYPE (query)) {
481 case GST_QUERY_LATENCY:{
482 GstClockTime min_latency, max_latency;
483 guint32 fps_n, fps_d;
484 guint num_buffers = 0;
486 /* device must be open */
487 if (!GST_V4L2_IS_OPEN (obj)) {
488 GST_WARNING_OBJECT (src,
489 "Can't give latency since device isn't open !");
493 fps_n = GST_V4L2_FPS_N (obj);
494 fps_d = GST_V4L2_FPS_D (obj);
496 /* we must have a framerate */
497 if (fps_n <= 0 || fps_d <= 0) {
498 GST_WARNING_OBJECT (src,
499 "Can't give latency since framerate isn't fixated !");
503 /* min latency is the time to capture one frame */
504 min_latency = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
506 /* max latency is total duration of the frame buffer */
507 if (obj->pool != NULL)
508 num_buffers = GST_V4L2_BUFFER_POOL_CAST (obj->pool)->num_buffers;
510 if (num_buffers == 0)
513 max_latency = num_buffers * min_latency;
515 GST_DEBUG_OBJECT (bsrc,
516 "report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
517 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
519 /* we are always live, the min latency is 1 frame and the max latency is
520 * the complete buffer of frames. */
521 gst_query_set_latency (query, TRUE, min_latency, max_latency);
527 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
536 /* start and stop are not symmetric -- start will open the device, but not start
537 * capture. it's setcaps that will start capture, which is called via basesrc's
538 * negotiate method. stop will both stop capture and close the device.
541 gst_v4l2src_start (GstBaseSrc * src)
543 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
547 /* activate settings for first frame */
548 v4l2src->ctrl_time = 0;
549 gst_object_sync_values (GST_OBJECT (src), v4l2src->ctrl_time);
555 gst_v4l2src_unlock (GstBaseSrc * src)
557 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
558 return gst_v4l2_object_unlock (v4l2src->v4l2object);
562 gst_v4l2src_unlock_stop (GstBaseSrc * src)
564 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
565 return gst_v4l2_object_unlock_stop (v4l2src->v4l2object);
569 gst_v4l2src_stop (GstBaseSrc * src)
571 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
572 GstV4l2Object *obj = v4l2src->v4l2object;
574 if (GST_V4L2_IS_ACTIVE (obj)) {
575 if (!gst_v4l2_object_stop (obj))
581 static GstStateChangeReturn
582 gst_v4l2src_change_state (GstElement * element, GstStateChange transition)
584 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
585 GstV4l2Src *v4l2src = GST_V4L2SRC (element);
586 GstV4l2Object *obj = v4l2src->v4l2object;
588 switch (transition) {
589 case GST_STATE_CHANGE_NULL_TO_READY:
590 /* open the device */
591 if (!gst_v4l2_object_open (obj))
592 return GST_STATE_CHANGE_FAILURE;
598 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
600 switch (transition) {
601 case GST_STATE_CHANGE_READY_TO_NULL:
602 /* close the device */
603 if (!gst_v4l2_object_close (obj))
604 return GST_STATE_CHANGE_FAILURE;
615 gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
617 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
618 GstV4l2Object *obj = v4l2src->v4l2object;
621 GstClockTime abs_time, base_time, timestamp, duration;
624 ret = GST_BASE_SRC_CLASS (parent_class)->alloc (GST_BASE_SRC (src), 0,
625 obj->info.size, buf);
627 if (G_UNLIKELY (ret != GST_FLOW_OK))
631 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL_CAST (obj->pool), buf);
633 if (G_UNLIKELY (ret != GST_FLOW_OK))
636 timestamp = GST_BUFFER_TIMESTAMP (*buf);
637 duration = obj->duration;
639 /* timestamps, LOCK to get clock and base time. */
640 /* FIXME: element clock and base_time is rarely changing */
641 GST_OBJECT_LOCK (v4l2src);
642 if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
643 /* we have a clock, get base time and ref clock */
644 base_time = GST_ELEMENT (v4l2src)->base_time;
645 gst_object_ref (clock);
647 /* no clock, can't set timestamps */
648 base_time = GST_CLOCK_TIME_NONE;
650 GST_OBJECT_UNLOCK (v4l2src);
652 /* sample pipeline clock */
654 abs_time = gst_clock_get_time (clock);
655 gst_object_unref (clock);
657 abs_time = GST_CLOCK_TIME_NONE;
660 if (timestamp != GST_CLOCK_TIME_NONE) {
664 /* v4l2 specs say to use the system time although many drivers switched to
665 * the more desirable monotonic time. We first try to use the monotonic time
666 * and see how that goes */
667 clock_gettime (CLOCK_MONOTONIC, &now);
668 gstnow = GST_TIMESPEC_TO_TIME (now);
670 if (gstnow < timestamp && (timestamp - gstnow) > (10 * GST_SECOND)) {
673 /* very large diff, fall back to system time */
674 g_get_current_time (&now);
675 gstnow = GST_TIMEVAL_TO_TIME (now);
678 if (gstnow > timestamp) {
679 delay = gstnow - timestamp;
684 GST_DEBUG_OBJECT (v4l2src, "ts: %" GST_TIME_FORMAT " now %" GST_TIME_FORMAT
685 " delay %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
686 GST_TIME_ARGS (gstnow), GST_TIME_ARGS (delay));
688 /* we assume 1 frame latency otherwise */
689 if (GST_CLOCK_TIME_IS_VALID (duration))
695 /* set buffer metadata */
696 GST_BUFFER_OFFSET (*buf) = v4l2src->offset++;
697 GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset;
699 if (G_LIKELY (abs_time != GST_CLOCK_TIME_NONE)) {
700 /* the time now is the time of the clock minus the base time */
701 timestamp = abs_time - base_time;
703 /* adjust for delay in the device */
704 if (timestamp > delay)
709 timestamp = GST_CLOCK_TIME_NONE;
712 /* activate settings for next frame */
713 if (GST_CLOCK_TIME_IS_VALID (duration)) {
714 v4l2src->ctrl_time += duration;
716 /* this is not very good (as it should be the next timestamp),
717 * still good enough for linear fades (as long as it is not -1)
719 v4l2src->ctrl_time = timestamp;
721 gst_object_sync_values (GST_OBJECT (src), v4l2src->ctrl_time);
723 GST_INFO_OBJECT (src, "sync to %" GST_TIME_FORMAT " out ts %" GST_TIME_FORMAT,
724 GST_TIME_ARGS (v4l2src->ctrl_time), GST_TIME_ARGS (timestamp));
726 GST_BUFFER_TIMESTAMP (*buf) = timestamp;
727 GST_BUFFER_DURATION (*buf) = duration;
734 if (ret != GST_FLOW_FLUSHING)
735 GST_ELEMENT_ERROR (src, RESOURCE, NO_SPACE_LEFT,
736 ("Failed to allocate a buffer"), (NULL));
741 GST_DEBUG_OBJECT (src, "error processing buffer %d (%s)", ret,
742 gst_flow_get_name (ret));
748 /* GstURIHandler interface */
750 gst_v4l2src_uri_get_type (GType type)
755 static const gchar *const *
756 gst_v4l2src_uri_get_protocols (GType type)
758 static const gchar *protocols[] = { "v4l2", NULL };
764 gst_v4l2src_uri_get_uri (GstURIHandler * handler)
766 GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
768 if (v4l2src->v4l2object->videodev != NULL) {
769 return g_strdup_printf ("v4l2://%s", v4l2src->v4l2object->videodev);
772 return g_strdup ("v4l2://");
776 gst_v4l2src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
779 GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
780 const gchar *device = DEFAULT_PROP_DEVICE;
782 if (strcmp (uri, "v4l2://") != 0) {
785 g_object_set (v4l2src, "device", device, NULL);
792 gst_v4l2src_uri_handler_init (gpointer g_iface, gpointer iface_data)
794 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
796 iface->get_type = gst_v4l2src_uri_get_type;
797 iface->get_protocols = gst_v4l2src_uri_get_protocols;
798 iface->get_uri = gst_v4l2src_uri_get_uri;
799 iface->set_uri = gst_v4l2src_uri_set_uri;