diff options
author | Prasad, Ram | 2017-11-20 09:57:44 -0600 |
---|---|---|
committer | Ramprasad N | 2018-01-19 04:06:53 -0600 |
commit | 375b2961f89e3d3f85ae610db7290c72b145295c (patch) | |
tree | 2a37d80cbeac40d71e7db94275921f31f7de5b32 | |
parent | 509daaa06dbf96651f92c3ebab89e1f8394b3039 (diff) | |
download | example-applications-375b2961f89e3d3f85ae610db7290c72b145295c.tar.gz example-applications-375b2961f89e3d3f85ae610db7290c72b145295c.tar.xz example-applications-375b2961f89e3d3f85ae610db7290c72b145295c.zip |
test-v4l2-m2m: Add support for cropping with vpe
Add cropping support on vpe's OUTPUT plane.
It is an optional argument in command line
Application respects crop if given in below format
crop=widthxheight@left,top
Signed-off-by: Ramprasad N <x0038811@ti.com>
-rw-r--r-- | v4l2-m2m/test-v4l2-m2m.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/v4l2-m2m/test-v4l2-m2m.c b/v4l2-m2m/test-v4l2-m2m.c index 930c4e2..0a5e9b0 100644 --- a/v4l2-m2m/test-v4l2-m2m.c +++ b/v4l2-m2m/test-v4l2-m2m.c | |||
@@ -464,7 +464,35 @@ void do_write (char *str, int fd, void *addr, int size) { | |||
464 | printf ("Total bytes written %s = %d\n", str, size); | 464 | printf ("Total bytes written %s = %d\n", str, size); |
465 | } | 465 | } |
466 | } | 466 | } |
467 | static void parse_crop(const char *p, struct v4l2_selection *s) | ||
468 | { | ||
469 | char *end; | ||
470 | |||
471 | p = p+5; | ||
472 | |||
473 | s->r.width = strtoul(p, &end, 10); | ||
474 | if (*end != 'x') | ||
475 | goto fail; | ||
476 | |||
477 | p = end + 1; | ||
478 | s->r.height = strtoul(p, &end, 10); | ||
479 | if (*end != '@') | ||
480 | goto fail; | ||
467 | 481 | ||
482 | p = end + 1; | ||
483 | s->r.left = strtoul(p, &end, 10); | ||
484 | if (*end != ',') | ||
485 | goto fail; | ||
486 | |||
487 | p = end + 1; | ||
488 | s->r.top = strtoul(p, &end, 10); | ||
489 | |||
490 | return; | ||
491 | |||
492 | fail: | ||
493 | s->r.height = 0; | ||
494 | return; | ||
495 | } | ||
468 | int main ( | 496 | int main ( |
469 | int argc, | 497 | int argc, |
470 | char *argv[]) | 498 | char *argv[]) |
@@ -492,15 +520,17 @@ int main ( | |||
492 | int translen = 3; | 520 | int translen = 3; |
493 | int frame_no = 0; | 521 | int frame_no = 0; |
494 | struct v4l2_control ctrl; | 522 | struct v4l2_control ctrl; |
523 | struct v4l2_selection selection; | ||
495 | struct timeval now; | 524 | struct timeval now; |
496 | int latency; | 525 | int latency; |
497 | int field; | 526 | int field; |
498 | 527 | ||
499 | if (argc < 12 || argc > 13) { | 528 | if (argc < 12 || argc > 14) { |
500 | printf ( | 529 | printf ( |
501 | "USAGE : <Devicename> <SRCfilename> <SRCWidth> <SRCHeight> <SRCFormat> " | 530 | "USAGE : <Devicename> <SRCfilename> <SRCWidth> <SRCHeight> <SRCFormat> " |
502 | "<DSTfilename> <DSTWidth> <DSTHeight> <DSTformat> " | 531 | "<DSTfilename> <DSTWidth> <DSTHeight> <DSTformat> " |
503 | "<interlace> <translen> <numframes>[optional]\n"); | 532 | "<interlace> <translen> <numframes>[optional] " |
533 | "crop=widthxheight@x,y[optional]\n"); | ||
504 | 534 | ||
505 | return 1; | 535 | return 1; |
506 | } | 536 | } |
@@ -521,15 +551,29 @@ int main ( | |||
521 | interlace = atoi (argv[10]); | 551 | interlace = atoi (argv[10]); |
522 | translen = atoi (argv[11]); | 552 | translen = atoi (argv[11]); |
523 | 553 | ||
524 | if (argc == 13) | 554 | selection.r.top = selection.r.left = 0; |
525 | num_frames = atoi (argv[12]); | 555 | selection.r.width = 0; |
556 | selection.r.height = 0; | ||
557 | selection.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | ||
558 | selection.target = V4L2_SEL_TGT_CROP_ACTIVE; | ||
526 | 559 | ||
560 | if (argc == 13 && !strstr(argv[12], "crop=")) | ||
561 | num_frames = atoi (argv[12]); | ||
562 | else if (argc == 13 && strstr(argv[12], "crop=")) | ||
563 | parse_crop (argv[12], &selection); | ||
564 | else if(argc == 14) { | ||
565 | num_frames = atoi (argv[12]); | ||
566 | if(strstr(argv[13], "crop=")) | ||
567 | parse_crop (argv[13], &selection); | ||
568 | } | ||
527 | printf ("Input @ %d = %d x %d , %d\nOutput @ %d = %d x %d , %d\n", | 569 | printf ("Input @ %d = %d x %d , %d\nOutput @ %d = %d x %d , %d\n", |
528 | fin, srcWidth, srcHeight, srcFourcc, | 570 | fin, srcWidth, srcHeight, srcFourcc, |
529 | fout, dstWidth, dstHeight, dstFourcc); | 571 | fout, dstWidth, dstHeight, dstFourcc); |
530 | 572 | ||
531 | if ( fin < 0 || srcHeight < 0 || srcWidth < 0 || srcFourcc < 0 || \ | 573 | if ( fin < 0 || srcHeight < 0 || srcWidth < 0 || srcFourcc < 0 || \ |
532 | fout < 0 || dstHeight < 0 || dstWidth < 0 || dstFourcc < 0 || \ | 574 | fout < 0 || dstHeight < 0 || dstWidth < 0 || dstFourcc < 0 || \ |
575 | selection.r.top < 0 || selection.r.left < 0 || \ | ||
576 | selection.r.width < 0 || selection.r.height < 0 || \ | ||
533 | interlace < 0 || translen < 0 || num_frames < 0) { | 577 | interlace < 0 || translen < 0 || num_frames < 0) { |
534 | printf("ERROR: Invalid arguments\n"); | 578 | printf("ERROR: Invalid arguments\n"); |
535 | /** TODO:Handle errors precisely */ | 579 | /** TODO:Handle errors precisely */ |
@@ -562,6 +606,7 @@ int main ( | |||
562 | pexit("Can't set translen control\n"); | 606 | pexit("Can't set translen control\n"); |
563 | 607 | ||
564 | printf("S_CTRL success\n"); | 608 | printf("S_CTRL success\n"); |
609 | |||
565 | } | 610 | } |
566 | 611 | ||
567 | /* Allocate buffers for CAPTURE and OUTPUT stream */ | 612 | /* Allocate buffers for CAPTURE and OUTPUT stream */ |
@@ -579,6 +624,13 @@ int main ( | |||
579 | pexit("Cant Allocate buffurs for CAPTURE device\n"); | 624 | pexit("Cant Allocate buffurs for CAPTURE device\n"); |
580 | } | 625 | } |
581 | 626 | ||
627 | if (selection.r.height > 0) { | ||
628 | ret = ioctl(fd, VIDIOC_S_SELECTION, &selection); | ||
629 | if (ret < 0) | ||
630 | pexit("error setting selection\n"); | ||
631 | |||
632 | printf("S_SELECTION success\n"); | ||
633 | } | ||
582 | /** Queue All empty buffers (Available to capture in) */ | 634 | /** Queue All empty buffers (Available to capture in) */ |
583 | ret = queueAllBuffers (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, dst_numbuf); | 635 | ret = queueAllBuffers (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, dst_numbuf); |
584 | if(ret < 0) { | 636 | if(ret < 0) { |