From 77f1df1a250d958317c930e6f3a36edf42f11d09 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 11 Mar 2016 15:48:18 -0500 Subject: fixes --- main.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index df892ac..9af7dd7 100644 --- a/main.c +++ b/main.c @@ -64,7 +64,7 @@ void start_ffmpeg(int in, int out) { close(fd); execlp("ffmpeg", "ffmpeg", - "-pix_fmt", "rgb24", "-s", "640x480", "-f", "rawvideo", "-i", "-", + "-pix_fmt", "rgb24", "-s", "640x480", "-f", "rawvideo", "-i", "/dev/stdin", "-f", "mpjpeg", "-", NULL); error(1, errno, "execlp: ffmpeg"); @@ -85,8 +85,7 @@ void* start_kinect_inner(void *args_anon) { struct thread_kinect_args *args = args_anon; thread_kinect(args->video_fd, args->depth_fd, args->accel_fd); wg_sub(&wg, 1); - running = 0; - close(httpsock); + finish(0); return NULL; } static @@ -117,16 +116,13 @@ void *start_mpjpeg_reader_inner(void *args_anon) { } static void start_mpjpeg_reader(struct mpjpeg_stream *s, int fd, const char *boundary) { - struct thread_mpjpeg { - struct thread_mpjpeg_args args; - pthread_t thread; - }; - struct thread_mpjpeg *thread = xrealloc(NULL, sizeof(struct thread_mpjpeg_args)); - thread->args.s = s; - thread->args.fd = fd; - thread->args.boundary = boundary; + struct thread_mpjpeg_args *args = xrealloc(NULL, sizeof(struct thread_mpjpeg_args)); + args->s = s; + args->fd = fd; + args->boundary = boundary; wg_add(&wg, 1); - pthread_create(&thread->thread, NULL, start_mpjpeg_reader_inner, &thread->args); + static pthread_t thread; + pthread_create(&thread, NULL, start_mpjpeg_reader_inner, args); } struct thread_http_args { @@ -140,8 +136,7 @@ void *start_http_inner(void *args_anon) { struct thread_http_args *args = args_anon; thread_http_listener(args->wg, args->video, args->depth); wg_sub(&wg, 1); - running = 0; - close(httpsock); + finish(0); return NULL; } static @@ -165,11 +160,13 @@ void sigchld_handler(int sig UNUSED) while (waitpid(-1, &status, WNOHANG) > 0) {} } -static -void sigint_handler(int num UNUSED) +void finish(int sig) { + if (sig != 0) + printf("Caught signal %d\n", sig); running = 0; close(httpsock); + kill(getpid(), SIGHUP); } int main(int argc UNUSED, char **argv UNUSED) @@ -190,13 +187,13 @@ int main(int argc UNUSED, char **argv UNUSED) error(EXIT_FAILURE, errno, _("Could not set up SIGCHLD handler")); } - struct sigaction act_int; - sigemptyset (&act_int.sa_mask); - act_int.sa_flags = 0; - act_int.sa_handler = sigint_handler; - if (sigaction(SIGINT, &act_int, 0)) { - error(EXIT_FAILURE, errno, _("Could not set up SIGINT handler")); - } + struct sigaction act_exit; + sigemptyset (&act_exit.sa_mask); + act_exit.sa_flags = 0; + act_exit.sa_handler = finish; + sigaction(SIGINT, &act_exit, 0); + sigaction(SIGQUIT, &act_exit, 0); + sigaction(SIGTERM, &act_exit, 0); if (pipe(kinect_video_fds) == -1) error(1, errno, "pipe"); if (pipe(kinect_depth_fds) == -1) error(1, errno, "pipe"); @@ -210,8 +207,8 @@ int main(int argc UNUSED, char **argv UNUSED) start_kinect(kinect_video_fds[1], kinect_depth_fds[1], kinect_accel_fds[1]); - start_mpjpeg_reader(&mpjpeg_video, mpjpeg_video_fds[0], "--ffserver"); - start_mpjpeg_reader(&mpjpeg_depth, mpjpeg_depth_fds[0], "--ffserver"); + start_mpjpeg_reader(&mpjpeg_video, mpjpeg_video_fds[0], "ffserver"); + start_mpjpeg_reader(&mpjpeg_depth, mpjpeg_depth_fds[0], "ffserver"); start_http(&wg, &mpjpeg_video, &mpjpeg_depth); /* never call exit() after we've started ffmpeg */ start_ffmpeg(kinect_video_fds[0], mpjpeg_video_fds[1]); -- cgit v1.2.3-54-g00ecf