aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Parrot2017-07-24 14:23:02 -0500
committerNikhil Devshatwar2017-07-26 03:11:34 -0500
commitb82d81988a7bc6e609f603c5f66d8b4b9569b155 (patch)
treed1df6ab2e96fe29e6cfad56d6c8c4f12c00e7560
parent58e24a30b14b8b90a19eeb5c5a10fd2d26d8e6d5 (diff)
downloadomapdrmtest-b82d81988a7bc6e609f603c5f66d8b4b9569b155.tar.gz
omapdrmtest-b82d81988a7bc6e609f603c5f66d8b4b9569b155.tar.xz
omapdrmtest-b82d81988a7bc6e609f603c5f66d8b4b9569b155.zip
v4l2: Fix white-space issue and compile warning
Signed-off-by: Benoit Parrot <bparrot@ti.com>
-rw-r--r--util/v4l2.c100
1 files changed, 47 insertions, 53 deletions
diff --git a/util/v4l2.c b/util/v4l2.c
index 5e5e5bf..7d16eaf 100644
--- a/util/v4l2.c
+++ b/util/v4l2.c
@@ -36,8 +36,7 @@ struct v4l2 {
36 struct buffer **bufs; 36 struct buffer **bufs;
37}; 37};
38 38
39void 39void v4l2_usage(void)
40v4l2_usage(void)
41{ 40{
42 MSG("V4L2 Capture Options:"); 41 MSG("V4L2 Capture Options:");
43 MSG("\t-c WxH@fourcc\tset capture dimensions/format"); 42 MSG("\t-c WxH@fourcc\tset capture dimensions/format");
@@ -112,9 +111,8 @@ MSG("\tfound entity: %s type=%08x, flags=%08x, group_id=%d, pads=%d, links=%d",
112entity->name, entity->type, entity->flags, entity->group_id, 111entity->name, entity->type, entity->flags, entity->group_id,
113entity->pads, entity->links); 112entity->pads, entity->links);
114 113
115 if ((entity->type == type) || (entity->id == entity_id)) { 114 if ((entity->type == type) || (entity->id == entity_id))
116 return 0; 115 return 0;
117 }
118 } 116 }
119 117
120 return ret; 118 return ret;
@@ -139,16 +137,16 @@ media_configure(struct media_entity_desc *entity,
139 137
140 fd = media_open_entity(entity); 138 fd = media_open_entity(entity);
141 if (fd < 0) { 139 if (fd < 0) {
142 ERROR("could not open media device: \"%s\" (%d:%d)", entity->name, 140 ERROR("could not open media device: \"%s\" (%d:%d)",
143 entity->v4l.major, entity->v4l.minor); 141 entity->name,
142 entity->v4l.major, entity->v4l.minor);
144 return; 143 return;
145 } 144 }
146 145
147 MSG("Setting format for: \"%s\" (%d)", entity->name, pad); 146 MSG("Setting format for: \"%s\" (%d)", entity->name, pad);
148 ret = ioctl(fd, VIDIOC_SUBDEV_S_FMT, &ent_format); 147 ret = ioctl(fd, VIDIOC_SUBDEV_S_FMT, &ent_format);
149 if (ret) { 148 if (ret)
150 MSG("Could not configure: %s (%d)", strerror(errno), ret); 149 MSG("Could not configure: %s (%d)", strerror(errno), ret);
151 }
152} 150}
153 151
154/* walk the graph and attempt to configure all the nodes to the same settings. 152/* walk the graph and attempt to configure all the nodes to the same settings.
@@ -164,14 +162,14 @@ media_setup(struct v4l2_format *format)
164 162
165 fd = open("/dev/media0", O_RDWR); 163 fd = open("/dev/media0", O_RDWR);
166 if (fd < 0) { 164 if (fd < 0) {
167 ERROR("could not open MCF: %s (%d)", strerror(errno), ret); 165 ERROR("could not open MCF: %s (%d)", strerror(errno), errno);
168 return fd; 166 return fd;
169 } 167 }
170 168
171 ret = media_find_entity(fd, &entity, MEDIA_ENT_T_V4L2_SUBDEV_SENSOR, ~0); 169 ret = media_find_entity(fd, &entity,
172 if (ret) { 170 MEDIA_ENT_T_V4L2_SUBDEV_SENSOR, ~0);
171 if (ret)
173 return ret; 172 return ret;
174 }
175 173
176 /* now walk the graph to the output, configure everything on the way: */ 174 /* now walk the graph to the output, configure everything on the way: */
177 do { 175 do {
@@ -191,27 +189,30 @@ media_setup(struct v4l2_format *format)
191 189
192 for (i = 0; i < entity.links; i++) { 190 for (i = 0; i < entity.links; i++) {
193 if (links[i].source.entity == entity.id) { 191 if (links[i].source.entity == entity.id) {
194 // XXX maybe if there are multiple links, we should prefer 192 /*
195 // an enabled link, otherwise just pick one.. 193 * XXX maybe if there are multiple links, we
196 194 * should prefer an enabled link, otherwise
197 media_configure(&entity, format, links[i].source.index); 195 * just pick one..
198 media_configure(&entity, format, links[i].sink.index); 196 */
197 media_configure(&entity, format,
198 links[i].source.index);
199 media_configure(&entity, format,
200 links[i].sink.index);
199 201
200 /* lets take this link.. */ 202 /* lets take this link.. */
201 if (!(links[i].flags & MEDIA_LNK_FL_ENABLED)) { 203 if (!(links[i].flags & MEDIA_LNK_FL_ENABLED)) {
202 links[i].flags |= MEDIA_LNK_FL_ENABLED; 204 links[i].flags |= MEDIA_LNK_FL_ENABLED;
203 ret = ioctl(fd, MEDIA_IOC_SETUP_LINK, &links[i]); 205 ret = ioctl(fd, MEDIA_IOC_SETUP_LINK,
204 if (ret) { 206 &links[i]);
207 if (ret)
205 ERROR("MEDIA_IOC_SETUP_LINK failed: %s (%d)", 208 ERROR("MEDIA_IOC_SETUP_LINK failed: %s (%d)",
206 strerror(errno), errno); 209 strerror(errno), errno);
207// return ret;
208 }
209 } 210 }
210 211
211 ret = media_find_entity(fd, &entity, ~0, links[i].sink.entity); 212 ret = media_find_entity(fd, &entity, ~0,
212 if (ret) { 213 links[i].sink.entity);
214 if (ret)
213 return ret; 215 return ret;
214 }
215 216
216 break; 217 break;
217 } 218 }
@@ -233,6 +234,7 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
233 int i, ret; 234 int i, ret;
234 bool mcf = false, user_format = false, user_dev = false; 235 bool mcf = false, user_format = false, user_dev = false;
235 char devname[20] = "/dev/video1"; 236 char devname[20] = "/dev/video1";
237 char fourccstr[5];
236 238
237 v4l2 = calloc(1, sizeof(*v4l2)); 239 v4l2 = calloc(1, sizeof(*v4l2));
238 240
@@ -240,11 +242,10 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
240 * that it is already parsed (since the arg parsing is decentralized) 242 * that it is already parsed (since the arg parsing is decentralized)
241 */ 243 */
242 for (i = 1; i < argc; i++) { 244 for (i = 1; i < argc; i++) {
243 if (!argv[i]) { 245 if (!argv[i])
244 continue; 246 continue;
245 }
246 if (!strcmp("-d", argv[i])) { 247 if (!strcmp("-d", argv[i])) {
247 if(user_dev) 248 if (user_dev)
248 continue; 249 continue;
249 250
250 argv[i++] = NULL; 251 argv[i++] = NULL;
@@ -254,10 +255,9 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
254 } 255 }
255 user_dev = true; 256 user_dev = true;
256 } else if (!strcmp("-c", argv[i])) { 257 } else if (!strcmp("-c", argv[i])) {
257 if(user_format) 258 if (user_format)
258 continue; 259 continue;
259 260
260 char fourccstr[5];
261 argv[i++] = NULL; 261 argv[i++] = NULL;
262 if (sscanf(argv[i], "%ux%u@%4s", 262 if (sscanf(argv[i], "%ux%u@%4s",
263 width, 263 width,
@@ -288,7 +288,7 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
288 format.fmt.pix.pixelformat = *fourcc; 288 format.fmt.pix.pixelformat = *fourcc;
289 format.fmt.pix.width = *width; 289 format.fmt.pix.width = *width;
290 format.fmt.pix.height = *height; 290 format.fmt.pix.height = *height;
291 if(*fourcc == FOURCC_STR("AR24")) 291 if (*fourcc == FOURCC_STR("AR24"))
292 format.fmt.pix.pixelformat = FOURCC_STR("RGB4"); 292 format.fmt.pix.pixelformat = FOURCC_STR("RGB4");
293 293
294 } 294 }
@@ -304,9 +304,8 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
304 304
305 if (mcf) { 305 if (mcf) {
306 ret = media_setup(&format); 306 ret = media_setup(&format);
307 if (ret < 0) { 307 if (ret < 0)
308 goto fail; 308 goto fail;
309 }
310 } 309 }
311 310
312 ret = ioctl(v4l2->fd, VIDIOC_S_FMT, &format); 311 ret = ioctl(v4l2->fd, VIDIOC_S_FMT, &format);
@@ -318,7 +317,6 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
318 return v4l2; 317 return v4l2;
319 318
320fail: 319fail:
321 // XXX cleanup
322 return NULL; 320 return NULL;
323} 321}
324 322
@@ -331,10 +329,10 @@ v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n)
331 .count = n, 329 .count = n,
332 }; 330 };
333 uint32_t i; 331 uint32_t i;
334 int ret,dmafd; 332 int ret, dmafd;
335 333
336 if (v4l2->v4l2bufs) { 334 if (v4l2->v4l2bufs) {
337 // maybe eventually need to support this? 335 /* maybe eventually need to support this? */
338 ERROR("already reqbuf'd"); 336 ERROR("already reqbuf'd");
339 return -1; 337 return -1;
340 } 338 }
@@ -379,7 +377,8 @@ v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n)
379 ret = ioctl(v4l2->fd, VIDIOC_QUERYBUF, &v4l2->v4l2bufs[i]); 377 ret = ioctl(v4l2->fd, VIDIOC_QUERYBUF, &v4l2->v4l2bufs[i]);
380 v4l2->v4l2bufs[i].m.fd = dmafd; 378 v4l2->v4l2bufs[i].m.fd = dmafd;
381 if (ret) { 379 if (ret) {
382 ERROR("VIDIOC_QUERYBUF failed: %s (%d)", strerror(errno), ret); 380 ERROR("VIDIOC_QUERYBUF failed: %s (%d)",
381 strerror(errno), ret);
383 return ret; 382 return ret;
384 } 383 }
385 } 384 }
@@ -393,13 +392,12 @@ v4l2_streamon(struct v4l2 *v4l2)
393 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 392 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
394 int ret; 393 int ret;
395 394
396 ret = ioctl(v4l2->fd, VIDIOC_STREAMON, &type); 395 ret = ioctl(v4l2->fd, VIDIOC_STREAMON, &type);
397 396
398 if (ret) { 397 if (ret)
399 ERROR("VIDIOC_STREAMON failed: %s (%d)", strerror(errno), ret); 398 ERROR("VIDIOC_STREAMON failed: %s (%d)", strerror(errno), ret);
400 }
401 399
402 return ret; 400 return ret;
403} 401}
404 402
405int 403int
@@ -408,13 +406,12 @@ v4l2_streamoff(struct v4l2 *v4l2)
408 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 406 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
409 int ret; 407 int ret;
410 408
411 ret = ioctl(v4l2->fd, VIDIOC_STREAMOFF, &type); 409 ret = ioctl(v4l2->fd, VIDIOC_STREAMOFF, &type);
412 410
413 if (ret) { 411 if (ret)
414 ERROR("VIDIOC_STREAMOFF failed: %s (%d)", strerror(errno), ret); 412 ERROR("VIDIOC_STREAMOFF failed: %s (%d)", strerror(errno), ret);
415 }
416 413
417 return ret; 414 return ret;
418} 415}
419 416
420int 417int
@@ -433,9 +430,8 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
433 fd = buf->fd[0]; 430 fd = buf->fd[0];
434 431
435 for (i = 0; i < v4l2->nbufs; i++) { 432 for (i = 0; i < v4l2->nbufs; i++) {
436 if (v4l2->v4l2bufs[i].m.fd == fd) { 433 if (v4l2->v4l2bufs[i].m.fd == fd)
437 v4l2buf = &v4l2->v4l2bufs[i]; 434 v4l2buf = &v4l2->v4l2bufs[i];
438 }
439 } 435 }
440 436
441 tid = pthread_self(); 437 tid = pthread_self();
@@ -444,7 +440,7 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
444 disp_time.tv_usec = now.tv_nsec / 1000; 440 disp_time.tv_usec = now.tv_nsec / 1000;
445 timersub(&disp_time, &v4l2buf->timestamp, &disp_lat); 441 timersub(&disp_time, &v4l2buf->timestamp, &disp_lat);
446 if(v4l2buf->timestamp.tv_sec) 442 if(v4l2buf->timestamp.tv_sec)
447 DBG("%x: DISP latency = %d.%6d", tid, disp_lat.tv_sec, disp_lat.tv_usec); 443 DBG("%lx: DISP latency = %ld.%6ld", tid, disp_lat.tv_sec, disp_lat.tv_usec);
448 444
449 if (!v4l2buf) { 445 if (!v4l2buf) {
450 ERROR("invalid buffer"); 446 ERROR("invalid buffer");
@@ -453,9 +449,8 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
453 449
454 ret = ioctl(v4l2->fd, VIDIOC_QBUF, v4l2buf); 450 ret = ioctl(v4l2->fd, VIDIOC_QBUF, v4l2buf);
455 v4l2buf->m.fd = buf->fd[0]; 451 v4l2buf->m.fd = buf->fd[0];
456 if (ret) { 452 if (ret)
457 ERROR("VIDIOC_QBUF failed: %s (%d)", strerror(errno), ret); 453 ERROR("VIDIOC_QBUF failed: %s (%d)", strerror(errno), ret);
458 }
459 454
460 return ret; 455 return ret;
461} 456}
@@ -476,9 +471,8 @@ v4l2_dqbuf(struct v4l2 *v4l2)
476 int ret; 471 int ret;
477 472
478 ret = ioctl(v4l2->fd, VIDIOC_DQBUF, &v4l2buf); 473 ret = ioctl(v4l2->fd, VIDIOC_DQBUF, &v4l2buf);
479 if (ret) { 474 if (ret)
480 ERROR("VIDIOC_DQBUF failed: %s (%d)", strerror(errno), ret); 475 ERROR("VIDIOC_DQBUF failed: %s (%d)", strerror(errno), ret);
481 }
482 476
483 buf = v4l2->bufs[v4l2buf.index]; 477 buf = v4l2->bufs[v4l2buf.index];
484 v4l2->v4l2bufs[v4l2buf.index].timestamp = v4l2buf.timestamp; 478 v4l2->v4l2bufs[v4l2buf.index].timestamp = v4l2buf.timestamp;
@@ -490,7 +484,7 @@ v4l2_dqbuf(struct v4l2 *v4l2)
490 dq_time.tv_sec = now.tv_sec; 484 dq_time.tv_sec = now.tv_sec;
491 dq_time.tv_usec = now.tv_nsec / 1000; 485 dq_time.tv_usec = now.tv_nsec / 1000;
492 timersub(&dq_time, &v4l2buf.timestamp, &dq_lat); 486 timersub(&dq_time, &v4l2buf.timestamp, &dq_lat);
493 DBG("%x: DQ latency = %d.%6d", tid, dq_lat.tv_sec, dq_lat.tv_usec); 487 DBG("%lx: DQ latency = %ld.%6ld", tid, dq_lat.tv_sec, dq_lat.tv_usec);
494 488
495 return buf; 489 return buf;
496} 490}