ab6e1d67098759ad030743a20094ddcccf742fa6
1 /*
2 * Copyright (C) 2011 Texas Instruments
3 * Author: Rob Clark <rob.clark@linaro.org>
4 * Adopted for testing VIP capture by: Nikhil Devshatwar <nikhil.nd@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
20 #include <pthread.h>
21 #include "util.h"
23 #define NBUF 6
24 #define CNT 500000
25 #define MAX_CAP 6
27 struct thr_data {
28 struct display *disp;
29 struct v4l2 *v4l2;
30 uint32_t fourcc, width, height;
31 };
33 static void
34 usage(char *name)
35 {
36 MSG("Usage: %s [OPTION]...", name);
37 MSG("Test of buffer passing between v4l2 camera and display.");
38 MSG("");
39 MSG("viddec3test options:");
40 MSG("\t-h, --help: Print this help and exit.");
41 MSG("\t--multi <num>: Capture from <num> different devices.");
42 MSG("\t\t\tEach device name and format would be parsed in the cmdline");
43 MSG("");
44 disp_usage();
45 v4l2_usage();
46 }
48 void *
49 capture_loop(void *arg)
50 {
51 struct thr_data *data = (struct thr_data *)arg;
52 struct display *disp = data->disp;
53 struct v4l2 *v4l2 = data->v4l2;
54 uint32_t fourcc = data->fourcc;
55 uint32_t width = data->width, height = data->height;
57 struct buffer **buffers, *capt;
58 int ret, i;
60 buffers = disp_get_vid_buffers(disp, NBUF, fourcc, width, height);
61 if (!buffers) {
62 return NULL;
63 }
65 ret = v4l2_reqbufs(v4l2, buffers, NBUF);
66 if (ret) {
67 return NULL;
68 }
70 for (i = 0; i < NBUF; i++) {
71 v4l2_qbuf(v4l2, buffers[i]);
72 }
74 v4l2_streamon(v4l2);
75 for (i = 1; i < CNT; i++) {
77 capt = v4l2_dqbuf(v4l2);
78 ret = disp_post_vid_buffer(disp, capt,
79 0, 0, width, height);
80 if (ret) {
81 ERROR("Post buffer failed");
82 return NULL;
83 }
84 v4l2_qbuf(v4l2, capt);
85 }
86 v4l2_streamoff(v4l2);
88 MSG("Ok!");
89 return disp;
90 }
92 int
93 main(int argc, char **argv)
94 {
95 struct display *disp;
96 struct v4l2 *v4l2;
97 pthread_t threads[MAX_CAP];
98 struct thr_data tdata[MAX_CAP];
99 void *result = NULL;
100 int ret = 0, i, multi = 1, idx = 0;
101 char c;
103 MSG("Opening Display..");
104 disp = disp_open(argc, argv);
105 if (!disp) {
106 usage(argv[0]);
107 return 1;
108 }
110 for (i = 1; i < argc; i++) {
111 if (!argv[i])
112 continue;
114 if (!strcmp("--multi", argv[i])) {
115 argv[i++] = NULL;
116 sscanf(argv[i], "%d", &multi);
117 argv[i] = NULL;
118 if(multi < 1 || multi > MAX_CAP) {
119 usage(argv[i]);
120 return 1;
121 }
122 }
123 }
125 for (i = 0; i < multi; i++) {
126 MSG("Opening V4L2..");
127 v4l2 = v4l2_open(argc, argv, &tdata[i].fourcc,
128 &tdata[i].width, &tdata[i].height);
129 if (!v4l2) {
130 usage(argv[0]);
131 return 1;
132 }
133 tdata[i].disp = disp;
134 tdata[i].v4l2 = v4l2;
135 }
137 if (check_args(argc, argv)) {
138 /* remaining args.. print usage msg */
139 usage(argv[0]);
140 return 0;
141 }
143 for (i = 0; i < multi; i++) {
144 ret = pthread_create(&threads[i], NULL, capture_loop, &tdata[i]);
145 if(ret) {
146 MSG("Failed creating thread");
147 }
148 }
150 for (i = 0; i < multi; i++) {
151 pthread_join(threads[i], &result);
152 }
154 disp_close(disp);
156 return ret;
157 }