From bb07a39c6766bc925ebd15af9de8ea9bee923210 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Tue, 13 Jul 2010 10:03:51 -0500 Subject: [PATCH] v4l2: cleanup get/set input/output output devices should use get/set output, and in either case we should not print a warning message if the ioctl fails but the device does not claim to support the tuner interface --- sys/v4l2/gstv4l2sink.c | 2 +- sys/v4l2/v4l2_calls.c | 71 +++++++++++++++++++++++++++++++++++++++--- sys/v4l2/v4l2_calls.h | 2 -- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c index 3de98512ee..421f639d84 100644 --- a/sys/v4l2/gstv4l2sink.c +++ b/sys/v4l2/gstv4l2sink.c @@ -286,7 +286,7 @@ gst_v4l2sink_init (GstV4l2Sink * v4l2sink, GstV4l2SinkClass * klass) { v4l2sink->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2sink), V4L2_BUF_TYPE_VIDEO_OUTPUT, DEFAULT_PROP_DEVICE, - gst_v4l2_get_input, gst_v4l2_set_input, NULL); + gst_v4l2_get_output, gst_v4l2_set_output, NULL); /* same default value for video output device as is used for * v4l2src/capture is no good.. so lets set a saner default diff --git a/sys/v4l2/v4l2_calls.c b/sys/v4l2/v4l2_calls.c index f2c2c081d1..b4feef3eb7 100644 --- a/sys/v4l2/v4l2_calls.c +++ b/sys/v4l2/v4l2_calls.c @@ -824,11 +824,14 @@ gst_v4l2_get_input (GstV4l2Object * v4l2object, gint * input) /* ERRORS */ input_failed: - { + if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) { + /* only give a warning message if driver actually claims to have tuner + * support + */ GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS, (_("Failed to get current input on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM); - return FALSE; } + return FALSE; } gboolean @@ -846,10 +849,70 @@ gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input) /* ERRORS */ input_failed: - { + if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) { + /* only give a warning message if driver actually claims to have tuner + * support + */ GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS, (_("Failed to set input %d on device %s."), input, v4l2object->videodev), GST_ERROR_SYSTEM); - return FALSE; } + return FALSE; +} + +gboolean +gst_v4l2_get_output (GstV4l2Object * v4l2object, gint * output) +{ + gint n; + + GST_DEBUG_OBJECT (v4l2object->element, "trying to get output"); + + if (!GST_V4L2_IS_OPEN (v4l2object)) + return FALSE; + + if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_OUTPUT, &n) < 0) + goto output_failed; + + *output = n; + + GST_DEBUG_OBJECT (v4l2object->element, "output: %d", n); + + return TRUE; + + /* ERRORS */ +output_failed: + if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) { + /* only give a warning message if driver actually claims to have tuner + * support + */ + GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS, + (_("Failed to get current output on device '%s'. May be it is a radio device"), v4l2object->videodev), GST_ERROR_SYSTEM); + } + return FALSE; +} + +gboolean +gst_v4l2_set_output (GstV4l2Object * v4l2object, gint output) +{ + GST_DEBUG_OBJECT (v4l2object->element, "trying to set output to %d", output); + + if (!GST_V4L2_IS_OPEN (v4l2object)) + return FALSE; + + if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_OUTPUT, &output) < 0) + goto output_failed; + + return TRUE; + + /* ERRORS */ +output_failed: + if (v4l2object->vcap.capabilities & V4L2_CAP_TUNER) { + /* only give a warning message if driver actually claims to have tuner + * support + */ + GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS, + (_("Failed to set output %d on device %s."), + output, v4l2object->videodev), GST_ERROR_SYSTEM); + } + return FALSE; } diff --git a/sys/v4l2/v4l2_calls.h b/sys/v4l2/v4l2_calls.h index c5c1808a4e..a47872dd43 100644 --- a/sys/v4l2/v4l2_calls.h +++ b/sys/v4l2/v4l2_calls.h @@ -111,12 +111,10 @@ gboolean gst_v4l2_get_input (GstV4l2Object * v4l2object, gint * input); gboolean gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input); -#if 0 /* output not handled by now */ gboolean gst_v4l2_get_output (GstV4l2Object *v4l2object, gint *output); gboolean gst_v4l2_set_output (GstV4l2Object *v4l2object, gint output); -#endif /* #if 0 - output not handled by now */ /* frequency control */ gboolean gst_v4l2_get_frequency (GstV4l2Object *v4l2object,