]> git.sesse.net Git - kdenlive/blobdiff - src/v4l/src.c
Merge branch 'refs/heads/v0.8.2'
[kdenlive] / src / v4l / src.c
index f7278236e54e9eaaf8beb8e6c6776e289ad39ba0..5d7666fc2064b25336f22567347cf84df725e158 100644 (file)
 #include <sys/ioctl.h>
 
 
-/* Supported palette types. */
-src_palette_t src_palette[] = {
-       { "PNG" },
-       { "JPEG" },
-       { "MJPEG" },
-       { "S561" },
-       { "RGB32" },
-       { "BGR32" },
-       { "RGB24" },
-       { "BGR24" },
-       { "YUYV" },
-       { "UYVY" },
-       { "YUV420P" },
-       { "NV12MB" },
-       { "BAYER" },
-       { "SGBRG8" },
-       { "SGRBG8" },
-       { "RGB565" },
-       { "RGB555" },
-       { "Y16" },
-       { "GREY" },
-       { NULL }
-};
-
-
-
 int v4l2_free_mmap(src_t *src)
 {
         src_v4l2_t *s = (src_v4l2_t *) src->state;
-        int i;
+        uint i;
 
         for(i = 0; i < s->req.count; i++)
                 munmap(s->buffer[i].start, s->buffer[i].length);
@@ -106,25 +80,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,10 +112,9 @@ 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);
+                if (strlen(*pixelformatdescription) > 2000) break;
+                if (snprintf( value, sizeof(value), ">%c%c%c%c", fmt.pixelformat >> 0,  fmt.pixelformat >> 8, fmt.pixelformat >> 16, fmt.pixelformat >> 24 ) > 0)
+                    strcat(*pixelformatdescription, (char *) value);
                 fprintf(stderr, "detected format: %s: %c%c%c%c\n", fmt.description, fmt.pixelformat >> 0,  fmt.pixelformat >> 8,
                       fmt.pixelformat >> 16, fmt.pixelformat >> 24);
 
@@ -155,12 +128,14 @@ const char *query_v4ldevice(src_t *src, char **pixelformatdescription)
                     rates.pixel_format = fmt.pixelformat;
                     rates.width = image_size.width;
                     rates.height = image_size.height;
-                    snprintf( value, sizeof(value), ":%dx%d=", image_size.width, image_size.height );
-                    strcat(*pixelformatdescription, (char *) value);
+                    if (strlen(*pixelformatdescription) > 2000) break;
+                    if (snprintf( value, sizeof(value), ":%dx%d=", image_size.width, image_size.height ) > 0)
+                        strcat(*pixelformatdescription, (char *) value);
                     fprintf(stderr, "Size: %dx%d: ", image_size.width, image_size.height);
                     while (ioctl(s->fd, VIDIOC_ENUM_FRAMEINTERVALS, &rates) != -1) {
-                        snprintf( value, sizeof(value), "%d/%d,", rates.un.discrete.denominator, rates.un.discrete.numerator );
-                        strcat(*pixelformatdescription, (char *) value);
+                        if (strlen(*pixelformatdescription) > 2000) break;
+                        if (snprintf( value, sizeof(value), "%d/%d,", rates.un.discrete.denominator, rates.un.discrete.numerator ) > 0)
+                            strcat(*pixelformatdescription, (char *) value);
                         fprintf(stderr, "%d/%d, ", rates.un.discrete.numerator, rates.un.discrete.denominator);
                         rates.index ++;
                     }