Fix device probing from multiple childs. It's done once in the parent class only...
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>
Sun, 9 Nov 2003 20:54:24 +0000 (20:54 +0000)
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>
Sun, 9 Nov 2003 20:54:24 +0000 (20:54 +0000)
Original commit message from CVS:
Fix device probing from multiple childs. It's done once in the parent class only now, but the childs do get the correct values. Also fixes an incorrect succesful state change if we opened a v4l device that doesn't have the capabilities that are needed by the plugin.

sys/v4l/gstv4lelement.c
sys/v4l/v4l_calls.c

index 5a2308ef41fa3e38fa823ce9c7da17a65950ae9d..4287bfbf5136ddd63dff38007233cdc31d67342d 100644 (file)
@@ -122,16 +122,17 @@ gst_v4l_class_probe_devices (GstV4lElementClass *klass,
                             gboolean            check)
 {
   static gboolean init = FALSE;
+  static GList *devices = NULL;
 
   if (!init && !check) {
     gchar *dev_base[] = { "/dev/video", "/dev/v4l/video", NULL };
     gint base, n, fd;
 
-    while (klass->devices) {
-      GList *item = klass->devices;
+    while (devices) {
+      GList *item = devices;
       gchar *device = item->data;
 
-      klass->devices = g_list_remove (klass->devices, item);
+      devices = g_list_remove (devices, item);
       g_free (device);
     }
 
@@ -148,7 +149,7 @@ gst_v4l_class_probe_devices (GstV4lElementClass *klass,
             if (fd > 0)
               close (fd);
 
-            klass->devices = g_list_append (klass->devices, device);
+            devices = g_list_append (devices, device);
             break;
           }
         }
@@ -159,6 +160,8 @@ gst_v4l_class_probe_devices (GstV4lElementClass *klass,
     init = TRUE;
   }
 
+  klass->devices = devices;
+
   return init;
 }
 
index 42bfdb3760823aa260477f912d24bef54d9f89a4..515299b98f160e517701746782d2053e6b2a69f5 100644 (file)
 #include "gstv4ltuner.h"
 #include "gstv4lcolorbalance.h"
 
+#include "gstv4lsrc.h"
+#include "gstv4lmjpegsrc.h"
+#include "gstv4lmjpegsink.h"
+
 #define DEBUG(format, args...) \
        GST_DEBUG_OBJECT (\
                GST_ELEMENT(v4lelement), \
@@ -130,6 +134,21 @@ gst_v4l_open (GstV4lElement *v4lelement)
     return FALSE;
   }
 
+  /* device type check */
+  if ((GST_IS_V4LSRC(v4lelement) &&
+       !(v4lelement->vcap.type & VID_TYPE_CAPTURE)) ||
+      (GST_IS_V4LMJPEGSRC(v4lelement) &&
+       !(v4lelement->vcap.type & VID_TYPE_MJPEG_ENCODER)) ||
+      (GST_IS_V4LMJPEGSINK(v4lelement) &&
+       !(v4lelement->vcap.type & VID_TYPE_MJPEG_DECODER))) {
+    gst_element_error(GST_ELEMENT(v4lelement),
+                     "Device opened, but wrong type (0x%x)",
+                     v4lelement->vcap.type);
+    close(v4lelement->video_fd);
+    v4lelement->video_fd = -1;
+    return FALSE;
+  }
+
   gst_info("Opened device \'%s\' (\'%s\') successfully\n",
     v4lelement->vcap.name, v4lelement->videodev);