From 4d4740b8ddcff9839598ba9f9df5bef648635332 Mon Sep 17 00:00:00 2001 From: AngelCarpintero Date: Fri, 22 Jan 2010 12:30:37 +0000 Subject: [PATCH] Only use post capture when we setup to record videos with external pipe or ffmpeg. Little fix in some log level. --- CHANGELOG | 1 + CREDITS | 5 ++++- alg.c | 4 ++-- conf.c | 4 ---- configure | 18 +++++++++--------- motion.c | 47 ++++++++++++++++++++++++++++++++--------------- netcam.c | 8 ++++---- netcam_jpeg.c | 14 +++++++------- 8 files changed, 59 insertions(+), 42 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d88bfc7..d308ae8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -48,6 +48,7 @@ Bugfixes * Exit when image dimension are not modulo 16. (Angel Carpintero) * Avoid logs flooding using some options of netcam_keepalive and try to discard images with weird header Content-Lenght 0. (Angel Carpintero) + * Only use post capture when we setup to record videos with external pipe or ffmpeg. (Angel Carpintero) 3.2.12 Summary of Changes diff --git a/CREDITS b/CREDITS index 0eee869..fd9b489 100644 --- a/CREDITS +++ b/CREDITS @@ -421,7 +421,10 @@ Angel Carpintero * Fix fd leaks in external pipe. * Fix segfault for new libjpeg v7. * Allow to change Standard method ( PAL / NECAM / SECAM ). - + * Exit when image dimension are not modulo 16. + * Avoid logs flooding using some options of netcam_keepalive and try to discard images with + weird header Content-Lenght 0. + * Only use post capture when we setup to record videos with external pipe or ffmpeg. Jared D * Change bayer2rgb24() to fix a problem with sn9c102 driver diff --git a/alg.c b/alg.c index e01734b..774c58c 100644 --- a/alg.c +++ b/alg.c @@ -528,7 +528,7 @@ static int alg_labeling(struct context *cnt) if (labelsize > 0) { if (debug_level >= CAMERA_VERBOSE) - motion_log(LOG_DEBUG, 0,"%s: Label: %i (%i) Size: %i (%i,%i)\n", + motion_log(LOG_DEBUG, 0,"%s: Label: %i (%i) Size: %i (%i,%i)", __FUNCTION__, current_label, cnt->current_image->total_labels, labelsize, ix, iy); @@ -553,7 +553,7 @@ static int alg_labeling(struct context *cnt) if (debug_level >= CAMERA_VERBOSE) motion_log(LOG_DEBUG, 0,"%s: %i Labels found. Largest connected Area: %i Pixel(s). " - "Largest Label: %i\n", __FUNCTION__, imgs->largest_label, imgs->labelsize_max, + "Largest Label: %i", __FUNCTION__, imgs->largest_label, imgs->labelsize_max, cnt->current_image->total_labels); /* return group of significant labels */ diff --git a/conf.c b/conf.c index e65a094..559cfd4 100644 --- a/conf.c +++ b/conf.c @@ -25,7 +25,6 @@ */ #include "motion.h" - #if (defined(BSD) && !defined(PWCBSD)) #include "video_freebsd.h" #else @@ -41,10 +40,8 @@ char *get_current_dir_name(void) } #endif - #define stripnewline(x) {if ((x)[strlen(x)-1]=='\n') (x)[strlen(x) - 1] = 0; } - struct config conf_template = { width: DEF_WIDTH, height: DEF_HEIGHT, @@ -159,7 +156,6 @@ struct config conf_template = { }; - static struct context **copy_bool(struct context **, const char *, int); static struct context **copy_int(struct context **, const char *, int); static struct context **config_thread(struct context **cnt, const char *str, int val); diff --git a/configure b/configure index 8ce5f86..faaddfd 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.64 for motion trunk-r476. +# Generated by GNU Autoconf 2.64 for motion trunk-r479. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software @@ -546,8 +546,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='motion' PACKAGE_TARNAME='motion' -PACKAGE_VERSION='trunk-r476' -PACKAGE_STRING='motion trunk-r476' +PACKAGE_VERSION='trunk-r479' +PACKAGE_STRING='motion trunk-r479' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1210,7 +1210,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures motion trunk-r476 to adapt to many kinds of systems. +\`configure' configures motion trunk-r479 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1271,7 +1271,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of motion trunk-r476:";; + short | recursive ) echo "Configuration of motion trunk-r479:";; esac cat <<\_ACEOF @@ -1412,7 +1412,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -motion configure trunk-r476 +motion configure trunk-r479 generated by GNU Autoconf 2.64 Copyright (C) 2009 Free Software Foundation, Inc. @@ -2009,7 +2009,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by motion $as_me trunk-r476, which was +It was created by motion $as_me trunk-r479, which was generated by GNU Autoconf 2.64. Invocation command line was $ $0 $@ @@ -5790,7 +5790,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by motion $as_me trunk-r476, which was +This file was extended by motion $as_me trunk-r479, which was generated by GNU Autoconf 2.64. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5850,7 +5850,7 @@ Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -motion config.status trunk-r476 +motion config.status trunk-r479 configured by $0, generated by GNU Autoconf 2.64, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/motion.c b/motion.c index c0e1da3..64fd610 100644 --- a/motion.c +++ b/motion.c @@ -544,9 +544,10 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) cnt->imgs.image_ring[cnt->imgs.image_ring_out].image, NULL, NULL, &cnt->imgs.image_ring[cnt->imgs.image_ring_out].timestamp_tm); -//#ifdef HAVE_FFMPEG - /* Check if we must add any "filler" frames into movie to keep up fps */ - if (cnt->imgs.image_ring[cnt->imgs.image_ring_out].shot == 0) { + /* Check if we must add any "filler" frames into movie to keep up fps + Only if we are recording videos ( ffmpeg or extenal pipe ) */ + if ((cnt->imgs.image_ring[cnt->imgs.image_ring_out].shot == 0) && + (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe))) { /* movie_last_shoot is -1 when file is created, * we don't know how many frames there is in first sec */ if (cnt->movie_last_shot >= 0) { @@ -573,7 +574,7 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) } cnt->movie_last_shot = 0; } else if (cnt->imgs.image_ring[cnt->imgs.image_ring_out].shot != (cnt->movie_last_shot + 1)) { - /* We are out of sync! Properbly we got motion - no motion - motion */ + /* We are out of sync! Propably we got motion - no motion - motion */ cnt->movie_last_shot = -1; } @@ -581,7 +582,6 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) * only when we not are within first sec */ if (cnt->movie_last_shot >= 0) cnt->movie_last_shot = cnt->imgs.image_ring[cnt->imgs.image_ring_out].shot; -//#endif } /* Mark the image as saved */ @@ -1670,8 +1670,16 @@ static void *motion_loop(void *arg) */ if (cnt->conf.emulate_motion && (cnt->startup_frames == 0)) { cnt->detecting_motion = 1; - /* Setup the postcap counter */ - cnt->postcap = cnt->conf.post_capture; + if (debug_level >= CAMERA_DEBUG) + motion_log(0, 0, "%s: Emulating motion %d", __FUNCTION__); + + if (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) { + /* Setup the postcap counter */ + cnt->postcap = cnt->conf.post_capture; + if (debug_level >= CAMERA_DEBUG) + motion_log(0, 0, "%s: (Em) Init post capture %d", __FUNCTION__, cnt->postcap); + } + cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); motion_detected(cnt, cnt->video_dev, cnt->current_image); } else if ((cnt->current_image->flags & IMAGE_MOTION) && (cnt->startup_frames == 0)) { @@ -1697,23 +1705,32 @@ static void *motion_loop(void *arg) if (frame_count >= cnt->conf.minimum_motion_frames) { cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); cnt->detecting_motion = 1; - /* Setup the postcap counter */ - cnt->postcap = cnt->conf.post_capture; + + if (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) { + /* Setup the postcap counter */ + cnt->postcap = cnt->conf.post_capture; + if (debug_level >= CAMERA_DEBUG) + motion_log(0, 0, "%s: Setup post capture %d", __FUNCTION__, cnt->postcap); + } /* Mark all images in image_ring to be saved */ for (i = 0; i < cnt->imgs.image_ring_size; i++) cnt->imgs.image_ring[i].flags |= IMAGE_SAVE; - } else if (cnt->postcap) { /* we have motion in this frame, - but not enought frames for trigger. Check postcap */ + } else if ((cnt->postcap) && + (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe))) { + /* we have motion in this frame, but not enought frames for trigger. Check postcap */ cnt->current_image->flags |= (IMAGE_POSTCAP | IMAGE_SAVE); cnt->postcap--; + if (debug_level >= CAMERA_DEBUG) + motion_log(0, 0, "%s: post capture %d", __FUNCTION__, cnt->postcap); } else { cnt->current_image->flags |= IMAGE_PRECAP; } /* Always call motion_detected when we have a motion image */ motion_detected(cnt, cnt->video_dev, cnt->current_image); - } else if (cnt->postcap) { + } else if ((cnt->postcap) && + (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe))) { /* No motion, doing postcap */ cnt->current_image->flags |= (IMAGE_POSTCAP | IMAGE_SAVE); cnt->postcap--; @@ -1748,7 +1765,7 @@ static void *motion_loop(void *arg) area_once = cnt->event_nr; /* Fire script only once per event */ if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "Motion in area %d detected.\n", z+1); + motion_log(0, 0, "Motion in area %d detected.", z+1); break; } } @@ -2561,7 +2578,7 @@ int main (int argc, char **argv) if (((motion_threads_running == 0) && finish) || ((motion_threads_running == 0) && (threads_running == 0))) { - if (debug_level >= CAMERA_VERBOSE) + if (debug_level >= CAMERA_ALL) motion_log(LOG_INFO, 0, "%s: DEBUG-1 threads_running %d motion_threads_running %d " ", finish %d", __FUNCTION__, threads_running, motion_threads_running, finish); break; @@ -2598,7 +2615,7 @@ int main (int argc, char **argv) } } - if (debug_level >= CAMERA_VERBOSE) + if (debug_level >= CAMERA_ALL) motion_log(LOG_INFO, 0, "%s: DEBUG-2 threads_running %d motion_threads_running %d finish %d", __FUNCTION__, threads_running, motion_threads_running, finish); } diff --git a/netcam.c b/netcam.c index 5645f74..3b2d930 100644 --- a/netcam.c +++ b/netcam.c @@ -1770,7 +1770,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) { int loop_counter = 0; - if (debug_level > CAMERA_VERBOSE) { + if (debug_level >= CAMERA_ALL) { motion_log(0, 0, "%s: Begin", __FUNCTION__); } @@ -1791,7 +1791,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) return -1; } - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_ALL) motion_log(0, 0, "%s: statbuf.st_mtime[%d] != last_st_mtime[%d]", __FUNCTION__, statbuf.st_mtime, netcam->file->last_st_mtime); @@ -1802,7 +1802,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) return -1; } - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_ALL) motion_log(0, 0, "%s: delay waiting new file image ", __FUNCTION__); //its waits 5seconds - READ_TIMEOUT @@ -1885,7 +1885,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) pthread_mutex_unlock(&netcam->mutex); - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_ALL) motion_log(0, 0, "%s: End", __FUNCTION__); return 0; diff --git a/netcam_jpeg.c b/netcam_jpeg.c index 7f60044..907defe 100644 --- a/netcam_jpeg.c +++ b/netcam_jpeg.c @@ -83,7 +83,7 @@ static boolean netcam_fill_input_buffer(j_decompress_ptr cinfo) src->buffer = (JOCTET *) src->data; } else { /* Insert a fake EOI marker - as per jpeglib recommendation */ - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_VERBOSE) motion_log(LOG_INFO, 0, "%s: **fake EOI inserted**", __FUNCTION__); src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; /* 0xD9 */ @@ -178,7 +178,7 @@ static void netcam_error_exit(j_common_ptr cinfo) /* need to "cleanup" the aborted decompression */ jpeg_destroy (cinfo); - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_VERBOSE) motion_log(LOG_ERR, 0, "%s: netcam->jpeg_error %d", __FUNCTION__, netcam->jpeg_error); @@ -228,7 +228,7 @@ static void netcam_output_message(j_common_ptr cinfo) * wrong, and that indicates a network problem rather * than a problem with the content. */ - if (debug_level > CAMERA_VERBOSE) { + if (debug_level >= CAMERA_VERBOSE) { /* * Format the message according to library standards. * Write it out to the motion log. @@ -299,7 +299,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR; } - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_VERBOSE) motion_log(0, 0, "%s: ***new pic delay successful***", __FUNCTION__); } @@ -337,7 +337,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) /* Start the decompressor */ jpeg_start_decompress(cinfo); - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_VERBOSE) motion_log(LOG_INFO, 0, "%s: jpeg_error %d", __FUNCTION__, netcam->jpeg_error); return netcam->jpeg_error; @@ -408,7 +408,7 @@ static int netcam_image_conv(netcam_context_ptr netcam, /* rotate as specified */ rotate_map(netcam->cnt, image); - if (debug_level > CAMERA_VERBOSE) + if (debug_level >= CAMERA_VERBOSE) motion_log(LOG_INFO, 0, "%s: jpeg_error %d", __FUNCTION__, netcam->jpeg_error); @@ -469,7 +469,7 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) "with JPEG image - expected %dx%d, JPEG %dx%d", " retval %d", __FUNCTION__, netcam->width, netcam->height, cinfo.output_width, cinfo.output_height, retval); - return retval; + return retval; } }