]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/omapdrmtest.git/blobdiff - dmabuftest.c
Added buf_lock and buf_unlock APIs in copycodec and yuvcopy test cases.
[glsdk/omapdrmtest.git] / dmabuftest.c
index a9f41e8a6afd73c65a52cf5ea5af3eb22694cd2a..43a3428a588598f1858c53193dbff50601062855 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2011 Texas Instruments
  * Author: Rob Clark <rob.clark@linaro.org>
+ * Adopted for testing VIP capture by: Nikhil Devshatwar <nikhil.nd@ti.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published by
  */
 
 
+#include <pthread.h>
 #include "util.h"
 
-#define NBUF 3
-#define CNT  500
+#define NBUF 6
+#define CNT  500000
+#define MAX_CAP 6
+
+pthread_t active_thread;
+
+enum display_area {
+       FULL,
+       OVERLAY
+};
+
+struct thr_data {
+       struct display *disp;
+       struct v4l2 *v4l2;
+       uint32_t fourcc, width, height;
+       enum display_area area;
+};
 
 static void
 usage(char *name)
@@ -27,19 +44,89 @@ usage(char *name)
        MSG("Usage: %s [OPTION]...", name);
        MSG("Test of buffer passing between v4l2 camera and display.");
        MSG("");
+       MSG("viddec3test options:");
+       MSG("\t-h, --help: Print this help and exit.");
+       MSG("\t--multi <num>: Capture from <num> different devices.");
+       MSG("\t\t\tEach device name and format would be parsed in the cmdline");
+       MSG("");
        disp_usage();
        v4l2_usage();
 }
 
+void *
+capture_loop(void *arg)
+{
+       struct thr_data *data = (struct thr_data *)arg;
+       struct display *disp = data->disp;
+       struct v4l2 *v4l2 = data->v4l2;
+       uint32_t fourcc = data->fourcc;
+       uint32_t width = data->width, height = data->height;
+
+       struct buffer **buffers, *capt;
+       pthread_t tid;
+       int ret, i;
+
+       tid = pthread_self();
+
+       buffers = disp_get_vid_buffers(disp, NBUF, fourcc, width, height);
+       if (!buffers) {
+               return NULL;
+       }
+
+       ret = v4l2_reqbufs(v4l2, buffers, NBUF);
+       if (ret) {
+               return NULL;
+       }
+
+       if(data->area == OVERLAY) {
+               for (i = 0; i < NBUF; i++) {
+                       buffers[i]->noScale = true;
+                       get_overlay_plane(disp, buffers[i]);
+               }
+       }
+
+       for (i = 0; i < NBUF; i++) {
+               v4l2_qbuf(v4l2, buffers[i]);
+       }
+
+       v4l2_streamon(v4l2);
+       for (i = 1; i < CNT; i++) {
+
+               capt = v4l2_dqbuf(v4l2);
+               if(active_thread == tid) {
+                       switch(data->area) {
+                       case FULL:
+                               ret = disp_post_vid_buffer(disp, capt,
+                                       0, 0, width, height);
+                       break;
+                       case OVERLAY:
+                               ret = disp_post_vid_buffer(disp, capt,
+                                       0, 0, width, height);
+                       break;
+                       }
+                       if (ret) {
+                               MSG("Quitting");
+                               return NULL;
+                       }
+               }
+               v4l2_qbuf(v4l2, capt);
+       }
+       v4l2_streamoff(v4l2);
+
+       MSG("Ok!");
+       return disp;
+}
+
 int
 main(int argc, char **argv)
 {
        struct display *disp;
        struct v4l2 *v4l2;
-       struct buffer *framebuf;
-       struct buffer **buffers;
-       uint32_t fourcc, width, height;
-       int ret, i;
+       pthread_t threads[MAX_CAP];
+       struct thr_data tdata[MAX_CAP];
+       void *result = NULL;
+       int ret = 0, i, multi = 1, idx = 0;
+       char c;
 
        MSG("Opening Display..");
        disp = disp_open(argc, argv);
@@ -48,11 +135,32 @@ main(int argc, char **argv)
                return 1;
        }
 
-       MSG("Opening V4L2..");
-       v4l2 = v4l2_open(argc, argv, &fourcc, &width, &height);
-       if (!v4l2) {
-               usage(argv[0]);
-               return 1;
+       for (i = 1; i < argc; i++) {
+               if (!argv[i])
+                       continue;
+
+               if (!strcmp("--multi", argv[i])) {
+                       argv[i++] = NULL;
+                       sscanf(argv[i], "%d", &multi);
+                       argv[i] = NULL;
+                       if(multi < 1 || multi > MAX_CAP) {
+                               usage(argv[i]);
+                               return 1;
+                       }
+               }
+       }
+
+       for (i = 0; i < multi; i++) {
+               MSG("Opening V4L2..");
+               v4l2 = v4l2_open(argc, argv, &tdata[i].fourcc,
+                       &tdata[i].width, &tdata[i].height);
+               if (!v4l2) {
+                       usage(argv[0]);
+                       return 1;
+               }
+               tdata[i].disp = disp;
+               tdata[i].v4l2 = v4l2;
+               tdata[i].area = FULL;
        }
 
        if (check_args(argc, argv)) {
@@ -61,32 +169,28 @@ main(int argc, char **argv)
                return 0;
        }
 
-       framebuf = disp_get_fb(disp);
-
-       buffers = disp_get_vid_buffers(disp, NBUF, fourcc, width, height);
-       if (!buffers) {
-               return 1;
+       for (i = 0; i < multi; i++) {
+               ret = pthread_create(&threads[i], NULL, capture_loop, &tdata[i]);
+               if(ret) {
+                       MSG("Failed creating thread");
+               }
+               MSG("Failed creating thread");
        }
+       active_thread = threads[0];
 
-       ret = v4l2_reqbufs(v4l2, buffers, NBUF);
-       if (ret) {
-               return 1;
+       while(1) {
+               c = getchar();
+               if(c == 's') {
+                       idx = (idx + 1) % multi;
+                       active_thread = threads[idx];
+               }
        }
 
-       v4l2_qbuf(v4l2, buffers[0]);
-       v4l2_streamon(v4l2);
-       for (i = 1; i < CNT; i++) {
-               v4l2_qbuf(v4l2, buffers[i % NBUF]);
-               ret = disp_post_vid_buffer(disp, v4l2_dqbuf(v4l2),
-                               0, 0, width, height);
-               if (ret) {
-                       return ret;
-               }
+       for (i = 0; i < multi; i++) {
+               pthread_join(threads[i], &result);
        }
-       v4l2_streamoff(v4l2);
-       v4l2_dqbuf(v4l2);
 
-       MSG("Ok!");
+       disp_close(disp);
 
        return ret;
 }