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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, 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 v4l2src ! xvimagesink
34 * ]| This pipeline shows the video captured from /dev/video0 tv card and for
37 * gst-launch v4l2src ! jpegdec ! xvimagesink
38 * ]| This pipeline shows the video captured from a webcam that delivers jpeg
53 #include "gstv4l2src.h"
55 #include "gstv4l2colorbalance.h"
56 #include "gstv4l2tuner.h"
58 #include "gstv4l2xoverlay.h"
60 #include "gstv4l2vidorient.h"
62 #include "gst/gst-i18n-plugin.h"
64 GST_DEBUG_CATEGORY (v4l2src_debug);
65 #define GST_CAT_DEFAULT v4l2src_debug
67 #define PROP_DEF_QUEUE_SIZE 2
68 #define PROP_DEF_ALWAYS_COPY TRUE
69 #define PROP_DEF_DECIMATE 1
71 #define DEFAULT_PROP_DEVICE "/dev/video0"
76 V4L2_STD_OBJECT_PROPS,
82 GST_IMPLEMENT_V4L2_PROBE_METHODS (GstV4l2SrcClass, gst_v4l2src);
83 GST_IMPLEMENT_V4L2_COLOR_BALANCE_METHODS (GstV4l2Src, gst_v4l2src);
84 GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Src, gst_v4l2src);
86 GST_IMPLEMENT_V4L2_XOVERLAY_METHODS (GstV4l2Src, gst_v4l2src);
88 GST_IMPLEMENT_V4L2_VIDORIENT_METHODS (GstV4l2Src, gst_v4l2src);
90 static void gst_v4l2src_uri_handler_init (gpointer g_iface,
93 #define gst_v4l2src_parent_class parent_class
94 G_DEFINE_TYPE_WITH_CODE (GstV4l2Src, gst_v4l2src, GST_TYPE_PUSH_SRC,
95 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_v4l2src_uri_handler_init);
96 G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER, gst_v4l2src_tuner_interface_init);
98 /* FIXME: does GstXOverlay for v4l2src make sense in a GStreamer context? */
99 G_IMPLEMENT_INTERFACE (GST_TYPE_X_OVERLAY,
100 gst_v4l2src_xoverlay_interface_init);
102 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
103 gst_v4l2src_color_balance_interface_init);
104 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
105 gst_v4l2src_video_orientation_interface_init);
106 G_IMPLEMENT_INTERFACE (GST_TYPE_PROPERTY_PROBE,
107 gst_v4l2src_property_probe_interface_init));
109 static void gst_v4l2src_dispose (GObject * object);
110 static void gst_v4l2src_finalize (GstV4l2Src * v4l2src);
112 /* element methods */
113 static GstStateChangeReturn gst_v4l2src_change_state (GstElement * element,
114 GstStateChange transition);
116 /* basesrc methods */
117 static gboolean gst_v4l2src_start (GstBaseSrc * src);
118 static gboolean gst_v4l2src_unlock (GstBaseSrc * src);
119 static gboolean gst_v4l2src_unlock_stop (GstBaseSrc * src);
120 static gboolean gst_v4l2src_stop (GstBaseSrc * src);
121 static gboolean gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps);
122 static GstCaps *gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter);
123 static gboolean gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query);
124 static GstFlowReturn gst_v4l2src_create (GstPushSrc * src, GstBuffer ** out);
125 static void gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps);
126 static gboolean gst_v4l2src_negotiate (GstBaseSrc * basesrc);
128 static void gst_v4l2src_set_property (GObject * object, guint prop_id,
129 const GValue * value, GParamSpec * pspec);
130 static void gst_v4l2src_get_property (GObject * object, guint prop_id,
131 GValue * value, GParamSpec * pspec);
134 gst_v4l2src_class_init (GstV4l2SrcClass * klass)
136 GObjectClass *gobject_class;
137 GstElementClass *element_class;
138 GstBaseSrcClass *basesrc_class;
139 GstPushSrcClass *pushsrc_class;
141 gobject_class = G_OBJECT_CLASS (klass);
142 element_class = GST_ELEMENT_CLASS (klass);
143 basesrc_class = GST_BASE_SRC_CLASS (klass);
144 pushsrc_class = GST_PUSH_SRC_CLASS (klass);
146 gobject_class->dispose = gst_v4l2src_dispose;
147 gobject_class->finalize = (GObjectFinalizeFunc) gst_v4l2src_finalize;
148 gobject_class->set_property = gst_v4l2src_set_property;
149 gobject_class->get_property = gst_v4l2src_get_property;
151 element_class->change_state = gst_v4l2src_change_state;
153 gst_v4l2_object_install_properties_helper (gobject_class,
154 DEFAULT_PROP_DEVICE);
155 g_object_class_install_property (gobject_class, PROP_QUEUE_SIZE,
156 g_param_spec_uint ("queue-size", "Queue size",
157 "Number of buffers to be enqueud in the driver in streaming mode",
158 GST_V4L2_MIN_BUFFERS, GST_V4L2_MAX_BUFFERS, PROP_DEF_QUEUE_SIZE,
159 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
160 g_object_class_install_property (gobject_class, PROP_ALWAYS_COPY,
161 g_param_spec_boolean ("always-copy", "Always Copy",
162 "If the buffer will or not be used directly from mmap",
163 PROP_DEF_ALWAYS_COPY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 * GstV4l2Src:decimate
167 * Only use every nth frame
171 g_object_class_install_property (gobject_class, PROP_DECIMATE,
172 g_param_spec_int ("decimate", "Decimate",
173 "Only use every nth frame", 1, G_MAXINT,
174 PROP_DEF_DECIMATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
176 gst_element_class_set_details_simple (element_class,
177 "Video (video4linux2) Source", "Source/Video",
178 "Reads frames from a Video4Linux2 device",
179 "Edgard Lima <edgard.lima@indt.org.br>, "
180 "Stefan Kost <ensonic@users.sf.net>");
182 gst_element_class_add_pad_template
184 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
185 gst_v4l2_object_get_all_caps ()));
187 basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_get_caps);
188 basesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_set_caps);
189 basesrc_class->start = GST_DEBUG_FUNCPTR (gst_v4l2src_start);
190 basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock);
191 basesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock_stop);
192 basesrc_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2src_stop);
193 basesrc_class->query = GST_DEBUG_FUNCPTR (gst_v4l2src_query);
194 basesrc_class->fixate = GST_DEBUG_FUNCPTR (gst_v4l2src_fixate);
195 basesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_v4l2src_negotiate);
197 pushsrc_class->create = GST_DEBUG_FUNCPTR (gst_v4l2src_create);
199 klass->v4l2_class_devices = NULL;
201 GST_DEBUG_CATEGORY_INIT (v4l2src_debug, "v4l2src", 0, "V4L2 source element");
205 gst_v4l2src_init (GstV4l2Src * v4l2src)
207 /* fixme: give an update_fps_function */
208 v4l2src->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2src),
209 V4L2_BUF_TYPE_VIDEO_CAPTURE, DEFAULT_PROP_DEVICE,
210 gst_v4l2_get_input, gst_v4l2_set_input, NULL);
212 /* number of buffers requested */
213 v4l2src->v4l2object->num_buffers = PROP_DEF_QUEUE_SIZE;
215 v4l2src->v4l2object->always_copy = PROP_DEF_ALWAYS_COPY;
216 v4l2src->decimate = PROP_DEF_DECIMATE;
218 gst_base_src_set_format (GST_BASE_SRC (v4l2src), GST_FORMAT_TIME);
219 gst_base_src_set_live (GST_BASE_SRC (v4l2src), TRUE);
223 gst_v4l2src_dispose (GObject * object)
225 GstV4l2Src *v4l2src = GST_V4L2SRC (object);
227 if (v4l2src->probed_caps) {
228 gst_caps_unref (v4l2src->probed_caps);
231 G_OBJECT_CLASS (parent_class)->dispose (object);
236 gst_v4l2src_finalize (GstV4l2Src * v4l2src)
238 gst_v4l2_object_destroy (v4l2src->v4l2object);
240 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (v4l2src));
245 gst_v4l2src_set_property (GObject * object,
246 guint prop_id, const GValue * value, GParamSpec * pspec)
248 GstV4l2Src *v4l2src = GST_V4L2SRC (object);
250 if (!gst_v4l2_object_set_property_helper (v4l2src->v4l2object,
251 prop_id, value, pspec)) {
253 case PROP_QUEUE_SIZE:
254 v4l2src->v4l2object->num_buffers = g_value_get_uint (value);
256 case PROP_ALWAYS_COPY:
257 v4l2src->v4l2object->always_copy = g_value_get_boolean (value);
260 v4l2src->decimate = g_value_get_int (value);
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
270 gst_v4l2src_get_property (GObject * object,
271 guint prop_id, GValue * value, GParamSpec * pspec)
273 GstV4l2Src *v4l2src = GST_V4L2SRC (object);
275 if (!gst_v4l2_object_get_property_helper (v4l2src->v4l2object,
276 prop_id, value, pspec)) {
278 case PROP_QUEUE_SIZE:
279 g_value_set_uint (value, v4l2src->v4l2object->num_buffers);
281 case PROP_ALWAYS_COPY:
282 g_value_set_boolean (value, v4l2src->v4l2object->always_copy);
285 g_value_set_int (value, v4l2src->decimate);
288 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
294 /* this function is a bit of a last resort */
296 gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps)
298 GstStructure *structure;
301 GST_DEBUG_OBJECT (basesrc, "fixating caps %" GST_PTR_FORMAT, caps);
303 for (i = 0; i < gst_caps_get_size (caps); ++i) {
306 structure = gst_caps_get_structure (caps, i);
308 /* We are fixating to a resonable 320x200 resolution
309 and the maximum framerate resolution for that size */
310 gst_structure_fixate_field_nearest_int (structure, "width", 320);
311 gst_structure_fixate_field_nearest_int (structure, "height", 200);
312 gst_structure_fixate_field_nearest_fraction (structure, "framerate",
315 v = gst_structure_get_value (structure, "format");
316 if (v && G_VALUE_TYPE (v) != G_TYPE_STRING) {
319 g_return_if_fail (G_VALUE_TYPE (v) == GST_TYPE_LIST);
321 format = g_value_get_string (gst_value_list_get_value (v, 0));
322 gst_structure_set (structure, "format", G_TYPE_STRING, format, NULL);
326 GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, caps);
331 gst_v4l2src_negotiate (GstBaseSrc * basesrc)
334 GstCaps *caps = NULL;
335 GstCaps *peercaps = NULL;
336 gboolean result = FALSE;
338 /* first see what is possible on our source pad */
339 thiscaps = gst_pad_get_caps (GST_BASE_SRC_PAD (basesrc), NULL);
340 GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
341 LOG_CAPS (basesrc, thiscaps);
343 /* nothing or anything is allowed, we're done */
344 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
347 /* get the peer caps */
348 peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc), thiscaps);
349 GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
350 LOG_CAPS (basesrc, peercaps);
351 if (peercaps && !gst_caps_is_any (peercaps)) {
352 GstCaps *icaps = NULL;
355 /* Prefer the first caps we are compatible with that the peer proposed */
356 for (i = 0; i < gst_caps_get_size (peercaps); i++) {
357 /* get intersection */
358 GstCaps *ipcaps = gst_caps_copy_nth (peercaps, i);
360 GST_DEBUG_OBJECT (basesrc, "peer: %" GST_PTR_FORMAT, ipcaps);
361 LOG_CAPS (basesrc, ipcaps);
363 icaps = gst_caps_intersect (thiscaps, ipcaps);
364 gst_caps_unref (ipcaps);
366 if (!gst_caps_is_empty (icaps))
369 gst_caps_unref (icaps);
373 GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, icaps);
374 LOG_CAPS (basesrc, icaps);
376 /* If there are multiple intersections pick the one with the smallest
377 * resolution strictly bigger then the first peer caps */
378 if (gst_caps_get_size (icaps) > 1) {
379 GstStructure *s = gst_caps_get_structure (peercaps, 0);
382 int width = G_MAXINT, height = G_MAXINT;
384 if (gst_structure_get_int (s, "width", &twidth)
385 && gst_structure_get_int (s, "height", &theight)) {
387 /* Walk the structure backwards to get the first entry of the
388 * smallest resolution bigger (or equal to) the preferred resolution)
390 for (i = gst_caps_get_size (icaps) - 1; i >= 0; i--) {
391 GstStructure *is = gst_caps_get_structure (icaps, i);
394 if (gst_structure_get_int (is, "width", &w)
395 && gst_structure_get_int (is, "height", &h)) {
396 if (w >= twidth && w <= width && h >= theight && h <= height) {
405 caps = gst_caps_copy_nth (icaps, best);
406 gst_caps_unref (icaps);
411 gst_caps_unref (thiscaps);
412 gst_caps_unref (peercaps);
414 /* no peer or peer have ANY caps, work with our own caps then */
418 caps = gst_caps_make_writable (caps);
419 gst_caps_truncate (caps);
422 if (!gst_caps_is_empty (caps)) {
423 gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
424 GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
425 LOG_CAPS (basesrc, caps);
427 if (gst_caps_is_any (caps)) {
428 /* hmm, still anything, so element can do anything and
429 * nego is not needed */
431 } else if (gst_caps_is_fixed (caps)) {
432 /* yay, fixed caps, use those then */
433 gst_pad_push_event (GST_BASE_SRC_PAD (basesrc),
434 gst_event_new_caps (caps));
435 result = gst_v4l2src_set_caps (basesrc, caps);
438 gst_caps_unref (caps);
444 GST_DEBUG_OBJECT (basesrc, "no negotiation needed");
446 gst_caps_unref (thiscaps);
452 gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter)
460 v4l2src = GST_V4L2SRC (src);
461 obj = v4l2src->v4l2object;
463 if (!GST_V4L2_IS_OPEN (obj)) {
466 gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
470 if (v4l2src->probed_caps)
471 return gst_caps_ref (v4l2src->probed_caps);
473 formats = gst_v4l2_object_get_format_list (obj);
475 ret = gst_caps_new_empty ();
477 for (walk = formats; walk; walk = walk->next) {
478 struct v4l2_fmtdesc *format;
479 GstStructure *template;
481 format = (struct v4l2_fmtdesc *) walk->data;
483 template = gst_v4l2_object_v4l2fourcc_to_structure (format->pixelformat);
489 gst_v4l2_object_probe_caps_for_format (obj,
490 format->pixelformat, template);
492 gst_caps_append (ret, tmp);
494 gst_structure_free (template);
496 GST_DEBUG_OBJECT (v4l2src, "unknown format %u", format->pixelformat);
500 v4l2src->probed_caps = gst_caps_ref (ret);
502 GST_INFO_OBJECT (v4l2src, "probed caps: %" GST_PTR_FORMAT, ret);
508 gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps)
513 v4l2src = GST_V4L2SRC (src);
514 obj = v4l2src->v4l2object;
516 /* make sure we stop capturing and dealloc buffers */
517 if (!gst_v4l2_object_stop (obj))
520 if (!gst_v4l2_object_set_format (obj, caps))
521 /* error already posted */
524 if (!gst_v4l2_object_start (obj))
527 /* now store the expected output size */
528 v4l2src->frame_byte_size = obj->size;
534 gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
538 gboolean res = FALSE;
540 src = GST_V4L2SRC (bsrc);
542 switch (GST_QUERY_TYPE (query)) {
543 case GST_QUERY_LATENCY:{
544 GstClockTime min_latency, max_latency;
545 guint32 fps_n, fps_d;
547 /* device must be open */
548 if (!GST_V4L2_IS_OPEN (src->v4l2object)) {
549 GST_WARNING_OBJECT (src,
550 "Can't give latency since device isn't open !");
554 fps_n = GST_V4L2_FPS_N (src->v4l2object);
555 fps_d = GST_V4L2_FPS_D (src->v4l2object);
557 /* we must have a framerate */
558 if (fps_n <= 0 || fps_d <= 0) {
559 GST_WARNING_OBJECT (src,
560 "Can't give latency since framerate isn't fixated !");
564 /* min latency is the time to capture one frame */
565 min_latency = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
567 /* max latency is total duration of the frame buffer */
568 max_latency = src->v4l2object->num_buffers * min_latency;
570 GST_DEBUG_OBJECT (bsrc,
571 "report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
572 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
574 /* we are always live, the min latency is 1 frame and the max latency is
575 * the complete buffer of frames. */
576 gst_query_set_latency (query, TRUE, min_latency, max_latency);
582 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
591 /* start and stop are not symmetric -- start will open the device, but not start
592 * capture. it's setcaps that will start capture, which is called via basesrc's
593 * negotiate method. stop will both stop capture and close the device.
596 gst_v4l2src_start (GstBaseSrc * src)
598 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
602 /* activate settings for first frame */
603 v4l2src->ctrl_time = 0;
604 gst_object_sync_values (G_OBJECT (src), v4l2src->ctrl_time);
610 gst_v4l2src_unlock (GstBaseSrc * src)
612 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
614 GST_LOG_OBJECT (src, "Flushing");
615 gst_poll_set_flushing (v4l2src->v4l2object->poll, TRUE);
621 gst_v4l2src_unlock_stop (GstBaseSrc * src)
623 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
625 GST_LOG_OBJECT (src, "No longer flushing");
626 gst_poll_set_flushing (v4l2src->v4l2object->poll, FALSE);
632 gst_v4l2src_stop (GstBaseSrc * src)
634 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
635 GstV4l2Object *obj = v4l2src->v4l2object;
637 if (GST_V4L2_IS_ACTIVE (obj)) {
638 if (!gst_v4l2_object_stop (obj))
644 static GstStateChangeReturn
645 gst_v4l2src_change_state (GstElement * element, GstStateChange transition)
647 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
648 GstV4l2Src *v4l2src = GST_V4L2SRC (element);
649 GstV4l2Object *obj = v4l2src->v4l2object;
651 switch (transition) {
652 case GST_STATE_CHANGE_NULL_TO_READY:
653 /* open the device */
654 if (!gst_v4l2_object_open (obj))
655 return GST_STATE_CHANGE_FAILURE;
661 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
663 switch (transition) {
664 case GST_STATE_CHANGE_READY_TO_NULL:
665 /* close the device */
666 if (!gst_v4l2_object_close (obj))
667 return GST_STATE_CHANGE_FAILURE;
669 if (v4l2src->probed_caps) {
670 gst_caps_unref (v4l2src->probed_caps);
671 v4l2src->probed_caps = NULL;
682 gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
684 GstV4l2Src *v4l2src = GST_V4L2SRC (src);
685 GstV4l2Object *obj = v4l2src->v4l2object;
689 /* decimate, just capture and throw away frames */
690 for (i = 0; i < v4l2src->decimate - 1; i++) {
691 ret = gst_v4l2_object_get_buffer (obj, buf);
692 if (ret != GST_FLOW_OK) {
695 gst_buffer_unref (*buf);
698 ret = gst_v4l2_object_get_buffer (obj, buf);
700 /* set buffer metadata */
701 if (G_LIKELY (ret == GST_FLOW_OK && *buf)) {
703 GstClockTime timestamp, duration;
705 GST_BUFFER_OFFSET (*buf) = v4l2src->offset++;
706 GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset;
708 /* timestamps, LOCK to get clock and base time. */
709 /* FIXME: element clock and base_time is rarely changing */
710 GST_OBJECT_LOCK (v4l2src);
711 if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
712 /* we have a clock, get base time and ref clock */
713 timestamp = GST_ELEMENT (v4l2src)->base_time;
714 gst_object_ref (clock);
716 /* no clock, can't set timestamps */
717 timestamp = GST_CLOCK_TIME_NONE;
719 GST_OBJECT_UNLOCK (v4l2src);
721 duration = obj->duration;
723 if (G_LIKELY (clock)) {
724 /* the time now is the time of the clock minus the base time */
725 timestamp = gst_clock_get_time (clock) - timestamp;
726 gst_object_unref (clock);
728 /* if we have a framerate adjust timestamp for frame latency */
729 if (GST_CLOCK_TIME_IS_VALID (duration)) {
730 if (timestamp > duration)
731 timestamp -= duration;
737 /* activate settings for next frame */
738 if (GST_CLOCK_TIME_IS_VALID (duration)) {
739 v4l2src->ctrl_time += duration;
741 /* this is not very good (as it should be the next timestamp),
742 * still good enough for linear fades (as long as it is not -1)
744 v4l2src->ctrl_time = timestamp;
746 gst_object_sync_values (G_OBJECT (src), v4l2src->ctrl_time);
747 GST_INFO_OBJECT (src, "sync to %" GST_TIME_FORMAT,
748 GST_TIME_ARGS (v4l2src->ctrl_time));
750 /* FIXME: use the timestamp from the buffer itself! */
751 GST_BUFFER_TIMESTAMP (*buf) = timestamp;
752 GST_BUFFER_DURATION (*buf) = duration;
758 /* GstURIHandler interface */
760 gst_v4l2src_uri_get_type (GType type)
766 gst_v4l2src_uri_get_protocols (GType type)
768 static gchar *protocols[] = { (char *) "v4l2", NULL };
774 gst_v4l2src_uri_get_uri (GstURIHandler * handler)
776 GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
778 if (v4l2src->v4l2object->videodev != NULL) {
781 /* need to return a const string, but also don't want to leak the generated
782 * string, so just intern it - there's a limited number of video devices
784 g_snprintf (uri, sizeof (uri), "v4l2://%s", v4l2src->v4l2object->videodev);
785 return g_intern_string (uri);
792 gst_v4l2src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
794 GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
795 const gchar *device = DEFAULT_PROP_DEVICE;
797 if (strcmp (uri, "v4l2://") != 0) {
800 g_object_set (v4l2src, "device", device, NULL);
807 gst_v4l2src_uri_handler_init (gpointer g_iface, gpointer iface_data)
809 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
811 iface->get_type = gst_v4l2src_uri_get_type;
812 iface->get_protocols = gst_v4l2src_uri_get_protocols;
813 iface->get_uri = gst_v4l2src_uri_get_uri;
814 iface->set_uri = gst_v4l2src_uri_set_uri;