3 * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@indt.org.br>
6 * v4l2_calls.c - generic V4L2 calls handling
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.
28 #include <sys/types.h>
31 #include <sys/ioctl.h>
37 /* Needed on older Solaris Nevada builds (72 at least) */
39 #include <sys/ioccom.h>
41 #include "v4l2_calls.h"
42 #include "gstv4l2tuner.h"
44 #include "gstv4l2xoverlay.h"
46 #include "gstv4l2colorbalance.h"
48 #include "gstv4l2src.h"
50 #ifdef HAVE_EXPERIMENTAL
51 #include "gstv4l2sink.h"
54 #include "gst/gst-i18n-plugin.h"
56 /* Those are ioctl calls */
57 #ifndef V4L2_CID_HCENTER
58 #define V4L2_CID_HCENTER V4L2_CID_HCENTER_DEPRECATED
60 #ifndef V4L2_CID_VCENTER
61 #define V4L2_CID_VCENTER V4L2_CID_VCENTER_DEPRECATED
64 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
65 #define GST_CAT_DEFAULT v4l2_debug
67 /******************************************************
68 * gst_v4l2_get_capabilities():
69 * get the device's capturing capabilities
70 * return value: TRUE on success, FALSE on error
71 ******************************************************/
73 gst_v4l2_get_capabilities (GstV4l2Object * v4l2object)
77 e = v4l2object->element;
79 GST_DEBUG_OBJECT (e, "getting capabilities");
81 if (!GST_V4L2_IS_OPEN (v4l2object))
84 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYCAP, &v4l2object->vcap) < 0)
87 GST_LOG_OBJECT (e, "driver: '%s'", v4l2object->vcap.driver);
88 GST_LOG_OBJECT (e, "card: '%s'", v4l2object->vcap.card);
89 GST_LOG_OBJECT (e, "bus_info: '%s'", v4l2object->vcap.bus_info);
90 GST_LOG_OBJECT (e, "version: %08x", v4l2object->vcap.version);
91 GST_LOG_OBJECT (e, "capabilites: %08x", v4l2object->vcap.capabilities);
98 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
99 (_("Error getting capabilities for device '%s': "
100 "It isn't a v4l2 driver. Check if it is a v4l1 driver."),
101 v4l2object->videodev), GST_ERROR_SYSTEM);
107 /******************************************************
108 * gst_v4l2_empty_lists() and gst_v4l2_fill_lists():
109 * fill/empty the lists of enumerations
110 * return value: TRUE on success, FALSE on error
111 ******************************************************/
113 gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
119 e = v4l2object->element;
121 GST_DEBUG_OBJECT (e, "getting enumerations");
122 GST_V4L2_CHECK_OPEN (v4l2object);
124 GST_DEBUG_OBJECT (e, " channels");
125 /* and now, the channels */
127 struct v4l2_input input;
128 GstV4l2TunerChannel *v4l2channel;
129 GstTunerChannel *channel;
131 memset (&input, 0, sizeof (input));
134 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMINPUT, &input) < 0) {
136 break; /* end of enumeration */
138 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
139 (_("Failed to query attributes of input %d in device %s"),
140 n, v4l2object->videodev),
141 ("Failed to get %d in input enumeration for %s. (%d - %s)",
142 n, v4l2object->videodev, errno, strerror (errno)));
147 GST_LOG_OBJECT (e, " index: %d", input.index);
148 GST_LOG_OBJECT (e, " name: '%s'", input.name);
149 GST_LOG_OBJECT (e, " type: %08x", input.type);
150 GST_LOG_OBJECT (e, " audioset: %08x", input.audioset);
151 GST_LOG_OBJECT (e, " std: %016x", (guint) input.std);
152 GST_LOG_OBJECT (e, " status: %08x", input.status);
154 v4l2channel = g_object_new (GST_TYPE_V4L2_TUNER_CHANNEL, NULL);
155 channel = GST_TUNER_CHANNEL (v4l2channel);
156 channel->label = g_strdup ((const gchar *) input.name);
157 channel->flags = GST_TUNER_CHANNEL_INPUT;
158 v4l2channel->index = n;
160 if (input.type == V4L2_INPUT_TYPE_TUNER) {
161 struct v4l2_tuner vtun;
163 v4l2channel->tuner = input.tuner;
164 channel->flags |= GST_TUNER_CHANNEL_FREQUENCY;
166 vtun.index = input.tuner;
167 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &vtun) < 0) {
168 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
169 (_("Failed to get setting of tuner %d on device '%s'."),
170 input.tuner, v4l2object->videodev), GST_ERROR_SYSTEM);
171 g_object_unref (G_OBJECT (channel));
175 channel->freq_multiplicator =
176 62.5 * ((vtun.capability & V4L2_TUNER_CAP_LOW) ? 1 : 1000);
177 channel->min_frequency = vtun.rangelow * channel->freq_multiplicator;
178 channel->max_frequency = vtun.rangehigh * channel->freq_multiplicator;
179 channel->min_signal = 0;
180 channel->max_signal = 0xffff;
182 if (input.audioset) {
183 /* we take the first. We don't care for
184 * the others for now */
185 while (!(input.audioset & (1 << v4l2channel->audio)))
186 v4l2channel->audio++;
187 channel->flags |= GST_TUNER_CHANNEL_AUDIO;
190 v4l2object->channels =
191 g_list_prepend (v4l2object->channels, (gpointer) channel);
193 v4l2object->channels = g_list_reverse (v4l2object->channels);
195 GST_DEBUG_OBJECT (e, " norms");
198 struct v4l2_standard standard = { 0, };
199 GstV4l2TunerNorm *v4l2norm;
203 /* fill in defaults */
204 standard.frameperiod.numerator = 1;
205 standard.frameperiod.denominator = 0;
208 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMSTD, &standard) < 0) {
209 if (errno == EINVAL || errno == ENOTTY)
210 break; /* end of enumeration */
212 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
213 (_("Failed to query norm on device '%s'."),
214 v4l2object->videodev),
215 ("Failed to get attributes for norm %d on devide '%s'. (%d - %s)",
216 n, v4l2object->videodev, errno, strerror (errno)));
221 GST_DEBUG_OBJECT (e, " '%s', fps: %d / %d",
222 standard.name, standard.frameperiod.denominator,
223 standard.frameperiod.numerator);
225 v4l2norm = g_object_new (GST_TYPE_V4L2_TUNER_NORM, NULL);
226 norm = GST_TUNER_NORM (v4l2norm);
227 norm->label = g_strdup ((const gchar *) standard.name);
228 gst_value_set_fraction (&norm->framerate,
229 standard.frameperiod.denominator, standard.frameperiod.numerator);
230 v4l2norm->index = standard.id;
232 v4l2object->norms = g_list_prepend (v4l2object->norms, (gpointer) norm);
234 v4l2object->norms = g_list_reverse (v4l2object->norms);
236 GST_DEBUG_OBJECT (e, " controls+menus");
238 /* and lastly, controls+menus (if appropriate) */
239 for (n = V4L2_CID_BASE;; n++) {
240 struct v4l2_queryctrl control = { 0, };
241 GstV4l2ColorBalanceChannel *v4l2channel;
242 GstColorBalanceChannel *channel;
244 /* when we reached the last official CID, continue with private CIDs */
245 if (n == V4L2_CID_LASTP1) {
246 GST_DEBUG_OBJECT (e, "checking private CIDs");
247 n = V4L2_CID_PRIVATE_BASE;
249 GST_DEBUG_OBJECT (e, "checking control %08x", n);
252 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYCTRL, &control) < 0) {
253 if (errno == EINVAL) {
254 if (n < V4L2_CID_PRIVATE_BASE) {
255 GST_DEBUG_OBJECT (e, "skipping control %08x", n);
256 /* continue so that we also check private controls */
259 GST_DEBUG_OBJECT (e, "controls finished");
263 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
264 (_("Failed getting controls attributes on device '%s'."),
265 v4l2object->videodev),
266 ("Failed querying control %d on device '%s'. (%d - %s)",
267 n, v4l2object->videodev, errno, strerror (errno)));
271 if (control.flags & V4L2_CTRL_FLAG_DISABLED) {
272 GST_DEBUG_OBJECT (e, "skipping disabled control");
277 case V4L2_CID_BRIGHTNESS:
278 case V4L2_CID_CONTRAST:
279 case V4L2_CID_SATURATION:
281 case V4L2_CID_BLACK_LEVEL:
282 case V4L2_CID_AUTO_WHITE_BALANCE:
283 case V4L2_CID_DO_WHITE_BALANCE:
284 case V4L2_CID_RED_BALANCE:
285 case V4L2_CID_BLUE_BALANCE:
287 case V4L2_CID_EXPOSURE:
288 case V4L2_CID_AUTOGAIN:
290 #ifdef V4L2_CID_SHARPNESS
291 case V4L2_CID_SHARPNESS:
293 /* we only handle these for now (why?) */
297 case V4L2_CID_HCENTER:
298 case V4L2_CID_VCENTER:
299 #ifdef V4L2_CID_PAN_RESET
300 case V4L2_CID_PAN_RESET:
302 #ifdef V4L2_CID_TILT_RESET
303 case V4L2_CID_TILT_RESET:
305 /* not handled here, handled by VideoOrientation interface */
308 case V4L2_CID_AUDIO_VOLUME:
309 case V4L2_CID_AUDIO_BALANCE:
310 case V4L2_CID_AUDIO_BASS:
311 case V4L2_CID_AUDIO_TREBLE:
312 case V4L2_CID_AUDIO_MUTE:
313 case V4L2_CID_AUDIO_LOUDNESS:
314 /* FIXME: We should implement GstMixer interface */
318 "ControlID %s (%x) unhandled, FIXME", control.name, n);
325 GST_DEBUG_OBJECT (e, "Adding ControlID %s (%x)", control.name, n);
326 v4l2channel = g_object_new (GST_TYPE_V4L2_COLOR_BALANCE_CHANNEL, NULL);
327 channel = GST_COLOR_BALANCE_CHANNEL (v4l2channel);
328 channel->label = g_strdup ((const gchar *) control.name);
332 /* FIXME: it will be need just when handling private controls
333 *(currently none of base controls are of this type) */
334 if (control.type == V4L2_CTRL_TYPE_MENU) {
335 struct v4l2_querymenu menu, *mptr;
342 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYMENU, &menu) < 0) {
344 break; /* end of enumeration */
346 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
347 (_("Failed getting controls attributes on device '%s'."),
348 v4l2object->videodev),
349 ("Failed to get %d in menu enumeration for %s. (%d - %s)",
350 n, v4l2object->videodev, errno, strerror (errno)));
354 mptr = g_malloc (sizeof (menu));
355 memcpy (mptr, &menu, sizeof (menu));
356 menus = g_list_append (menus, mptr);
359 v4l2object->menus = g_list_append (v4l2object->menus, menus);
362 switch (control.type) {
363 case V4L2_CTRL_TYPE_INTEGER:
364 channel->min_value = control.minimum;
365 channel->max_value = control.maximum;
367 case V4L2_CTRL_TYPE_BOOLEAN:
368 channel->min_value = FALSE;
369 channel->max_value = TRUE;
372 /* FIXME we should find out how to handle V4L2_CTRL_TYPE_BUTTON.
373 BUTTON controls like V4L2_CID_DO_WHITE_BALANCE can just be set (1) or
374 unset (0), but can't be queried */
376 "Control with non supported type %s (%x), type=%d",
377 control.name, n, control.type);
378 channel->min_value = channel->max_value = 0;
383 g_list_prepend (v4l2object->colors, (gpointer) channel);
385 v4l2object->colors = g_list_reverse (v4l2object->colors);
387 GST_DEBUG_OBJECT (e, "done");
393 gst_v4l2_empty_lists (GstV4l2Object * v4l2object)
395 GST_DEBUG_OBJECT (v4l2object->element, "deleting enumerations");
397 g_list_foreach (v4l2object->channels, (GFunc) g_object_unref, NULL);
398 g_list_free (v4l2object->channels);
399 v4l2object->channels = NULL;
401 g_list_foreach (v4l2object->norms, (GFunc) g_object_unref, NULL);
402 g_list_free (v4l2object->norms);
403 v4l2object->norms = NULL;
405 g_list_foreach (v4l2object->colors, (GFunc) g_object_unref, NULL);
406 g_list_free (v4l2object->colors);
407 v4l2object->colors = NULL;
410 /******************************************************
412 * open the video device (v4l2object->videodev)
413 * return value: TRUE on success, FALSE on error
414 ******************************************************/
416 gst_v4l2_open (GstV4l2Object * v4l2object)
420 GstPollFD pollfd = GST_POLL_FD_INIT;
422 GST_DEBUG_OBJECT (v4l2object->element, "Trying to open device %s",
423 v4l2object->videodev);
425 GST_V4L2_CHECK_NOT_OPEN (v4l2object);
426 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
428 /* be sure we have a device */
429 if (!v4l2object->videodev)
430 v4l2object->videodev = g_strdup ("/dev/video");
432 /* check if it is a device */
433 if (stat (v4l2object->videodev, &st) == -1)
436 if (!S_ISCHR (st.st_mode))
439 /* open the device */
440 v4l2object->video_fd =
441 open (v4l2object->videodev, O_RDWR /* | O_NONBLOCK */ );
443 if (!GST_V4L2_IS_OPEN (v4l2object))
446 libv4l2_fd = v4l2_fd_open (v4l2object->video_fd,
447 V4L2_ENABLE_ENUM_FMT_EMULATION);
448 /* Note the v4l2_xxx functions are designed so that if they get passed an
449 unknown fd, the will behave exactly as their regular xxx counterparts, so
450 if v4l2_fd_open fails, we continue as normal (missing the libv4l2 custom
451 cam format to normal formats conversion). Chances are big we will still
452 fail then though, as normally v4l2_fd_open only fails if the device is not
454 if (libv4l2_fd != -1)
455 v4l2object->video_fd = libv4l2_fd;
457 v4l2object->can_poll_device = TRUE;
459 /* get capabilities, error will be posted */
460 if (!gst_v4l2_get_capabilities (v4l2object))
463 /* do we need to be a capture device? */
464 if (GST_IS_V4L2SRC (v4l2object->element) &&
465 !(v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
468 #ifdef HAVE_EXPERIMENTAL
469 if (GST_IS_V4L2SINK (v4l2object->element) &&
470 !(v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_OUTPUT))
474 /* create enumerations, posts errors. */
475 if (!gst_v4l2_fill_lists (v4l2object))
478 GST_INFO_OBJECT (v4l2object->element,
479 "Opened device '%s' (%s) successfully",
480 v4l2object->vcap.card, v4l2object->videodev);
482 pollfd.fd = v4l2object->video_fd;
483 gst_poll_add_fd (v4l2object->poll, &pollfd);
484 gst_poll_fd_ctl_read (v4l2object->poll, &pollfd, TRUE);
491 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
492 (_("Cannot identify device '%s'."), v4l2object->videodev),
498 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
499 (_("This isn't a device '%s'."), v4l2object->videodev),
505 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ_WRITE,
506 (_("Could not open device '%s' for reading and writing."),
507 v4l2object->videodev), GST_ERROR_SYSTEM);
512 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
513 (_("Device '%s' is not a capture device."),
514 v4l2object->videodev),
515 ("Capabilities: 0x%x", v4l2object->vcap.capabilities));
518 #ifdef HAVE_EXPERIMENTAL
521 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
522 (_("Device '%s' is not a output device."),
523 v4l2object->videodev),
524 ("Capabilities: 0x%x", v4l2object->vcap.capabilities));
530 if (GST_V4L2_IS_OPEN (v4l2object)) {
532 v4l2_close (v4l2object->video_fd);
533 v4l2object->video_fd = -1;
536 gst_v4l2_empty_lists (v4l2object);
543 /******************************************************
545 * close the video device (v4l2object->video_fd)
546 * return value: TRUE on success, FALSE on error
547 ******************************************************/
549 gst_v4l2_close (GstV4l2Object * v4l2object)
551 GstPollFD pollfd = GST_POLL_FD_INIT;
552 GST_DEBUG_OBJECT (v4l2object->element, "Trying to close %s",
553 v4l2object->videodev);
555 GST_V4L2_CHECK_OPEN (v4l2object);
556 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
559 v4l2_close (v4l2object->video_fd);
560 pollfd.fd = v4l2object->video_fd;
561 gst_poll_remove_fd (v4l2object->poll, &pollfd);
562 v4l2object->video_fd = -1;
565 gst_v4l2_empty_lists (v4l2object);
571 /******************************************************
572 * gst_v4l2_get_norm()
573 * Get the norm of the current device
574 * return value: TRUE on success, FALSE on error
575 ******************************************************/
577 gst_v4l2_get_norm (GstV4l2Object * v4l2object, v4l2_std_id * norm)
579 GST_DEBUG_OBJECT (v4l2object->element, "getting norm");
581 if (!GST_V4L2_IS_OPEN (v4l2object))
584 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_STD, norm) < 0)
592 GST_DEBUG ("Failed to get the current norm for device %s",
593 v4l2object->videodev);
599 /******************************************************
600 * gst_v4l2_set_norm()
601 * Set the norm of the current device
602 * return value: TRUE on success, FALSE on error
603 ******************************************************/
605 gst_v4l2_set_norm (GstV4l2Object * v4l2object, v4l2_std_id norm)
607 GST_DEBUG_OBJECT (v4l2object->element, "trying to set norm to "
608 "%" G_GINT64_MODIFIER "x", (guint64) norm);
610 if (!GST_V4L2_IS_OPEN (v4l2object))
613 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_STD, &norm) < 0)
621 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
622 (_("Failed to set norm for device '%s'."),
623 v4l2object->videodev), GST_ERROR_SYSTEM);
628 /******************************************************
629 * gst_v4l2_get_frequency():
630 * get the current frequency
631 * return value: TRUE on success, FALSE on error
632 ******************************************************/
634 gst_v4l2_get_frequency (GstV4l2Object * v4l2object,
635 gint tunernum, gulong * frequency)
637 struct v4l2_frequency freq = { 0, };
639 GstTunerChannel *channel;
641 GST_DEBUG_OBJECT (v4l2object->element, "getting current tuner frequency");
643 if (!GST_V4L2_IS_OPEN (v4l2object))
646 channel = gst_tuner_get_channel (GST_TUNER (v4l2object->element));
648 freq.tuner = tunernum;
649 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq) < 0)
652 *frequency = freq.frequency * channel->freq_multiplicator;
659 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
660 (_("Failed to get current tuner frequency for device '%s'."),
661 v4l2object->videodev), GST_ERROR_SYSTEM);
667 /******************************************************
668 * gst_v4l2_set_frequency():
670 * return value: TRUE on success, FALSE on error
671 ******************************************************/
673 gst_v4l2_set_frequency (GstV4l2Object * v4l2object,
674 gint tunernum, gulong frequency)
676 struct v4l2_frequency freq = { 0, };
678 GstTunerChannel *channel;
680 GST_DEBUG_OBJECT (v4l2object->element,
681 "setting current tuner frequency to %lu", frequency);
683 if (!GST_V4L2_IS_OPEN (v4l2object))
686 channel = gst_tuner_get_channel (GST_TUNER (v4l2object->element));
688 freq.tuner = tunernum;
689 /* fill in type - ignore error */
690 v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq);
691 freq.frequency = frequency / channel->freq_multiplicator;
693 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_FREQUENCY, &freq) < 0)
701 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
702 (_("Failed to set current tuner frequency for device '%s' to %lu Hz."),
703 v4l2object->videodev, frequency), GST_ERROR_SYSTEM);
708 /******************************************************
709 * gst_v4l2_signal_strength():
710 * get the strength of the signal on the current input
711 * return value: TRUE on success, FALSE on error
712 ******************************************************/
714 gst_v4l2_signal_strength (GstV4l2Object * v4l2object,
715 gint tunernum, gulong * signal_strength)
717 struct v4l2_tuner tuner = { 0, };
719 GST_DEBUG_OBJECT (v4l2object->element, "trying to get signal strength");
721 if (!GST_V4L2_IS_OPEN (v4l2object))
724 tuner.index = tunernum;
725 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &tuner) < 0)
728 *signal_strength = tuner.signal;
735 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
736 (_("Failed to get signal strength for device '%s'."),
737 v4l2object->videodev), GST_ERROR_SYSTEM);
742 /******************************************************
743 * gst_v4l2_get_attribute():
744 * try to get the value of one specific attribute
745 * return value: TRUE on success, FALSE on error
746 ******************************************************/
748 gst_v4l2_get_attribute (GstV4l2Object * v4l2object,
749 int attribute_num, int *value)
751 struct v4l2_control control = { 0, };
753 GST_DEBUG_OBJECT (v4l2object->element, "getting value of attribute %d",
756 if (!GST_V4L2_IS_OPEN (v4l2object))
759 control.id = attribute_num;
761 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) < 0)
764 *value = control.value;
771 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
772 (_("Failed to get value for control %d on device '%s'."),
773 attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
779 /******************************************************
780 * gst_v4l2_set_attribute():
781 * try to set the value of one specific attribute
782 * return value: TRUE on success, FALSE on error
783 ******************************************************/
785 gst_v4l2_set_attribute (GstV4l2Object * v4l2object,
786 int attribute_num, const int value)
788 struct v4l2_control control = { 0, };
790 GST_DEBUG_OBJECT (v4l2object->element, "setting value of attribute %d to %d",
791 attribute_num, value);
793 if (!GST_V4L2_IS_OPEN (v4l2object))
796 control.id = attribute_num;
797 control.value = value;
798 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_CTRL, &control) < 0)
806 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
807 (_("Failed to set value %d for control %d on device '%s'."),
808 value, attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
814 gst_v4l2_get_input (GstV4l2Object * v4l2object, gint * input)
818 GST_DEBUG_OBJECT (v4l2object->element, "trying to get input");
820 if (!GST_V4L2_IS_OPEN (v4l2object))
823 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_INPUT, &n) < 0)
828 GST_DEBUG_OBJECT (v4l2object->element, "input: %d", n);
834 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
835 /* only give a warning message if driver actually claims to have tuner
838 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
839 (_("Failed to get current input on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM);
845 gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input)
847 GST_DEBUG_OBJECT (v4l2object->element, "trying to set input to %d", input);
849 if (!GST_V4L2_IS_OPEN (v4l2object))
852 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_INPUT, &input) < 0)
859 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
860 /* only give a warning message if driver actually claims to have tuner
863 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
864 (_("Failed to set input %d on device %s."),
865 input, v4l2object->videodev), GST_ERROR_SYSTEM);
871 gst_v4l2_get_output (GstV4l2Object * v4l2object, gint * output)
875 GST_DEBUG_OBJECT (v4l2object->element, "trying to get output");
877 if (!GST_V4L2_IS_OPEN (v4l2object))
880 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_OUTPUT, &n) < 0)
885 GST_DEBUG_OBJECT (v4l2object->element, "output: %d", n);
891 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
892 /* only give a warning message if driver actually claims to have tuner
895 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
896 (_("Failed to get current output on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM);
902 gst_v4l2_set_output (GstV4l2Object * v4l2object, gint output)
904 GST_DEBUG_OBJECT (v4l2object->element, "trying to set output to %d", output);
906 if (!GST_V4L2_IS_OPEN (v4l2object))
909 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_OUTPUT, &output) < 0)
916 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
917 /* only give a warning message if driver actually claims to have tuner
920 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
921 (_("Failed to set output %d on device %s."),
922 output, v4l2object->videodev), GST_ERROR_SYSTEM);