]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/udev.c
lua: remove variable callback
[vlc] / modules / services_discovery / udev.c
index e80c93cd632808fd64fbcf66e570c43290ee3a3a..8c65b75541aa614c9be454c83bb9facde9581a7c 100644 (file)
@@ -5,20 +5,20 @@
 /*****************************************************************************
  * Copyright © 2009 Rémi Denis-Courmont
  *
- * This library 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- ****************************************************************************/
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -36,7 +36,9 @@
 #include <errno.h>
 
 static int OpenV4L (vlc_object_t *);
+#ifdef HAVE_ALSA
 static int OpenALSA (vlc_object_t *);
+#endif
 static int OpenDisc (vlc_object_t *);
 static void Close (vlc_object_t *);
 static int vlc_sd_probe_Open (vlc_object_t *);
@@ -52,7 +54,7 @@ vlc_module_begin ()
     set_capability ("services_discovery", 0)
     set_callbacks (OpenV4L, Close)
     add_shortcut ("v4l")
-
+#ifdef HAVE_ALSA
     add_submodule ()
     set_shortname (N_("Audio capture"))
     set_description (N_("Audio capture (ALSA)"))
@@ -61,7 +63,7 @@ vlc_module_begin ()
     set_capability ("services_discovery", 0)
     set_callbacks (OpenALSA, Close)
     add_shortcut ("alsa")
-
+#endif
     add_submodule ()
     set_shortname (N_("Discs"))
     set_description (N_("Discs"))
@@ -88,8 +90,10 @@ static int vlc_sd_probe_Open (vlc_object_t *obj)
     {
         vlc_sd_probe_Add (probe, "v4l{longname=\"Video capture\"}",
                           N_("Video capture"), SD_CAT_DEVICES);
+#ifdef HAVE_ALSA
         vlc_sd_probe_Add (probe, "alsa{longname=\"Audio capture\"}",
                           N_("Audio capture"), SD_CAT_DEVICES);
+#endif
         vlc_sd_probe_Add (probe, "disc{longname=\"Discs\"}", N_("Discs"),
                           SD_CAT_DEVICES);
         udev_monitor_unref (mon);
@@ -158,8 +162,7 @@ static int AddDevice (services_discovery_t *sd, struct udev_device *dev)
     if (mrl == NULL)
         return 0; /* don't know if it was an error... */
     char *name = p_sys->subsys->get_name (dev);
-    input_item_t *item = input_item_NewWithType (VLC_OBJECT (sd), mrl,
-                                                 name ? name : mrl,
+    input_item_t *item = input_item_NewWithType (mrl, name ? name : mrl,
                                                  0, NULL, 0, -1,
                                                  p_sys->subsys->item_type);
     msg_Dbg (sd, "adding %s (%s)", mrl, name);
@@ -395,24 +398,32 @@ static char *decode_property (struct udev_device *dev, const char *name)
 
 
 /*** Video4Linux support ***/
-static bool is_v4l_legacy (struct udev_device *dev)
+static bool v4l_is_legacy (struct udev_device *dev)
 {
     const char *version;
 
     version = udev_device_get_property_value (dev, "ID_V4L_VERSION");
-    return version && !strcmp (version, "1");
+    return (version != NULL) && !strcmp (version, "1");
+}
+
+static bool v4l_can_capture (struct udev_device *dev)
+{
+    const char *caps;
+
+    caps = udev_device_get_property_value (dev, "ID_V4L_CAPABILITIES");
+    return (caps != NULL) && (strstr (caps, ":capture:") != NULL);
 }
 
 static char *v4l_get_mrl (struct udev_device *dev)
 {
     /* Determine media location */
-    const char *scheme = "v4l2";
-    if (is_v4l_legacy (dev))
-        scheme = "v4l";
+    if (v4l_is_legacy (dev) || !v4l_can_capture (dev))
+        return NULL;
+
     const char *node = udev_device_get_devnode (dev);
     char *mrl;
 
-    if (asprintf (&mrl, "%s://%s", scheme, node) == -1)
+    if (asprintf (&mrl, "v4l2://%s", node) == -1)
         mrl = NULL;
     return mrl;
 }