Skip to contentSkip to conversation

gspca: add g_std/s_std methods

PATCH In review Olaf Titz 2 participants 3 messages Aug 9, 2009 – Aug 11, 2009 Media (V4L/DVB)

lore
Share & tools
lore

Olaf Titz

author
#0 lore raw

PATCH 1/1 gspca: add g_std/s_std methods

Some applications are unhappy about getting EINVAL errors for query/set TV standard operations, especially (or only?) when working over the v4l1compat.so bridge. This patch adds the appropriate methods to the gspca driver (claim to support all TV modes, setting TV mode does nothing).

--- a/linux/drivers/media/video/gspca/gspca.c Sat Aug 08 03:28:41 2009
-0300
+++ b/linux/drivers/media/video/gspca/gspca.c Sun Aug 09 22:00:03 2009
+0200
@@ -1249,6 +1249,7 @@

        if (input->index != 0)
                return -EINVAL;
        input->type = V4L2_INPUT_TYPE_CAMERA;
+       input->std = V4L2_STD_ALL;
        input->status = gspca_dev->cam.input_flags;
        strncpy(input->name, gspca_dev->sd_desc->name,
                sizeof input->name);
@@ -1624,6 +1625,17 @@
        return ret;

}

+static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm) +{
+ *norm = V4L2_STD_UNKNOWN;
+ return 0;
+}
+
+static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) +{
+ return 0;
+}
+
/*
* wait for a video frame
*
@@ -1958,6 +1970,8 @@

        .vidioc_s_fmt_vid_cap   = vidioc_s_fmt_vid_cap,
        .vidioc_streamon        = vidioc_streamon,
        .vidioc_queryctrl       = vidioc_queryctrl,
+       .vidioc_g_std           = vidioc_g_std,
+       .vidioc_s_std           = vidioc_s_std,
        .vidioc_g_ctrl          = vidioc_g_ctrl,
        .vidioc_s_ctrl          = vidioc_s_ctrl,
        .vidioc_g_audio         = vidioc_g_audio,
#1 lore raw
Quoted 5 lines · On Sun, 09 Aug 2009 22:13:12 +0200 Olaf Titz <[email protected]> wrote:

Some applications are unhappy about getting EINVAL errors for query/set TV standard operations, especially (or only?) when working over the v4l1compat.so bridge. This patch adds the appropriate methods to the gspca driver (claim to support all TV modes, setting TV mode does nothing).

The vidioc_s_std() has been removed last month by Németh Márton according to the v4l2 API http://v4l2spec.bytesex.org/spec/x448.htm

Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
author
#2 lore raw
Quoted 2 lines · Jean-Francois Moine

The vidioc_s_std() has been removed last month by Németh Márton according to the v4l2 API http://v4l2spec.bytesex.org/spec/x448.htm

Ah, I see. This is a recent change, which explains why it has not come up earlier :-)
The standard clearly states that my change is incorrect, but then v4l1-compat.c is wrong in how it implements v4l_compat_get_input_info() and v4l1_compat_set_input(). These calls query rsp. set video input and standard in one call, and there is no special provision for webcams in
http://v4l2spec.bytesex.org/spec/x309.htm, so these calls should not fail. IOW, something like this would be in order instead (untested):

--- a/linux/drivers/media/video/v4l1-compat.c Sat Aug 08 03:28:41 2009
-0300
+++ b/linux/drivers/media/video/v4l1-compat.c Tue Aug 11 20:30:47 2009
+0200
@@ -540,7 +540,7 @@

 {
        long err;
        struct v4l2_input       input2;
-       v4l2_std_id             sid;
+       v4l2_std_id             sid = V4L2_STD_UNKNOWN;
        memset(&input2, 0, sizeof(input2));
        input2.index = chan->channel;
@@ -566,19 +566,21 @@
                break;
        }
        chan->norm = 0;

- err = drv(file, VIDIOC_G_STD, &sid);
- if (err < 0)
- dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %ld\n", err);
- if (err == 0) {
- if (sid & V4L2_STD_PAL)
- chan->norm = VIDEO_MODE_PAL;
- if (sid & V4L2_STD_NTSC)
- chan->norm = VIDEO_MODE_NTSC;
- if (sid & V4L2_STD_SECAM)
- chan->norm = VIDEO_MODE_SECAM;
- if (sid == V4L2_STD_ALL)
- chan->norm = VIDEO_MODE_AUTO;
- }
+ {
+ int err2 = drv(file, VIDIOC_G_STD, &sid);
+ if (err2 < 0)
+ dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %ld\n", err2);
+ if (err2 == 0) {
+ if (sid & V4L2_STD_PAL)
+ chan->norm = VIDEO_MODE_PAL;
+ if (sid & V4L2_STD_NTSC)
+ chan->norm = VIDEO_MODE_NTSC;
+ if (sid & V4L2_STD_SECAM)
+ chan->norm = VIDEO_MODE_SECAM;
+ if (sid == V4L2_STD_ALL)
+ chan->norm = VIDEO_MODE_AUTO;
+ }
+ }
done:

        return err;
 }
@@ -609,9 +611,9 @@
                break;
        }
        if (0 != sid) {

- err = drv(file, VIDIOC_S_STD, &sid);
- if (err < 0)
- dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err);
+ int err2 = drv(file, VIDIOC_S_STD, &sid);
+ if (err2 < 0)

+                       dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err2);
        }
        return err;

}

I'm not sure if v4l1_compat_get_tuner() needs this kind of change too.

We also should keep the input->std = V4L2_STD_ALL; because an application may bomb with something like "Invalid standard PAL, valid choices are:" (empty). This (and the EINVAL) breaks at least ekiga 2 with the v4l1 module (which is what Ubuntu has) run over libv4l1compat.so. (Ekiga 3 with the v4l2 module does work.) It also breaks xawtv, the canonical v4l test app...

Olaf