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"
49 #include "gstv4l2sink.h"
51 #include "gst/gst-i18n-plugin.h"
53 /* Those are ioctl calls */
54 #ifndef V4L2_CID_HCENTER
55 #define V4L2_CID_HCENTER V4L2_CID_HCENTER_DEPRECATED
57 #ifndef V4L2_CID_VCENTER
58 #define V4L2_CID_VCENTER V4L2_CID_VCENTER_DEPRECATED
61 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
62 #define GST_CAT_DEFAULT v4l2_debug
64 /******************************************************
65 * gst_v4l2_get_capabilities():
66 * get the device's capturing capabilities
67 * return value: TRUE on success, FALSE on error
68 ******************************************************/
70 gst_v4l2_get_capabilities (GstV4l2Object * v4l2object)
74 e = v4l2object->element;
76 GST_DEBUG_OBJECT (e, "getting capabilities");
78 if (!GST_V4L2_IS_OPEN (v4l2object))
81 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYCAP, &v4l2object->vcap) < 0)
84 GST_LOG_OBJECT (e, "driver: '%s'", v4l2object->vcap.driver);
85 GST_LOG_OBJECT (e, "card: '%s'", v4l2object->vcap.card);
86 GST_LOG_OBJECT (e, "bus_info: '%s'", v4l2object->vcap.bus_info);
87 GST_LOG_OBJECT (e, "version: %08x", v4l2object->vcap.version);
88 GST_LOG_OBJECT (e, "capabilites: %08x", v4l2object->vcap.capabilities);
95 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
96 (_("Error getting capabilities for device '%s': "
97 "It isn't a v4l2 driver. Check if it is a v4l1 driver."),
98 v4l2object->videodev), GST_ERROR_SYSTEM);
104 /******************************************************
105 * gst_v4l2_empty_lists() and gst_v4l2_fill_lists():
106 * fill/empty the lists of enumerations
107 * return value: TRUE on success, FALSE on error
108 ******************************************************/
110 gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
116 e = v4l2object->element;
118 GST_DEBUG_OBJECT (e, "getting enumerations");
119 GST_V4L2_CHECK_OPEN (v4l2object);
121 GST_DEBUG_OBJECT (e, " channels");
122 /* and now, the channels */
124 struct v4l2_input input;
125 GstV4l2TunerChannel *v4l2channel;
126 GstTunerChannel *channel;
128 memset (&input, 0, sizeof (input));
131 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMINPUT, &input) < 0) {
133 break; /* end of enumeration */
135 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
136 (_("Failed to query attributes of input %d in device %s"),
137 n, v4l2object->videodev),
138 ("Failed to get %d in input enumeration for %s. (%d - %s)",
139 n, v4l2object->videodev, errno, strerror (errno)));
144 GST_LOG_OBJECT (e, " index: %d", input.index);
145 GST_LOG_OBJECT (e, " name: '%s'", input.name);
146 GST_LOG_OBJECT (e, " type: %08x", input.type);
147 GST_LOG_OBJECT (e, " audioset: %08x", input.audioset);
148 GST_LOG_OBJECT (e, " std: %016x", (guint) input.std);
149 GST_LOG_OBJECT (e, " status: %08x", input.status);
151 v4l2channel = g_object_new (GST_TYPE_V4L2_TUNER_CHANNEL, NULL);
152 channel = GST_TUNER_CHANNEL (v4l2channel);
153 channel->label = g_strdup ((const gchar *) input.name);
154 channel->flags = GST_TUNER_CHANNEL_INPUT;
155 v4l2channel->index = n;
157 if (input.type == V4L2_INPUT_TYPE_TUNER) {
158 struct v4l2_tuner vtun;
160 v4l2channel->tuner = input.tuner;
161 channel->flags |= GST_TUNER_CHANNEL_FREQUENCY;
163 vtun.index = input.tuner;
164 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &vtun) < 0) {
165 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
166 (_("Failed to get setting of tuner %d on device '%s'."),
167 input.tuner, v4l2object->videodev), GST_ERROR_SYSTEM);
168 g_object_unref (G_OBJECT (channel));
172 channel->freq_multiplicator =
173 62.5 * ((vtun.capability & V4L2_TUNER_CAP_LOW) ? 1 : 1000);
174 channel->min_frequency = vtun.rangelow * channel->freq_multiplicator;
175 channel->max_frequency = vtun.rangehigh * channel->freq_multiplicator;
176 channel->min_signal = 0;
177 channel->max_signal = 0xffff;
179 if (input.audioset) {
180 /* we take the first. We don't care for
181 * the others for now */
182 while (!(input.audioset & (1 << v4l2channel->audio)))
183 v4l2channel->audio++;
184 channel->flags |= GST_TUNER_CHANNEL_AUDIO;
187 v4l2object->channels =
188 g_list_prepend (v4l2object->channels, (gpointer) channel);
190 v4l2object->channels = g_list_reverse (v4l2object->channels);
192 GST_DEBUG_OBJECT (e, " norms");
195 struct v4l2_standard standard = { 0, };
196 GstV4l2TunerNorm *v4l2norm;
200 /* fill in defaults */
201 standard.frameperiod.numerator = 1;
202 standard.frameperiod.denominator = 0;
205 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMSTD, &standard) < 0) {
206 if (errno == EINVAL || errno == ENOTTY)
207 break; /* end of enumeration */
209 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
210 (_("Failed to query norm on device '%s'."),
211 v4l2object->videodev),
212 ("Failed to get attributes for norm %d on devide '%s'. (%d - %s)",
213 n, v4l2object->videodev, errno, strerror (errno)));
218 GST_DEBUG_OBJECT (e, " '%s', fps: %d / %d",
219 standard.name, standard.frameperiod.denominator,
220 standard.frameperiod.numerator);
222 v4l2norm = g_object_new (GST_TYPE_V4L2_TUNER_NORM, NULL);
223 norm = GST_TUNER_NORM (v4l2norm);
224 norm->label = g_strdup ((const gchar *) standard.name);
225 gst_value_set_fraction (&norm->framerate,
226 standard.frameperiod.denominator, standard.frameperiod.numerator);
227 v4l2norm->index = standard.id;
229 GST_DEBUG_OBJECT (v4l2object->element, "index=%08x, label=%s",
230 (unsigned int) v4l2norm->index, norm->label);
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 || errno == ENOTTY || errno == EIO) {
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_WARNING_OBJECT (e, "Failed querying control %d on device '%s'. "
264 "(%d - %s)", n, v4l2object->videodev, errno, strerror (errno));
268 if (control.flags & V4L2_CTRL_FLAG_DISABLED) {
269 GST_DEBUG_OBJECT (e, "skipping disabled control");
274 case V4L2_CID_BRIGHTNESS:
275 case V4L2_CID_CONTRAST:
276 case V4L2_CID_SATURATION:
278 case V4L2_CID_BLACK_LEVEL:
279 case V4L2_CID_AUTO_WHITE_BALANCE:
280 case V4L2_CID_DO_WHITE_BALANCE:
281 case V4L2_CID_RED_BALANCE:
282 case V4L2_CID_BLUE_BALANCE:
284 case V4L2_CID_EXPOSURE:
285 case V4L2_CID_AUTOGAIN:
287 #ifdef V4L2_CID_SHARPNESS
288 case V4L2_CID_SHARPNESS:
290 /* we only handle these for now (why?) */
294 case V4L2_CID_HCENTER:
295 case V4L2_CID_VCENTER:
296 #ifdef V4L2_CID_PAN_RESET
297 case V4L2_CID_PAN_RESET:
299 #ifdef V4L2_CID_TILT_RESET
300 case V4L2_CID_TILT_RESET:
302 /* not handled here, handled by VideoOrientation interface */
305 case V4L2_CID_AUDIO_VOLUME:
306 case V4L2_CID_AUDIO_BALANCE:
307 case V4L2_CID_AUDIO_BASS:
308 case V4L2_CID_AUDIO_TREBLE:
309 case V4L2_CID_AUDIO_MUTE:
310 case V4L2_CID_AUDIO_LOUDNESS:
311 /* FIXME: We should implement GstMixer interface */
315 "ControlID %s (%x) unhandled, FIXME", control.name, n);
322 GST_DEBUG_OBJECT (e, "Adding ControlID %s (%x)", control.name, n);
323 v4l2channel = g_object_new (GST_TYPE_V4L2_COLOR_BALANCE_CHANNEL, NULL);
324 channel = GST_COLOR_BALANCE_CHANNEL (v4l2channel);
325 channel->label = g_strdup ((const gchar *) control.name);
329 /* FIXME: it will be need just when handling private controls
330 *(currently none of base controls are of this type) */
331 if (control.type == V4L2_CTRL_TYPE_MENU) {
332 struct v4l2_querymenu menu, *mptr;
339 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYMENU, &menu) < 0) {
341 break; /* end of enumeration */
343 GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS,
344 (_("Failed getting controls attributes on device '%s'."),
345 v4l2object->videodev),
346 ("Failed to get %d in menu enumeration for %s. (%d - %s)",
347 n, v4l2object->videodev, errno, strerror (errno)));
351 mptr = g_malloc (sizeof (menu));
352 memcpy (mptr, &menu, sizeof (menu));
353 menus = g_list_append (menus, mptr);
356 v4l2object->menus = g_list_append (v4l2object->menus, menus);
359 switch (control.type) {
360 case V4L2_CTRL_TYPE_INTEGER:
361 channel->min_value = control.minimum;
362 channel->max_value = control.maximum;
364 case V4L2_CTRL_TYPE_BOOLEAN:
365 channel->min_value = FALSE;
366 channel->max_value = TRUE;
369 /* FIXME we should find out how to handle V4L2_CTRL_TYPE_BUTTON.
370 BUTTON controls like V4L2_CID_DO_WHITE_BALANCE can just be set (1) or
371 unset (0), but can't be queried */
373 "Control with non supported type %s (%x), type=%d",
374 control.name, n, control.type);
375 channel->min_value = channel->max_value = 0;
380 g_list_prepend (v4l2object->colors, (gpointer) channel);
382 v4l2object->colors = g_list_reverse (v4l2object->colors);
384 GST_DEBUG_OBJECT (e, "done");
390 gst_v4l2_empty_lists (GstV4l2Object * v4l2object)
392 GST_DEBUG_OBJECT (v4l2object->element, "deleting enumerations");
394 g_list_foreach (v4l2object->channels, (GFunc) g_object_unref, NULL);
395 g_list_free (v4l2object->channels);
396 v4l2object->channels = NULL;
398 g_list_foreach (v4l2object->norms, (GFunc) g_object_unref, NULL);
399 g_list_free (v4l2object->norms);
400 v4l2object->norms = NULL;
402 g_list_foreach (v4l2object->colors, (GFunc) g_object_unref, NULL);
403 g_list_free (v4l2object->colors);
404 v4l2object->colors = NULL;
407 /******************************************************
409 * open the video device (v4l2object->videodev)
410 * return value: TRUE on success, FALSE on error
411 ******************************************************/
413 gst_v4l2_open (GstV4l2Object * v4l2object)
417 GstPollFD pollfd = GST_POLL_FD_INIT;
419 GST_DEBUG_OBJECT (v4l2object->element, "Trying to open device %s",
420 v4l2object->videodev);
422 GST_V4L2_CHECK_NOT_OPEN (v4l2object);
423 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
425 /* be sure we have a device */
426 if (!v4l2object->videodev)
427 v4l2object->videodev = g_strdup ("/dev/video");
429 /* check if it is a device */
430 if (stat (v4l2object->videodev, &st) == -1)
433 if (!S_ISCHR (st.st_mode))
436 /* open the device */
437 v4l2object->video_fd =
438 open (v4l2object->videodev, O_RDWR /* | O_NONBLOCK */ );
440 if (!GST_V4L2_IS_OPEN (v4l2object))
443 libv4l2_fd = v4l2_fd_open (v4l2object->video_fd,
444 V4L2_ENABLE_ENUM_FMT_EMULATION);
445 /* Note the v4l2_xxx functions are designed so that if they get passed an
446 unknown fd, the will behave exactly as their regular xxx counterparts, so
447 if v4l2_fd_open fails, we continue as normal (missing the libv4l2 custom
448 cam format to normal formats conversion). Chances are big we will still
449 fail then though, as normally v4l2_fd_open only fails if the device is not
451 if (libv4l2_fd != -1)
452 v4l2object->video_fd = libv4l2_fd;
454 v4l2object->can_poll_device = TRUE;
456 /* get capabilities, error will be posted */
457 if (!gst_v4l2_get_capabilities (v4l2object))
460 /* do we need to be a capture device? */
461 if (GST_IS_V4L2SRC (v4l2object->element) &&
462 !(v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
465 if (GST_IS_V4L2SINK (v4l2object->element) &&
466 !(v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_OUTPUT))
469 /* create enumerations, posts errors. */
470 if (!gst_v4l2_fill_lists (v4l2object))
473 GST_INFO_OBJECT (v4l2object->element,
474 "Opened device '%s' (%s) successfully",
475 v4l2object->vcap.card, v4l2object->videodev);
477 pollfd.fd = v4l2object->video_fd;
478 gst_poll_add_fd (v4l2object->poll, &pollfd);
479 gst_poll_fd_ctl_read (v4l2object->poll, &pollfd, TRUE);
486 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
487 (_("Cannot identify device '%s'."), v4l2object->videodev),
493 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
494 (_("This isn't a device '%s'."), v4l2object->videodev),
500 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ_WRITE,
501 (_("Could not open device '%s' for reading and writing."),
502 v4l2object->videodev), GST_ERROR_SYSTEM);
507 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
508 (_("Device '%s' is not a capture device."),
509 v4l2object->videodev),
510 ("Capabilities: 0x%x", v4l2object->vcap.capabilities));
515 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
516 (_("Device '%s' is not a output device."),
517 v4l2object->videodev),
518 ("Capabilities: 0x%x", v4l2object->vcap.capabilities));
523 if (GST_V4L2_IS_OPEN (v4l2object)) {
525 v4l2_close (v4l2object->video_fd);
526 v4l2object->video_fd = -1;
529 gst_v4l2_empty_lists (v4l2object);
536 /******************************************************
538 * close the video device (v4l2object->video_fd)
539 * return value: TRUE on success, FALSE on error
540 ******************************************************/
542 gst_v4l2_close (GstV4l2Object * v4l2object)
544 GstPollFD pollfd = GST_POLL_FD_INIT;
545 GST_DEBUG_OBJECT (v4l2object->element, "Trying to close %s",
546 v4l2object->videodev);
548 GST_V4L2_CHECK_OPEN (v4l2object);
549 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
552 v4l2_close (v4l2object->video_fd);
553 pollfd.fd = v4l2object->video_fd;
554 gst_poll_remove_fd (v4l2object->poll, &pollfd);
555 v4l2object->video_fd = -1;
558 gst_v4l2_empty_lists (v4l2object);
564 /******************************************************
565 * gst_v4l2_get_norm()
566 * Get the norm of the current device
567 * return value: TRUE on success, FALSE on error
568 ******************************************************/
570 gst_v4l2_get_norm (GstV4l2Object * v4l2object, v4l2_std_id * norm)
572 GST_DEBUG_OBJECT (v4l2object->element, "getting norm");
574 if (!GST_V4L2_IS_OPEN (v4l2object))
577 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_STD, norm) < 0)
585 GST_DEBUG ("Failed to get the current norm for device %s",
586 v4l2object->videodev);
592 /******************************************************
593 * gst_v4l2_set_norm()
594 * Set the norm of the current device
595 * return value: TRUE on success, FALSE on error
596 ******************************************************/
598 gst_v4l2_set_norm (GstV4l2Object * v4l2object, v4l2_std_id norm)
600 GST_DEBUG_OBJECT (v4l2object->element, "trying to set norm to "
601 "%" G_GINT64_MODIFIER "x", (guint64) norm);
603 if (!GST_V4L2_IS_OPEN (v4l2object))
606 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_STD, &norm) < 0)
614 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
615 (_("Failed to set norm for device '%s'."),
616 v4l2object->videodev), GST_ERROR_SYSTEM);
621 /******************************************************
622 * gst_v4l2_get_frequency():
623 * get the current frequency
624 * return value: TRUE on success, FALSE on error
625 ******************************************************/
627 gst_v4l2_get_frequency (GstV4l2Object * v4l2object,
628 gint tunernum, gulong * frequency)
630 struct v4l2_frequency freq = { 0, };
632 GstTunerChannel *channel;
634 GST_DEBUG_OBJECT (v4l2object->element, "getting current tuner frequency");
636 if (!GST_V4L2_IS_OPEN (v4l2object))
639 channel = gst_tuner_get_channel (GST_TUNER (v4l2object->element));
641 freq.tuner = tunernum;
642 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq) < 0)
645 *frequency = freq.frequency * channel->freq_multiplicator;
652 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
653 (_("Failed to get current tuner frequency for device '%s'."),
654 v4l2object->videodev), GST_ERROR_SYSTEM);
660 /******************************************************
661 * gst_v4l2_set_frequency():
663 * return value: TRUE on success, FALSE on error
664 ******************************************************/
666 gst_v4l2_set_frequency (GstV4l2Object * v4l2object,
667 gint tunernum, gulong frequency)
669 struct v4l2_frequency freq = { 0, };
671 GstTunerChannel *channel;
673 GST_DEBUG_OBJECT (v4l2object->element,
674 "setting current tuner frequency to %lu", frequency);
676 if (!GST_V4L2_IS_OPEN (v4l2object))
679 channel = gst_tuner_get_channel (GST_TUNER (v4l2object->element));
681 freq.tuner = tunernum;
682 /* fill in type - ignore error */
683 v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq);
684 freq.frequency = frequency / channel->freq_multiplicator;
686 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_FREQUENCY, &freq) < 0)
694 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
695 (_("Failed to set current tuner frequency for device '%s' to %lu Hz."),
696 v4l2object->videodev, frequency), GST_ERROR_SYSTEM);
701 /******************************************************
702 * gst_v4l2_signal_strength():
703 * get the strength of the signal on the current input
704 * return value: TRUE on success, FALSE on error
705 ******************************************************/
707 gst_v4l2_signal_strength (GstV4l2Object * v4l2object,
708 gint tunernum, gulong * signal_strength)
710 struct v4l2_tuner tuner = { 0, };
712 GST_DEBUG_OBJECT (v4l2object->element, "trying to get signal strength");
714 if (!GST_V4L2_IS_OPEN (v4l2object))
717 tuner.index = tunernum;
718 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &tuner) < 0)
721 *signal_strength = tuner.signal;
728 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
729 (_("Failed to get signal strength for device '%s'."),
730 v4l2object->videodev), GST_ERROR_SYSTEM);
735 /******************************************************
736 * gst_v4l2_get_attribute():
737 * try to get the value of one specific attribute
738 * return value: TRUE on success, FALSE on error
739 ******************************************************/
741 gst_v4l2_get_attribute (GstV4l2Object * v4l2object,
742 int attribute_num, int *value)
744 struct v4l2_control control = { 0, };
746 GST_DEBUG_OBJECT (v4l2object->element, "getting value of attribute %d",
749 if (!GST_V4L2_IS_OPEN (v4l2object))
752 control.id = attribute_num;
754 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) < 0)
757 *value = control.value;
764 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
765 (_("Failed to get value for control %d on device '%s'."),
766 attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
772 /******************************************************
773 * gst_v4l2_set_attribute():
774 * try to set the value of one specific attribute
775 * return value: TRUE on success, FALSE on error
776 ******************************************************/
778 gst_v4l2_set_attribute (GstV4l2Object * v4l2object,
779 int attribute_num, const int value)
781 struct v4l2_control control = { 0, };
783 GST_DEBUG_OBJECT (v4l2object->element, "setting value of attribute %d to %d",
784 attribute_num, value);
786 if (!GST_V4L2_IS_OPEN (v4l2object))
789 control.id = attribute_num;
790 control.value = value;
791 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_CTRL, &control) < 0)
799 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
800 (_("Failed to set value %d for control %d on device '%s'."),
801 value, attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
807 gst_v4l2_get_input (GstV4l2Object * v4l2object, gint * input)
811 GST_DEBUG_OBJECT (v4l2object->element, "trying to get input");
813 if (!GST_V4L2_IS_OPEN (v4l2object))
816 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_INPUT, &n) < 0)
821 GST_DEBUG_OBJECT (v4l2object->element, "input: %d", n);
827 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
828 /* only give a warning message if driver actually claims to have tuner
831 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
832 (_("Failed to get current input on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM);
838 gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input)
840 GST_DEBUG_OBJECT (v4l2object->element, "trying to set input to %d", input);
842 if (!GST_V4L2_IS_OPEN (v4l2object))
845 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_INPUT, &input) < 0)
852 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
853 /* only give a warning message if driver actually claims to have tuner
856 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
857 (_("Failed to set input %d on device %s."),
858 input, v4l2object->videodev), GST_ERROR_SYSTEM);
864 gst_v4l2_get_output (GstV4l2Object * v4l2object, gint * output)
868 GST_DEBUG_OBJECT (v4l2object->element, "trying to get output");
870 if (!GST_V4L2_IS_OPEN (v4l2object))
873 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_OUTPUT, &n) < 0)
878 GST_DEBUG_OBJECT (v4l2object->element, "output: %d", n);
884 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
885 /* only give a warning message if driver actually claims to have tuner
888 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
889 (_("Failed to get current output on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM);
895 gst_v4l2_set_output (GstV4l2Object * v4l2object, gint output)
897 GST_DEBUG_OBJECT (v4l2object->element, "trying to set output to %d", output);
899 if (!GST_V4L2_IS_OPEN (v4l2object))
902 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_OUTPUT, &output) < 0)
909 if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) {
910 /* only give a warning message if driver actually claims to have tuner
913 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
914 (_("Failed to set output %d on device %s."),
915 output, v4l2object->videodev), GST_ERROR_SYSTEM);