diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index 5e4de6a1..1880a749 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -728,17 +728,30 @@ static int mlp_init(struct ctx_cam *cam) /** clean up all memory etc. from motion init */ void mlp_cleanup(struct ctx_cam *cam) { + /* When the watchdog counter is less than zero we + * only do the minimal necessary to free the memory variables + * rather than finish off any event processing + */ + if (cam->watchdog > 0) { + event(cam, EVENT_TLAPSE_END, NULL, NULL, NULL, NULL); + if (cam->event_nr == cam->prev_event) { + mlp_ring_process(cam); + if (cam->imgs.image_preview.diffs) { + event(cam, EVENT_IMAGE_PREVIEW, NULL, NULL, NULL, &cam->current_image->imgts); + cam->imgs.image_preview.diffs = 0; + } - event(cam, EVENT_TLAPSE_END, NULL, NULL, NULL, NULL); - - if (cam->event_nr == cam->prev_event) { - mlp_ring_process(cam); - if (cam->imgs.image_preview.diffs) { - event(cam, EVENT_IMAGE_PREVIEW, NULL, NULL, NULL, &cam->current_image->imgts); - cam->imgs.image_preview.diffs = 0; + event(cam, EVENT_END, NULL, NULL, NULL, &cam->current_image->imgts); } + } else { + movie_free(cam->movie_norm); + cam->movie_norm = NULL; - event(cam, EVENT_END, NULL, NULL, NULL, &cam->current_image->imgts); + movie_free(cam->movie_motion); + cam->movie_motion = NULL; + + movie_free(cam->movie_timelapse); + cam->movie_timelapse = NULL; } webu_stream_deinit(cam); diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 852373cd..acf274a7 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -473,6 +473,11 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) * Best to just not get into a watchdog situation... */ + int sec_cancel, sec_kill; + + sec_cancel = 0 -motapp->cam_list[indx]->conf->watchdog_kill; + sec_kill = 2 * sec_cancel; + if (!motapp->cam_list[indx]->running_cam) { return; } @@ -484,11 +489,19 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) , motapp->cam_list[indx]->threadnr); motapp->cam_list[indx]->event_stop = true; /* Trigger end of event */ motapp->cam_list[indx]->finish_cam = true; + if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && + (motapp->cam_list[indx]->netcam != NULL)) { + motapp->cam_list[indx]->netcam->finish = true; + } + if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && + (motapp->cam_list[indx]->netcam_high != NULL)) { + motapp->cam_list[indx]->netcam_high->finish = true; + } } - if (motapp->cam_list[indx]->watchdog == (0 - motapp->cam_list[indx]->conf->watchdog_kill) ) { + if (motapp->cam_list[indx]->watchdog == sec_cancel) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO - ,_("Thread %d - Watchdog timeout did NOT restart, killing it!") + ,_("Thread %d - Watchdog timeout. Requesting cancel.") , motapp->cam_list[indx]->threadnr); if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && (motapp->cam_list[indx]->netcam != NULL)) { @@ -501,11 +514,10 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) pthread_cancel(motapp->cam_list[indx]->thread_id); } - if (motapp->cam_list[indx]->watchdog < (0 - motapp->cam_list[indx]->conf->watchdog_kill)) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO - ,_("Thread %d - Watchdog kill!") + if (motapp->cam_list[indx]->watchdog < sec_kill) { + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO + ,_("Thread %d - Watchdog timeout. Requesting kill.") , motapp->cam_list[indx]->threadnr); - if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && (motapp->cam_list[indx]->netcam != NULL)) { if (!motapp->cam_list[indx]->netcam->handler_finished && @@ -534,7 +546,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) } if (motapp->cam_list[indx]->running_cam && pthread_kill(motapp->cam_list[indx]->thread_id, 0) == ESRCH) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Thread %d - Cleaning thread.") , motapp->cam_list[indx]->threadnr); pthread_mutex_lock(&motapp->global_lock); diff --git a/src/movie.cpp b/src/movie.cpp index 3266abe7..5c821dd0 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1562,6 +1562,14 @@ int movie_open(struct ctx_movie *movie) } +void movie_free(struct ctx_movie *movie) +{ + if (movie != NULL) { + movie_free_context(movie); + movie_free_nal(movie); + } +} + void movie_close(struct ctx_movie *movie) { @@ -1582,8 +1590,7 @@ void movie_close(struct ctx_movie *movie) } } } - movie_free_context(movie); - movie_free_nal(movie); + movie_free(movie); } } diff --git a/src/movie.hpp b/src/movie.hpp index a971fcf9..c9a048d5 100644 --- a/src/movie.hpp +++ b/src/movie.hpp @@ -90,5 +90,6 @@ void movie_reset_start_time(struct ctx_movie *ffmpeg, const struct timespec *tv1 int movie_init_timelapse(struct ctx_cam *cam, struct timespec *ts1); int movie_init_norm(struct ctx_cam *cam, struct timespec *ts1); int movie_init_motion(struct ctx_cam *cam, struct timespec *ts1); +void movie_free(struct ctx_movie *movie); #endif /* #define _INCLUDE_MOVIE_HPP_ */