]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l2/v4l2.c
BluRay instead of Blu-Ray. Re-using short messages for long ones
[vlc] / modules / access / v4l2 / v4l2.c
index ec65a17b1e0fb5d0bdc6acfcd1bb3bf905e8b547..e06c80d3514e114a3b719f3fe3b1fda7d0c84770 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * v4l2.c : Video4Linux2 input module for VLC
  *****************************************************************************
- * Copyright (C) 2002-2009 the VideoLAN team
+ * Copyright (C) 2002-2009 VLC authors and VideoLAN
  * Copyright (C) 2011-2012 RĂ©mi Denis-Courmont
  *
  * Authors: Benjamin Pracht <bigben at videolan dot org>
@@ -9,14 +9,14 @@
  *          Antoine Cellerier <dionoea at videolan d.t org>
  *          Dennis Lou <dlou99 at yahoo dot com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
 #include <string.h>
 #include <assert.h>
 
+#include <sys/types.h>
+#include <fcntl.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
+#include <vlc_fs.h>
 
 #include "v4l2.h"
 
-#define DEVICE_TEXT N_( "Device" )
-#define DEVICE_LONGTEXT N_("Video device node." )
+#define VIDEO_DEVICE_TEXT N_( "Video capture device" )
+#define VIDEO_DEVICE_LONGTEXT N_("Video capture device node." )
+#define VBI_DEVICE_TEXT N_("VBI capture device")
+#define VBI_DEVICE_LONGTEXT N_( \
+    "The device node where VBI data can be read "   \
+    " (for closed captions) " )
 #define STANDARD_TEXT N_( "Standard" )
 #define STANDARD_LONGTEXT N_( \
     "Video standard (Default, SECAM, PAL, or NTSC)." )
 #define SIZE_LONGTEXT N_( \
     "The specified pixel resolution is forced " \
     "(if both width and height are strictly positive)." )
-#define FPS_TEXT N_( "Framerate" )
-#define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \
-    "(0 for autodetect)." )
+/*#define FPS_TEXT N_( "Frame rate" )
+#define FPS_LONGTEXT N_( "Maximum frame rate to use (0 = no limits)." )*/
+
+#define RADIO_DEVICE_TEXT N_( "Radio device" )
+#define RADIO_DEVICE_LONGTEXT N_("Radio tuner device node." )
+#define FREQUENCY_TEXT N_("Frequency")
+#define FREQUENCY_LONGTEXT N_( \
+    "Tuner frequency in Hz or kHz (see debug output)" )
+#define TUNER_AUDIO_MODE_TEXT N_("Audio mode")
+#define TUNER_AUDIO_MODE_LONGTEXT N_( \
+    "Tuner audio mono/stereo and track selection." )
 
 #define CTRL_RESET_TEXT N_( "Reset controls" )
 #define CTRL_RESET_LONGTEXT N_( "Reset controls to defaults." )
@@ -121,7 +137,7 @@ static const char *const power_freq_user[] = { N_("Unspecified"),
     N_("Off"), N_("50 Hz"), N_("60 Hz"), N_("Automatic"),
 };
 #define BKLT_COMPENSATE_TEXT N_( "Backlight compensation" )
-#define BKLT_COMPENSATE_LONGTEXT N_( "Backlight compensation." )
+#define BKLT_COMPENSATE_LONGTEXT BKLT_COMPENSATE_TEXT
 #define BAND_STOP_FILTER_TEXT N_( "Band-stop filter" )
 #define BAND_STOP_FILTER_LONGTEXT N_(  \
     "Cut a light band induced by fluorescent lighting (unit undocumented)." )
@@ -177,16 +193,6 @@ static const char *const colorfx_user[] = { N_("Unspecified"), N_("None"),
     "To list available controls, increase verbosity (-vvv) " \
     "or use the v4l2-ctl application." )
 
-#define TUNER_TEXT N_("Tuner id")
-#define TUNER_LONGTEXT N_( \
-    "Tuner id (see debug output)." )
-#define FREQUENCY_TEXT N_("Frequency")
-#define FREQUENCY_LONGTEXT N_( \
-    "Tuner frequency in Hz or kHz (see debug output)" )
-#define TUNER_AUDIO_MODE_TEXT N_("Audio mode")
-#define TUNER_AUDIO_MODE_LONGTEXT N_( \
-    "Tuner audio mono/stereo and track selection." )
-
 #define ASPECT_TEXT N_("Picture aspect-ratio n:m")
 #define ASPECT_LONGTEXT N_("Define input picture aspect-ratio to use. Default is 4:3" )
 
@@ -266,18 +272,22 @@ static const char *const psz_tuner_audio_modes_list_text[] = {
 };
 
 vlc_module_begin ()
-    set_shortname( N_("Video4Linux2") )
-    set_description( N_("Video4Linux2 input") )
+    set_shortname( N_("V4L") )
+    set_description( N_("Video4Linux input") )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
 
     set_section( N_( "Video input" ), NULL )
     add_loadfile( CFG_PREFIX "dev", "/dev/video0",
-                  DEVICE_TEXT, DEVICE_LONGTEXT, false )
+                  VIDEO_DEVICE_TEXT, VIDEO_DEVICE_LONGTEXT, false )
         change_safe()
+#ifdef ZVBI_COMPILED
+    add_loadfile( CFG_PREFIX "vbidev", NULL,
+                  VBI_DEVICE_TEXT, VBI_DEVICE_LONGTEXT, false )
+#endif
     add_string( CFG_PREFIX "standard", "",
                 STANDARD_TEXT, STANDARD_LONGTEXT, false )
-        change_string_list( standards_vlc, standards_user, NULL )
+        change_string_list( standards_vlc, standards_user )
         change_safe()
     add_string( CFG_PREFIX "chroma", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
                 true )
@@ -300,11 +310,15 @@ vlc_module_begin ()
     add_string( CFG_PREFIX "aspect-ratio", "4:3", ASPECT_TEXT,
               ASPECT_LONGTEXT, true )
         change_safe()
-    add_float( CFG_PREFIX "fps", 0, FPS_TEXT, FPS_LONGTEXT, true )
-        change_safe()
+    /*add_float( CFG_PREFIX "fps", 0, FPS_TEXT, FPS_LONGTEXT, true )*/
+    add_obsolete_float( CFG_PREFIX "fps" )
+        change_safe() /* since 2.1.0 */
     add_obsolete_bool( CFG_PREFIX "use-libv4l2" ) /* since 2.1.0 */
 
     set_section( N_( "Tuner" ), NULL )
+    add_loadfile( CFG_PREFIX "radio-dev", "/dev/radio0",
+                  RADIO_DEVICE_TEXT, RADIO_DEVICE_LONGTEXT, false )
+        change_safe()
     add_obsolete_integer( CFG_PREFIX "tuner" ) /* since 2.1.0 */
     add_integer( CFG_PREFIX "tuner-frequency", -1, FREQUENCY_TEXT,
                  FREQUENCY_LONGTEXT, true )
@@ -408,11 +422,17 @@ vlc_module_begin ()
 
     add_submodule ()
     add_shortcut( "v4l", "v4l2", "v4l2c" )
-    set_description( N_("Video4Linux2 Compressed A/V") )
+    set_description( N_("Video4Linux compressed A/V input") )
     set_capability( "access", 0 )
     /* use these when open as access_demux fails; VLC will use another demux */
     set_callbacks( AccessOpen, AccessClose )
 
+    add_submodule ()
+    add_shortcut ("radio" /*, "fm", "am" */)
+    set_description (N_("Video4Linux radio tuner"))
+    set_capability ("access_demux", 0)
+    set_callbacks (RadioOpen, RadioClose)
+
 vlc_module_end ()
 
 /**
@@ -443,6 +463,53 @@ void ParseMRL( vlc_object_t *obj, const char *mrl )
     }
 }
 
+int OpenDevice (vlc_object_t *obj, const char *path, uint32_t *restrict caps)
+{
+    msg_Dbg (obj, "opening device '%s'", path);
+
+    int rawfd = vlc_open (path, O_RDWR);
+    if (rawfd == -1)
+    {
+        msg_Err (obj, "cannot open device '%s': %m", path);
+        return -1;
+    }
+
+    int fd = v4l2_fd_open (rawfd, 0);
+    if (fd == -1)
+    {
+        msg_Warn (obj, "cannot initialize user-space library: %m");
+        /* fallback to direct kernel mode anyway */
+        fd = rawfd;
+    }
+
+    /* Get device capabilites */
+    struct v4l2_capability cap;
+    if (v4l2_ioctl (fd, VIDIOC_QUERYCAP, &cap) < 0)
+    {
+        msg_Err (obj, "cannot get device capabilities: %m");
+        v4l2_close (fd);
+        return -1;
+    }
+
+    msg_Dbg (obj, "device %s using driver %s (version %u.%u.%u) on %s",
+            cap.card, cap.driver, (cap.version >> 16) & 0xFF,
+            (cap.version >> 8) & 0xFF, cap.version & 0xFF, cap.bus_info);
+
+    if (cap.capabilities & V4L2_CAP_DEVICE_CAPS)
+    {
+        msg_Dbg (obj, " with capabilities 0x%08"PRIX32" "
+                 "(overall 0x%08"PRIX32")", cap.device_caps, cap.capabilities);
+        *caps = cap.device_caps;
+    }
+    else
+    {
+        msg_Dbg (obj, " with unknown capabilities  "
+                 "(overall 0x%08"PRIX32")", cap.capabilities);
+        *caps = cap.capabilities;
+    }
+    return fd;
+}
+
 v4l2_std_id var_InheritStandard (vlc_object_t *obj, const char *varname)
 {
     char *name = var_InheritString (obj, varname);