]> git.sesse.net Git - kdenlive/commitdiff
Clean up v4l detection
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 31 May 2011 21:49:41 +0000 (21:49 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 31 May 2011 21:49:41 +0000 (21:49 +0000)
svn path=/trunk/kdenlive/; revision=5628

src/v4l/src.c
src/v4l/v4lcapture.cpp

index f7278236e54e9eaaf8beb8e6c6776e289ad39ba0..b6b8867b50b75aa42722bd741d470b11d55cc433 100644 (file)
@@ -106,25 +106,25 @@ const char *query_v4ldevice(src_t *src, char **pixelformatdescription)
                 free(s);
                 return NULL;
         }
-
+        char *res = NULL;
+        int captureEnabled = 1;
         if(ioctl(s->fd, VIDIOC_QUERYCAP, &s->cap) < 0) {
-            close_v4l2(src);
             fprintf(stderr, "Cannot get capabilities.");
-            return NULL;
-        }
-        char *res = strdup((char*) s->cap.card);
-        /*strcpy(res, (char*) s->cap.card);*/
-        if(!s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
-            // Device cannot capture
+            //return NULL;
         }
         else {
+            res = strdup((char*) s->cap.card);
+            if(!s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
+                // Device cannot capture
+                captureEnabled = 0;
+            }
+        }
+        
+        if (captureEnabled) {
             struct v4l2_format format;
             memset(&format,0,sizeof(format));
             format.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-            if (ioctl(s->fd,VIDIOC_G_FMT,&format) < 0) {
-                fprintf(stderr, "Cannot get format.");
-                // Cannot query
-            }
+
             struct v4l2_fmtdesc fmt;
             memset(&fmt,0,sizeof(fmt));
             fmt.index = 0;
@@ -138,8 +138,6 @@ const char *query_v4ldevice(src_t *src, char **pixelformatdescription)
 
             while (ioctl(s->fd, VIDIOC_ENUM_FMT, &fmt) != -1)
             {
-                /*strcpy(*pixelformatdescription, (char *) fmt.description);*/
-                //*pixelformatdescription = strdup((char*)fmt.description);
                 snprintf( value, sizeof(value), ">%c%c%c%c", fmt.pixelformat >> 0,  fmt.pixelformat >> 8, fmt.pixelformat >> 16, fmt.pixelformat >> 24 );
                 strcat(*pixelformatdescription, (char *) value);
                 fprintf(stderr, "detected format: %s: %c%c%c%c\n", fmt.description, fmt.pixelformat >> 0,  fmt.pixelformat >> 8,
index 530fe8143eae704540a38eea25237b8009852442..752a6b13196ea744379c9a720ae85c23b7bd4baf 100644 (file)
@@ -63,10 +63,12 @@ QStringList V4lCaptureHandler::getDeviceName(QString input)
     v4lsrc.source     = strdup(input.toUtf8().constData());
     char *pixelformatdescription;
     pixelformatdescription = (char *) calloc(2048, sizeof(char));
-    QString deviceName(query_v4ldevice(&v4lsrc, &pixelformatdescription));
+    QStringList result;
+    const char *devName = query_v4ldevice(&v4lsrc, &pixelformatdescription);
+    if (devName == NULL) return result; 
+    QString deviceName(devName);
     QString info(pixelformatdescription);
     free (pixelformatdescription);
-    QStringList result;
     result << (deviceName.isEmpty() ? input : deviceName) << info;
     return result;
 }