summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a30dd9a)
raw | patch | inline | side by side (parent: a30dd9a)
author | Pooja Prajod <a0132412@ti.com> | |
Thu, 29 Sep 2016 15:00:22 +0000 (20:30 +0530) | ||
committer | Pooja Prajod <a0132412@ti.com> | |
Thu, 29 Sep 2016 15:10:32 +0000 (20:40 +0530) |
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>
This is a sample handler which can be extended further.
Signed-off-by: Pooja Prajod <a0132412@ti.com>
viddec3test.c | patch | blob | history | |
videnc2test.c | patch | blob | history |
diff --git a/viddec3test.c b/viddec3test.c
index edaaf41775c7712043b93abcff17aa063e2640e3..8c57ed92fd6333ea185ed51bd559491c354a4a99 100644 (file)
--- a/viddec3test.c
+++ b/viddec3test.c
#include <xf86drm.h>
#include <omap_drm.h>
#include <omap_drmif.h>
+#include <signal.h>
+#include <unistd.h>
#include <pthread.h>
int num_outBuf;
size_t *outBuf_fd;
suseconds_t tdisp;
+ int id;
};
+
+struct decoder *decoders[8] = {};
+int ndecoders = 0;
+
/* When true, do not actually call VIDDEC3_process. For benchmarking. */
static int no_process = 0;
static int inloop = 0;
if (dev) dce_deinit(dev);
if (decoder->demux) demux_deinit(decoder->demux);
if (decoder->disp) disp_close(decoder->disp);
- if(decoder) free(decoder);
+ if(decoder) {
+ free(decoder);
+ }
}
}
static struct decoder *
decoder_open(int argc, char **argv)
{
- static struct decoder *decoder = NULL;
+ struct decoder *decoder = NULL;
char *infile = NULL;
int i;
- static int width, height, padded_width, padded_height;
+ int width, height, padded_width, padded_height;
Engine_Error ec;
XDAS_Int32 err;
/* get the output buffer and write it to file */
buf = (struct buffer *)outArgs->outputID[i];
if(!no_process)
- disp_post_vid_buffer(decoder->disp, buf,
+ disp_post_vid_buffer(decoder->disp, buf,
r->topLeft.x, r->topLeft.y,
r->bottomRight.x - r->topLeft.x,
r->bottomRight.y - r->topLeft.y);
return (inBufs->numBufs > 0) ? 0 : -1;
}
+/* Returns 1 (true) if the mutex is unlocked, which is the
+ * thread's signal to terminate.
+ */
+
+pthread_mutex_t mtx;
+
+int needQuit()
+ {
+ switch(pthread_mutex_trylock(&mtx)) {
+ case 0: /* if we got the lock, unlock and return 1 (true) */
+ pthread_mutex_unlock(&mtx);
+ return 1;
+ case EBUSY: /* return 0 (false) if the mutex was locked */
+ return 0;
+ }
+ return 1;
+ }
+
void *decode_stream(void *decoderHandle)
{
int ret = 0;
int n = 0;
if(!decoder) goto exit;
- while((ret = decoder_process(decoder)) == 0);
+ while((ret = decoder_process(decoder)) == 0) {
+ if(needQuit()){
+ inloop = 1;
+ break;
+ }
+ }
if((ret != -1 && ret != 0) && inloop) inloop = 1; /*Assuming Good case. Otherwise logic gets messy*/
- decoder_close(decoder);
+ int i = decoder->id;
+ decoder_close(decoder);
+ decoders[i]=NULL;
exit:
return NULL;
}
+
+static void sig_handler(int signo)
+{
+ if (signo == SIGINT) {
+ int i=0;
+ pthread_mutex_unlock(&mtx);
+ sleep(1);
+ exit(0);
+ }
+}
+
+
int
main(int argc, char **argv)
{
- struct decoder *decoders[8] = {};
- int i, first = 0, ndecoders = 0;
- for (i = 1; i < argc; i++) {
+ int i, first = 0;
+
+ struct sigaction sa;
+
+ sa.sa_handler = sig_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (sigaction(SIGINT, &sa, NULL) == -1) {
+ ERROR ("\nDid not catch SIGINT\n");
+ }
+ signal(SIGINT,sig_handler);
+
+ pthread_mutex_init(&mtx,NULL);
+ pthread_mutex_lock(&mtx);
+
+ for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
usage(argv[0]);
exit(0);
argv[i] = NULL;
} else if (!strcmp(argv[i], "--")) {
argv[first] = argv[0];
- decoders[ndecoders++] = decoder_open(i - first, &argv[first]);
+ decoders[ndecoders] = decoder_open(i - first, &argv[first]);
+ decoders[ndecoders]->id = ndecoders;
+ ndecoders++;
first = i;
}
}
argv[first] = argv[0];
argc = i - first;
- if(ndecoders) decoders[ndecoders++] = decoder_open(argc ,&argv[first]);
+ if(ndecoders) {
+ decoders[ndecoders] = decoder_open(argc ,&argv[first]);
+ decoders[ndecoders]->id = ndecoders;
+ ndecoders++;
+ }
if (ndecoders > 1) {
pthread_t threadIds[8];
int itr = 0;
do {
decoders[0] = decoder_open(argc, &argv[first]);
+ decoders[0]->id = 0;
+ ndecoders++;
decode_stream(decoders[0]);
if (inloop) {
MSG("=================Iteration %d complete =============== %d\n", ++itr);
diff --git a/videnc2test.c b/videnc2test.c
index 5fcb2936010e5ffe2e6e4b24bfe9685e87e1562f..dbc972ee84531648a3dce1f594df1924e0aed24a 100644 (file)
--- a/videnc2test.c
+++ b/videnc2test.c
#include <errno.h>
#include <time.h>
#include <sys/mman.h>
+#include <signal.h>
+
#include <omap_drm.h>
#include <omap_drmif.h>
memset(enc, 0, sizeof(encoder));
return 0;
}
+
+encoder encObj;
+
+static void sig_handler(int signo, siginfo_t *siginfo, void *context)
+ {
+ if (signo == SIGINT) {
+ encoder_deinit(&encObj);
+ sleep(1);
+ exit(0);
+ }
+ }
+
/* encoder body */
int main(int argc, char * *argv)
{
- XDAS_Int32 err;
+ struct sigaction sa;
+ sa.sa_handler = sig_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO;
+ if (sigaction(SIGINT, &sa, NULL) == -1) {
+ ERROR ("\nDid not catch SIGINT\n");
+ }
+
+ XDAS_Int32 err;
IH264ENC_InArgs *h264enc_inArgs;
IMPEG4ENC_InArgs *mpeg4enc_inArgs;
IH264ENC_OutArgs *h264enc_outArgs;
int bytesGenerated = 0;
- encoder encObj;
memset(&encObj, 0, sizeof(encoder));
if(parse_command(argc, argv, &encObj)){