diff options
author | Pooja Prajod | 2016-09-29 10:00:22 -0500 |
---|---|---|
committer | Pooja Prajod | 2016-09-29 10:10:32 -0500 |
commit | c3f20b080571f5f363bfb7e0956b6c56004004f8 (patch) | |
tree | 40b17464e6a6bc8b713fa57510bf7fe5831bb983 | |
parent | a30dd9a5fc1ae7cdfb8c17a4685efb7eaf693ddc (diff) | |
download | omapdrmtest-c3f20b080571f5f363bfb7e0956b6c56004004f8.tar.gz omapdrmtest-c3f20b080571f5f363bfb7e0956b6c56004004f8.tar.xz omapdrmtest-c3f20b080571f5f363bfb7e0956b6c56004004f8.zip |
Add signal handler for viddec3test and videnc2test
This patch adds a signal handler for SIGINT signal.
This is a sample handler which can be extended further.
Signed-off-by: Pooja Prajod <a0132412@ti.com>
-rw-r--r-- | viddec3test.c | 90 | ||||
-rw-r--r-- | videnc2test.c | 25 |
2 files changed, 102 insertions, 13 deletions
diff --git a/viddec3test.c b/viddec3test.c index edaaf41..8c57ed9 100644 --- a/viddec3test.c +++ b/viddec3test.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <xf86drm.h> | 21 | #include <xf86drm.h> |
22 | #include <omap_drm.h> | 22 | #include <omap_drm.h> |
23 | #include <omap_drmif.h> | 23 | #include <omap_drmif.h> |
24 | #include <signal.h> | ||
25 | #include <unistd.h> | ||
24 | 26 | ||
25 | #include <pthread.h> | 27 | #include <pthread.h> |
26 | 28 | ||
@@ -55,8 +57,13 @@ struct decoder { | |||
55 | int num_outBuf; | 57 | int num_outBuf; |
56 | size_t *outBuf_fd; | 58 | size_t *outBuf_fd; |
57 | suseconds_t tdisp; | 59 | suseconds_t tdisp; |
60 | int id; | ||
58 | }; | 61 | }; |
59 | 62 | ||
63 | |||
64 | struct decoder *decoders[8] = {}; | ||
65 | int ndecoders = 0; | ||
66 | |||
60 | /* When true, do not actually call VIDDEC3_process. For benchmarking. */ | 67 | /* When true, do not actually call VIDDEC3_process. For benchmarking. */ |
61 | static int no_process = 0; | 68 | static int no_process = 0; |
62 | static int inloop = 0; | 69 | static int inloop = 0; |
@@ -105,17 +112,19 @@ decoder_close(struct decoder *decoder) | |||
105 | if (dev) dce_deinit(dev); | 112 | if (dev) dce_deinit(dev); |
106 | if (decoder->demux) demux_deinit(decoder->demux); | 113 | if (decoder->demux) demux_deinit(decoder->demux); |
107 | if (decoder->disp) disp_close(decoder->disp); | 114 | if (decoder->disp) disp_close(decoder->disp); |
108 | if(decoder) free(decoder); | 115 | if(decoder) { |
116 | free(decoder); | ||
117 | } | ||
109 | } | 118 | } |
110 | } | 119 | } |
111 | 120 | ||
112 | static struct decoder * | 121 | static struct decoder * |
113 | decoder_open(int argc, char **argv) | 122 | decoder_open(int argc, char **argv) |
114 | { | 123 | { |
115 | static struct decoder *decoder = NULL; | 124 | struct decoder *decoder = NULL; |
116 | char *infile = NULL; | 125 | char *infile = NULL; |
117 | int i; | 126 | int i; |
118 | static int width, height, padded_width, padded_height; | 127 | int width, height, padded_width, padded_height; |
119 | Engine_Error ec; | 128 | Engine_Error ec; |
120 | XDAS_Int32 err; | 129 | XDAS_Int32 err; |
121 | 130 | ||
@@ -413,7 +422,7 @@ decoder_process(struct decoder *decoder) | |||
413 | /* get the output buffer and write it to file */ | 422 | /* get the output buffer and write it to file */ |
414 | buf = (struct buffer *)outArgs->outputID[i]; | 423 | buf = (struct buffer *)outArgs->outputID[i]; |
415 | if(!no_process) | 424 | if(!no_process) |
416 | disp_post_vid_buffer(decoder->disp, buf, | 425 | disp_post_vid_buffer(decoder->disp, buf, |
417 | r->topLeft.x, r->topLeft.y, | 426 | r->topLeft.x, r->topLeft.y, |
418 | r->bottomRight.x - r->topLeft.x, | 427 | r->bottomRight.x - r->topLeft.x, |
419 | r->bottomRight.y - r->topLeft.y); | 428 | r->bottomRight.y - r->topLeft.y); |
@@ -445,6 +454,24 @@ decoder_process(struct decoder *decoder) | |||
445 | return (inBufs->numBufs > 0) ? 0 : -1; | 454 | return (inBufs->numBufs > 0) ? 0 : -1; |
446 | } | 455 | } |
447 | 456 | ||
457 | /* Returns 1 (true) if the mutex is unlocked, which is the | ||
458 | * thread's signal to terminate. | ||
459 | */ | ||
460 | |||
461 | pthread_mutex_t mtx; | ||
462 | |||
463 | int needQuit() | ||
464 | { | ||
465 | switch(pthread_mutex_trylock(&mtx)) { | ||
466 | case 0: /* if we got the lock, unlock and return 1 (true) */ | ||
467 | pthread_mutex_unlock(&mtx); | ||
468 | return 1; | ||
469 | case EBUSY: /* return 0 (false) if the mutex was locked */ | ||
470 | return 0; | ||
471 | } | ||
472 | return 1; | ||
473 | } | ||
474 | |||
448 | void *decode_stream(void *decoderHandle) | 475 | void *decode_stream(void *decoderHandle) |
449 | { | 476 | { |
450 | int ret = 0; | 477 | int ret = 0; |
@@ -452,20 +479,53 @@ void *decode_stream(void *decoderHandle) | |||
452 | int n = 0; | 479 | int n = 0; |
453 | if(!decoder) goto exit; | 480 | if(!decoder) goto exit; |
454 | 481 | ||
455 | while((ret = decoder_process(decoder)) == 0); | 482 | while((ret = decoder_process(decoder)) == 0) { |
483 | if(needQuit()){ | ||
484 | inloop = 1; | ||
485 | break; | ||
486 | } | ||
487 | } | ||
456 | if((ret != -1 && ret != 0) && inloop) inloop = 1; /*Assuming Good case. Otherwise logic gets messy*/ | 488 | if((ret != -1 && ret != 0) && inloop) inloop = 1; /*Assuming Good case. Otherwise logic gets messy*/ |
457 | decoder_close(decoder); | 489 | int i = decoder->id; |
490 | decoder_close(decoder); | ||
491 | decoders[i]=NULL; | ||
458 | exit: | 492 | exit: |
459 | return NULL; | 493 | return NULL; |
460 | } | 494 | } |
461 | 495 | ||
496 | |||
497 | static void sig_handler(int signo) | ||
498 | { | ||
499 | if (signo == SIGINT) { | ||
500 | int i=0; | ||
501 | pthread_mutex_unlock(&mtx); | ||
502 | sleep(1); | ||
503 | exit(0); | ||
504 | } | ||
505 | } | ||
506 | |||
507 | |||
462 | int | 508 | int |
463 | main(int argc, char **argv) | 509 | main(int argc, char **argv) |
464 | { | 510 | { |
465 | struct decoder *decoders[8] = {}; | ||
466 | int i, first = 0, ndecoders = 0; | ||
467 | 511 | ||
468 | for (i = 1; i < argc; i++) { | 512 | int i, first = 0; |
513 | |||
514 | struct sigaction sa; | ||
515 | |||
516 | sa.sa_handler = sig_handler; | ||
517 | sigemptyset(&sa.sa_mask); | ||
518 | sa.sa_flags = 0; | ||
519 | |||
520 | if (sigaction(SIGINT, &sa, NULL) == -1) { | ||
521 | ERROR ("\nDid not catch SIGINT\n"); | ||
522 | } | ||
523 | signal(SIGINT,sig_handler); | ||
524 | |||
525 | pthread_mutex_init(&mtx,NULL); | ||
526 | pthread_mutex_lock(&mtx); | ||
527 | |||
528 | for (i = 1; i < argc; i++) { | ||
469 | if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 529 | if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { |
470 | usage(argv[0]); | 530 | usage(argv[0]); |
471 | exit(0); | 531 | exit(0); |
@@ -485,7 +545,9 @@ main(int argc, char **argv) | |||
485 | argv[i] = NULL; | 545 | argv[i] = NULL; |
486 | } else if (!strcmp(argv[i], "--")) { | 546 | } else if (!strcmp(argv[i], "--")) { |
487 | argv[first] = argv[0]; | 547 | argv[first] = argv[0]; |
488 | decoders[ndecoders++] = decoder_open(i - first, &argv[first]); | 548 | decoders[ndecoders] = decoder_open(i - first, &argv[first]); |
549 | decoders[ndecoders]->id = ndecoders; | ||
550 | ndecoders++; | ||
489 | first = i; | 551 | first = i; |
490 | } | 552 | } |
491 | } | 553 | } |
@@ -493,7 +555,11 @@ main(int argc, char **argv) | |||
493 | argv[first] = argv[0]; | 555 | argv[first] = argv[0]; |
494 | argc = i - first; | 556 | argc = i - first; |
495 | 557 | ||
496 | if(ndecoders) decoders[ndecoders++] = decoder_open(argc ,&argv[first]); | 558 | if(ndecoders) { |
559 | decoders[ndecoders] = decoder_open(argc ,&argv[first]); | ||
560 | decoders[ndecoders]->id = ndecoders; | ||
561 | ndecoders++; | ||
562 | } | ||
497 | 563 | ||
498 | if (ndecoders > 1) { | 564 | if (ndecoders > 1) { |
499 | pthread_t threadIds[8]; | 565 | pthread_t threadIds[8]; |
@@ -516,6 +582,8 @@ main(int argc, char **argv) | |||
516 | int itr = 0; | 582 | int itr = 0; |
517 | do { | 583 | do { |
518 | decoders[0] = decoder_open(argc, &argv[first]); | 584 | decoders[0] = decoder_open(argc, &argv[first]); |
585 | decoders[0]->id = 0; | ||
586 | ndecoders++; | ||
519 | decode_stream(decoders[0]); | 587 | decode_stream(decoders[0]); |
520 | if (inloop) { | 588 | if (inloop) { |
521 | MSG("=================Iteration %d complete =============== %d\n", ++itr); | 589 | MSG("=================Iteration %d complete =============== %d\n", ++itr); |
diff --git a/videnc2test.c b/videnc2test.c index 5fcb293..dbc972e 100644 --- a/videnc2test.c +++ b/videnc2test.c | |||
@@ -41,6 +41,8 @@ | |||
41 | #include <errno.h> | 41 | #include <errno.h> |
42 | #include <time.h> | 42 | #include <time.h> |
43 | #include <sys/mman.h> | 43 | #include <sys/mman.h> |
44 | #include <signal.h> | ||
45 | |||
44 | 46 | ||
45 | #include <omap_drm.h> | 47 | #include <omap_drm.h> |
46 | #include <omap_drmif.h> | 48 | #include <omap_drmif.h> |
@@ -1070,10 +1072,30 @@ static int encoder_deinit(encoder *enc) | |||
1070 | memset(enc, 0, sizeof(encoder)); | 1072 | memset(enc, 0, sizeof(encoder)); |
1071 | return 0; | 1073 | return 0; |
1072 | } | 1074 | } |
1075 | |||
1076 | encoder encObj; | ||
1077 | |||
1078 | static void sig_handler(int signo, siginfo_t *siginfo, void *context) | ||
1079 | { | ||
1080 | if (signo == SIGINT) { | ||
1081 | encoder_deinit(&encObj); | ||
1082 | sleep(1); | ||
1083 | exit(0); | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1073 | /* encoder body */ | 1087 | /* encoder body */ |
1074 | int main(int argc, char * *argv) | 1088 | int main(int argc, char * *argv) |
1075 | { | 1089 | { |
1076 | XDAS_Int32 err; | 1090 | struct sigaction sa; |
1091 | sa.sa_handler = sig_handler; | ||
1092 | sigemptyset(&sa.sa_mask); | ||
1093 | sa.sa_flags = SA_SIGINFO; | ||
1094 | if (sigaction(SIGINT, &sa, NULL) == -1) { | ||
1095 | ERROR ("\nDid not catch SIGINT\n"); | ||
1096 | } | ||
1097 | |||
1098 | XDAS_Int32 err; | ||
1077 | IH264ENC_InArgs *h264enc_inArgs; | 1099 | IH264ENC_InArgs *h264enc_inArgs; |
1078 | IMPEG4ENC_InArgs *mpeg4enc_inArgs; | 1100 | IMPEG4ENC_InArgs *mpeg4enc_inArgs; |
1079 | IH264ENC_OutArgs *h264enc_outArgs; | 1101 | IH264ENC_OutArgs *h264enc_outArgs; |
@@ -1084,7 +1106,6 @@ int main(int argc, char * *argv) | |||
1084 | int bytesGenerated = 0; | 1106 | int bytesGenerated = 0; |
1085 | 1107 | ||
1086 | 1108 | ||
1087 | encoder encObj; | ||
1088 | memset(&encObj, 0, sizeof(encoder)); | 1109 | memset(&encObj, 0, sizeof(encoder)); |
1089 | 1110 | ||
1090 | if(parse_command(argc, argv, &encObj)){ | 1111 | if(parse_command(argc, argv, &encObj)){ |