From 79cf297cd4669002019ce8a65914def4e1182c72 Mon Sep 17 00:00:00 2001 From: AngelCarpintero Date: Sat, 3 Apr 2010 19:34:23 +0000 Subject: [PATCH] Implemented http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionLog --- CHANGELOG | 2 + CODE_STANDARD | 7 +- alg.c | 14 +- conf.c | 82 ++++--- conf.h | 4 +- configure | 18 +- event.c | 87 +++---- ffmpeg.c | 70 +++--- jpegutils.c | 58 ++--- logger.c | 118 +++++++++- logger.h | 47 +++- motion-dist.conf.in | 6 + motion.1 | 24 +- motion.c | 249 ++++++++++---------- motion.h | 20 +- netcam.c | 536 +++++++++++++++++++++----------------------- netcam_ftp.c | 48 ++-- netcam_jpeg.c | 69 +++--- picture.c | 28 +-- rotate.c | 4 +- stream.c | 75 +++---- track.c | 235 +++++++++---------- video.c | 86 ++++--- video2.c | 185 ++++++++------- video_common.c | 27 +-- video_freebsd.c | 317 +++++++++++++------------- vloopback_motion.c | 49 ++-- webhttpd.c | 114 ++++++---- 28 files changed, 1379 insertions(+), 1200 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 06b330b..427173c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -35,6 +35,8 @@ Features * Add authentication methods 'Basic Authentication' and 'Digest Authentication' to the "Live Stream Server". (Michael Finsterbusch) http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionStreamAuthPatch + * Implemented new logging system + http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionLog (Angel Carpintero) Bugfixes diff --git a/CODE_STANDARD b/CODE_STANDARD index dd1be5a..921094b 100644 --- a/CODE_STANDARD +++ b/CODE_STANDARD @@ -17,7 +17,8 @@ void * mymalloc(size_t nbytes) void *dummy = malloc(nbytes); if (!dummy) { printf("Could not allocate %llu bytes of memory!\n", (unsigned long long) nbytes); - syslog(LOG_EMERG, "Could not allocate %llu bytes of memory!", (unsigned long long) nbytes); + syslog(EMERG, TYPE_ALL, "%s: Could not allocate %llu bytes of memory!", + __FUNCTION__, (unsigned long long) nbytes); exit(1); } @@ -41,8 +42,8 @@ void * mymalloc(size_t nbytes) if (!dummy) { printf("Could not allocate %llu bytes of memory!\n", (unsigned long long) nbytes); - syslog(LOG_EMERG, "Could not allocate %llu bytes of memory!", - (unsigned long long) nbytes); + syslog(EMERG, TYPE_ALL,"Could not allocate %llu bytes of memory!", + __FUNCTION__, (unsigned long long) nbytes); exit(1); } diff --git a/alg.c b/alg.c index 12e675b..8c7b501 100644 --- a/alg.c +++ b/alg.c @@ -535,10 +535,9 @@ static int alg_labeling(struct context *cnt) labelsize = iflood(ix, iy, width, height, out, labels, current_label, 0); if (labelsize > 0) { - if (debug_level >= CAMERA_VERBOSE) - motion_log(LOG_DEBUG, 0,"%s: Label: %i (%i) Size: %i (%i,%i)", - __FUNCTION__, current_label, cnt->current_image->total_labels, - labelsize, ix, iy); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Label: %i (%i) Size: %i (%i,%i)", + __FUNCTION__, current_label, cnt->current_image->total_labels, + labelsize, ix, iy); /* Label above threshold? Mark it again (add 32768 to labelnumber) */ if (labelsize > cnt->threshold) { @@ -559,10 +558,9 @@ static int alg_labeling(struct context *cnt) pixelpos++; /* compensate for ix= CAMERA_VERBOSE) - motion_log(LOG_DEBUG, 0,"%s: %i Labels found. Largest connected Area: %i Pixel(s). " - "Largest Label: %i", __FUNCTION__, imgs->largest_label, imgs->labelsize_max, - cnt->current_image->total_labels); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: %i Labels found. Largest connected Area: %i Pixel(s). " + "Largest Label: %i", __FUNCTION__, imgs->largest_label, imgs->labelsize_max, + cnt->current_image->total_labels); /* return group of significant labels */ return imgs->labelgroup_max; diff --git a/conf.c b/conf.c index 828c308..647312c 100644 --- a/conf.c +++ b/conf.c @@ -153,6 +153,8 @@ struct config conf_template = { minimum_motion_frames: 1, pid_file: NULL, log_file: NULL, + log_level: LEVEL_DEFAULT, + log_type_str: NULL, }; @@ -213,6 +215,22 @@ config_param config_params[] = { print_string }, { + "log_level", + "# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR)", + 1, + CONF_OFFSET(log_level), + copy_int, + print_int + }, + { + "log_type", + "# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)", + 1, + CONF_OFFSET(log_type_str), + copy_string, + print_string + }, + { "videodevice", "\n###########################################################\n" "# Capture device options\n" @@ -1475,7 +1493,7 @@ config_param config_params[] = { { NULL, NULL, 0, 0, NULL, NULL } }; -/* conf_cmdline sets the conf struct options as defined by the command line. +/* 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, int thread) @@ -1487,7 +1505,7 @@ static void conf_cmdline(struct context *cnt, 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?pl:")) != EOF) + while ((c = getopt(conf->argc, conf->argv, "c:d:hns?p:k:l:")) != EOF) switch (c) { case 'c': if (thread == -1) @@ -1501,8 +1519,13 @@ static void conf_cmdline(struct context *cnt, int thread) break; case 'd': /* no validation - just take what user gives */ - debug_level = (unsigned int)atoi(optarg); + if (thread == -1) + debug_level = (unsigned int)atoi(optarg); break; + case 'k': + if (thread == -1) + strcpy(cnt->log_type_str, optarg); + break; case 'p': if (thread == -1) strcpy(cnt->pid_file, optarg); @@ -1565,7 +1588,8 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char } /* We reached the end of config_params without finding a matching option */ - motion_log(LOG_ERR, 0, "%s: Unknown config option \"%s\"", __FUNCTION__, cmd); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"", + __FUNCTION__, cmd); return cnt; } @@ -1656,7 +1680,7 @@ void conf_print(struct context **cnt) FILE *conffile; for (thread = 0; cnt[thread]; thread++) { - motion_log(LOG_INFO, 0, "%s: Writing config file to %s", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s", __FUNCTION__, cnt[thread]->conf_filename); conffile = myfopen(cnt[thread]->conf_filename, "w", 0); @@ -1710,7 +1734,7 @@ void conf_print(struct context **cnt) /************************************************************************** * conf_load is the main function, called from motion.c * The function sets the important context structure "cnt" including - * loading the config parameters from config files and command line. + * loading the config parameters from config files and Command-line. * The following takes place in the function: * - The default start values for cnt stored in the struct conf_template * are copied to cnt[0] which is the default context structure common to @@ -1721,8 +1745,8 @@ void conf_print(struct context **cnt) * - motion.conf is opened and processed. The process populates the cnt[0] and * for each thread config file it populates a cnt[1], cnt[2]... for each * thread - * - Finally it process the options given in the command line. This is done - * for each thread cnt[i] so that the command line options overrides any + * - Finally it process the options given in the Command-line. This is done + * for each thread cnt[i] so that the Command-line options overrides any * option given by motion.conf or a thread config file. **************************************************************************/ struct context **conf_load(struct context **cnt) @@ -1745,7 +1769,7 @@ struct context **conf_load(struct context **cnt) * 2. Copy the conf_template given string to the reserved memory * 3. Change the cnt[0] member (char*) pointing to the string in reserved memory * This ensures that we can free and malloc the string when changed - * via http remote control or config file or command line options + * via http remote control or config file or Command-line options */ malloc_strings(cnt[0]); @@ -1754,33 +1778,33 @@ struct context **conf_load(struct context **cnt) cnt[0]->conf.argc = argc; /* Open the motion.conf file. We try in this sequence: - * 1. commandline + * 1. Command-line * 2. current working directory * 3. $HOME/.motion/motion.conf * 4. sysconfig/motion.conf */ - /* Get filename , pid file & log file from commandline */ + /* Get filename , pid file & log file from Command-line */ + cnt[0]->log_type_str[0] = 0; cnt[0]->conf_filename[0] = 0; cnt[0]->pid_file[0] = 0; cnt[0]->log_file[0] = 0; - conf_cmdline(cnt[0], -1); - if (cnt[0]->conf_filename[0]) { /* User has supplied filename on commandline*/ + if (cnt[0]->conf_filename[0]) { /* User has supplied filename on Command-line*/ strcpy(filename, cnt[0]->conf_filename); fp = fopen (filename, "r"); } - if (!fp) { /* Commandline didn't work, try current dir */ + if (!fp) { /* Command-line didn't work, try current dir */ char *path = NULL; if (cnt[0]->conf_filename[0]) - motion_log(0, 1, "%s: Configfile %s not found - trying defaults.", + motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.", __FUNCTION__, filename); if ((path = get_current_dir_name()) == NULL) { - motion_log(LOG_ERR, 1, "%s: Error get_current_dir_name", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error get_current_dir_name", __FUNCTION__); exit(-1); } @@ -1798,7 +1822,7 @@ struct context **conf_load(struct context **cnt) fp = fopen(filename, "r"); if (!fp) /* there is no config file.... use defaults */ - motion_log(0, 1, "%s: could not open configfile %s", + motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s", __FUNCTION__, filename); } } @@ -1806,12 +1830,12 @@ struct context **conf_load(struct context **cnt) /* Now we process the motion.conf config file and close it */ if (fp) { strcpy(cnt[0]->conf_filename, filename); - motion_log(LOG_INFO, 0, "%s: Processing thread 0 - config file %s", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", __FUNCTION__, filename); cnt = conf_process(cnt, fp); myfclose(fp); } else { - motion_log(LOG_INFO, 0, "%s: Not config file to process using default values", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values", __FUNCTION__); } @@ -1822,7 +1846,7 @@ struct context **conf_load(struct context **cnt) * cnt[0] is the default context structure * cnt[1], cnt[2], ... are context structures for each thread * Command line options always wins over config file options - * so we go through each thread and overrides any set command line + * so we go through each thread and overrides any set Command-line * options */ i = -1; @@ -1830,13 +1854,17 @@ struct context **conf_load(struct context **cnt) while (cnt[++i]) conf_cmdline(cnt[i], i); - /* if pid file was passed from command line copy to main thread conf struct */ + /* if pid file was passed from Command-line copy to main thread conf struct */ 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); + if (cnt[0]->log_type_str[0]) + cnt[0]->conf.log_type_str = mystrcpy(cnt[0]->conf.log_type_str, cnt[0]->log_type_str); + + return cnt; } @@ -2167,7 +2195,7 @@ static struct context **config_thread(struct context **cnt, const char *str, fp = fopen(str, "r"); if (!fp) { - motion_log(LOG_ERR, 1, "%s: Thread config file %s not found", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found", __FUNCTION__, str); return cnt; } @@ -2183,7 +2211,7 @@ static struct context **config_thread(struct context **cnt, const char *str, * First thread is 0 so the number of threads is i+1 * plus an extra for the NULL pointer. This gives i+2 */ - cnt = myrealloc(cnt, sizeof(struct context *)*(i+2), "config_thread"); + cnt = myrealloc(cnt, sizeof(struct context *) * (i + 2), "config_thread"); /* Now malloc space for an additional context structure for thread nr. i */ cnt[i] = mymalloc(sizeof(struct context)); @@ -2201,11 +2229,12 @@ static struct context **config_thread(struct context **cnt, const char *str, malloc_strings(cnt[i]); /* Mark the end if the array of pointers to context structures */ - cnt[i+1] = NULL; + cnt[i + 1] = NULL; /* process the thread's config file and notify user on console */ strcpy(cnt[i]->conf_filename, str); - motion_log(LOG_INFO, 0, "%s: Processing config file %s", __FUNCTION__, str); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s", + __FUNCTION__, str); conf_process(cnt+i, fp); /* Finally we close the thread config file */ @@ -2223,7 +2252,8 @@ static void usage() printf("-n\t\t\tRun in non-daemon mode.\n"); printf("-s\t\t\tRun in setup mode.\n"); printf("-c config\t\tFull path and filename of config file.\n"); - printf("-d level\t\tDebug mode.\n"); + printf("-d level\t\tLog level (1-9) (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). default: 4 / ERR.\n"); + printf("-k type\t\t\tType of log (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). default: ALL.\n"); printf("-p process_id_file\tFull path and filename of process id file (pid file).\n"); printf("-l log file \t\tFull path and filename of log file.\n"); printf("-h\t\t\tShow this screen.\n"); diff --git a/conf.h b/conf.h index a0bbf76..33b776d 100644 --- a/conf.h +++ b/conf.h @@ -19,6 +19,8 @@ * More parameters may be added later. */ struct config { + unsigned int log_level; + char *log_type_str; char *log_file; int setup_mode; int width; @@ -40,7 +42,7 @@ struct config { int frame_limit; int quiet; int useextpipe; /* ext_pipe on or off */ - const char *extpipe; /* full command line for pipe -- must accept YUV420P images */ + const char *extpipe; /* full Command-line for pipe -- must accept YUV420P images */ const char *picture_type; int noise; int noise_tune; diff --git a/configure b/configure index db04bca..39c50e6 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 trunkREV500. +# Generated by GNU Autoconf 2.64 for motion trunkREV501. # # 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='trunkREV500' -PACKAGE_STRING='motion trunkREV500' +PACKAGE_VERSION='trunkREV501' +PACKAGE_STRING='motion trunkREV501' 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 trunkREV500 to adapt to many kinds of systems. +\`configure' configures motion trunkREV501 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 trunkREV500:";; + short | recursive ) echo "Configuration of motion trunkREV501:";; 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 trunkREV500 +motion configure trunkREV501 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 trunkREV500, which was +It was created by motion $as_me trunkREV501, 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 trunkREV500, which was +This file was extended by motion $as_me trunkREV501, 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 trunkREV500 +motion config.status trunkREV501 configured by $0, generated by GNU Autoconf 2.64, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/event.c b/event.c index 0a608f9..b0f3f12 100644 --- a/event.c +++ b/event.c @@ -46,12 +46,14 @@ static void exec_command(struct context *cnt, char *command, char *filename, int execl("/bin/sh", "sh", "-c", stamp, " &", NULL); /* if above function succeeds the program never reach here */ - motion_log(LOG_ERR, 1, "%s: Unable to start external command '%s'", __FUNCTION__, stamp); + motion_log(ALR, TYPE_EVENTS, SHOW_ERRNO, "%s: Unable to start external command '%s'", + __FUNCTION__, stamp); exit(1); - } else if (debug_level >= CAMERA_VERBOSE) { - motion_log(0, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp); - } + } + + motion_log(DBG, TYPE_EVENTS, NO_ERRNO, "%s: Executing external command '%s'", + __FUNCTION__, stamp); } /* @@ -62,8 +64,8 @@ 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(0, 0, "%s: File of type %ld saved to: %s", __FUNCTION__, - (unsigned long)ftype, filename); + motion_log(EMG, TYPE_EVENTS, NO_ERRNO, "%s: File of type %ld saved to: %s", + __FUNCTION__, (unsigned long)ftype, filename); } @@ -126,28 +128,29 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, { char sqlquery[PATH_MAX]; - mystrftime(cnt, sqlquery, sizeof(sqlquery), cnt->conf.sql_query, &cnt->current_image->timestamp_tm, filename, sqltype); + mystrftime(cnt, sqlquery, sizeof(sqlquery), cnt->conf.sql_query, + &cnt->current_image->timestamp_tm, filename, sqltype); #ifdef HAVE_MYSQL if (!strcmp(cnt->conf.database_type, "mysql")) { if (mysql_query(cnt->database, sqlquery) != 0) { int error_code = mysql_errno(cnt->database); - motion_log(LOG_ERR, 1, "%s: Mysql query failed %s error code %d", + motion_log(ERR, TYPE_DB, SHOW_ERRNO, "%s: Mysql query failed %s error code %d", __FUNCTION__, mysql_error(cnt->database), error_code); /* Try to reconnect ONCE if fails continue and discard this sql query */ if (error_code >= 2000) { cnt->database = (MYSQL *) mymalloc(sizeof(MYSQL)); mysql_init(cnt->database); - if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user, - cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) { - motion_log(LOG_ERR, 0, "%s: Cannot reconnect to MySQL database " - "%s on host %s with user %s MySQL error was %s", + if (!mysql_real_connect(cnt->database, cnt->conf.database_host, + cnt->conf.database_user, cnt->conf.database_password, + cnt->conf.database_dbname, 0, NULL, 0)) { + motion_log(ALR, TYPE_DB, NO_ERRNO, "%s: Cannot reconnect to MySQL" + " database %s on host %s with user %s MySQL error was %s", __FUNCTION__, cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user, mysql_error(cnt->database)); - } else { mysql_query(cnt->database, sqlquery); } @@ -163,7 +166,8 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, res = PQexec(cnt->database_pg, sqlquery); if (PQresultStatus(res) != PGRES_COMMAND_OK) { - motion_log(LOG_ERR, 1, "%s: PGSQL query failed", __FUNCTION__); + motion_log(ERR, TYPE_DB, SHOW_ERRNO, "%s: PGSQL query failed", + __FUNCTION__); PQclear(res); } } @@ -175,7 +179,8 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, char *errmsg = 0; res = sqlite3_exec(cnt->database_sqlite3, sqlquery, NULL, 0, &errmsg); if (res != SQLITE_OK ) { - motion_log(LOG_ERR, 0, "%s: SQLite error was %s", __FUNCTION__, errmsg); + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: SQLite error was %s", + __FUNCTION__, errmsg); sqlite3_free(errmsg); } } @@ -236,7 +241,8 @@ static void event_vid_putpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, { if (*(int *)devpipe >= 0) { if (vid_putpipe(*(int *)devpipe, img, cnt->imgs.size) == -1) - motion_log(LOG_ERR, 1, "%s: Failed to put image into video pipe", __FUNCTION__); + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Failed to put image into video pipe", + __FUNCTION__); } } #endif /* !WITHOUT_V4L && !BSD */ @@ -338,7 +344,7 @@ static void event_image_snapshot(struct context *cnt, int type ATTRIBUTE_UNUSED, remove(linkpath); if (symlink(filename, linkpath)) { - motion_log(LOG_ERR, 1, "%s: Could not create symbolic link [%s]", + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Could not create symbolic link [%s]", __FUNCTION__, filename); return; } @@ -376,9 +382,10 @@ static void event_extpipe_end(struct context *cnt, int type ATTRIBUTE_UNUSED, if (cnt->extpipe_open) { cnt->extpipe_open = 0; fflush(cnt->extpipe); - motion_log(LOG_INFO, 0, "%s: CLOSING: extpipe file desc %d, error state %d", + motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: CLOSING: extpipe file desc %d, error state %d", __FUNCTION__, fileno(cnt->extpipe), ferror(cnt->extpipe)); - motion_log(LOG_INFO, 0, "%s: pclose return: %d", __FUNCTION__, pclose(cnt->extpipe)); + motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", + __FUNCTION__, pclose(cnt->extpipe)); event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); } } @@ -400,8 +407,8 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, moviepath = cnt->conf.moviepath; } else { moviepath = DEF_MOVIEPATH; - if (debug_level >= CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: moviepath: %s", __FUNCTION__, moviepath); + motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: moviepath: %s", + __FUNCTION__, moviepath); } mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tm, NULL, 0); @@ -414,11 +421,13 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, if (fd_dummy == NULL) { /* Permission denied */ if (errno == EACCES) { - motion_log(LOG_ERR, 1, "%s: error opening file %s ... check access " - "rights to target directory", __FUNCTION__, cnt->extpipefilename); + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s ..." + "check access rights to target directory", + __FUNCTION__, cnt->extpipefilename); return ; } else { - motion_log(LOG_ERR, 1, "%s: error opening file %s", __FUNCTION__, cnt->extpipefilename); + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s", + __FUNCTION__, cnt->extpipefilename); return ; } @@ -429,16 +438,16 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.extpipe, currenttime_tm, cnt->extpipefilename, 0); - if (debug_level >= CAMERA_INFO) { - motion_log(LOG_INFO, 0, "%s: pipe: %s", __FUNCTION__, stamp); - motion_log(LOG_INFO, 0, "%s: cnt->moviefps: %d", __FUNCTION__, cnt->movie_fps); - } + motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pipe: %s", + __FUNCTION__, stamp); + motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: cnt->moviefps: %d", + __FUNCTION__, cnt->movie_fps); event(cnt, EVENT_FILECREATE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); cnt->extpipe = popen(stamp, "w"); if (cnt->extpipe == NULL) { - motion_log(LOG_ERR, 1, "%s: popen failed", __FUNCTION__); + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: popen failed", __FUNCTION__); return; } @@ -453,15 +462,15 @@ static void event_extpipe_put(struct context *cnt, int type ATTRIBUTE_UNUSED, { /* Check use_extpipe enabled and ext_pipe not NULL */ if ((cnt->conf.useextpipe) && (cnt->extpipe != NULL)) { - if (debug_level >= CAMERA_DEBUG) - motion_log(LOG_INFO, 0, "%s:", __FUNCTION__); + motion_log(DBG, TYPE_EVENTS, NO_ERRNO, "%s:", __FUNCTION__); + /* Check that is open */ if ((cnt->extpipe_open) && (fileno(cnt->extpipe) > 0)) { if (!fwrite(img, cnt->imgs.size, 1, cnt->extpipe)) - motion_log(LOG_ERR, 1, "%s: Error writting in pipe , state error %d", + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Error writting in pipe , state error %d", __FUNCTION__, ferror(cnt->extpipe)); } else { - motion_log(LOG_ERR, 0, "%s: pipe %s not created or closed already ", + motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pipe %s not created or closed already ", __FUNCTION__, cnt->extpipe); } } @@ -476,8 +485,8 @@ static void event_new_video(struct context *cnt, int type ATTRIBUTE_UNUSED, cnt->movie_fps = cnt->lastrate; - if (debug_level >= CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s FPS %d", __FUNCTION__, cnt->movie_fps); + motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s FPS %d", + __FUNCTION__, cnt->movie_fps); if (cnt->movie_fps > 30) cnt->movie_fps = 30; @@ -543,7 +552,7 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->newfilename, y, u, v, cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(LOG_ERR, 1, "%s: ffopen_open error creating (new) file [%s]", + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]", __FUNCTION__, cnt->newfilename); cnt->finish = 1; return; @@ -571,7 +580,7 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->motionfilename, y, u, v, cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(LOG_ERR, 1, "%s: ffopen_open error creating (motion) file [%s]", + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]", __FUNCTION__, cnt->motionfilename); cnt->finish = 1; return; @@ -626,8 +635,8 @@ static void event_ffmpeg_timelapse(struct context *cnt, ffmpeg_open((char *)TIMELAPSE_CODEC, cnt->timelapsefilename, y, u, v, cnt->imgs.width, cnt->imgs.height, 24, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(LOG_ERR, 1, "%s: ffopen_open error creating (timelapse) file [%s]", - __FUNCTION__, cnt->timelapsefilename); + motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating " + "(timelapse) file [%s]", __FUNCTION__, cnt->timelapsefilename); cnt->finish = 1; return; } diff --git a/ffmpeg.c b/ffmpeg.c index 49cd946..8ddfab4 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -252,8 +252,8 @@ static int mpeg1_write_trailer(AVFormatContext *s) */ void ffmpeg_init() { - motion_log(LOG_INFO, 0, "%s: ffmpeg LIBAVCODEC_BUILD %d LIBAVFORMAT_BUILD %d", - __FUNCTION__, LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg LIBAVCODEC_BUILD %d" + " LIBAVFORMAT_BUILD %d", __FUNCTION__, LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD); av_register_all(); #if LIBAVCODEC_BUILD > 4680 @@ -315,8 +315,8 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) #ifdef FFMPEG_NO_NONSTD_MPEG1 } else if (strcmp(codec, "mpeg1") == 0) { - motion_log(LOG_ERR, 0, "%s: *** mpeg1 support for normal videos has been disabled ***", - __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: *** mpeg1 support for normal" + " videos has been disabled ***", __FUNCTION__); return NULL; #endif } else if (strcmp(codec, "mpeg4") == 0) { @@ -351,13 +351,14 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) ext = ".mov"; of = guess_format("mov", NULL, NULL); } else { - motion_log(LOG_ERR, 0, "%s: ffmpeg_video_codec option value %s is not supported", - __FUNCTION__, codec); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg_video_codec option value" + " %s is not supported", __FUNCTION__, codec); return NULL; } if (!of) { - motion_log(LOG_ERR, 0, "%s: Could not guess format for %s", __FUNCTION__, codec); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not guess format for %s", + __FUNCTION__, codec); return NULL; } @@ -403,7 +404,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* allocation the output media context */ ffmpeg->oc = av_mallocz(sizeof(AVFormatContext)); if (!ffmpeg->oc) { - motion_log(LOG_ERR, 1, "%s: Memory error while allocating output media context", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Memory error while allocating" + " output media context", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -423,13 +425,15 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->video_st = av_new_stream(ffmpeg->oc, 0); if (!ffmpeg->video_st) { - motion_log(LOG_ERR, 1, "%s: av_new_stream - could not alloc stream", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: av_new_stream - could" + " not alloc stream", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return NULL; } } else { /* We did not get a proper video codec. */ - motion_log(LOG_ERR, 0, "%s: Failed to obtain a proper video codec", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Failed to obtain a proper" + " video codec", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -458,8 +462,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, c->frame_rate_base = 1; #endif /* LIBAVCODEC_BUILD >= 4754 */ - if (debug_level >= CAMERA_DEBUG) - motion_log(LOG_DEBUG, 0, "%s FPS %d", __FUNCTION__, rate); + motion_log(DBG, TYPE_ENCODER, NO_ERRNO, "%s FPS %d", + __FUNCTION__, rate); if (vbr) c->flags |= CODEC_FLAG_QSCALE; @@ -479,8 +483,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* set the output parameters (must be done even if no parameters). */ if (av_set_parameters(ffmpeg->oc, NULL) < 0) { - motion_log(LOG_ERR, 0, "%s: av_set_parameters error: Invalid output format parameters", - __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: av_set_parameters error:" + " Invalid output format parameters", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -495,7 +499,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, codec = avcodec_find_encoder(c->codec_id); if (!codec) { - motion_log(LOG_ERR, 0, "%s: Codec %s not found", __FUNCTION__, ffmpeg_video_codec); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", + __FUNCTION__, ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -510,8 +515,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, if (avcodec_open(c, codec) < 0) { /* Release the lock. */ pthread_mutex_unlock(&global_lock); - motion_log(LOG_ERR, 0, "%s: avcodec_open - could not open codec %s", __FUNCTION__, - ffmpeg_video_codec); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_open - could not open codec %s", + __FUNCTION__, ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -535,7 +540,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->picture = avcodec_alloc_frame(); if (!ffmpeg->picture) { - motion_log(LOG_ERR, 0, "%s: avcodec_alloc_frame - could not alloc frame", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_alloc_frame -" + " could not alloc frame", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -577,21 +583,22 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* and retry opening the file (use file_proto) */ if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { - motion_log(LOG_ERR, 1, "%s: url_fopen - error opening file %s", - __FUNCTION__, filename); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen -" + " error opening file %s", __FUNCTION__, filename); ffmpeg_cleanups(ffmpeg); return NULL; } /* Permission denied */ } else if (errno == EACCES) { - motion_log(LOG_ERR, 1, + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen - error opening file %s" " ... check access rights to target directory", __FUNCTION__, filename); ffmpeg_cleanups(ffmpeg); return NULL; } else { - motion_log(LOG_ERR, 1, "%s: Error opening file %s", __FUNCTION__, filename); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", + __FUNCTION__, filename); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -790,7 +797,8 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) } if (ret != 0) { - motion_log(LOG_ERR, 1, "%s: Error while writing video frame", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error while writing" + " video frame", __FUNCTION__); ffmpeg_cleanups(ffmpeg); return -1; } @@ -816,7 +824,8 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y, picture = avcodec_alloc_frame(); if (!picture) { - motion_log(LOG_ERR, 1, "%s: Could not alloc frame", __FUNCTION__); + motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not alloc frame", + __FUNCTION__); return NULL; } @@ -888,15 +897,12 @@ void ffmpeg_avcodec_log(void *ignoreme ATTRIBUTE_UNUSED, int errno_flag, const c { char buf[1024]; - /* Do not log the message coming from avcodec if the debug_level is not set. */ - if (debug_level) { - - /* Flatten the message coming in from avcodec */ - vsnprintf(buf, sizeof(buf), fmt, vl); + /* Flatten the message coming in from avcodec */ + vsnprintf(buf, sizeof(buf), fmt, vl); - /* If the debug_level is correct then send the message to the motion logging routine. */ - motion_log(LOG_ERR, 0, "%s: %s - flag %d", __FUNCTION__, buf, errno_flag); - } + /* If the debug_level is correct then send the message to the motion logging routine. */ + motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: %s - flag %d", + __FUNCTION__, buf, errno_flag); } #endif /* HAVE_FFMPEG */ diff --git a/jpegutils.c b/jpegutils.c index 4f891b9..0b350b7 100644 --- a/jpegutils.c +++ b/jpegutils.c @@ -201,8 +201,9 @@ static void init_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) static boolean empty_output_buffer(j_compress_ptr cinfo) { /*FIXME: */ - motion_log(LOG_ERR, 0, "%s: Given jpeg buffer was too small", __FUNCTION__); - ERREXIT (cinfo, JERR_BUFFER_SIZE); /* shouldn't be FILE_WRITE but BUFFER_OVERRUN! */ + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small", + __FUNCTION__); + ERREXIT (cinfo, JERR_BUFFER_SIZE); /* shouldn't be FILE_WRITE but BUFFER_OVERRUN! */ return TRUE; } @@ -335,7 +336,7 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, nsymbols += bits[len]; if (nsymbols < 1 || nsymbols > 256) - motion_log(LOG_ERR, 0, "%s: Given jpeg buffer was too small", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small", __FUNCTION__); memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8)); @@ -507,8 +508,8 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, jpeg_start_decompress (&dinfo); if (dinfo.output_components != 3) { - motion_log(LOG_ERR, 0, "%s: Output components of JPEG image = %d, must be 3", - __FUNCTION__, dinfo.output_components); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Output components of JPEG image" + " = %d, must be 3", __FUNCTION__, dinfo.output_components); goto ERR_EXIT; } @@ -519,15 +520,16 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, if ((hsf[0] != 2 && hsf[0] != 1) || hsf[1] != 1 || hsf[2] != 1 || (vsf[0] != 1 && vsf[0] != 2) || vsf[1] != 1 || vsf[2] != 1) { - motion_log(LOG_ERR, 0, "%s: Unsupported sampling factors, hsf=(%d, %d, %d) " - "vsf=(%d, %d, %d) !", __FUNCTION__, hsf[0], hsf[1], hsf[2], vsf[0], vsf[1], vsf[2]); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported sampling factors," + " hsf=(%d, %d, %d) vsf=(%d, %d, %d) !", __FUNCTION__, hsf[0], hsf[1], + hsf[2], vsf[0], vsf[1], vsf[2]); goto ERR_EXIT; } if (hsf[0] == 1) { if (height % 8 != 0) { - motion_log(LOG_ERR, 0, "%s: YUV 4:4:4 sampling, but image height %d " - "not dividable by 8 !", __FUNCTION__, height); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: YUV 4:4:4 sampling, but image" + " height %d not dividable by 8 !", __FUNCTION__, height); goto ERR_EXIT; } @@ -546,7 +548,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, } else if (2 * dinfo.output_height == height) { numfields = 2; } else { - motion_log(LOG_ERR, 0, "%s: Read JPEG: requested height = %d, " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " "height of image = %d", __FUNCTION__, height, dinfo.output_height); goto ERR_EXIT; } @@ -554,7 +556,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* Width is more flexible */ if (dinfo.output_width > MAX_LUMA_WIDTH) { - motion_log(LOG_ERR, 0, "%s: Image width of %d exceeds max", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", __FUNCTION__, dinfo.output_width); goto ERR_EXIT; } @@ -604,8 +606,8 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, yl = yc = (1 - field); break; default: - motion_log(LOG_ERR, 0, "%s: Input is interlaced but no interlacing set", - __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced but" + " no interlacing set", __FUNCTION__); goto ERR_EXIT; } } else { @@ -810,8 +812,8 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, dinfo.dct_method = JDCT_IFAST; if (dinfo.jpeg_color_space != JCS_GRAYSCALE) { - motion_log(LOG_ERR, 0, "%s: Expected grayscale colorspace for JPEG raw decoding", - __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Expected grayscale colorspace" + " for JPEG raw decoding", __FUNCTION__); goto ERR_EXIT; } @@ -828,7 +830,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, } else if (2 * dinfo.output_height == height) { numfields = 2; } else { - motion_log(LOG_ERR, 0, "%s: Read JPEG: requested height = %d, " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " "height of image = %d", __FUNCTION__, height, dinfo.output_height); goto ERR_EXIT; } @@ -836,7 +838,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, /* Width is more flexible */ if (dinfo.output_width > MAX_LUMA_WIDTH) { - motion_log(LOG_ERR, 0, "%s: Image width of %d exceeds max", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", __FUNCTION__, dinfo.output_width); goto ERR_EXIT; } @@ -886,8 +888,8 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, yl = yc = (1 - field); break; default: - motion_log(LOG_ERR, 0, "%s: Input is interlaced but no interlacing set", - __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" + " but no interlacing set", __FUNCTION__); goto ERR_EXIT; } } else { @@ -976,7 +978,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, } break; /* - * should be case Y4M_CHROMA_420JPEG: but use default: for compatibility. Some + * Should be case Y4M_CHROMA_420JPEG: but use default: for compatibility. Some * pass things like '420' in with the expectation that anything other than * Y4M_CHROMA_422 will default to 420JPEG. */ @@ -1098,14 +1100,14 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, if ((width > 4096) || (height > 4096)) { - motion_log(LOG_ERR, 0, "%s: Image dimensions (%dx%d) exceed lavtools' max " - "(4096x4096)", __FUNCTION__, width, height); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) exceed" + " lavtools' max (4096x4096)", __FUNCTION__, width, height); goto ERR_EXIT; } if ((width % 16) || (height % 16)) { - motion_log(LOG_ERR, 0, "%s: Image dimensions (%dx%d) not multiples of 16", - __FUNCTION__, width, height); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) not" + " multiples of 16", __FUNCTION__, width, height); goto ERR_EXIT; } @@ -1119,8 +1121,8 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, default: numfields = 1; if (height > 2048) { - motion_log(LOG_ERR, 0, "%s: Image height (%d) exceeds lavtools max " - "for non-interlaced frames", __FUNCTION__, height); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image height (%d) exceeds" + " lavtools max for non-interlaced frames", __FUNCTION__, height); goto ERR_EXIT; } } @@ -1146,8 +1148,8 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, yl = yc = (1 - field); break; default: - motion_log(LOG_ERR, 0, "%s: Input is interlaced but no interlacing set", - __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" + " but no interlacing set", __FUNCTION__); goto ERR_EXIT; } diff --git a/logger.c b/logger.c index 7263bca..e2d927d 100644 --- a/logger.c +++ b/logger.c @@ -15,11 +15,84 @@ static int log_mode = LOGMODE_SYSLOG; static FILE *logfile; +static unsigned int log_level = LEVEL_DEFAULT; +static unsigned int log_type = TYPE_DEFAULT; + +static const char *log_type_str[] = {NULL, "STR", "ENC", "NET", "DBL", "EVT", "TRK", "VID", "ALL" }; +static const char *log_level_str[] = {NULL, "EMG", "ALR", "CRT", "ERR", "WRN", "NTC", "INF", "DBG", "ALL" }; + + +/** + * get_log_type + * + * + * Returns: index of log type or 0 if not valid type. + */ +int get_log_type(const char *type) +{ + unsigned int i, ret = 0; + unsigned int maxtype = sizeof(log_type_str)/sizeof(const char *); + + for (i = 1;i < maxtype; i++) { + /* printf("Debug %s\n", log_type_str[i]); */ + if (!strncasecmp(type, log_type_str[i], 3)) { + ret = i; + break; + } + } + + return ret; +} + +/** + * get_log_type_str + * Gets string value for type log level. + * + * Returns: name of type log level. + */ +const char* get_log_type_str(unsigned int type) +{ + return log_type_str[type]; +} + +/** + * set_log_type + * Sets log type level. + * + * Returns: nothing. + */ +void set_log_type(unsigned int type) +{ + log_type = type; +} + +/** + * get_log_level_str + * Gets string value for log level. + * + * Returns: name of log level. + */ +const char* get_log_level_str(unsigned int level) +{ + return log_level_str[SHOW_LEVEL_VALUE(level)]; +} + +/** + * set_log_level + * Sets log level. + * + * Returns nothing. + */ +void set_log_level(unsigned int level) +{ + log_level = level; +} /** * set_log_mode + * Sets mode of logging , could be using syslog or files. * - * Set mode of logging , could be using syslog or files. + * Returns: nothing. */ void set_log_mode(int mode) { @@ -28,8 +101,9 @@ void set_log_mode(int mode) /** * set_logfile + * Sets logfile to be used instead of syslog. * - * Set logfile to be used instead of syslog. + * Returns: pointer to log file. */ FILE * set_logfile(const char *logfile_name) { @@ -43,11 +117,10 @@ FILE * set_logfile(const char *logfile_name) return logfile; } - /** * str_time * - * Return string with human readable time + * Return: string with human readable time */ static char *str_time(void) { @@ -71,7 +144,9 @@ static char *str_time(void) * Parameters: * * level logging level for the 'syslog' function - * (-1 implies no syslog message should be produced) + * + * type logging type. + * * errno_flag if set, the log message should be followed by the * error message. * fmt the format string for producing the message @@ -80,7 +155,7 @@ static char *str_time(void) * Returns: * Nothing */ -void motion_log(int level, int errno_flag, const char *fmt, ...) +void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, ...) { int errno_save, n; char buf[1024]; @@ -91,6 +166,18 @@ void motion_log(int level, int errno_flag, const char *fmt, ...) va_list ap; int threadnr; + /* Exit if level is greater than log_level */ + if ((unsigned int)level > log_level) + return; + + //printf("Level %d <= Log_level %d ", level, log_level); + + /* Exit if type is greater than log_type */ + if (type > log_type) + return; + + //printf("Type %d <= Log_type %d\n---------\n", type, log_type); + /* * If pthread_getspecific fails (e.g., because the thread's TLS doesn't * contain anything for thread number, it returns NULL which casts to zero, @@ -104,12 +191,23 @@ void motion_log(int level, int errno_flag, const char *fmt, ...) */ errno_save = errno; - /* Prefix the message with the time and thread number */ + /* + * Prefix the message with the log level string, log type string, + * time and thread number. i.ex [ERR] [ENC] [Apr 03 00:08:44] [1] blah + * + */ if (!log_mode) { - n = snprintf(buf, sizeof(buf), "[%s] [%d] ", str_time(), threadnr); + n = snprintf(buf, sizeof(buf), "[%s] [%s] [%d] [%s]", + get_log_level_str(level), get_log_type_str(type), + threadnr, str_time()); } else { - /* Prefix the message with the thread number */ - n = snprintf(buf, sizeof(buf), "[%d] ", threadnr); + /* + * Prefix the message with the log level string, log type string + * and thread number. i.ex [DBG] [TRK] [1] blah + */ + n = snprintf(buf, sizeof(buf), "[%s] [%s] [%d]", + get_log_level_str(level), get_log_type_str(type), + threadnr); } /* Next add the user's message */ diff --git a/logger.h b/logger.h index c68c670..a672b2d 100644 --- a/logger.h +++ b/logger.h @@ -19,19 +19,44 @@ #define LOGMODE_FILE 0 /* Log messages to file */ #define LOGMODE_SYSLOG 1 /* Log messages to syslog */ -/* Debug levels */ -#define CAMERA_ALERT 1 /* alerts only */ -#define CAMERA_CRITICAL 2 /* critical only */ -#define CAMERA_WARNINGS 3 /* warnings only */ -#define TRACK_DEBUG 4 /* track debug */ -#define CAMERA_INFO 5 /* info debug */ -#define CAMERA_VIDEO 6 /* debug video not verbose */ -#define CAMERA_DEBUG 7 /* debug but not verbose */ -#define CAMERA_VERBOSE 8 /* verbose level */ -#define CAMERA_ALL 9 /* everything */ +#define NO_ERRNO 0 /* Flag to avoid how message associated to errno */ +#define SHOW_ERRNO 1 /* Flag to show message associated to errno */ +/* Log levels */ +#define LOG_CONSOLE -1 +#define LOG_ALL 8 +#define CONSOLE LOG_CONSOLE /* -1 */ +#define EMG LOG_EMERG /* syslog 0 motion 1 */ +#define ALR LOG_ALERT /* syslog 1 motion 2 */ +#define CRT LOG_CRIT /* syslog 2 motion 3 */ +#define ERR LOG_ERR /* syslog 3 motion 4 */ +#define WRN LOG_WARNING /* syslog 4 motion 5 */ +#define NTC LOG_NOTICE /* syslog 5 motion 6 */ +#define INF LOG_INFO /* syslog 6 motion 7 */ +#define DBG LOG_DEBUG /* syslog 7 motion 8 */ +#define ALL LOG_ALL /* syslog 8 motion 9 */ +#define LEVEL_DEFAULT ERR /* syslog 3 motion 4 default */ +#define SHOW_LEVEL_VALUE(x) (x+1) + +/* Log types */ +#define TYPE_STREAM 1 /* Stream logs */ +#define TYPE_ENCODER 2 /* Encoder logs */ +#define TYPE_NETCAM 3 /* Netcam logs */ +#define TYPE_DB 4 /* Database logs */ +#define TYPE_EVENTS 5 /* Events logs */ +#define TYPE_TRACK 6 /* Track logs */ +#define TYPE_VIDEO 7 /* V4L1/2 Bktr logs */ +#define TYPE_ALL 8 /* All type logs */ +#define TYPE_DEFAULT TYPE_ALL /* Default type */ +#define TYPE_DEFAULT_STR "ALL" /* Default name logs */ + +int get_log_type(const char* type); +const char* get_log_type_str(unsigned int type); +void set_log_type(unsigned int type); +const char* get_log_level_str(unsigned int level); +void set_log_level(unsigned int level); void set_log_mode(int mode); FILE * set_logfile(const char *logfile_name); -void motion_log(int, int, const char *, ...); +void motion_log(int, unsigned int, int, const char *, ...); #endif diff --git a/motion-dist.conf.in b/motion-dist.conf.in index 1a6d035..bcddaf8 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -24,6 +24,12 @@ setup_mode off # Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined) ;logfile +# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR) +log_level 4 + +# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL) +log_type all + ########################################################### # Capture device options ############################################################ diff --git a/motion.1 b/motion.1 index 906a5d6..75baa57 100644 --- a/motion.1 +++ b/motion.1 @@ -3,7 +3,7 @@ motion \- Detect motion using a video4linux device .SH SYNOPSIS .B motion -[ -hns ] [ -c config file path ] [ -d level ] [ -p process_id_file ] [ -l logfile ] +[ -hns ] [ -c config file path ] [ -d log level ] [ -k log type ] [ -p process_id_file ] [ -l logfile ] .SH DESCRIPTION .I Motion uses a video4linux device to detect motion. If motion is detected both normal @@ -23,8 +23,11 @@ Run in non-daemon mode. .B \-s Run in setup mode. Also forces non-daemon mode .TP -.B \-d level -Run in debug mode, level 1-9. +.B \-d log level +Set log level [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR) +.TP +.B \-k log type +Set type of log (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL) .TP .B \-p Full path and filename for process id file (pid file). E.g /var/run/motion.pid. Default is not defined. Pid file is only created when Motion is started in daemon mode. @@ -202,6 +205,21 @@ Values: Max 4095 characters / Default: Not defined .br Use a file to save logs messages, if not defined stderr and syslog is used. .TP +.B logfile string +Values: Max 4095 characters / Default: Not defined +.br +Use a file to save logs messages, if not defined stderr and syslog is used. +.TP +.B log_level integer +Values: 1 - 9 / Default: 4 +.br +Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR). +.TP +.B log_type discrete strings +Values: STR, ENC, NET, DBL, EVT, TRK, VID, ALL / Default: ALL +.br +Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). +.TP .B mask_file string Values: Max 4095 characters / Default: Not defined .br diff --git a/motion.c b/motion.c index c881c0d..822d83c 100644 --- a/motion.c +++ b/motion.c @@ -63,6 +63,7 @@ volatile int threads_running = 0; * types of messages get output. */ unsigned int debug_level; +unsigned int debug_type; /* Set this when we want main to end or restart */ volatile unsigned int finish = 0; @@ -110,7 +111,7 @@ static void image_ring_resize(struct context *cnt, int new_size) smallest = cnt->imgs.image_ring_size; if (cnt->imgs.image_ring_in == smallest - 1 || smallest == 0) { - motion_log(LOG_INFO, 0, "%s: Resizing pre_capture buffer to %d items", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Resizing pre_capture buffer to %d items", __FUNCTION__, new_size); /* Create memory for new ring buffer */ @@ -387,13 +388,13 @@ static void motion_remove_pid(void) { if ((cnt_list[0]->daemon) && (cnt_list[0]->conf.pid_file) && (restart == 0)) { if (!unlink(cnt_list[0]->conf.pid_file)) - motion_log(LOG_INFO, 0, "%s: Removed process id file (pid file).", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Removed process id file (pid file).", __FUNCTION__); else - motion_log(LOG_INFO, 1, "%s: Error removing pid file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error removing pid file", __FUNCTION__); } if (ptr_logfile) { - motion_log(LOG_INFO, 0, "%s: Closing logfile (%s).", __FUNCTION__, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Closing logfile (%s).", __FUNCTION__, cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_SYSLOG); myfclose(ptr_logfile); @@ -470,9 +471,8 @@ static void motion_detected(struct context *cnt, int dev, struct image_data *img /* EVENT_FIRSTMOTION triggers on_event_start_command and event_ffmpeg_newfile */ event(cnt, EVENT_FIRSTMOTION, img->image, NULL, NULL, &img->timestamp_tm); - if (debug_level >= CAMERA_INFO) - motion_log(0, 0, "%s: Motion detected - starting event %d", - __FUNCTION__, cnt->event_nr); + motion_log(WRN, TYPE_ALL, NO_ERRNO, "%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 */ if (cnt->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) @@ -540,7 +540,7 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) cnt->current_image = &cnt->imgs.image_ring[cnt->imgs.image_ring_out]; if (cnt->imgs.image_ring[cnt->imgs.image_ring_out].shot < cnt->conf.frame_limit) { - if (debug_level >= CAMERA_DEBUG) { + if (debug_level >= DBG) { char tmp[32]; const char *t; @@ -583,11 +583,11 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) * we don't know how many frames there is in first sec */ if (cnt->movie_last_shot >= 0) { - if (debug_level >= CAMERA_DEBUG) { + if (debug_level >= DBG) { int frames = cnt->movie_fps - (cnt->movie_last_shot + 1); if (frames > 0) { char tmp[15]; - motion_log(LOG_DEBUG, 0, "%s: Added %d fillerframes into movie", + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Added %d fillerframes into movie", __FUNCTION__, frames); sprintf(tmp, "Fillerframes %d", frames); draw_text(cnt->imgs.image_ring[cnt->imgs.image_ring_out].image, 10, 40, @@ -695,7 +695,7 @@ static int motion_init(struct context *cnt) cnt->detecting_motion = 0; cnt->makemovie = 0; - motion_log(LOG_DEBUG, 0, "%s: Thread %d started", + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d started", __FUNCTION__, (unsigned long)pthread_getspecific(tls_key_threadnr)); if (!cnt->conf.filepath) @@ -710,7 +710,7 @@ static int motion_init(struct context *cnt) * file options. */ if (cnt->video_dev == -1) { - motion_log(LOG_ERR, 0, "%s: Could not fetch initial image from camera " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " "Motion continues using width and height from config file(s)", __FUNCTION__); cnt->imgs.width = cnt->conf.width; @@ -719,7 +719,7 @@ static int motion_init(struct context *cnt) cnt->imgs.motionsize = cnt->conf.width * cnt->conf.height; cnt->imgs.type = VIDEO_PALETTE_YUV420P; } else if (cnt->video_dev == -2) { - motion_log(LOG_ERR, 0, "%s: Could not fetch initial image from camera " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " "Motion only supports width and height modulo 16", __FUNCTION__); return -3; @@ -780,7 +780,7 @@ static int motion_init(struct context *cnt) memset(cnt->imgs.image_virgin, 0x80, cnt->imgs.size); /* initialize to grey */ draw_text(cnt->imgs.image_virgin, 10, 20, cnt->imgs.width, "Error capturing first image", cnt->conf.text_double); - motion_log(LOG_ERR, 0, "%s: Error capturing first image", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Error capturing first image", __FUNCTION__); } } @@ -790,31 +790,29 @@ static int motion_init(struct context *cnt) #if !defined(WITHOUT_V4L) && !defined(BSD) /* open video loopback devices if enabled */ if (cnt->conf.vidpipe) { - if (debug_level >= CAMERA_DEBUG) - 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__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for normal pictures", + __FUNCTION__); /* vid_startpipe should get the output dimensions */ cnt->pipe = vid_startpipe(cnt->conf.vidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); if (cnt->pipe < 0) { - motion_log(LOG_ERR, 0, "%s: Failed to open video loopback for normal pictures", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for normal pictures", + __FUNCTION__); return -1; } } if (cnt->conf.motionvidpipe) { - if (debug_level >= CAMERA_DEBUG) - 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__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for motion pictures", + __FUNCTION__); /* vid_startpipe should get the output dimensions */ cnt->mpipe = vid_startpipe(cnt->conf.motionvidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); if (cnt->mpipe < 0) { - motion_log(LOG_ERR, 0, "%s: Failed to open video loopback for motion pictures", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for motion pictures", + __FUNCTION__); return -1; } } @@ -822,16 +820,16 @@ static int motion_init(struct context *cnt) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) if (cnt->conf.database_type) { - motion_log(LOG_INFO, 0, "%s: Database backend %s", __FUNCTION__, + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Database backend %s", __FUNCTION__, cnt->conf.database_type); #ifdef HAVE_SQLITE3 if ((!strcmp(cnt->conf.database_type, "sqlite3")) && cnt->conf.sqlite3_db) { - motion_log(LOG_INFO, 0, "%s: DB %s", __FUNCTION__, + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: DB %s", __FUNCTION__, cnt->conf.sqlite3_db); if (sqlite3_open(cnt->conf.sqlite3_db, &cnt->database_sqlite3) != SQLITE_OK) { - motion_log(LOG_ERR, 0, "%s: Can't open database %s : %s\n", __FUNCTION__, + motion_log(EMG, TYPE_DB, NO_ERRNO, "%s: Can't open database %s : %s\n", __FUNCTION__, cnt->conf.sqlite3_db, sqlite3_errmsg(cnt->database_sqlite3)); sqlite3_close(cnt->database_sqlite3); exit(1); @@ -846,10 +844,10 @@ static int motion_init(struct context *cnt) if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user, cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) { - motion_log(LOG_ERR, 0, "%s: Cannot connect to MySQL database %s on host %s with user %s", + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Cannot connect to MySQL database %s on host %s with user %s", __FUNCTION__, cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user); - motion_log(LOG_ERR, 0, "%s: MySQL error was %s", __FUNCTION__, mysql_error(cnt->database)); + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: MySQL error was %s", __FUNCTION__, mysql_error(cnt->database)); return -2; } #if (defined(MYSQL_VERSION_ID)) && (MYSQL_VERSION_ID > 50012) @@ -878,7 +876,7 @@ static int motion_init(struct context *cnt) cnt->database_pg = PQconnectdb(connstring); if (PQstatus(cnt->database_pg) == CONNECTION_BAD) { - motion_log(LOG_ERR, 0, "%s: Connection to PostgreSQL database '%s' failed: %s", + motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Connection to PostgreSQL database '%s' failed: %s", __FUNCTION__, cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); return -2; } @@ -907,7 +905,7 @@ static int motion_init(struct context *cnt) cnt->imgs.mask = get_pgm(picture, cnt->imgs.width, cnt->imgs.height); myfclose(picture); } else { - motion_log(LOG_ERR, 1, "%s: Error opening mask file %s", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening mask file %s", __FUNCTION__, cnt->conf.mask_file); /* * Try to write an empty mask file to make it easier @@ -917,15 +915,11 @@ static int motion_init(struct context *cnt) } if (!cnt->imgs.mask) { - motion_log(LOG_ERR, 0, "%s: Failed to read mask image. Mask feature disabled.", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to read mask image. Mask feature disabled.", __FUNCTION__); } else { - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: Maskfile \"%s\" loaded.", - __FUNCTION__, cnt->conf.mask_file); - else - motion_log(LOG_INFO, 0, "%s: Maskfile \"%s\" loaded.", - __FUNCTION__, cnt->conf.mask_file); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Maskfile \"%s\" loaded.", + __FUNCTION__, cnt->conf.mask_file); } } else { cnt->imgs.mask = NULL; @@ -945,11 +939,11 @@ static int motion_init(struct context *cnt) /* Initialize stream server if stream port is specified to not 0 */ if (cnt->conf.stream_port) { if (stream_init(cnt) == -1) { - motion_log(LOG_ERR, 1, "%s: Problem enabling motion-stream server in port %d", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem enabling motion-stream server in port %d", __FUNCTION__, cnt->conf.stream_port); cnt->finish = 1; } else { - motion_log(LOG_DEBUG, 0, "%s: Started motion-stream server in port %d", + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Started motion-stream server in port %d", __FUNCTION__, cnt->conf.stream_port); } } @@ -980,7 +974,7 @@ static void motion_cleanup(struct context *cnt) event(cnt, EVENT_STOP, NULL, NULL, NULL, NULL); if (cnt->video_dev >= 0) { - motion_log(LOG_DEBUG, 0, "%s: Calling vid_close() from motion_cleanup", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Calling vid_close() from motion_cleanup", __FUNCTION__); vid_close(cnt); } @@ -1306,7 +1300,7 @@ static void *motion_loop(void *arg) */ if (cnt->video_dev < 0 && cnt->currenttime % 10 == 0 && cnt->shots == 0) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Retrying until successful connection with camera", __FUNCTION__); cnt->video_dev = vid_start(cnt); @@ -1315,7 +1309,7 @@ static void *motion_loop(void *arg) * we need to restart Motion to re-allocate all the buffers */ if (cnt->imgs.width != cnt->conf.width || cnt->imgs.height != cnt->conf.height) { - motion_log(LOG_ERR, 0, "%s: Camera has finally become available\n" + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Camera has finally become available\n" "Camera image has different width and height" "from what is in the config file. You should fix that\n" "Restarting Motion thread to reinitialize all " @@ -1354,7 +1348,7 @@ static void *motion_loop(void *arg) /* If all is well reset missing_frame_counter */ if (cnt->missing_frame_counter >= MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) { /* If we previously logged starting a grey image, now log video re-start */ - motion_log(LOG_ERR, 0, "%s: Video signal re-acquired", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal re-acquired", __FUNCTION__); // event for re-acquired video signal can be called here } cnt->missing_frame_counter = 0; @@ -1384,7 +1378,7 @@ static void *motion_loop(void *arg) // FATAL ERROR - leave the thread by breaking out of the main loop } else if (vid_return_code < 0) { /* Fatal error - Close video device */ - motion_log(LOG_ERR, 0, "%s: Video device fatal error - Closing video device", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video device fatal error - Closing video device", __FUNCTION__); vid_close(cnt); /* @@ -1403,8 +1397,8 @@ static void *motion_loop(void *arg) */ } else { - if (debug_level >= CAMERA_VERBOSE) - motion_log(0, 0, "%s: vid_return_code %d", __FUNCTION__, vid_return_code); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: vid_return_code %d", + __FUNCTION__, vid_return_code); /* * Netcams that change dimensions while Motion is running will @@ -1413,7 +1407,7 @@ static void *motion_loop(void *arg) * other way */ if (vid_return_code == NETCAM_RESTART_ERROR) { - motion_log(LOG_ERR, 0, "%s: Restarting Motion thread to reinitialize all " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting Motion thread to reinitialize all " "image buffers", __FUNCTION__); /* * Break out of main loop terminating thread @@ -1463,7 +1457,7 @@ static void *motion_loop(void *arg) /* Write error message only once */ if (cnt->missing_frame_counter == MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) { - motion_log(LOG_ERR, 0, "%s: Video signal lost - Adding grey image", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal lost - Adding grey image", __FUNCTION__); // Event for lost video signal can be called from here event(cnt, EVENT_CAMERA_LOST, NULL, NULL, @@ -1476,7 +1470,7 @@ static void *motion_loop(void *arg) */ if ((cnt->video_dev > 0) && (cnt->missing_frame_counter == (MISSING_FRAMES_TIMEOUT * 4) * cnt->conf.frame_limit)) { - motion_log(LOG_ERR, 0, "%s: Video signal still lost - " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal still lost - " "Trying to close video device",__FUNCTION__); vid_close(cnt); } @@ -1516,8 +1510,8 @@ 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(0, 0, "%s: Lightswitch detected", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Lightswitch detected", + __FUNCTION__); if (cnt->moved < 5) cnt->moved = 5; @@ -1543,8 +1537,8 @@ static void *motion_loop(void *arg) if (cnt->current_image->diffs <= cnt->threshold) { cnt->current_image->diffs = 0; - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: Switchfilter detected", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Switchfilter detected", + __FUNCTION__); } } @@ -1646,8 +1640,8 @@ static void *motion_loop(void *arg) cnt->current_image->diffs = 0; cnt->lightswitch_framecounter = 0; - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: micro-lightswitch!", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: micro-lightswitch!", + __FUNCTION__); } else { alg_update_reference_frame(cnt, UPDATE_REF_FRAME); } @@ -1756,8 +1750,7 @@ static void *motion_loop(void *arg) */ if (cnt->conf.emulate_motion && (cnt->startup_frames == 0)) { cnt->detecting_motion = 1; - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: Emulating motion %d", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Emulating motion %d", __FUNCTION__); #ifdef HAVE_FFMPEG if (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) { #else @@ -1765,8 +1758,8 @@ static void *motion_loop(void *arg) #endif /* 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: (Em) Init post capture %d", + __FUNCTION__, cnt->postcap); } cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); @@ -1802,8 +1795,8 @@ static void *motion_loop(void *arg) #endif /* 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%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++) @@ -1818,8 +1811,8 @@ static void *motion_loop(void *arg) /* 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: post capture %d", + __FUNCTION__, cnt->postcap); } else { cnt->current_image->flags |= IMAGE_PRECAP; } @@ -1868,8 +1861,8 @@ static void *motion_loop(void *arg) NULL, cnt->currenttime_tm); 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.", z+1); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Motion in area %d detected.", + __FUNCTION__, z + 1); break; } } @@ -1910,9 +1903,8 @@ static void *motion_loop(void *arg) if (cnt->track.type) cnt->moved = track_center(cnt, cnt->video_dev, 0, 0, 0); - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: End of event %d", - __FUNCTION__, cnt->event_nr); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: End of event %d", + __FUNCTION__, cnt->event_nr); cnt->makemovie = 0; /* Reset post capture */ @@ -1963,7 +1955,7 @@ static void *motion_loop(void *arg) strcat(msg, part); } - motion_log(0, 0, "%s", msg); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s", msg); } } /* get_image end */ @@ -2037,9 +2029,9 @@ static void *motion_loop(void *arg) &cnt->current_image->timestamp_tm); /* If invalid we report in syslog once and continue in manual mode */ } else { - motion_log(LOG_ERR, 0, "%s: Invalid timelapse_mode argument '%s'", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Invalid timelapse_mode argument '%s'", __FUNCTION__, cnt->conf.timelapse_mode); - motion_log(LOG_ERR, 0, "%:s Defaulting to manual timelapse mode", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%:s Defaulting to manual timelapse mode", __FUNCTION__); conf_cmdparse(&cnt, (char *)"ffmpeg_timelapse_mode",(char *)"manual"); } @@ -2227,7 +2219,7 @@ static void *motion_loop(void *arg) free(rolling_average_data); cnt->lost_connection = 1; - motion_log(0, 0, "%s: Thread exiting", __FUNCTION__); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Thread exiting", __FUNCTION__); motion_cleanup(cnt); @@ -2276,7 +2268,7 @@ static void become_daemon(void) /* fork */ if (fork()) { - motion_log(0, 0, "%s: Motion going to daemon mode", __FUNCTION__); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion going to daemon mode", __FUNCTION__); exit(0); } @@ -2293,8 +2285,8 @@ static void become_daemon(void) (void)fprintf(pidf, "%d\n", getpid()); myfclose(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); + motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create process" + " id file (pid file) %s", __FUNCTION__, cnt_list[0]->conf.pid_file); if (ptr_logfile) myfclose(ptr_logfile); exit(0); @@ -2306,7 +2298,7 @@ static void become_daemon(void) * without having to stop Motion */ if (chdir("/")) - motion_log(LOG_ERR, 1, "%s: Could not change directory", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not change directory", __FUNCTION__); #if (defined(BSD)) @@ -2339,7 +2331,7 @@ static void become_daemon(void) /* Now it is safe to add the PID creation to the logs */ if (pidf) - motion_log(LOG_INFO, 0, "%s: Created process id file %s. Process ID is %d", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Created process id file %s. Process ID is %d", __FUNCTION__, cnt_list[0]->conf.pid_file, getpid()); sigaction(SIGTTOU, &sig_ign_action, NULL); @@ -2442,7 +2434,19 @@ static void motion_startup(int daemonize, int argc, char *argv[]) */ cntlist_create(argc, argv); - motion_log(LOG_INFO, 0, "%s: Motion "VERSION" Started", __FUNCTION__); + debug_level = cnt_list[0]->conf.log_level; + + if ((cnt_list[0]->conf.log_level > ALL) || + (cnt_list[0]->conf.log_level == 0)) { + cnt_list[0]->conf.log_level = LEVEL_DEFAULT; + debug_level = cnt_list[0]->conf.log_level; + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log level (%s) (%d)", + __FUNCTION__, get_log_level_str(debug_level), SHOW_LEVEL_VALUE(debug_level)); + } + + set_log_level(debug_level); + + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started", __FUNCTION__); if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) { set_log_mode(LOGMODE_FILE); @@ -2450,18 +2454,29 @@ static void motion_startup(int daemonize, int argc, char *argv[]) if (ptr_logfile) { set_log_mode(LOGMODE_SYSLOG); - motion_log(LOG_INFO, 0, "%s: Logging to file (%s)", __FUNCTION__, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to file (%s)", __FUNCTION__, cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_FILE); } else { - motion_log(LOG_ERR, 1, "%s: Exit motion, cannot create log file %s", + motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create log file %s", __FUNCTION__, cnt_list[0]->conf.log_file); exit(0); } } else { - motion_log(LOG_INFO, 0, "%s: Logging to syslog", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to syslog", __FUNCTION__); + } + + if (!(debug_type = get_log_type(cnt_list[0]->conf.log_type_str))) { + debug_type = TYPE_DEFAULT; + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log type (%s)", __FUNCTION__, + get_log_type_str(debug_type)); } + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using log type (%s) log level (%s)", __FUNCTION__, + get_log_type_str(debug_type), get_log_level_str(debug_level)); + + set_log_type(debug_type); + initialize_chars(); if (daemonize) { @@ -2471,7 +2486,7 @@ static void motion_startup(int daemonize, int argc, char *argv[]) */ if (cnt_list[0]->daemon && cnt_list[0]->conf.setup_mode == 0) { become_daemon(); - motion_log(LOG_INFO, 0, "%s: Motion running as daemon process", __FUNCTION__); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running as daemon process", __FUNCTION__); } } @@ -2544,10 +2559,10 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr if (cnt->conf.stream_port != 0) { /* Compare against the control port. */ if (cnt_list[0]->conf.webcontrol_port == cnt->conf.stream_port) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with the control port", __FUNCTION__, cnt->conf.stream_port, cnt->threadnr); - motion_log(LOG_ERR, 0, "%s: Stream feature for thread %d is disabled.", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", __FUNCTION__, cnt->threadnr); cnt->conf.stream_port = 0; } @@ -2558,10 +2573,10 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr continue; if (cnt_list[i]->conf.stream_port == cnt->conf.stream_port) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with thread %d", __FUNCTION__, cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr); - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", __FUNCTION__, cnt->threadnr); cnt->conf.stream_port = 0; @@ -2636,7 +2651,7 @@ int main (int argc, char **argv) * optimize motion detection and stuff. */ if (cnt_list[0]->conf.setup_mode) - motion_log(0, 0, "%s: Motion running in setup mode.", __FUNCTION__); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode.", __FUNCTION__); /* * Create and a thread attribute for the threads we spawn later on. @@ -2656,14 +2671,14 @@ int main (int argc, char **argv) * cleanup everything, and then initialize everything again * (including re-reading the config file(s)). */ - motion_log(LOG_INFO, 0, "%s: Restarting motion.", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting motion.", __FUNCTION__); motion_shutdown(); restart = 0; /* only one reset for now */ #ifndef WITHOUT_V4L SLEEP(5, 0); // maybe some cameras needs less time #endif motion_startup(0, argc, argv); /* 0 = skip daemon init */ - motion_log(LOG_INFO, 0, "%s: Motion restarted", __FUNCTION__); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion restarted", __FUNCTION__); } /* @@ -2675,19 +2690,16 @@ int main (int argc, char **argv) cnt_list[i]->threadnr = i ? i : 1; if (strcmp(cnt_list[i]->conf_filename, "")) - motion_log(LOG_INFO, 0, "%s: Thread %d is from %s", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", __FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf_filename); - if (debug_level >= CAMERA_DEBUG) - 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%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); - - if (debug_level >= CAMERA_DEBUG) - motion_log(LOG_ERR, 0, "%s: Stream port %d", - __FUNCTION__, cnt_list[i]->conf.stream_port); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Stream port %d", + __FUNCTION__, cnt_list[i]->conf.stream_port); start_motion_thread(cnt_list[i], &thread_attr); } @@ -2699,8 +2711,8 @@ int main (int argc, char **argv) if (cnt_list[0]->conf.webcontrol_port) pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list); - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: Waiting for threads to finish, pid: %d", __FUNCTION__, getpid()); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Waiting for threads to finish, pid: %d", + __FUNCTION__, getpid()); /* * Crude way of waiting for all threads to finish - check the thread @@ -2722,16 +2734,15 @@ int main (int argc, char **argv) if (((motion_threads_running == 0) && finish) || ((motion_threads_running == 0) && (threads_running == 0))) { - 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-1 threads_running %d motion_threads_running %d " + ", finish %d", __FUNCTION__, threads_running, motion_threads_running, finish); break; } for (i = (cnt_list[1] != NULL ? 1 : 0); cnt_list[i]; i++) { /* Check if threads wants to be restarted */ if ((!cnt_list[i]->running) && (cnt_list[i]->restart)) { - motion_log(LOG_INFO, 0, "%s: Motion thread %d restart", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion thread %d restart", __FUNCTION__, cnt_list[i]->threadnr); start_motion_thread(cnt_list[i], &thread_attr); } @@ -2740,13 +2751,13 @@ int main (int argc, char **argv) cnt_list[i]->watchdog--; if (cnt_list[i]->watchdog == 0) { - motion_log(LOG_ERR, 0, "%s: Thread %d - Watchdog timeout, trying to do " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, trying to do " "a graceful restart", __FUNCTION__, cnt_list[i]->threadnr); cnt_list[i]->finish = 1; } if (cnt_list[i]->watchdog == -60) { - motion_log(LOG_ERR, 0, "%s: Thread %d - Watchdog timeout, did NOT restart graceful," + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, did NOT restart graceful," "killing it!", __FUNCTION__, cnt_list[i]->threadnr); pthread_cancel(cnt_list[i]->thread_id); pthread_mutex_lock(&global_lock); @@ -2759,15 +2770,13 @@ int main (int argc, char **argv) } } - 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); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-2 threads_running %d motion_threads_running %d finish %d", + __FUNCTION__, threads_running, motion_threads_running, finish); } /* Reset end main loop flag */ finish = 0; - if (debug_level >= CAMERA_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Threads finished", __FUNCTION__); + motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Threads finished", __FUNCTION__); /* Rest for a while if we're supposed to restart. */ if (restart) @@ -2778,7 +2787,7 @@ int main (int argc, char **argv) // Be sure that http control exits fine cnt_list[0]->finish = 1; SLEEP(1, 0); - motion_log(LOG_INFO, 0, "%s: Motion terminating", __FUNCTION__); + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion terminating", __FUNCTION__); /* Perform final cleanup. */ pthread_key_delete(tls_key_threadnr); @@ -2813,7 +2822,7 @@ void * mymalloc(size_t nbytes) void *dummy = malloc(nbytes); if (!dummy) { - motion_log(LOG_EMERG, 1, "%s: Could not allocate %llu bytes of memory!", + motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Could not allocate %llu bytes of memory!", __FUNCTION__, (unsigned long long)nbytes); motion_remove_pid(); exit(1); @@ -2844,13 +2853,13 @@ void *myrealloc(void *ptr, size_t size, const char *desc) if (size == 0) { free(ptr); - motion_log(LOG_WARNING, 0, + motion_log(WRN, TYPE_ALL, NO_ERRNO, "%s: Warning! Function %s tries to resize memoryblock at %p to 0 bytes!", __FUNCTION__, desc, ptr); } else { dummy = realloc(ptr, size); if (!dummy) { - motion_log(LOG_EMERG, 0, + motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Could not resize memory-block at offset %p to %llu bytes (function %s)!", __FUNCTION__, ptr, (unsigned long long)size, desc); motion_remove_pid(); @@ -2892,7 +2901,7 @@ int create_path(const char *path) buffer[start-path] = 0x00; if (mkdir(buffer, mode) == -1 && errno != EEXIST) { - motion_log(LOG_ERR, 1, "%s: Problem creating directory %s", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem creating directory %s", __FUNCTION__, buffer); free(buffer); return -1; @@ -2901,7 +2910,7 @@ int create_path(const char *path) start = strchr(start + 1, '/'); if (!start) - motion_log(LOG_INFO, 0, "%s: creating directory %s", __FUNCTION__, buffer); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: creating directory %s", __FUNCTION__, buffer); free(buffer); } @@ -3016,7 +3025,7 @@ FILE * myfopen(const char *path, const char *mode, size_t bufsize) * first time * 2: could still not open the file after the path was created */ - motion_log(LOG_ERR, 1, "%s: Error opening file %s with mode %s", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening file %s with mode %s", __FUNCTION__, path, mode); } diff --git a/motion.h b/motion.h index 724573a..c160567 100644 --- a/motion.h +++ b/motion.h @@ -149,21 +149,21 @@ #define WATCHDOG_TMO 30 /* 30 sec max motion_loop interval */ #define WATCHDOG_OFF -127 /* Turn off watchdog, used when we wants to quit a thread */ -#define CONNECTION_KO "Lost connection" -#define CONNECTION_OK "Connection OK" +#define CONNECTION_KO "Lost connection" +#define CONNECTION_OK "Connection OK" #define DEF_MAXSTREAMS 10 /* Maximum number of stream clients per camera */ #define DEF_MAXWEBQUEUE 10 /* Maximum number of stream client in queue */ -#define DEF_TIMESTAMP "%Y-%m-%d\\n%T" -#define DEF_EVENTSTAMP "%Y%m%d%H%M%S" +#define DEF_TIMESTAMP "%Y-%m-%d\\n%T" +#define DEF_EVENTSTAMP "%Y%m%d%H%M%S" -#define DEF_SNAPPATH "%v-%Y%m%d%H%M%S-snapshot" -#define DEF_IMAGEPATH "%v-%Y%m%d%H%M%S-%q" -#define DEF_MOVIEPATH "%v-%Y%m%d%H%M%S" -#define DEF_TIMEPATH "%Y%m%d-timelapse" +#define DEF_SNAPPATH "%v-%Y%m%d%H%M%S-snapshot" +#define DEF_IMAGEPATH "%v-%Y%m%d%H%M%S-%q" +#define DEF_MOVIEPATH "%v-%Y%m%d%H%M%S" +#define DEF_TIMEPATH "%Y%m%d-timelapse" -#define DEF_TIMELAPSE_MODE "daily" +#define DEF_TIMELAPSE_MODE "daily" /* Do not break this line into two or more. Must be ONE line */ #define DEF_SQL_QUERY "sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')" @@ -340,6 +340,7 @@ struct context { unsigned int daemon; char pid_file[PATH_MAX]; char log_file[PATH_MAX]; + char log_type_str[6]; struct config conf; struct images imgs; @@ -437,6 +438,7 @@ struct context { extern pthread_mutex_t global_lock; extern volatile int threads_running; extern unsigned int debug_level; +extern unsigned int debug_type; extern FILE *ptr_logfile; /* TLS keys below */ diff --git a/netcam.c b/netcam.c index 261ac05..057f3ff 100644 --- a/netcam.c +++ b/netcam.c @@ -53,15 +53,6 @@ #define MAX_HEADER_RETRIES 5 /* Max tries to find a header record */ #define MINVAL(x, y) ((x) < (y) ? (x) : (y)) -/* - * The macro NETCAM_DEBUG is for development testing of this module. - * The macro SETUP is to assure that "configuration-setup" type messages - * are also printed when NETCAM_DEBUG is set. Set the following #if to - * 1 to enable it, or 0 (normal setting) to disable it. - */ -#define SETUP (debug_level >= CAMERA_INFO) - - tfile_context *file_new_context(void); void file_free_context(tfile_context* ctxt); @@ -164,8 +155,8 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) re = "(file)://(((.*):(.*))@)?" "([^/:]|[-.a-z0-9]*)(:([0-9]*))?($|(/[^:][/-_.a-z0-9]+))"; - if (debug_level > CAMERA_DEBUG) - motion_log(0, 0, "%s: Entry netcam_url_parse data %s", __FUNCTION__, text_url); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Entry netcam_url_parse data %s", + __FUNCTION__, text_url); memset(parse_url, 0, sizeof(struct url_t)); /* @@ -179,8 +170,8 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) if (regexec(&pattbuf, text_url, 10, matches, 0) != REG_NOMATCH) { for (i = 0; i < 10; i++) { if ((s = netcam_url_match(matches[i], text_url)) != NULL) { - if (debug_level > CAMERA_DEBUG) - motion_log(0, 0, "%s: Parse case %d data %s", __FUNCTION__, i, s); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Parse case %d" + " data %s", __FUNCTION__, i, s); switch (i) { case 1: parse_url->service = s; @@ -305,13 +296,13 @@ static long netcam_check_content_length(char *header) * we were able to recognize the header section and the * number we might as well try to use it. */ - if ((debug_level > CAMERA_INFO) && (length > 0)) - motion_log(LOG_DEBUG, 0, "%s: malformed token Content-Length but value %ld", - __FUNCTION__, length); + if (length > 0) + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: malformed token" + " Content-Length but value %ld", __FUNCTION__, length); } - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: Content-Length %ld", __FUNCTION__, length); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length %ld", + __FUNCTION__, length); return length; } @@ -401,8 +392,8 @@ static int netcam_check_content_type(char *header) if (!header_process(header, "Content-type", http_process_type, &content_type)) return -1; - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: Content-type %s", __FUNCTION__, content_type); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-type %s", + __FUNCTION__, content_type); if (!strcmp(content_type, "image/jpeg")) { ret = 1; @@ -463,15 +454,13 @@ static int netcam_read_next_header(netcam_context_ptr netcam) if (retval != HG_OK) { /* Header reported as not-OK, check to see if it's null */ if (strlen(header) == 0) { - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: Error reading image header, " - "streaming mode (1). Null header.", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " + "streaming mode (1). Null header.", __FUNCTION__); } else { /* Header is not null. Output it in case it's a new camera with unknown headers. */ - if (debug_level > CAMERA_INFO) - motion_log(LOG_ERR, 0, "%s: Error reading image header, " - "streaming mode (1). Unknown header '%s'", - __FUNCTION__, header); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " + "streaming mode (1). Unknown header '%s'", + __FUNCTION__, header); } free(header); @@ -490,7 +479,8 @@ static int netcam_read_next_header(netcam_context_ptr netcam) retval = header_get(netcam, &header, HG_NONE); if (retval != HG_OK) { - motion_log(LOG_ERR, 0, "%s: Error reading image header (2)", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header (2)", + __FUNCTION__); free(header); return -1; } @@ -500,7 +490,8 @@ static int netcam_read_next_header(netcam_context_ptr netcam) if ((retval = netcam_check_content_type(header)) >= 0) { if (retval != 1) { - motion_log(LOG_ERR, 0, "%s: Header not JPEG", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Header not JPEG", + __FUNCTION__); free(header); return -1; } @@ -512,8 +503,9 @@ static int netcam_read_next_header(netcam_context_ptr netcam) netcam->receiving->content_length = retval; } else { netcam->receiving->content_length = 0; - motion_log(LOG_ERR, 0, "%s: Content-Length 0", __FUNCTION__); - free(header);free(header); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length 0", + __FUNCTION__); + free(header); return -1; } } @@ -521,8 +513,8 @@ static int netcam_read_next_header(netcam_context_ptr netcam) free(header); } - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Found image header record", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Found image header record", + __FUNCTION__); free(header); return 0; @@ -559,12 +551,12 @@ static int netcam_read_first_header(netcam_context_ptr netcam) int closeflag = 0; /* If we have seen a Connection: close header from cam */ char *header; char *boundary; - //struct context *cnt = netcam->cnt; /* for conf debug_level */ /* Send the initial command to the camera */ if (send(netcam->sock, netcam->connect_request, strlen(netcam->connect_request), 0) < 0) { - motion_log(LOG_ERR, 1, "%s: Error sending 'connect' request", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Error sending" + " 'connect' request", __FUNCTION__); return -1; } @@ -593,20 +585,20 @@ static int netcam_read_first_header(netcam_context_ptr netcam) while (1) { /* 'Do forever' */ ret = header_get(netcam, &header, HG_NONE); - if (debug_level > CAMERA_INFO) /* Changed criterion and moved up from below to catch headers that cause returns */ - motion_log(LOG_DEBUG, 0, "%s: Received first header ('%s')", __FUNCTION__, header); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received first header ('%s')", + __FUNCTION__, header); if (ret != HG_OK) { - if (debug_level > CAMERA_INFO) - motion_log(LOG_ERR, 0, "%s: Error reading first header (%s)", __FUNCTION__, header); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header (%s)", + __FUNCTION__, header); free(header); return -1; } if (firstflag) { if ((ret = http_result_code(header)) != 200) { - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: HTTP Result code %d", __FUNCTION__, ret); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: HTTP Result code %d", + __FUNCTION__, ret); free(header); if (netcam->connect_keepalive) { @@ -619,7 +611,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam) netcam->connect_keepalive = FALSE; free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - motion_log(LOG_INFO, 0, "%s: Removed netcam Keep-Alive flag" + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag" "due to apparent closed HTTP connection.", __FUNCTION__); } return ret; @@ -644,20 +636,19 @@ static int netcam_read_first_header(netcam_context_ptr netcam) */ switch (ret) { case 1: /* not streaming */ - if (SETUP) { - if (netcam->connect_keepalive) - motion_log(LOG_DEBUG, 0, "%s: Non-streaming camera " - "(keep-alive set)", __FUNCTION__); - else - motion_log(LOG_DEBUG, 0, "%s: Non-streaming camera " - "(keep-alive not set)", __FUNCTION__); - } + if (netcam->connect_keepalive) + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " + "(keep-alive set)", __FUNCTION__); + else + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " + "(keep-alive not set)", __FUNCTION__); + netcam->caps.streaming = NCS_UNSUPPORTED; break; case 2: /* streaming */ - if (SETUP) - motion_log(LOG_DEBUG, 0, "%s: Streaming camera", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera", + __FUNCTION__); netcam->caps.streaming = NCS_MULTIPART; @@ -676,35 +667,32 @@ static int netcam_read_first_header(netcam_context_ptr netcam) check_quote(netcam->boundary); netcam->boundary_length = strlen(netcam->boundary); - if (SETUP) - motion_log(LOG_DEBUG, 0, "%s: Boundary string [%s]", - __FUNCTION__, netcam->boundary); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Boundary string [%s]", + __FUNCTION__, netcam->boundary); } break; case 3: /* MJPG-Block style streaming */ - if (SETUP) - motion_log(LOG_DEBUG, 0, "%s: Streaming camera probably using MJPG-blocks," - " consider using mjpg:// netcam_url.", __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera probably using MJPG-blocks," + " consider using mjpg:// netcam_url.", __FUNCTION__); break; default: /* error */ - motion_log(LOG_ERR, 0, "%s: Unrecognized content type", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized content type", __FUNCTION__); free(header); return -1; } } else if ((ret = (int) netcam_check_content_length(header)) >= 0) { - if (SETUP) - motion_log(LOG_DEBUG, 0, "%s: Content-length present", __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Content-length present", __FUNCTION__); if (ret > 0) { netcam->caps.content_length = 1; /* set flag */ netcam->receiving->content_length = ret; } else { netcam->receiving->content_length = 0; - motion_log(LOG_ERR, 0, "%s: Content-length 0", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-length 0", __FUNCTION__); retval = -2; } } else if (netcam_check_keepalive(header) == TRUE) { @@ -722,8 +710,8 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * This flag is acted upon below * Changed criterion and moved up from below to catch headers that cause returns */ - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: Found Conn: close header ('%s')", __FUNCTION__, header); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Found Conn: close header ('%s')", + __FUNCTION__, header); } free(header); } @@ -738,7 +726,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam) netcam->warning_count++; if (netcam->warning_count > 3) { netcam->warning_count = 0; - motion_log(LOG_INFO, 0, "%s: Info: Both 'Connection: Keep-Alive' and " + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " "'Connection: close' header received. Motion removes keepalive.", __FUNCTION__); netcam->connect_keepalive = FALSE; @@ -750,7 +738,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * did not see a Keep-Alive field returned from netcam and a Close field. * Not quite sure what the correct course of action is here. In for testing. */ - motion_log(LOG_INFO, 0, "%s: Info: Both 'Connection: Keep-Alive' and " + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " "'Connection: close' header received. Motion continues unchanged.", __FUNCTION__); } else { @@ -762,9 +750,8 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * No action, as this is the normal case. In debug we print a notification. */ - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: Info: Received a Keep-Alive field in this" - "set of headers.", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received a Keep-Alive field in this" + "set of headers.", __FUNCTION__); } } else { /* !aliveflag */ if (!closeflag) { @@ -772,8 +759,8 @@ static int netcam_read_first_header(netcam_context_ptr netcam) if (netcam->warning_count > 3) { netcam->warning_count = 0; - motion_log(LOG_INFO, 0, "%s: No 'Connection: Keep-Alive' nor 'Connection: close' " - "header received.\n Motion removes keepalive.", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" + " header received.\n Motion removes keepalive.", __FUNCTION__); netcam->connect_keepalive = FALSE; free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); @@ -783,8 +770,8 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * did not see a Keep-Alive field returned from netcam nor a Close field. * Not quite sure what the correct course of action is here. In for testing. */ - motion_log(LOG_INFO, 0, "%s: Info: No 'Connection: Keep-Alive' nor 'Connection: close' " - "header received.\n Motion continues unchanged.", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" + " header received.\n Motion continues unchanged.", __FUNCTION__); } else { /* * !aliveflag & closeflag @@ -812,13 +799,14 @@ static int netcam_read_first_header(netcam_context_ptr netcam) netcam->connect_keepalive = FALSE; /* No further attempts at keep-alive */ free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - motion_log(LOG_INFO, 0, "%s: Removed netcam Keep-Alive flag because " - "'Connection: close' header received.\n Netcam does not support " + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag because" + " 'Connection: close' header received.\n Netcam does not support " "Keep-Alive. Motion continues in non-Keep-Alive.", __FUNCTION__); } else { netcam->keepalive_timeup = TRUE; /* We will close and re-open keep-alive */ - motion_log(LOG_INFO, 0, "Keep-Alive has reached end of valid period.\n Motion will close " - "netcam, then resume Keep-Alive with a new socket.", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "Keep-Alive has reached end of valid period.\n" + "Motion will close netcam, then resume Keep-Alive with a new socket.", + __FUNCTION__); } } } @@ -843,7 +831,7 @@ static void netcam_disconnect(netcam_context_ptr netcam) { if (netcam->sock > 0) { if (close(netcam->sock) < 0) - motion_log(LOG_ERR, 1, "%s: netcam_disconnect", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: netcam_disconnect", __FUNCTION__); netcam->sock = -1; } @@ -881,75 +869,70 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) /* Assure any previous connection has been closed - IF we are not in keepalive */ if (!netcam->connect_keepalive) { - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting netcam " - "since keep-alive not set.", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam " + "since keep-alive not set.", __FUNCTION__); netcam_disconnect(netcam); /* create a new socket */ if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - motion_log(LOG_ERR, 1, "%s: with no keepalive, attempt " + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with no keepalive, attempt " "to create socket failed.", __FUNCTION__); return -1; } - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: with no keepalive, " - "new socket created fd %d", __FUNCTION__, netcam->sock); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: with no keepalive, " + "new socket created fd %d", __FUNCTION__, netcam->sock); } else if (netcam->sock == -1) { /* We are in keepalive mode, check for invalid socket */ /* Must be first time, or closed, create a new socket */ if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - motion_log(LOG_ERR, 1, "%s: with keepalive set, invalid socket." + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with keepalive set, invalid socket." "This could be the first time. Creating a new one failed.", __FUNCTION__); return -1; } - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: with keepalive set, invalid socket." - "This could be first time, created a new one with fd %d", - __FUNCTION__, netcam->sock); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: with keepalive set, invalid socket." + "This could be first time, created a new one with fd %d", + __FUNCTION__, netcam->sock); /* Record that this connection has not yet received a Keep-Alive header */ netcam->keepalive_thisconn = FALSE; /* Check the socket status for the keepalive option */ if (getsockopt(netcam->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen) < 0) { - motion_log(LOG_ERR, 1, "%s: getsockopt()", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: getsockopt()", __FUNCTION__); return -1; } - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: SO_KEEPALIVE is %s", __FUNCTION__, optval ? "ON":"OFF"); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE is %s", + __FUNCTION__, optval ? "ON":"OFF"); /* Set the option active */ optval = 1; optlen = sizeof(optval); if (setsockopt(netcam->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { - motion_log(LOG_ERR, 1, "%s: setsockopt()", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setsockopt()", __FUNCTION__); return -1; } - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: SO_KEEPALIVE set on socket.", __FUNCTION__); - - } else if (debug_level > CAMERA_INFO) { - motion_log(LOG_DEBUG, 0, "%s: re-using socket %d since keepalive is set.", - __FUNCTION__, netcam->sock); - } + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE set on socket.", + __FUNCTION__); + } + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: re-using socket %d since keepalive is set.", + __FUNCTION__, netcam->sock); /* lookup the hostname given in the netcam URL */ if ((ret = getaddrinfo(netcam->connect_host, NULL, NULL, &res)) != 0) { if (!err_flag) - motion_log(LOG_ERR, 0, "%s: getaddrinfo() failed (%s): %s", + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getaddrinfo() failed (%s): %s", __FUNCTION__, netcam->connect_host, gai_strerror(ret)); - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting netcam (1)", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (1)", + __FUNCTION__); netcam_disconnect(netcam); return -1; @@ -972,14 +955,14 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) */ if ((saveflags = fcntl(netcam->sock, F_GETFL, 0)) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl(1) on socket", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(1) on socket", __FUNCTION__); netcam_disconnect(netcam); return -1; } /* Set the socket non-blocking */ if (fcntl(netcam->sock, F_SETFL, saveflags | O_NONBLOCK) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl(2) on socket", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(2) on socket", __FUNCTION__); netcam_disconnect(netcam); return -1; } @@ -992,12 +975,11 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) /* If the connect failed with anything except EINPROGRESS, error */ if ((ret < 0) && (back_err != EINPROGRESS)) { if (!err_flag) - motion_log(LOG_ERR, 1, "%s: connect() failed (%d)", + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect() failed (%d)", __FUNCTION__, back_err); - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting netcam (4)", - __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (4)", + __FUNCTION__); netcam_disconnect(netcam); return -1; @@ -1012,10 +994,11 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) if (ret == 0) { /* 0 means timeout */ if (!err_flag) - motion_log(LOG_ERR, 0, "%s: timeout on connect()", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: timeout on connect()", + __FUNCTION__); - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting netcam (2)", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (2)", + __FUNCTION__); netcam_disconnect(netcam); return -1; @@ -1029,7 +1012,8 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) len = sizeof(ret); if (getsockopt(netcam->sock, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) { - motion_log(LOG_ERR, 0, "%s: getsockopt after connect", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getsockopt after connect", + __FUNCTION__); netcam_disconnect(netcam); return -1; } @@ -1037,10 +1021,11 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) /* If the return code is anything except 0, error on connect */ if (ret) { if (!err_flag) - motion_log(LOG_ERR, 1, "%s: connect returned error", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect returned error", + __FUNCTION__); - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting netcam (3)", __FUNCTION__); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (3)", + __FUNCTION__); netcam_disconnect(netcam); return -1; @@ -1083,10 +1068,9 @@ 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(0, 0, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", - __FUNCTION__, (int) buff->used, (int) buff->size, - (int) buff->used, new_size); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", + __FUNCTION__, (int) buff->used, (int) buff->size, + (int) buff->used, new_size); buff->ptr = myrealloc(buff->ptr, new_size, "netcam_check_buf_size"); @@ -1291,13 +1275,11 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * module netcam_wget.c to do this job! */ - if (debug_level > CAMERA_INFO) { - motion_log(0, 0, - "%s: Potential split boundary - " - "%d chars flushed, %d " - "re-positioned", __FUNCTION__, ix, - (int) netcam->response->buffer_left); - } + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, + "%s: Potential split boundary - " + "%d chars flushed, %d " + "re-positioned", __FUNCTION__, ix, + (int) netcam->response->buffer_left); memmove(netcam->response->buffer, ptr, netcam->response->buffer_left); @@ -1309,7 +1291,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) netcam->response->buffer_left); if (retval <= 0) { /* this is a fatal error */ - motion_log(LOG_ERR, 1, "%s: recv() fail after boundary string", + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv() fail after boundary string", __FUNCTION__); return -1; } @@ -1346,7 +1328,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * the new 'receiving' */ if (gettimeofday(&curtime, NULL) < 0) - motion_log(LOG_ERR, 1, "%s: gettimeofday in netcam_read_jpeg", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", __FUNCTION__); netcam->receiving->image_time = curtime; @@ -1361,9 +1343,8 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) 1000000.0 * (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1384,15 +1365,13 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) if (netcam->caps.streaming == NCS_UNSUPPORTED) { if (!netcam->connect_keepalive) { - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: disconnecting " - "netcam since keep-alive not set.", __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting " + "netcam since keep-alive not set.", __FUNCTION__); netcam_disconnect(netcam); - } else if (debug_level > CAMERA_INFO) { - motion_log(LOG_DEBUG, 0, "%s: leaving netcam connected.", - __FUNCTION__); - } + } + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: leaving netcam connected.", + __FUNCTION__); } return 0; @@ -1432,12 +1411,11 @@ static int netcam_http_request(netcam_context_ptr netcam) * safe to include it as part of this loop * (Not always true now Keep-Alive is implemented) */ - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: about to try to connect, time #%d", - __FUNCTION__, ix); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: about to try to connect, time #%d", + __FUNCTION__, ix); if (netcam_connect(netcam, 0) != 0) { - motion_log(LOG_ERR, 0, "Failed to open camera - check your config " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "Failed to open camera - check your config " "and that netcamera is online", __FUNCTION__); /* Fatal error on startup */ @@ -1448,11 +1426,11 @@ static int netcam_http_request(netcam_context_ptr netcam) if (netcam_read_first_header(netcam) >= 0) break; - motion_log(LOG_ERR, 0, "%s: Error reading first header - re-trying", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header - re-trying", __FUNCTION__); } if (ix == MAX_HEADER_RETRIES) { - motion_log(LOG_ERR, 0, "%s: Failed to read first camera header " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to read first camera header " "- giving up for now", __FUNCTION__); return -1; } @@ -1483,10 +1461,12 @@ 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(0, 0, "%s: Read error, trying to reconnect..", __FUNCTION__); + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: Read error," + " trying to reconnect..", __FUNCTION__); /* We may have lost the connexion */ if (netcam_http_request(netcam) < 0) { - motion_log(0, 0, "%s: lost the cam.", __FUNCTION__); + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: lost the cam.", + __FUNCTION__); return -1; /* We REALLY lost the cam... bail out for now. */ } } @@ -1498,9 +1478,8 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam) netcam->response->buffer_left = retval; netcam->response->buffer_pos = netcam->response->buffer; - if (SETUP) - motion_log(LOG_DEBUG, 0, "%s: Refilled buffer with [%d] bytes from the network.", - __FUNCTION__, retval); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Refilled buffer with [%d]" + " bytes from the network.", __FUNCTION__, retval); return retval; } @@ -1567,10 +1546,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) retval = rbuf_flush(netcam, ((char *)&mh) + read_bytes, sizeof(mh) - read_bytes); read_bytes += retval; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Read [%d/%d] header bytes.", - __FUNCTION__, read_bytes, sizeof(mh)); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Read [%d/%d] header bytes.", + __FUNCTION__, read_bytes, sizeof(mh)); /* If we don't have received a full header, refill our buffer. */ if (read_bytes < sizeof(mh)) { @@ -1581,11 +1559,8 @@ 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(0, 0, "%s: Invalid header received, reconnecting", - __FUNCTION__); - - + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Invalid header received," + " reconnecting", __FUNCTION__); /* * We shall reconnect to restart the stream, and get a chance * to resync. @@ -1605,13 +1580,12 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) retval = rbuf_flush(netcam, buffer->ptr + buffer->used + read_bytes, mh.mh_chunksize - read_bytes); read_bytes += retval; - if (debug_level > CAMERA_INFO) - 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); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "Chunk incomplete, going to refill."); */ + /* motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "Chunk incomplete, going to refill."); */ if (netcam_mjpg_buffer_refill(netcam) < 0) return -1; @@ -1619,21 +1593,18 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) } buffer->used += read_bytes; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Chunk complete, buffer used [%d] bytes.", - __FUNCTION__, buffer->used); - + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Chunk complete," + " buffer used [%d] bytes.", __FUNCTION__, buffer->used); /* Is our JPG image complete ? */ if (mh.mh_framesize == buffer->used) { - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Image complete, buffer used [%d] bytes.", - __FUNCTION__, buffer->used); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Image complete," + " buffer used [%d] bytes.", __FUNCTION__, buffer->used); break; } - /* motion_log(LOG_ERR, 0, " -> Rlen now at [%d] bytes", rlen); */ + /* motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Rlen now at [%d] bytes", __FUNCTION__, rlen); */ } /* @@ -1642,9 +1613,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) * the new 'receiving' */ if (gettimeofday(&curtime, NULL) < 0) - motion_log(LOG_ERR, 1, "%s: gettimeofday in netcam_read_jpeg", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", + __FUNCTION__); - netcam->receiving->image_time = curtime; /* @@ -1657,9 +1628,8 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) 1000000.0 * (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1702,7 +1672,7 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) /* Request the image from the remote server */ if (ftp_get_socket(netcam->ftp) <= 0) { - motion_log(LOG_ERR, 0, "%s: ftp_get_socket failed in netcam_read_jpeg", + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: ftp_get_socket failed", __FUNCTION__); return -1; } @@ -1720,9 +1690,9 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) } while (len > 0); if (gettimeofday(&curtime, NULL) < 0) - motion_log(LOG_ERR, 1, "%s: gettimeofday in netcam_read_jpeg", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", + __FUNCTION__); - netcam->receiving->image_time = curtime; /* * Calculate our "running average" time for this netcam's @@ -1734,9 +1704,8 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1778,9 +1747,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) { int loop_counter = 0; - if (debug_level >= CAMERA_ALL) { - motion_log(0, 0, "%s: Begin", __FUNCTION__); - } + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Begin", __FUNCTION__); netcam_buff_ptr buffer; int len; @@ -1795,23 +1762,24 @@ 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(0, 0, "%s: stat(%s) error", __FUNCTION__, netcam->file->path); + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: stat(%s) error", + __FUNCTION__, netcam->file->path); return -1; } - 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); - + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "%s: waiting new file image timeout", __FUNCTION__); + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: waiting new file image" + " timeout", __FUNCTION__); return -1; } - if (debug_level >= CAMERA_ALL) - motion_log(0, 0, "%s: delay waiting new file image ", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: delay waiting new" + " file image ", __FUNCTION__); //its waits 5seconds - READ_TIMEOUT //SLEEP(netcam->timeout.tv_sec, netcam->timeout.tv_usec*1000); @@ -1823,9 +1791,8 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) netcam->file->last_st_mtime = statbuf.st_mtime; - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: processing new file image - st_mtime " - "%d", __FUNCTION__, netcam->file->last_st_mtime); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing new file image -" + " st_mtime %d", __FUNCTION__, netcam->file->last_st_mtime); /* Assure there's enough room in the buffer */ while (buffer->size < (size_t)statbuf.st_size) @@ -1835,23 +1802,24 @@ 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(0, 0, "%s: open(%s) error: %d", __FUNCTION__, - netcam->file->path, netcam->file->control_file_desc); + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "%s: read(%s) error: %d", __FUNCTION__, - netcam->file->control_file_desc, len); + if ((len = read(netcam->file->control_file_desc, + buffer->ptr + buffer->used, statbuf.st_size)) < 0) { + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: read(%s) error: %d", + __FUNCTION__, netcam->file->control_file_desc, len); return -1; } buffer->used += len; - close(netcam->file->control_file_desc); if (gettimeofday(&curtime, NULL) < 0) - motion_log(LOG_ERR, 1, "%s: gettimeofday in netcam_read_jpeg", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", + __FUNCTION__); netcam->receiving->image_time = curtime; @@ -1865,9 +1833,8 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Calculated frame time %f", __FUNCTION__, - netcam->av_frame_time); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + __FUNCTION__, netcam->av_frame_time); } netcam->last_image = curtime; @@ -1893,8 +1860,8 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) pthread_mutex_unlock(&netcam->mutex); - if (debug_level >= CAMERA_ALL) - motion_log(0, 0, "%s: End", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: End", + __FUNCTION__); return 0; } @@ -1939,9 +1906,8 @@ static int netcam_setup_file(netcam_context_ptr netcam, struct url_t *url) netcam->file->path = url->path; url->path = NULL; - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: netcam->file->path %s", - __FUNCTION__, netcam->file->path); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->file->path %s", + __FUNCTION__, netcam->file->path); netcam_url_free(url); @@ -1974,9 +1940,8 @@ static void *netcam_handler_loop(void *arg) */ pthread_setspecific(tls_key_threadnr, (void *)((unsigned long)cnt->threadnr)); - if (SETUP) - motion_log(LOG_INFO, 0, "%s: Camera handler thread [%d] started", - __FUNCTION__, netcam->threadnr); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Camera handler thread [%d]" + " started", __FUNCTION__, netcam->threadnr); /* * The logic of our loop is very simple. If this is a non- @@ -1993,12 +1958,13 @@ static void *netcam_handler_loop(void *arg) if (netcam->response) { /* if html input */ if (netcam->caps.streaming == NCS_UNSUPPORTED) { /* Non-streaming ie. jpeg */ - if (!netcam->connect_keepalive || (netcam->connect_keepalive && netcam->keepalive_timeup)) { + if (!netcam->connect_keepalive || + (netcam->connect_keepalive && netcam->keepalive_timeup)) { /* If keepalive flag set but time up, time to close this socket */ if (netcam->connect_keepalive && netcam->keepalive_timeup) { - motion_log(LOG_INFO, 0, "%s: Closing netcam socket as Keep-Alive" - "time is up (camera sent Close field). A reconnect should happen.", - __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Closing netcam socket" + " as Keep-Alive time is up (camera sent Close field). A reconnect" + " should happen.", __FUNCTION__); netcam_disconnect(netcam); netcam->keepalive_timeup = FALSE; } @@ -2006,7 +1972,7 @@ static void *netcam_handler_loop(void *arg) /* And the netcam_connect call below will open a new one */ if (netcam_connect(netcam, open_error) < 0) { if (!open_error) { /* log first error */ - motion_log(LOG_ERR, 0, + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: re-opening camera (non-streaming)", __FUNCTION__); open_error = 1; } @@ -2016,7 +1982,7 @@ static void *netcam_handler_loop(void *arg) } if (open_error) { /* log re-connection */ - motion_log(LOG_ERR, 0, + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: camera re-connected", __FUNCTION__); open_error = 0; } @@ -2024,10 +1990,10 @@ static void *netcam_handler_loop(void *arg) /* Send our request and look at the response */ if ((retval = netcam_read_first_header(netcam)) != 1) { if (retval > 0) { - motion_log(LOG_ERR, 0, "%s: Unrecognized image header (%d)", - __FUNCTION__, retval); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized image" + " header (%d)", __FUNCTION__, retval); } else if (retval != -1) { - motion_log(LOG_ERR, 0, "%s: Error in header (%d)", + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error in header (%d)", __FUNCTION__, retval); } /* need to have a dynamic delay here */ @@ -2037,7 +2003,7 @@ static void *netcam_handler_loop(void *arg) if (netcam_read_next_header(netcam) < 0) { if (netcam_connect(netcam, open_error) < 0) { if (!open_error) { /* log first error */ - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: re-opening camera (streaming)", __FUNCTION__); open_error = 1; @@ -2048,11 +2014,11 @@ static void *netcam_handler_loop(void *arg) if ((retval = netcam_read_first_header(netcam) != 2)) { if (retval > 0) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized image header (%d)", __FUNCTION__, retval); } else if (retval != -1) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error in header (%d)", __FUNCTION__, retval); } /* FIXME need some limit */ @@ -2060,7 +2026,7 @@ static void *netcam_handler_loop(void *arg) } } if (open_error) { /* log re-connection */ - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: camera re-connected", __FUNCTION__); open_error = 0; } @@ -2072,12 +2038,14 @@ static void *netcam_handler_loop(void *arg) } } if (netcam->get_image(netcam) < 0) { - motion_log(LOG_ERR, 0, "%s: Error getting jpeg image", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error getting jpeg image", + __FUNCTION__); /* if FTP connection, attempt to re-connect to server */ if (netcam->ftp) { close(netcam->ftp->control_file_desc); if (ftp_connect(netcam) < 0) - motion_log(LOG_ERR, 0, "%s: Trying to re-connect", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Trying to re-connect", + __FUNCTION__); } continue; @@ -2125,8 +2093,8 @@ static void *netcam_handler_loop(void *arg) pthread_mutex_unlock(&global_lock); /* log out a termination message */ - motion_log(LOG_INFO, 0, "%s: netcam camera handler: finish set, exiting", - __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam camera handler:" + " finish set, exiting", __FUNCTION__); /* setting netcam->thread_id to zero shows netcam_cleanup we're done */ netcam->thread_id = 0; @@ -2168,10 +2136,10 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) netcam->response = (struct rbuf *) mymalloc(sizeof(struct rbuf)); memset(netcam->response, 0, sizeof(struct rbuf)); - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: Netcam has flags: HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", - __FUNCTION__, netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", - netcam->connect_keepalive ? "ON":"OFF"); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam has flags:" + " HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", __FUNCTION__, + netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", + netcam->connect_keepalive ? "ON":"OFF"); /* * The network camera may require a username and password. If @@ -2247,9 +2215,9 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - if (debug_level > CAMERA_INFO) - motion_log(LOG_DEBUG, 0, "%s: Removed netcam_keepalive flag due to proxy set." - "Proxy is incompatible with Keep-Alive.", __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: " + "Removed netcam_keepalive flag due to proxy set." + "Proxy is incompatible with Keep-Alive.", __FUNCTION__); } else { /* if no proxy, set as netcam_url path */ ptr = url->path; @@ -2312,9 +2280,9 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) free((void *)ptr); netcam_url_free(url); /* Cleanup the url data */ - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: Camera connect string is ''%s'' End of camera connect string.", - __FUNCTION__, netcam->connect_request); + motion_log(INF , TYPE_NETCAM, NO_ERRNO, "%s: Camera connect" + " string is ''%s'' End of camera connect string.", + __FUNCTION__, netcam->connect_request); return 0; } @@ -2354,14 +2322,15 @@ static int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url) */ if (netcam->caps.streaming == NCS_MULTIPART) { if (netcam_read_next_header(netcam) < 0) { - motion_log(LOG_ERR, 0, "%s: Failed to read first stream header - " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed " + "to read first stream header - " "giving up for now", __FUNCTION__); return -1; } } - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: connected, going on to read image.", __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," + " going on to read image.", __FUNCTION__); netcam->get_image = netcam_read_html_jpeg; return 0; @@ -2404,9 +2373,8 @@ static int netcam_setup_mjpg(netcam_context_ptr netcam, struct url_t *url) * We are positionned right just at the start of the first MJPG * header, so don't move anymore, initialization complete. */ - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: connected, going on to read and decode MJPG chunks.", - __FUNCTION__); + motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," + " going on to read and decode MJPG chunks.", __FUNCTION__); netcam->get_image = netcam_read_mjpg_jpeg; @@ -2429,9 +2397,9 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) netcam->ftp->path = url->path; url->path = NULL; - if (cnt->conf.netcam_userpass != NULL) + if (cnt->conf.netcam_userpass != NULL) { ptr = cnt->conf.netcam_userpass; - else { + } else { ptr = url->userpass; /* don't set this one NULL, gets freed */ } @@ -2459,7 +2427,8 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) } if (ftp_send_type(netcam->ftp, 'I') < 0) { - motion_log(LOG_ERR, 0, "%s: Error sending TYPE I to ftp server", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error sending" + " TYPE I to ftp server", __FUNCTION__); return -1; } @@ -2595,7 +2564,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(0, 0, "%s: No response from camera " + motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: No response from camera " "handler - it must have already died", __FUNCTION__); pthread_mutex_lock(&global_lock); @@ -2682,9 +2651,8 @@ int netcam_next(struct context *cnt, unsigned char *image) netcam = cnt->netcam; if (!netcam->latest->used) { - if (debug_level) - motion_log(LOG_INFO, 0, "%s: netcam_next called with no data in buffer", - __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: called with no data in buffer", + __FUNCTION__); return NETCAM_NOTHING_NEW_ERROR; } @@ -2741,8 +2709,8 @@ int netcam_start(struct context *cnt) memset(&url, 0, sizeof(url)); - motion_log(LOG_INFO, 0, "%s: Network Camera thread starting... for url (%s)", - __FUNCTION__, cnt->conf.netcam_url); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Network Camera thread" + " starting... for url (%s)", __FUNCTION__, cnt->conf.netcam_url); /* * Create a new netcam_context for this camera * and clear all the entries. @@ -2788,15 +2756,15 @@ int netcam_start(struct context *cnt) netcam_url_parse(&url, cnt->conf.netcam_proxy); if (!url.host) { - motion_log(LOG_ERR, 0, "%s: Invalid netcam_proxy (%s)", + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_proxy (%s)", __FUNCTION__, cnt->conf.netcam_proxy); netcam_url_free(&url); return -1; } if (url.userpass) { - motion_log(LOG_ERR, 0, "%s: Username/password not allowed on a proxy URL", - __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Username/password" + " not allowed on a proxy URL", __FUNCTION__); netcam_url_free(&url); return -1; } @@ -2818,7 +2786,7 @@ int netcam_start(struct context *cnt) netcam_url_parse(&url, cnt->conf.netcam_url); if (!url.host) { - motion_log(LOG_ERR, 0, "%s: Invalid netcam_url (%s)", + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_url (%s)", __FUNCTION__, cnt->conf.netcam_url); netcam_url_free(&url); return -1; @@ -2852,38 +2820,38 @@ int netcam_start(struct context *cnt) netcam->connect_keepalive = TRUE; /* HTTP 1.1 has keepalive by default */ } - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: Netcam_http parameter '%s' converts to flags: HTTP/1.0:" - "%s HTTP/1.1: %s Keep-Alive %s.", __FUNCTION__, cnt->conf.netcam_keepalive, - netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", - netcam->connect_keepalive ? "ON":"OFF"); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam_http parameter '%s'" + " converts to flags: HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", + __FUNCTION__, cnt->conf.netcam_keepalive, + netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", + netcam->connect_keepalive ? "ON":"OFF"); /* Initialise the netcam socket to -1 to trigger a connection by the keep-alive logic */ netcam->sock = -1; if ((url.service) && (!strcmp(url.service, "http"))) { - if (debug_level > CAMERA_INFO) - motion_log(0, 0, "%s: now calling netcam_setup_html()", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "%s:: now calling netcam_setup_ftp", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "%s: now calling netcam_setup_file()", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%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(0, 0, "%s: now calling netcam_setup_mjpg()", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_mjpg()", __FUNCTION__); strcpy(url.service, "http"); /* Put back a real URL service. */ retval = netcam_setup_mjpg(netcam, &url); } else { - motion_log(LOG_ERR, 0, "%s: Invalid netcam service '%s' - " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam service '%s' - " "must be http, ftp, mjpg or file.", __FUNCTION__, url.service); netcam_url_free(&url); return -1; @@ -2900,8 +2868,8 @@ int netcam_start(struct context *cnt) * these to set the required image buffer(s) in our netcam_struct. */ if ((retval = netcam->get_image(netcam)) != 0) { - motion_log(LOG_ERR, 0, "%s: Failed trying to read first image - retval:%d", - __FUNCTION__, retval); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed trying to " + "read first image - retval:%d", __FUNCTION__, retval); return -1; } @@ -2911,7 +2879,7 @@ int netcam_start(struct context *cnt) * occurs during startup, we will just abandon this attempt. */ if (setjmp(netcam->setjmp_buffer)) { - motion_log(LOG_ERR, 0, "%s: libjpeg decompression failure " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: libjpeg decompression failure " "on first frame - giving up!", __FUNCTION__); return -1; } @@ -2924,14 +2892,14 @@ int netcam_start(struct context *cnt) * multiple of 16. So we check for this. */ if (netcam->width % 16) { - motion_log(LOG_ERR, 0, "%s: netcam image width (%d) is not modulo 16", - __FUNCTION__, netcam->width); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)" + " is not modulo 16", __FUNCTION__, netcam->width); return -3; } if (netcam->height % 16) { - motion_log(LOG_ERR, 0, "%s: netcam image height (%d) is not modulo 16", - __FUNCTION__, netcam->height); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)" + " is not modulo 16", __FUNCTION__, netcam->height); return -3; } @@ -2954,8 +2922,8 @@ int netcam_start(struct context *cnt) if ((retval = pthread_create(&netcam->thread_id, &handler_attribute, &netcam_handler_loop, netcam)) < 0) { - motion_log(LOG_ERR, 1, "%s: Starting camera handler thread [%d]", - __FUNCTION__, netcam->threadnr); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Starting camera" + " handler thread [%d]", __FUNCTION__, netcam->threadnr); return -1; } diff --git a/netcam_ftp.c b/netcam_ftp.c index b91feb4..afe20a6 100644 --- a/netcam_ftp.c +++ b/netcam_ftp.c @@ -167,7 +167,7 @@ static int ftp_get_more(ftp_context_pointer ctxt) /* Read the amount left on the control connection */ if ((len = recv(ctxt->control_file_desc, &ctxt->control_buffer[ctxt->control_buffer_index], size, 0)) < 0) { - motion_log(LOG_ERR, 1, "%s: recv failed in ftp_get_more", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_get_more", __FUNCTION__); close(ctxt->control_file_desc); ctxt->control_file_desc = -1; return -1; @@ -280,7 +280,7 @@ static int ftp_send_user(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_send_user", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_user", __FUNCTION__); return res; } return 0; @@ -306,7 +306,7 @@ static int ftp_send_passwd(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_send_passwd", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_passwd", __FUNCTION__); return res; } @@ -337,7 +337,7 @@ static int ftp_quit(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_quit", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_quit", __FUNCTION__); return res; } @@ -385,13 +385,13 @@ int ftp_connect(netcam_context_ptr netcam) hp = gethostbyname (netcam->connect_host); if (hp == NULL) { - motion_log(LOG_ERR, 1, "%s: gethostbyname failed in ftp_connect", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname failed in ftp_connect", __FUNCTION__); return -1; } if ((unsigned int) hp->h_length > sizeof(((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr)) { - motion_log(LOG_ERR, 1, "%s: gethostbyname address mismatch " + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname address mismatch " "in ftp_connect", __FUNCTION__); return -1; } @@ -404,14 +404,14 @@ int ftp_connect(netcam_context_ptr netcam) addrlen = sizeof (struct sockaddr_in); if (ctxt->control_file_desc < 0) { - motion_log(LOG_ERR, 1, "%s: socket failed", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed", __FUNCTION__); return -1; } /* Do the connect. */ if (connect(ctxt->control_file_desc, (struct sockaddr *) &ctxt->ftp_address, addrlen) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to create a connection", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a connection", __FUNCTION__); close(ctxt->control_file_desc); ctxt->control_file_desc = -1; return -1; @@ -465,7 +465,8 @@ int ftp_connect(netcam_context_ptr netcam) case 2: break; case 3: - motion_log(LOG_ERR, 0, "%s: FTP server asking for ACCT on anonymous", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FTP server asking for ACCT on anonymous", + __FUNCTION__); case 1: case 4: case 5: @@ -513,7 +514,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) ctxt->data_file_desc = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ctxt->data_file_desc < 0) { - motion_log(LOG_ERR, 1, "%s: socket failed", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed", __FUNCTION__); return -1; } @@ -521,7 +522,8 @@ static int ftp_get_connection(ftp_context_pointer ctxt) if (setsockopt(ctxt->data_file_desc, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { - motion_log(LOG_ERR, 1, "%s: setting socket option SO_REUSEADDR", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setting socket option SO_REUSEADDR", + __FUNCTION__); return -1; } @@ -535,7 +537,8 @@ static int ftp_get_connection(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_connection", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection", + __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -565,7 +568,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) if (sscanf(cur, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2], &temp[3], &temp[4], &temp[5]) != 6) { - motion_log(LOG_ERR, 0, "%s: Invalid answer to PASV", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid answer to PASV", __FUNCTION__); if (ctxt->data_file_desc != -1) { close (ctxt->data_file_desc); ctxt->data_file_desc = -1; @@ -582,7 +585,8 @@ static int ftp_get_connection(ftp_context_pointer ctxt) /* Now try to connect to the data port */ if (connect(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to create a data connection", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a data connection", + __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -601,7 +605,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) /* bind to the socket - should give us a unique port */ if (bind(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) { - motion_log(LOG_ERR, 1, "%s: bind failed", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: bind failed", __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -613,7 +617,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) /* set up a 'listen' on the port to get the server's connection */ if (listen(ctxt->data_file_desc, 1) < 0) { - motion_log(LOG_ERR, 1, "%s: listen failed", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: listen failed", __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -633,7 +637,8 @@ static int ftp_get_connection(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_connection", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection", + __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -740,7 +745,8 @@ int ftp_get_socket(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_socket", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket", + __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -765,7 +771,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) if ((acfd = accept(ctxt->data_file_desc, (struct sockaddr *)&data_address, &data_address_length)) < 0) { - motion_log(LOG_ERR, 1, "%s: accept in ftp_get_socket", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: accept in ftp_get_socket", __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -802,7 +808,7 @@ int ftp_send_type(ftp_context_pointer ctxt, char type) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_socket", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket", __FUNCTION__); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -852,7 +858,7 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len) if (len <= 0) { if (len < 0) - motion_log(LOG_ERR, 1, "%s: recv failed in ftp_read", __FUNCTION__); + motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_read", __FUNCTION__); ftp_close_connection(ctxt); } diff --git a/netcam_jpeg.c b/netcam_jpeg.c index 21a97ca..678f8e8 100644 --- a/netcam_jpeg.c +++ b/netcam_jpeg.c @@ -81,8 +81,8 @@ 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) - motion_log(LOG_INFO, 0, "%s: **fake EOI inserted**", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: **fake EOI inserted**", + __FUNCTION__); src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; /* 0xD9 */ nbytes = 2; @@ -176,9 +176,8 @@ static void netcam_error_exit(j_common_ptr cinfo) /* need to "cleanup" the aborted decompression */ jpeg_destroy (cinfo); - if (debug_level >= CAMERA_VERBOSE) - motion_log(LOG_ERR, 0, "%s: netcam->jpeg_error %d", __FUNCTION__, - netcam->jpeg_error); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: netcam->jpeg_error %d", + __FUNCTION__, netcam->jpeg_error); /* jump back to wherever we started */ longjmp(netcam->setjmp_buffer, 1); @@ -219,21 +218,15 @@ static void netcam_output_message(j_common_ptr cinfo) if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && (cinfo->err->msg_code == JWRN_NOT_SEQUENTIAL) && (!netcam->netcam_tolerant_check)) netcam->jpeg_error |= 2; /* Set flag to show problem */ + /* - * We only display and log errors when debug_level - * is non-zero. The reasoning here is that these kinds - * of errors are only produced when the input data is - * wrong, and that indicates a network problem rather - * than a problem with the content. + * Format the message according to library standards. + * Write it out to the motion log. */ - if (debug_level >= CAMERA_VERBOSE) { - /* - * Format the message according to library standards. - * Write it out to the motion log. - */ - (*cinfo->err->format_message)(cinfo, buffer); - motion_log(LOG_ERR, 0, "%s: %s", __FUNCTION__, buffer); - } + (*cinfo->err->format_message)(cinfo, buffer); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: %s", + __FUNCTION__, buffer); + } /** @@ -291,14 +284,14 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) if (retcode) { /* we assume a non-zero reply is ETIMEOUT */ pthread_mutex_unlock(&netcam->mutex); - if (debug_level > CAMERA_WARNINGS) - motion_log(0, 0, "%s: no new pic, no signal rcvd", __FUNCTION__); + motion_log(WRN, TYPE_NETCAM, NO_ERRNO, + "%s: no new pic, no signal rcvd", __FUNCTION__); return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR; } - if (debug_level >= CAMERA_VERBOSE) - motion_log(0, 0, "%s: ***new pic delay successful***", __FUNCTION__); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, + "%s: ***new pic delay successful***", __FUNCTION__); } netcam->imgcnt_last = netcam->imgcnt; @@ -337,8 +330,8 @@ 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) - motion_log(LOG_INFO, 0, "%s: jpeg_error %d", __FUNCTION__, netcam->jpeg_error); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", + __FUNCTION__, netcam->jpeg_error); return netcam->jpeg_error; } @@ -370,7 +363,7 @@ static int netcam_image_conv(netcam_context_ptr netcam, height = cinfo->output_height; if (width && ((width != netcam->width) || (height != netcam->height))) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: JPEG image size %dx%d, JPEG was %dx%d", __FUNCTION__, netcam->width, netcam->height, width, height); jpeg_destroy_decompress(cinfo); @@ -418,9 +411,8 @@ static int netcam_image_conv(netcam_context_ptr netcam, /* rotate as specified */ rotate_map(netcam->cnt, image); - if (debug_level >= CAMERA_VERBOSE) - motion_log(LOG_INFO, 0, "%s: jpeg_error %d", __FUNCTION__, - netcam->jpeg_error); + motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", __FUNCTION__, + netcam->jpeg_error); return netcam->jpeg_error; } @@ -454,15 +446,14 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) * decompress it. netcam_init_jpeg uses * netcam->mutex to do this; */ - if (debug_level > CAMERA_INFO) - motion_log(LOG_INFO, 0, "%s: processing jpeg image - content length " - "%d", __FUNCTION__, netcam->latest->content_length); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing jpeg image" + " - content length %d", __FUNCTION__, netcam->latest->content_length); ret = netcam_init_jpeg(netcam, &cinfo); if (ret != 0) { - if (debug_level > CAMERA_INFO) - motion_log(LOG_ERR, 0, "%s: ret %d", __FUNCTION__, ret); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d", + __FUNCTION__, ret); return ret; } @@ -476,7 +467,7 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) if ((cinfo.output_width != netcam->width) || (cinfo.output_height != netcam->height)) { retval = NETCAM_RESTART_ERROR; - motion_log(LOG_ERR, 0, "%s: Camera width/height mismatch " + motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Camera width/height mismatch " "with JPEG image - expected %dx%d, JPEG %dx%d", " retval %d", __FUNCTION__, netcam->width, netcam->height, cinfo.output_width, cinfo.output_height, retval); @@ -489,9 +480,8 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) if (ret != 0) { retval |= NETCAM_JPEG_CONV_ERROR; - if (debug_level > CAMERA_INFO) - motion_log(LOG_ERR, 0, "%s: ret %d retval %d", __FUNCTION__, - ret, retval); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d retval %d", + __FUNCTION__, ret, retval); } return retval; @@ -523,7 +513,6 @@ void netcam_get_dimensions(netcam_context_ptr netcam) jpeg_destroy_decompress(&cinfo); - if (debug_level > CAMERA_INFO) - motion_log(LOG_ERR, 0, "%s: JFIF_marker %s PRESENT ret %d", - __FUNCTION__, netcam->JFIF_marker ? "IS" : "NOT", ret); + motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: JFIF_marker %s PRESENT ret %d", + __FUNCTION__, netcam->JFIF_marker ? "IS" : "NOT", ret); } diff --git a/picture.c b/picture.c index fba6ad4..bb57b62 100644 --- a/picture.c +++ b/picture.c @@ -519,7 +519,7 @@ int put_picture_memory(struct context *cnt, unsigned char* dest_image, int image return put_jpeg_grey_memory(dest_image, image_size, image, cnt->imgs.width, cnt->imgs.height, quality); default: - motion_log(LOG_ERR, 0, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); } return 0; @@ -538,7 +538,7 @@ void put_picture_fd(struct context *cnt, FILE *picture, unsigned char *image, in put_jpeg_grey_file(picture, image, cnt->imgs.width, cnt->imgs.height, quality); break; default: - motion_log(LOG_ERR, 0, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); } } } @@ -552,7 +552,7 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp if (!picture) { /* Report to syslog - suggest solution if the problem is access rights to target dir */ if (errno == EACCES) { - motion_log(LOG_ERR, 1, + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Can't write picture to file %s - check access rights to target directory\n" "Thread is going to finish due to this fatal error", __FUNCTION__, file); @@ -561,7 +561,7 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp return; } else { /* If target dir is temporarily unavailable we may survive */ - motion_log(LOG_ERR, 1, "%s: Can't write picture to file %s", __FUNCTION__, file); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Can't write picture to file %s", __FUNCTION__, file); return; } } @@ -581,12 +581,12 @@ unsigned char *get_pgm(FILE *picture, int width, int height) line[255] = 0; if (!fgets(line, 255, picture)) { - motion_log(LOG_ERR, 1, "%s: Could not read from ppm file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not read from ppm file", __FUNCTION__); return NULL; } if (strncmp(line, "P5", 2)) { - motion_log(LOG_ERR, 1, "%s: This is not a ppm file, starts with '%s'", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: This is not a ppm file, starts with '%s'", __FUNCTION__, line); return NULL; } @@ -599,12 +599,12 @@ unsigned char *get_pgm(FILE *picture, int width, int height) /* check size */ if (sscanf(line, "%d %d", &x, &y) != 2) { - motion_log(LOG_ERR, 1, "%s: Failed reading size in pgm file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading size in pgm file", __FUNCTION__); return NULL; } if (x != width || y != height) { - motion_log(LOG_ERR, 1, "%s: Wrong image size %dx%d should be %dx%d", + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Wrong image size %dx%d should be %dx%d", __FUNCTION__, x, y, width, height); return NULL; } @@ -616,7 +616,7 @@ unsigned char *get_pgm(FILE *picture, int width, int height) return NULL; if (sscanf(line, "%d", &maxval) != 1) { - motion_log(LOG_ERR, 1, "%s: Failed reading maximum value in pgm file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading maximum value in pgm file", __FUNCTION__); return NULL; } @@ -626,7 +626,7 @@ unsigned char *get_pgm(FILE *picture, int width, int height) for (y = 0; y < height; y++) { if ((int)fread(&image[y * width], 1, width, picture) != width) - motion_log(LOG_ERR, 1, "%s: Failed reading image data from pgm file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading image data from pgm file", __FUNCTION__); for (x = 0; x < width; x++) image[y * width + x] = (int)image[y * width + x] * 255 / maxval; @@ -648,12 +648,12 @@ void put_fixed_mask(struct context *cnt, const char *file) if (!picture) { /* Report to syslog - suggest solution if the problem is access rights to target dir */ if (errno == EACCES) { - motion_log(LOG_ERR, 1, + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: can't write mask file %s - check access rights to target directory", __FUNCTION__, file); } else { /* If target dir is temporarily unavailable we may survive */ - motion_log(LOG_ERR, 1, "%s: can't write mask file %s", __FUNCTION__, file); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: can't write mask file %s", __FUNCTION__, file); } return; } @@ -666,13 +666,13 @@ void put_fixed_mask(struct context *cnt, const char *file) /* write pgm image data at once */ if ((int)fwrite(cnt->imgs.out, cnt->conf.width, cnt->conf.height, picture) != cnt->conf.height) { - motion_log(LOG_ERR, 1, "%s: Failed writing default mask as pgm file", __FUNCTION__); + motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed writing default mask as pgm file", __FUNCTION__); return; } myfclose(picture); - motion_log(LOG_ERR, 0, "%s: Creating empty mask %s\nPlease edit this file and " + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Creating empty mask %s\nPlease edit this file and " "re-run motion to enable mask feature", __FUNCTION__, cnt->conf.mask_file); } diff --git a/rotate.c b/rotate.c index 4470498..2f50cfd 100644 --- a/rotate.c +++ b/rotate.c @@ -238,7 +238,7 @@ void rotate_init(struct context *cnt) * we have a value that is safe from changes caused by motion-control. */ if ((cnt->conf.rotate_deg % 90) > 0) { - motion_log(LOG_ERR, 0, "%s: Config option \"rotate\" not a multiple of 90: %d", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Config option \"rotate\" not a multiple of 90: %d", __FUNCTION__, cnt->conf.rotate_deg); cnt->conf.rotate_deg = 0; /* disable rotation */ cnt->rotate_data.degrees = 0; /* force return below */ @@ -291,7 +291,7 @@ void rotate_init(struct context *cnt) break; default: cnt->rotate_data.degrees = 0; - motion_log(LOG_ERR, 0, "%s: Unsupported palette (%d), rotation is disabled", + motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported palette (%d), rotation is disabled", __FUNCTION__, cnt->imgs.type); return; } diff --git a/stream.c b/stream.c index 8de67e9..fe4fc15 100644 --- a/stream.c +++ b/stream.c @@ -54,7 +54,7 @@ static int set_sock_timeout(int sock, int sec) tv.tv_usec = 0; if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*) &tv, sizeof(tv))) { - motion_log(LOG_ERR, 1, "%s: set socket timeout failed", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: set socket timeout failed", __FUNCTION__); return 1; } return 0; @@ -103,8 +103,8 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int nread += readb; if (nread > buflen) { - motion_log(LOG_ERR, 1, "%s: motion-stream End buffer reached waiting " - "for buffer ending", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream End buffer reached" + " waiting for buffer ending", __FUNCTION__); break; } @@ -121,7 +121,7 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int return 0; } - motion_log(LOG_ERR, 1, "%s: motion-stream READ give up!", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream READ give up!", __FUNCTION__); return 0; } @@ -225,7 +225,7 @@ static void* handle_basic_auth(void* param) /* Set socket to non blocking */ if (fcntl(p->sock, F_SETFL, p->sock_flags) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); goto Error; } @@ -442,13 +442,15 @@ static void* handle_md5_digest(void* param) snprintf(server_nonce, SERVER_NONCE_LEN, "%08x%08x", rand1, rand2); if (!p->conf->stream_authentication) { - motion_log(LOG_ERR, 1, "%s: Error no authentication data", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data", + __FUNCTION__); goto InternalError; } h = strstr(p->conf->stream_authentication, ":"); if (!h) { - motion_log(LOG_ERR, 1, "%s: Error no authentication data (no ':' found)", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data (no ':' found)", + __FUNCTION__); goto InternalError; } @@ -456,7 +458,7 @@ static void* handle_md5_digest(void* param) server_pass = (char*)malloc(strlen(h) + 1); if (!server_user || !server_pass) { - motion_log(LOG_ERR, 1, "%s: Error malloc failed", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error malloc failed", __FUNCTION__); goto InternalError; } @@ -469,7 +471,6 @@ static void* handle_md5_digest(void* param) if(!read_http_request(p->sock, buffer, length, server_uri, SERVER_URI_LEN - 1)) goto Invalid_Request; - auth = strstr(buffer, "Authorization: Digest"); if(!auth) goto Error; @@ -580,7 +581,7 @@ static void* handle_md5_digest(void* param) /* Set socket to non blocking */ if (fcntl(p->sock, F_SETFL, p->sock_flags) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); goto Error; } @@ -653,7 +654,8 @@ static void do_client_auth(struct context *cnt, int sc) handle_func = handle_md5_digest; break; default: - motion_log(LOG_ERR, 1, "%s: Error unknown stream authentication method", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error unknown stream authentication method", + __FUNCTION__); goto Error; break; } @@ -666,13 +668,13 @@ static void do_client_auth(struct context *cnt, int sc) /* Set socket to blocking */ if ((flags = fcntl(sc, F_GETFL, 0)) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); goto Error; } handle_param->sock_flags = flags; if (fcntl(sc, F_SETFL, flags & (~O_NONBLOCK)) < 0) { - motion_log(LOG_ERR, 1, "%s: fcntl", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); goto Error; } @@ -680,18 +682,18 @@ static void do_client_auth(struct context *cnt, int sc) goto Error; if (pthread_attr_init(&attr)) { - motion_log(LOG_ERR, 1, "%s: Error pthread_attr_init", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_init", __FUNCTION__); goto Error; } if (pthread_create(&thread_id, &attr, handle_func, handle_param)) { - motion_log(LOG_ERR, 1, "%s: Error pthread_create", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_create", __FUNCTION__); goto Error; } pthread_detach(thread_id); if (pthread_attr_destroy(&attr)) - motion_log(LOG_ERR, 1, "%s: Error pthread_attr_destroy", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_destroy", __FUNCTION__); return; @@ -735,7 +737,7 @@ int http_bindsock(int port, int local, int ipv6_enabled) optval = getaddrinfo(local ? "localhost" : NULL, portnumber, &hints, &res); if (optval != 0) { - motion_log(LOG_ERR, 1, "%s: getaddrinfo() for motion-stream socket failed: %s", + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for motion-stream socket failed: %s", __FUNCTION__, gai_strerror(optval)); if (res != NULL) @@ -757,33 +759,36 @@ int http_bindsock(int port, int local, int ipv6_enabled) /* Reuse Address */ setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)); - motion_log(LOG_INFO, 0, "%s: motion-stream testing : %s addr: %s port: %s", + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-stream testing : %s addr: %s port: %s", __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); if (bind(sl, res->ai_addr, res->ai_addrlen) == 0) { - motion_log(LOG_INFO, 0, "%s: motion-stream Bound : %s addr: %s port: %s", + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-stream Bound : %s addr: %s port: %s", __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); break; } - motion_log(LOG_ERR, 1, "%s: motion-stream bind() failed, retrying", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream bind() failed, retrying", + __FUNCTION__); close(sl); sl = -1; } - motion_log(LOG_ERR, 1, "%s: motion-stream socket failed, retrying", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream socket failed, retrying", + __FUNCTION__); res = res->ai_next; } freeaddrinfo(ressave); if (sl < 0) { - motion_log(LOG_ERR, 1, "%s: motion-stream creating socket/bind ERROR", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream creating socket/bind ERROR", + __FUNCTION__); return -1; } if (listen(sl, DEF_MAXWEBQUEUE) == -1) { - motion_log(LOG_ERR, 1, "%s: motion-stream listen() ERROR", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream listen() ERROR", __FUNCTION__); close(sl); sl = -1; } @@ -810,7 +815,7 @@ static int http_acceptsock(int sl) return sc; } - motion_log(LOG_ERR, 1, "%s: motion-stream accept()", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream accept()", __FUNCTION__); return -1; } @@ -964,7 +969,8 @@ static void stream_add_client(struct stream *list, int sc) new->socket = sc; if ((new->tmpbuffer = stream_tmpbuffer(sizeof(header))) == NULL) { - motion_log(LOG_ERR, 1, "%s: Error creating tmpbuffer in stream_add_client", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer in stream_add_client", + __FUNCTION__); } else { memcpy(new->tmpbuffer->ptr, header, sizeof(header)-1); new->tmpbuffer->size = sizeof(header)-1; @@ -1057,12 +1063,8 @@ void stream_stop(struct context *cnt) struct stream *list; struct stream *next = cnt->stream.next; - if (debug_level >= CAMERA_VERBOSE) - 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" - " & active motion-stream sockets", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: Closing motion-stream listen socket" + " & active motion-stream sockets", __FUNCTION__); close(cnt->stream.socket); cnt->stream.socket = -1; @@ -1080,12 +1082,8 @@ void stream_stop(struct context *cnt) free(list); } - if (debug_level >= CAMERA_VERBOSE) - 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" - " & active motion-stream sockets", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: Closed motion-stream listen socket" + " & active motion-stream sockets", __FUNCTION__); } /* @@ -1209,7 +1207,8 @@ void stream_put(struct context *cnt, unsigned char *image) */ stream_add_write(&cnt->stream, tmpbuffer, cnt->conf.stream_maxrate); } else { - motion_log(LOG_ERR, 1, "%s: Error creating tmpbuffer", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer", + __FUNCTION__); } } diff --git a/track.c b/track.c index 72a51b4..1e6781b 100644 --- a/track.c +++ b/track.c @@ -74,7 +74,7 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, unsigned int ret; ret = stepper_center(cnt, xoff, yoff); if (!ret) { - motion_log(LOG_ERR, 1, "%s: internal error", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error", __FUNCTION__); return 0; } else return ret; @@ -94,7 +94,7 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, else if (cnt->track.type == TRACK_TYPE_GENERIC) return 10; // FIX ME. I chose to return something reasonable. - motion_log(LOG_ERR, 1, "%s: internal error, %hu is not a known track-type", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", __FUNCTION__, cnt->track.type); return 0; @@ -125,7 +125,7 @@ unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct else if (cnt->track.type == TRACK_TYPE_GENERIC) return cnt->track.move_wait; // FIX ME. I chose to return something reasonable. - motion_log(LOG_ERR, 1, "%s: internal error, %hu is not a known track-type", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", __FUNCTION__, cnt->track.type); return 0; @@ -150,15 +150,15 @@ static unsigned int stepper_command(struct context *cnt, unsigned int motor, buffer[2] = data; if (write(cnt->track.dev, buffer, 3) != 3) { - motion_log(LOG_ERR, 1, "%s: port %s dev fd %i, motor %hu command %hu data %hu", + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", __FUNCTION__, cnt->track.port, cnt->track.dev, motor, command, data); return 0; } - while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout+1); + while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1); - if (time(NULL) >= timeout+2) { - motion_log(LOG_ERR, 1, "%s: Status byte timeout!", __FUNCTION__); + if (time(NULL) >= timeout + 2) { + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Status byte timeout!", __FUNCTION__); return 0; } @@ -177,10 +177,10 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs struct termios adtio; if (cnt->track.dev < 0) { - motion_log(LOG_INFO, 0, "%s: Try to open serial device %s", __FUNCTION__, cnt->track.port); + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Try to open serial device %s", __FUNCTION__, cnt->track.port); if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to open serial device %s", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", __FUNCTION__, cnt->track.port); return 0; } @@ -195,12 +195,12 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs tcflush (cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to initialize serial device %s", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", __FUNCTION__, cnt->track.port); cnt->track.dev = -1; return 0; } - motion_log(LOG_INFO, 0, "$s: Opened serial device %s and initialize, fd %i", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", __FUNCTION__, cnt->track.port, cnt->track.dev); } @@ -237,16 +237,16 @@ static unsigned int stepper_move(struct context *cnt, 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()", + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: No device %s started yet , trying stepper_center()", __FUNCTION__, cnt->track.port); if (!stepper_center(cnt, 0, 0)) { - motion_log(LOG_ERR, 1, "%s: failed to initialize stepper device on %s , fd [%i].", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed to initialize stepper device on %s , fd [%i].", __FUNCTION__, cnt->track.port, cnt->track.dev); return 0; } - motion_log(LOG_INFO, 0, "%s: succeed , device started %s , fd [%i]", + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed , device started %s , fd [%i]", __FUNCTION__, cnt->track.port, cnt->track.dev); } @@ -299,7 +299,7 @@ static int servo_open(struct context *cnt) struct termios adtio; if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to open serial device %s", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", __FUNCTION__, cnt->track.port); return 0; } @@ -314,13 +314,13 @@ static int servo_open(struct context *cnt) tcflush (cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(LOG_INFO, 0, "%s: Unable to initialize serial device %s", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Unable to initialize serial device %s", __FUNCTION__, cnt->track.port); cnt->track.dev = -1; return 0; } - motion_log(LOG_INFO, 0, "%s: Opened serial device %s and initialize, fd %i", + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", __FUNCTION__, cnt->track.port, cnt->track.dev); return 1; @@ -338,26 +338,23 @@ static unsigned int servo_command(struct context *cnt, unsigned int motor, buffer[2] = data; - if (debug_level >= TRACK_DEBUG) { - motion_log(LOG_DEBUG, 0, "%s: SENDS port %s dev fd %i, motor %hu command %hu data %hu", - __FUNCTION__, cnt->track.port, cnt->track.dev, buffer[0], buffer[1], buffer[2]); - } + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: SENDS port %s dev fd %i, motor %hu command %hu data %hu", + __FUNCTION__, cnt->track.port, cnt->track.dev, buffer[0], buffer[1], buffer[2]); if (write(cnt->track.dev, buffer, 3) != 3) { - motion_log(LOG_INFO, 0, "%s: port %s dev fd %i, motor %hu command %hu data %hu", + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", __FUNCTION__, cnt->track.port, cnt->track.dev, motor, command, data); return 0; } - while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout+1); + while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1); - if (time(NULL) >= timeout+2) { - motion_log(LOG_ERR, 0, "%s: Status byte timeout!", __FUNCTION__); + if (time(NULL) >= timeout + 2) { + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Status byte timeout!", __FUNCTION__); return 0; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Command return %d", __FUNCTION__, buffer[0]); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Command return %d", __FUNCTION__, buffer[0]); return buffer[0]; @@ -390,17 +387,15 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, /* If device is not open yet , open and center */ if (cnt->track.dev < 0) { if (!servo_center(cnt, 0, 0)) { - motion_log(LOG_INFO, 0, "%s: Problem opening servo!", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!", __FUNCTION__); return 0; } } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: cent->x %d, cent->y %d, reversex %d," - "reversey %d manual %d", __FUNCTION__, cent->x , cent->y, - cnt->track.motorx_reverse, cnt->track.motory_reverse, manual); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: cent->x %d, cent->y %d, reversex %d," + "reversey %d manual %d", __FUNCTION__, cent->x , cent->y, + cnt->track.motorx_reverse, cnt->track.motory_reverse, manual); - if (manual) { int offset; @@ -419,7 +414,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, 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)", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); return 0; } @@ -445,12 +440,11 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, 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)", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); return 0; } - /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motory, command, data); @@ -478,8 +472,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: X offset %d", __FUNCTION__, data); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X offset %d", __FUNCTION__, data); data = data * cnt->track.stepsize / imgs->width; @@ -490,7 +483,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, 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)", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); return 0; } @@ -500,11 +493,10 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motorx, command, data); - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: X cent->x %d, cent->y %d, reversex %d," - "reversey %d motorx %d data %d command %d", __FUNCTION__, - cent->x, cent->y, cnt->track.motorx_reverse, - cnt->track.motory_reverse, cnt->track.motorx, data, command); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X cent->x %d, cent->y %d, reversex %d," + "reversey %d motorx %d data %d command %d", __FUNCTION__, + cent->x, cent->y, cnt->track.motorx_reverse, + cnt->track.motory_reverse, cnt->track.motorx, data, command); } /***** y-axis *****/ @@ -527,8 +519,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, data = cent->y - imgs->height / 2; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Y offset %d", __FUNCTION__, data); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y offset %d", __FUNCTION__, data); data = data * cnt->track.stepsize / imgs->height; @@ -539,7 +530,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, 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)", + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); return 0; } @@ -548,11 +539,10 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motory, command, data); - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Y cent->x %d, cent->y %d, reversex %d," - "reversey %d motory %d data %d command %d", __FUNCTION__, - cent->x, cent->y, cnt->track.motorx_reverse, - cnt->track.motory_reverse, cnt->track.motory, command); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y cent->x %d, cent->y %d, reversex %d," + "reversey %d motory %d data %d command %d", __FUNCTION__, + cent->x, cent->y, cnt->track.motorx_reverse, + cnt->track.motory_reverse, cnt->track.motory, command); } } @@ -585,19 +575,17 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset /* If device is not open yet */ if (cnt->track.dev < 0) { if (!servo_open(cnt)) { - motion_log(LOG_ERR, 0, "%s: Problem opening servo!", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!", __FUNCTION__); return 0; } } - - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: X-offset %d, Y-offset %d, x-position %d. y-position %d," - "reversex %d, reversey %d , stepsize %d", __FUNCTION__, x_offset, y_offset, - cnt->track.homex + (x_offset * cnt->track.stepsize), - cnt->track.homey + (y_offset * cnt->track.stepsize), - cnt->track.motorx_reverse, cnt->track.motory_reverse, - cnt->track.stepsize); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X-offset %d, Y-offset %d, x-position %d. y-position %d," + "reversex %d, reversey %d , stepsize %d", __FUNCTION__, x_offset, y_offset, + cnt->track.homex + (x_offset * cnt->track.stepsize), + cnt->track.homey + (y_offset * cnt->track.stepsize), + cnt->track.motorx_reverse, cnt->track.motory_reverse, + cnt->track.stepsize); /* x-axis */ if (cnt->track.motorx_reverse) @@ -645,7 +633,7 @@ static char iomojo_command(struct context *cnt, char *command, int len, unsigned while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 2); if (time(NULL) >= timeout + 2) { - motion_log(LOG_ERR, 1, "%s: Return byte timeout!", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Return byte timeout!", __FUNCTION__); return 0; } } @@ -662,7 +650,7 @@ static void iomojo_setspeed(struct context *cnt, unsigned int speed) command[2] = speed; if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET) - motion_log(LOG_ERR, 1, "%s: Unable to set camera speed", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to set camera speed", __FUNCTION__); } static void iomojo_movehome(struct context *cnt) @@ -682,7 +670,7 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse if (cnt->track.dev < 0) { if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to open serial device %s", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", __FUNCTION__, cnt->track.port); return 0; } @@ -696,7 +684,7 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse adtio.c_cc[VMIN] = 0; /* blocking read until 1 char */ tcflush(cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to initialize serial device %s", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", __FUNCTION__, cnt->track.port); return 0; } @@ -734,7 +722,7 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse iomojo_command(cnt, command, 5, 0); } - motion_log(LOG_INFO, 0, "%s: succeed", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed", __FUNCTION__); return cnt->track.move_wait; } @@ -814,7 +802,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y if (cnt->track.dev == -1) { if (ioctl(dev, VIDIOCPWCMPTRESET, &reset) == -1) { - motion_log(LOG_ERR, 1, "%s: Failed to reset pwc camera to starting position! Reason", + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset pwc camera to starting position! Reason", __FUNCTION__); return 0; } @@ -822,7 +810,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y SLEEP(6, 0); if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) { - motion_log(LOG_ERR, 1, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); + motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); return 0; } @@ -835,7 +823,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y } if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); pma.absolute = 1; @@ -846,11 +834,11 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y pma.tilt = y_angle * 100; if (ioctl(dev, VIDIOCPWCMPTSANGLE, &pma) == -1) { - motion_log(LOG_ERR, 1, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); return 0; } - motion_log(LOG_INFO, 0, "%s: succeed", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed", __FUNCTION__); return cnt->track.move_wait; } @@ -881,7 +869,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, /* If we never checked for the min/max values for pan/tilt we do it now */ if (cnt->track.minmaxfound == 0) { if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) { - motion_log(LOG_ERR, 1, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); return 0; } cnt->track.minmaxfound = 1; @@ -893,23 +881,23 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, /* Get current camera position */ if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); /* * Check current position of camera and see if we need to adjust * values down to what is left to move */ - if (move_x_degrees<0 && (cnt->track.minx - pma.pan) > move_x_degrees) + if (move_x_degrees < 0 && (cnt->track.minx - pma.pan) > move_x_degrees) move_x_degrees = (cnt->track.minx - pma.pan); - if (move_x_degrees>0 && (cnt->track.maxx - pma.pan) < move_x_degrees) + if (move_x_degrees > 0 && (cnt->track.maxx - pma.pan) < move_x_degrees) move_x_degrees = (cnt->track.maxx - pma.pan); - if (move_y_degrees<0 && (cnt->track.miny - pma.tilt) > move_y_degrees) + if (move_y_degrees < 0 && (cnt->track.miny - pma.tilt) > move_y_degrees) move_y_degrees = (cnt->track.miny - pma.tilt); - if (move_y_degrees>0 && (cnt->track.maxy - pma.tilt) < move_y_degrees) + if (move_y_degrees > 0 && (cnt->track.maxy - pma.tilt) < move_y_degrees) move_y_degrees = (cnt->track.maxy - pma.tilt); /* Move camera relative to current position */ @@ -918,7 +906,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, pma.tilt = move_y_degrees; if (ioctl(dev, VIDIOCPWCMPTSANGLE, &pma) == -1) { - motion_log(LOG_ERR, 1, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); return 0; } @@ -957,28 +945,26 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = (unsigned char) reset; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to reset UVC camera to starting position! Reason", + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason", __FUNCTION__); return 0; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Reseting UVC camera to starting position", - __FUNCTION__); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position", + __FUNCTION__); SLEEP(8, 0); /* Get camera range */ struct v4l2_queryctrl queryctrl; - queryctrl.id = V4L2_CID_PAN_RELATIVE; + if (ioctl(dev, VIDIOC_QUERYCTRL, &queryctrl) < 0) { - motion_log(LOG_ERR, 1, "%s: ioctl querycontrol", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl querycontrol", __FUNCTION__); return 0; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Getting camera range", __FUNCTION__); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Getting camera range", __FUNCTION__); /* DWe 30.03.07 The orig request failed : @@ -1006,12 +992,10 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ struct v4l2_control control_s; - if (debug_level >= TRACK_DEBUG) { - motion_log(LOG_DEBUG, 0, "%s: INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", - __FUNCTION__, cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); - motion_log(LOG_DEBUG, 0, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", - __FUNCTION__, x_angle, y_angle); - } + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", + __FUNCTION__, cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", + __FUNCTION__, x_angle, y_angle); if (x_angle <= cnt->track.maxx && x_angle >= cnt->track.minx) move_x_degrees = x_angle - (cnt->track.pan_angle); @@ -1029,9 +1013,8 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ pan.s16.pan = -move_x_degrees * INCPANTILT; pan.s16.tilt = -move_y_degrees * INCPANTILT; - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: For_SET_ABS move_X %d,move_Y %d", - __FUNCTION__, move_x_degrees, move_y_degrees); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: For_SET_ABS move_X %d,move_Y %d", + __FUNCTION__, move_x_degrees, move_y_degrees); /* DWe 30.03.07 Must be broken in diff calls, because * one call for both is not accept via VIDIOC_S_CTRL -> maybe via VIDIOC_S_EXT_CTRLS @@ -1044,7 +1027,7 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = pan.s16.pan; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to move UVC camera!", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); return 0; } } @@ -1059,16 +1042,16 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = pan.s16.tilt; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to move UVC camera!", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); return 0; } } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Found MINMAX = %d", __FUNCTION__, cnt->track.minmaxfound); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + __FUNCTION__, cnt->track.minmaxfound); if (cnt->track.dev != -1) { - motion_log(LOG_DEBUG, 0, "%s: Before_ABS_Y_Angel : x= %d , Y= %d, ", + motion_log(DBG, TYPE_TRACK, NO_ERRNO, "%s: Before_ABS_Y_Angel : x= %d , Y= %d, ", __FUNCTION__, cnt->track.pan_angle, cnt->track.tilt_angle); if (move_x_degrees != -1) { @@ -1079,9 +1062,8 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ cnt->track.tilt_angle += move_y_degrees; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: After_ABS_Y_Angel : x= %d , Y= %d", - __FUNCTION__, cnt->track.pan_angle, cnt->track.tilt_angle); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: After_ABS_Y_Angel : x= %d , Y= %d", + __FUNCTION__, cnt->track.pan_angle, cnt->track.tilt_angle); } return cnt->track.move_wait; @@ -1110,13 +1092,12 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.value = (unsigned char) reset; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to reset UVC camera to starting position! Reason", + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason", __FUNCTION__); return 0; } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Reseting UVC camera to starting position", __FUNCTION__); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position", __FUNCTION__); /* set the "helpvalue" back to null because after reset CAM should be in x=0 and not 70 */ cent->x = 0; @@ -1183,13 +1164,11 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, move_y_degrees = cnt->track.maxy - cnt->track.tilt_angle; } - if (debug_level >= TRACK_DEBUG) { - motion_log(LOG_DEBUG, 0, "For_SET_REL pan_min %d,pan_max %d,tilt_min %d,tilt_max %d", - cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); - motion_log(LOG_DEBUG, 0, "For_SET_REL track_pan_Angel %d, track_tilt_Angel %d", - cnt->track.pan_angle, cnt->track.tilt_angle); - motion_log(LOG_DEBUG, 0, "For_SET_REL move_X %d,move_Y %d", move_x_degrees, move_y_degrees); - } + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL pan_min %d,pan_max %d,tilt_min %d,tilt_max %d", + cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL track_pan_Angel %d, track_tilt_Angel %d", + cnt->track.pan_angle, cnt->track.tilt_angle); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL move_X %d,move_Y %d", move_x_degrees, move_y_degrees); /* * tilt up: - value @@ -1211,12 +1190,11 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.id = V4L2_CID_PAN_RELATIVE; control_s.value = pan.s16.pan; - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, " dev %d, addr= %d, control_S= %d, Wert= %d", - dev, VIDIOC_S_CTRL, &control_s, pan.s16.pan); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, " dev %d, addr= %d, control_S= %d, Wert= %d", + dev, VIDIOC_S_CTRL, &control_s, pan.s16.pan); if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to move UVC camera!", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); return 0; } } @@ -1231,35 +1209,30 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.id = V4L2_CID_TILT_RELATIVE; control_s.value = pan.s16.tilt; - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, " dev %d,addr= %d, control_S= %d, Wert= %d", - dev, VIDIOC_S_CTRL, &control_s, pan.s16.tilt); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, " dev %d,addr= %d, control_S= %d, Wert= %d", + dev, VIDIOC_S_CTRL, &control_s, pan.s16.tilt); if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to move UVC camera!", __FUNCTION__); + motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); return 0; } } - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "%s: Found MINMAX = %d", - __FUNCTION__, cnt->track.minmaxfound); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + __FUNCTION__, cnt->track.minmaxfound); if (cnt->track.minmaxfound == 1) { - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "Before_REL_Y_Angel : x= %d , Y= %d", - cnt->track.pan_angle, cnt->track.tilt_angle); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "Before_REL_Y_Angel : x= %d , Y= %d", + cnt->track.pan_angle, cnt->track.tilt_angle); if (move_x_degrees != 0) cnt->track.pan_angle += -pan.s16.pan / INCPANTILT; - if (move_y_degrees != 0) cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT; - if (debug_level >= TRACK_DEBUG) - motion_log(LOG_DEBUG, 0, "After_REL_Y_Angel : x= %d , Y= %d", - cnt->track.pan_angle, cnt->track.tilt_angle); + motion_log(NTC, TYPE_TRACK, NO_ERRNO, "After_REL_Y_Angel : x= %d , Y= %d", + cnt->track.pan_angle, cnt->track.tilt_angle); } return cnt->track.move_wait; diff --git a/video.c b/video.c index e70064b..d747894 100644 --- a/video.c +++ b/video.c @@ -25,7 +25,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (cnt->conf.contrast && cnt->conf.contrast != viddev->contrast) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); make_change = 1; vid_pic.contrast = cnt->conf.contrast * 256; @@ -36,7 +36,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic)==-1) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); } make_change = 1; @@ -48,7 +48,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); } make_change = 1; @@ -63,10 +63,10 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) int fps; if (ioctl(dev, VIDIOCGWIN, &vw) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl VIDIOCGWIN", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN", __FUNCTION__); } else { fps = vw.flags >> PWC_FPS_SHIFT; - motion_log(LOG_DEBUG, 0, "%s: Get Current framerate %d .. trying %d", + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Get Current framerate %d .. trying %d", __FUNCTION__, fps, cnt->conf.frame_limit); } @@ -74,12 +74,12 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) vw.flags = fps << PWC_FPS_SHIFT; if (ioctl(dev, VIDIOCSWIN, &vw) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl VIDIOCSWIN", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCSWIN", __FUNCTION__); } else if (ioctl(dev, VIDIOCGWIN, &vw) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl VIDIOCGWIN", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN", __FUNCTION__); } else { fps = vw.flags >> PWC_FPS_SHIFT; - motion_log(LOG_DEBUG, 0, "%s: Set new framerate %d", __FUNCTION__, fps); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Set new framerate %d", __FUNCTION__, fps); } viddev->fps = fps; @@ -92,7 +92,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) /* If we already read the VIDIOGPICT - we should not do it again */ if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); } vid_pic.brightness = viddev->brightness * 256; @@ -102,7 +102,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) } else if (cnt->conf.brightness && cnt->conf.brightness != viddev->brightness) { if ((!make_change) && (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); make_change = 1; vid_pic.brightness = cnt->conf.brightness * 256; @@ -111,7 +111,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (make_change) { if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__); } } @@ -141,7 +141,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp void *map; if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCAP)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCAP)", __FUNCTION__); return NULL; } @@ -153,13 +153,13 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp vid_chnl.channel = input; if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCHAN) Input %d", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", __FUNCTION__, input); } else { vid_chnl.channel = input; vid_chnl.norm = norm; if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", __FUNCTION__, input, norm); return NULL; } @@ -170,7 +170,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp memset(&vid_tuner, 0, sizeof(struct video_tuner)); vid_tuner.tuner = tuner_number; if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGTUNER) tuner %d", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner %d", __FUNCTION__, tuner_number); } else { if (vid_tuner.flags & VIDEO_TUNER_LOW) @@ -179,20 +179,20 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp freq = freq * 10 / 625; if (ioctl(dev, VIDIOCSFREQ, &freq) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", __FUNCTION__, freq); return NULL; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set Tuner to %d Frequency set to %ul", - __FUNCTION__, tuner_number, freq); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency set to %ul", + __FUNCTION__, tuner_number, freq); } } if (ioctl (dev, VIDIOCGMBUF, &vid_buf) == -1) { - motion_log(LOG_ERR, 0, "%s: ioctl(VIDIOCGMBUF) - Error device does not support memory map\n", - "V4L capturing using read is deprecated!\nMotion only supports mmap.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: ioctl(VIDIOCGMBUF) - Error device does not support memory map\n", + "V4L capturing using read is deprecated!\nMotion only supports mmap.", + __FUNCTION__); return NULL; } else { map = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0); @@ -208,7 +208,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp } if (MAP_FAILED == map) { - motion_log(LOG_ERR, 1, "%s: MAP_FAILED", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: MAP_FAILED", __FUNCTION__); return NULL; } @@ -219,33 +219,33 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp vid_mmap.height = height; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_DEBUG, 1, "%s: Failed with YUV420P, trying YUV422 palette", + motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV420P, trying YUV422 palette", __FUNCTION__); viddev->v4l_fmt = VIDEO_PALETTE_YUV422; vid_mmap.format = viddev->v4l_fmt; /* Try again... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_DEBUG, 1, "%s: Failed with YUV422, trying YUYV palette", + motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV422, trying YUYV palette", __FUNCTION__); viddev->v4l_fmt = VIDEO_PALETTE_YUYV; vid_mmap.format = viddev->v4l_fmt; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_DEBUG, 1, "%s: Failed with YUYV, trying RGB24 palette", + motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUYV, trying RGB24 palette", __FUNCTION__); viddev->v4l_fmt = VIDEO_PALETTE_RGB24; vid_mmap.format = viddev->v4l_fmt; /* Try again... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_DEBUG, 1, "%s: Failed with RGB24, trying" + motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with RGB24, trying" "GREYSCALE palette", __FUNCTION__); viddev->v4l_fmt = VIDEO_PALETTE_GREY; vid_mmap.format = viddev->v4l_fmt; /* Try one last time... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_ERR, 1, "%s: Failed with all supported palettes " + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with all supported palettes " "- giving up", __FUNCTION__); return NULL; } @@ -258,23 +258,23 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp switch (viddev->v4l_fmt) { case VIDEO_PALETTE_YUV420P: viddev->v4l_bufsize = (width * height * 3) / 2; - motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUV420P palette", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV420P palette", __FUNCTION__); break; case VIDEO_PALETTE_YUV422: viddev->v4l_bufsize = (width * height * 2); - motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUV422 palette", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV422 palette", __FUNCTION__); break; case VIDEO_PALETTE_YUYV: viddev->v4l_bufsize = (width * height * 2); - motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUYV palette", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUYV palette", __FUNCTION__); break; case VIDEO_PALETTE_RGB24: viddev->v4l_bufsize = (width * height * 3); - motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_RGB24 palette", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_RGB24 palette", __FUNCTION__); break; case VIDEO_PALETTE_GREY: viddev->v4l_bufsize = width * height; - motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_GREY palette", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_GREY palette", __FUNCTION__); break; } @@ -330,7 +330,7 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height vid_mmap.frame = viddev->v4l_curbuffer; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(LOG_ERR, 1, "%s: mcapture error in proc %d", __FUNCTION__, getpid()); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mcapture error in proc %d", __FUNCTION__, getpid()); sigprocmask (SIG_UNBLOCK, &old, NULL); return V4L_FATAL_ERROR; } @@ -338,7 +338,7 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height vid_mmap.frame = frame; if (ioctl(dev, VIDIOCSYNC, &vid_mmap.frame) == -1) { - motion_log(LOG_ERR, 1, "%s: sync error in proc %d", __FUNCTION__, getpid()); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: sync error in proc %d", __FUNCTION__, getpid()); sigprocmask (SIG_UNBLOCK, &old, NULL); } @@ -396,7 +396,7 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_tuner.tuner = tuner_number; if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGTUNER) tuner number %d", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner number %d", __FUNCTION__, tuner_number); } else { if (vid_tuner.flags & VIDEO_TUNER_LOW) @@ -405,14 +405,13 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char frequnits = (freq * 10) / 625; if (ioctl(dev, VIDIOCSFREQ, &frequnits) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", __FUNCTION__, frequnits); return; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set Tuner to %d Frequency to %ul", - __FUNCTION__, tuner_number, frequnits); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency to %ul", + __FUNCTION__, tuner_number, frequnits); } } @@ -420,20 +419,19 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_chnl.channel = input; if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCHAN) Input %d", __FUNCTION__, input); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", __FUNCTION__, input); } else { vid_chnl.channel = input; vid_chnl.norm = norm; if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", __FUNCTION__, input, norm); return; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set Input to %d Standard method to %d", - __FUNCTION__, input, norm); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Input to %d Standard method to %d", + __FUNCTION__, input, norm); } v4l_picture_controls(cnt, viddev); diff --git a/video2.c b/video2.c index 91e55be..69540c8 100644 --- a/video2.c +++ b/video2.c @@ -136,8 +136,6 @@ #define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */ #endif - - #define ZC301_V4L2_CID_DAC_MAGN V4L2_CID_PRIVATE_BASE #define ZC301_V4L2_CID_GREEN_BALANCE (V4L2_CID_PRIVATE_BASE+1) @@ -198,11 +196,12 @@ static int xioctl(int fd, int request, void *arg) static int v4l2_get_capability(src_v4l2_t * vid_source) { if (xioctl(vid_source->fd, VIDIOC_QUERYCAP, &vid_source->cap) < 0) { - motion_log(LOG_ERR, 0, "%s: Not a V4L2 device?", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not a V4L2 device?", __FUNCTION__); return -1; } - motion_log(LOG_INFO, 0, "%s: \n------------------------\ncap.driver: \"%s\"\n" + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \n------------------------\n" + "cap.driver: \"%s\"\n" "cap.card: \"%s\"\n" "cap.bus_info: \"%s\"\n" "cap.capabilities=0x%08X\n------------------------", __FUNCTION__, @@ -210,32 +209,33 @@ static int v4l2_get_capability(src_v4l2_t * vid_source) vid_source->cap.capabilities); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) - motion_log(LOG_INFO, 0, "- VIDEO_CAPTURE"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) - motion_log(LOG_INFO, 0, "- VIDEO_OUTPUT"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) - motion_log(LOG_INFO, 0, "- VIDEO_OVERLAY"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OVERLAY"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_CAPTURE) - motion_log(LOG_INFO, 0, "- VBI_CAPTURE"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_OUTPUT) - motion_log(LOG_INFO, 0, "- VBI_OUTPUT"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_RDS_CAPTURE) - motion_log(LOG_INFO, 0, "- RDS_CAPTURE"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- RDS_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_TUNER) - motion_log(LOG_INFO, 0, "- TUNER"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- TUNER"); if (vid_source->cap.capabilities & V4L2_CAP_AUDIO) - motion_log(LOG_INFO, 0, "- AUDIO"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- AUDIO"); if (vid_source->cap.capabilities & V4L2_CAP_READWRITE) - motion_log(LOG_INFO, 0, "- READWRITE"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- READWRITE"); if (vid_source->cap.capabilities & V4L2_CAP_ASYNCIO) - motion_log(LOG_INFO, 0, "- ASYNCIO"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- ASYNCIO"); if (vid_source->cap.capabilities & V4L2_CAP_STREAMING) - motion_log(LOG_INFO, 0, "- STREAMING"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- STREAMING"); if (vid_source->cap.capabilities & V4L2_CAP_TIMEPERFRAME) - motion_log(LOG_INFO, 0, "- TIMEPERFRAME"); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- TIMEPERFRAME"); if (!(vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - motion_log(LOG_ERR, 0, "%s: Device does not support capturing.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Device does not support capturing.", + __FUNCTION__); return -1; } @@ -263,23 +263,22 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ else input.index = in; if (xioctl(vid_source->fd, VIDIOC_ENUMINPUT, &input) == -1) { - motion_log(LOG_ERR, 1, "%s: Unable to query input %d. VIDIOC_ENUMINPUT", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to query input %d. VIDIOC_ENUMINPUT", __FUNCTION__, input.index); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_INFO, 0, "%s: name = \"%s\", type 0x%08X, status %08x", __FUNCTION__, - input.name, input.type, input.status); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: name = \"%s\", type 0x%08X, status %08x", + __FUNCTION__, input.name, input.type, input.status); - if ((input.type & V4L2_INPUT_TYPE_TUNER) && (debug_level >= CAMERA_VIDEO)) - motion_log(LOG_INFO, 0, "- TUNER"); + if (input.type & V4L2_INPUT_TYPE_TUNER) + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "- TUNER"); - if ((input.type & V4L2_INPUT_TYPE_CAMERA) && (debug_level >= CAMERA_VIDEO)) - motion_log(LOG_INFO, 0, "- CAMERA"); + if (input.type & V4L2_INPUT_TYPE_CAMERA) + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "- CAMERA"); if (xioctl(vid_source->fd, VIDIOC_S_INPUT, &input.index) == -1) { - motion_log(LOG_ERR, 1, "%s: Error selecting input %d VIDIOC_S_INPUT", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting input %d VIDIOC_S_INPUT", __FUNCTION__, input.index); return -1; } @@ -288,8 +287,8 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ /* Set video standard usually webcams doesn't support the ioctl or return V4L2_STD_UNKNOWN */ if (xioctl(vid_source->fd, VIDIOC_G_STD, &std_id) == -1) { - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_INFO, 0, "%s: Device doesn't support VIDIOC_G_STD", __FUNCTION__); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Device doesn't support VIDIOC_G_STD", + __FUNCTION__); norm = std_id = 0; // V4L2_STD_UNKNOWN = 0 } @@ -298,8 +297,9 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ standard.index = 0; while (xioctl(vid_source->fd, VIDIOC_ENUMSTD, &standard) == 0) { - if ((standard.id & std_id) && (debug_level >= CAMERA_VIDEO)) - motion_log(LOG_INFO, 0, "%s: - video standard %s", __FUNCTION__, standard.name); + if (standard.id & std_id) + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - video standard %s", + __FUNCTION__, standard.name); standard.index++; } @@ -316,13 +316,12 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ } if (xioctl(vid_source->fd, VIDIOC_S_STD, &std_id) == -1) { - motion_log(LOG_ERR, 1, "%s: Error selecting standard method %d VIDIOC_S_STD", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting standard method %d VIDIOC_S_STD", __FUNCTION__, (int)std_id); } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set standard method %d", __FUNCTION__, (int)std_id); - + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set standard method %d", + __FUNCTION__, (int)std_id); } viddev->norm = conf->norm = norm; @@ -338,12 +337,13 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ tuner.index = input.tuner; if (xioctl(vid_source->fd, VIDIOC_G_TUNER, &tuner) == -1) { - motion_log(LOG_ERR, 1, "%s: tuner %d VIDIOC_G_TUNER", __FUNCTION__, tuner.index); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: tuner %d VIDIOC_G_TUNER", + __FUNCTION__, tuner.index); return 0; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set tuner %d", __FUNCTION__, tuner.index); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set tuner %d", + __FUNCTION__, tuner.index); /* Set the frequency. */ memset(&freq, 0, sizeof(struct v4l2_frequency)); @@ -352,14 +352,15 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ freq.frequency = (freq_ / 1000) * 16; if (xioctl(vid_source->fd, VIDIOC_S_FREQUENCY, &freq) == -1) { - motion_log(LOG_ERR, 1, "%s: freq %ul VIDIOC_S_FREQUENCY", __FUNCTION__, freq.frequency); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: freq %ul VIDIOC_S_FREQUENCY", + __FUNCTION__, freq.frequency); return 0; } viddev->freq = conf->frequency = freq_; - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: Set Frequency to %ul", __FUNCTION__, freq.frequency); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Frequency to %ul", + __FUNCTION__, freq.frequency); } else { viddev->freq = conf->frequency = 0; } @@ -402,23 +403,23 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int fmtd.index = v4l2_pal = 0; fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - motion_log(LOG_INFO, 0, "%s: Supported palettes:", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Supported palettes:", __FUNCTION__); while (xioctl(vid_source->fd, VIDIOC_ENUM_FMT, &fmtd) != -1) { int i; - motion_log(LOG_INFO, 0, "%i: %c%c%c%c (%s)", v4l2_pal, fmtd.pixelformat >> 0, + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%i: %c%c%c%c (%s)", v4l2_pal, fmtd.pixelformat >> 0, fmtd.pixelformat >> 8, fmtd.pixelformat >> 16, fmtd.pixelformat >> 24, fmtd.description); - motion_log(LOG_INFO, 0, "%s: %d - %s (compressed : %d) (%#x)", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: %d - %s (compressed : %d) (%#x)", __FUNCTION__, fmtd.index, fmtd.description, fmtd.flags, fmtd.pixelformat); for (i = 0; supported_formats[i]; i++) if (supported_formats[i] == fmtd.pixelformat) { if (cnt->conf.v4l2_palette == i) { index_format = cnt->conf.v4l2_palette; - motion_log(LOG_INFO, 0, "Selected palette %c%c%c%c", fmtd.pixelformat >> 0, + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "Selected palette %c%c%c%c", fmtd.pixelformat >> 0, fmtd.pixelformat >> 8, fmtd.pixelformat >> 16, fmtd.pixelformat >> 24); i = sizeof(supported_formats)/sizeof(u32); break; @@ -449,14 +450,14 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int if (xioctl(vid_source->fd, VIDIOC_TRY_FMT, &vid_source->dst_fmt) != -1 && vid_source->dst_fmt.fmt.pix.pixelformat == pixformat) { - motion_log(LOG_INFO, 0, "%s: index_format %d Testing palette %c%c%c%c (%dx%d)", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: index_format %d Testing palette %c%c%c%c (%dx%d)", __FUNCTION__, index_format, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height); if (vid_source->dst_fmt.fmt.pix.width != (unsigned int) *width || vid_source->dst_fmt.fmt.pix.height != (unsigned int) *height) { - motion_log(LOG_INFO, 0, "%s: Adjusting resolution from %ix%i to %ix%i.", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Adjusting resolution from %ix%i to %ix%i.", __FUNCTION__, *width, *height, vid_source->dst_fmt.fmt.pix.width, vid_source->dst_fmt.fmt.pix.height); @@ -465,12 +466,12 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int } if (xioctl(vid_source->fd, VIDIOC_S_FMT, &vid_source->dst_fmt) == -1) { - motion_log(LOG_ERR, 1, "%s: Error setting pixel format.\nVIDIOC_S_FMT: ", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error setting pixel format.\nVIDIOC_S_FMT: ", __FUNCTION__); return -1; } - motion_log(LOG_INFO, 0, "%s: Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage " + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage " "%d colorspace %08x", __FUNCTION__, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height, vid_source->dst_fmt.fmt.pix.bytesperline, vid_source->dst_fmt.fmt.pix.sizeimage, vid_source->dst_fmt.fmt.pix.colorspace); @@ -478,13 +479,13 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int return 0; } - motion_log(LOG_ERR, 1, "%s: VIDIOC_TRY_FMT failed for format %c%c%c%c ", __FUNCTION__, - pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_TRY_FMT failed for format %c%c%c%c ", + __FUNCTION__, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24); return -1; } - motion_log(LOG_ERR, 0, "%s: Unable to find a compatible palette format.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find a compatible palette format.", __FUNCTION__); return -1; } @@ -500,7 +501,7 @@ static void v4l2_set_fps(src_v4l2_t * vid_source) { setfpvid_source->parm.capture.timeperframe.denominator = vid_source->fps; if (xioctl(vid_source->fd, VIDIOC_S_PARM, setfps) == -1) - motion_log(LOG_ERR, 1, "%s: v4l2_set_fps VIDIOC_S_PARM", __FUNCTION__); + motion_log(ERR, 1, "%s: v4l2_set_fps VIDIOC_S_PARM", __FUNCTION__); } @@ -525,15 +526,16 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) vid_source->req.memory = V4L2_MEMORY_MMAP; if (xioctl(vid_source->fd, VIDIOC_REQBUFS, &vid_source->req) == -1) { - motion_log(LOG_ERR, 1, "%s: Error requesting buffers %d for memory map. VIDIOC_REQBUFS", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error requesting buffers %d for memory map. VIDIOC_REQBUFS", __FUNCTION__, vid_source->req.count); return -1; } - motion_log(LOG_DEBUG, 0, "%s: mmap information: frames=%d", __FUNCTION__, vid_source->req.count); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: mmap information: frames=%d", + __FUNCTION__, vid_source->req.count); if (vid_source->req.count < MIN_MMAP_BUFFERS) { - motion_log(LOG_ERR, 1, "%s: Insufficient buffer memory %d < MIN_MMAP_BUFFERS.", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory %d < MIN_MMAP_BUFFERS.", __FUNCTION__, vid_source->req.count); return -1; } @@ -541,7 +543,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) vid_source->buffers = calloc(vid_source->req.count, sizeof(video_buff)); if (!vid_source->buffers) { - motion_log(LOG_ERR, 1, "%s: Out of memory.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory.", __FUNCTION__); return -1; } @@ -555,7 +557,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) buf.index = buffer_index; if (xioctl(vid_source->fd, VIDIOC_QUERYBUF, &buf) == -1) { - motion_log(LOG_ERR, 1, "%s: Error querying buffer %i\nVIDIOC_QUERYBUF: ", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error querying buffer %i\nVIDIOC_QUERYBUF: ", __FUNCTION__, buffer_index); free(vid_source->buffers); return -1; @@ -566,13 +568,14 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) MAP_SHARED, vid_source->fd, buf.m.offset); if (vid_source->buffers[buffer_index].ptr == MAP_FAILED) { - motion_log(LOG_ERR, 1, "%s: Error mapping buffer %i mmap", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error mapping buffer %i mmap", __FUNCTION__, buffer_index); free(vid_source->buffers); return -1; } - motion_log(LOG_DEBUG, 0, "%s: %i length=%d", __FUNCTION__, buffer_index, buf.length); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: %i length=%d", + __FUNCTION__, buffer_index, buf.length); } for (buffer_index = 0; buffer_index < vid_source->req.count; buffer_index++) { @@ -583,7 +586,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) vid_source->buf.index = buffer_index; if (xioctl(vid_source->fd, VIDIOC_QBUF, &vid_source->buf) == -1) { - motion_log(LOG_ERR, 1, "%s: VIDIOC_QBUF", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF", __FUNCTION__); return -1; } } @@ -591,7 +594,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (xioctl(vid_source->fd, VIDIOC_STREAMON, &type) == -1) { - motion_log(LOG_ERR, 1, "%s: Error starting stream. VIDIOC_STREAMON", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error starting stream. VIDIOC_STREAMON", __FUNCTION__); return -1; } @@ -622,7 +625,7 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) struct v4l2_queryctrl *ctrl = vid_source->controls = calloc(count, sizeof(struct v4l2_queryctrl)); if (!ctrl) { - motion_log(LOG_ERR, 1, "%s: Insufficient buffer memory.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory.", __FUNCTION__); return -1; } @@ -636,14 +639,14 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) memcpy(ctrl, &queryctrl, sizeof(struct v4l2_queryctrl)); - motion_log(LOG_INFO, 0, "%s: found control 0x%08x, \"%s\", range %d,%d %s", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: found control 0x%08x, \"%s\", range %d,%d %s", __FUNCTION__,ctrl->id, ctrl->name, ctrl->minimum, ctrl->maximum, ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : ""); memset(&control, 0, sizeof (control)); control.id = queried_ctrls[i]; xioctl(vid_source->fd, VIDIOC_G_CTRL, &control); - motion_log(LOG_INFO, 0, "%s: \t\"%s\", default %d, current %d", __FUNCTION__, + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \t\"%s\", default %d, current %d", __FUNCTION__, ctrl->name, ctrl->default_value, control.value); ctrl++; @@ -687,14 +690,14 @@ static int v4l2_set_control(src_v4l2_t * vid_source, u32 cid, int value) break; default: - motion_log(LOG_ERR, 0, "%s: control type not supported yet", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: control type not supported yet", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_INFO, 0, "%s: setting control \"%s\" to %d (ret %d %s) %s", - __FUNCTION__, ctrl->name, value, ret, ret ? strerror(errno) : "", - ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "Control is DISABLED!" : ""); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setting control \"%s\" to %d (ret %d %s) %s", + __FUNCTION__, ctrl->name, value, ret, ret ? strerror(errno) : "", + ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "Control is DISABLED!" : ""); return 0; } @@ -753,7 +756,7 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid /* Allocate memory for the state structure. */ if (!(vid_source = calloc(sizeof(src_v4l2_t), 1))) { - motion_log(LOG_ERR, 1, "%s: Out of memory.", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory.", __FUNCTION__); goto err; } @@ -849,9 +852,8 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char src_v4l2_t *vid_source = (src_v4l2_t *) viddev->v4l2_private; unsigned int counter = 0; - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: set_input_skip_frame switch_time=%ld:%ld", - __FUNCTION__, switchTime.tv_sec, switchTime.tv_usec); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set_input_skip_frame switch_time=%ld:%ld", + __FUNCTION__, switchTime.tv_sec, switchTime.tv_usec); /* Avoid hang using the number of mmap buffers */ while(counter < vid_source->req.count) { @@ -864,10 +866,9 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_source->buf.timestamp.tv_usec > switchTime.tv_usec)) break; - if (debug_level >= CAMERA_VIDEO) - motion_log(LOG_DEBUG, 0, "%s: got frame before switch timestamp=%ld:%ld", - __FUNCTION__, vid_source->buf.timestamp.tv_sec, - vid_source->buf.timestamp.tv_usec); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: got frame before switch timestamp=%ld:%ld", + __FUNCTION__, vid_source->buf.timestamp.tv_sec, + vid_source->buf.timestamp.tv_usec); } } @@ -900,14 +901,12 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, sigaddset(&set, SIGHUP); pthread_sigmask(SIG_BLOCK, &set, &old); - if (debug_level == CAMERA_VIDEO) { - motion_log(LOG_DEBUG, 0, "%s: 1) vid_source->pframe %i", - __FUNCTION__, vid_source->pframe); - } + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 1) vid_source->pframe %i", + __FUNCTION__, vid_source->pframe); if (vid_source->pframe >= 0) { if (xioctl(vid_source->fd, VIDIOC_QBUF, &vid_source->buf) == -1) { - motion_log(LOG_ERR, 1, "%s: VIDIOC_QBUF", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF", __FUNCTION__); pthread_sigmask(SIG_UNBLOCK, &old, NULL); return -1; } @@ -932,15 +931,15 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, vid_source->pframe = 0; vid_source->buf.index = vid_source->pframe; - motion_log(LOG_ERR, 1, "%s: VIDIOC_DQBUF: EIO (vid_source->pframe %d)", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EIO (vid_source->pframe %d)", __FUNCTION__, vid_source->pframe); ret = 1; } else if (errno == EAGAIN) { - motion_log(LOG_INFO, 1, "%s: VIDIOC_DQBUF: EAGAIN (vid_source->pframe %d)", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EAGAIN (vid_source->pframe %d)", __FUNCTION__, vid_source->pframe); ret = 1; } else { - motion_log(LOG_ERR, 1, "%s: VIDIOC_DQBUF", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF", __FUNCTION__); ret = -1; } @@ -948,21 +947,17 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, return ret; } - if (debug_level == CAMERA_VIDEO) { - motion_log(LOG_DEBUG, 0, "%s: 2) vid_source->pframe %i", - __FUNCTION__, vid_source->pframe); - } + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 2) vid_source->pframe %i", + __FUNCTION__, vid_source->pframe); vid_source->pframe = vid_source->buf.index; vid_source->buffers[vid_source->buf.index].used = vid_source->buf.bytesused; vid_source->buffers[vid_source->buf.index].content_length = vid_source->buf.bytesused; - if (debug_level == CAMERA_VIDEO) { - motion_log(LOG_DEBUG, 0, "%s: 3) vid_source->pframe %i vid_source->buf.index %i", - __FUNCTION__, vid_source->pframe, vid_source->buf.index); - motion_log(LOG_DEBUG, 0, "%s: vid_source->buf.bytesused %i", - __FUNCTION__, vid_source->buf.bytesused); - } + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 3) vid_source->pframe %i vid_source->buf.index %i", + __FUNCTION__, vid_source->pframe, vid_source->buf.index); + motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: vid_source->buf.bytesused %i", + __FUNCTION__, vid_source->buf.bytesused); pthread_sigmask(SIG_UNBLOCK, &old, NULL); /*undo the signal blocking */ diff --git a/video_common.c b/video_common.c index 7ddb464..90170b6 100644 --- a/video_common.c +++ b/video_common.c @@ -393,8 +393,8 @@ int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int he ret = decode_jpeg_raw(cap_map, size, 0, 420, width, height, yuv[0], yuv[1], yuv[2]); if (ret == 1) { - if (debug_level >= CAMERA_WARNINGS) - motion_log(LOG_ERR, 0, "%s: Corrupt image ... continue", __FUNCTION__); + motion_log(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Corrupt image ... continue", + __FUNCTION__); ret = 2; } @@ -547,7 +547,7 @@ void vid_close(struct context *cnt) /* Cleanup the netcam part */ if (cnt->netcam) { - motion_log(LOG_DEBUG, 0, "%s: calling netcam_cleanup", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: calling netcam_cleanup", __FUNCTION__); netcam_cleanup(cnt->netcam, 0); cnt->netcam = NULL; return; @@ -569,12 +569,13 @@ void vid_close(struct context *cnt) cnt->video_dev = -1; if (dev == NULL) { - motion_log(LOG_ERR, 0, "%s: Unable to find video device", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device", __FUNCTION__); return; } if (--dev->usage_count == 0) { - motion_log(LOG_INFO, 0, "%s: Closing video device %s", __FUNCTION__, dev->video_device); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", + __FUNCTION__, dev->video_device); #ifdef MOTION_V4L2 if (dev->v4l2) { v4l2_close(dev); @@ -599,7 +600,7 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - motion_log(LOG_INFO, 0, "%s: Still %d users of video device %s, so we don't close it now", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, so we don't close it now", __FUNCTION__, dev->usage_count, dev->video_device); /* * There is still at least one thread using this device @@ -657,13 +658,13 @@ static int vid_v4lx_start(struct context *cnt) * for this first. */ if (conf->width % 16) { - motion_log(LOG_ERR, 0, "%s: config image width (%d) is not modulo 16", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image width (%d) is not modulo 16", __FUNCTION__, conf->width); return -3; } if (conf->height % 16) { - motion_log(LOG_ERR, 0, "%s: config image height (%d) is not modulo 16", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image height (%d) is not modulo 16", __FUNCTION__, conf->height); return -3; } @@ -716,7 +717,7 @@ static int vid_v4lx_start(struct context *cnt) dev = dev->next; } - motion_log(1, 0, "%s: Using videodevice %s and input %d", + motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using videodevice %s and input %d", __FUNCTION__, conf->video_device, conf->input); dev = mymalloc(sizeof(struct video_dev)); @@ -727,7 +728,7 @@ static int vid_v4lx_start(struct context *cnt) fd = open(dev->video_device, O_RDWR); if (fd < 0) { - motion_log(LOG_ERR, 1, "%s: Failed to open video device %s", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open video device %s", __FUNCTION__, conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -785,9 +786,9 @@ static int vid_v4lx_start(struct context *cnt) } #endif if (dev->v4l2 == 0) { - motion_log(1, 0, "%s: Using V4L1", __FUNCTION__); + motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L1", __FUNCTION__); } else { - motion_log(1, 0, "%s: Using V4L2", __FUNCTION__); + motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L2", __FUNCTION__); /* Update width & height because could be changed in v4l2_start () */ width = dev->width; height = dev->height; @@ -858,7 +859,7 @@ int vid_start(struct context *cnt) } #ifdef WITHOUT_V4L else - motion_log(LOG_ERR, 0, "%s: You must setup netcam_url", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url", __FUNCTION__); #else else dev = vid_v4lx_start(cnt); diff --git a/video_freebsd.c b/video_freebsd.c index bb88d5d..43293b4 100644 --- a/video_freebsd.c +++ b/video_freebsd.c @@ -17,7 +17,6 @@ #include /* Hack from xawtv 4.x */ - #define VIDEO_NONE 0 #define VIDEO_RGB08 1 /* bt848 dithered */ #define VIDEO_GRAY 2 @@ -68,13 +67,11 @@ volatile sig_atomic_t bktr_frame_waiting; //sigset_t sa_mask; - static void catchsignal(int sig) { bktr_frame_waiting++; } - /* Not tested yet */ static void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, int height) { @@ -111,7 +108,6 @@ static void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, } /* FIXME seems no work with METEOR_GEO_RGB24 , check BPP as well ? */ - static void rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height) { unsigned char *y, *u, *v; @@ -179,12 +175,12 @@ static int set_hue(int viddev, int new_hue) signed char ioctlval = new_hue; if (ioctl(viddev, METEORSHUE, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORSHUE Error setting hue [%d]", __FUNCTION__, new_hue); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSHUE Error setting hue [%d]", + __FUNCTION__, new_hue); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -194,12 +190,12 @@ static int get_hue(int viddev , int *hue) signed char ioctlval; if (ioctl(viddev, METEORGHUE, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORGHUE Error getting hue", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGHUE Error getting hue", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); *hue = ioctlval; return ioctlval; @@ -210,13 +206,12 @@ static int set_saturation(int viddev, int new_saturation) unsigned char ioctlval= new_saturation; if (ioctl(viddev, METEORSCSAT, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORSCSAT Error setting saturation [%d]", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCSAT Error setting saturation [%d]", __FUNCTION__, new_saturation); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -226,12 +221,12 @@ static int get_saturation(int viddev , int *saturation) unsigned char ioctlval; if (ioctl(viddev, METEORGCSAT, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORGCSAT Error getting saturation", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCSAT Error getting saturation", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); *saturation = ioctlval; return ioctlval; @@ -242,13 +237,12 @@ static int set_contrast(int viddev, int new_contrast) unsigned char ioctlval = new_contrast; if (ioctl(viddev, METEORSCONT, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORSCONT Error setting contrast [%d]", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCONT Error setting contrast [%d]", __FUNCTION__, new_contrast); return 0; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -258,12 +252,12 @@ static int get_contrast(int viddev, int *contrast) unsigned char ioctlval; if (ioctl(viddev, METEORGCONT, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORGCONT Error getting contrast", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCONT Error getting contrast", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); *contrast = ioctlval; return ioctlval; @@ -275,13 +269,12 @@ static int set_brightness(int viddev, int new_bright) unsigned char ioctlval = new_bright; if (ioctl(viddev, METEORSBRIG, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORSBRIG brightness [%d]", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSBRIG brightness [%d]", __FUNCTION__, new_bright); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); return ioctlval; } @@ -292,12 +285,12 @@ static int get_brightness(int viddev, int *brightness) unsigned char ioctlval; if (ioctl(viddev, METEORGBRIG, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORGBRIG getting brightness", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGBRIG getting brightness", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, ioctlval); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); *brightness = ioctlval; return ioctlval; @@ -311,10 +304,10 @@ static int set_channel(struct video_dev *viddev, int new_channel) ioctlval = new_channel; if (ioctl(viddev->fd_tuner, TVTUNER_SETCHNL, &ioctlval) < 0) { - motion_log(LOG_ERR, 1, "Error channel %d", ioctlval); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "Error channel %d", ioctlval); return -1; } else { - motion_log(LOG_DEBUG, 0, "channel set to %d", ioctlval); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "channel set to %d", ioctlval); } viddev->channel = new_channel; @@ -323,27 +316,27 @@ static int set_channel(struct video_dev *viddev, int new_channel) } */ -/* set frequency to tuner */ - +/** + * set_freq + * Sets frequency to tuner + */ static int set_freq(struct video_dev *viddev, unsigned long freq) { int tuner_fd = viddev->fd_tuner; int old_audio; - motion_log(LOG_DEBUG, 0, "%s: Not implemented", __FUNCTION__); - + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Not implemented", __FUNCTION__); return 0; /* HACK maybe not need it , but seems that is needed to mute before changing frequency */ - if (ioctl(tuner_fd, BT848_GAUDIO, &old_audio) < 0) { - motion_log(LOG_ERR, 1, "%s: BT848_GAUDIO", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_GAUDIO", __FUNCTION__); return -1; } if (ioctl(tuner_fd, TVTUNER_SETFREQ, &freq) < 0) { - motion_log(LOG_ERR, 1, "%s: Tuning (TVTUNER_SETFREQ) failed , freq [%lu]", - __FUNCTION__, freq); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Tuning (TVTUNER_SETFREQ) failed, ", + "freq [%lu]", __FUNCTION__, freq); return -1; } @@ -351,7 +344,8 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) if (old_audio) { old_audio = AUDIO_MUTE; if (ioctl(tuner_fd , BT848_SAUDIO, &old_audio) < 0) { - motion_log(LOG_ERR, 1, "%s: BT848_SAUDIO %i", __FUNCTION__, old_audio); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_SAUDIO %i", __FUNCTION__, + old_audio); return -1; } } @@ -359,15 +353,15 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) return 0; } -/* - set the input to capture images , could be tuner (METEOR_INPUT_DEV1) - or any of others input : - RCA/COMPOSITE1 (METEOR_INPUT_DEV0) - COMPOSITE2/S-VIDEO (METEOR_INPUT_DEV2) - S-VIDEO (METEOR_INPUT_DEV3) - VBI ?! (METEOR_INPUT_DEV_SVIDEO) -*/ - +/** + * set_input + * Sets the input to capture images , could be tuner (METEOR_INPUT_DEV1) + * or any of others input : + * RCA/COMPOSITE1 (METEOR_INPUT_DEV0) + * COMPOSITE2/S-VIDEO (METEOR_INPUT_DEV2) + * S-VIDEO (METEOR_INPUT_DEV3) + * VBI ?! (METEOR_INPUT_DEV_SVIDEO) + */ static int set_input(struct video_dev *viddev, unsigned input) { int actport; @@ -376,7 +370,7 @@ static int set_input(struct video_dev *viddev, unsigned input) METEOR_INPUT_DEV_SVIDEO }; if (input >= array_elem(portdata)) { - motion_log(LOG_INFO, 0, "%s: Channel Port %d out of range (0-4)", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Channel Port %d out of range (0-4)", __FUNCTION__, input); return -1; } @@ -384,23 +378,23 @@ static int set_input(struct video_dev *viddev, unsigned input) actport = portdata[ input ]; if (ioctl(viddev->fd_bktr, METEORSINPUT, &actport) < 0) { if (input != IN_DEFAULT) { - motion_log(LOG_INFO, 1, "%s: METEORSINPUT %d invalid - Trying default %d", - __FUNCTION__, input, IN_DEFAULT); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d invalid -" + "Trying default %d", __FUNCTION__, input, IN_DEFAULT); input = IN_DEFAULT; actport = portdata[ input ]; if (ioctl(viddev->fd_bktr, METEORSINPUT, &actport) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORSINPUT %d init", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", __FUNCTION__, input); return -1; } } else { - motion_log(LOG_ERR, 1, "%s: METEORSINPUT %d init", __FUNCTION__, input); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", + __FUNCTION__, input); return -1; } } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d]", __FUNCTION__, input); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, input); return input; } @@ -412,10 +406,8 @@ static int set_geometry(struct video_dev *viddev, int width, int height) geom.columns = width; geom.rows = height; - geom.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; - switch (viddev->norm) { case PAL: h_max = PAL_HEIGHT; @@ -436,28 +428,28 @@ static int set_geometry(struct video_dev *viddev, int width, int height) geom.frames = 1; if (ioctl(viddev->fd_bktr, METEORSETGEO, &geom) < 0) { - motion_log(LOG_ERR, 1, "%s: Couldn't set the geometry", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Couldn't set the geometry", + __FUNCTION__); return -1; } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to [%d/%d] Norm %d", __FUNCTION__, - width, height, viddev->norm); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d/%d] Norm %d", + __FUNCTION__, width, height, viddev->norm); return 0; } -/* - set input format ( PAL, NTSC, SECAM, etc ... ) -*/ - +/** + * set_input_format + * Sets input format ( PAL, NTSC, SECAM, etc ... ) + */ 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; if (newformat >= array_elem(input_format)) { - motion_log(LOG_WARNING, 0, "%s: Input format %d out of range (0-2)", + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Input format %d out of range (0-2)", __FUNCTION__, newformat); return -1; } @@ -465,20 +457,19 @@ static int set_input_format(struct video_dev *viddev, unsigned newformat) format = input_format[newformat]; if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { - motion_log(LOG_ERR, 1, "%s: BT848SFMT, Couldn't set the input format , " + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format, " "try again with default", __FUNCTION__); format = NORM_DEFAULT_NEW; newformat = 3; if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { - motion_log(LOG_ERR, 1, "%s: BT848SFMT, Couldn't set the input format " + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format " "either default", __FUNCTION__); return -1; } } - if (debug_level >= CAMERA_VIDEO) - motion_log(0, 0, "%s: to %d", __FUNCTION__, newformat); + motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to %d", __FUNCTION__, newformat); return newformat; } @@ -495,7 +486,7 @@ statict int setup_pixelformat(int bktr) if (ioctl(bktr, METEORGSUPPIXFMT, &p) < 0) { if (errno == EINVAL) break; - motion_log(LOG_ERR, 1, "METEORGSUPPIXFMT getting pixformat %d", i); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "METEORGSUPPIXFMT getting pixformat %d", i); return -1; } @@ -504,40 +495,40 @@ statict int setup_pixelformat(int bktr) switch (p.type) { case METEOR_PIXTYPE_RGB: - motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "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(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); break; case 63488: // 16 bpp format = p.swap_bytes ? VIDEO_RGB16_LE : VIDEO_RGB16_BE; - motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "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(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "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(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "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(0, 0, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); } } break; case METEOR_PIXTYPE_YUV: format = VIDEO_YUV422P; - motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV"); break; case METEOR_PIXTYPE_YUV_12: format = VIDEO_YUV422P; - motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_12"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV_12"); break; case METEOR_PIXTYPE_YUV_PACKED: format = VIDEO_YUV422P; - motion_log(0, 0, "setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); break; } @@ -545,20 +536,20 @@ statict int setup_pixelformat(int bktr) if (p.type == METEOR_PIXTYPE_RGB && p.Bpp == 3) { // Found a good pixeltype -- set it up if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { - motion_log(LOG_WARNING, 1, "METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3"); + motion_log(WRN, TYPE_VIDEO, SHOW_ERRNO, "METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3"); // Not immediately fatal } - motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_RGB %i", i); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "input format METEOR_PIXTYPE_RGB %i", i); format = i; } if (p.type == METEOR_PIXTYPE_YUV_PACKED) { // Found a good pixeltype -- set it up if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { - motion_log(LOG_WARNING, 1, "METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED"); + motion_log(WRN, TYPE_VIDEO, SHOW_ERRNO, "METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED"); // Not immediately fatal } - motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_YUV_PACKED %i", i); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "input format METEOR_PIXTYPE_YUV_PACKED %i", i); format = i; } @@ -629,44 +620,44 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, /* if we have choose the tuner is needed to setup the frequency */ if ((viddev->tuner_device != NULL) && (input == IN_TV)) { if (!freq) { - motion_log(LOG_ERR, 0, "%s: Not valid Frequency [%lu] for Source input [%i]", - __FUNCTION__, freq, input); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for " + "Source input [%i]", __FUNCTION__, freq, input); return NULL; } else if (set_freq(viddev, freq) == -1) { - motion_log(LOG_ERR, 0, "%s: Frequency [%lu] Source input [%i]", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]", __FUNCTION__, freq, input); return NULL; } } /* FIXME if we set as input tuner , we need to set option for tuner not for bktr */ - if ((dummy = set_input(viddev, input)) == -1) { - motion_log(LOG_ERR, 0, "%s: set input [%d]", __FUNCTION__, input); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", __FUNCTION__, input); return NULL; } viddev->input = dummy; if ((dummy = set_input_format(viddev, norm)) == -1) { - motion_log(LOG_ERR, 0, "%s: set input format [%d]", __FUNCTION__, norm); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]", + __FUNCTION__, norm); return NULL; } viddev->norm = dummy; if (set_geometry(viddev, width, height) == -1) { - motion_log(LOG_ERR, 0, "%s: set geometry [%d]x[%d]", __FUNCTION__, width, height); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]", + __FUNCTION__, width, height); return NULL; } /* if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) { - motion_log(LOG_ERR, 1, "set encoding method BSD_VIDFMT_I420"); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "set encoding method BSD_VIDFMT_I420"); return NULL; } - NEEDED !? FIXME if (setup_pixelformat(viddev) == -1) @@ -674,8 +665,8 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, */ if (freq) { - if (debug_level >= CAMERA_DEBUG) - motion_log(0, 0, "%s: Frequency set (no implemented yet", __FUNCTION__); + motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Frequency set (no implemented yet", + __FUNCTION__); /* TODO missing implementation set_channelset(viddev); @@ -686,12 +677,11 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, } - - /* set capture mode and capture buffers */ - - /* That is the buffer size for capture images , - so is dependent of color space of input format / FIXME */ - + /* + * Set capture mode and capture buffers + * That is the buffer size for capture images , + * so is dependent of color space of input format / FIXME + */ viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char)); viddev->v4l_fmt = VIDEO_PALETTE_YUV420P; @@ -700,7 +690,7 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, dev_bktr, (off_t)0); if (map == MAP_FAILED) { - motion_log(LOG_ERR, 1, "%s: mmap failed", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed", __FUNCTION__); return NULL; } @@ -718,14 +708,12 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, viddev->v4l_curbuffer = 0; /* Clear the buffer */ - if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) { - motion_log(LOG_ERR, 1, "%s: BT848SCBUF", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SCBUF", __FUNCTION__); return NULL; } /* signal handler to know when data is ready to be read() */ - memset(&act, 0, sizeof(act)); sigemptyset(&act.sa_mask); act.sa_handler = catchsignal; @@ -738,15 +726,16 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) { - motion_log(LOG_ERR, 1, "%s: METEORSSIGNAL", __FUNCTION__); - motion_log(LOG_INFO, 0 , "%s: METEORSSIGNAL", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSSIGNAL", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, TYPE_VIDEO, NO_ERRNO, "%s: METEORSSIGNAL", + __FUNCTION__); viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method " + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); - motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method " + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); } } else { @@ -754,25 +743,25 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { - motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method " + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); - motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method " + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); } } } if (viddev->capture_method == METEOR_CAP_CONTINOUS) - motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", __FUNCTION__); else - motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_SINGLE", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_SINGLE", __FUNCTION__); // settle , sleep(1) replaced SLEEP(1, 0); - /* FIXME*/ + /* FIXME */ switch (viddev->v4l_fmt) { case VIDEO_PALETTE_YUV420P: viddev->v4l_bufsize = (width * height * 3) / 2; @@ -788,10 +777,14 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, break; } - motion_log(LOG_INFO, 0, "HUE [%d]", get_hue(dev_bktr, &dummy)); - motion_log(LOG_INFO, 0, "SATURATION [%d]", get_saturation(dev_bktr, &dummy)); - motion_log(LOG_INFO, 0, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy)); - motion_log(LOG_INFO, 0, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy)); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "HUE [%d]", + get_hue(dev_bktr, &dummy)); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "SATURATION [%d]", + get_saturation(dev_bktr, &dummy)); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "BRIGHTNESS [%d]", + get_brightness(dev_bktr, &dummy)); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "CONTRAST [%d]", + get_contrast(dev_bktr, &dummy)); return map; } @@ -820,8 +813,10 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int /* ONLY MMAP method is used to Capture */ - /* Allocate a new mmap buffer */ - /* Block signals during IOCTL */ + /* + * Allocates a new mmap buffer + * Block signals during IOCTL + */ sigemptyset (&set); sigaddset (&set, SIGCHLD); sigaddset (&set, SIGALRM); @@ -842,13 +837,13 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int bktr_frame_waiting = 0; } else if (ioctl(dev_bktr, METEORCAPTUR, &single) < 0) { - motion_log(LOG_ERR, 1, "%s: Error capturing using single method", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error capturing using single method", __FUNCTION__); sigprocmask(SIG_UNBLOCK, &old, NULL); return -1; } - /*undo the signal blocking*/ + /* Undo the signal blocking */ pthread_sigmask(SIG_UNBLOCK, &old, NULL); switch (viddev->v4l_fmt) { @@ -866,12 +861,13 @@ 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 input, unsigned norm, int skip, unsigned long freq) +/** + * v4l_set_input + * Sets 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 input, unsigned norm, int skip, unsigned long freq) { - if (input != viddev->input || norm != viddev->norm || freq != viddev->freq) { int dummy; unsigned long frequnits = freq; @@ -887,7 +883,8 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne viddev->norm = dummy; - if ((viddev->tuner_device != NULL) && (viddev->input == IN_TV) && (frequnits > 0)) { + if ((viddev->tuner_device != NULL) && (viddev->input == IN_TV) && + (frequnits > 0)) { if (set_freq(viddev, freq) == -1) return; } @@ -895,12 +892,10 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne // FIXME /* if (setup_pixelformat(viddev) == -1) { - motion_log(LOG_ERR, 1, "ioctl (VIDIOCSFREQ)"); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "ioctl (VIDIOCSFREQ)"); return } - */ - /* if (set_geometry(viddev, width, height) == -1) return; */ @@ -937,14 +932,12 @@ vid_cleanup - Destroy vid_mutex. */ static pthread_mutex_t vid_mutex; - /* Here we setup the viddevs structure which is used globally in the vid_* * functions. */ static struct video_dev *viddevs = NULL; - -/* +/** * vid_init * * Called from motion.c at the very beginning before setting up the threads. @@ -967,7 +960,6 @@ void vid_cleanup(void) #endif /*WITHOUT_V4L*/ - /** * vid_close * @@ -1005,13 +997,13 @@ void vid_close(struct context *cnt) cnt->video_dev = -1; if (dev == NULL) { - motion_log(LOG_ERR, 0, "%s: Unable to find video device", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device", __FUNCTION__); return; } if (--dev->usage_count == 0) { - motion_log(LOG_INFO, 0, "%s: Closing video device %s", + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", __FUNCTION__, dev->video_device); if (dev->fd_tuner > 0) @@ -1045,11 +1037,12 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - motion_log(LOG_INFO, 0, "%s: Still %d users of video device %s, " + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, " "so we don't close it now", __FUNCTION__, dev->usage_count, dev->video_device); - /* There is still at least one thread using this device - * If we own it, release it + /* + * There is still at least one thread using this device + * If we own it, release it. */ if (dev->owner == cnt->threadnr) { dev->frames = 0; @@ -1061,7 +1054,10 @@ void vid_close(struct context *cnt) } - +/** + * vid_start + * + */ int vid_start(struct context *cnt) { struct config *conf = &cnt->conf; @@ -1076,7 +1072,8 @@ int vid_start(struct context *cnt) } #ifdef WITHOUT_V4L else - motion_log(LOG_ERR, 0, "%s: You must setup netcam_url", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url", + __FUNCTION__); #else else { struct video_dev *dev; @@ -1086,22 +1083,24 @@ int vid_start(struct context *cnt) unsigned long frequency; - motion_log(0, 0, "%s: [%s]", __FUNCTION__, conf->video_device); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: [%s]", + __FUNCTION__, conf->video_device); - /* We use width and height from conf in this function. They will be assigned + /* + * 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 * rotate_data won't be set until in rotate_init. * Motion requires that width and height are multiples of 16 so we check for this */ if (conf->width % 16) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image width (%d) is not modulo 16", __FUNCTION__, conf->width); return -1; } if (conf->height % 16) { - motion_log(LOG_ERR, 0, + motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image height (%d) is not modulo 16", __FUNCTION__, conf->height); return -1; @@ -1116,17 +1115,19 @@ int vid_start(struct context *cnt) pthread_mutex_lock(&vid_mutex); - /* Transfer width and height from conf to imgs. The imgs values are the ones + /* + * Transfer width and height from conf to imgs. The imgs values are the ones * that is used internally in Motion. That way, setting width and height via * http remote control won't screw things up. */ cnt->imgs.width = width; cnt->imgs.height = height; - /* First we walk through the already discovered video devices to see + /* + * First we walk through the already discovered video devices to see * if we have already setup the same device before. If this is the case * the device is a Round Robin device and we set the basic settings - * and return the file descriptor + * and return the file descriptor. */ dev = viddevs; while (dev) { @@ -1136,12 +1137,13 @@ int vid_start(struct context *cnt) cnt->imgs.type = dev->v4l_fmt; if (ioctl(dev->fd_bktr, METEORCAPTUR, &dummy) < 0) { - motion_log(LOG_ERR, 1, "%s Stopping capture", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s Stopping capture", + __FUNCTION__); return -1; } - motion_log(0, 0, "%s Reusing [%s] inputs [%d,%d] Change capture method " - "METEOR_CAP_SINGLE", __FUNCTION__, dev->video_device, + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s Reusing [%s] inputs [%d,%d] Change " + "capture method METEOR_CAP_SINGLE", __FUNCTION__, dev->video_device, dev->input, conf->input); dev->capture_method = METEOR_CAP_SINGLE; @@ -1155,8 +1157,8 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(0, 0, "%s VIDEO_PALETTE_YUV420P setting imgs.size " - "and imgs.motionsize", __FUNCTION__); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s VIDEO_PALETTE_YUV420P setting" + " imgs.size and imgs.motionsize", __FUNCTION__); cnt->imgs.motionsize = width * height; cnt->imgs.size = (width * height * 3) / 2; break; @@ -1175,7 +1177,7 @@ int vid_start(struct context *cnt) fd_bktr = open(conf->video_device, O_RDWR); if (fd_bktr < 0) { - motion_log(LOG_ERR, 1, "%s: open video device %s", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: open video device %s", __FUNCTION__, conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -1187,7 +1189,7 @@ int vid_start(struct context *cnt) if ((conf->tuner_device != NULL) && (frequency > 0) && (input == IN_TV)) { fd_tuner = open(conf->tuner_device, O_RDWR); if (fd_tuner < 0) { - motion_log(LOG_ERR, 1, "%s: open tuner device %s", + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: open tuner device %s", __FUNCTION__, conf->tuner_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -1247,7 +1249,8 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(0, 0, "%s: VIDEO_PALETTE_YUV420P imgs.type", __FUNCTION__); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: VIDEO_PALETTE_YUV420P imgs.type", + __FUNCTION__); cnt->imgs.size = (width * height * 3) / 2; cnt->imgs.motionsize = width * height; break; diff --git a/vloopback_motion.c b/vloopback_motion.c index ac9ba67..ee4c877 100644 --- a/vloopback_motion.c +++ b/vloopback_motion.c @@ -27,15 +27,17 @@ static int v4l_open_vidpipe(void) struct utsname uts; if (uname(&uts) < 0) { - motion_log(LOG_ERR, 1, "%s: Unable to execute uname", __FUNCTION__); - return -1; + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname", + __FUNCTION__); + return -1; } major = strtok(uts.release, "."); minor = strtok(NULL, "."); if ((major == NULL) || (minor == NULL) || (strcmp(major, "2"))) { - motion_log(LOG_ERR, 1, "%s: Unable to decipher OS version", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version", + __FUNCTION__); return -1; } @@ -50,14 +52,15 @@ static int v4l_open_vidpipe(void) vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r"); if (!vloopbacks) { - motion_log(LOG_ERR, 1, "%s: Failed to open '/proc/video/vloopback/vloopbacks'", - __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open " + "'/proc/video/vloopback/vloopbacks'", __FUNCTION__); return -1; } /* Read vloopback version*/ if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - motion_log(LOG_ERR, 1, "%s: Unable to read vloopback version", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version", + __FUNCTION__); return -1; } @@ -66,8 +69,8 @@ static int v4l_open_vidpipe(void) /* Read explanation line */ if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - motion_log(LOG_ERR, 1, "%s: Unable to read vloopback explanation line", - __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback" + " explanation line", __FUNCTION__); return -1; } @@ -85,8 +88,8 @@ static int v4l_open_vidpipe(void) pipe_fd = open(pipepath, O_RDWR); if (pipe_fd >= 0) { - motion_log(0, 0, "%s: \tInput: /dev/%s \tOutput: /dev/%s", - __FUNCTION__, input, output); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s " + "\tOutput: /dev/%s", __FUNCTION__, input, output); break; } } @@ -105,7 +108,8 @@ static int v4l_open_vidpipe(void) int tnum; if ((dir = opendir(prefix)) == NULL) { - motion_log(LOG_ERR, 1, "%s: Failed to open '%s'", __FUNCTION__, prefix); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'", + __FUNCTION__, prefix); return -1; } @@ -145,7 +149,7 @@ static int v4l_open_vidpipe(void) tnum = atoi(minor); if (tnum < low) { - strcpy(buffer, "/dev/"); + mystrcpy(buffer, "/dev/"); strncat(buffer, dirp->d_name, sizeof(buffer) - strlen(buffer)); if ((tfd = open(buffer, O_RDWR)) >= 0) { strncpy(pipepath, buffer, sizeof(pipepath)); @@ -165,7 +169,8 @@ static int v4l_open_vidpipe(void) closedir(dir); if (pipe_fd >= 0) - motion_log(0, 0, "%s: Opened %s as input", __FUNCTION__, pipepath); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + __FUNCTION__, pipepath); } return pipe_fd; @@ -185,28 +190,33 @@ 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(0, 0, "%s: Opened %s as input", __FUNCTION__, dev_name); + motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + __FUNCTION__, dev_name); } if (dev < 0) { - motion_log(LOG_ERR, 1, "%s: Opening %s as input failed", __FUNCTION__, dev_name); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed", + __FUNCTION__, dev_name); return -1; } if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", + __FUNCTION__); return -1; } vid_pic.palette = type; if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)", + __FUNCTION__); return -1; } if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGWIN)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)", + __FUNCTION__); return -1; } @@ -214,7 +224,8 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type) vid_win.width = width; if (ioctl(dev, VIDIOCSWIN, &vid_win) == -1) { - motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSWIN)", __FUNCTION__); + motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)", + __FUNCTION__); return -1; } diff --git a/webhttpd.c b/webhttpd.c index 9c6ff13..aa9af29 100644 --- a/webhttpd.c +++ b/webhttpd.c @@ -249,7 +249,8 @@ static void send_template_ini_client(int client_socket, const char *template) nwrite = write_nonblock(client_socket, ok_response, strlen(ok_response)); nwrite += write_nonblock(client_socket, template, strlen(template)); if (nwrite != (ssize_t)(strlen(ok_response) + strlen(template))) - motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__); + motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", + __FUNCTION__); } /** @@ -260,7 +261,8 @@ static void send_template_ini_client_raw(int client_socket) ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, ok_response_raw, strlen(ok_response_raw)); if (nwrite != (ssize_t)strlen(ok_response_raw)) - motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__); + motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", + __FUNCTION__); } /** @@ -271,7 +273,8 @@ static void send_template(int client_socket, char *res) ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, res, strlen(res)); if (nwrite != (ssize_t)strlen(res)) - motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__); + motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", + __FUNCTION__); } /** @@ -1002,7 +1005,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, /* call restart */ if (thread == 0) { - motion_log(LOG_DEBUG, 0, "%s: httpd restart", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart", + __FUNCTION__); kill(getpid(),SIGHUP); if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); @@ -1016,7 +1020,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, } return 0; // to restart } else { - motion_log(LOG_DEBUG, 0, "%s: httpd restart thread %d", __FUNCTION__, thread); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart thread %d", + __FUNCTION__, thread); if (cnt[thread]->running) { cnt[thread]->makemovie = 1; cnt[thread]->finish = 1; @@ -1047,7 +1052,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, /* call quit */ if (thread == 0) { - motion_log(LOG_DEBUG, 0, "%s: httpd quit", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit", + __FUNCTION__); kill(getpid(),SIGQUIT); if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); @@ -1061,7 +1067,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, } return 0; // to quit } else { - motion_log(LOG_DEBUG, 0, "%s: httpd quit thread %d", __FUNCTION__, thread); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit thread %d", + __FUNCTION__, thread); cnt[thread]->restart = 0; cnt[thread]->makemovie = 1; cnt[thread]->finish = 1; @@ -1302,7 +1309,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, if ((question != '=') || (command[0] == '\0')) { /* no valid syntax */ - motion_log(LOG_WARNING, 0, "%s: httpd debug race 1", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 1", + __FUNCTION__); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1352,7 +1360,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, } } else { /* no valid syntax */ - motion_log(LOG_WARNING, 0, "%s: httpd debug race 2", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 2", + __FUNCTION__); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1363,7 +1372,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, /* first value check for error */ if (!warningkill) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 3", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 3", + __FUNCTION__); /* error value */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); @@ -1515,7 +1525,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, warningkill = sscanf(pointer, "%c%255[a-z]" , &question, command); if ((question != '&') || (command[0] == '\0')) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 4", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 4", + __FUNCTION__); if (strstr(pointer, "&")) { if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); @@ -1539,7 +1550,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer = pointer + 3; length_uri = length_uri - 3; if (pan || !tilt || X || Y) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 5", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 5", + __FUNCTION__); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1555,7 +1567,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, length_uri = length_uri - 4; if (tilt || !pan || X || Y) { /* no valid syntax */ - motion_log(LOG_WARNING, 0, "%s: httpd debug race 6", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 6", + __FUNCTION__); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1569,7 +1582,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer++; length_uri--; if (X || !Y || pan || tilt) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 7", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 7", + __FUNCTION__); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) @@ -1585,7 +1599,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer++; length_uri--; if (Y || !X || pan || tilt) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 8", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 8", + __FUNCTION__); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1597,7 +1612,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, warningkill = sscanf(pointer, "%c%10[-0-9]" , &question, y_value); } else { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 9", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 9", + __FUNCTION__); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1609,7 +1625,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, /* Second value check */ if ((warningkill < 2) && (question != '=')) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 10", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 10", + __FUNCTION__); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1617,7 +1634,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, response_client(client_socket, not_valid_syntax_raw, NULL); return 1; } else if ((question == '=') && (warningkill == 1)) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 11", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 11", + __FUNCTION__); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); else @@ -1642,7 +1660,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, if (length_uri != 0) { - motion_log(LOG_WARNING, 0, "%s: httpd debug race 12", __FUNCTION__); + motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 12", + __FUNCTION__); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); else @@ -1692,7 +1711,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, cent.y = 0; cent.x = atoi(panvalue); // Add the number of frame to skip for motion detection - cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, ¢, &relativecnt->imgs, 1); + cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, + ¢, &relativecnt->imgs, 1); if (cnt[thread]->moved) { /* move tilt */ @@ -1702,7 +1722,8 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, cent.x = 0; cent.y = atoi(tiltvalue); // SLEEP(1,0); - cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, ¢, &relativecnt->imgs, 1); + cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, + ¢, &relativecnt->imgs, 1); if (cnt[thread]->moved) { if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); @@ -2217,7 +2238,8 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) nread = read_nonblock(client_socket, buffer, length); if (nread <= 0) { - motion_log(LOG_ERR, 1, "%s: motion-httpd First Read Error", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd First Read Error", + __FUNCTION__); pthread_mutex_unlock(&httpd_mutex); return 1; } else { @@ -2252,8 +2274,8 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) nread += readb; if (nread > length) { - motion_log(LOG_ERR, 1, "%s: motion-httpd End buffer reached waiting " - "for buffer ending", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd End buffer" + " reached waiting for buffer ending", __FUNCTION__); break; } buffer[nread] = '\0'; @@ -2264,7 +2286,8 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) * problem with the connection, so give up. */ if (nread == -1) { - motion_log(LOG_ERR, 1, "%s: motion-httpd READ give up!", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd READ give up!", + __FUNCTION__); pthread_mutex_unlock(&httpd_mutex); return 1; } @@ -2419,7 +2442,7 @@ void httpd_run(struct context **cnt) /* check != 0 to allow FreeBSD compatibility */ if (val != 0) { - motion_log(LOG_ERR, 1, "%s: getaddrinfo() for httpd socket failed: %s", + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for httpd socket failed: %s", __FUNCTION__, gai_strerror(val)); if (res) freeaddrinfo(res); @@ -2436,7 +2459,7 @@ void httpd_run(struct context **cnt) getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV); - motion_log(LOG_INFO, 0, "%s: motion-httpd testing : %s addr: %s port: %s", + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd testing : %s addr: %s port: %s", __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); if (sd >= 0) { @@ -2445,40 +2468,43 @@ void httpd_run(struct context **cnt) setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int)); if (bind(sd, res->ai_addr, res->ai_addrlen) == 0) { - motion_log(LOG_INFO, 0, "%s: motion-httpd Bound : %s addr: %s port: %s", - __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Bound : %s addr: %s" + " port: %s", __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", + hbuf, sbuf); break; } - motion_log(LOG_ERR, 1, "%s: motion-httpd failed bind() interface %s / port %s, retrying", - __FUNCTION__, hbuf, sbuf); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd failed bind() interface %s" + " / port %s, retrying", __FUNCTION__, hbuf, sbuf); close(sd); sd = -1; } - motion_log(LOG_ERR, 1, "%s: motion-httpd socket failed interface %s / port %s, retrying", - __FUNCTION__, hbuf, sbuf); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd socket failed interface %s" + " / port %s, retrying", __FUNCTION__, hbuf, sbuf); res = res->ai_next; } freeaddrinfo(ressave); if (sd < 0) { - motion_log(LOG_ERR, 1, "%s: motion-httpd ERROR bind() [interface %s port %s]", - __FUNCTION__, hbuf, sbuf); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR bind()" + " [interface %s port %s]", __FUNCTION__, hbuf, sbuf); pthread_mutex_destroy(&httpd_mutex); return; } if (listen(sd,5) == -1) { - motion_log(LOG_ERR, 1, "%s: motion-httpd ERROR listen() [interface %s port %s]", - __FUNCTION__, hbuf, sbuf); + motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR listen()" + " [interface %s port %s]", __FUNCTION__, hbuf, sbuf); close(sd); pthread_mutex_destroy(&httpd_mutex); return; } - motion_log(LOG_DEBUG, 0, "%s: motion-httpd/"VERSION" running, accepting connections", __FUNCTION__); - motion_log(LOG_DEBUG, 0, "%s: motion-httpd: waiting for data on %s port TCP %s", __FUNCTION__, hbuf, sbuf); + motion_log(DBG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd/"VERSION" running," + " accepting connections", __FUNCTION__); + motion_log(DBG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd: waiting for data" + " on %s port TCP %s", __FUNCTION__, hbuf, sbuf); if (cnt[0]->conf.webcontrol_authentication != NULL) { char *userpass = NULL; @@ -2499,13 +2525,15 @@ void httpd_run(struct context **cnt) if (client_socket_fd < 0) { if ((!cnt[0]) || (cnt[0]->finish)) { - motion_log(0, 0, "%s: motion-httpd - Finishing", __FUNCTION__); + motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%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(0, 0, "%s: motion-httpd - Read from client", __FUNCTION__); + motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd - Read from client", + __FUNCTION__); /* Close Connection */ if (client_socket_fd) @@ -2517,7 +2545,7 @@ void httpd_run(struct context **cnt) if (authentication != NULL) free(authentication); close(sd); - motion_log(LOG_DEBUG, 0, "%s: motion-httpd Closing", __FUNCTION__); + motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Closing", __FUNCTION__); pthread_mutex_destroy(&httpd_mutex); } @@ -2529,6 +2557,6 @@ void *motion_web_control(void *arg) { struct context **cnt = arg; httpd_run(cnt); - motion_log(LOG_DEBUG, 0, "%s: motion-httpd thread exit", __FUNCTION__); + motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd thread exit", __FUNCTION__); pthread_exit(NULL); }