]> git.sesse.net Git - kdenlive/blobdiff - src/v4l/src_v4l2.c
Complete rewrite of the video4linux capture to use MLT, in progress.
[kdenlive] / src / v4l / src_v4l2.c
index 641913f6bf230a333eb26eb11ff864d9ef053e5a..716804d9ec7c4a739d958f9df1c29378248da689 100644 (file)
 
 #ifdef HAVE_V4L2
 
-typedef struct {
-       void *start;
-       size_t length;
-} v4l2_buffer_t;
-
-typedef struct {
-       
-       int fd;
-       char map;
-       
-       struct v4l2_capability cap;
-       struct v4l2_format fmt;
-       struct v4l2_requestbuffers req;
-       struct v4l2_buffer buf;
-       
-       v4l2_buffer_t *buffer;
-       
-       int pframe;
-       
-} src_v4l2_t;
-
-static int src_v4l2_close(src_t *src);
-
-typedef struct {
-       uint16_t src;
-       uint32_t v4l2;
-} v4l2_palette_t;
-
-v4l2_palette_t v4l2_palette[] = {
-       { SRC_PAL_JPEG,    V4L2_PIX_FMT_JPEG   },
-       { SRC_PAL_MJPEG,   V4L2_PIX_FMT_MJPEG  },
-       { SRC_PAL_S561,    V4L2_PIX_FMT_SPCA561 },
-       { SRC_PAL_RGB24,   V4L2_PIX_FMT_RGB24  },
-       { SRC_PAL_BGR24,   V4L2_PIX_FMT_BGR24  },
-       { SRC_PAL_RGB32,   V4L2_PIX_FMT_RGB32  },
-       { SRC_PAL_BGR32,   V4L2_PIX_FMT_BGR32  },
-       { SRC_PAL_YUYV,    V4L2_PIX_FMT_YUYV   },
-       { SRC_PAL_UYVY,    V4L2_PIX_FMT_UYVY   },
-       { SRC_PAL_YUV420P, V4L2_PIX_FMT_YUV420 },
-       { SRC_PAL_BAYER,   V4L2_PIX_FMT_SBGGR8 },
-       { SRC_PAL_SGBRG8,  V4L2_PIX_FMT_SGBRG8 },
-       { SRC_PAL_SGRBG8,  V4L2_PIX_FMT_SGRBG8 },
-       { SRC_PAL_RGB565,  V4L2_PIX_FMT_RGB565 },
-       { SRC_PAL_RGB555,  V4L2_PIX_FMT_RGB555 },
-       { SRC_PAL_Y16,     V4L2_PIX_FMT_Y16    },
-       { SRC_PAL_GREY,    V4L2_PIX_FMT_GREY   },
-       { 0, 0 }
-};
-
 int src_v4l2_get_capability(src_t *src)
 {
        src_v4l2_t *s = (src_v4l2_t *) src->state;
@@ -802,7 +753,7 @@ int src_v4l2_set_read(src_t *src)
        return(0);
 }
 
-static const char *src_v4l2_query(src_t *src, int *width, int *height)
+static const char *src_v4l2_query(src_t *src, uint *width, uint *height, char **pixelformatdescription)
 {
        if(!src->source)
        {
@@ -836,10 +787,11 @@ static const char *src_v4l2_query(src_t *src, int *width, int *height)
            fprintf(stderr, "Cannot get capabilities.");
            return NULL;
        }
-       char * res = (char*) s->cap.card;
+       char *res = strdup((char*) s->cap.card);
+       /*strcpy(res, (char*) s->cap.card);*/
        if(!s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
-           width = 0;
-           height = 0;
+           *width = 0;
+           *height = 0;
        }
        else {
            struct v4l2_format format;
@@ -851,8 +803,62 @@ static const char *src_v4l2_query(src_t *src, int *width, int *height)
             else {
                *width = format.fmt.pix.width;
                *height = format.fmt.pix.height;
-               fprintf(stderr, "Size: %d, %d.", width, height);
            }
+           struct v4l2_fmtdesc fmt;
+           memset(&fmt,0,sizeof(fmt));
+           fmt.index = 0;
+           fmt.type  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+            struct v4l2_frmsizeenum sizes;
+            memset(&sizes,0,sizeof(sizes));
+
+            struct v4l2_frmivalenum rates;
+            memset(&rates,0,sizeof(rates));
+            char value[200];
+            *pixelformatdescription = strdup((char *) "result:");
+
+           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, strdup((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);
+
+                sizes.pixel_format = fmt.pixelformat;
+                sizes.index = 0;
+                // Query supported frame size
+                while (ioctl(s->fd, VIDIOC_ENUM_FRAMESIZES, &sizes) != -1) {
+                    struct v4l2_frmsize_discrete image_size = sizes.un.discrete;
+                    // Query supported frame rates
+                    rates.index = 0;
+                    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, strdup((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.numerator, rates.un.discrete.denominator );
+                        strcat(*pixelformatdescription, strdup((char *) value));
+                        fprintf(stderr, "%d/%d, ", rates.un.discrete.numerator, rates.un.discrete.denominator);
+                        rates.index ++;
+                    }
+                    fprintf(stderr, "\n");
+                    sizes.index++;
+                }
+                
+
+                /*[0x%08X] '%c%c%c%c' (%s)", v4l2_pal,
+                      fmt.pixelformat,
+                      fmt.pixelformat >> 0,  fmt.pixelformat >> 8,
+                      fmt.pixelformat >> 16, fmt.pixelformat >> 24*/
+                fmt.index++;
+           }
+           /*else {
+               *pixelformatdescription = '\0';
+           }*/
        }
        src_v4l2_close(src);
        return res;