From 0f71dabed4039796a6c537a1dd7a63954f02eb1e Mon Sep 17 00:00:00 2001 From: AngelCarpintero Date: Mon, 9 Mar 2009 04:36:17 +0000 Subject: [PATCH] Added the option logfile to log message to text file. Removed level -1 to log to stderr, don't use always short --- conf.c | 164 +++++++++++++++++++------------------------- conf.h | 7 +- configure | 18 ++--- draw.c | 7 +- event.c | 4 +- logger.c | 65 +++++++++++++++--- logger.h | 2 + motion-dist.conf.in | 4 ++ motion.c | 79 +++++++++++++-------- motion.h | 48 ++++++------- netcam.c | 72 +++++++++---------- netcam_jpeg.c | 4 +- stream.c | 4 +- track.c | 110 ++++++++++++++--------------- track.h | 34 ++++----- video.c | 2 +- video2.c | 6 +- video_common.c | 4 +- video_freebsd.c | 60 ++++++++-------- video_freebsd.h | 4 +- vloopback_motion.c | 6 +- webhttpd.c | 52 +++++++------- 22 files changed, 405 insertions(+), 351 deletions(-) diff --git a/conf.c b/conf.c index fccb596..31dc329 100644 --- a/conf.c +++ b/conf.c @@ -152,20 +152,19 @@ struct config conf_template = { area_detect: NULL, minimum_motion_frames: 1, pid_file: NULL, + log_file: NULL, }; static struct context **copy_bool(struct context **, const char *, int); static struct context **copy_int(struct context **, const char *, int); -static struct context **copy_short(struct context **, const char *, int); static struct context **config_thread(struct context **cnt, const char *str, int val); -static const char *print_bool(struct context **, char **, int, unsigned short int); -static const char *print_int(struct context **, char **, int, unsigned short int); -static const char *print_short(struct context **, char **, int, unsigned short int); -static const char *print_string(struct context **, char **, int, unsigned short int); -static const char *print_thread(struct context **, char **, int, unsigned short int); +static const char *print_bool(struct context **, char **, int, unsigned int); +static const char *print_int(struct context **, char **, int, unsigned int); +static const char *print_string(struct context **, char **, int, unsigned int); +static const char *print_thread(struct context **, char **, int, unsigned int); static void usage(void); @@ -206,6 +205,15 @@ config_param config_params[] = { copy_bool, print_bool }, + { + "logfile", + "# Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined)", + 1, + CONF_OFFSET(log_file), + copy_string, + print_string + }, + { "videodevice", "\n###########################################################\n" @@ -242,8 +250,8 @@ config_param config_params[] = { "# V4L2_PIX_FMT_YUV420 : 11 'YU12'\n", 0, CONF_OFFSET(v4l2_palette), - copy_short, - print_short + copy_int, + print_int }, #if (defined(BSD)) { @@ -1023,8 +1031,8 @@ config_param config_params[] = { "# be used with the conversion specifiers for options like on_motion_detected", 0, TRACK_OFFSET(type), - copy_short, - print_short + copy_int, + print_int }, { "track_auto", @@ -1047,8 +1055,8 @@ config_param config_params[] = { "# Motor number for x-axis (default: 0)", 0, TRACK_OFFSET(motorx), - copy_short, - print_short + copy_int, + print_int }, { "track_motorx_reverse", @@ -1063,8 +1071,8 @@ config_param config_params[] = { "# Motor number for y-axis (default: 0)", 0, TRACK_OFFSET(motory), - copy_short, - print_short + copy_int, + print_int }, { "track_motory_reverse", @@ -1079,56 +1087,56 @@ config_param config_params[] = { "# Maximum value on x-axis (default: 0)", 0, TRACK_OFFSET(maxx), - copy_short, - print_short + copy_int, + print_int }, { "track_minx", "# Minimum value on x-axis (default: 0)", 0, TRACK_OFFSET(minx), - copy_short, - print_short + copy_int, + print_int }, { "track_maxy", "# Maximum value on y-axis (default: 0)", 0, TRACK_OFFSET(maxy), - copy_short, - print_short + copy_int, + print_int }, { "track_miny", "# Minimum value on y-axis (default: 0)", 0, TRACK_OFFSET(miny), - copy_short, - print_short + copy_int, + print_int }, { "track_homex", "# Center value on x-axis (default: 0)", 0, TRACK_OFFSET(homex), - copy_short, - print_short + copy_int, + print_int }, { "track_homey", "# Center value on y-axis (default: 0)", 0, TRACK_OFFSET(homey), - copy_short, - print_short + copy_int, + print_int }, { "track_iomojo_id", "# ID of an iomojo camera if used (default: 0)", 0, TRACK_OFFSET(iomojo_id), - copy_short, - print_short + copy_int, + print_int }, { "track_step_angle_x", @@ -1137,8 +1145,8 @@ config_param config_params[] = { "# Currently only used with pwc type cameras", 0, TRACK_OFFSET(step_angle_x), - copy_short, - print_short + copy_int, + print_int }, { "track_step_angle_y", @@ -1147,8 +1155,8 @@ config_param config_params[] = { "# Currently only used with pwc type cameras", 0, TRACK_OFFSET(step_angle_y), - copy_short, - print_short + copy_int, + print_int }, { "track_move_wait", @@ -1156,24 +1164,24 @@ config_param config_params[] = { "# of picture frames (default: 10)", 0, TRACK_OFFSET(move_wait), - copy_short, - print_short + copy_int, + print_int }, { "track_speed", "# Speed to set the motor to (stepper motor option) (default: 255)", 0, TRACK_OFFSET(speed), - copy_short, - print_short + copy_int, + print_int }, { "track_stepsize", "# Number of steps to make (stepper motor option) (default: 40)", 0, TRACK_OFFSET(stepsize), - copy_short, - print_short + copy_int, + print_int }, { "quiet", @@ -1434,7 +1442,7 @@ config_param config_params[] = { /* conf_cmdline sets the conf struct options as defined by the command line. * Any option already set from a config file are overridden. */ -static void conf_cmdline(struct context *cnt, short int thread) +static void conf_cmdline(struct context *cnt, int thread) { struct config *conf = &cnt->conf; int c; @@ -1443,7 +1451,7 @@ static void conf_cmdline(struct context *cnt, short int thread) * if necessary. This is accomplished by calling mystrcpy(); * see this function for more information. */ - while ((c = getopt(conf->argc, conf->argv, "c:d:hns?p:")) != EOF) + while ((c = getopt(conf->argc, conf->argv, "c:d:hns?pl:")) != EOF) switch (c) { case 'c': if (thread == -1) @@ -1457,12 +1465,16 @@ static void conf_cmdline(struct context *cnt, short int thread) break; case 'd': /* no validation - just take what user gives */ - debug_level = (unsigned short int)atoi(optarg); + debug_level = (unsigned int)atoi(optarg); break; case 'p': if (thread == -1) strcpy(cnt->pid_file, optarg); - break; + break; + case 'l': + if (thread == -1) + strcpy(cnt->log_file, optarg); + break; case 'h': case '?': default: @@ -1482,7 +1494,7 @@ static void conf_cmdline(struct context *cnt, short int thread) */ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char *arg1) { - unsigned short int i = 0; + unsigned int i = 0; if (!cmd) return cnt; @@ -1502,7 +1514,6 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char /* We call the function given by the pointer config_params[i].copy * If the option is a bool, copy_bool is called. * If the option is an int, copy_int is called. - * If the option is a short, copy_short is called. * If the option is a string, copy_string is called. * If the option is a thread, config_thread is called. * The arguments to the function are: @@ -1605,7 +1616,7 @@ void conf_print(struct context **cnt) { const char *retval; char *val; - unsigned short int i, thread; + unsigned int i, thread; FILE *conffile; for (thread = 0; cnt[thread]; thread++) { @@ -1712,9 +1723,11 @@ struct context **conf_load(struct context **cnt) * 3. $HOME/.motion/motion.conf * 4. sysconfig/motion.conf */ - /* Get filename & pid file from commandline */ + /* Get filename , pid file & log file from commandline */ cnt[0]->conf_filename[0] = 0; cnt[0]->pid_file[0] = 0; + cnt[0]->log_file[0] = 0; + conf_cmdline(cnt[0], -1); @@ -1727,7 +1740,7 @@ struct context **conf_load(struct context **cnt) char *path = NULL; if (cnt[0]->conf_filename[0]) - motion_log(-1, 1, "%s: Configfile %s not found - trying defaults.", + motion_log(0, 1, "%s: Configfile %s not found - trying defaults.", __FUNCTION__, filename); if ((path = get_current_dir_name()) == NULL) { @@ -1749,7 +1762,7 @@ struct context **conf_load(struct context **cnt) fp = fopen(filename, "r"); if (!fp) /* there is no config file.... use defaults */ - motion_log(-1, 1, "%s: could not open configfile %s", + motion_log(0, 1, "%s: could not open configfile %s", __FUNCTION__, filename); } } @@ -1784,6 +1797,9 @@ struct context **conf_load(struct context **cnt) if (cnt[0]->pid_file[0]) cnt[0]->conf.pid_file = mystrcpy(cnt[0]->conf.pid_file, cnt[0]->pid_file); + if (cnt[0]->log_file[0]) + cnt[0]->conf.log_file = mystrcpy(cnt[0]->conf.log_file, cnt[0]->log_file); + return cnt; } @@ -1797,7 +1813,7 @@ struct context **conf_load(struct context **cnt) */ void malloc_strings(struct context *cnt) { - unsigned short int i = 0; + unsigned int i = 0; char **val; while (config_params[i].param_name != NULL) { if (config_params[i].copy == copy_string) { /* if member is a string */ @@ -1820,7 +1836,6 @@ void malloc_strings(struct context *cnt) * * copy_bool - convert a bool representation to int * copy_int - convert a string to int - * copy_short - convert a string to short * copy_string - just a string copy * * @param str - A char *, pointing to a string representation of the @@ -1886,27 +1901,6 @@ static struct context **copy_int(struct context **cnt, const char *str, int val_ return cnt; } -/* copy_short assigns a config option to a new short value. - * The integer is given as a string in str which is converted to short by the function. - */ -static struct context **copy_short(struct context **cnt, const char *str, int val_ptr) -{ - void *tmp; - int i; - - i = -1; - - while (cnt[++i]) { - tmp = (char *)cnt[i]+val_ptr; - *((short int *)tmp) = atoi(str); - - if (cnt[0]->threadnr) - return cnt; - } - - return cnt; -} - /* copy_string assigns a new string value to a config option. * Strings are handled differently from bool and int. * the char *conf->option that we are working on is free()'d @@ -2007,8 +2001,6 @@ const char *config_type(config_param *configparam) return "string"; if (configparam->copy == copy_int) return "int"; - if (configparam->copy == copy_short) - return "short"; if (configparam->copy == copy_bool) return "bool"; @@ -2016,7 +2008,7 @@ const char *config_type(config_param *configparam) } static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, - int parm, unsigned short int threadnr) + int parm, unsigned int threadnr) { int val = config_params[parm].conf_value; @@ -2038,7 +2030,7 @@ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, */ static const char *print_string(struct context **cnt, char **str ATTRIBUTE_UNUSED, int parm, - unsigned short int threadnr) + unsigned int threadnr) { int val = config_params[parm].conf_value; const char **cptr0, **cptr1; @@ -2054,7 +2046,7 @@ static const char *print_string(struct context **cnt, } static const char *print_int(struct context **cnt, char **str ATTRIBUTE_UNUSED, - int parm, unsigned short int threadnr) + int parm, unsigned int threadnr) { static char retval[20]; int val = config_params[parm].conf_value; @@ -2069,26 +2061,11 @@ static const char *print_int(struct context **cnt, char **str ATTRIBUTE_UNUSED, } -static const char *print_short(struct context **cnt, char **str ATTRIBUTE_UNUSED, - int parm, unsigned short int threadnr) -{ - static char retval[20]; - int val = config_params[parm].conf_value; - - if (threadnr && - *(short int*)((char *)cnt[threadnr] + val) == *(short int*)((char *)cnt[0] + val)) - return NULL; - - sprintf(retval, "%d", *(short int*)((char *)cnt[threadnr] + val)); - - return retval; -} - static const char *print_thread(struct context **cnt, char **str, - int parm ATTRIBUTE_UNUSED, unsigned short int threadnr) + int parm ATTRIBUTE_UNUSED, unsigned int threadnr) { char *retval; - unsigned short int i = 0; + unsigned int i = 0; if (!str || threadnr) return NULL; @@ -2184,6 +2161,7 @@ static void usage() printf("-c config\t\tFull path and filename of config file.\n"); printf("-d level\t\tDebug mode.\n"); printf("-p process_id_file\tFull path and filename of process id file (pid file).\n"); + printf("-l log file \tFull path and filename of log file.\n"); printf("-h\t\t\tShow this screen.\n"); printf("\n"); printf("Motion is configured using a config file only. If none is supplied,\n"); diff --git a/conf.h b/conf.h index 579fa6e..0a94820 100644 --- a/conf.h +++ b/conf.h @@ -19,6 +19,7 @@ more parameters may be added later. */ struct config { + char *log_file; int setup_mode; int width; int height; @@ -79,7 +80,7 @@ struct config { const char *tuner_device; #endif const char *video_device; - short unsigned int v4l2_palette; + int v4l2_palette; const char *vidpipe; const char *filepath; const char *imagepath; @@ -131,7 +132,7 @@ struct config { * typedef for a param copy function. */ typedef struct context ** (* conf_copy_func)(struct context **, const char *, int); -typedef const char *(* conf_print_func)(struct context **, char **, int, unsigned short int); +typedef const char *(* conf_print_func)(struct context **, char **, int, unsigned int); /** * description for parameters in the config file @@ -139,7 +140,7 @@ typedef const char *(* conf_print_func)(struct context **, char **, int, unsigne typedef struct { const char *param_name; /* name for this parameter */ const char *param_help; /* short explanation for parameter */ - unsigned short int main_thread; /* belong only to main thread when value>0 */ + unsigned int main_thread; /* belong only to main thread when value>0 */ int conf_value; /* pointer to a field in struct context */ conf_copy_func copy; /* a function to set the value in 'config' */ conf_print_func print; /* a function to output the value to a file */ diff --git a/configure b/configure index 26a05c1..15faa03 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.61 for motion trunk-r441. +# Generated by GNU Autoconf 2.61 for motion trunk-r442. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='motion' PACKAGE_TARNAME='motion' -PACKAGE_VERSION='trunk-r441' -PACKAGE_STRING='motion trunk-r441' +PACKAGE_VERSION='trunk-r442' +PACKAGE_STRING='motion trunk-r442' PACKAGE_BUGREPORT='' ac_unique_file="motion.c" @@ -1177,7 +1177,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-r441 to adapt to many kinds of systems. +\`configure' configures motion trunk-r442 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1238,7 +1238,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of motion trunk-r441:";; + short | recursive ) echo "Configuration of motion trunk-r442:";; esac cat <<\_ACEOF @@ -1376,7 +1376,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -motion configure trunk-r441 +motion configure trunk-r442 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1390,7 +1390,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-r441, which was +It was created by motion $as_me trunk-r442, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -8230,7 +8230,7 @@ exec 6>&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-r441, which was +This file was extended by motion $as_me trunk-r442, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -8279,7 +8279,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -motion config.status trunk-r441 +motion config.status trunk-r442 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/draw.c b/draw.c index 35d2057..87e6052 100644 --- a/draw.c +++ b/draw.c @@ -1076,7 +1076,7 @@ struct big_char big_table[sizeof(draw_table) / sizeof(struct draw_char)]; #define NEWLINE "\\n" -static int draw_textn (unsigned char *image, int startx, int starty, int width, const char *text, int len, unsigned short int factor) +static int draw_textn(unsigned char *image, unsigned int startx, unsigned int starty, unsigned int width, const char *text, int len, unsigned int factor) { int pos, x, y, line_offset, next_char_offs; unsigned char *image_ptr, *char_ptr, **char_arr_ptr; @@ -1084,9 +1084,6 @@ static int draw_textn (unsigned char *image, int startx, int starty, int width, if (startx > width / 2) startx -= len * (6 * (factor + 1)); - if (startx < 0) - startx = 0; - if (startx + len * 6 * (factor + 1) >= width) len = (width-startx-1)/(6*(factor+1)); @@ -1124,7 +1121,7 @@ static int draw_textn (unsigned char *image, int startx, int starty, int width, return 0; } -int draw_text (unsigned char *image, int startx, int starty, int width, const char *text, unsigned short int factor) +int draw_text(unsigned char *image, unsigned int startx, unsigned int starty, unsigned int width, const char *text, unsigned int factor) { int num_nl = 0; const char *end, *begin; diff --git a/event.c b/event.c index 865085b..0d4e816 100644 --- a/event.c +++ b/event.c @@ -51,7 +51,7 @@ static void exec_command(struct context *cnt, char *command, char *filename, int exit(1); } else if (debug_level >= CAMERA_VERBOSE) { - motion_log(-1, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp); + motion_log(0, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp); } } @@ -63,7 +63,7 @@ static void event_newfile(struct context *cnt ATTRIBUTE_UNUSED, int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED, char *filename, void *ftype, struct tm *tm ATTRIBUTE_UNUSED) { - motion_log(-1, 0, "%s: File of type %ld saved to: %s", __FUNCTION__, + motion_log(0, 0, "%s: File of type %ld saved to: %s", __FUNCTION__, (unsigned long)ftype, filename); } diff --git a/logger.c b/logger.c index 831f611..1c321fa 100644 --- a/logger.c +++ b/logger.c @@ -13,6 +13,45 @@ #include "logger.h" /* already includes motion.h */ #include +static int log_mode = 1; +static FILE *logfile; + +/** + * set_log_mode + * + * Set mode of logging , could be using syslog or files. + */ +void set_log_mode(int mode) +{ + log_mode = mode; +} + +/** + * set_logfile + * + * Set logfile to be used instead of syslog. + */ +FILE * set_logfile(const char *logfile_name) +{ + return logfile = myfopen(logfile_name, "a"); +} + + +/** + * str_time + * + * Return string with human readable time + */ +static char *str_time(void) +{ + static char buffer[16]; + time_t now = 0; + + now = time(0); + strftime(buffer, 16, "%b %d %H:%M:%S", localtime(&now)); + return buffer; +} + /** * motion_log * @@ -56,8 +95,13 @@ void motion_log(int level, int errno_flag, const char *fmt, ...) */ errno_save = errno; + /* Prefix the message with the time and thread number */ + if (!log_mode) { + n = snprintf(buf, sizeof(buf), "[%s] [%d] ", str_time(), threadnr); + } else { /* Prefix the message with the thread number */ - n = snprintf(buf, sizeof(buf), "[%d] ", threadnr); + n = snprintf(buf, sizeof(buf), "[%d] ", threadnr); + } /* Next add the user's message */ va_start(ap, fmt); @@ -78,15 +122,20 @@ void motion_log(int level, int errno_flag, const char *fmt, ...) strncat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)), 1024 - strlen(buf)); #endif } - /* If 'level' is not negative, send the message to the syslog */ - if (level >= 0) - syslog(level, "%s", buf); - /* For printing to stderr we need to add a newline */ - strncat(buf, "\n", 1024 - strlen(buf)); - fputs(buf, stderr); - fflush(stderr); + if (!log_mode) { + strncat(buf, "\n", 1024 - strlen(buf)); + fputs(buf, logfile); + fflush(logfile); + /* If log_mode, send the message to the syslog */ + } else { + syslog(level, "%s", buf); + strncat(buf, "\n", 1024 - strlen(buf)); + fputs(buf, stderr); + fflush(stderr); + } + /* Clean up the argument list routine */ va_end(ap); } diff --git a/logger.h b/logger.h index 89bb852..d493bcf 100644 --- a/logger.h +++ b/logger.h @@ -28,6 +28,8 @@ #define CAMERA_VERBOSE 8 /* verbose level */ #define CAMERA_ALL 9 /* everything */ +void set_log_mode(int mode); +FILE * set_logfile(const char *logfile_name); void motion_log(int, int, const char *, ...); #endif diff --git a/motion-dist.conf.in b/motion-dist.conf.in index c94237d..899cfd7 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -20,6 +20,10 @@ process_id_file /var/run/motion/motion.pid # Start in Setup-Mode, daemon disabled. (default: off) setup_mode off + +# Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined) +;logfile + ########################################################### # Capture device options ############################################################ diff --git a/motion.c b/motion.c index c2348a2..db67980 100644 --- a/motion.c +++ b/motion.c @@ -62,11 +62,15 @@ volatile int threads_running = 0; * debug_level is for developers, normally used to control which * types of messages get output. */ -unsigned short int debug_level; +unsigned int debug_level; /* Set this when we want main to end or restart */ -volatile unsigned short int finish = 0; +volatile unsigned int finish = 0; + +/* Log file used instead of stderr and syslog + */ +FILE *ptr_logfile = NULL; /** * restart @@ -75,7 +79,7 @@ volatile unsigned short int finish = 0; * finished running, 'main' checks if 'restart' is true and if so starts * up again (instead of just quitting). */ -unsigned short int restart = 0; +unsigned int restart = 0; /** * image_ring_resize @@ -152,7 +156,7 @@ static void image_ring_resize(struct context *cnt, int new_size) */ static void image_ring_destroy(struct context *cnt) { - unsigned short int i; + int i; /* Exit if don't have any ring */ if (cnt->imgs.image_ring == NULL) @@ -267,7 +271,7 @@ static void context_init (struct context *cnt) */ static void context_destroy(struct context *cnt) { - unsigned short int j; + unsigned int j; /* Free memory allocated for config parameters */ for (j = 0; config_params[j].param_name != NULL; j++) { @@ -291,7 +295,7 @@ static void context_destroy(struct context *cnt) */ static void sig_handler(int signo) { - short int i; + int i; switch(signo) { case SIGALRM: @@ -375,6 +379,10 @@ static void motion_remove_pid(void) else motion_log(LOG_INFO, 1, "%s: Error removing pid file", __FUNCTION__); } + + if (ptr_logfile) + fclose(ptr_logfile); + } /** @@ -444,7 +452,7 @@ static void motion_detected(struct context *cnt, int dev, struct image_data *img event(cnt, EVENT_FIRSTMOTION, img->image, NULL, NULL, &img->timestamp_tm); if (debug_level >= CAMERA_INFO) - motion_log(-1, 0, "%s: Motion detected - starting event %d", + motion_log(0, 0, "%s: Motion detected - starting event %d", __FUNCTION__, cnt->event_nr); /* always save first motion frame as preview-shot, may be changed to an other one later */ @@ -738,7 +746,7 @@ static int motion_init(struct context *cnt) /* open video loopback devices if enabled */ if (cnt->conf.vidpipe) { if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Opening video loopback device for normal pictures", __FUNCTION__); + motion_log(0, 0, "%s: Opening video loopback device for normal pictures", __FUNCTION__); else motion_log(LOG_INFO, 0, "%s: Opening video loopback device for normal pictures", __FUNCTION__); @@ -753,7 +761,7 @@ static int motion_init(struct context *cnt) if (cnt->conf.motionvidpipe) { if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Opening video loopback device for motion pictures", __FUNCTION__); + motion_log(0, 0, "%s: Opening video loopback device for motion pictures", __FUNCTION__); else motion_log(LOG_INFO, 0, "%s: Opening video loopback device for motion pictures", __FUNCTION__); @@ -864,7 +872,7 @@ static int motion_init(struct context *cnt) __FUNCTION__); } else { if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Maskfile \"%s\" loaded.", + motion_log(0, 0, "%s: Maskfile \"%s\" loaded.", __FUNCTION__, cnt->conf.mask_file); else motion_log(LOG_INFO, 0, "%s: Maskfile \"%s\" loaded.", @@ -1027,16 +1035,16 @@ static void *motion_loop(void *arg) int i, j, z = 0; time_t lastframetime = 0; int frame_buffer_size; - unsigned short int rate_limit = 0; + unsigned int rate_limit = 0; int area_once = 0; int area_minx[9], area_miny[9], area_maxx[9], area_maxy[9]; int smartmask_ratio = 0; int smartmask_count = 20; - int smartmask_lastrate = 0; + unsigned int smartmask_lastrate = 0; int olddiffs = 0; int previous_diffs = 0, previous_location_x = 0, previous_location_y = 0; - unsigned short int text_size_factor; - unsigned short int passflag = 0; + unsigned int text_size_factor; + unsigned int passflag = 0; long int *rolling_average_data = NULL; long int rolling_average_limit, required_frame_time, frame_delay, delay_time_nsec; int rolling_frame = 0; @@ -1045,7 +1053,7 @@ static void *motion_loop(void *arg) unsigned long long int timenow = 0, timebefore = 0; int vid_return_code = 0; /* Return code used when calling vid_next */ int minimum_frame_time_downcounter = cnt->conf.minimum_frame_time; /* time in seconds to skip between capturing images */ - unsigned short int get_image = 1; /* Flag used to signal that we capture new image when we run the loop */ + unsigned int get_image = 1; /* Flag used to signal that we capture new image when we run the loop */ struct image_data *old_image; /* Next two variables are used for snapshot and timelapse feature @@ -1329,7 +1337,7 @@ static void *motion_loop(void *arg) } else { if (debug_level >= CAMERA_VERBOSE) - motion_log(-1, 0, "%s: vid_return_code %d", __FUNCTION__, vid_return_code); + motion_log(0, 0, "%s: vid_return_code %d", __FUNCTION__, vid_return_code); /* Netcams that change dimensions while Motion is running will * require that Motion restarts to reinitialize all the many @@ -1432,7 +1440,7 @@ static void *motion_loop(void *arg) if (cnt->conf.lightswitch && !cnt->lost_connection) { if (alg_lightswitch(cnt, cnt->current_image->diffs)) { if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Lightswitch detected", __FUNCTION__); + motion_log(0, 0, "%s: Lightswitch detected", __FUNCTION__); if (cnt->moved < 5) cnt->moved = 5; @@ -1458,7 +1466,7 @@ static void *motion_loop(void *arg) cnt->current_image->diffs = 0; if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Switchfilter detected", __FUNCTION__); + motion_log(0, 0, "%s: Switchfilter detected", __FUNCTION__); } } @@ -1553,7 +1561,7 @@ static void *motion_loop(void *arg) cnt->lightswitch_framecounter = 0; if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: micro-lightswitch!", __FUNCTION__); + motion_log(0, 0, "%s: micro-lightswitch!", __FUNCTION__); } else { alg_update_reference_frame(cnt, UPDATE_REF_FRAME); } @@ -1736,7 +1744,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(-1, 0, "Motion in area %d detected.\n", z+1); + motion_log(0, 0, "Motion in area %d detected.\n", z+1); break; } } @@ -1775,7 +1783,7 @@ static void *motion_loop(void *arg) cnt->moved = track_center(cnt, cnt->video_dev, 0, 0, 0); if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: End of event %d", + motion_log(0, 0, "%s: End of event %d", __FUNCTION__, cnt->event_nr); cnt->makemovie = 0; @@ -1826,7 +1834,7 @@ static void *motion_loop(void *arg) strcat(msg, part); } - motion_log(-1, 0, "%s", msg); + motion_log(0, 0, "%s", msg); } } /* get_image end */ @@ -2078,7 +2086,7 @@ static void *motion_loop(void *arg) free(rolling_average_data); cnt->lost_connection = 1; - motion_log(-1, 0, "%s: Thread exiting", __FUNCTION__); + motion_log(0, 0, "%s: Thread exiting", __FUNCTION__); motion_cleanup(cnt); @@ -2127,7 +2135,7 @@ static void become_daemon(void) /* fork */ if (fork()) { - motion_log(-1, 0, "%s: Motion going to daemon mode", __FUNCTION__); + motion_log(0, 0, "%s: Motion going to daemon mode", __FUNCTION__); exit(0); } @@ -2144,7 +2152,9 @@ static void become_daemon(void) fclose(pidf); } else { motion_log(LOG_ERR, 1, "%s: Exit motion, cannot create process id file (pid file) %s", - __FUNCTION__, cnt_list[0]->conf.pid_file); + __FUNCTION__, cnt_list[0]->conf.pid_file); + if (ptr_logfile) + fclose(ptr_logfile); exit(0); } } @@ -2285,6 +2295,19 @@ static void motion_startup(int daemonize, int argc, char *argv[]) */ cntlist_create(argc, argv); + if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file,"syslog",6))) { + set_log_mode(0); + ptr_logfile = set_logfile(cnt_list[0]->conf.log_file); + if (ptr_logfile) { + + } else { + motion_log(LOG_ERR, 1, "%s: Exit motion, cannot create log file %s", + __FUNCTION__, cnt_list[0]->conf.log_file); + exit(0); + } + + } + motion_log(LOG_INFO, 0, "%s: Motion "VERSION" Started", __FUNCTION__); initialize_chars(); @@ -2454,7 +2477,7 @@ int main (int argc, char **argv) * optimize motion detection and stuff. */ if (cnt_list[0]->conf.setup_mode) - motion_log(-1, 0, "%s: Motion running in setup mode.", __FUNCTION__); + motion_log(0, 0, "%s: Motion running in setup mode.", __FUNCTION__); /* Create and a thread attribute for the threads we spawn later on. * PTHREAD_CREATE_DETACHED means to create threads detached, i.e. @@ -2494,7 +2517,7 @@ int main (int argc, char **argv) __FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf_filename); if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Thread %d is device: %s input %d", __FUNCTION__, + motion_log(0, 0, "%s: Thread %d is device: %s input %d", __FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf.netcam_url ? cnt_list[i]->conf.netcam_url : cnt_list[i]->conf.video_device, cnt_list[i]->conf.netcam_url ? -1 : cnt_list[i]->conf.input); @@ -2514,7 +2537,7 @@ int main (int argc, char **argv) pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list); if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Waiting for threads to finish, pid: %d", __FUNCTION__, getpid()); + motion_log(0, 0, "%s: Waiting for threads to finish, pid: %d", __FUNCTION__, getpid()); /* Crude way of waiting for all threads to finish - check the thread * counter (because we cannot do join on the detached threads). diff --git a/motion.h b/motion.h index b99b58f..e581265 100644 --- a/motion.h +++ b/motion.h @@ -21,6 +21,10 @@ #include #endif +#ifdef HAVE_PGSQL +#include +#endif + #include #include @@ -47,10 +51,6 @@ #include -#ifdef HAVE_PGSQL -#include -#endif - #include "logger.h" #include "conf.h" #include "stream.h" @@ -255,7 +255,7 @@ struct image_data { */ /* date/time drawing, draw.c */ -int draw_text (unsigned char *image, int startx, int starty, int width, const char *text, unsigned short int factor); +int draw_text(unsigned char *image, unsigned int startx, unsigned int starty, unsigned int width, const char *text, unsigned int factor); int initialize_chars(void); struct images { @@ -313,15 +313,16 @@ struct context { int extpipe_open; char conf_filename[PATH_MAX]; int threadnr; - unsigned short int daemon; + unsigned int daemon; char pid_file[PATH_MAX]; + char log_file[PATH_MAX]; struct config conf; struct images imgs; struct trackoptions track; struct netcam_context *netcam; struct image_data *current_image; /* Pointer to a structure where the image, diffs etc is stored */ - unsigned short int new_img; + unsigned int new_img; int locate_motion_mode; int locate_motion_style; @@ -334,25 +335,25 @@ struct context { int smartmask_speed; /* Commands to the motion thread */ - volatile unsigned short int snapshot; /* Make a snapshot */ - volatile unsigned short int makemovie; /* End a movie */ - volatile unsigned short int finish; /* End the thread */ - volatile unsigned short int restart; /* Restart the thread when it ends */ + volatile unsigned int snapshot; /* Make a snapshot */ + volatile unsigned int makemovie; /* End a movie */ + volatile unsigned int finish; /* End the thread */ + volatile unsigned int restart; /* Restart the thread when it ends */ /* Is the motion thread running */ - volatile unsigned short int running; + volatile unsigned int running; volatile int watchdog; pthread_t thread_id; int event_nr; int prev_event; - int lightswitch_framecounter; + unsigned int lightswitch_framecounter; char text_event_string[PATH_MAX]; /* The text for conv. spec. %C - we assume PATH_MAX normally 4096 characters is fine */ int postcap; /* downcounter, frames left to to send post event */ - short int shots; - unsigned short int detecting_motion; + int shots; + unsigned int detecting_motion; struct tm *currenttime_tm; struct tm *eventtime_tm; @@ -361,12 +362,12 @@ struct context { time_t eventtime; time_t connectionlosttime; /* timestamp from connection lost */ - int lastrate; - unsigned short int startup_frames; - unsigned short int moved; - unsigned short int pause; + unsigned int lastrate; + unsigned int startup_frames; + unsigned int moved; + unsigned int pause; int missing_frame_counter; /* counts failed attempts to fetch picture frame from camera */ - unsigned short int lost_connection; + unsigned int lost_connection; #if (defined(BSD)) int tuner_dev; @@ -394,10 +395,10 @@ struct context { PGconn *database_pg; #endif - short int movie_fps; + int movie_fps; char newfilename[PATH_MAX]; char extpipefilename[PATH_MAX]; - short int movie_last_shot; + int movie_last_shot; #ifdef HAVE_FFMPEG struct ffmpeg *ffmpeg_output; @@ -411,7 +412,8 @@ struct context { extern pthread_mutex_t global_lock; extern volatile int threads_running; -extern unsigned short int debug_level; +extern unsigned int debug_level; +extern FILE *ptr_logfile; /* TLS keys below */ extern pthread_key_t tls_key_threadnr; /* key for thread number */ diff --git a/netcam.c b/netcam.c index 69acec4..0662761 100644 --- a/netcam.c +++ b/netcam.c @@ -165,7 +165,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) "([^/:]|[-.a-z0-9]*)(:([0-9]*))?($|(/[^:][/-_.a-z0-9]+))"; if (debug_level > CAMERA_DEBUG) - motion_log(-1, 0, "%s: Entry netcam_url_parse data %s", __FUNCTION__, text_url); + motion_log(0, 0, "%s: Entry netcam_url_parse data %s", __FUNCTION__, text_url); memset(parse_url, 0, sizeof(struct url_t)); /* @@ -180,7 +180,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) for (i = 0; i < 10; i++) { if ((s = netcam_url_match(matches[i], text_url)) != NULL) { if (debug_level > CAMERA_DEBUG) - motion_log(-1, 0, "%s: Parse case %d data %s", __FUNCTION__, i, s); + motion_log(0, 0, "%s: Parse case %d data %s", __FUNCTION__, i, s); switch (i) { case 1: parse_url->service = s; @@ -510,7 +510,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam) } if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Found image header record", __FUNCTION__); + motion_log(0, 0, "%s: Found image header record", __FUNCTION__); free(header); return 0; @@ -594,7 +594,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam) if (firstflag) { if ((ret = http_result_code(header)) != 200) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: HTTP Result code %d", __FUNCTION__, ret); + motion_log(0, 0, "%s: HTTP Result code %d", __FUNCTION__, ret); free(header); if (netcam->connect_keepalive) { @@ -1039,7 +1039,7 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) new_size = buff->size + real_alloc; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", + motion_log(0, 0, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", __FUNCTION__, (int) buff->used, (int) buff->size, (int) buff->used, new_size); @@ -1246,7 +1246,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) */ if (debug_level > CAMERA_INFO) { - motion_log(-1, 0, + motion_log(0, 0, "%s: Potential split boundary - " "%d chars flushed, %d " "re-positioned", __FUNCTION__, ix, @@ -1316,7 +1316,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Calculated frame time %f", + motion_log(0, 0, "%s: Calculated frame time %f", __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1387,7 +1387,7 @@ static int netcam_http_request(netcam_context_ptr netcam) * (Not always true now Keep-Alive is implemented) */ if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: about to try to connect, time #%d", + motion_log(0, 0, "%s: about to try to connect, time #%d", __FUNCTION__, ix); if (netcam_connect(netcam, 0) != 0) { @@ -1437,10 +1437,10 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam) while (1) { retval = rbuf_read_bufferful(netcam); if (retval <= 0) { /* If we got 0, we timeoutted. */ - motion_log(-1, 0, "%s: Read error, trying to reconnect..", __FUNCTION__); + motion_log(0, 0, "%s: Read error, trying to reconnect..", __FUNCTION__); /* We may have lost the connexion */ if (netcam_http_request(netcam) < 0) { - motion_log(-1, 0, "%s: lost the cam.", __FUNCTION__); + motion_log(0, 0, "%s: lost the cam.", __FUNCTION__); return -1; /* We REALLY lost the cam... bail out for now. */ } } @@ -1522,7 +1522,7 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) read_bytes += retval; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Read [%d/%d] header bytes.", + motion_log(0, 0, "%s: Read [%d/%d] header bytes.", __FUNCTION__, read_bytes, sizeof(mh)); @@ -1536,7 +1536,7 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) /* Now check the validity of our header. */ if (strncmp(mh.mh_magic, MJPG_MH_MAGIC, MJPG_MH_MAGIC_SIZE)) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Invalid header received, reconnecting", + motion_log(0, 0, "%s: Invalid header received, reconnecting", __FUNCTION__); @@ -1560,12 +1560,12 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) mh.mh_chunksize - read_bytes); read_bytes += retval; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Read [%d/%d] chunk bytes, [%d/%d] total", + motion_log(0, 0, "%s: Read [%d/%d] chunk bytes, [%d/%d] total", __FUNCTION__, read_bytes, mh.mh_chunksize, buffer->used + read_bytes, mh.mh_framesize); if (retval < (int)(mh.mh_chunksize - read_bytes)) { - /* motion_log(-1, 0, "Chunk incomplete, going to refill."); */ + /* motion_log(0, 0, "Chunk incomplete, going to refill."); */ if (netcam_mjpg_buffer_refill(netcam) < 0) return -1; @@ -1574,7 +1574,7 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) buffer->used += read_bytes; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Chunk complete, buffer used [%d] bytes.", + motion_log(0, 0, "%s: Chunk complete, buffer used [%d] bytes.", __FUNCTION__, buffer->used); @@ -1582,7 +1582,7 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) if (mh.mh_framesize == buffer->used) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Image complete, buffer used [%d] bytes.", + motion_log(0, 0, "%s: Image complete, buffer used [%d] bytes.", __FUNCTION__, buffer->used); break; @@ -1612,7 +1612,7 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Calculated frame time %f", + motion_log(0, 0, "%s: Calculated frame time %f", __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1689,7 +1689,7 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Calculated frame time %f", + motion_log(0, 0, "%s: Calculated frame time %f", __FUNCTION__, netcam->av_frame_time); } @@ -1733,7 +1733,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) int loop_counter = 0; if (debug_level > CAMERA_VERBOSE) { - motion_log(-1, 0, "%s: Begin", __FUNCTION__); + motion_log(0, 0, "%s: Begin", __FUNCTION__); } netcam_buff_ptr buffer; @@ -1749,23 +1749,23 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) /*int fstat(int filedes, struct stat *buf);*/ do { if (stat(netcam->file->path, &statbuf)) { - motion_log(-1, 0, "%s: stat(%s) error", __FUNCTION__, netcam->file->path); + motion_log(0, 0, "%s: stat(%s) error", __FUNCTION__, netcam->file->path); return -1; } if (debug_level > CAMERA_VERBOSE) - motion_log(-1, 0, "%s: statbuf.st_mtime[%d] != last_st_mtime[%d]", + motion_log(0, 0, "%s: statbuf.st_mtime[%d] != last_st_mtime[%d]", __FUNCTION__, statbuf.st_mtime, netcam->file->last_st_mtime); /* its waits POLLING_TIMEOUT */ if (loop_counter>((POLLING_TIMEOUT*1000*1000)/(POLLING_TIME/1000))) { - motion_log(-1, 0, "%s: waiting new file image timeout", __FUNCTION__); + motion_log(0, 0, "%s: waiting new file image timeout", __FUNCTION__); return -1; } if (debug_level > CAMERA_VERBOSE) - motion_log(-1, 0, "%s: delay waiting new file image ", __FUNCTION__); + motion_log(0, 0, "%s: delay waiting new file image ", __FUNCTION__); //its waits 5seconds - READ_TIMEOUT //SLEEP(netcam->timeout.tv_sec, netcam->timeout.tv_usec*1000); @@ -1789,13 +1789,13 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) /* Do the read */ netcam->file->control_file_desc = open(netcam->file->path, O_RDONLY); if (netcam->file->control_file_desc < 0) { - motion_log(-1, 0, "%s: open(%s) error: %d", __FUNCTION__, + motion_log(0, 0, "%s: open(%s) error: %d", __FUNCTION__, netcam->file->path, netcam->file->control_file_desc); return -1; } if ((len = read(netcam->file->control_file_desc, buffer->ptr + buffer->used, statbuf.st_size)) < 0) { - motion_log(-1, 0, "%s: read(%s) error: %d", __FUNCTION__, + motion_log(0, 0, "%s: read(%s) error: %d", __FUNCTION__, netcam->file->control_file_desc, len); return -1; } @@ -1820,7 +1820,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Calculated frame time %f", __FUNCTION__, + motion_log(0, 0, "%s: Calculated frame time %f", __FUNCTION__, netcam->av_frame_time); } @@ -1848,7 +1848,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) pthread_mutex_unlock(&netcam->mutex); if (debug_level > CAMERA_VERBOSE) - motion_log(-1, 0, "%s: End", __FUNCTION__); + motion_log(0, 0, "%s: End", __FUNCTION__); return 0; } @@ -2263,7 +2263,7 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) netcam_url_free(url); /* Cleanup the url data */ if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: Camera connect string is ''%s'' End of camera connect string.", + motion_log(0, 0, "%s: Camera connect string is ''%s'' End of camera connect string.", __FUNCTION__, netcam->connect_request); return 0; } @@ -2311,7 +2311,7 @@ static int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url) } if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: connected, going on to read image.", __FUNCTION__); + motion_log(0, 0, "%s: connected, going on to read image.", __FUNCTION__); netcam->get_image = netcam_read_html_jpeg; return 0; @@ -2355,7 +2355,7 @@ static int netcam_setup_mjpg(netcam_context_ptr netcam, struct url_t *url) * header, so don't move anymore, initialization complete. */ if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: connected, going on to read and decode MJPG chunks.", + motion_log(0, 0, "%s: connected, going on to read and decode MJPG chunks.", __FUNCTION__); netcam->get_image = netcam_read_mjpg_jpeg; @@ -2545,7 +2545,7 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag) * Although this shouldn't happen, if it *does* happen we will * log it (just for the programmer's information) */ - motion_log(-1, 0, "%s: No response from camera " + motion_log(0, 0, "%s: No response from camera " "handler - it must have already died", __FUNCTION__); pthread_mutex_lock(&global_lock); @@ -2688,7 +2688,7 @@ int netcam_start(struct context *cnt) struct url_t url; /* for parsing netcam URL */ if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: entered netcam_start()", __FUNCTION__); + motion_log(0, 0, "%s: entered netcam_start()", __FUNCTION__); memset(&url, 0, sizeof(url)); if (SETUP) @@ -2814,22 +2814,22 @@ int netcam_start(struct context *cnt) if ((url.service) && (!strcmp(url.service, "http"))) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: now calling netcam_setup_html()", __FUNCTION__); + motion_log(0, 0, "%s: now calling netcam_setup_html()", __FUNCTION__); retval = netcam_setup_html(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "ftp"))) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s:: now calling netcam_setup_ftp", __FUNCTION__); + motion_log(0, 0, "%s:: now calling netcam_setup_ftp", __FUNCTION__); retval = netcam_setup_ftp(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "file"))) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: now calling netcam_setup_file()", __FUNCTION__); + motion_log(0, 0, "%s: now calling netcam_setup_file()", __FUNCTION__); retval = netcam_setup_file(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "mjpg"))) { if (debug_level > CAMERA_INFO) - motion_log(-1, 0, "%s: now calling netcam_setup_mjpg()", __FUNCTION__); + motion_log(0, 0, "%s: now calling netcam_setup_mjpg()", __FUNCTION__); strcpy(url.service, "http"); /* Put back a real URL service. */ retval = netcam_setup_mjpg(netcam, &url); diff --git a/netcam_jpeg.c b/netcam_jpeg.c index 2a34d85..7f60044 100644 --- a/netcam_jpeg.c +++ b/netcam_jpeg.c @@ -294,13 +294,13 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) pthread_mutex_unlock(&netcam->mutex); if (debug_level > CAMERA_WARNINGS) - motion_log(-1, 0, "%s: no new pic, no signal rcvd", __FUNCTION__); + motion_log(0, 0, "%s: no new pic, no signal rcvd", __FUNCTION__); return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR; } if (debug_level > CAMERA_VERBOSE) - motion_log(-1, 0, "%s: ***new pic delay successful***", __FUNCTION__); + motion_log(0, 0, "%s: ***new pic delay successful***", __FUNCTION__); } netcam->imgcnt_last = netcam->imgcnt; diff --git a/stream.c b/stream.c index 64cf98f..894a41e 100644 --- a/stream.c +++ b/stream.c @@ -343,7 +343,7 @@ void stream_stop(struct context *cnt) struct stream *next = cnt->stream.next; if (debug_level >= CAMERA_VERBOSE) - motion_log(-1, 0, "%s: Closing motion-stream listen socket" + motion_log(0, 0, "%s: Closing motion-stream listen socket" " & active motion-stream sockets", __FUNCTION__); else motion_log(LOG_INFO, 0, "%s: Closing motion-stream listen socket" @@ -366,7 +366,7 @@ void stream_stop(struct context *cnt) } if (debug_level >= CAMERA_VERBOSE) - motion_log(-1, 0, "%s: Closed motion-stream listen socket" + motion_log(0, 0, "%s: Closed motion-stream listen socket" " & active motion-stream sockets", __FUNCTION__); else motion_log(LOG_INFO, 0, "%s: Closed motion-stream listen socket" diff --git a/track.c b/track.c index d1ef978..d1175b4 100644 --- a/track.c +++ b/track.c @@ -41,37 +41,37 @@ struct trackoptions track_template = { /* Add your own center and move functions here: */ -static unsigned short int servo_position(struct context *cnt, short unsigned int motor); +static unsigned int servo_position(struct context *cnt, unsigned int motor); -static unsigned short int servo_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED); -static unsigned short int stepper_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED); -static unsigned short int iomojo_center(struct context *cnt, int xoff, int yoff); +static unsigned int servo_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED); +static unsigned int stepper_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED); +static unsigned int iomojo_center(struct context *cnt, int xoff, int yoff); -static unsigned short int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs); -static unsigned short int servo_move(struct context *cnt, struct coord *cent, - struct images *imgs, unsigned short int manual); -static unsigned short int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs); +static unsigned int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs); +static unsigned int servo_move(struct context *cnt, struct coord *cent, + struct images *imgs, unsigned int manual); +static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs); #ifndef WITHOUT_V4L -static unsigned short int lqos_center(struct context *cnt, int dev, int xoff, int yoff); -static unsigned short int lqos_move(struct context *cnt, int dev, struct coord *cent, - struct images *imgs, unsigned short int manual); +static unsigned int lqos_center(struct context *cnt, int dev, int xoff, int yoff); +static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, + struct images *imgs, unsigned int manual); #ifdef MOTION_V4L2 -static unsigned short int uvc_center(struct context *cnt, int dev, int xoff, int yoff); -static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *cent, - struct images *imgs, unsigned short int manual); +static unsigned int uvc_center(struct context *cnt, int dev, int xoff, int yoff); +static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, + struct images *imgs, unsigned int manual); #endif /* MOTION_V4L2 */ #endif /* WITHOUT_V4L */ /* Add a call to your functions here: */ -unsigned short int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, - unsigned short int manual, int xoff, int yoff) +unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, + unsigned int manual, int xoff, int yoff) { if (!manual && !cnt->track.active) return 0; if (cnt->track.type == TRACK_TYPE_STEPPER) { - unsigned short int ret; + unsigned int ret; ret = stepper_center(cnt, xoff, yoff); if (!ret) { motion_log(LOG_ERR, 1, "%s: internal error", __FUNCTION__); @@ -101,8 +101,8 @@ unsigned short int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, } /* Add a call to your functions here: */ -unsigned short int track_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, - unsigned short int manual) +unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, + unsigned int manual) { if (!manual && !cnt->track.active) @@ -139,8 +139,8 @@ unsigned short int track_move(struct context *cnt, int dev, struct coord *cent, ******************************************************************************/ -static unsigned short int stepper_command(struct context *cnt, unsigned short int motor, - unsigned short int command, unsigned short int data) +static unsigned int stepper_command(struct context *cnt, unsigned int motor, + unsigned int command, unsigned int data) { char buffer[3]; time_t timeout = time(NULL); @@ -166,13 +166,13 @@ static unsigned short int stepper_command(struct context *cnt, unsigned short in } -static unsigned short int stepper_status(struct context *cnt, unsigned short int motor) +static unsigned int stepper_status(struct context *cnt, unsigned int motor) { return stepper_command(cnt, motor, STEPPER_COMMAND_STATUS, 0); } -static unsigned short int stepper_center(struct context *cnt, int x_offset, int y_offset) +static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offset) { struct termios adtio; @@ -231,10 +231,10 @@ static unsigned short int stepper_center(struct context *cnt, int x_offset, int return cnt->track.move_wait; } -static unsigned short int stepper_move(struct context *cnt, +static unsigned int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs) { - unsigned short int command = 0, data = 0; + unsigned int command = 0, data = 0; if (cnt->track.dev < 0) { motion_log(LOG_INFO, 0, "%s: No device %s started yet , trying stepper_center()", @@ -327,8 +327,8 @@ static int servo_open(struct context *cnt) } -static unsigned short int servo_command(struct context *cnt, unsigned short int motor, - unsigned short int command, unsigned short int data) +static unsigned int servo_command(struct context *cnt, unsigned int motor, + unsigned int command, unsigned int data) { unsigned char buffer[3]; time_t timeout = time(NULL); @@ -364,9 +364,9 @@ static unsigned short int servo_command(struct context *cnt, unsigned short int } -static unsigned short int servo_position(struct context *cnt, short unsigned int motor) +static unsigned int servo_position(struct context *cnt, unsigned int motor) { - unsigned short int ret = 0; + unsigned int ret = 0; ret = servo_command(cnt, motor, SERVO_COMMAND_POSITION, 0); @@ -381,11 +381,12 @@ static unsigned short int servo_position(struct context *cnt, short unsigned int * - Does relative movements to current position. * */ -static unsigned short int servo_move(struct context *cnt, struct coord *cent, - struct images *imgs, short unsigned int manual) +static unsigned int servo_move(struct context *cnt, struct coord *cent, + struct images *imgs, unsigned int manual) { - unsigned short int command = 0; - unsigned short int data = 0; + unsigned int command = 0; + unsigned int data = 0; + unsigned int position; /* If device is not open yet , open and center */ if (cnt->track.dev < 0) { @@ -403,7 +404,6 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, if (manual) { int offset; - int position; if (cent->x) { position = servo_position(cnt, cnt->track.motorx); @@ -418,7 +418,8 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, data = abs(offset); - if ((data + position > cnt->track.maxx) || (position - offset < cnt->track.minx)) { + if ((data + position > (unsigned)cnt->track.maxx) || + (position - offset < (unsigned)cnt->track.minx)) { motion_log(LOG_INFO, 0, "%s: x %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); return 0; @@ -443,7 +444,8 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, data = abs(offset); - if ((data + position > cnt->track.maxy) || (position - offset < cnt->track.miny)) { + if ((data + position > (unsigned)cnt->track.maxy) || + (position - offset < (unsigned)cnt->track.miny)) { motion_log(LOG_INFO, 0, "%s: y %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); return 0; @@ -456,8 +458,6 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, } } else { - int position; - /***** x-axis *****/ /* Move left */ @@ -489,7 +489,8 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, // TODO: need to get position to avoid overflow limits position = servo_position(cnt, cnt->track.motorx); - if ((position + data > cnt->track.maxx) || (position - data < cnt->track.minx)) { + if ((position + data > (unsigned)cnt->track.maxx) || + (position - data < (unsigned)cnt->track.minx)) { motion_log(LOG_INFO, 0, "%s: x %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); return 0; @@ -537,7 +538,8 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, // TODO: need to get position to avoid overflow limits position = servo_position(cnt, cnt->track.motory); - if ((position + data > cnt->track.maxy) || (position - data < cnt->track.miny)) { + if ((position + data > (unsigned)cnt->track.maxy) || + (position - data < (unsigned)cnt->track.miny)) { motion_log(LOG_INFO, 0, "%s: y %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); return 0; @@ -559,7 +561,7 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, } #if 0 -static unsigned short int servo_status(struct context *cnt, unsigned short int motor) +static unsigned int servo_status(struct context *cnt, unsigned int motor) { return servo_command(cnt, motor, SERVO_COMMAND_STATUS, 0); } @@ -576,9 +578,9 @@ static unsigned short int servo_status(struct context *cnt, unsigned short int m * */ -static unsigned short int servo_center(struct context *cnt, int x_offset, int y_offset) +static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset) { - unsigned short int ret = 0; + unsigned int ret = 0; int x_offset_abs; int y_offset_abs; @@ -633,7 +635,7 @@ static unsigned short int servo_center(struct context *cnt, int x_offset, int y_ ******************************************************************************/ -static char iomojo_command(struct context *cnt, char *command, unsigned short int len, unsigned short int ret) +static char iomojo_command(struct context *cnt, char *command, int len, unsigned int ret) { char buffer[1]; time_t timeout = time(NULL); @@ -653,7 +655,7 @@ static char iomojo_command(struct context *cnt, char *command, unsigned short in return buffer[0]; } -static void iomojo_setspeed(struct context *cnt, unsigned short int speed) +static void iomojo_setspeed(struct context *cnt, unsigned int speed) { char command[3]; @@ -675,7 +677,7 @@ static void iomojo_movehome(struct context *cnt) iomojo_command(cnt, command, 2, 0); } -static unsigned short int iomojo_center(struct context *cnt, int x_offset, int y_offset) +static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offset) { struct termios adtio; char command[5], direction = 0; @@ -739,7 +741,7 @@ static unsigned short int iomojo_center(struct context *cnt, int x_offset, int y return cnt->track.move_wait; } -static unsigned short int iomojo_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs) { char command[5]; @@ -805,7 +807,7 @@ static unsigned short int iomojo_move(struct context *cnt, int dev, struct coord ******************************************************************************/ #ifndef WITHOUT_V4L -static unsigned short int lqos_center(struct context *cnt, int dev, int x_angle, int y_angle) +static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y_angle) { int reset = 3; struct pwc_mpt_angles pma; @@ -855,8 +857,8 @@ static unsigned short int lqos_center(struct context *cnt, int dev, int x_angle, return cnt->track.move_wait; } -static unsigned short int lqos_move(struct context *cnt, int dev, struct coord *cent, - struct images *imgs, unsigned short int manual) +static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, + struct images *imgs, unsigned int manual) { int delta_x = cent->x - (imgs->width / 2); int delta_y = cent->y - (imgs->height / 2); @@ -932,7 +934,7 @@ static unsigned short int lqos_move(struct context *cnt, int dev, struct coord * ******************************************************************************/ #ifdef MOTION_V4L2 -static unsigned short int uvc_center(struct context *cnt, int dev, int x_angle, int y_angle) +static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_angle) { /* CALC ABSOLUTE MOVING : Act.Position +/- delta to request X and Y */ int move_x_degrees = 0, move_y_degrees = 0; @@ -1085,8 +1087,8 @@ static unsigned short int uvc_center(struct context *cnt, int dev, int x_angle, return cnt->track.move_wait; } -static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *cent, - struct images *imgs, unsigned short int manual) +static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, + struct images *imgs, unsigned int manual) { /* RELATIVE MOVING : Act.Position +/- X and Y */ @@ -1099,7 +1101,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c /* Don't worry, if the WebCam make a sound - over End at PAN - hmmm, should it be normal ...? */ /* PAN Value 7777 in relative will init also a want reset for CAM - it will be "0" after that */ if ((cnt->track.minmaxfound != 1) || (cent->x == 7777)) { - unsigned short int reset = 3; //0-non reset, 1-reset pan, 2-reset tilt, 3-reset pan&tilt + unsigned int reset = 3; //0-non reset, 1-reset pan, 2-reset tilt, 3-reset pan&tilt struct v4l2_control control_s; control_s.id = V4L2_CID_PANTILT_RESET; diff --git a/track.h b/track.h index 5bab97f..0e44ae6 100644 --- a/track.h +++ b/track.h @@ -15,26 +15,26 @@ struct trackoptions { int dev; /* Config options: */ - unsigned short int type; + unsigned int type; char *port; - unsigned short int motorx; - unsigned short int motory; + unsigned int motorx; + unsigned int motory; int maxx; int maxy; int minx; int miny; - unsigned short int stepsize; - unsigned short int speed; - unsigned short int homex; - unsigned short int homey; - unsigned short int iomojo_id; - unsigned short int active; - unsigned short int motorx_reverse; - unsigned short int motory_reverse; - unsigned short int minmaxfound; - unsigned short int step_angle_x; - unsigned short int step_angle_y; - unsigned short int move_wait; + unsigned int stepsize; + unsigned int speed; + unsigned int homex; + unsigned int homey; + unsigned int iomojo_id; + unsigned int active; + unsigned int motorx_reverse; + unsigned int motory_reverse; + unsigned int minmaxfound; + unsigned int step_angle_x; + unsigned int step_angle_y; + unsigned int move_wait; /* UVC */ int pan_angle; // degrees int tilt_angle; // degrees @@ -42,8 +42,8 @@ struct trackoptions { extern struct trackoptions track_template; -unsigned short int track_center(struct context *, int, unsigned short int, int, int); -unsigned short int track_move(struct context *, int, struct coord *, struct images *, unsigned short int); +unsigned int track_center(struct context *, int, unsigned int, int, int); +unsigned int track_move(struct context *, int, struct coord *, struct images *, unsigned int); /* * Some default values: diff --git a/video.c b/video.c index 96a717d..266b1df 100644 --- a/video.c +++ b/video.c @@ -176,7 +176,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp } if (debug_level >= CAMERA_VERBOSE) - motion_log(-1, 0, "%s: Frequency set", __FUNCTION__); + motion_log(0, 0, "%s: Frequency set", __FUNCTION__); } } diff --git a/video2.c b/video2.c index 601653e..59103a3 100644 --- a/video2.c +++ b/video2.c @@ -309,7 +309,7 @@ static int v4l2_select_input(src_v4l2_t * vid_source, int in, int norm, unsigned static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int *width, int *height) { struct v4l2_fmtdesc fmt; - short int v4l2_pal; + int v4l2_pal; static const u32 supported_formats[] = { /* higher index means better chance to be used */ V4L2_PIX_FMT_SN9C10X, @@ -327,7 +327,7 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int 0 }; - short int index_format = -1; + int index_format = -1; memset(&fmt, 0, sizeof(struct v4l2_fmtdesc)); fmt.index = v4l2_pal = 0; @@ -336,7 +336,7 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int motion_log(LOG_INFO, 0, "%s: Supported palettes:", __FUNCTION__); while (xioctl(vid_source->fd, VIDIOC_ENUM_FMT, &fmt) != -1) { - short int i; + int i; motion_log(LOG_INFO, 0, "%i: %c%c%c%c (%s)", v4l2_pal, fmt.pixelformat >> 0, fmt.pixelformat >> 8, fmt.pixelformat >> 16, fmt.pixelformat >> 24, fmt.description); diff --git a/video_common.c b/video_common.c index 5f883db..7d6cfb4 100644 --- a/video_common.c +++ b/video_common.c @@ -763,9 +763,9 @@ static int vid_v4lx_start(struct context *cnt) } #endif if (dev->v4l2 == 0) { - motion_log(-1, 0, "%s: Using V4L1", __FUNCTION__); + motion_log(1, 0, "%s: Using V4L1", __FUNCTION__); } else { - motion_log(-1, 0, "%s: Using V4L2", __FUNCTION__); + motion_log(1, 0, "%s: Using V4L2", __FUNCTION__); /* Update width & height because could be changed in v4l2_start () */ width = dev->width; height = dev->height; diff --git a/video_freebsd.c b/video_freebsd.c index 42a3c7b..9d43ad7 100644 --- a/video_freebsd.c +++ b/video_freebsd.c @@ -184,7 +184,7 @@ static int set_hue(int viddev, int new_hue) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -199,7 +199,7 @@ static int get_hue(int viddev , int *hue) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); *hue = ioctlval; return ioctlval; @@ -216,7 +216,7 @@ static int set_saturation(int viddev, int new_saturation) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -231,7 +231,7 @@ static int get_saturation(int viddev , int *saturation) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); *saturation = ioctlval; return ioctlval; @@ -248,7 +248,7 @@ static int set_contrast(int viddev, int new_contrast) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -263,7 +263,7 @@ static int get_contrast(int viddev, int *contrast) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); *contrast = ioctlval; return ioctlval; @@ -281,7 +281,7 @@ static int set_brightness(int viddev, int new_bright) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -297,7 +297,7 @@ static int get_brightness(int viddev, int *brightness) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); *brightness = ioctlval; return ioctlval; @@ -368,7 +368,7 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) VBI ?! (METEOR_INPUT_DEV_SVIDEO) */ -static int set_input(struct video_dev *viddev, unsigned short input) +static int set_input(struct video_dev *viddev, unsigned input) { int actport; int portdata[] = { METEOR_INPUT_DEV0, METEOR_INPUT_DEV1, @@ -400,7 +400,7 @@ static int set_input(struct video_dev *viddev, unsigned short input) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d]", __FUNCTION__, input); + motion_log(0, 0, "%s: to [%d]", __FUNCTION__, input); return input; } @@ -441,7 +441,7 @@ static int set_geometry(struct video_dev *viddev, int width, int height) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to [%d/%d] Norm %d", __FUNCTION__, + motion_log(0, 0, "%s: to [%d/%d] Norm %d", __FUNCTION__, width, height, viddev->norm); return 0; @@ -451,7 +451,7 @@ static int set_geometry(struct video_dev *viddev, int width, int height) set input format ( PAL, NTSC, SECAM, etc ... ) */ -static int set_input_format(struct video_dev *viddev, unsigned short newformat) +static int set_input_format(struct video_dev *viddev, unsigned newformat) { int input_format[] = { NORM_PAL_NEW, NORM_NTSC_NEW, NORM_SECAM_NEW, NORM_DEFAULT_NEW}; int format; @@ -478,7 +478,7 @@ static int set_input_format(struct video_dev *viddev, unsigned short newformat) } if (debug_level >= CAMERA_VIDEO) - motion_log(-1, 0, "%s: to %d", __FUNCTION__, newformat); + motion_log(0, 0, "%s: to %d", __FUNCTION__, newformat); return newformat; } @@ -504,40 +504,40 @@ statict int setup_pixelformat(int bktr) switch (p.type) { case METEOR_PIXTYPE_RGB: - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB"); switch (p.masks[0]) { case 31744: // 15 bpp format = p.swap_bytes ? VIDEO_RGB15_LE : VIDEO_RGB15_BE; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); break; case 63488: // 16 bpp format = p.swap_bytes ? VIDEO_RGB16_LE : VIDEO_RGB16_BE; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); break; case 16711680: // 24/32 bpp if (p.Bpp == 3 && p.swap_bytes == 1) { format = VIDEO_BGR24; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); } else if (p.Bpp == 4 && p.swap_bytes == 1 && p.swap_shorts == 1) { format = VIDEO_BGR32; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); } else if (p.Bpp == 4 && p.swap_bytes == 0 && p.swap_shorts == 0) { format = VIDEO_RGB32; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); } } break; case METEOR_PIXTYPE_YUV: format = VIDEO_YUV422P; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_YUV"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV"); break; case METEOR_PIXTYPE_YUV_12: format = VIDEO_YUV422P; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_12"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_12"); break; case METEOR_PIXTYPE_YUV_PACKED: format = VIDEO_YUV422P; - motion_log(-1, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); + motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); break; } @@ -613,7 +613,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) */ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, - unsigned short input, unsigned short norm, unsigned long freq) + unsigned input, unsigned norm, unsigned long freq) { int dev_bktr = viddev->fd_bktr; struct sigaction act, old; @@ -675,7 +675,7 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, if (freq) { if (debug_level >= CAMERA_DEBUG) - motion_log(-1, 0, "%s: Frequency set (no implemented yet", __FUNCTION__); + motion_log(0, 0, "%s: Frequency set (no implemented yet", __FUNCTION__); /* TODO missing implementation set_channelset(viddev); @@ -869,7 +869,7 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int /* set input & freq if needed FIXME not allowed use Tuner yet */ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height, - unsigned short input, unsigned short norm, int skip, unsigned long freq) + unsigned input, unsigned norm, int skip, unsigned long freq) { if (input != viddev->input || norm != viddev->norm || freq != viddev->freq) { @@ -1082,11 +1082,11 @@ int vid_start(struct context *cnt) struct video_dev *dev; int fd_tuner = -1; int width, height, capture_method; - unsigned short input, norm; + unsigned input, norm; unsigned long frequency; - motion_log(-1, 0, "%s: [%s]", __FUNCTION__, conf->video_device); + motion_log(0, 0, "%s: [%s]", __FUNCTION__, conf->video_device); /* We use width and height from conf in this function. They will be assigned * to width and height in imgs here, and cap_width and cap_height in @@ -1140,7 +1140,7 @@ int vid_start(struct context *cnt) return -1; } - motion_log(-1, 0, "%s Reusing [%s] inputs [%d,%d] Change capture method " + motion_log(0, 0, "%s Reusing [%s] inputs [%d,%d] Change capture method " "METEOR_CAP_SINGLE", __FUNCTION__, dev->video_device, dev->input, conf->input); @@ -1155,7 +1155,7 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(-1, 0, "%s VIDEO_PALETTE_YUV420P setting imgs.size " + motion_log(0, 0, "%s VIDEO_PALETTE_YUV420P setting imgs.size " "and imgs.motionsize", __FUNCTION__); cnt->imgs.motionsize = width * height; cnt->imgs.size = (width * height * 3) / 2; @@ -1247,7 +1247,7 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(-1, 0, "%s: VIDEO_PALETTE_YUV420P imgs.type", __FUNCTION__); + motion_log(0, 0, "%s: VIDEO_PALETTE_YUV420P imgs.type", __FUNCTION__); cnt->imgs.size = (width * height * 3) / 2; cnt->imgs.motionsize = width * height; break; diff --git a/video_freebsd.h b/video_freebsd.h index 0a348b7..ce3bd1a 100644 --- a/video_freebsd.h +++ b/video_freebsd.h @@ -93,8 +93,8 @@ struct video_dev { int fd_tuner; const char *video_device; const char *tuner_device; - unsigned short input; - unsigned short norm; + unsigned input; + unsigned norm; int width; int height; int contrast; diff --git a/vloopback_motion.c b/vloopback_motion.c index 1f39fd9..9d8056f 100644 --- a/vloopback_motion.c +++ b/vloopback_motion.c @@ -83,7 +83,7 @@ static int v4l_open_vidpipe(void) pipe_fd = open(pipepath, O_RDWR); if (pipe_fd >= 0) { - motion_log(-1, 0, "%s: \tInput: /dev/%s \tOutput: /dev/%s", + motion_log(0, 0, "%s: \tInput: /dev/%s \tOutput: /dev/%s", __FUNCTION__, input, output); break; } @@ -163,7 +163,7 @@ static int v4l_open_vidpipe(void) closedir(dir); if (pipe_fd >= 0) - motion_log(-1, 0, "%s: Opened %s as input", __FUNCTION__, pipepath); + motion_log(0, 0, "%s: Opened %s as input", __FUNCTION__, pipepath); } return pipe_fd; @@ -179,7 +179,7 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type) dev = v4l_open_vidpipe(); } else { dev = open(dev_name, O_RDWR); - motion_log(-1, 0, "%s: Opened %s as input", __FUNCTION__, dev_name); + motion_log(0, 0, "%s: Opened %s as input", __FUNCTION__, dev_name); } if (dev < 0) { diff --git a/webhttpd.c b/webhttpd.c index b0a41bc..b9f484a 100644 --- a/webhttpd.c +++ b/webhttpd.c @@ -364,12 +364,12 @@ static void url_decode(char *urlencoded, size_t length) return 1 to exit from function. */ -static unsigned short int config(char *pointer, char *res, unsigned short int length_uri, - unsigned short int thread, int client_socket, void *userdata) +static unsigned int config(char *pointer, char *res, unsigned int length_uri, + unsigned int thread, int client_socket, void *userdata) { char question='\0'; char command[256] = {'\0'}; - unsigned short int i; + unsigned int i; struct context **cnt = userdata; warningkill = sscanf(pointer, "%255[a-z]%c", command , &question); @@ -410,7 +410,7 @@ static unsigned short int config(char *pointer, char *res, unsigned short int le char *temp = retval; size_t retval_miss = 0; size_t retval_len = strlen(retval); - unsigned short int ind = 0; + unsigned int ind = 0; char thread_strings[1024] = {'\0'}; while (retval_miss != retval_len) { @@ -545,10 +545,6 @@ static unsigned short int config(char *pointer, char *res, unsigned short int le free(type); type = mystrdup("0"); conf_cmdparse(cnt+thread, config_params[i].param_name, type); - } else if (!strcmp(type, "short")) { - free(type); - type = mystrdup("0"); - conf_cmdparse(cnt+thread, config_params[i].param_name, type); } else if (!strcmp(type, "bool")) { free(type); type = mystrdup("off"); @@ -898,13 +894,13 @@ static unsigned short int config(char *pointer, char *res, unsigned short int le return 1 for makemovie & snaphost */ -static unsigned short int action(char *pointer, char *res, unsigned short int length_uri, - unsigned short int thread, int client_socket, void *userdata) +static unsigned int action(char *pointer, char *res, unsigned int length_uri, + unsigned int thread, int client_socket, void *userdata) { /* parse action commands */ char command[256] = {'\0'}; struct context **cnt = userdata; - unsigned short int i = 0; + unsigned int i = 0; warningkill = sscanf(pointer, "%255[a-z]" , command); if (!strcmp(command, "makemovie")) { @@ -1076,12 +1072,12 @@ static unsigned short int action(char *pointer, char *res, unsigned short int le return 1 to exit from function. */ -static unsigned short int detection(char *pointer, char *res, unsigned short int length_uri, - unsigned short int thread, int client_socket, void *userdata) +static unsigned int detection(char *pointer, char *res, unsigned int length_uri, + unsigned int thread, int client_socket, void *userdata) { char command[256] = {'\0'}; struct context **cnt = userdata; - unsigned short int i = 0; + unsigned int i = 0; warningkill = sscanf(pointer, "%255[a-z]" , command); if (!strcmp(command, "status")) { @@ -1239,8 +1235,8 @@ static unsigned short int detection(char *pointer, char *res, unsigned short int return 1 to exit from function. */ -static unsigned short int track(char *pointer, char *res, unsigned short int length_uri, - unsigned short int thread, int client_socket, void *userdata) +static unsigned int track(char *pointer, char *res, unsigned int length_uri, + unsigned int thread, int client_socket, void *userdata) { char question='\0'; char command[256] = {'\0'}; @@ -1906,12 +1902,12 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len return 1 on success */ -static unsigned short int handle_get(int client_socket, const char *url, void *userdata) +static unsigned int handle_get(int client_socket, const char *url, void *userdata) { struct context **cnt = userdata; if (*url == '/') { - unsigned short int i = 0; + int i = 0; char *res=NULL; res = mymalloc(2048); @@ -1919,7 +1915,7 @@ static unsigned short int handle_get(int client_socket, const char *url, void *u while (cnt[++i]); /* ROOT_URI -> GET / */ if (!strcmp(url, "/")) { - unsigned short int y; + int y; if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "Motion "VERSION" Running [%hu] Threads
\n" @@ -1943,7 +1939,7 @@ static unsigned short int handle_get(int client_socket, const char *url, void *u } else { char command[256] = {'\0'}; char slash; - short int thread = -1; + int thread = -1; size_t length_uri = 0; char *pointer = (char *)url; @@ -1951,7 +1947,7 @@ static unsigned short int handle_get(int client_socket, const char *url, void *u /* Check for Thread number first -> GET /2 */ pointer++; length_uri--; - warningkill = sscanf(pointer, "%hd%c", &thread, &slash); + warningkill = sscanf(pointer, "%d%c", &thread, &slash); if ((thread != -1) && (thread < i)) { /* thread_number found */ @@ -2026,7 +2022,7 @@ static unsigned short int handle_get(int client_socket, const char *url, void *u send_template_raw(client_socket, res); } } else if ((slash == '/') && (length_uri > 4)) { - unsigned short int ret = 1; + unsigned int ret = 1; pointer++; length_uri--; ret = action(pointer, res, length_uri, thread, client_socket, cnt); @@ -2169,10 +2165,10 @@ static unsigned short int handle_get(int client_socket, const char *url, void *u return 1 on success */ -static unsigned short int read_client(int client_socket, void *userdata, char *auth) +static unsigned int read_client(int client_socket, void *userdata, char *auth) { - unsigned short int alive = 1; - unsigned short int ret = 1; + unsigned int alive = 1; + unsigned int ret = 1; char buffer[1024] = {'\0'}; ssize_t length = 1023; struct context **cnt = userdata; @@ -2350,7 +2346,7 @@ static int acceptnonblocking(int serverfd, int timeout) void httpd_run(struct context **cnt) { int sd = -1, client_socket_fd, val; - unsigned short int client_sent_quit_message = 1, closehttpd = 0; + unsigned int client_sent_quit_message = 1, closehttpd = 0; struct addrinfo hints, *res, *ressave; struct sigaction act; char *authentication = NULL; @@ -2462,13 +2458,13 @@ void httpd_run(struct context **cnt) if (client_socket_fd < 0) { if ((!cnt[0]) || (cnt[0]->finish)) { - motion_log(-1, 0, "%s: motion-httpd - Finishing", __FUNCTION__); + motion_log(0, 0, "%s: motion-httpd - Finishing", __FUNCTION__); closehttpd = 1; } } else { /* Get the Client request */ client_sent_quit_message = read_client(client_socket_fd, cnt, authentication); - motion_log(-1, 0, "%s: motion-httpd - Read from client", __FUNCTION__); + motion_log(0, 0, "%s: motion-httpd - Read from client", __FUNCTION__); /* Close Connection */ if (client_socket_fd)