[vlc-devel] [PATCH 3/3] v4l2: only use VBI device is standard selected is NTSC

Devin Heitmueller dheitmueller at kernellabs.com
Sun Oct 21 22:01:02 CEST 2012


We don't currently support any VBI other than EIA-608 closed
caption parsing, so don't attempt to use the /dev/vbi device
unless the standard selected is NTSC.  This mitigates the risk
of causing problems with devices that use other standards (e.g.
PAL, SECAM, etc).
---
 modules/access/v4l2/access.c |    3 ++-
 modules/access/v4l2/demux.c  |   22 ++++++++++++----------
 modules/access/v4l2/v4l2.h   |    2 +-
 modules/access/v4l2/video.c  |   21 +++++++++++++--------
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/modules/access/v4l2/access.c b/modules/access/v4l2/access.c
index df5add0..d4676f5 100644
--- a/modules/access/v4l2/access.c
+++ b/modules/access/v4l2/access.c
@@ -103,7 +103,8 @@ int InitVideo (access_t *access, int fd, uint32_t caps)
         return -1;
     }
 
-    if (SetupInput (VLC_OBJECT(access), fd))
+    v4l2_std_id std;
+    if (SetupInput (VLC_OBJECT(access), fd, &std))
         return -1;
 
     /* NOTE: The V4L access_demux expects a VLC FOURCC as "chroma". It is used to set the
diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index a2dbbb2..bb2309a 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -72,7 +72,7 @@ static void *UserPtrThread (void *);
 static void *MmapThread (void *);
 static void *ReadThread (void *);
 static int DemuxControl( demux_t *, int, va_list );
-static int InitVideo (demux_t *, int fd, uint32_t caps);
+static int InitVideo (demux_t *, int fd, uint32_t caps, v4l2_std_id *std);
 #ifdef ZVBI_COMPILED
 static int InitVBI (demux_t *);
 #endif
@@ -85,6 +85,7 @@ int DemuxOpen( vlc_object_t *obj )
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
     demux->p_sys = sys;
+    sys->vbi_cap = NULL;
 
     ParseMRL( obj, demux->psz_location );
 
@@ -99,9 +100,16 @@ int DemuxOpen( vlc_object_t *obj )
         goto error;
     sys->fd = fd;
 
+    v4l2_std_id std;
+    if (InitVideo (demux, fd, caps, &std))
+    {
+        v4l2_close (fd);
+        goto error;
+    }
+
 #ifdef ZVBI_COMPILED
     char *vbi_path = var_InheritString (obj, CFG_PREFIX"vbidev");
-    if (vbi_path != NULL)
+    if (vbi_path != NULL && (std & V4L2_STD_NTSC_M))
     {    
         sys->vbi_cap = OpenVBIDev (obj, vbi_path);
         if (sys->vbi_cap)
@@ -110,12 +118,6 @@ int DemuxOpen( vlc_object_t *obj )
     }
 #endif
     
-    if (InitVideo (demux, fd, caps))
-    {
-        v4l2_close (fd);
-        goto error;
-    }
-
     sys->controls = ControlsInit (VLC_OBJECT(demux), fd);
     sys->start = mdate ();
     demux->pf_demux = NULL;
@@ -283,7 +285,7 @@ static void GetAR (int fd, unsigned *restrict num, unsigned *restrict den)
     *den = cropcap.pixelaspect.denominator;
 }
 
-static int InitVideo (demux_t *demux, int fd, uint32_t caps)
+static int InitVideo (demux_t *demux, int fd, uint32_t caps, v4l2_std_id *std)
 {
     demux_sys_t *sys = demux->p_sys;
 
@@ -293,7 +295,7 @@ static int InitVideo (demux_t *demux, int fd, uint32_t caps)
         return -1;
     }
 
-    if (SetupInput (VLC_OBJECT(demux), fd))
+    if (SetupInput (VLC_OBJECT(demux), fd, std))
         return -1;
 
     /* Picture format negotiation */
diff --git a/modules/access/v4l2/v4l2.h b/modules/access/v4l2/v4l2.h
index 97f0764..76a7848 100644
--- a/modules/access/v4l2/v4l2.h
+++ b/modules/access/v4l2/v4l2.h
@@ -51,7 +51,7 @@ vbi_capture* OpenVBIDev( vlc_object_t *, const char *);
 v4l2_std_id var_InheritStandard (vlc_object_t *, const char *);
 
 /* video.c */
-int SetupInput (vlc_object_t *, int fd);
+int SetupInput (vlc_object_t *, int fd, v4l2_std_id *std);
 int SetupFormat (vlc_object_t *, int, uint32_t,
                  struct v4l2_format *, struct v4l2_streamparm *);
 #define SetupFormat(o,fd,fcc,fmt,p) \
diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
index 7636937..a38a172 100644
--- a/modules/access/v4l2/video.c
+++ b/modules/access/v4l2/video.c
@@ -39,7 +39,8 @@
 #include "v4l2.h"
 
 static int SetupStandard (vlc_object_t *obj, int fd,
-                          const struct v4l2_input *restrict input)
+                          const struct v4l2_input *restrict input,
+                          v4l2_std_id *std)
 {
     if (!(input->capabilities & V4L2_IN_CAP_STD))
     {
@@ -47,18 +48,22 @@ static int SetupStandard (vlc_object_t *obj, int fd,
         return 0;
     }
 
-    v4l2_std_id std = var_InheritStandard (obj, CFG_PREFIX"standard");
-    if (std == V4L2_STD_UNKNOWN)
+    *std = var_InheritStandard (obj, CFG_PREFIX"standard");
+    if (*std == V4L2_STD_UNKNOWN)
     {
         msg_Warn (obj, "video standard not set");
+
+        /* Grab the currently selected standard */
+        if (v4l2_ioctl (fd, VIDIOC_G_STD, std) < 0)
+            msg_Err (obj, "cannot get video standard");
         return 0;
     }
-    if (v4l2_ioctl (fd, VIDIOC_S_STD, &std) < 0)
+    if (v4l2_ioctl (fd, VIDIOC_S_STD, std) < 0)
     {
-        msg_Err (obj, "cannot set video standard 0x%"PRIx64": %m", std);
+        msg_Err (obj, "cannot set video standard 0x%"PRIx64": %m", *std);
         return -1;
     }
-    msg_Dbg (obj, "video standard set to 0x%"PRIx64":", std);
+    msg_Dbg (obj, "video standard set to 0x%"PRIx64":", *std);
     return 0;
 }
 
@@ -230,7 +235,7 @@ static int ResetCrop (vlc_object_t *obj, int fd)
     return 0;
 }
 
-int SetupInput (vlc_object_t *obj, int fd)
+int SetupInput (vlc_object_t *obj, int fd, v4l2_std_id *std)
 {
     struct v4l2_input input;
 
@@ -263,7 +268,7 @@ int SetupInput (vlc_object_t *obj, int fd)
     }
     msg_Dbg (obj, "selected input %"PRIu32, input.index);
 
-    SetupStandard (obj, fd, &input);
+    SetupStandard (obj, fd, &input, std);
 
     switch (input.type)
     {
-- 
1.7.9.5




More information about the vlc-devel mailing list