From d8063fb1df2bdfacb451ca87ee7015afebeea35d Mon Sep 17 00:00:00 2001 From: Angel Carpintero Date: Sun, 23 May 2010 00:01:05 +0200 Subject: [PATCH] - Change default log level to 6 / NTC - Reviewed log levels to make motion less verbose and move most of them to NTC level. --- conf.c | 206 +++++++++++------------ configure | 18 +-- event.c | 180 ++++++++++----------- ffmpeg.c | 230 +++++++++++++------------- jpegutils.c | 102 ++++++------ jpegutils.h | 16 +- logger.c | 42 ++--- logger.h | 14 +- md5.c | 13 +- md5.h | 9 +- motion-dist.conf.in | 36 ++--- motion.1 | 28 ++-- motion.c | 98 +++++------ netcam.c | 6 +- netcam_ftp.c | 82 +++++----- netcam_ftp.h | 5 +- netcam_jpeg.c | 76 ++++----- picture.c | 142 ++++++++-------- rotate.c | 116 ++++++------- stream.c | 320 ++++++++++++++++++------------------ track.c | 362 ++++++++++++++++++++--------------------- video.c | 26 +-- video2.c | 322 ++++++++++++++++++------------------ video_common.c | 94 +++++------ video_freebsd.c | 387 ++++++++++++++++++++++---------------------- video_freebsd.h | 28 ++-- vloopback_motion.c | 54 +++---- vloopback_motion.h | 2 +- webhttpd.c | 302 +++++++++++++++++----------------- webhttpd.h | 6 +- 30 files changed, 1660 insertions(+), 1662 deletions(-) diff --git a/conf.c b/conf.c index d4a1aa9..2494968 100644 --- a/conf.c +++ b/conf.c @@ -104,7 +104,7 @@ struct config conf_template = { tuner_device: NULL, #endif video_device: VIDEO_DEVICE, - v4l2_palette: DEF_PALETTE, + v4l2_palette: DEF_PALETTE, vidpipe: NULL, filepath: NULL, imagepath: DEF_IMAGEPATH, @@ -127,10 +127,10 @@ struct config conf_template = { database_user: NULL, database_password: NULL, database_port: 0, -#ifdef HAVE_SQLITE3 +#ifdef HAVE_SQLITE3 sqlite3_db: NULL, -#endif -#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || define(HAVE_SQLITE3) */ +#endif +#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || define(HAVE_SQLITE3) */ on_picture_save: NULL, on_motion_detected: NULL, on_area_detected: NULL, @@ -172,8 +172,8 @@ static void usage(void); /* Pointer magic to determine relative addresses of variables to a struct context pointer */ #define CNT_OFFSET(varname) ((long)&((struct context *)NULL)->varname) -#define CONF_OFFSET(varname) ((long)&((struct context *)NULL)->conf.varname) -#define TRACK_OFFSET(varname) ((long)&((struct context *)NULL)->track.varname) +#define CONF_OFFSET(varname) ((long)&((struct context *)NULL)->conf.varname) +#define TRACK_OFFSET(varname) ((long)&((struct context *)NULL)->track.varname) config_param config_params[] = { { @@ -216,19 +216,19 @@ config_param config_params[] = { }, { "log_level", - "# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR)", + "# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 6 / NTC)", 1, CONF_OFFSET(log_level), copy_int, - print_int + print_int }, { "log_type", - "# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)", + "# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)", 1, - CONF_OFFSET(log_type_str), + CONF_OFFSET(log_type_str), copy_string, - print_string + print_string }, { "videodevice", @@ -257,10 +257,10 @@ config_param config_params[] = { "# V4L2_PIX_FMT_SBGGR8 : 2 'BA81'\n" "# V4L2_PIX_FMT_SPCA561 : 3 'S561'\n" "# V4L2_PIX_FMT_SGBRG8 : 4 'GBRG'\n" - "# V4L2_PIX_FMT_SGRBG8 : 5 'GRBG'\n" + "# V4L2_PIX_FMT_SGRBG8 : 5 'GRBG'\n" "# V4L2_PIX_FMT_PAC207 : 6 'P207'\n" "# V4L2_PIX_FMT_PJPG : 7 'PJPG'\n" - "# V4L2_PIX_FMT_MJPEG : 8 'MJPEG'\n" + "# V4L2_PIX_FMT_MJPEG : 8 'MJPEG'\n" "# V4L2_PIX_FMT_JPEG : 9 'JPEG'\n" "# V4L2_PIX_FMT_RGB24 : 10 'RGB3'\n" "# V4L2_PIX_FMT_SPCA501 : 11 'S501'\n" @@ -400,11 +400,11 @@ config_param config_params[] = { { "netcam_tolerant_check", "# Set less strict jpeg checks for network cameras with a poor/buggy firmware.\n" - "# Default: off", + "# Default: off", 0, CONF_OFFSET(netcam_tolerant_check), copy_bool, - print_bool + print_bool }, { "auto_brightness", @@ -531,7 +531,7 @@ config_param config_params[] = { }, { "area_detect", - "# Detect motion in predefined areas (1 - 9). Areas are numbered like that: 1 2 3\n" + "# Detect motion in predefined areas (1 - 9). Areas are numbered like that: 1 2 3\n" "# A script (on_area_detected) is started immediately when motion is 4 5 6\n" "# detected in one of the given areas, but only once during an event. 7 8 9\n" "# One or more areas can be specified with this option. (Default: not defined)", @@ -658,7 +658,7 @@ config_param config_params[] = { print_int }, { - "picture_type", + "picture_type", "# Type of output images\n" "# Valid values: jpeg, ppm (default: jpeg)", 0, @@ -758,9 +758,9 @@ config_param config_params[] = { }, #endif /* HAVE_FFMPEG */ { - "use_extpipe", + "use_extpipe", "\n############################################################\n" - "# External pipe to video encoder\n" + "# External pipe to video encoder\n" "# Replacement for FFMPEG builtin encoder for ffmpeg_output_movies only.\n" "# The options movie_filename and timelapse_filename are also used\n" "# by the ffmpeg feature\n" @@ -1252,7 +1252,7 @@ config_param config_params[] = { "# %f = filename with full path\n" "# %n = number indicating filetype\n" "# Both %f and %n are only defined for on_picture_save,\n" - "# on_movie_start and on_movie_end\n" + "# on_movie_start and on_movie_end\n" "# Quotation marks round string are allowed.\n" "############################################################\n\n" "# Do not sound beeps when detecting motion (default: on)\n" @@ -1401,13 +1401,13 @@ config_param config_params[] = { print_string }, { - "database_dbname", + "database_dbname", "# database to log to (default: not defined)", 0, CONF_OFFSET(database_dbname), copy_string, - print_string - }, + print_string + }, { "database_host", "# The host on which the database is located (default: not defined)", @@ -1462,7 +1462,7 @@ config_param config_params[] = { "# Video Loopback Device (vloopback project)\n" "############################################################\n\n" "# Output images to a video4linux loopback device\n" - "# The value '-' means next available (default: not defined)", + "# The value '-' means next available (default: not defined)", 0, CONF_OFFSET(vidpipe), copy_string, @@ -1494,7 +1494,7 @@ config_param config_params[] = { }; /** - * conf_cmdline + * conf_cmdline * Sets the conf struct options as defined by the Command-line. * Any option already set from a config file are overridden. * @@ -1513,7 +1513,7 @@ static void conf_cmdline(struct context *cnt, int thread) while ((c = getopt(conf->argc, conf->argv, "c:d:hns?p:k:l:")) != EOF) switch (c) { case 'c': - if (thread == -1) + if (thread == -1) strcpy(cnt->conf_filename, optarg); break; case 'n': @@ -1530,15 +1530,15 @@ static void conf_cmdline(struct context *cnt, int thread) case 'k': if (thread == -1) strcpy(cnt->log_type_str, optarg); - break; + break; case 'p': - if (thread == -1) + if (thread == -1) strcpy(cnt->pid_file, optarg); - break; + break; case 'l': - if (thread == -1) - strcpy(cnt->log_file, optarg); - break; + if (thread == -1) + strcpy(cnt->log_file, optarg); + break; case 'h': case '?': default: @@ -1551,7 +1551,7 @@ static void conf_cmdline(struct context *cnt, int thread) /** - * conf_cmdparse + * conf_cmdparse * Sets a config option given by 'cmd' to the value given by 'arg1'. * Based on the name of the option it searches through the struct 'config_params' * for an option where the config_params[i].param_name matches the option. @@ -1567,20 +1567,20 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char if (!cmd) return cnt; - /* + /* * We search through config_params until we find a param_name that matches * our option given by cmd (or reach the end = NULL). */ while (config_params[i].param_name != NULL) { if (!strncasecmp(cmd, config_params[i].param_name , 255 + 50)) { // Why +50? - - /* If config_param is string we don't want to check arg1. */ + + /* If config_param is string we don't want to check arg1. */ if (strcmp(config_type(&config_params[i]), "string")) { if (config_params[i].conf_value && !arg1) return cnt; } - - /* + + /* * We call the function given by the pointer config_params[i].copy * If the option is a bool, copy_bool is called. * If the option is an int, copy_int is called. @@ -1599,14 +1599,14 @@ 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(ALR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"", + MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"", cmd); return cnt; } -/** - * conf_process +/** + * conf_process * Walks through an already open config file line by line * Any line starting with '#' or ';' or empty lines are ignored as a comments. * Any non empty line is process so that the first word is the name of an option 'cnd' @@ -1622,48 +1622,48 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char static struct context **conf_process(struct context **cnt, FILE *fp) { /* Process each line from the config file. */ - + char line[PATH_MAX], *cmd = NULL, *arg1 = NULL; char *beg = NULL, *end = NULL; while (fgets(line, PATH_MAX-1, fp)) { if (!(line[0] == '#' || line[0] == ';' || strlen(line) < 2)) {/* skipcomment */ - + arg1 = NULL; /* Trim white space and any CR or LF at the end of the line. */ end = line + strlen(line) - 1; /* Point to the last non-null character in the string. */ - while (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r') + while (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r') end--; - + *(end+1) = '\0'; - + /* If line is only whitespace we continue to the next line. */ if (strlen(line) == 0) continue; /* Trim leading whitespace from the line and find command. */ beg = line; - while (*beg == ' ' || *beg == '\t') + while (*beg == ' ' || *beg == '\t') beg++; - + cmd = beg; /* Command starts here. */ - while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0') + while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0') beg++; - + *beg = '\0'; /* Command string terminates here. */ /* Trim space between command and argument. */ beg++; if (strlen(beg) > 0) { - while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') + while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') beg++; - - /* + + /* * If argument is in "" we will strip them off * It is important that we can use "" so that we can use * leading spaces in text_left and text_right. @@ -1673,7 +1673,7 @@ static struct context **conf_process(struct context **cnt, FILE *fp) beg[strlen(beg)-1] = '\0'; beg++; } - + arg1 = beg; /* Argument starts here */ } /* Else arg1 stays null pointer */ @@ -1686,8 +1686,8 @@ static struct context **conf_process(struct context **cnt, FILE *fp) } -/** - * conf_print +/** + * conf_print * Is used to write out the config file(s) motion.conf and any thread * config files. The function is called when using http remote control. * @@ -1701,11 +1701,11 @@ void conf_print(struct context **cnt) FILE *conffile; for (thread = 0; cnt[thread]; thread++) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s", cnt[thread]->conf_filename); - + conffile = myfopen(cnt[thread]->conf_filename, "w", 0); - + if (!conffile) continue; @@ -1718,7 +1718,7 @@ void conf_print(struct context **cnt) /* If config parameter has a value (not NULL) print it to the config file. */ if (retval) { fprintf(conffile, "%s\n", config_params[i].param_help); - /* + /* * If the option is a text_* and first char is a space put * quotation marks around to allow leading spaces. */ @@ -1729,11 +1729,11 @@ void conf_print(struct context **cnt) } else { val = NULL; config_params[i].print(cnt, &val, i, thread); - /* + /* * It can either be a thread file parameter or a disabled parameter. * If it is a thread parameter write it out. * Else write the disabled option to the config file but with a - * comment mark in front of the parameter name. + * comment mark in front of the parameter name. */ if (val) { fprintf(conffile, "%s\n", config_params[i].param_help); @@ -1743,7 +1743,7 @@ void conf_print(struct context **cnt) fprintf(conffile, "; thread /usr/local/etc/thread1.conf\n"); free(val); - } else if (thread == 0) { + } else if (thread == 0) { fprintf(conffile, "%s\n", config_params[i].param_help); fprintf(conffile, "; %s value\n\n", config_params[i].param_name); } @@ -1757,7 +1757,7 @@ void conf_print(struct context **cnt) } /** - * conf_load + * 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. @@ -1786,13 +1786,13 @@ struct context **conf_load(struct context **cnt) char **argv = cnt[0]->conf.argv; int argc = cnt[0]->conf.argc; - /* + /* * Copy the template config structure with all the default config values * into cnt[0]->conf */ memcpy(&cnt[0]->conf, &conf_template, sizeof(struct config)); - - /* + + /* * For each member of cnt[0] which is a pointer to a string * if the member points to a string in conf_template and is not NULL. * 1. Reserve (malloc) memory for the string. @@ -1832,7 +1832,7 @@ struct context **conf_load(struct context **cnt) char *path = NULL; if (cnt[0]->conf_filename[0]) - MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.", + MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.", filename); if ((path = get_current_dir_name()) == NULL) { @@ -1854,7 +1854,7 @@ struct context **conf_load(struct context **cnt) fp = fopen(filename, "r"); if (!fp) /* There is no config file.... use defaults. */ - MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s", + MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s", filename); } } @@ -1862,16 +1862,16 @@ 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(ALR, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", filename); cnt = conf_process(cnt, fp); myfclose(fp); } else { - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values"); + MOTION_LOG(CRT, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values"); } - - /* + + /* * For each thread (given by cnt[i]) being not null * cnt is an array of pointers to a context type structure * cnt[0] is the default context structure @@ -1886,7 +1886,7 @@ struct context **conf_load(struct context **cnt) conf_cmdline(cnt[i], i); /* If pid file was passed from Command-line copy to main thread conf struct. */ - if (cnt[0]->pid_file[0]) + if (cnt[0]->pid_file[0]) cnt[0]->conf.pid_file = mystrcpy(cnt[0]->conf.pid_file, cnt[0]->pid_file); /* If log file was passed from Command-line copy to main thread conf struct. */ @@ -1898,14 +1898,14 @@ struct context **conf_load(struct context **cnt) cnt[0]->conf.log_type_str = mystrcpy(cnt[0]->conf.log_type_str, cnt[0]->log_type_str); /* if log level was passed from Command-line copy to main thread conf struct. */ - if (cnt[0]->log_level != -1) + if (cnt[0]->log_level != -1) cnt[0]->conf.log_level = cnt[0]->log_level; return cnt; } -/** - * malloc_strings +/** + * malloc_strings * goes through the members of a context structure. * For each context structure member which is a pointer to a string it does this: * If the member points to a string and is not NULL @@ -1925,7 +1925,7 @@ void malloc_strings(struct context *cnt) /* val is made to point to a pointer to the current string. */ val = (char **)((char *)cnt+config_params[i].conf_value); - /* + /* * If there is a string, malloc() space for it, copy * the string to new space, and point to the new * string. we don't free() because we're copying a @@ -1961,9 +1961,9 @@ void malloc_strings(struct context *cnt) ***********************************************************************/ /** - * copy_bool + * copy_bool * Assigns a config option to a new boolean value. - * The boolean is given as a string in str which is converted to 0 or 1 + * The boolean is given as a string in str which is converted to 0 or 1 * by the function. Values 1, yes and on are converted to 1 ignoring case. * Any other value is converted to 0. * @@ -1991,8 +1991,8 @@ static struct context **copy_bool(struct context **cnt, const char *str, int val return cnt; } -/** - * copy_int +/** + * copy_int * Assigns a config option to a new integer value. * The integer is given as a string in str which is converted to integer * by the function. @@ -2017,7 +2017,7 @@ static struct context **copy_int(struct context **cnt, const char *str, int val_ } /** - * copy_string + * copy_string * Assigns a new string value to a config option. * Strings are handled differently from bool and int. * the char *conf->option that we are working on is free()'d @@ -2037,7 +2037,7 @@ struct context **copy_string(struct context **cnt, const char *str, int val_ptr) while (cnt[++i]) { tmp = (char **)((char *)cnt[i] + val_ptr); - /* + /* * mystrcpy assigns the new string value * including free'ing and reserving new memory for it. */ @@ -2055,7 +2055,7 @@ struct context **copy_string(struct context **cnt, const char *str, int val_ptr) } -/** +/** * mystrcpy * Is used to assign string type fields (e.g. config options) * In a way so that we the memory is malloc'ed to fit the string. @@ -2075,13 +2075,13 @@ struct context **copy_string(struct context **cnt, const char *str, int val_ptr) */ char *mystrcpy(char *to, const char *from) { - /* + /* * Free the memory used by the to string, if such memory exists, * and return a pointer to a freshly malloc()'d string with the * same value as from. */ - if (to != NULL) + if (to != NULL) free(to); return mystrdup(from); @@ -2111,7 +2111,7 @@ char *mystrdup(const char *from) tmp = (char *)mymalloc(stringlength + 1); strncpy(tmp, from, stringlength); - /* + /* * We must ensure the string always has a NULL terminator. * This necessary because strncpy will not append a NULL terminator * if the original string is greater than string length. @@ -2129,7 +2129,7 @@ char *mystrdup(const char *from) * Returns a pointer to string containing value the type of config parameter passed. * * Returns const char *. - */ + */ const char *config_type(config_param *configparam) { if (configparam->copy == copy_string) @@ -2148,7 +2148,7 @@ const char *config_type(config_param *configparam) * Returns a pointer to string containing boolean value 'on' / 'off' or NULL. * * Returns const char *. - */ + */ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, int parm, unsigned int threadnr) { @@ -2165,14 +2165,14 @@ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, } /** - * print_string + * print_string * Returns a pointer to a string containing the value of the config option, * If the thread number is not 0 the string is compared with the value of the same * option in thread 0. * * Returns If the option is not defined NULL is returned. * If the value is the same, NULL is returned which means that - * the option is not written to the thread config file. + * the option is not written to the thread config file. */ static const char *print_string(struct context **cnt, char **str ATTRIBUTE_UNUSED, int parm, @@ -2180,7 +2180,7 @@ static const char *print_string(struct context **cnt, { int val = config_params[parm].conf_value; const char **cptr0, **cptr1; - + /* strcmp does not like NULL so we have to check for this also. */ cptr0 = (const char **)((char *)cnt[0] + val); cptr1 = (const char **)((char *)cnt[threadnr] + val); @@ -2220,7 +2220,7 @@ static const char *print_thread(struct context **cnt, char **str, retval[0] = 0; while (cnt[++i]) { - retval = myrealloc(retval, strlen(retval) + strlen(cnt[i]->conf_filename) + 10, + retval = myrealloc(retval, strlen(retval) + strlen(cnt[i]->conf_filename) + 10, "print_thread"); sprintf(retval + strlen(retval), "thread %s\n", cnt[i]->conf_filename); } @@ -2247,14 +2247,14 @@ static struct context **config_thread(struct context **cnt, const char *str, { int i; FILE *fp; - + if (cnt[0]->threadnr) return cnt; fp = fopen(str, "r"); if (!fp) { - MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found", + MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found", str); return cnt; } @@ -2264,7 +2264,7 @@ static struct context **config_thread(struct context **cnt, const char *str, while (cnt[++i]); - /* + /* * Make space for the threads + the terminating NULL pointer * in the array of pointers to context structures * First thread is 0 so the number of threads is i + 1 @@ -2274,7 +2274,7 @@ static struct context **config_thread(struct context **cnt, const char *str, /* Now malloc space for an additional context structure for thread nr. i */ cnt[i] = mymalloc(sizeof(struct context)); - + /* And make this an exact clone of the context structure for thread 0 */ memcpy(cnt[i], cnt[0], sizeof(struct context)); @@ -2286,16 +2286,16 @@ static struct context **config_thread(struct context **cnt, const char *str, * malloc_strings takes care of this. */ malloc_strings(cnt[i]); - + /* Mark the end if the array of pointers to context structures. */ cnt[i + 1] = NULL; /* Process the thread's config file and notify user on console. */ strcpy(cnt[i]->conf_filename, str); - MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s", str); conf_process(cnt + i, fp); - + /* Finally we close the thread config file. */ myfclose(fp); @@ -2307,7 +2307,7 @@ static struct context **config_thread(struct context **cnt, const char *str, * Prints usage and options allowed from Command-line. * * Returns nothing. - */ + */ static void usage() { printf("motion Version "VERSION", Copyright 2000-2005 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen\n"); @@ -2317,7 +2317,7 @@ 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\tLog level (1-9) (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). default: 4 / ERR.\n"); + printf("-d level\t\tLog level (1-9) (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). default: 6 / NTC.\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"); diff --git a/configure b/configure index 9991244..c9d2abb 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.65 for motion trunkREV513. +# Generated by GNU Autoconf 2.65 for motion trunkREV514. # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -549,8 +549,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='motion' PACKAGE_TARNAME='motion' -PACKAGE_VERSION='trunkREV513' -PACKAGE_STRING='motion trunkREV513' +PACKAGE_VERSION='trunkREV514' +PACKAGE_STRING='motion trunkREV514' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1213,7 +1213,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 trunkREV513 to adapt to many kinds of systems. +\`configure' configures motion trunkREV514 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1274,7 +1274,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of motion trunkREV513:";; + short | recursive ) echo "Configuration of motion trunkREV514:";; esac cat <<\_ACEOF @@ -1415,7 +1415,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -motion configure trunkREV513 +motion configure trunkREV514 generated by GNU Autoconf 2.65 Copyright (C) 2009 Free Software Foundation, Inc. @@ -2012,7 +2012,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 trunkREV513, which was +It was created by motion $as_me trunkREV514, which was generated by GNU Autoconf 2.65. Invocation command line was $ $0 $@ @@ -5817,7 +5817,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 trunkREV513, which was +This file was extended by motion $as_me trunkREV514, which was generated by GNU Autoconf 2.65. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5879,7 +5879,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -motion config.status trunkREV513 +motion config.status trunkREV514 configured by $0, generated by GNU Autoconf 2.65, with options \\"\$ac_cs_config\\" diff --git a/event.c b/event.c index d979f03..2eaa8a8 100644 --- a/event.c +++ b/event.c @@ -11,14 +11,14 @@ #include "ffmpeg.h" /* must be first to avoid 'shadow' warning */ #include "picture.h" /* already includes motion.h */ #include "event.h" -#if (!defined(BSD)) +#if (!defined(BSD)) #include "video.h" #endif /* Various functions (most doing the actual action) */ /** - * exec_command + * exec_command * Execute 'command' with 'arg' as its argument. * if !arg command is started with no arguments * Before we call execl we need to close all the file handles @@ -29,10 +29,10 @@ static void exec_command(struct context *cnt, char *command, char *filename, int { char stamp[PATH_MAX]; mystrftime(cnt, stamp, sizeof(stamp), command, &cnt->current_image->timestamp_tm, filename, filetype); - + if (!fork()) { int i; - + /* Detach from parent */ setsid(); @@ -42,21 +42,21 @@ static void exec_command(struct context *cnt, char *command, char *filename, int */ for (i = getdtablesize(); i > 2; --i) close(i); - + execl("/bin/sh", "sh", "-c", stamp, " &", NULL); /* if above function succeeds the program never reach here */ - MOTION_LOG(ALR, TYPE_EVENTS, SHOW_ERRNO, "%s: Unable to start external command '%s'", + MOTION_LOG(ALR, TYPE_EVENTS, SHOW_ERRNO, "%s: Unable to start external command '%s'", stamp); exit(1); } - MOTION_LOG(DBG, TYPE_EVENTS, NO_ERRNO, "%s: Executing external command '%s'", + MOTION_LOG(DBG, TYPE_EVENTS, NO_ERRNO, "%s: Executing external command '%s'", stamp); } -/* +/* * Event handlers */ @@ -64,7 +64,7 @@ static void event_newfile(struct context *cnt ATTRIBUTE_UNUSED, int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED, char *filename, void *ftype, struct tm *tm ATTRIBUTE_UNUSED) { - MOTION_LOG(EMG, TYPE_EVENTS, NO_ERRNO, "%s: File of type %ld saved to: %s", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: File of type %ld saved to: %s", (unsigned long)ftype, filename); } @@ -79,8 +79,8 @@ static void event_beep(struct context *cnt, int type ATTRIBUTE_UNUSED, printf("\a"); } -/** - * on_picture_save_command +/** + * on_picture_save_command * handles both on_picture_save and on_movie_start * If arg = FTYPE_IMAGE_ANY on_picture_save script is executed * If arg = FTYPE_MPEG_ANY on_movie_start script is executed @@ -91,7 +91,7 @@ static void on_picture_save_command(struct context *cnt, int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED, char *filename, void *arg, struct tm *tm ATTRIBUTE_UNUSED) { - int filetype = (unsigned long)arg; + int filetype = (unsigned long)arg; if ((filetype & FTYPE_IMAGE_ANY) != 0 && cnt->conf.on_picture_save) exec_command(cnt, cnt->conf.on_picture_save, filename, filetype); @@ -118,24 +118,24 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, int sqltype = (unsigned long)arg; /* Only log the file types we want */ - if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0) + if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0) return; - /* + /* * We place the code in a block so we only spend time making space in memory * for the sqlquery and timestr when we actually need it. */ { char sqlquery[PATH_MAX]; - - mystrftime(cnt, sqlquery, sizeof(sqlquery), cnt->conf.sql_query, + + 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(ERR, TYPE_DB, SHOW_ERRNO, "%s: Mysql query failed %s error code %d", mysql_error(cnt->database), error_code); /* Try to reconnect ONCE if fails continue and discard this sql query */ @@ -143,19 +143,19 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, 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, + 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", - cnt->conf.database_dbname, + cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user, mysql_error(cnt->database)); } else { mysql_query(cnt->database, sqlquery); - } - } - } + } + } + } } #endif /* HAVE_MYSQL */ @@ -178,7 +178,7 @@ 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(ERR, TYPE_DB, NO_ERRNO, "%s: SQLite error was %s", + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: SQLite error was %s", errmsg); sqlite3_free(errmsg); } @@ -263,15 +263,15 @@ static void event_image_detect(struct context *cnt, int type ATTRIBUTE_UNUSED, if (cnt->new_img & NEWIMG_ON) { const char *imagepath; - /* + /* * conf.imagepath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.imagepath) imagepath = cnt->conf.imagepath; else imagepath = DEF_IMAGEPATH; - + mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tm, NULL, 0); snprintf(fullfilename, PATH_MAX, "%s/%s.%s", cnt->conf.filepath, filename, imageext(cnt)); @@ -291,15 +291,15 @@ static void event_imagem_detect(struct context *cnt, int type ATTRIBUTE_UNUSED, if (conf->motion_img) { const char *imagepath; - /* + /* * conf.imagepath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.imagepath) imagepath = cnt->conf.imagepath; else imagepath = DEF_IMAGEPATH; - + mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tm, NULL, 0); /* motion images gets same name as normal images plus an appended 'm' */ snprintf(filenamem, PATH_MAX, "%sm", filename); @@ -320,29 +320,29 @@ static void event_image_snapshot(struct context *cnt, int type ATTRIBUTE_UNUSED, char filepath[PATH_MAX]; char linkpath[PATH_MAX]; const char *snappath; - /* + /* * conf.snappath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.snappath) snappath = cnt->conf.snappath; else snappath = DEF_SNAPPATH; - + mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tm, NULL, 0); snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cnt)); snprintf(fullfilename, PATH_MAX, "%s/%s", cnt->conf.filepath, filename); put_picture(cnt, fullfilename, img, FTYPE_IMAGE_SNAPSHOT); - /* + /* * Update symbolic link *after* image has been written so that - * the link always points to a valid file. + * the link always points to a valid file. */ snprintf(linkpath, PATH_MAX, "%s/lastsnap.%s", cnt->conf.filepath, imageext(cnt)); remove(linkpath); if (symlink(filename, linkpath)) { - MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Could not create symbolic link [%s]", + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Could not create symbolic link [%s]", filename); return; } @@ -380,9 +380,9 @@ 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(ERR, TYPE_EVENTS, NO_ERRNO, "%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", fileno(cnt->extpipe), ferror(cnt->extpipe)); - MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", + MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", pclose(cnt->extpipe)); event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); } @@ -397,15 +397,15 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, const char *moviepath; FILE *fd_dummy = NULL; - /* + /* * conf.mpegpath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.moviepath) { moviepath = cnt->conf.moviepath; } else { moviepath = DEF_MOVIEPATH; - MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: moviepath: %s", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: moviepath: %s", moviepath); } @@ -419,26 +419,26 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, if (fd_dummy == NULL) { /* Permission denied */ if (errno == EACCES) { - MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s ..." - "check access rights to target directory", + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s ..." + "check access rights to target directory", cnt->extpipefilename); return ; } else { - MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s", + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s", cnt->extpipefilename); return ; - } + } + + } - } - - myfclose(fd_dummy); + myfclose(fd_dummy); unlink(cnt->extpipefilename); mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.extpipe, currenttime_tm, cnt->extpipefilename, 0); - MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pipe: %s", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pipe: %s", stamp); - MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: cnt->moviefps: %d", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: cnt->moviefps: %d", cnt->movie_fps); event(cnt, EVENT_FILECREATE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); @@ -467,11 +467,11 @@ static void event_extpipe_put(struct context *cnt, int type ATTRIBUTE_UNUSED, if (!fwrite(img, cnt->imgs.size, 1, cnt->extpipe)) MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Error writting in pipe , state error %d", ferror(cnt->extpipe)); - } else { - MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pipe %s not created or closed already ", + } else { + MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pipe %s not created or closed already ", cnt->extpipe); - } - } + } + } } @@ -483,12 +483,12 @@ static void event_new_video(struct context *cnt, int type ATTRIBUTE_UNUSED, cnt->movie_fps = cnt->lastrate; - MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s FPS %d", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s FPS %d", cnt->movie_fps); - if (cnt->movie_fps > 30) + if (cnt->movie_fps > 30) cnt->movie_fps = 30; - else if (cnt->movie_fps < 2) + else if (cnt->movie_fps < 2) cnt->movie_fps = 2; } @@ -511,12 +511,12 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, char stamp[PATH_MAX]; const char *moviepath; - if (!cnt->conf.ffmpeg_output && !cnt->conf.ffmpeg_output_debug) + if (!cnt->conf.ffmpeg_output && !cnt->conf.ffmpeg_output_debug) return; - - /* + + /* * conf.mpegpath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.moviepath) moviepath = cnt->conf.moviepath; @@ -525,9 +525,9 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tm, NULL, 0); - /* - * motion movies get the same name as normal movies plus an appended 'm' - * PATH_MAX - 4 to allow for .mpg to be appended without overflow + /* + * motion movies get the same name as normal movies plus an appended 'm' + * PATH_MAX - 4 to allow for .mpg to be appended without overflow */ snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%sm", cnt->conf.filepath, stamp); snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, stamp); @@ -550,7 +550,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(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]", + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]", cnt->newfilename); cnt->finish = 1; return; @@ -578,7 +578,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(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]", + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]", cnt->motionfilename); cnt->finish = 1; return; @@ -602,20 +602,20 @@ static void event_ffmpeg_timelapse(struct context *cnt, char tmp[PATH_MAX]; const char *timepath; - /* + /* * conf.timepath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail + * it is better to revert to the default than fail */ if (cnt->conf.timepath) timepath = cnt->conf.timepath; else timepath = DEF_TIMEPATH; - + mystrftime(cnt, tmp, sizeof(tmp), timepath, currenttime_tm, NULL, 0); - + /* PATH_MAX - 4 to allow for .mpg to be appended without overflow */ snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, tmp); - + if (cnt->imgs.type == VIDEO_PALETTE_GREY) { convbuf = mymalloc((width * height) / 2); y = img; @@ -628,7 +628,7 @@ static void event_ffmpeg_timelapse(struct context *cnt, u = img + width * height; v = u + (width * height) / 4; } - + if ((cnt->ffmpeg_timelapse = ffmpeg_open((char *)TIMELAPSE_CODEC, cnt->timelapsefilename, y, u, v, cnt->imgs.width, cnt->imgs.height, 24, cnt->conf.ffmpeg_bps, @@ -638,25 +638,25 @@ static void event_ffmpeg_timelapse(struct context *cnt, cnt->finish = 1; return; } - + cnt->ffmpeg_timelapse->udata = convbuf; event(cnt, EVENT_FILECREATE, NULL, cnt->timelapsefilename, (void *)FTYPE_MPEG_TIMELAPSE, NULL); } - + y = img; - + if (cnt->imgs.type == VIDEO_PALETTE_GREY) u = cnt->ffmpeg_timelapse->udata; else u = img + width * height; - + v = u + (width * height) / 4; if (ffmpeg_put_other_image(cnt->ffmpeg_timelapse, y, u, v) == -1) { cnt->finish = 1; cnt->restart = 0; - } - + } + } static void event_ffmpeg_put(struct context *cnt, int type ATTRIBUTE_UNUSED, @@ -668,24 +668,24 @@ static void event_ffmpeg_put(struct context *cnt, int type ATTRIBUTE_UNUSED, int height = cnt->imgs.height; unsigned char *y = img; unsigned char *u, *v; - + if (cnt->imgs.type == VIDEO_PALETTE_GREY) u = cnt->ffmpeg_timelapse->udata; else u = y + (width * height); - + v = u + (width * height) / 4; if (ffmpeg_put_other_image(cnt->ffmpeg_output, y, u, v) == -1) { cnt->finish = 1; cnt->restart = 0; - } + } } - + if (cnt->ffmpeg_output_debug) { if (ffmpeg_put_image(cnt->ffmpeg_output_debug) == -1) { cnt->finish = 1; cnt->restart = 0; - } + } } } @@ -694,7 +694,7 @@ static void event_ffmpeg_closefile(struct context *cnt, char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED, struct tm *tm ATTRIBUTE_UNUSED) { - + if (cnt->ffmpeg_output) { if (cnt->ffmpeg_output->udata) free(cnt->ffmpeg_output->udata); @@ -735,7 +735,7 @@ static void event_ffmpeg_timelapseend(struct context *cnt, #endif /* HAVE_FFMPEG */ -/* +/* * Starting point for all events */ @@ -745,7 +745,7 @@ struct event_handlers { }; struct event_handlers event_handlers[] = { -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) { EVENT_FILECREATE, event_sqlnewfile @@ -798,7 +798,7 @@ struct event_handlers event_handlers[] = { }, { EVENT_IMAGEM, - event_vid_putpipe + event_vid_putpipe }, #endif /* !WITHOUT_V4L && !BSD */ { @@ -841,7 +841,7 @@ struct event_handlers event_handlers[] = { }, { EVENT_FIRSTMOTION, - event_create_extpipe + event_create_extpipe }, { EVENT_IMAGE_DETECTED, @@ -868,7 +868,7 @@ struct event_handlers event_handlers[] = { /** - * event + * event * defined with the following parameters: * - Type as defined in event.h (EVENT_...) * - The global context struct cnt diff --git a/ffmpeg.c b/ffmpeg.c index 5e09eab..d265875 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -5,7 +5,7 @@ * This software is distributed under the GNU Public License version 2 * See also the file 'COPYING'. * - * The contents of this file has been derived from output_example.c + * The contents of this file has been derived from output_example.c * and apiexample.c from the FFmpeg distribution. * */ @@ -17,8 +17,8 @@ #if LIBAVCODEC_BUILD > 4680 /* - * FFmpeg after build 4680 doesn't have support for mpeg1 videos with - * non-standard framerates. Previous builds contained a broken hack + * FFmpeg after build 4680 doesn't have support for mpeg1 videos with + * non-standard framerates. Previous builds contained a broken hack * that padded with B frames to obtain the correct framerate. */ # define FFMPEG_NO_NONSTD_MPEG1 @@ -42,7 +42,7 @@ /* * The API for av_write_frame changed with FFmpeg version 0.4.9pre1. * It now uses an AVPacket struct instead of direct parameters to the - * function. + * function. */ # define FFMPEG_AVWRITEFRAME_NEWAPI #endif /* LIBAVFORMAT_BUILD >= 4616 */ @@ -67,14 +67,14 @@ /* Some forward-declarations. */ int ffmpeg_put_frame(struct ffmpeg *, AVFrame *); void ffmpeg_cleanups(struct ffmpeg *); -AVFrame *ffmpeg_prepare_frame(struct ffmpeg *, unsigned char *, +AVFrame *ffmpeg_prepare_frame(struct ffmpeg *, unsigned char *, unsigned char *, unsigned char *); /* This is the trailer used to end mpeg1 videos. */ static unsigned char mpeg1_trailer[] = {0x00, 0x00, 0x01, 0xb7}; -/** - * file_open_append +/** + * file_open_append * Append version of the file open function used in libavformat when opening * an ordinary file. The original file open function truncates an existing * file, but this version appends to it instead. @@ -92,9 +92,9 @@ static int file_open_append(URLContext *h, const char *filename, int flags) /* Skip past the protocol part of filename. */ colon = strchr(filename, ':'); - if (colon) + if (colon) filename = colon + 1; - + if (flags & URL_RDWR) { mode = "ab+"; @@ -109,12 +109,12 @@ static int file_open_append(URLContext *h, const char *filename, int flags) fh = myfopen(filename, mode, bufsize); if (fh == NULL) return AVERROR(ENOENT); - + h->priv_data = (void *)fh; return 0; } -/* +/* * URLProtocol entry for the append file protocol, which we use for mpeg1 videos * in order to get append behavior with url_fopen. * @@ -132,7 +132,7 @@ URLProtocol mpeg1_file_protocol = { #ifdef HAVE_FFMPEG_NEW -/* file_procotol has been removed from avio.h */ +/* file_procotol has been removed from avio.h */ #ifdef FFMPEG_NEW_INCLUDES #include #else @@ -169,7 +169,7 @@ static int file_open(URLContext *h, const char *filename, int flags) /** * file_read - */ + */ static int file_read(URLContext *h, unsigned char *buf, int size) { FILE *fh = (FILE *)h->priv_data; @@ -212,7 +212,7 @@ URLProtocol file_protocol = { file_write, file_seek, file_close, -#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8) +#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8) NULL, NULL, NULL, @@ -222,8 +222,8 @@ URLProtocol file_protocol = { #endif -/** - * mpeg1_write_trailer +/** + * mpeg1_write_trailer * We set AVOutputFormat->write_trailer to this function for mpeg1. That way, * the mpeg1 video gets a proper trailer when it is closed. * @@ -232,9 +232,9 @@ URLProtocol file_protocol = { */ static int mpeg1_write_trailer(AVFormatContext *s) { -#if LIBAVFORMAT_BUILD >= (52<<16) +#if LIBAVFORMAT_BUILD >= (52<<16) put_buffer(s->pb, mpeg1_trailer, 4); - put_flush_packet(s->pb); + put_flush_packet(s->pb); #else put_buffer(&s->pb, mpeg1_trailer, 4); put_flush_packet(&s->pb); @@ -244,15 +244,15 @@ static int mpeg1_write_trailer(AVFormatContext *s) } /** - * ffmpeg_init - * Initializes for libavformat. + * ffmpeg_init + * Initializes for libavformat. * * Returns - * Function returns nothing. + * Function returns nothing. */ void ffmpeg_init() { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg LIBAVCODEC_BUILD %d" + MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg LIBAVCODEC_BUILD %d" " LIBAVFORMAT_BUILD %d", LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD); av_register_all(); @@ -260,7 +260,7 @@ void ffmpeg_init() av_log_set_callback((void *)ffmpeg_avcodec_log); #endif - /* + /* * Copy the functions to use for the append file protocol from the standard * file protocol. */ @@ -272,13 +272,13 @@ void ffmpeg_init() /* Register the append file protocol. */ #if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8) av_register_protocol(&mpeg1_file_protocol); -#else +#else register_protocol(&mpeg1_file_protocol); -#endif +#endif } -/** - * get_oformat +/** + * get_oformat * Obtains the output format used for the specified codec. For mpeg4 codecs, * the format is avi; for mpeg1 codec, the format is mpeg. The filename has * to be passed, because it gets the appropriate extension appended onto it. @@ -300,22 +300,22 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) if ((strcmp(codec, TIMELAPSE_CODEC) == 0) #ifndef FFMPEG_NO_NONSTD_MPEG1 || (strcmp(codec, "mpeg1") == 0) -#endif +#endif ) { ext = ".mpg"; - /* + /* * We use "mpeg1video" for raw mpeg1 format. Using "mpeg" would * result in a muxed output file, which isn't appropriate here. */ of = guess_format("mpeg1video", NULL, NULL); /* But we want the trailer to be correctly written. */ - if (of) + if (of) of->write_trailer = mpeg1_write_trailer; - + #ifdef FFMPEG_NO_NONSTD_MPEG1 } else if (strcmp(codec, "mpeg1") == 0) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: *** mpeg1 support for normal" + MOTION_LOG(WRN, TYPE_ENCODER, NO_ERRNO, "%s: *** mpeg1 support for normal" " videos has been disabled ***"); return NULL; #endif @@ -327,9 +327,9 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) of = guess_format("avi", NULL, NULL); /* Manually override the codec id. */ - if (of) + if (of) of->video_codec = CODEC_ID_MSMPEG4V2; - + } else if (strcmp(codec, "swf") == 0) { ext = ".swf"; of = guess_format("swf", NULL, NULL); @@ -341,16 +341,16 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) ext = ".avi"; of = guess_format("avi", NULL, NULL); - /* + /* * Use the FFMPEG Lossless Video codec (experimental!). - * Requires strict_std_compliance to be <= -2 + * Requires strict_std_compliance to be <= -2 */ - if (of) + if (of) of->video_codec = CODEC_ID_FFV1; - + } else if (strcmp(codec, "mov") == 0) { ext = ".mov"; - of = guess_format("mov", NULL, NULL); + of = guess_format("mov", NULL, NULL); } else { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg_video_codec option value" " %s is not supported", codec); @@ -358,7 +358,7 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) } if (!of) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not guess format for %s", + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not guess format for %s", codec); return NULL; } @@ -369,14 +369,14 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) return of; } -/** - * ffmpeg_open +/** + * ffmpeg_open * Opens an mpeg file using the new libavformat method. Both mpeg1 * and mpeg4 are supported. However, if the current ffmpeg version doesn't allow * mpeg1 with non-standard framerate, the open will fail. Timelapse is a special * case and is tested separately. * - * Returns + * Returns * A new allocated ffmpeg struct or NULL if any error happens. */ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, @@ -388,8 +388,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, struct ffmpeg *ffmpeg; int is_mpeg1; - /* - * Allocate space for our ffmpeg structure. This structure contains all the + /* + * Allocate space for our ffmpeg structure. This structure contains all the * codec and image information we need to generate movies. * FIXME when motion exits we should close the movie to ensure that * ffmpeg is freed. @@ -398,7 +398,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, memset(ffmpeg, 0, sizeof(struct ffmpeg)); ffmpeg->vbr = vbr; - + /* Store codec name in ffmpeg->codec, with buffer overflow check. */ snprintf(ffmpeg->codec, sizeof(ffmpeg->codec), "%s", ffmpeg_video_codec); @@ -445,7 +445,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, is_mpeg1 = c->codec_id == CODEC_ID_MPEG1VIDEO; if (strcmp(ffmpeg_video_codec, "ffv1") == 0) - c->strict_std_compliance = -2; + c->strict_std_compliance = -2; /* Uncomment to allow non-standard framerates. */ //c->strict_std_compliance = -1; @@ -463,20 +463,20 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, c->frame_rate_base = 1; #endif /* LIBAVCODEC_BUILD >= 4754 */ - MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "%s FPS %d", - rate); + MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, "%s FPS %d", + rate); if (vbr) c->flags |= CODEC_FLAG_QSCALE; /* - * Set codec specific parameters. - * Set intra frame distance in frames depending on codec. + * Set codec specific parameters. + * Set intra frame distance in frames depending on codec. */ c->gop_size = is_mpeg1 ? 10 : 12; - + /* Some formats want stream headers to be separate. */ - if (!strcmp(ffmpeg->oc->oformat->name, "mp4") || + if (!strcmp(ffmpeg->oc->oformat->name, "mp4") || !strcmp(ffmpeg->oc->oformat->name, "mov") || !strcmp(ffmpeg->oc->oformat->name, "3gp")) { c->flags |= CODEC_FLAG_GLOBAL_HEADER; @@ -493,19 +493,19 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* Dump the format settings. This shows how the various streams relate to each other. */ //dump_format(ffmpeg->oc, 0, filename, 1); - /* + /* * Now that all the parameters are set, we can open the video * codec and allocate the necessary encode buffers. */ codec = avcodec_find_encoder(c->codec_id); if (!codec) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } - + /* Set the picture format - need in ffmpeg starting round April-May 2005 */ c->pix_fmt = PIX_FMT_YUV420P; @@ -516,7 +516,7 @@ 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(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_open - could not open codec %s", + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_open - could not open codec %s", ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; @@ -528,10 +528,10 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->video_outbuf = NULL; if (!(ffmpeg->oc->oformat->flags & AVFMT_RAWPICTURE)) { - /* - * Allocate output buffer - * XXX: API change will be done - * ffmpeg->video_outbuf_size = 200000 + /* + * Allocate output buffer + * XXX: API change will be done + * ffmpeg->video_outbuf_size = 200000 */ ffmpeg->video_outbuf_size = ffmpeg->c->width * 512; ffmpeg->video_outbuf = mymalloc(ffmpeg->video_outbuf_size); @@ -548,9 +548,9 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, } /* Set variable bitrate if requested. */ - if (ffmpeg->vbr) + if (ffmpeg->vbr) ffmpeg->picture->quality = ffmpeg->vbr; - + /* Set the frame data. */ ffmpeg->picture->data[0] = y; @@ -564,13 +564,13 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { char file_proto[256]; - /* - * Use append file protocol for mpeg1, to get the append behavior from + /* + * Use append file protocol for mpeg1, to get the append behavior from * url_fopen, but no protocol (=> default) for other codecs. */ - if (is_mpeg1) + if (is_mpeg1) snprintf(file_proto, sizeof(file_proto), APPEND_PROTO ":%s", filename); - else + else snprintf(file_proto, sizeof(file_proto), "%s", filename); if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { @@ -593,12 +593,12 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, } else if (errno == EACCES) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen - error opening file %s" - " ... check access rights to target directory", + " ... check access rights to target directory", filename); ffmpeg_cleanups(ffmpeg); return NULL; } else { - MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", filename); ffmpeg_cleanups(ffmpeg); return NULL; @@ -608,11 +608,11 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* Write the stream header, if any. */ av_write_header(ffmpeg->oc); - + return ffmpeg; } -/** +/** * ffmpeg_cleanups * Clean up ffmpeg struct if something was wrong. * @@ -630,18 +630,18 @@ void ffmpeg_cleanups(struct ffmpeg *ffmpeg) if (ffmpeg->video_st->codec->priv_data != NULL) #endif avcodec_close(AVSTREAM_CODEC_PTR(ffmpeg->video_st)); - pthread_mutex_unlock(&global_lock); + pthread_mutex_unlock(&global_lock); av_freep(&ffmpeg->picture); free(ffmpeg->video_outbuf); } /* Free the streams */ - for (i = 0; i < ffmpeg->oc->nb_streams; i++) + for (i = 0; i < ffmpeg->oc->nb_streams; i++) av_freep(&ffmpeg->oc->streams[i]); - + /* if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { - // close the output file + // close the output file if (ffmpeg->oc->pb) url_fclose(&ffmpeg->oc->pb); } */ @@ -653,11 +653,11 @@ void ffmpeg_cleanups(struct ffmpeg *ffmpeg) free(ffmpeg); } -/** +/** * ffmpeg_close - * Closes a video file. + * Closes a video file. * - * Returns + * Returns * Function returns nothing. */ void ffmpeg_close(struct ffmpeg *ffmpeg) @@ -677,13 +677,13 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) av_write_trailer(ffmpeg->oc); /* Free the streams. */ - for (i = 0; i < ffmpeg->oc->nb_streams; i++) + for (i = 0; i < ffmpeg->oc->nb_streams; i++) av_freep(&ffmpeg->oc->streams[i]); - + if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { /* Close the output file. */ -#if LIBAVFORMAT_BUILD >= (52<<16) +#if LIBAVFORMAT_BUILD >= (52<<16) url_fclose(ffmpeg->oc->pb); #else url_fclose(&ffmpeg->oc->pb); @@ -698,24 +698,24 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) free(ffmpeg); } -/** +/** * ffmpeg_put_image - * Puts the image pointed to by ffmpeg->picture. + * Puts the image pointed to by ffmpeg->picture. * * Returns * value returned by ffmpeg_put_frame call. */ -int ffmpeg_put_image(struct ffmpeg *ffmpeg) +int ffmpeg_put_image(struct ffmpeg *ffmpeg) { return ffmpeg_put_frame(ffmpeg, ffmpeg->picture); } -/** - * ffmpeg_put_other_image - * Puts an arbitrary picture defined by y, u and v. +/** + * ffmpeg_put_other_image + * Puts an arbitrary picture defined by y, u and v. * - * Returns - * Number of bytes written by ffmpeg_put_frame + * Returns + * Number of bytes written by ffmpeg_put_frame * -1 if any error happens in ffmpeg_put_frame * 0 if error allocating picture. */ @@ -737,13 +737,13 @@ int ffmpeg_put_other_image(struct ffmpeg *ffmpeg, unsigned char *y, return ret; } -/** - * ffmpeg_put_frame +/** + * ffmpeg_put_frame * Encodes and writes a video frame using the av_write_frame API. This is * a helper function for ffmpeg_put_image and ffmpeg_put_other_image. - * + * * Returns - * Number of bytes written or -1 if any error happens. + * Number of bytes written or -1 if any error happens. */ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) { @@ -769,34 +769,34 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) } else { /* Encodes the image. */ out_size = avcodec_encode_video(AVSTREAM_CODEC_PTR(ffmpeg->video_st), - ffmpeg->video_outbuf, + ffmpeg->video_outbuf, ffmpeg->video_outbuf_size, pic); /* If zero size, it means the image was buffered. */ if (out_size != 0) { - /* - * Writes the compressed frame in the media file. - * XXX: in case of B frames, the pts is not yet valid. + /* + * Writes the compressed frame in the media file. + * XXX: in case of B frames, the pts is not yet valid. */ #ifdef FFMPEG_AVWRITEFRAME_NEWAPI pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts; - if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame) + if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; - + pkt.data = ffmpeg->video_outbuf; pkt.size = out_size; ret = av_write_frame(ffmpeg->oc, &pkt); #else - ret = av_write_frame(ffmpeg->oc, ffmpeg->video_st->index, + ret = av_write_frame(ffmpeg->oc, ffmpeg->video_st->index, ffmpeg->video_outbuf, out_size); #endif /* FFMPEG_AVWRITEFRAME_NEWAPI */ } else { ret = 0; } } - + if (ret != 0) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error while writing" " video frame"); @@ -804,15 +804,15 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) return -1; } - return ret; + return ret; } -/** - * ffmpeg_prepare_frame +/** + * ffmpeg_prepare_frame * Allocates and prepares a picture frame by setting up the U, Y and V pointers in * the frame according to the passed pointers. - * - * Returns + * + * Returns * NULL If the allocation fails. * * The returned AVFrame pointer must be freed after use. @@ -830,9 +830,9 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y, } /* Take care of variable bitrate setting. */ - if (ffmpeg->vbr) + if (ffmpeg->vbr) picture->quality = ffmpeg->vbr; - + /* Setup pointers and line widths. */ picture->data[0] = y; picture->data[1] = u; @@ -845,10 +845,10 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y, } -/** +/** * ffmpeg_deinterlace * Make the image suitable for deinterlacing using ffmpeg, then deinterlace the picture. - * + * * Parameters * img image in YUV420P format * width image width in pixels @@ -862,14 +862,14 @@ void ffmpeg_deinterlace(unsigned char *img, int width, int height) { AVPicture picture; int width2 = width / 2; - + picture.data[0] = img; picture.data[1] = img + width * height; picture.data[2] = picture.data[1] + (width * height) / 4; picture.linesize[0] = width; picture.linesize[1] = width2; picture.linesize[2] = width2; - + /* We assume using 'PIX_FMT_YUV420P' always */ avpicture_deinterlace(&picture, &picture, PIX_FMT_YUV420P, width, height); @@ -880,10 +880,10 @@ void ffmpeg_deinterlace(unsigned char *img, int width, int height) return; } -/** +/** * ffmpeg_avcodec_log * Handle any logging output from the ffmpeg library avcodec. - * + * * Parameters * *ignoreme A pointer we will ignore * errno_flag The error number value @@ -901,7 +901,7 @@ void ffmpeg_avcodec_log(void *ignoreme ATTRIBUTE_UNUSED, int errno_flag, const c vsnprintf(buf, sizeof(buf), fmt, vl); /* If the debug_level is correct then send the message to the motion logging routine. */ - MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s: %s - flag %d", + MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, "%s: %s - flag %d", buf, errno_flag); } diff --git a/jpegutils.c b/jpegutils.c index b44daa8..88574b4 100644 --- a/jpegutils.c +++ b/jpegutils.c @@ -4,7 +4,7 @@ * * Copyright (C) 1999 Rainer Johanni * Copyright (C) 2001 pHilipp Zabel - * Copyright (C) 2008 Angel Carpintero + * Copyright (C) 2008 Angel Carpintero * * based on jdatasrc.c and jdatadst.c from the Independent * JPEG Group's software by Thomas G. Lane @@ -190,7 +190,7 @@ static void init_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) static boolean empty_output_buffer(j_compress_ptr cinfo) { /*FIXME: */ - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small"); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small"); ERREXIT (cinfo, JERR_BUFFER_SIZE); /* Shouldn't be FILE_WRITE but BUFFER_OVERRUN! */ return TRUE; } @@ -219,7 +219,7 @@ static void term_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) static void jpeg_buffer_dest(j_compress_ptr cinfo, unsigned char *buf, long len) { - /* + /* * The destination object is made permanent so that multiple JPEG images * can be written to the same file without re-executing jpeg_stdio_dest. * This makes it dangerous to use this manager and a different destination @@ -268,9 +268,9 @@ static void my_error_exit(j_common_ptr cinfo) /* cinfo->err really points to a my_error_mgr struct, so coerce pointer. */ struct my_error_mgr *myerr = (struct my_error_mgr *) cinfo->err; - /* - * Always display the message. - * We could postpone this until after returning, if we chose. + /* + * Always display the message. + * We could postpone this until after returning, if we chose. */ (*cinfo->err->output_message) (cinfo); @@ -303,7 +303,7 @@ static unsigned char chr2[8][MAX_CHROMA_WIDTH]; #if 1 /* Generation of 'std' Huffman tables... */ -static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, +static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) /* Define a Huffman table */ { @@ -315,7 +315,7 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, /* Copy the number-of-symbols-of-each-code-length counts. */ memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); - /* + /* * Validate the counts. We do this here mainly so we can copy the right * number of symbols from the val[] array, without risking marching off * the end of memory. jchuff.c will do a more thorough test later. @@ -326,7 +326,7 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, nsymbols += bits[len]; if (nsymbols < 1 || nsymbols > 256) - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small"); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small"); memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8)); } @@ -341,12 +341,12 @@ static void std_huff_tables (j_decompress_ptr dinfo) { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; static const UINT8 val_dc_luminance[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - + static const UINT8 bits_dc_chrominance[17] = { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; static const UINT8 val_dc_chrominance[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - + static const UINT8 bits_ac_luminance[17] = { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; static const UINT8 val_ac_luminance[] = @@ -371,7 +371,7 @@ static void std_huff_tables (j_decompress_ptr dinfo) 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa }; - + static const UINT8 bits_ac_chrominance[17] = { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; static const UINT8 val_ac_chrominance[] = @@ -396,7 +396,7 @@ static void std_huff_tables (j_decompress_ptr dinfo) 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa }; - + add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0], bits_dc_luminance, val_dc_luminance); add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0], @@ -435,19 +435,19 @@ static void guarantee_huff_tables(j_decompress_ptr dinfo) * returns: * -1 on fatal error * 0 on success - * 1 if jpeg lib threw a "corrupt jpeg data" warning. + * 1 if jpeg lib threw a "corrupt jpeg data" warning. * in this case, "a damaged output image is likely." - * + * */ int decode_jpeg_raw (unsigned char *jpeg_data, int len, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2) { int numfields, hsf[3], field, yl, yc; int i, xsl, xsc, xs, hdown; unsigned int x, y = 0, vsf[3], xd; - + JSAMPROW row0[16] = { buf0[0], buf0[1], buf0[2], buf0[3], buf0[4], buf0[5], buf0[6], buf0[7], buf0[8], buf0[9], buf0[10], buf0[11], @@ -487,7 +487,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* * Read header, make some checks and try to figure out what the - * user really wants. + * user really wants. */ jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; @@ -519,15 +519,15 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, if (height % 8 != 0) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: YUV 4:4:4 sampling, but image" " height %d not dividable by 8 !", height); - goto ERR_EXIT; + goto ERR_EXIT; } for (y = 0; y < 16; y++) { // Allocate a special buffer for the extra sampling depth. row1_444[y] = (unsigned char *)malloc(dinfo.output_width * sizeof(char)); row2_444[y] = (unsigned char *)malloc(dinfo.output_width * sizeof(char)); } - scanarray[1] = row1_444; - scanarray[2] = row2_444; + scanarray[1] = row1_444; + scanarray[2] = row2_444; } /* Height match image height or be exact twice the image height. */ @@ -545,7 +545,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* Width is more flexible */ if (dinfo.output_width > MAX_LUMA_WIDTH) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", dinfo.output_width); goto ERR_EXIT; } @@ -601,7 +601,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, } } else { yl = yc = 0; - } + } while (dinfo.output_scanline < dinfo.output_height) { /* Read raw data */ @@ -622,7 +622,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, raw0[xd] = (2 * row0[y][xs] + row0[y][xs + 1]) / 3; raw0[xd + 1] = (2 * row0[y][xs + 2] + row0[y][xs + 1]) / 3; } - } + } } /* Horizontal downsampling of chroma */ @@ -631,7 +631,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, xs = xsc; if (hsf[0] == 1) - for (x = 0; x < width / 2; x++, xs++) { + for (x = 0; x < width / 2; x++, xs++) { row1[y][xs] = (row1_444[y][2*x] + row1_444[y][2*x + 1]) >> 1; row2[y][xs] = (row2_444[y][2*x] + row2_444[y][2*x + 1]) >> 1; } @@ -641,12 +641,12 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, for (x = 0; x < width / 2; x++, xs++) { chr1[y][x] = row1[y][xs]; chr2[y][x] = row2[y][xs]; - } + } } else if (hdown == 1) { for (x = 0; x < width / 2; x++, xs += 2) { chr1[y][x] = (row1[y][xs] + row1[y][xs + 1]) >> 1; chr2[y][x] = (row2[y][xs] + row2[y][xs + 1]) >> 1; - } + } } else { for (x = 0; x < width / 2; x += 2, xs += 3) { chr1[y][x] = (2 * row1[y][xs] + row1[y][xs + 1]) / 3; @@ -654,7 +654,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, chr2[y][x] = (2 * row2[y][xs] + row2[y][xs + 1]) / 3; chr2[y][x + 1] = (2 * row2[y][xs + 2] + row2[y][xs + 1]) / 3; } - } + } } /* Vertical resampling of chroma */ @@ -675,7 +675,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* upsample */ for (y = 0; y < 8 /*&& yc < height */; y++) { xd = yc * width / 2; - + for (x = 0; x < width / 2; x++, xd++) { raw1[xd] = chr1[y][x]; raw2[xd] = chr2[y][x]; @@ -715,7 +715,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* Just copy */ for (y = 0; y < 8 /* && yc < height / 2 */; y++, yc += numfields) { xd = yc * width / 2; - + for (x = 0; x < width / 2; x++, xd++) { raw1[xd] = chr1[y][x]; raw2[xd] = chr2[y][x]; @@ -760,8 +760,8 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, * Currently only Y4M_CHROMA_{420JPEG,422} are available */ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2) { int numfields, hsf[3], field, yl, yc, xsl, xsc, xs, xd, hdown; @@ -791,16 +791,16 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, jpeg_buffer_src (&dinfo, jpeg_data, len); - /* + /* * Read header, make some checks and try to figure out what the - * user really wants. + * user really wants. */ jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; dinfo.out_color_space = JCS_GRAYSCALE; dinfo.dct_method = JDCT_IFAST; - - if (dinfo.jpeg_color_space != JCS_GRAYSCALE) { + + if (dinfo.jpeg_color_space != JCS_GRAYSCALE) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Expected grayscale colorspace" " for JPEG raw decoding"); goto ERR_EXIT; @@ -827,7 +827,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", dinfo.output_width); goto ERR_EXIT; } @@ -883,7 +883,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, } } else { yl = yc = 0; - } + } while (dinfo.output_scanline < dinfo.output_height) { jpeg_read_raw_data (&dinfo, scanarray, 16); @@ -903,7 +903,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, raw0[xd] = (2 * row0[y][xs] + row0[y][xs + 1]) / 3; raw0[xd + 1] = (2 * row0[y][xs + 2] + row0[y][xs + 1]) / 3; } - } + } } @@ -914,12 +914,12 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, for (x = 0; x < width / 2; x++, xs++) { chr1[y][x] = 0; //row1[y][xs]; chr2[y][x] = 0; //row2[y][xs]; - } + } } else if (hdown == 1) { for (x = 0; x < width / 2; x++, xs += 2) { chr1[y][x] = 0; //(row1[y][xs] + row1[y][xs + 1]) >> 1; chr2[y][x] = 0; //(row2[y][xs] + row2[y][xs + 1]) >> 1; - } + } } else { for (x = 0; x < width / 2; x += 2, xs += 3) { chr1[y][x] = 0; //(2 * row1[y][xs] + row1[y][xs + 1]) / 3; @@ -928,7 +928,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, chr2[y][x] = 0; // (2 * row2[y][xs] + row2[y][xs + 1]) / 3; chr2[y][x + 1] = 0; //(2 * row2[y][xs + 2] + row2[y][xs + 1]) / 3; - } + } } } @@ -948,7 +948,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, /* upsample */ for (y = 0; y < 8 /* && yc < height */; y++) { xd = yc * width / 2; - + for (x = 0; x < width / 2; x++, xd++) { raw1[xd] = 127; //chr1[y][x]; raw2[xd] = 127; //chr2[y][x]; @@ -956,7 +956,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, yc += numfields; xd = yc * width / 2; - + for (x = 0; x < width / 2; x++, xd++) { raw1[xd] = 127; //chr1[y][x]; raw2[xd] = 127; //chr2[y][x]; @@ -1019,7 +1019,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, * may be interlaced * * * *******************************************************************/ - + /* * jpeg_data: Buffer to hold output jpeg * len: Length of buffer @@ -1030,8 +1030,8 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, * Currently only Y4M_CHROMA_{420JPEG,422} are available */ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2) { int numfields, field, yl, yc, y, i; @@ -1121,7 +1121,7 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, for (field = 0; field < numfields; field++) { jpeg_start_compress (&cinfo, FALSE); - + if (numfields == 2) { static const JOCTET marker0[40]; @@ -1144,7 +1144,7 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, } else { yl = yc = 0; } - + while (cinfo.next_scanline < cinfo.image_height) { for (y = 0; y < 8 * cinfo.comp_info[0].v_samp_factor; @@ -1167,7 +1167,7 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, (void) jpeg_finish_compress (&cinfo); } - + /* FIXME */ i = len - cinfo.dest->free_in_buffer; diff --git a/jpegutils.h b/jpegutils.h index e1263ce..d0b38c5 100644 --- a/jpegutils.h +++ b/jpegutils.h @@ -1,10 +1,10 @@ -/* +/* * jpegutils.h: Some Utility programs for dealing with * JPEG encoded images * * Copyright (C) 1999 Rainer Johanni * Copyright (C) 2001 pHilipp Zabel - * Copyright (C) 2008 Angel Carpintero + * Copyright (C) 2008 Angel Carpintero * */ @@ -44,17 +44,17 @@ int decode_jpeg_raw(unsigned char *jpeg_data, int len, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2); int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2); int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, - int itype, int ctype, unsigned int width, - unsigned int height, unsigned char *raw0, + int itype, int ctype, unsigned int width, + unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2); #endif diff --git a/logger.c b/logger.c index 4df1c20..6eb8b14 100644 --- a/logger.c +++ b/logger.c @@ -1,10 +1,10 @@ /* * logger.c * - * Logger for motion + * Logger for motion * - * Copyright 2005, William M. Brack - * Copyright 2008 by Angel Carpintero (ack@telefonica.net) + * Copyright 2005, William M. Brack + * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU Public License Version 2 * See also the file 'COPYING'. * @@ -37,7 +37,7 @@ int get_log_type(const char *type) if (!strncasecmp(type, log_type_str[i], 3)) { ret = i; break; - } + } } return ret; @@ -70,7 +70,7 @@ void set_log_type(unsigned int type) * Gets string value for log level. * * Returns: name of log level. - */ + */ const char* get_log_level_str(unsigned int level) { return log_level_str[level]; @@ -92,7 +92,7 @@ void set_log_level(unsigned int level) * Sets mode of logging , could be using syslog or files. * * Returns: nothing. - */ + */ void set_log_mode(int mode) { log_mode = mode; @@ -120,7 +120,7 @@ FILE * set_logfile(const char *logfile_name) * str_time * * Return: string with human readable time - */ + */ static char *str_time(void) { static char buffer[16]; @@ -143,7 +143,7 @@ static char *str_time(void) * Parameters: * * level logging level for the 'syslog' function - * + * * type logging type. * * errno_flag if set, the log message should be followed by the @@ -158,7 +158,7 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . { int errno_save, n; char buf[1024]; -/* GNU-specific strerror_r() */ +/* GNU-specific strerror_r() */ #if (!defined(XSI_STRERROR_R)) char msg_buf[100]; #endif @@ -173,7 +173,7 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . if ((log_type != TYPE_ALL) && (type != log_type)) return; - /* + /* * 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, * which is nice because that's what we want in that case. @@ -186,21 +186,21 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . */ errno_save = errno; - /* + /* * Prefix the message with the log level string, log type string, * time and thread number. e.g. [1] [ERR] [ENC] [Apr 03 00:08:44] blah * */ if (!log_mode) { - n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] [%s] ", - threadnr, get_log_level_str(level), get_log_type_str(type), + n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] [%s] ", + threadnr, get_log_level_str(level), get_log_type_str(type), str_time()); - } else { - /* + } else { + /* * Prefix the message with the log level string, log type string * and thread number. e.g. [1] [DBG] [TRK] blah */ - n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] ", + n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] ", threadnr, get_log_level_str(level), get_log_type_str(type)); } @@ -224,7 +224,7 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . /* XSI-compliant strerror_r() */ strerror_r(errno_save, buf + n, sizeof(buf) - n); /* 2 for the ': ' */ #else -#warning "************************************" +#warning "************************************" #warning "* Using GNU-COMPLIANT strerror_r() *" #warning "************************************" /* GNU-specific strerror_r() */ @@ -237,14 +237,14 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . fputs(buf, logfile); fflush(logfile); - /* If log_mode, send the message to the syslog. */ - } else { + /* If log_mode, send the message to the syslog. */ + } else { syslog(level, "%s", buf); strncat(buf, "\n", 1024 - strlen(buf)); fputs(buf, stderr); fflush(stderr); - } - + } + /* Clean up the argument list routine. */ va_end(ap); } diff --git a/logger.h b/logger.h index 980c84b..9910147 100644 --- a/logger.h +++ b/logger.h @@ -1,10 +1,10 @@ /* * logger.h * - * Include file for logger.c + * Include file for logger.c * - * Copyright 2005, William M. Brack - * Copyright 2008 by Angel Carpintero (ack@telefonica.net) + * Copyright 2005, William M. Brack + * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU Public License Version 2 * See also the file 'COPYING'. * @@ -33,11 +33,11 @@ #define INF LOG_INFO /* syslog 6 motion 7 */ #define DBG LOG_DEBUG /* syslog 7 motion 8 */ #define ALL LOG_ALL /* syslog 7 motion 9 */ -#define LEVEL_DEFAULT ERR /* syslog 3 motion 4 default */ +#define LEVEL_DEFAULT NTC /* syslog 5 motion 6 default */ #define SHOW_LEVEL_VALUE(x) (x+1) /* Log types */ -#define TYPE_STREAM 1 /* Stream logs */ +#define TYPE_STREAM 1 /* Stream logs */ #define TYPE_ENCODER 2 /* Encoder logs */ #define TYPE_NETCAM 3 /* Netcam logs */ #define TYPE_DB 4 /* Database logs */ @@ -48,7 +48,7 @@ #define TYPE_DEFAULT TYPE_ALL /* Default type */ #define TYPE_DEFAULT_STR "ALL" /* Default name logs */ -#define MOTION_LOG(x, y, z, format, args...) motion_log(x, y, z, format, __FUNCTION__, ##args) +#define MOTION_LOG(x, y, z, format, args...) motion_log(x, y, z, format, __FUNCTION__, ##args) int get_log_type(const char* type); const char* get_log_type_str(unsigned int type); @@ -59,4 +59,4 @@ void set_log_mode(int mode); FILE * set_logfile(const char *logfile_name); void motion_log(int, unsigned int, int, const char *, ...); -#endif +#endif diff --git a/md5.c b/md5.c index f606519..27af6f8 100644 --- a/md5.c +++ b/md5.c @@ -1,8 +1,9 @@ -/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm +/* + * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm * taken from RFC 1321 */ -/* +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. @@ -27,7 +28,7 @@ documentation and/or software. #include "md5.h" -/* +/* * Constants for MD5Transform routine. */ @@ -68,12 +69,12 @@ static unsigned char PADDING[64] = { #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | (~z))) -/* +/* * ROTATE_LEFT rotates x left n bits. */ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) -/* +/* * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. * Rotation is separate from addition to prevent recomputation. */ @@ -183,7 +184,7 @@ void MD5Final ( MD5_memset ((POINTER)context, 0, sizeof (*context)); } -/* +/* * MD5 basic transformation. Transforms state based on block. */ static void MD5Transform (state, block) diff --git a/md5.h b/md5.h index 2e2a4cd..137c65a 100644 --- a/md5.h +++ b/md5.h @@ -1,5 +1,6 @@ -/* MD5.H - header file for MD5C.C - taken from RFC 1321 +/* + * MD5.H - header file for MD5C.C + * taken from RFC 1321 */ #ifndef MD5_H @@ -30,7 +31,7 @@ documentation and/or software. /* GLOBAL.H - RSAREF types and constants */ -/* +/* * PROTOTYPES should be set to one if and only if the compiler supports * function argument prototyping. * The following makes PROTOTYPES default to 0 if it has not already @@ -50,7 +51,7 @@ typedef unsigned short int UINT2; /* UINT4 defines a four byte word */ typedef unsigned int UINT4; -/* +/* * PROTO_LIST is defined depending on how PROTOTYPES is defined above. * If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it * returns an empty list. diff --git a/motion-dist.conf.in b/motion-dist.conf.in index c37a4fd..3b3e4b0 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -11,7 +11,7 @@ daemon on # File to store the process ID, also called pid file. (default: not defined) -process_id_file /var/run/motion/motion.pid +process_id_file /var/run/motion/motion.pid ############################################################ # Basic Setup Mode @@ -24,10 +24,10 @@ setup_mode off # Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined) ;logfile /tmp/motion.log -# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR) -log_level 4 +# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 6 / NTC) +log_level 6 -# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL) +# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL) log_type all ########################################################### @@ -47,7 +47,7 @@ videodevice /dev/video0 # # Values : # V4L2_PIX_FMT_SN9C10X : 0 'S910' -# V4L2_PIX_FMT_SBGGR16 : 1 'BYR2' +# V4L2_PIX_FMT_SBGGR16 : 1 'BYR2' # V4L2_PIX_FMT_SBGGR8 : 2 'BA81' # V4L2_PIX_FMT_SPCA561 : 3 'S561' # V4L2_PIX_FMT_SGBRG8 : 4 'GBRG' @@ -57,9 +57,9 @@ videodevice /dev/video0 # V4L2_PIX_FMT_MJPEG : 8 'MJPEG' # V4L2_PIX_FMT_JPEG : 9 'JPEG' # V4L2_PIX_FMT_RGB24 : 10 'RGB3' -# V4L2_PIX_FMT_SPCA501 : 11 'S501' -# V4L2_PIX_FMT_SPCA505 : 12 'S505' -# V4L2_PIX_FMT_SPCA508 : 13 'S508' +# V4L2_PIX_FMT_SPCA501 : 11 'S501' +# V4L2_PIX_FMT_SPCA505 : 12 'S505' +# V4L2_PIX_FMT_SPCA508 : 13 'S508' # V4L2_PIX_FMT_UYVY : 14 'UYVY' # V4L2_PIX_FMT_YUYV : 15 'YUYV' # V4L2_PIX_FMT_YUV422P : 16 '422P' @@ -119,7 +119,7 @@ netcam_keepalive off # URL to use for a netcam proxy server, if required, e.g. "http://myproxy". # If a port number other than 80 is needed, use "http://myproxy:1234". # Default: not defined -; netcam_proxy value +; netcam_proxy value # Set less strict jpeg checks for network cameras with a poor/buggy firmware. # Default: off @@ -272,7 +272,7 @@ ffmpeg_output_movies on # object (ghost images) (default: off) ffmpeg_output_debug_movies off -# Use ffmpeg to encode a timelapse movie +# Use ffmpeg to encode a timelapse movie # Default value 0 = off - else save frame every Nth second ffmpeg_timelapse 0 @@ -357,7 +357,7 @@ locate_motion_mode off # Set to 'redbox' will draw a red box. # Set to 'cross' will draw a little cross to mark center. # Set to 'redcross' will draw a little red cross to mark center. -locate_motion_style box +locate_motion_style box # Draws the timestamp using same options as C function strftime(3) # Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock @@ -469,7 +469,7 @@ stream_localhost on stream_limit 0 # Set the authentication method (default: 0) -# 0 = disabled +# 0 = disabled # 1 = Basic authentication # 2 = MD5 digest (the safer authentication) stream_auth_method 0 @@ -504,7 +504,7 @@ webcontrol_html_output on # Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo) # The generic type enables the definition of motion center and motion size to # be used with the conversion specifiers for options like on_motion_detected -track_type 0 +track_type 0 # Enable auto tracking (default: off) track_auto off @@ -588,7 +588,7 @@ track_stepsize 40 quiet on # Command to be executed when an event starts. (default: none) -# An event starts at first motion detected after a period of no motion defined by event_gap +# An event starts at first motion detected after a period of no motion defined by event_gap ; on_event_start value # Command to be executed when an event ends after a period of no motion @@ -648,7 +648,7 @@ quiet on ############################################################ -# Database Options +# Database Options ############################################################ # database type : mysql, postgresql, sqlite3 (default : not defined) @@ -666,14 +666,14 @@ quiet on # User password for database (default: not defined) ; database_password value -# Port on which the database is located +# Port on which the database is located # mysql 3306 , postgresql 5432 (default: not defined) ; database_port value ############################################################ # Database Options For SQLite3 ############################################################ - + # SQLite3 database (file path) (default: not defined) ; sqlite3_db value @@ -703,7 +703,7 @@ quiet on # thread file for each camera. E.g. 2 cameras requires 3 files: # This motion.conf file AND thread1.conf and thread2.conf. # Only put the options that are unique to each camera in the -# thread config files. +# thread config files. ; thread /usr/local/etc/thread1.conf ; thread /usr/local/etc/thread2.conf ; thread /usr/local/etc/thread3.conf diff --git a/motion.1 b/motion.1 index 6d12d13..cb20102 100644 --- a/motion.1 +++ b/motion.1 @@ -24,7 +24,7 @@ Run in non-daemon mode. Run in setup mode. Also forces non-daemon mode .TP .B \-d log level -Set log level [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR) +Set log level [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 6 / NTC) .TP .B \-k log type Set type of log (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL) @@ -72,7 +72,7 @@ Values: Max 4095 characters / Default: Not defined Name of the database. .TP .B database_host string -Values: Max 4095 characters / Default: localhost +Values: Max 4095 characters / Default: localhost .br IP address or domain name for the database server. Use "localhost" if motion and database runs on the same server. .TP @@ -86,7 +86,7 @@ Values: 0 - 65535 / Default: Not defined .br The database server port number. .TP -.B database_type discrete strings +.B database_type discrete strings Values: mysql, postgresql / Default: Not defined .br The database type ( mysql , postgresql ). @@ -140,7 +140,7 @@ Values: on, off / Default: off .br Use ffmpeg to deinterlace video. Necessary if you use an analog camera and see horizontal combing on moving objects in video or pictures. .TP -.B ffmpeg_timelapse integer +.B ffmpeg_timelapse integer Values: 0 - 2147483647 / Default: 0 (disabled) .br Create a timelapse movie saving a picture frame at the interval in seconds set by this parameter. Set it to 0 if not used. @@ -165,7 +165,7 @@ Values: 2 - 100 / Default: 100 (no limit) .br Maximum number of frames to be captured from the camera per second. .TP -.B frequency integer +.B frequency integer Values: 0 - 999999 / Default: 0 (Not set) .br The frequency to set the tuner to (kHz). Valid range: per tuner spec, default: 0 (Don't set it) @@ -195,7 +195,7 @@ Values: 0 - 100 / Default: 0 (disabled) .br Ignore sudden massive light intensity changes given as a percentage of the picture area that changed intensity. .TP -.B locate_motion discrete strings +.B locate_motion discrete strings Values: on, off, redbox, center, redcross, preview / Default: off .br Locate and draw a box around the moving object. Value 'preview' makes Motion only draw a box on a saved preview jpeg image and not on the saved movie. @@ -211,9 +211,9 @@ Values: Max 4095 characters / Default: Not defined 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 +Values: 1 - 9 / Default: 6 .br -Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR). +Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 6 / NTC). .TP .B log_type discrete strings Values: STR, ENC, NET, DBL, EVT, TRK, VID, ALL / Default: ALL @@ -235,7 +235,7 @@ Values: 0 - 2147483647 / Default: 0 .br Minimum time in seconds between the capturing picture frames from the camera. Default: 0 = disabled - the capture rate is given by the camera framerate. .TP -.B minimum_motion_frames integer +.B minimum_motion_frames integer Values: 1 - 1000s / Default: 1 .br Picture frames must contain motion at least the specified number of frames in a row before they are detected as true motion. At the default of 1, all motion is detected. Valid range is 1 to thousands, but it is recommended to keep it within 1-5. @@ -285,7 +285,7 @@ Values: on, off / Default: on .br Activates the automatic tuning of noise level. .TP -.B norm integer +.B norm integer Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour) / Default: 0 (PAL) .br Select the norm of the video device. Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL) @@ -348,7 +348,7 @@ File path for motion triggered images (jpeg or ppm) relative to target_dir. Valu .B picture_type discrete strings Values: jpeg , ppm / Default: jpeg .br -Type of images motion will trigger when motion is detected. +Type of images motion will trigger when motion is detected. .TP .B post_capture integer Values: 0 - 2147483647 / Default: 0 (disabled) @@ -441,7 +441,7 @@ Values: Max 4095 characters / Default: insert into security(camera, filename, fr SQL query string that is sent to the database. The values for each field are given by using convertion specifiers .TP .B stream_auth_method integer -Values: 0 = disabled , 1 = Basic authentication ,2 = MD5 digest (the safer authentication). / Default: 0 (disabled) +Values: 0 = disabled , 1 = Basic authentication ,2 = MD5 digest (the safer authentication). / Default: 0 (disabled) .br Set the authentication method for stream. .TP @@ -610,7 +610,7 @@ Values: on, off / Default: off .br Enables extpipe to use an external video encoder feeding with YUV420 using a pipe . .TP -.B v4l2_palette discrete strings +.B v4l2_palette discrete strings Values: 0 - 8 / Default: 8 .br Allow to choose preferable palette to be use by motion to capture from those supported by your videodevice. @@ -716,7 +716,7 @@ So always call the thread config files in the end of the motion.conf file. If yo .br If motion is built without specific features such as ffmpeg, mysql etc it will ignore the options that belongs to these features. You do not have to remove them or comment them out. .br -If you run the webcontrol command http://host:port/0/config/writeyes, motion will overwrite motion.conf and all the thread.conf files by autogenerated config files neatly formatted and only with the features included that Motion was built with. If you later re-build Motion with more features or upgrade to a new version, you can use your old config files, run the motion.conf.write command, and you will have new config files with the new options included all set to their default values. This makes upgrading very easy to do. +If you run the webcontrol command http://host:port/0/config/writeyes, motion will overwrite motion.conf and all the thread.conf files by autogenerated config files neatly formatted and only with the features included that Motion was built with. If you later re-build Motion with more features or upgrade to a new version, you can use your old config files, run the motion.conf.write command, and you will have new config files with the new options included all set to their default values. This makes upgrading very easy to do. .TP .B Conversion Specifiers for Advanced Filename and Text Features The table below shows all the supported Conversion Specifiers you can use in the options text_left, text_right, snapshot_filename, picture_filename, movie_filename, timelapse_filename, on_area_detected, on_camera_lost, on_event_start, on_event_end, on_picture_save, on_movie_start, on_movie_end, and on_motion_detected. diff --git a/motion.c b/motion.c index 55f5be3..1064d56 100644 --- a/motion.c +++ b/motion.c @@ -104,7 +104,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Resizing pre_capture buffer to %d items", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Resizing pre_capture buffer to %d items", new_size); /* Create memory for new ring buffer */ @@ -381,13 +381,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Removed process id file (pid file)."); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Removed process id file (pid file)."); else MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error removing pid file"); } if (ptr_logfile) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Closing logfile (%s).", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Closing logfile (%s).", cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_SYSLOG); myfclose(ptr_logfile); @@ -464,7 +464,7 @@ 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); - MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Motion detected - starting event %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion detected - starting event %d", cnt->event_nr); /* always save first motion frame as preview-shot, may be changed to an other one later */ @@ -688,7 +688,7 @@ static int motion_init(struct context *cnt) cnt->detecting_motion = 0; cnt->makemovie = 0; - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d started", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread %d started", (unsigned long)pthread_getspecific(tls_key_threadnr)); if (!cnt->conf.filepath) @@ -703,7 +703,7 @@ static int motion_init(struct context *cnt) * file options. */ if (cnt->video_dev == -1) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " "Motion continues using width and height from config file(s)"); cnt->imgs.width = cnt->conf.width; cnt->imgs.height = cnt->conf.height; @@ -711,7 +711,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " "Motion only supports width and height modulo 16"); return -3; } @@ -781,7 +781,7 @@ static int motion_init(struct context *cnt) #if !defined(WITHOUT_V4L) && !defined(BSD) /* open video loopback devices if enabled */ if (cnt->conf.vidpipe) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for normal pictures"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for normal pictures"); /* vid_startpipe should get the output dimensions */ cnt->pipe = vid_startpipe(cnt->conf.vidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); @@ -793,7 +793,7 @@ static int motion_init(struct context *cnt) } if (cnt->conf.motionvidpipe) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for motion pictures"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for motion pictures"); /* vid_startpipe should get the output dimensions */ cnt->mpipe = vid_startpipe(cnt->conf.motionvidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); @@ -807,16 +807,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(ERR, TYPE_DB, NO_ERRNO, "%s: Database backend %s", + MOTION_LOG(NTC, TYPE_DB, NO_ERRNO, "%s: Database backend %s", cnt->conf.database_type); #ifdef HAVE_SQLITE3 if ((!strcmp(cnt->conf.database_type, "sqlite3")) && cnt->conf.sqlite3_db) { - MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: DB %s", + MOTION_LOG(NTC, TYPE_DB, NO_ERRNO, "%s: DB %s", cnt->conf.sqlite3_db); if (sqlite3_open(cnt->conf.sqlite3_db, &cnt->database_sqlite3) != SQLITE_OK) { - MOTION_LOG(EMG, TYPE_DB, NO_ERRNO, "%s: Can't open database %s : %s\n", + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Can't open database %s : %s\n", cnt->conf.sqlite3_db, sqlite3_errmsg(cnt->database_sqlite3)); sqlite3_close(cnt->database_sqlite3); exit(1); @@ -904,7 +904,7 @@ static int motion_init(struct context *cnt) if (!cnt->imgs.mask) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to read mask image. Mask feature disabled."); } else { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Maskfile \"%s\" loaded.", + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: Maskfile \"%s\" loaded.", cnt->conf.mask_file); } } else { @@ -929,7 +929,7 @@ static int motion_init(struct context *cnt) cnt->conf.stream_port); cnt->finish = 1; } else { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Started motion-stream server in port %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Started motion-stream server in port %d", cnt->conf.stream_port); } } @@ -960,7 +960,7 @@ static void motion_cleanup(struct context *cnt) event(cnt, EVENT_STOP, NULL, NULL, NULL, NULL); if (cnt->video_dev >= 0) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Calling vid_close() from motion_cleanup"); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: Calling vid_close() from motion_cleanup"); vid_close(cnt); } @@ -1296,7 +1296,7 @@ static void *motion_loop(void *arg) */ if (cnt->video_dev < 0 && cnt->currenttime % 10 == 0 && cnt->shots == 0) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Retrying until successful connection with camera"); cnt->video_dev = vid_start(cnt); @@ -1305,7 +1305,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Camera has finally become available\n" + MOTION_LOG(NTC, 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 " @@ -1344,7 +1344,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal re-acquired"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Video signal re-acquired"); // event for re-acquired video signal can be called here } cnt->missing_frame_counter = 0; @@ -1402,7 +1402,7 @@ static void *motion_loop(void *arg) * other way */ if (vid_return_code == NETCAM_RESTART_ERROR) { - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting Motion thread to reinitialize all " + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Restarting Motion thread to reinitialize all " "image buffers"); /* * Break out of main loop terminating thread @@ -1452,7 +1452,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(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal lost - Adding grey image"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Video signal lost - Adding grey image"); // Event for lost video signal can be called from here event(cnt, EVENT_CAMERA_LOST, NULL, NULL, NULL, cnt->currenttime_tm); @@ -1504,7 +1504,7 @@ static void *motion_loop(void *arg) */ if (cnt->conf.lightswitch && !cnt->lost_connection) { if (alg_lightswitch(cnt, cnt->current_image->diffs)) { - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Lightswitch detected"); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: Lightswitch detected"); if (cnt->moved < 5) cnt->moved = 5; @@ -1530,7 +1530,7 @@ static void *motion_loop(void *arg) if (cnt->current_image->diffs <= cnt->threshold) { cnt->current_image->diffs = 0; - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Switchfilter detected"); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: Switchfilter detected"); } } @@ -1632,7 +1632,7 @@ static void *motion_loop(void *arg) cnt->current_image->diffs = 0; cnt->lightswitch_framecounter = 0; - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: micro-lightswitch!"); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: micro-lightswitch!"); } else { alg_update_reference_frame(cnt, UPDATE_REF_FRAME); } @@ -1741,7 +1741,7 @@ static void *motion_loop(void *arg) */ if (cnt->conf.emulate_motion && (cnt->startup_frames == 0)) { cnt->detecting_motion = 1; - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Emulating motion"); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: Emulating motion"); #ifdef HAVE_FFMPEG if (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) { #else @@ -1946,7 +1946,7 @@ static void *motion_loop(void *arg) strcat(msg, part); } - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: %s", msg); + MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, "%s: %s", msg); } } /* get_image end */ @@ -2022,7 +2022,7 @@ static void *motion_loop(void *arg) } else { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Invalid timelapse_mode argument '%s'", cnt->conf.timelapse_mode); - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%:s Defaulting to manual timelapse mode"); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%:s Defaulting to manual timelapse mode"); conf_cmdparse(&cnt, (char *)"ffmpeg_timelapse_mode",(char *)"manual"); } } @@ -2209,7 +2209,7 @@ static void *motion_loop(void *arg) free(rolling_average_data); cnt->lost_connection = 1; - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Thread exiting"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread exiting"); motion_cleanup(cnt); @@ -2258,7 +2258,7 @@ static void become_daemon(void) /* fork */ if (fork()) { - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion going to daemon mode"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion going to daemon mode"); exit(0); } @@ -2321,7 +2321,7 @@ static void become_daemon(void) /* Now it is safe to add the PID creation to the logs */ if (pidf) - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Created process id file %s. Process ID is %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Created process id file %s. Process ID is %d", cnt_list[0]->conf.pid_file, getpid()); sigaction(SIGTTOU, &sig_ign_action, NULL); @@ -2428,7 +2428,7 @@ static void motion_startup(int daemonize, int argc, char *argv[]) (cnt_list[0]->conf.log_level == 0)) { cnt_list[0]->conf.log_level = LEVEL_DEFAULT; cnt_list[0]->log_level = cnt_list[0]->conf.log_level; - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Using default log level (%s) (%d)", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Using default log level (%s) (%d)", get_log_level_str(cnt_list[0]->log_level), SHOW_LEVEL_VALUE(cnt_list[0]->log_level)); } else { cnt_list[0]->log_level = cnt_list[0]->conf.log_level - 1; // Let's make syslog compatible @@ -2436,7 +2436,7 @@ static void motion_startup(int daemonize, int argc, char *argv[]) set_log_level(cnt_list[0]->log_level); - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started"); if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) { set_log_mode(LOGMODE_FILE); @@ -2444,7 +2444,7 @@ static void motion_startup(int daemonize, int argc, char *argv[]) if (ptr_logfile) { set_log_mode(LOGMODE_SYSLOG); - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Logging to file (%s)", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Logging to file (%s)", cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_FILE); } else { @@ -2453,18 +2453,18 @@ static void motion_startup(int daemonize, int argc, char *argv[]) exit(0); } } else { - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Logging to syslog"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Logging to syslog"); } if ((cnt_list[0]->conf.log_type_str == NULL) || !(cnt_list[0]->log_type = get_log_type(cnt_list[0]->conf.log_type_str))) { cnt_list[0]->log_type = TYPE_DEFAULT; cnt_list[0]->conf.log_type_str = mystrcpy(cnt_list[0]->conf.log_type_str, "ALL"); - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Using default log type (%s)", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Using default log type (%s)", get_log_type_str(cnt_list[0]->log_type)); } - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Using log type (%s) log level (%s)", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Using log type (%s) log level (%s)", get_log_type_str(cnt_list[0]->log_type), get_log_level_str(cnt_list[0]->log_level)); set_log_type(cnt_list[0]->log_type); @@ -2478,7 +2478,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(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running as daemon process"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion running as daemon process"); } } @@ -2554,7 +2554,7 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with the control port", cnt->conf.stream_port, cnt->threadnr); - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", cnt->threadnr); cnt->conf.stream_port = 0; } @@ -2568,7 +2568,7 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with thread %d", cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr); - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", cnt->threadnr); cnt->conf.stream_port = 0; @@ -2643,7 +2643,7 @@ int main (int argc, char **argv) * optimize motion detection and stuff. */ if (cnt_list[0]->conf.setup_mode) - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode."); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode."); /* * Create and a thread attribute for the threads we spawn later on. @@ -2663,14 +2663,14 @@ int main (int argc, char **argv) * cleanup everything, and then initialize everything again * (including re-reading the config file(s)). */ - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting motion."); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Restarting motion."); 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(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion restarted"); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Motion restarted"); } /* @@ -2682,15 +2682,15 @@ int main (int argc, char **argv) cnt_list[i]->threadnr = i ? i : 1; if (strcmp(cnt_list[i]->conf_filename, "")) - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", cnt_list[i]->threadnr, cnt_list[i]->conf_filename); - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d is device: %s input %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread %d is device: %s input %d", 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: Stream port %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Stream port %d", cnt_list[i]->conf.stream_port); start_motion_thread(cnt_list[i], &thread_attr); @@ -2703,7 +2703,7 @@ int main (int argc, char **argv) if (cnt_list[0]->conf.webcontrol_port) pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list); - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Waiting for threads to finish, pid: %d", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Waiting for threads to finish, pid: %d", getpid()); /* @@ -2734,7 +2734,7 @@ int main (int argc, char **argv) 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(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion thread %d restart", + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion thread %d restart", cnt_list[i]->threadnr); start_motion_thread(cnt_list[i], &thread_attr); } @@ -2768,7 +2768,7 @@ int main (int argc, char **argv) /* Reset end main loop flag */ finish = 0; - MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Threads finished"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Threads finished"); /* Rest for a while if we're supposed to restart. */ if (restart) @@ -2779,7 +2779,7 @@ int main (int argc, char **argv) // Be sure that http control exits fine cnt_list[0]->finish = 1; SLEEP(1, 0); - MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion terminating"); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion terminating"); /* Perform final cleanup. */ pthread_key_delete(tls_key_threadnr); @@ -2902,7 +2902,7 @@ int create_path(const char *path) start = strchr(start + 1, '/'); if (!start) - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: creating directory %s", buffer); + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: creating directory %s", buffer); free(buffer); } diff --git a/netcam.c b/netcam.c index 45b8a38..85e398a 100644 --- a/netcam.c +++ b/netcam.c @@ -1446,7 +1446,7 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam) " trying to reconnect.."); /* We may have lost the connexion */ if (netcam_http_request(netcam) < 0) { - MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "%s: lost the cam."); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: lost the cam."); return -1; /* We REALLY lost the cam... bail out for now. */ } } @@ -1748,7 +1748,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) /* its waits POLLING_TIMEOUT */ if (loop_counter>((POLLING_TIMEOUT*1000*1000)/(POLLING_TIME/1000))) { - MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "%s: waiting new file image" + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: waiting new file image" " timeout"); return -1; } @@ -2530,7 +2530,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(EMG, TYPE_NETCAM, NO_ERRNO, "%s: No response from camera " + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: No response from camera " "handler - it must have already died"); pthread_mutex_lock(&global_lock); threads_running--; diff --git a/netcam_ftp.c b/netcam_ftp.c index 6846a89..0a129b2 100644 --- a/netcam_ftp.c +++ b/netcam_ftp.c @@ -1,13 +1,13 @@ -/** -* Much of the FTP code was inspired by the nanoftp.c module from -* libxml2 (Copyright Daniel Veillard, 2003). The routines have been -* modified to fit the needs of the Motion project. -* -* Copyright 2005, William M. Brack -* This software is distributed under the GNU Public license Version 2. -* See also the file 'COPYING'. -* -*/ +/* + * Much of the FTP code was inspired by the nanoftp.c module from + * libxml2 (Copyright Daniel Veillard, 2003). The routines have been + * modified to fit the needs of the Motion project. + * + * Copyright 2005, William M. Brack + * This software is distributed under the GNU Public license Version 2. + * See also the file 'COPYING'. + * + */ #include "motion.h" /* Needs to come first, because _GNU_SOURCE_ set there. */ #include @@ -87,7 +87,7 @@ void ftp_free_context(ftp_context_pointer ctxt) * +XXX for last line of response * -XXX for response to be continued */ -static int ftp_parse_response(char *buf, int len) +static int ftp_parse_response(char *buf, int len) { int val = 0; @@ -132,7 +132,7 @@ static int ftp_parse_response(char *buf, int len) * * Returns the number of bytes read, < 0 indicates an error */ -static int ftp_get_more(ftp_context_pointer ctxt) +static int ftp_get_more(ftp_context_pointer ctxt) { int len; int size; @@ -161,9 +161,9 @@ static int ftp_get_more(ftp_context_pointer ctxt) size = FTP_BUF_SIZE - ctxt->control_buffer_used; - if (size == 0) + if (size == 0) return 0; - + /* 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) { @@ -190,7 +190,7 @@ static int ftp_get_more(ftp_context_pointer ctxt) * * Returns the code number */ -static int ftp_get_response(ftp_context_pointer ctxt) +static int ftp_get_response(ftp_context_pointer ctxt) { char *ptr, *end; int len; @@ -201,18 +201,18 @@ static int ftp_get_response(ftp_context_pointer ctxt) get_more: /* - * Assumes everything up to control_buffer[control_buffer_index] + * Assumes everything up to control_buffer[control_buffer_index] * has been read and analyzed. */ len = ftp_get_more(ctxt); - if (len < 0) + if (len < 0) return -1; - - if ((ctxt->control_buffer_used == 0) && (len == 0)) + + if ((ctxt->control_buffer_used == 0) && (len == 0)) return -1; - + ptr = &ctxt->control_buffer[ctxt->control_buffer_index]; end = &ctxt->control_buffer[ctxt->control_buffer_used]; @@ -228,13 +228,13 @@ static int ftp_get_response(ftp_context_pointer ctxt) res = cur; ptr += 3; ctxt->control_buffer_answer = ptr - ctxt->control_buffer; - while ((ptr < end) && (*ptr != '\n')) + while ((ptr < end) && (*ptr != '\n')) ptr++; - if (*ptr == '\n') + if (*ptr == '\n') ptr++; - if (*ptr == '\r') + if (*ptr == '\r') ptr++; break; @@ -248,7 +248,7 @@ static int ftp_get_response(ftp_context_pointer ctxt) goto get_more; } - if (*ptr != '\r') + if (*ptr != '\r') ptr++; } @@ -261,10 +261,10 @@ static int ftp_get_response(ftp_context_pointer ctxt) } /** -* ftp_send_user +* ftp_send_user * Sends the user authentication. */ -static int ftp_send_user(ftp_context_pointer ctxt) +static int ftp_send_user(ftp_context_pointer ctxt) { char buf[200]; int len; @@ -290,7 +290,7 @@ static int ftp_send_user(ftp_context_pointer ctxt) * ftp_send_passwd * Sends the password authentication. */ -static int ftp_send_passwd(ftp_context_pointer ctxt) +static int ftp_send_passwd(ftp_context_pointer ctxt) { char buf[200]; int len; @@ -324,7 +324,7 @@ static int ftp_send_passwd(ftp_context_pointer ctxt) * * Returns -1 in case of error, 0 otherwise */ -static int ftp_quit(ftp_context_pointer ctxt) +static int ftp_quit(ftp_context_pointer ctxt) { char buf[200]; int len, res; @@ -355,7 +355,7 @@ static int ftp_quit(ftp_context_pointer ctxt) * * Returns -1 in case of error, 0 otherwise. */ -int ftp_connect(netcam_context_ptr netcam) +int ftp_connect(netcam_context_ptr netcam) { ftp_context_pointer ctxt; struct hostent *hp; @@ -389,7 +389,7 @@ int ftp_connect(netcam_context_ptr netcam) return -1; } - if ((unsigned int) hp->h_length > + if ((unsigned int) hp->h_length > sizeof(((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr)) { MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname address mismatch " "in ftp_connect"); @@ -471,7 +471,7 @@ int ftp_connect(netcam_context_ptr netcam) case 5: case -1: default: - close(ctxt->control_file_desc); + close(ctxt->control_file_desc); ctxt->control_file_desc = -1; ctxt->control_file_desc = -1; return-1; @@ -491,7 +491,7 @@ int ftp_connect(netcam_context_ptr netcam) * * Returns -1 in case of error, 0 otherwise */ -static int ftp_get_connection(ftp_context_pointer ctxt) +static int ftp_get_connection(ftp_context_pointer ctxt) { char buf[200], *cur; int len, i; @@ -533,7 +533,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) snprintf (buf, sizeof(buf), "PASV\r\n"); len = strlen (buf); res = send(ctxt->control_file_desc, buf, len, 0); - + if (res < 0) { MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection"); close(ctxt->data_file_desc); @@ -542,7 +542,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) } /* Check server's answer */ res = ftp_get_response(ctxt); - + if (res != 2) { if (res == 5) { close(ctxt->data_file_desc); @@ -563,7 +563,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(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid answer to PASV"); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Invalid answer to PASV"); if (ctxt->data_file_desc != -1) { close (ctxt->data_file_desc); ctxt->data_file_desc = -1; @@ -620,7 +620,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) /* Now generate the PORT command. */ adp = (unsigned char *) &((struct sockaddr_in *)&data_address)->sin_addr; portp = (unsigned char *) &((struct sockaddr_in *)&data_address)->sin_port; - snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n", + snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n", adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff, portp[0] & 0xff, portp[1] & 0xff); @@ -660,7 +660,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) * * Returns -1 in case of error, 0 otherwise */ -static int ftp_close_connection(ftp_context_pointer ctxt) +static int ftp_close_connection(ftp_context_pointer ctxt) { int res; fd_set rfd, efd; @@ -714,7 +714,7 @@ static int ftp_close_connection(ftp_context_pointer ctxt) * * Returns the socket for the data connection, or <0 in case of error */ -int ftp_get_socket(ftp_context_pointer ctxt) +int ftp_get_socket(ftp_context_pointer ctxt) { char buf[300]; int res, len; @@ -788,7 +788,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) * Returns 0 for success, negative error code for failure. * */ -int ftp_send_type(ftp_context_pointer ctxt, char type) +int ftp_send_type(ftp_context_pointer ctxt, char type) { char buf[100], utype; int len, res; @@ -832,7 +832,7 @@ int ftp_send_type(ftp_context_pointer ctxt, char type) * 0 is an indication of an end of connection. * -1 indicates a parameter error. */ -int ftp_read(ftp_context_pointer ctxt, void *dest, int len) +int ftp_read(ftp_context_pointer ctxt, void *dest, int len) { if (ctxt == NULL) return -1; @@ -869,7 +869,7 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len) * * Returns -1 in case of error, 0 otherwise. */ -int ftp_close(ftp_context_pointer ctxt) +int ftp_close(ftp_context_pointer ctxt) { if (ctxt == NULL) return -1; diff --git a/netcam_ftp.h b/netcam_ftp.h index e06dfad..48c90be 100644 --- a/netcam_ftp.h +++ b/netcam_ftp.h @@ -1,5 +1,4 @@ - -/** +/* * Much of the FTP routines was inspired by the nanoftp.c module from * libxml2 (Copyright Daniel Veillard, 2003). The routines have been * modified to fit the needs of the Motion project. @@ -7,7 +6,7 @@ * Copyright 2005, William M. Brack * This software is distributed under the GNU Public license Version 2. * See also the file 'COPYING'. - * + * */ #ifndef _INCLUDE_NETCAM_FTP_H #define _INCLUDE_NETCAM_FTP_H diff --git a/netcam_jpeg.c b/netcam_jpeg.c index f4c27db..20fbda2 100644 --- a/netcam_jpeg.c +++ b/netcam_jpeg.c @@ -81,7 +81,7 @@ static boolean netcam_fill_input_buffer(j_decompress_ptr cinfo) src->buffer = (JOCTET *) src->data; } else { /* Insert a fake EOI marker - as per jpeglib recommendation */ - MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: **fake EOI inserted**"); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: **fake EOI inserted**"); src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; /* 0xD9 */ nbytes = 2; @@ -124,18 +124,18 @@ static void netcam_term_source(j_decompress_ptr cinfo ATTRIBUTE_UNUSED) * length total size of the image. * * Returns: Nothing - * + * */ static void netcam_memory_src(j_decompress_ptr cinfo, char *data, int length) { netcam_src_ptr src; - if (cinfo->src == NULL) + if (cinfo->src == NULL) cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (netcam_source_mgr)); - + src = (netcam_src_ptr)cinfo->src; src->data = data; @@ -175,9 +175,9 @@ static void netcam_error_exit(j_common_ptr cinfo) /* Need to "cleanup" the aborted decompression. */ jpeg_destroy (cinfo); - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->jpeg_error %d", + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->jpeg_error %d", netcam->jpeg_error); - + /* Jump back to wherever we started. */ longjmp(netcam->setjmp_buffer, 1); } @@ -199,7 +199,7 @@ static void netcam_error_exit(j_common_ptr cinfo) static void netcam_output_message(j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; - + /* Fetch our pre-stored pointer to the netcam context. */ netcam_context_ptr netcam = cinfo->client_data; @@ -208,23 +208,23 @@ static void netcam_output_message(j_common_ptr cinfo) * that the jpeg data produced by the camera caused warning * messages from libjpeg (JWRN_EXTRANEOUS_DATA). The following * code is to assure that specific warning is ignored. - * + * * NOTE: It's likely that we will discover other error message * codes which we want to ignore. In that case, we should have * some sort of table-lookup to decide which messages we really * care about. */ - if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && - (cinfo->err->msg_code == JWRN_NOT_SEQUENTIAL) && (!netcam->netcam_tolerant_check)) + 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 */ - + /* * Format the message according to library standards. * Write it out to the motion log. */ (*cinfo->err->format_message)(cinfo, buffer); MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: %s", buffer); - + } /** @@ -255,7 +255,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) struct timespec waittime; struct timeval curtime; int retcode; - + /* * We calculate the delay time (representing the desired frame * rate). This delay time is in *nanoseconds*. @@ -270,28 +270,28 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) curtime.tv_usec -= 1000000; curtime.tv_sec++; } - + waittime.tv_sec = curtime.tv_sec; waittime.tv_nsec = 1000L * curtime.tv_usec; - + do { retcode = pthread_cond_timedwait(&netcam->pic_ready, &netcam->mutex, &waittime); } while (retcode == EINTR); - + if (retcode) { /* We assume a non-zero reply is ETIMEOUT */ pthread_mutex_unlock(&netcam->mutex); - - MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, + + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: no new pic, no signal rcvd"); - + return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR; } - - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, + + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ***new pic delay successful***"); } - + netcam->imgcnt_last = netcam->imgcnt; /* Set latest buffer as "current". */ @@ -302,7 +302,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) /* Clear any error flag from previous work. */ netcam->jpeg_error = 0; - + buff = netcam->jpegbuf; /* * Prepare for the decompression. @@ -328,7 +328,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) /* Start the decompressor. */ jpeg_start_decompress(cinfo); - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", netcam->jpeg_error); return netcam->jpeg_error; @@ -361,7 +361,7 @@ static int netcam_image_conv(netcam_context_ptr netcam, height = cinfo->output_height; if (width && ((width != netcam->width) || (height != netcam->height))) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: JPEG image size %dx%d, JPEG was %dx%d", netcam->width, netcam->height, width, height); jpeg_destroy_decompress(cinfo); @@ -405,13 +405,13 @@ static int netcam_image_conv(netcam_context_ptr netcam, jpeg_finish_decompress(cinfo); jpeg_destroy_decompress(cinfo); - if (netcam->cnt->rotate_data.degrees > 0) + if (netcam->cnt->rotate_data.degrees > 0) /* Rotate as specified */ rotate_map(netcam->cnt, image); - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", netcam->jpeg_error); - + return netcam->jpeg_error; } @@ -425,7 +425,7 @@ static int netcam_image_conv(netcam_context_ptr netcam, * netcam pointer to the netcam_context structure. * image pointer to a buffer for the returned image. * - * Returns: + * Returns: * * 0 Success * non-zero error code from other routines @@ -446,15 +446,15 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) */ MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing jpeg image" " - content length %d", netcam->latest->content_length); - + ret = netcam_init_jpeg(netcam, &cinfo); - + if (ret != 0) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d", ret); return ret; - } + } - /* + /* * Do a sanity check on dimensions * If dimensions have changed we throw an * error message that will cause @@ -468,18 +468,18 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) "with JPEG image - expected %dx%d, JPEG %dx%d", " retval %d", netcam->width, netcam->height, cinfo.output_width, cinfo.output_height, retval); - return retval; + return retval; } } /* Do the conversion */ ret = netcam_image_conv(netcam, &cinfo, image); - + if (ret != 0) { retval |= NETCAM_JPEG_CONV_ERROR; - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d retval %d", + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d retval %d", ret, retval); - } + } return retval; } @@ -510,6 +510,6 @@ void netcam_get_dimensions(netcam_context_ptr netcam) jpeg_destroy_decompress(&cinfo); - MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: JFIF_marker %s PRESENT ret %d", + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: JFIF_marker %s PRESENT ret %d", netcam->JFIF_marker ? "IS" : "NOT", ret); } diff --git a/picture.c b/picture.c index a75eaab..f946217 100644 --- a/picture.c +++ b/picture.c @@ -15,8 +15,8 @@ #include #include -/* - * The following declarations and 5 functions are jpeg related +/* + * The following declarations and 5 functions are jpeg related * functions used by put_jpeg_grey_memory and put_jpeg_yuv420p_memory. */ typedef struct { @@ -82,7 +82,7 @@ static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo) /** - * put_jpeg_yuv420p_memory + * put_jpeg_yuv420p_memory * Converts an input image in the YUV420P format into a jpeg image and puts * it in a memory buffer. * Inputs: @@ -94,7 +94,7 @@ static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo) * Output: * - dest_image is a pointer to the jpeg image buffer * - * Returns buffer size of jpeg image + * Returns buffer size of jpeg image */ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, unsigned char *input_image, int width, int height, int quality) @@ -111,8 +111,8 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, data[1] = cb; data[2] = cr; - cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr - + cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr + jpeg_create_compress(&cinfo); cinfo.image_width = width; cinfo.image_height = height; @@ -123,9 +123,9 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, cinfo.raw_data_in = TRUE; // Supply downsampled data #if JPEG_LIB_VERSION >= 70 -#warning using JPEG_LIB_VERSION >= 70 +#warning using JPEG_LIB_VERSION >= 70 cinfo.do_fancy_downsampling = FALSE; // Fix segfault with v7 -#endif +#endif cinfo.comp_info[0].h_samp_factor = 2; cinfo.comp_info[0].v_samp_factor = 2; cinfo.comp_info[1].h_samp_factor = 1; @@ -137,7 +137,7 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, cinfo.dct_method = JDCT_FASTEST; _jpeg_mem_dest(&cinfo, dest_image, image_size); // Data written to mem - + jpeg_start_compress (&cinfo, TRUE); for (j = 0; j < height; j += 16) { @@ -155,12 +155,12 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, jpeg_finish_compress(&cinfo); jpeg_image_size = _jpeg_mem_size(&cinfo); jpeg_destroy_compress(&cinfo); - + return jpeg_image_size; } /** - * put_jpeg_grey_memory + * put_jpeg_grey_memory * Converts an input image in the grayscale format into a jpeg image. * * Inputs: @@ -172,7 +172,7 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, * Output: * - dest_image is a pointer to the jpeg image buffer * - * Returns buffer size of jpeg image. + * Returns buffer size of jpeg image. */ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsigned char *input_image, int width, int height, int quality) { @@ -197,12 +197,12 @@ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsig jpeg_start_compress (&cjpeg, TRUE); row_ptr[0] = input_image; - + for (y = 0; y < height; y++) { jpeg_write_scanlines(&cjpeg, row_ptr, 1); row_ptr[0] += width; } - + jpeg_finish_compress(&cjpeg); dest_image_size = _jpeg_mem_size(&cjpeg); jpeg_destroy_compress(&cjpeg); @@ -211,7 +211,7 @@ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsig } /** - * put_jpeg_yuv420p_file + * put_jpeg_yuv420p_file * Converts an YUV420P coded image to a jpeg image and writes * it to an already open file. * @@ -239,8 +239,8 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int data[1] = cb; data[2] = cr; - cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr - + cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr + jpeg_create_compress(&cinfo); cinfo.image_width = width; cinfo.image_height = height; @@ -284,7 +284,7 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int /** - * put_jpeg_grey_file + * put_jpeg_grey_file * Converts an greyscale image to a jpeg image and writes * it to an already open file. * @@ -331,8 +331,8 @@ static void put_jpeg_grey_file(FILE *picture, unsigned char *image, int width, i } -/** - * put_ppm_bgr24_file +/** + * put_ppm_bgr24_file * Converts an greyscale image to a PPM image and writes * it to an already open file. * Inputs: @@ -353,8 +353,8 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i int r, g, b; int warningkiller; unsigned char rgb[3]; - - /* + + /* * ppm header * width height * maxval @@ -363,7 +363,7 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i fprintf(picture, "%d %d\n", width, height); fprintf(picture, "%d\n", 255); for (y = 0; y < height; y++) { - + for (x = 0; x < width; x++) { r = 76283 * (((int)*l) - 16)+104595*(((int)*u) - 128); g = 76283 * (((int)*l) - 16)- 53281*(((int)*u) - 128) - 25625 * (((int)*v) - 128); @@ -404,7 +404,7 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i } /** - * overlay_smartmask + * overlay_smartmask * Copies smartmask as an overlay into motion images and movies. * * Returns nothing. @@ -415,7 +415,7 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) struct images *imgs = &cnt->imgs; unsigned char *smartmask = imgs->smartmask_final; unsigned char *out_y, *out_u, *out_v; - + i = imgs->motionsize; v = i + ((imgs->motionsize) / 4); width = imgs->width; @@ -428,7 +428,7 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) line = i * width; for (x = 0; x < width; x += 2) { if (smartmask[line + x] == 0 || smartmask[line + x + 1] == 0 || - smartmask[line + width + x] == 0 || + smartmask[line + width + x] == 0 || smartmask[line + width + x + 1] == 0) { *out_v = 255; @@ -448,7 +448,7 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) } /** - * overlay_fixed_mask + * overlay_fixed_mask * Copies fixed mask as green overlay into motion images and movies. * * Returns nothing. @@ -459,7 +459,7 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) struct images *imgs = &cnt->imgs; unsigned char *mask = imgs->mask; unsigned char *out_y, *out_u, *out_v; - + i = imgs->motionsize; v = i + ((imgs->motionsize) / 4); width = imgs->width; @@ -472,7 +472,7 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) line = i * width; for (x = 0; x < width; x += 2) { if (mask[line + x] == 0 || mask[line + x + 1] == 0 || - mask[line + width + x] == 0 || + mask[line + width + x] == 0 || mask[line + width + x + 1] == 0) { *out_v = 0; @@ -495,7 +495,7 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) * overlay_largest_label * Copies largest label as an overlay into motion images and movies. * - * Returns nothing. + * Returns nothing. */ void overlay_largest_label(struct context *cnt, unsigned char *out) { @@ -503,7 +503,7 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) struct images *imgs = &cnt->imgs; int *labels = imgs->labels; unsigned char *out_y, *out_u, *out_v; - + i = imgs->motionsize; v = i + ((imgs->motionsize) / 4); width = imgs->width; @@ -516,7 +516,7 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) line = i * width; for (x = 0; x < width; x += 2) { if (labels[line + x] & 32768 || labels[line + x + 1] & 32768 || - labels[line + width + x] & 32768 || + labels[line + width + x] & 32768 || labels[line + width + x + 1] & 32768) { *out_u = 255; @@ -535,8 +535,8 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) } } -/** - * put_picture_mem +/** + * put_picture_mem * Is used for the webcam feature. Depending on the image type * (colour YUV420P or greyscale) the corresponding put_jpeg_X_memory function is called. * Inputs: @@ -550,7 +550,7 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) * converted image it put * * Returns the dest_image_size if successful. Otherwise 0. - */ + */ int put_picture_memory(struct context *cnt, unsigned char* dest_image, int image_size, unsigned char *image, int quality) { @@ -562,8 +562,8 @@ 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(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", - cnt->imgs.type); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", + cnt->imgs.type); } return 0; @@ -582,8 +582,8 @@ 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(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", - cnt->imgs.type); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", + cnt->imgs.type); } } } @@ -617,7 +617,7 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp /** * get_pgm - * Get the pgm file used as fixed mask + * Get the pgm file used as fixed mask * */ unsigned char *get_pgm(FILE *picture, int width, int height) @@ -627,18 +627,18 @@ unsigned char *get_pgm(FILE *picture, int width, int height) unsigned char *image; line[255] = 0; - + if (!fgets(line, 255, picture)) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not read from ppm file"); return NULL; } - + if (strncmp(line, "P5", 2)) { - MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%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'", line); return NULL; } - + /* Skip comment */ line[0] = '#'; while (line[0] == '#') @@ -650,9 +650,9 @@ unsigned char *get_pgm(FILE *picture, int width, int height) MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading size in pgm file"); return NULL; } - + if (x != width || y != height) { - MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%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", x, y, width, height); return NULL; } @@ -662,30 +662,30 @@ unsigned char *get_pgm(FILE *picture, int width, int height) while (line[0] == '#') if (!fgets(line, 255, picture)) return NULL; - + if (sscanf(line, "%d", &maxval) != 1) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading maximum value in pgm file"); return NULL; } - + /* Read data */ - + image = mymalloc(width * height); - + for (y = 0; y < height; y++) { if ((int)fread(&image[y * width], 1, width, picture) != width) MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading image data from pgm file"); - + for (x = 0; x < width; x++) image[y * width + x] = (int)image[y * width + x] * 255 / maxval; - - } + + } return image; } /** - * put_fixed_mask + * put_fixed_mask * If a mask file is asked for but does not exist this function * creates an empty mask file in the right binary pgm format and * and the right size - easy to edit with Gimp or similar tool. @@ -701,7 +701,7 @@ void put_fixed_mask(struct context *cnt, const char *file) /* Report to syslog - suggest solution if the problem is access rights to target dir. */ if (errno == EACCES) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, - "%s: can't write mask file %s - check access rights to target directory", + "%s: can't write mask file %s - check access rights to target directory", file); } else { /* If target dir is temporarily unavailable we may survive. */ @@ -710,18 +710,18 @@ void put_fixed_mask(struct context *cnt, const char *file) return; } memset(cnt->imgs.out, 255, cnt->imgs.motionsize); /* Initialize to unset */ - + /* Write pgm-header. */ fprintf(picture, "P5\n"); fprintf(picture, "%d %d\n", cnt->conf.width, cnt->conf.height); fprintf(picture, "%d\n", 255); - + /* Write pgm image data at once. */ if ((int)fwrite(cnt->imgs.out, cnt->conf.width, cnt->conf.height, picture) != cnt->conf.height) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed writing default mask as pgm file"); return; } - + myfclose(picture); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Creating empty mask %s\nPlease edit this file and " @@ -732,7 +732,7 @@ void put_fixed_mask(struct context *cnt, const char *file) * preview_save * save preview_shot * - * Returns nothing. + * Returns nothing. */ void preview_save(struct context *cnt) { @@ -752,40 +752,40 @@ void preview_save(struct context *cnt) /* Use filename of movie i.o. jpeg_filename when set to 'preview'. */ use_imagepath = strcmp(cnt->conf.imagepath, "preview"); -#ifdef HAVE_FFMPEG - if ((cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) +#ifdef HAVE_FFMPEG + if ((cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) && !use_imagepath) { #else - if ((cnt->conf.useextpipe && cnt->extpipe) && !use_imagepath) { -#endif + if ((cnt->conf.useextpipe && cnt->extpipe) && !use_imagepath) { +#endif if (cnt->conf.useextpipe && cnt->extpipe) { basename_len = strlen(cnt->extpipefilename) + 1; strncpy(previewname, cnt->extpipefilename, basename_len); - previewname[basename_len - 1] = '.'; - } else { + previewname[basename_len - 1] = '.'; + } else { /* Replace avi/mpg with jpg/ppm and keep the rest of the filename. */ basename_len = strlen(cnt->newfilename) - 3; strncpy(previewname, cnt->newfilename, basename_len); - } + } previewname[basename_len] = '\0'; strcat(previewname, imageext(cnt)); put_picture(cnt, previewname, cnt->imgs.preview_image.image , FTYPE_IMAGE); } else { - /* + /* * Save best preview-shot also when no movies are recorded or imagepath - * is used. Filename has to be generated - nothing available to reuse! + * is used. Filename has to be generated - nothing available to reuse! */ MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: different filename or picture only!"); /* - * conf.imagepath would normally be defined but if someone deleted it by - * control interface it is better to revert to the default than fail. + * conf.imagepath would normally be defined but if someone deleted it by + * control interface it is better to revert to the default than fail. */ if (cnt->conf.imagepath) imagepath = cnt->conf.imagepath; else imagepath = (char *)DEF_IMAGEPATH; - + mystrftime(cnt, filename, sizeof(filename), imagepath, &cnt->imgs.preview_image.timestamp_tm, NULL, 0); snprintf(previewname, PATH_MAX, "%s/%s.%s", cnt->conf.filepath, filename, imageext(cnt)); diff --git a/rotate.c b/rotate.c index 793323b..e8796ff 100644 --- a/rotate.c +++ b/rotate.c @@ -4,13 +4,13 @@ * Module for handling image rotation. * * Copyright 2004-2005, Per Jonsson (per@pjd.nu) - * + * * This software is distributed under the GNU Public license * Version 2. See also the file 'COPYING'. * * Image rotation is a feature of Motion that can be used when the * camera is mounted upside-down or on the side. The module only - * supports rotation in multiples of 90 degrees. Using rotation + * supports rotation in multiples of 90 degrees. Using rotation * increases the Motion CPU usage slightly. * * Version history: @@ -22,7 +22,7 @@ * - fixed bug where initialization would be * incomplete for invalid degrees of rotation * - now uses MOTION_LOG for error reporting - * v4 (26-Oct-2004) - new fix for width/height from imgs/conf due to + * v4 (26-Oct-2004) - new fix for width/height from imgs/conf due to * earlier misinterpretation * v3 (11-Oct-2004) - cleanup of width/height from imgs/conf * v2 (26-Sep-2004) - separation of capture/internal dimensions @@ -49,18 +49,18 @@ typedef unsigned TYPE_32BIT __uint32; /** * The code below is copied (with modification) from bits/byteswap.h. It provides - * a macro/function named rot__bswap_32 that swaps the bytes in a 32-bit integer, + * a macro/function named rot__bswap_32 that swaps the bytes in a 32-bit integer, * preferably using the bswap assembler instruction if configure found support * for it. * * It would be neater to simply include byteswap.h and use the bswap_32 macro * defined there, but the problem is that the bswap asm instruction would then - * only be used for certain processor architectures, excluding athlon (and + * only be used for certain processor architectures, excluding athlon (and * probably athlon64 as well). Moreover, byteswap.h doesn't seem to exist on * FreeBSD. So, we rely on the HAVE_BSWAP macro defined by configure instead. * - * Note that the macro names have been prefixed with "rot" in order to avoid - * collision since we have the include chain rotate.h -> motion.h -> netcam.h -> + * Note that the macro names have been prefixed with "rot" in order to avoid + * collision since we have the include chain rotate.h -> motion.h -> netcam.h -> * netinet/in.h -> ... -> byteswap.h -> bits/byteswap.h. */ @@ -71,8 +71,8 @@ typedef unsigned TYPE_32BIT __uint32; #ifdef __GNUC__ # if (__GNUC__ >= 2) && (i386 || __i386 || __i386__) -/* We're on an Intel-compatible platform, so we can use inline Intel assembler - * for the swapping. +/* We're on an Intel-compatible platform, so we can use inline Intel assembler + * for the swapping. */ # ifndef HAVE_BSWAP /* Bswap is not available, we have to use three instructions instead. */ @@ -108,7 +108,7 @@ typedef unsigned TYPE_32BIT __uint32; # endif #else /* Not a GNU compiler. */ -static inline __uint32 rot__bswap_32(__uint32 __bsx) +static inline __uint32 rot__bswap_32(__uint32 __bsx) { return __bswap_constant_32 (__bsx); } @@ -123,18 +123,18 @@ static inline __uint32 rot__bswap_32(__uint32 __bsx) /** * reverse_inplace_quad - * + * * Reverses a block of memory in-place, 4 bytes at a time. This function * requires the __uint32 type, which is 32 bits wide. * * Parameters: - * + * * src - the memory block to reverse * size - the size (in bytes) of the memory block * * Returns: nothing */ -static void reverse_inplace_quad(unsigned char *src, int size) +static void reverse_inplace_quad(unsigned char *src, int size) { __uint32 *nsrc = (__uint32 *)src; /* first quad */ __uint32 *ndst = (__uint32 *)(src + size - 4); /* last quad */ @@ -149,13 +149,13 @@ static void reverse_inplace_quad(unsigned char *src, int size) /** * rot90cw - * - * Performs a 90 degrees clockwise rotation of the memory block pointed to - * by src. The rotation is NOT performed in-place; dst must point to a + * + * Performs a 90 degrees clockwise rotation of the memory block pointed to + * by src. The rotation is NOT performed in-place; dst must point to a * receiving memory block the same size as src. * * Parameters: - * + * * src - pointer to the memory block (image) to rotate clockwise * dst - where to put the rotated memory block * size - the size (in bytes) of the memory blocks (both src and dst) @@ -165,7 +165,7 @@ static void reverse_inplace_quad(unsigned char *src, int size) * Returns: nothing */ static void rot90cw(unsigned char *src, register unsigned char *dst, int size, - int width, int height) + int width, int height) { unsigned char *endp; register unsigned char *base; @@ -174,21 +174,21 @@ static void rot90cw(unsigned char *src, register unsigned char *dst, int size, endp = src + size; for (base = endp - width; base < endp; base++) { src = base; - for (j = 0; j < height; j++, src -= width) + for (j = 0; j < height; j++, src -= width) *dst++ = *src; - + } } /** * rot90ccw - * + * * Performs a 90 degrees counterclockwise rotation of the memory block pointed - * to by src. The rotation is not performed in-place; dst must point to a - * receiving memory block the same size as src. + * to by src. The rotation is not performed in-place; dst must point to a + * receiving memory block the same size as src. * * Parameters: - * + * * src - pointer to the memory block (image) to rotate counterclockwise * dst - where to put the rotated memory block * size - the size (in bytes) of the memory blocks (both src and dst) @@ -198,7 +198,7 @@ static void rot90cw(unsigned char *src, register unsigned char *dst, int size, * Returns: nothing */ static inline void rot90ccw(unsigned char *src, register unsigned char *dst, - int size, int width, int height) + int size, int width, int height) { unsigned char *endp; register unsigned char *base; @@ -208,28 +208,28 @@ static inline void rot90ccw(unsigned char *src, register unsigned char *dst, dst = dst + size - 1; for (base = endp - width; base < endp; base++) { src = base; - for (j = 0; j < height; j++, src -= width) + for (j = 0; j < height; j++, src -= width) *dst-- = *src; - + } } /** * rotate_init - * + * * Initializes rotation data - allocates memory and determines which function * to use for 180 degrees rotation. * * Parameters: - * + * * cnt - the current thread's context structure * * Returns: nothing */ -void rotate_init(struct context *cnt) +void rotate_init(struct context *cnt) { int size; - + /* Make sure temp_buf isn't freed if it hasn't been allocated. */ cnt->rotate_data.temp_buf = NULL; @@ -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(ERR, TYPE_ALL, NO_ERRNO, "%s: Config option \"rotate\" not a multiple of 90: %d", + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Config option \"rotate\" not a multiple of 90: %d", cnt->conf.rotate_deg); cnt->conf.rotate_deg = 0; /* Disable rotation. */ cnt->rotate_data.degrees = 0; /* Force return below. */ @@ -248,8 +248,8 @@ void rotate_init(struct context *cnt) /* * Upon entrance to this function, imgs.width and imgs.height contain the - * capture dimensions (as set in the configuration file, or read from a - * netcam source). + * capture dimensions (as set in the configuration file, or read from a + * netcam source). * * If rotating 90 or 270 degrees, the capture dimensions and output dimensions * are not the same. Capture dimensions will be contained in cap_width and @@ -271,19 +271,19 @@ void rotate_init(struct context *cnt) * If we're not rotating, let's exit once we have setup the capture dimensions * and output dimensions properly. */ - if (cnt->rotate_data.degrees == 0) + if (cnt->rotate_data.degrees == 0) return; switch (cnt->imgs.type) { case VIDEO_PALETTE_YUV420P: /* * For YUV 4:2:0 planar, the memory block used for 90/270 degrees - * rotation needs to be width x height x 1.5 bytes large. + * rotation needs to be width x height x 1.5 bytes large. */ size = cnt->imgs.width * cnt->imgs.height * 3 / 2; break; case VIDEO_PALETTE_GREY: - /* + /* * For greyscale, the memory block used for 90/270 degrees rotation * needs to be width x height bytes large. */ @@ -291,61 +291,61 @@ void rotate_init(struct context *cnt) break; default: cnt->rotate_data.degrees = 0; - MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported palette (%d), rotation is disabled", + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Unsupported palette (%d), rotation is disabled", cnt->imgs.type); return; } /* - * Allocate memory if rotating 90 or 270 degrees, because those rotations + * Allocate memory if rotating 90 or 270 degrees, because those rotations * cannot be performed in-place (they can, but it would be too slow). */ - if ((cnt->rotate_data.degrees == 90) || (cnt->rotate_data.degrees == 270)) + if ((cnt->rotate_data.degrees == 90) || (cnt->rotate_data.degrees == 270)) cnt->rotate_data.temp_buf = mymalloc(size); } -/** +/** * rotate_deinit - * - * Frees resources previously allocated by rotate_init. + * + * Frees resources previously allocated by rotate_init. * * Parameters: - * + * * cnt - the current thread's context structure * * Returns: nothing */ -void rotate_deinit(struct context *cnt) +void rotate_deinit(struct context *cnt) { - if (cnt->rotate_data.temp_buf) + if (cnt->rotate_data.temp_buf) free(cnt->rotate_data.temp_buf); } /** * rotate_map - * + * * Main entry point for rotation. This is the function that is called from * video.c/video_freebsd.c to perform the rotation. * * Parameters: - * + * * map - pointer to the image/data to rotate * cnt - the current thread's context structure * - * Returns: - * + * Returns: + * * 0 - success * -1 - failure (shouldn't happen) */ int rotate_map(struct context *cnt, unsigned char *map) { /* - * The image format is either YUV 4:2:0 planar, in which case the pixel + * The image format is either YUV 4:2:0 planar, in which case the pixel * data is divided in three parts: * Y - width x height bytes * U - width x height / 4 bytes * V - as U - * or, it is in greyscale, in which case the pixel data simply consists + * or, it is in greyscale, in which case the pixel data simply consists * of width x height bytes. */ int wh, wh4 = 0, w2 = 0, h2 = 0; /* width * height, width * height / 4 etc. */ @@ -384,11 +384,11 @@ int rotate_map(struct context *cnt, unsigned char *map) rot90cw(map + wh + wh4, cnt->rotate_data.temp_buf + wh + wh4, wh4, w2, h2); } - + /* Then copy back from the temp buffer to map. */ memcpy(map, cnt->rotate_data.temp_buf, size); break; - + case 180: /* * 180 degrees is easy - just reverse the data within @@ -408,19 +408,19 @@ int rotate_map(struct context *cnt, unsigned char *map) if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { /* Then do U and V */ rot90ccw(map + wh, cnt->rotate_data.temp_buf + wh, wh4, w2, h2); - rot90ccw(map + wh + wh4, cnt->rotate_data.temp_buf + wh + wh4, + rot90ccw(map + wh + wh4, cnt->rotate_data.temp_buf + wh + wh4, wh4, w2, h2); } - + /* Then copy back from the temp buffer to map. */ memcpy(map, cnt->rotate_data.temp_buf, size); break; - + default: /* Invalid */ return -1; } - + return 0; } diff --git a/stream.c b/stream.c index 581760a..8f8d6a5 100644 --- a/stream.c +++ b/stream.c @@ -42,9 +42,9 @@ struct auth_param { pthread_mutex_t stream_auth_mutex; /** - * set_sock_timeout + * set_sock_timeout * - * Returns : 0 or 1 on timeout + * Returns : 0 or 1 on timeout */ static int set_sock_timeout(int sock, int sec) { @@ -54,16 +54,16 @@ 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(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: set socket timeout failed"); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: set socket timeout failed"); return 1; } return 0; } /** - * read_http_request + * read_http_request + * * - * * Returns : 1 on success or 0 if any error happens */ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int uri_len) @@ -90,19 +90,19 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int "Request Timeout\n"; buffer[0] = '\0'; - + while ((strstr(buffer, "\r\n\r\n") == NULL) && (readb != 0) && (nread < buflen)) { - + readb = read(sock, buffer+nread, buflen - nread); - if (readb == -1) { + if (readb == -1) { nread = -1; break; } nread += readb; - if (nread > buflen) { + if (nread > buflen) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream End buffer reached" " waiting for buffer ending"); break; @@ -111,38 +111,38 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int buffer[nread] = '\0'; } - /* + /* * Make sure the last read didn't fail. If it did, there's a - * problem with the connection, so give up. + * problem with the connection, so give up. */ if (nread == -1) { if(errno == EAGAIN) { // Timeout ret = write(sock, timeout_response_template_raw, strlen(timeout_response_template_raw)); - return 0; + return 0; } - + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream READ give up!"); return 0; } - + ret = sscanf(buffer, "%9s %511s %9s", method, url, protocol); - - if (ret != 3) { + + if (ret != 3) { ret = write(sock, bad_request_response_raw, sizeof(bad_request_response_raw)); return 0; } /* Check Protocol */ - if (strcmp(protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) { + if (strcmp(protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) { /* We don't understand this protocol. Report a bad response. */ ret = write(sock, bad_request_response_raw, sizeof(bad_request_response_raw)); return 0; } if (strcmp(method, "GET")) { - /* + /* * This server only implements the GET method. If client - * uses other method, report the failure. + * uses other method, report the failure. */ char response[1024]; snprintf(response, sizeof(response), bad_method_response_template_raw, method); @@ -163,7 +163,7 @@ static void stream_add_client(struct stream *list, int sc); * handle_basic_auth * * - */ + */ static void* handle_basic_auth(void* param) { struct auth_param *p = (struct auth_param*)param; @@ -179,30 +179,30 @@ static void* handle_basic_auth(void* param) "Cache-Control: no-cache, private\r\n" "Pragma: no-cache\r\n" "WWW-Authenticate: Basic realm=\""STREAM_REALM"\"\r\n\r\n"; - + pthread_mutex_lock(&stream_auth_mutex); p->thread_count++; pthread_mutex_unlock(&stream_auth_mutex); if (!read_http_request(p->sock,buffer, length, NULL, 0)) goto Invalid_Request; - + auth = strstr(buffer, "Authorization: Basic"); - + if (!auth) goto Error; auth += sizeof("Authorization: Basic"); h = strstr(auth, "\r\n"); - + if(!h) goto Error; *h='\0'; if (p->conf->stream_authentication != NULL) { - + char *userpass = NULL; size_t auth_size = strlen(p->conf->stream_authentication); @@ -231,7 +231,7 @@ static void* handle_basic_auth(void* param) /* Lock the mutex */ pthread_mutex_lock(&stream_auth_mutex); - + stream_add_client(&p->cnt->stream, p->sock); p->cnt->stream_count++; p->thread_count--; @@ -264,7 +264,7 @@ typedef char HASHHEX[HASHHEXLEN+1]; #define IN #define OUT /** - * CvtHex + * CvtHex * Calculates H(A1) as per HTTP Digest spec -- taken from RFC 2617. */ static void CvtHex(IN HASH Bin, OUT HASHHEX Hex) @@ -287,8 +287,8 @@ static void CvtHex(IN HASH Bin, OUT HASHHEX Hex) Hex[HASHHEXLEN] = '\0'; }; -/** - * DigestCalcHA1 +/** + * DigestCalcHA1 * Calculates H(A1) as per spec. */ static void DigestCalcHA1( @@ -324,8 +324,8 @@ static void DigestCalcHA1( CvtHex(HA1, SessionKey); }; -/** - * DigestCalcResponse +/** + * DigestCalcResponse * Calculates request-digest/response-digest as per HTTP Digest spec. */ static void DigestCalcResponse( @@ -344,13 +344,13 @@ static void DigestCalcResponse( HASH HA2; HASH RespHash; HASHHEX HA2Hex; - + // Calculate H(A2) MD5Init(&Md5Ctx); MD5Update(&Md5Ctx, (unsigned char *)pszMethod, strlen(pszMethod)); MD5Update(&Md5Ctx, (unsigned char *)":", 1); MD5Update(&Md5Ctx, (unsigned char *)pszDigestUri, strlen(pszDigestUri)); - + if (strcmp(pszQop, "auth-int") == 0) { MD5Update(&Md5Ctx, (unsigned char *)":", 1); MD5Update(&Md5Ctx, (unsigned char *)HEntity, HASHHEXLEN); @@ -383,7 +383,7 @@ static void DigestCalcResponse( * handle_md5_digest * * - */ + */ static void* handle_md5_digest(void* param) { struct auth_param *p = (struct auth_param*)param; @@ -430,7 +430,7 @@ static void* handle_md5_digest(void* param) "\r\n" "

500 Internal Server Error

\r\n" "\r\n"; - + pthread_mutex_lock(&stream_auth_mutex); p->thread_count++; pthread_mutex_unlock(&stream_auth_mutex); @@ -440,13 +440,13 @@ static void* handle_md5_digest(void* param) rand1 = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); rand2 = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); snprintf(server_nonce, SERVER_NONCE_LEN, "%08x%08x", rand1, rand2); - + if (!p->conf->stream_authentication) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data"); goto InternalError; } h = strstr(p->conf->stream_authentication, ":"); - + if (!h) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data (no ':' found)"); goto InternalError; @@ -454,7 +454,7 @@ static void* handle_md5_digest(void* param) server_user = (char*)malloc((h - p->conf->stream_authentication) + 1); server_pass = (char*)malloc(strlen(h) + 1); - + if (!server_user || !server_pass) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error malloc failed"); goto InternalError; @@ -468,85 +468,85 @@ static void* handle_md5_digest(void* param) while(1) { 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; auth += sizeof("Authorization: Digest"); h = strstr(auth, "\r\n"); - + if (!h) goto Error; *h = '\0'; // Username h=strstr(auth, "username=\""); - + if (!h) goto Error; - + username = h + 10; h = strstr(username + 1, "\""); - + if (!h) goto Error; - + username_len = h - username; // Realm h = strstr(auth, "realm=\""); if (!h) goto Error; - + realm = h + 7; h = strstr(realm + 1, "\""); - + if (!h) goto Error; - + realm_len = h - realm; // URI h = strstr(auth, "uri=\""); - + if (!h) goto Error; - + uri = h + 5; h = strstr(uri + 1, "\""); - + if (!h) goto Error; - + uri_len = h - uri; // Nonce h = strstr(auth, "nonce=\""); - + if (!h) goto Error; - + nonce = h + 7; h = strstr(nonce + 1, "\""); - + if (!h) goto Error; - + nonce_len = h - nonce; // Response h = strstr(auth, "response=\""); - + if (!h) goto Error; - + response = h + 10; h = strstr(response + 1, "\""); - + if (!h) goto Error; - + response_len = h - response; username[username_len] = '\0'; @@ -565,12 +565,12 @@ static void* handle_md5_digest(void* param) rand2 = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); snprintf(server_nonce, SERVER_NONCE_LEN, "%08x%08x", rand1, rand2); snprintf(buffer, length, "%s realm=\""STREAM_REALM"\", nonce=\"%s\"\r\n" - "Content-Type: text/html\r\n" - "Keep-Alive: timeout=%i\r\n" - "Connection: keep-alive\r\n" - "Content-Length: %Zu\r\n\r\n", - request_auth_response_template, server_nonce, - KEEP_ALIVE_TIMEOUT, strlen(auth_failed_html_template)); + "Content-Type: text/html\r\n" + "Keep-Alive: timeout=%i\r\n" + "Connection: keep-alive\r\n" + "Content-Length: %Zu\r\n\r\n", + request_auth_response_template, server_nonce, + KEEP_ALIVE_TIMEOUT, strlen(auth_failed_html_template)); ret = write(p->sock, buffer, strlen(buffer)); ret = write(p->sock, auth_failed_html_template, strlen(auth_failed_html_template)); } @@ -585,7 +585,7 @@ static void* handle_md5_digest(void* param) if(server_user) free(server_user); - + if(server_pass) free(server_pass); @@ -601,11 +601,11 @@ static void* handle_md5_digest(void* param) free(p); pthread_exit(NULL); - + InternalError: if(server_user) free(server_user); - + if(server_pass) free(server_pass); @@ -636,33 +636,33 @@ static void do_client_auth(struct context *cnt, int sc) int flags; static int first_call = 0; static int thread_count = 0; - + if(first_call == 0) { first_call = 1; /* Initialize the mutex */ pthread_mutex_init(&stream_auth_mutex, NULL); } - + switch(cnt->conf.stream_auth_method) { case 1: // Basic - handle_func = handle_basic_auth; - break; + handle_func = handle_basic_auth; + break; case 2: // MD5 Digest - handle_func = handle_md5_digest; - break; + handle_func = handle_md5_digest; + break; default: - MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error unknown stream authentication method"); - goto Error; - break; + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error unknown stream authentication method"); + goto Error; + break; } - + handle_param = mymalloc(sizeof(struct auth_param)); handle_param->cnt = cnt; handle_param->sock = sc; handle_param->conf = &cnt->conf; handle_param->thread_count = &thread_count; - + /* Set socket to blocking */ if ((flags = fcntl(sc, F_GETFL, 0)) < 0) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl"); @@ -677,7 +677,7 @@ static void do_client_auth(struct context *cnt, int sc) if (thread_count >= DEF_MAXSTREAMS) goto Error; - + if (pthread_attr_init(&attr)) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_init"); goto Error; @@ -693,15 +693,15 @@ static void do_client_auth(struct context *cnt, int sc) MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_destroy"); return; - + Error: close(sc); if(handle_param) free(handle_param); } -/** - * http_bindsock +/** + * http_bindsock * Sets up a TCP/IP socket for incoming requests. It is called only during * initialisation of Motion from the function stream_init * The function sets up a a socket on the port number given by _port_. @@ -734,9 +734,9 @@ int http_bindsock(int port, int local, int ipv6_enabled) optval = getaddrinfo(local ? "localhost" : NULL, portnumber, &hints, &res); if (optval != 0) { - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for motion-stream socket failed: %s", + MOTION_LOG(CRT, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for motion-stream socket failed: %s", gai_strerror(optval)); - + if (res != NULL) freeaddrinfo(res); return -1; @@ -753,36 +753,36 @@ int http_bindsock(int port, int local, int ipv6_enabled) if (sl >= 0) { optval = 1; - /* Reuse Address */ + /* Reuse Address */ setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)); - MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-stream testing : %s addr: %s port: %s", + MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO, "%s: motion-stream testing : %s addr: %s port: %s", res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); if (bind(sl, res->ai_addr, res->ai_addrlen) == 0) { - MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-stream Bound : %s addr: %s port: %s", - res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); + MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO, "%s: motion-stream Bound : %s addr: %s port: %s", + res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); break; } - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream bind() failed, retrying"); + MOTION_LOG(CRT, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream bind() failed, retrying"); close(sl); sl = -1; } - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream socket failed, retrying"); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream socket failed, retrying"); res = res->ai_next; } freeaddrinfo(ressave); if (sl < 0) { - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream creating socket/bind ERROR"); + MOTION_LOG(CRT, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream creating socket/bind ERROR"); return -1; } - + if (listen(sl, DEF_MAXWEBQUEUE) == -1) { - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream listen() ERROR"); + MOTION_LOG(CRT, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream listen() ERROR"); close(sl); sl = -1; } @@ -808,15 +808,15 @@ static int http_acceptsock(int sl) ioctl(sc, FIONBIO, &i); return sc; } - - MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream accept()"); + + MOTION_LOG(CRT, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream accept()"); return -1; } -/** - * stream_flush +/** + * stream_flush * Sends any outstanding data to all connected clients. * It continuously goes through the client list until no data is able * to be sent (either because there isn't any, or because the clients @@ -832,11 +832,11 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) client = list->next; while (client) { - + /* If data waiting for client, try to send it. */ if (client->tmpbuffer) { - - /* + + /* * We expect that list->filepos < list->tmpbuffer->size * should always be true. The check is more for safety, * in case of trouble is some other part of the code. @@ -844,8 +844,8 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) * clean up. */ if (client->filepos < client->tmpbuffer->size) { - - /* + + /* * Here we are finally ready to write out the * data. Remember that (because the socket * has been set non-blocking) we may only @@ -853,11 +853,11 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) * 'filepos' contains how much of the buffer * has already been written. */ - written = write(client->socket, + written = write(client->socket, client->tmpbuffer->ptr + client->filepos, client->tmpbuffer->size - client->filepos); - - /* + + /* * If any data has been written, update the * data pointer and set the workdone flag. */ @@ -867,8 +867,8 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) } } else written = 0; - - /* + + /* * If we have written the entire buffer to the socket, * or if there was some error (other than EAGAIN, which * means the system couldn't take it), this request is @@ -881,12 +881,12 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) free(client->tmpbuffer->ptr); free(client->tmpbuffer); } - + /* Mark this client's buffer as empty. */ client->tmpbuffer = NULL; client->nr++; } - + /* * If the client is no longer connected, or the total * number of frames already sent to this client is @@ -898,10 +898,10 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) void *tmp; close(client->socket); - + if (client->next) client->next->prev = client->prev; - + client->prev->next = client->next; tmp = client; client = client->prev; @@ -909,8 +909,8 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) (*stream_count)--; } } /* End if (client->tmpbuffer) */ - - /* + + /* * Step the the next client in the list. If we get to the * end of the list, check if anything was written during * that loop; (if so) reset the 'workdone' flag and go back @@ -926,7 +926,7 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) } /** - * stream_tmpbuffer + * stream_tmpbuffer * Routine to create a new "tmpbuffer", which is a common * object used by all clients connected to a single camera. * @@ -937,7 +937,7 @@ static struct stream_buffer *stream_tmpbuffer(int size) struct stream_buffer *tmpbuffer = mymalloc(sizeof(struct stream_buffer)); tmpbuffer->ref = 0; tmpbuffer->ptr = mymalloc(size); - + return tmpbuffer; } @@ -961,20 +961,20 @@ static void stream_add_client(struct stream *list, int sc) memset(new, 0, sizeof(struct stream)); new->socket = sc; - + if ((new->tmpbuffer = stream_tmpbuffer(sizeof(header))) == NULL) { MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer in stream_add_client"); } else { memcpy(new->tmpbuffer->ptr, header, sizeof(header)-1); new->tmpbuffer->size = sizeof(header)-1; } - + new->prev = list; new->next = list->next; - + if (new->next) new->next->prev = new; - + list->next = new; } @@ -990,10 +990,10 @@ static void stream_add_write(struct stream *list, struct stream_buffer *tmpbuffe gettimeofday(&curtimeval, NULL); curtime = curtimeval.tv_usec + 1000000L * curtimeval.tv_sec; - + while (list->next) { list = list->next; - + if (list->tmpbuffer == NULL && ((curtime - list->last) >= 1000000L / fps)) { list->last = curtime; list->tmpbuffer = tmpbuffer; @@ -1001,7 +1001,7 @@ static void stream_add_write(struct stream *list, struct stream_buffer *tmpbuffe list->filepos = 0; } } - + if (tmpbuffer->ref <= 0) { free(tmpbuffer->ptr); free(tmpbuffer); @@ -1010,19 +1010,19 @@ static void stream_add_write(struct stream *list, struct stream_buffer *tmpbuffe /** - * stream_check_write + * stream_check_write * We walk through the chain of stream structs until we reach the end. * Here we check if the tmpbuffer points to NULL. * We return 1 if it finds a list->tmpbuffer which is a NULL pointer which would * be the next client ready to be sent a new image. If not a 0 is returned. * - * Returns: + * Returns: */ static int stream_check_write(struct stream *list) { while (list->next) { list = list->next; - + if (list->tmpbuffer == NULL) return 1; } @@ -1031,7 +1031,7 @@ static int stream_check_write(struct stream *list) /** - * stream_init + * stream_init * This function is called from motion.c for each motion thread starting up. * The function setup the incoming tcp socket that the clients connect to. * The function returns an integer representing the socket. @@ -1040,7 +1040,7 @@ static int stream_check_write(struct stream *list) */ int stream_init(struct context *cnt) { - cnt->stream.socket = http_bindsock(cnt->conf.stream_port, cnt->conf.stream_localhost, + cnt->stream.socket = http_bindsock(cnt->conf.stream_port, cnt->conf.stream_localhost, cnt->conf.ipv6_enabled); cnt->stream.next = NULL; cnt->stream.prev = NULL; @@ -1048,40 +1048,40 @@ int stream_init(struct context *cnt) } /** - * stream_stop + * stream_stop * This function is called from the motion_loop when it ends * and motion is terminated or restarted. */ void stream_stop(struct context *cnt) -{ +{ struct stream *list; struct stream *next = cnt->stream.next; - MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: Closing motion-stream listen socket" + MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO, "%s: Closing motion-stream listen socket" " & active motion-stream sockets"); - + close(cnt->stream.socket); cnt->stream.socket = -1; while (next) { list = next; next = list->next; - + if (list->tmpbuffer) { free(list->tmpbuffer->ptr); free(list->tmpbuffer); } - + close(list->socket); free(list); } - MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: Closed motion-stream listen socket" + MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO, "%s: Closed motion-stream listen socket" " & active motion-stream sockets"); } /* - * stream_put + * stream_put * Is the starting point of the stream loop. It is called from * the motion_loop with the argument 'image' pointing to the latest frame. * If config option 'stream_motion' is 'on' this function is called once @@ -1098,7 +1098,7 @@ void stream_stop(struct context *cnt) */ void stream_put(struct context *cnt, unsigned char *image) { - struct timeval timeout; + struct timeval timeout; struct stream_buffer *tmpbuffer; fd_set fdread; int sl = cnt->stream.socket; @@ -1109,8 +1109,8 @@ void stream_put(struct context *cnt, unsigned char *image) "Content-Length: "; int headlength = sizeof(jpeghead) - 1; /* Don't include terminator. */ char len[20]; /* Will be used for sprintf, must be >= 16 */ - - /* + + /* * Timeout struct used to timeout the time we wait for a client * and we do not wait at all. */ @@ -1118,8 +1118,8 @@ void stream_put(struct context *cnt, unsigned char *image) timeout.tv_usec = 0; FD_ZERO(&fdread); FD_SET(cnt->stream.socket, &fdread); - - /* + + /* * If we have not reached the max number of allowed clients per * thread we will check to see if new clients are waiting to connect. * If this is the case we add the client as a new stream struct and @@ -1129,44 +1129,44 @@ void stream_put(struct context *cnt, unsigned char *image) if ((cnt->stream_count < DEF_MAXSTREAMS) && (select(sl + 1, &fdread, NULL, NULL, &timeout) > 0)) { sc = http_acceptsock(sl); - if (cnt->conf.stream_auth_method == 0) { - stream_add_client(&cnt->stream, sc); + if (cnt->conf.stream_auth_method == 0) { + stream_add_client(&cnt->stream, sc); cnt->stream_count++; - } else { - do_client_auth(cnt, sc); - } + } else { + do_client_auth(cnt, sc); + } } - + /* Lock the mutex */ if (cnt->conf.stream_auth_method != 0) pthread_mutex_lock(&stream_auth_mutex); - + /* Call flush to send any previous partial-sends which are waiting. */ stream_flush(&cnt->stream, &cnt->stream_count, cnt->conf.stream_limit); - + /* Check if any clients have available buffers. */ if (stream_check_write(&cnt->stream)) { - /* + /* * Yes - create a new tmpbuffer for current image. * Note that this should create a buffer which is *much* larger * than necessary, but it is difficult to estimate the * minimum size actually required. */ tmpbuffer = stream_tmpbuffer(cnt->imgs.size); - + /* Check if allocation was ok. */ if (tmpbuffer) { int imgsize; - /* + /* * We need a pointer that points to the picture buffer * just after the mjpeg header. We create a working pointer wptr * to be used in the call to put_picture_memory which we can change * and leave tmpbuffer->ptr intact. */ unsigned char *wptr = tmpbuffer->ptr; - + /* * For web protocol, our image needs to be preceded * with a little HTTP, so we put that into the buffer @@ -1184,17 +1184,17 @@ void stream_put(struct context *cnt, unsigned char *image) /* Fill in the image length into the header. */ imgsize = sprintf(len, "%9ld\r\n\r\n", tmpbuffer->size); memcpy(wptr - imgsize, len, imgsize); - + /* Append a CRLF for good measure. */ memcpy(wptr + tmpbuffer->size, "\r\n", 2); - - /* + + /* * Now adjust tmpbuffer->size to reflect the * header at the beginning and the extra CRLF * at the end. */ tmpbuffer->size += headlength + 2; - + /* * And finally put this buffer to all clients with * no outstanding data from previous frames. @@ -1204,13 +1204,13 @@ void stream_put(struct context *cnt, unsigned char *image) MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer"); } } - - /* + + /* * Now we call flush again. This time (assuming some clients were * ready for the new frame) the new data will be written out. */ stream_flush(&cnt->stream, &cnt->stream_count, cnt->conf.stream_limit); - + /* Unlock the mutex */ if (cnt->conf.stream_auth_method != 0) pthread_mutex_unlock(&stream_auth_mutex); diff --git a/track.c b/track.c index 2f82ebc..5f8dc12 100644 --- a/track.c +++ b/track.c @@ -48,23 +48,23 @@ static unsigned int stepper_center(struct context *cnt, int xoff, int yoff ATTRI static unsigned int iomojo_center(struct context *cnt, int xoff, int yoff); static unsigned int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs); -static unsigned int servo_move(struct context *cnt, struct coord *cent, +static unsigned int servo_move(struct context *cnt, struct coord *cent, struct images *imgs, unsigned int manual); static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs); #ifndef WITHOUT_V4L static unsigned int lqos_center(struct context *cnt, int dev, int xoff, int yoff); -static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual); #ifdef MOTION_V4L2 static unsigned int uvc_center(struct context *cnt, int dev, int xoff, int yoff); -static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual); #endif /* MOTION_V4L2 */ #endif /* WITHOUT_V4L */ /* Add a call to your functions here: */ -unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, +unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, unsigned int manual, int xoff, int yoff) { if (!manual && !cnt->track.active) @@ -74,14 +74,14 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, unsigned int ret; ret = stepper_center(cnt, xoff, yoff); if (!ret) { - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error"); - return 0; + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error"); + return 0; } - else return ret; + else return ret; } else if (cnt->track.type == TRACK_TYPE_SERVO) { return servo_center(cnt, xoff, yoff); - } -#ifndef WITHOUT_V4L + } +#ifndef WITHOUT_V4L else if (cnt->track.type == TRACK_TYPE_PWC) return lqos_center(cnt, dev, xoff, yoff); #ifdef MOTION_V4L2 @@ -94,14 +94,14 @@ 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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", cnt->track.type); return 0; } /* Add a call to your functions here: */ -unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, +unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual) { @@ -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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", + MOTION_LOG(WRN, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", cnt->track.type); return 0; @@ -137,7 +137,7 @@ unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct http://www.lavrsen.dk/twiki/bin/view/Motion/MotionTrackerAPI ******************************************************************************/ -static unsigned int stepper_command(struct context *cnt, unsigned int motor, +static unsigned int stepper_command(struct context *cnt, unsigned int motor, unsigned int command, unsigned int data) { char buffer[3]; @@ -176,9 +176,9 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs if (cnt->track.dev < 0) { MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Try to open serial device %s", cnt->track.port); - + if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", cnt->track.port); return 0; } @@ -193,17 +193,17 @@ 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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", cnt->track.port); - cnt->track.dev = -1; + cnt->track.dev = -1; return 0; } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", cnt->track.port, cnt->track.dev); } /* x-axis */ - + stepper_command(cnt, cnt->track.motorx, STEPPER_COMMAND_SPEED, cnt->track.speed); stepper_command(cnt, cnt->track.motorx, STEPPER_COMMAND_LEFT_N, cnt->track.maxx); @@ -220,36 +220,36 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs stepper_command(cnt, cnt->track.motory, STEPPER_COMMAND_UP_N, cnt->track.maxy); while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_UP) - + stepper_command(cnt, cnt->track.motory, STEPPER_COMMAND_DOWN_N, cnt->track.maxy / 2 + y_offset * cnt->track.stepsize); - + while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_DOWN); - + return cnt->track.move_wait; } -static unsigned int stepper_move(struct context *cnt, +static unsigned int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs) { unsigned int command = 0, data = 0; if (cnt->track.dev < 0) { - MOTION_LOG(WRN, TYPE_TRACK, NO_ERRNO, "%s: No device %s started yet , trying stepper_center()", - cnt->track.port); + MOTION_LOG(WRN, TYPE_TRACK, NO_ERRNO, "%s: No device %s started yet , trying stepper_center()", + cnt->track.port); if (!stepper_center(cnt, 0, 0)) { - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed to initialize stepper device on %s , fd [%i].", - cnt->track.port, cnt->track.dev); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: failed to initialize stepper device on %s , fd [%i].", + cnt->track.port, cnt->track.dev); return 0; } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: succeed , device started %s , fd [%i]", - cnt->track.port, cnt->track.dev); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: succeed , device started %s , fd [%i]", + cnt->track.port, cnt->track.dev); } /* x-axis */ - + if (cent->x < imgs->width / 2) { command = STEPPER_COMMAND_LEFT_N; data = imgs->width / 2 - cent->x; @@ -275,13 +275,13 @@ static unsigned int stepper_move(struct context *cnt, command = STEPPER_COMMAND_DOWN_N; data = cent->y - imgs->height / 2; } - + data = data * cnt->track.stepsize / imgs->height; - if (data) - stepper_command(cnt, cnt->track.motory, command, data); - - + if (data) + stepper_command(cnt, cnt->track.motory, command, data); + + return cnt->track.move_wait; } @@ -296,7 +296,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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", cnt->track.port); return 0; } @@ -311,20 +311,20 @@ static int servo_open(struct context *cnt) tcflush (cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: Unable to initialize serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: Unable to initialize serial device %s", cnt->track.port); - cnt->track.dev = -1; + cnt->track.dev = -1; return 0; } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", cnt->track.port, cnt->track.dev); return 1; } -static unsigned int servo_command(struct context *cnt, unsigned int motor, +static unsigned int servo_command(struct context *cnt, unsigned int motor, unsigned int command, unsigned int data) { unsigned char buffer[3]; @@ -345,14 +345,14 @@ static unsigned int servo_command(struct context *cnt, unsigned int motor, } while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1); - + if (time(NULL) >= timeout + 2) { MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: Status byte timeout!"); return 0; } MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Command return %d", buffer[0]); - + return buffer[0]; } @@ -372,8 +372,8 @@ static unsigned int servo_position(struct context *cnt, unsigned int motor) * servo_move * Does relative movements to current position. * - */ -static unsigned int servo_move(struct context *cnt, struct coord *cent, + */ +static unsigned int servo_move(struct context *cnt, struct coord *cent, struct images *imgs, unsigned int manual) { unsigned int command = 0; @@ -383,13 +383,13 @@ 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(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); return 0; } } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: cent->x %d, cent->y %d, reversex %d," - "reversey %d manual %d", cent->x , cent->y, + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: cent->x %d, cent->y %d, reversex %d," + "reversey %d manual %d", cent->x , cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, manual); if (manual) { @@ -400,19 +400,19 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, offset = cent->x * cnt->track.stepsize; - if ((cnt->track.motorx_reverse && (offset > 0)) || - (!cnt->track.motorx_reverse && (offset < 0))) + if ((cnt->track.motorx_reverse && (offset > 0)) || + (!cnt->track.motorx_reverse && (offset < 0))) command = SERVO_COMMAND_LEFT_N; - else + else command = SERVO_COMMAND_RIGHT_N; data = abs(offset); - if ((data + position > (unsigned)cnt->track.maxx) || - (position - offset < (unsigned)cnt->track.minx)) { - MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", + if ((data + position > (unsigned)cnt->track.maxx) || + (position - offset < (unsigned)cnt->track.minx)) { + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", data, cnt->track.minx, cnt->track.maxx); - return 0; + return 0; } /* Set Speed , TODO : it should be done only when speed changes */ @@ -423,9 +423,9 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if (cent->y) { position = servo_position(cnt, cnt->track.motory); - offset = cent->y * cnt->track.stepsize; + offset = cent->y * cnt->track.stepsize; - if ((cnt->track.motory_reverse && (offset > 0)) || + if ((cnt->track.motory_reverse && (offset > 0)) || (!cnt->track.motory_reverse && (offset < 0))) command = SERVO_COMMAND_UP_N; else @@ -433,13 +433,13 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, data = abs(offset); - if ((data + position > (unsigned)cnt->track.maxy) || - (position - offset < (unsigned)cnt->track.miny)) { - MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", + if ((data + position > (unsigned)cnt->track.maxy) || + (position - offset < (unsigned)cnt->track.miny)) { + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", data, cnt->track.miny, cnt->track.maxy); - return 0; + 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); @@ -447,7 +447,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, } else { /***** x-axis *****/ - + /* Move left */ if (cent->x < imgs->width / 2) { if (cnt->track.motorx_reverse) @@ -457,7 +457,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, data = imgs->width / 2 - cent->x; } - /* Move right */ + /* Move right */ if (cent->x > imgs->width / 2) { if (cnt->track.motorx_reverse) command = SERVO_COMMAND_LEFT_N; @@ -474,29 +474,29 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if (data && command) { // TODO: need to get position to avoid overflow limits - position = servo_position(cnt, cnt->track.motorx); + position = servo_position(cnt, cnt->track.motorx); - if ((position + data > (unsigned)cnt->track.maxx) || + if ((position + data > (unsigned)cnt->track.maxx) || (position - data < (unsigned)cnt->track.minx)) { - MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", data, cnt->track.minx, cnt->track.maxx); return 0; - } + } /* Set Speed , TODO : it should be done only when speed changes */ - + servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motorx, command, data); 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", - cent->x, cent->y, cnt->track.motorx_reverse, + "reversey %d motorx %d data %d command %d", + cent->x, cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, cnt->track.motorx, data, command); - } + } /***** y-axis *****/ - /* Move down */ + /* Move down */ if (cent->y < imgs->height / 2) { if (cnt->track.motory_reverse) command = SERVO_COMMAND_UP_N; @@ -523,9 +523,9 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, // TODO: need to get position to avoid overflow limits position = servo_position(cnt, cnt->track.motory); - if ((position + data > (unsigned)cnt->track.maxy) || + if ((position + data > (unsigned)cnt->track.maxy) || (position - data < (unsigned)cnt->track.miny)) { - MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", data, cnt->track.miny, cnt->track.maxy); return 0; } @@ -533,13 +533,13 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, /* 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); - + 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", - cent->x, cent->y, cnt->track.motorx_reverse, + "reversey %d motory %d data %d command %d", + cent->x, cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, cnt->track.motory, command); } - } + } return cnt->track.move_wait; } @@ -556,7 +556,7 @@ static unsigned int servo_status(struct context *cnt, unsigned int motor) * Moves servo to home position. * Does absolute movements ( offsets relative to home position ). * - * Note : Using Clockwise as a convention for right , left , up , down + * Note : Using Clockwise as a convention for right , left , up , down * so left minx , right maxx , down miny , up maxy * */ @@ -570,17 +570,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(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); return 0; } } - 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", 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", 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) @@ -592,7 +592,7 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); ret = servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_ABSOLUTE, x_offset_abs); - } + } /* y-axis */ if (cnt->track.motory_reverse) @@ -603,8 +603,8 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset if (y_offset_abs <= cnt->track.maxy && y_offset_abs >= cnt->track.minx) { /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed); - ret = servo_command(cnt, cnt->track.motory, SERVO_COMMAND_ABSOLUTE, y_offset_abs); - } + ret = servo_command(cnt, cnt->track.motory, SERVO_COMMAND_ABSOLUTE, y_offset_abs); + } return cnt->track.move_wait; } @@ -626,9 +626,9 @@ static char iomojo_command(struct context *cnt, char *command, int len, unsigned if (ret) { while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 2); - + if (time(NULL) >= timeout + 2) { - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Return byte timeout!"); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Return byte timeout!"); return 0; } } @@ -639,19 +639,19 @@ static char iomojo_command(struct context *cnt, char *command, int len, unsigned static void iomojo_setspeed(struct context *cnt, unsigned int speed) { char command[3]; - + command[0] = IOMOJO_SETSPEED_CMD; command[1] = cnt->track.iomojo_id; command[2] = speed; - + if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET) - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to set camera speed"); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to set camera speed"); } static void iomojo_movehome(struct context *cnt) { char command[2]; - + command[0] = IOMOJO_MOVEHOME; command[1] = cnt->track.iomojo_id; @@ -665,7 +665,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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", cnt->track.port); return 0; } @@ -679,7 +679,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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", cnt->track.port); return 0; } @@ -722,14 +722,14 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse return cnt->track.move_wait; } -static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs) { char command[5]; int direction = 0; int nx = 0, ny = 0; int i; - + if (dev < 0) if (!iomojo_center(cnt, 0, 0)) return 0; @@ -797,14 +797,14 @@ 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(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset pwc camera to starting position! Reason"); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset pwc camera to starting position! Reason"); return 0; } SLEEP(6, 0); if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) { - MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE"); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE"); return 0; } @@ -818,7 +818,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE"); - + pma.absolute = 1; if (x_angle * 100 < cnt->track.maxx && x_angle * 100 > cnt->track.minx) @@ -837,7 +837,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y return cnt->track.move_wait; } -static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual) { int delta_x = cent->x - (imgs->width / 2); @@ -859,7 +859,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, move_x_degrees = cent->x * 100; move_y_degrees = cent->y * 100; } - + /* 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) { @@ -878,9 +878,9 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE"); - /* + /* * Check current position of camera and see if we need to adjust - * values down to what is left to move + * values down to what is left to move */ if (move_x_degrees < 0 && (cnt->track.minx - pma.pan) > move_x_degrees) move_x_degrees = (cnt->track.minx - pma.pan); @@ -893,7 +893,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, 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 */ pma.absolute = 0; pma.pan = move_x_degrees; @@ -909,9 +909,9 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, /****************************************************************************** Logitech QuickCam Sphere camera tracking code by oBi - - Modify by Dirk Wesenberg(Munich) 30.03.07 - - for new API in uvcvideo + + Modify by Dirk Wesenberg(Munich) 30.03.07 + - for new API in uvcvideo - add Trace-steps for investigation ******************************************************************************/ #ifdef MOTION_V4L2 @@ -957,20 +957,20 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ } MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Getting camera range"); - - /* DWe 30.03.07 The orig request failed : - * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual - * Range X = -70 to +70 degrees - * Y = -30 to +30 degrees - */ - + + /* DWe 30.03.07 The orig request failed : + * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual + * Range X = -70 to +70 degrees + * Y = -30 to +30 degrees + */ + //get mininum //pan.value = queryctrl.minimum; cnt->track.minx = -4480 / INCPANTILT; cnt->track.miny = -1920 / INCPANTILT; //get maximum - cnt->track.maxx = 4480 / INCPANTILT; + cnt->track.maxx = 4480 / INCPANTILT; cnt->track.maxy = 1920 / INCPANTILT; //pan.value = queryctrl.maximum; @@ -983,9 +983,9 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ struct v4l2_control control_s; - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS 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(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", x_angle, y_angle); if (x_angle <= cnt->track.maxx && x_angle >= cnt->track.minx) @@ -993,7 +993,7 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ if (y_angle <= cnt->track.maxy && y_angle >= cnt->track.miny) move_y_degrees = y_angle - (cnt->track.tilt_angle); - + /* * tilt up: - value @@ -1003,15 +1003,15 @@ 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; - - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: For_SET_ABS move_X %d,move_Y %d", + + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: For_SET_ABS move_X %d,move_Y %d", move_x_degrees, move_y_degrees); - - /* DWe 30.03.07 Must be broken in diff calls, because + + /* 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 - * The Webcam or uvcvideo does not like a call with a zero-move + * The Webcam or uvcvideo does not like a call with a zero-move */ - + if (move_x_degrees != 0) { control_s.id = V4L2_CID_PAN_RELATIVE; //control_s.value = pan.value; @@ -1023,10 +1023,10 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ } } - /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ - if ((move_x_degrees != 0) && (move_y_degrees != 0)) + /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ + if ((move_x_degrees != 0) && (move_y_degrees != 0)) SLEEP(1, 0); - + if (move_y_degrees != 0) { control_s.id = V4L2_CID_TILT_RELATIVE; //control_s.value = pan.value; @@ -1035,46 +1035,46 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; - } + } } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", - cnt->track.minmaxfound); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + cnt->track.minmaxfound); if (cnt->track.dev != -1) { - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%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, ", cnt->track.pan_angle, cnt->track.tilt_angle); - if (move_x_degrees != -1) { + if (move_x_degrees != -1) { cnt->track.pan_angle += move_x_degrees; } - if (move_x_degrees != -1) { + if (move_x_degrees != -1) { cnt->track.tilt_angle += move_y_degrees; } - MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: After_ABS_Y_Angel : x= %d , Y= %d", - cnt->track.pan_angle, cnt->track.tilt_angle); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: After_ABS_Y_Angel : x= %d , Y= %d", + cnt->track.pan_angle, cnt->track.tilt_angle); } return cnt->track.move_wait; } -static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, +static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual) { /* RELATIVE MOVING : Act.Position +/- X and Y */ - + int delta_x = cent->x - (imgs->width / 2); int delta_y = cent->y - (imgs->height / 2); int move_x_degrees, move_y_degrees; - - /* - * DWe 30.03.07 Does the request of act.position from WebCam work ? luvcview shows at every position 180 :( - * Now we init the Web by call Reset, so we can sure, that we are at x/y = 0,0 - * Don't worry, if the WebCam make a sound - over End at PAN - hmmm, should it be normal ...? - * PAN Value 7777 in relative will init also a want reset for CAM - it will be "0" after that - */ + + /* + * DWe 30.03.07 Does the request of act.position from WebCam work ? luvcview shows at every position 180 :( + * Now we init the Web by call Reset, so we can sure, that we are at x/y = 0,0 + * Don't worry, if the WebCam make a sound - over End at PAN - hmmm, should it be normal ...? + * PAN Value 7777 in relative will init also a want reset for CAM - it will be "0" after that + */ if ((cnt->track.minmaxfound != 1) || (cent->x == 7777)) { unsigned int reset = 3; //0-non reset, 1-reset pan, 2-reset tilt, 3-reset pan&tilt struct v4l2_control control_s; @@ -1088,21 +1088,21 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, } MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position"); - + /* set the "helpvalue" back to null because after reset CAM should be in x=0 and not 70 */ cent->x = 0; SLEEP(8, 0); - - /* - * DWe 30.03.07 The orig request failed : - * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual - * Range X = -70 to +70 degrees - * Y = -30 to +30 degrees - */ + + /* + * DWe 30.03.07 The orig request failed : + * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual + * Range X = -70 to +70 degrees + * Y = -30 to +30 degrees + */ cnt->track.minx = -4480 / INCPANTILT; cnt->track.miny = -1920 / INCPANTILT; - cnt->track.maxx = 4480 / INCPANTILT; + cnt->track.maxx = 4480 / INCPANTILT; cnt->track.maxy = 1920 / INCPANTILT; cnt->track.dev = dev; cnt->track.pan_angle = 0; @@ -1110,7 +1110,7 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, cnt->track.minmaxfound = 1; } - + /* If we are on auto track we calculate delta, otherwise we use user input in degrees */ if (!manual) { if (delta_x > imgs->width * 3/8 && delta_x < imgs->width * 5/8) @@ -1137,9 +1137,9 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, union pantilt pan; if (cnt->track.minmaxfound == 1) { - /* + /* * Check current position of camera and see if we need to adjust - * values down to what is left to move + * values down to what is left to move */ if (move_x_degrees < 0 && (cnt->track.minx - cnt->track.pan_angle) > move_x_degrees) move_x_degrees = cnt->track.minx - cnt->track.pan_angle; @@ -1154,10 +1154,10 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, move_y_degrees = cnt->track.maxy - cnt->track.tilt_angle; } - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "For_SET_REL pan_min %d,pan_max %d,tilt_min %d,tilt_max %d", + MOTION_LOG(DBG, 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(DBG, 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(DBG, 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(DBG, TYPE_TRACK, NO_ERRNO, "For_SET_REL move_X %d,move_Y %d", move_x_degrees, move_y_degrees); /* @@ -1169,10 +1169,10 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, pan.s16.pan = -move_x_degrees * INCPANTILT; pan.s16.tilt = -move_y_degrees * INCPANTILT; - - /* DWe 30.03.07 Must be broken in diff calls, because + + /* 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 - * The Webcam or uvcvideo does not like a call with a zero-move + * The Webcam or uvcvideo does not like a call with a zero-move */ if (move_x_degrees != 0) { @@ -1180,17 +1180,17 @@ 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; - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, " dev %d, addr= %d, control_S= %d, Wert= %d", - dev, VIDIOC_S_CTRL, &control_s, pan.s16.pan); + MOTION_LOG(DBG, 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(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } - - /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ - if ((move_x_degrees != 0) && (move_y_degrees != 0)) + + /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ + if ((move_x_degrees != 0) && (move_y_degrees != 0)) SLEEP (1, 0); @@ -1199,29 +1199,29 @@ 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; - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, " dev %d,addr= %d, control_S= %d, Wert= %d", - dev, VIDIOC_S_CTRL, &control_s, pan.s16.tilt); + MOTION_LOG(DBG, 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(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } - - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", - cnt->track.minmaxfound); + + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + cnt->track.minmaxfound); if (cnt->track.minmaxfound == 1) { - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "Before_REL_Y_Angel : x= %d , Y= %d", + MOTION_LOG(DBG, 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) + + if (move_x_degrees != 0) cnt->track.pan_angle += -pan.s16.pan / INCPANTILT; - if (move_y_degrees != 0) + if (move_y_degrees != 0) cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT; - - MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "After_REL_Y_Angel : x= %d , Y= %d", + + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "After_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle); } diff --git a/video.c b/video.c index 37280ea..5762fca 100644 --- a/video.c +++ b/video.c @@ -66,7 +66,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN"); } else { fps = vw.flags >> PWC_FPS_SHIFT; - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Get Current framerate %d .. trying %d", + MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "%s: Get Current framerate %d .. trying %d", fps, cnt->conf.frame_limit); } @@ -79,7 +79,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN"); } else { fps = vw.flags >> PWC_FPS_SHIFT; - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Set new framerate %d", fps); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set new framerate %d", fps); } viddev->fps = fps; @@ -182,13 +182,13 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp return NULL; } - MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency set to %ul", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency set to %ul", tuner_number, freq); } } if (ioctl (dev, VIDIOCGMBUF, &vid_buf) == -1) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: ioctl(VIDIOCGMBUF) - Error device" + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: ioctl(VIDIOCGMBUF) - Error device" " does not support memory map\n V4L capturing using read is deprecated!\n" "Motion only supports mmap."); return NULL; @@ -206,7 +206,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp } if (MAP_FAILED == map) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: MAP_FAILED"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: MAP_FAILED"); return NULL; } @@ -242,7 +242,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp /* Try one last time... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with all supported palettes " + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with all supported palettes " "- giving up"); return NULL; } @@ -255,23 +255,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(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV420P palette"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV420P palette"); break; case VIDEO_PALETTE_YUV422: viddev->v4l_bufsize = (width * height * 2); - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV422 palette"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV422 palette"); break; case VIDEO_PALETTE_YUYV: viddev->v4l_bufsize = (width * height * 2); - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUYV palette"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUYV palette"); break; case VIDEO_PALETTE_RGB24: viddev->v4l_bufsize = (width * height * 3); - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_RGB24 palette"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_RGB24 palette"); break; case VIDEO_PALETTE_GREY: viddev->v4l_bufsize = width * height; - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_GREY palette"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_GREY palette"); break; } @@ -409,7 +409,7 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char return; } - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency to %ul", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency to %ul", tuner_number, frequnits); } } @@ -430,7 +430,7 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char return; } - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Set Input to %d Standard method to %d", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Input to %d Standard method to %d", input, norm); } diff --git a/video2.c b/video2.c index 51aab5f..4dbcb1a 100644 --- a/video2.c +++ b/video2.c @@ -3,8 +3,8 @@ * * V4L2 interface with basically JPEG decompression support and even more ... * Copyright 2006 Krzysztof Blaszkowski (kb@sysmikro.com.pl) - * 2007 Angel Carpintero (ack@telefonica.net) - + * 2007 Angel Carpintero (motiondevelop@gmail.com) + * Supported features and TODO - preferred palette is JPEG which seems to be very popular for many 640x480 usb cams - other supported palettes (NOT TESTED) @@ -27,31 +27,31 @@ V4L2_PIX_FMT_YUV420, (tested) V4L2_PIX_FMT_YUYV (tested) - * - setting tuner - NOT TESTED + * - setting tuner - NOT TESTED * - access to V4L2 device controls is missing. Partially added but requires some improvements likely. - * - changing resolution at run-time may not work. + * - changing resolution at run-time may not work. * - ucvideo svn r75 or above to work with MJPEG ( e.g. Logitech 5000 pro ) - + * This work is inspired by fswebcam and current design of motion. * This interface has been tested with ZC0301 driver from kernel 2.6.17.3 and Labtec's usb camera (PAS202 sensor) - - * I'm very pleased by achieved image quality and cpu usage comparing to junky v4l1 spca5xx driver with + + * I'm very pleased by achieved image quality and cpu usage comparing to junky v4l1 spca5xx driver with * it nonsensical kernel messy jpeg decompressor. * Default sensor settings used by ZC0301 driver are very reasonable choosen. * apparently brigthness should be controlled automatically by motion still for light compensation. * it can be done by adjusting ADC gain and also exposure time. * Kernel 2.6.27 - - V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') YUYV per line - V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') YYUV per line - V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') YUVY per line - V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') 8 GBGB.. RGRG.. + + V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') YUYV per line + V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') YYUV per line + V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') YUVY per line + V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') 8 GBGB.. RGRG.. V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') 8 GRGR.. BGBG.. - V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') 16 BGBG.. GRGR.. - V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') compressed GBRG bayer + V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') 16 BGBG.. GRGR.. + V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') compressed GBRG bayer V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') Pixart 73xx JPEG - V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') compressed BGGR bayer + V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') compressed BGGR bayer * @@ -125,7 +125,7 @@ #endif #ifndef V4L2_PIX_FMT_SPCA501 -#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */ +#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */ #endif #ifndef V4L2_PIX_FMT_SPCA505 @@ -178,8 +178,8 @@ typedef struct { /** * xioctl - */ -static int xioctl(int fd, int request, void *arg) + */ +static int xioctl(int fd, int request, void *arg) { int ret; @@ -192,49 +192,49 @@ static int xioctl(int fd, int request, void *arg) /** * v4l2_get_capability - */ -static int v4l2_get_capability(src_v4l2_t * vid_source) + */ +static int v4l2_get_capability(src_v4l2_t * vid_source) { if (xioctl(vid_source->fd, VIDIOC_QUERYCAP, &vid_source->cap) < 0) { MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not a V4L2 device?"); return -1; } - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \n------------------------\n" + MOTION_LOG(NTC, 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------------------------", - vid_source->cap.driver, vid_source->cap.card, vid_source->cap.bus_info, + "cap.capabilities=0x%08X\n------------------------", + vid_source->cap.driver, vid_source->cap.card, vid_source->cap.bus_info, vid_source->cap.capabilities); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_CAPTURE"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_OUTPUT"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_OVERLAY"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - VIDEO_OVERLAY"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_CAPTURE) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - VBI_CAPTURE"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - VBI_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_OUTPUT) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - VBI_OUTPUT"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - VBI_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_RDS_CAPTURE) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - RDS_CAPTURE"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - RDS_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_TUNER) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - TUNER"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - TUNER"); if (vid_source->cap.capabilities & V4L2_CAP_AUDIO) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - AUDIO"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - AUDIO"); if (vid_source->cap.capabilities & V4L2_CAP_READWRITE) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - READWRITE"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - READWRITE"); if (vid_source->cap.capabilities & V4L2_CAP_ASYNCIO) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - ASYNCIO"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - ASYNCIO"); if (vid_source->cap.capabilities & V4L2_CAP_STREAMING) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - STREAMING"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - STREAMING"); if (vid_source->cap.capabilities & V4L2_CAP_TIMEPERFRAME) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: - TIMEPERFRAME"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - TIMEPERFRAME"); if (!(vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Device does not support capturing."); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Device does not support capturing."); return -1; } @@ -243,9 +243,9 @@ static int v4l2_get_capability(src_v4l2_t * vid_source) /** * v4l2_select_input - */ -static int v4l2_select_input(struct config *conf, struct video_dev *viddev, - src_v4l2_t * vid_source, int in, int norm, + */ +static int v4l2_select_input(struct config *conf, struct video_dev *viddev, + src_v4l2_t * vid_source, int in, int norm, unsigned long freq_, int tuner_number ATTRIBUTE_UNUSED) { struct v4l2_input input; @@ -274,7 +274,7 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, if (input.type & V4L2_INPUT_TYPE_TUNER) MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - TUNER"); - if (input.type & V4L2_INPUT_TYPE_CAMERA) + if (input.type & V4L2_INPUT_TYPE_CAMERA) MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - CAMERA"); if (xioctl(vid_source->fd, VIDIOC_S_INPUT, &input.index) == -1) { @@ -284,13 +284,13 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, } viddev->input = conf->input = in; - - /* - * Set video standard usually webcams doesn't support the ioctl or - * return V4L2_STD_UNKNOWN + + /* + * 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) { - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Device doesn't support VIDIOC_G_STD"); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Device doesn't support VIDIOC_G_STD"); norm = std_id = 0; // V4L2_STD_UNKNOWN = 0 } @@ -299,10 +299,10 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, standard.index = 0; while (xioctl(vid_source->fd, VIDIOC_ENUMSTD, &standard) == 0) { - if (standard.id & std_id) - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - video standard %s", + if (standard.id & std_id) + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - video standard %s", standard.name); - + standard.index++; } @@ -317,11 +317,11 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, std_id = V4L2_STD_PAL; } - if (xioctl(vid_source->fd, VIDIOC_S_STD, &std_id) == -1) - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting standard" + if (xioctl(vid_source->fd, VIDIOC_S_STD, &std_id) == -1) + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting standard" " method %d VIDIOC_S_STD", (int)std_id); - - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set standard method %d", + + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set standard method %d", (int)std_id); } @@ -338,8 +338,8 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, tuner.index = input.tuner; if (xioctl(vid_source->fd, VIDIOC_G_TUNER, &tuner) == -1) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: tuner %d VIDIOC_G_TUNER", - tuner.index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: tuner %d VIDIOC_G_TUNER", + tuner.index); return 0; } @@ -353,14 +353,14 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, freq.frequency = (freq_ / 1000) * 16; if (xioctl(vid_source->fd, VIDIOC_S_FREQUENCY, &freq) == -1) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: freq %ul VIDIOC_S_FREQUENCY", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: freq %ul VIDIOC_S_FREQUENCY", freq.frequency); return 0; } viddev->freq = conf->frequency = freq_; - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Frequency to %ul", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Frequency to %ul", freq.frequency); } else { viddev->freq = conf->frequency = 0; @@ -372,12 +372,12 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, /* * * v4l2_do_set_pix_format - * + * * This routine does the actual request to the driver - * + * * Returns: 0 Ok * -1 Problems setting palette or not supported - * + * * Our algorithm for setting the picture format for the data which the * driver returns to us will be as follows: * @@ -403,19 +403,19 @@ static int v4l2_do_set_pix_format(u32 pixformat, src_v4l2_t * vid_source, vid_source->dst_fmt.fmt.pix.height = *height; vid_source->dst_fmt.fmt.pix.pixelformat = pixformat; vid_source->dst_fmt.fmt.pix.field = V4L2_FIELD_ANY; - - if (xioctl(vid_source->fd, VIDIOC_TRY_FMT, &vid_source->dst_fmt) != -1 && + + if (xioctl(vid_source->fd, VIDIOC_TRY_FMT, &vid_source->dst_fmt) != -1 && vid_source->dst_fmt.fmt.pix.pixelformat == pixformat) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Testing palette %c%c%c%c (%dx%d)", - pixformat >> 0, pixformat >> 8, + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Testing palette %c%c%c%c (%dx%d)", + pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height); - if (vid_source->dst_fmt.fmt.pix.width != (unsigned int) *width || + if (vid_source->dst_fmt.fmt.pix.width != (unsigned int) *width || vid_source->dst_fmt.fmt.pix.height != (unsigned int) *height) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Adjusting resolution " - "from %ix%i to %ix%i.", - *width, *height, vid_source->dst_fmt.fmt.pix.width, + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Adjusting resolution " + "from %ix%i to %ix%i.", + *width, *height, vid_source->dst_fmt.fmt.pix.width, vid_source->dst_fmt.fmt.pix.height); *width = vid_source->dst_fmt.fmt.pix.width; @@ -428,22 +428,22 @@ static int v4l2_do_set_pix_format(u32 pixformat, src_v4l2_t * vid_source, return -1; } - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Using palette %c%c%c%c (%dx%d)" - " bytesperlines %d sizeimage %d colorspace %08x", pixformat >> 0, - pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, - *height, vid_source->dst_fmt.fmt.pix.bytesperline, - vid_source->dst_fmt.fmt.pix.sizeimage, + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using palette %c%c%c%c (%dx%d)" + " bytesperlines %d sizeimage %d colorspace %08x", 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); return 0; - } - + } + return -1; } /** * v4l2_set_pix_format - * + * * Returns: 0 Ok * -1 Problems setting palette or not supported */ @@ -455,11 +455,11 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, /* * Note that this array MUST exactly match the config file list. - * A higher index means better chance to be used + * A higher index means better chance to be used */ - static const u32 supported_formats[] = { + static const u32 supported_formats[] = { V4L2_PIX_FMT_SN9C10X, - V4L2_PIX_FMT_SBGGR16, + V4L2_PIX_FMT_SBGGR16, V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SPCA561, V4L2_PIX_FMT_SGBRG8, @@ -468,12 +468,12 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, V4L2_PIX_FMT_PJPG, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_JPEG, - V4L2_PIX_FMT_RGB24, - V4L2_PIX_FMT_SPCA501, - V4L2_PIX_FMT_SPCA505, - V4L2_PIX_FMT_SPCA508, + V4L2_PIX_FMT_RGB24, + V4L2_PIX_FMT_SPCA501, + V4L2_PIX_FMT_SPCA505, + V4L2_PIX_FMT_SPCA508, V4L2_PIX_FMT_UYVY, - V4L2_PIX_FMT_YUYV, + V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_YUV422P, V4L2_PIX_FMT_YUV420 /* most efficient for motion */ }; @@ -490,27 +490,27 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, supported_formats[cnt->conf.v4l2_palette] >> 8, supported_formats[cnt->conf.v4l2_palette] >> 16, supported_formats[cnt->conf.v4l2_palette] >> 24, 0}; - - if (v4l2_do_set_pix_format(supported_formats[cnt->conf.v4l2_palette], - vid_source, width, height) >= 0) + + if (v4l2_do_set_pix_format(supported_formats[cnt->conf.v4l2_palette], + vid_source, width, height) >= 0) return 0; - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Config palette index %d (%s)" + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Config palette index %d (%s)" " doesn't work.", cnt->conf.v4l2_palette, name); } - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Supported palettes:"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Supported palettes:"); while (xioctl(vid_source->fd, VIDIOC_ENUM_FMT, &fmtd) != -1) { int i; - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: (%i) %c%c%c%c (%s)", - v4l2_pal, fmtd.pixelformat >> 0, + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: (%i) %c%c%c%c (%s)", + v4l2_pal, fmtd.pixelformat >> 0, fmtd.pixelformat >> 8, fmtd.pixelformat >> 16, fmtd.pixelformat >> 24, fmtd.description); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: %d - %s (compressed : %d) (%#x)", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: %d - %s (compressed : %d) (%#x)", fmtd.index, fmtd.description, fmtd.flags, fmtd.pixelformat); /* Adjust index_format if larger value found */ @@ -529,19 +529,19 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, supported_formats[index_format] >> 16, supported_formats[index_format] >> 24, 0}; - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s Selected palette %s", name); - - if (v4l2_do_set_pix_format(supported_formats[index_format], + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s Selected palette %s", name); + + if (v4l2_do_set_pix_format(supported_formats[index_format], vid_source, width, height) >= 0) return 0; - + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "VIDIOC_TRY_FMT failed for " "format %s", name); } MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find a compatible" " palette format."); - + return -1; } @@ -555,16 +555,16 @@ static void v4l2_set_fps(src_v4l2_t * vid_source) { setfpvid_source->parm.capture.timeperframe.numerator = 1; setfpvid_source->parm.capture.timeperframe.denominator = vid_source->fps; - if (xioctl(vid_source->fd, VIDIOC_S_PARM, setfps) == -1) + if (xioctl(vid_source->fd, VIDIOC_S_PARM, setfps) == -1) MOTION_LOG(ERR, 1, "%s: v4l2_set_fps VIDIOC_S_PARM"); - + } #endif /** * v4l2_set_mmap - */ + */ static int v4l2_set_mmap(src_v4l2_t * vid_source) { enum v4l2_buf_type type; @@ -581,17 +581,17 @@ 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(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error requesting buffers" + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error requesting buffers" " %d for memory map. VIDIOC_REQBUFS", vid_source->req.count); return -1; } - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: mmap information: frames=%d", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: mmap information: frames=%d", vid_source->req.count); if (vid_source->req.count < MIN_MMAP_BUFFERS) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory" + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory" " %d < MIN_MMAP_BUFFERS.", vid_source->req.count); return -1; } @@ -620,17 +620,17 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) } vid_source->buffers[buffer_index].size = buf.length; - vid_source->buffers[buffer_index].ptr = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, + vid_source->buffers[buffer_index].ptr = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, vid_source->fd, buf.m.offset); if (vid_source->buffers[buffer_index].ptr == MAP_FAILED) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error mapping buffer %i mmap", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error mapping buffer %i mmap", buffer_index); free(vid_source->buffers); return -1; } - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: %i length=%d Address (%x)", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: %i length=%d Address (%x)", buffer_index, buf.length, vid_source->buffers[buffer_index].ptr); } @@ -651,7 +651,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) if (xioctl(vid_source->fd, VIDIOC_STREAMON, &type) == -1) { MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error starting stream." - " VIDIOC_STREAMON"); + " VIDIOC_STREAMON"); return -1; } @@ -660,7 +660,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) /** * v4l2_scan_controls - */ + */ static int v4l2_scan_controls(src_v4l2_t * vid_source) { int count, i; @@ -678,7 +678,7 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) } if (count) { - struct v4l2_queryctrl *ctrl = vid_source->controls + struct v4l2_queryctrl *ctrl = vid_source->controls = calloc(count, sizeof(struct v4l2_queryctrl)); if (!ctrl) { @@ -696,15 +696,15 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) memcpy(ctrl, &queryctrl, sizeof(struct v4l2_queryctrl)); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: found control 0x%08x, \"%s\"," - " range %d,%d %s", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: found control 0x%08x, \"%s\"," + " range %d,%d %s", 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(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \t\"%s\", default %d, current %d", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: \t\"%s\", default %d, current %d", ctrl->name, ctrl->default_value, control.value); ctrl++; @@ -717,7 +717,7 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) /** * v4l2_set_control - */ + */ static int v4l2_set_control(src_v4l2_t * vid_source, u32 cid, int value) { int i, count; @@ -748,7 +748,7 @@ static int v4l2_set_control(src_v4l2_t * vid_source, u32 cid, int value) break; default: - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: control type not supported yet"); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: control type not supported yet"); return -1; } @@ -767,7 +767,7 @@ static int v4l2_set_control(src_v4l2_t * vid_source, u32 cid, int value) /** * v4l2_picture_controls - */ + */ static void v4l2_picture_controls(struct context *cnt, struct video_dev *viddev) { src_v4l2_t *vid_source = (src_v4l2_t *) viddev->v4l2_private; @@ -805,7 +805,7 @@ static void v4l2_picture_controls(struct context *cnt, struct video_dev *viddev) /* public functions */ /** * v4l2_start - */ + */ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int width, int height, int input, int norm, unsigned long freq, int tuner_number) { @@ -823,24 +823,24 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid vid_source->pframe = -1; struct config *conf = &cnt->conf; - if (v4l2_get_capability(vid_source)) + if (v4l2_get_capability(vid_source)) goto err; - - if (v4l2_select_input(conf, viddev, vid_source, input, norm, freq, tuner_number)) + + if (v4l2_select_input(conf, viddev, vid_source, input, norm, freq, tuner_number)) goto err; - - if (v4l2_set_pix_format(cnt, vid_source, &width, &height)) + + if (v4l2_set_pix_format(cnt, vid_source, &width, &height)) goto err; - - if (v4l2_scan_controls(vid_source)) + + if (v4l2_scan_controls(vid_source)) goto err; #if 0 v4l2_set_fps(vid_source); #endif - if (v4l2_set_mmap(vid_source)) + if (v4l2_set_mmap(vid_source)) goto err; - + viddev->size_map = 0; viddev->v4l_buffers[0] = NULL; viddev->v4l_maxbuffer = 1; @@ -857,7 +857,7 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid return (void *) 1; err: - if (vid_source) + if (vid_source) free(vid_source); viddev->v4l2_private = NULL; @@ -867,8 +867,8 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid /** * v4l2_set_input - */ -void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, + */ +void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height, struct config *conf) { int input = conf->input; @@ -879,14 +879,14 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char if (input != viddev->input || width != viddev->width || height != viddev->height || freq != viddev->freq || tuner_number != viddev->tuner_number || norm != viddev->norm) { - unsigned int i; + unsigned int i; struct timeval switchTime; unsigned int skip = conf->roundrobin_skip; - - if (conf->roundrobin_skip < 0) + + if (conf->roundrobin_skip < 0) skip = 1; - v4l2_select_input(conf, viddev, (src_v4l2_t *) viddev->v4l2_private, + v4l2_select_input(conf, viddev, (src_v4l2_t *) viddev->v4l2_private, input, norm, freq, tuner_number); gettimeofday(&switchTime, NULL); @@ -919,14 +919,14 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char if (v4l2_next(cnt, viddev, map, width, height)) break; - if (vid_source->buf.timestamp.tv_sec > switchTime.tv_sec || - (vid_source->buf.timestamp.tv_sec == switchTime.tv_sec && + if (vid_source->buf.timestamp.tv_sec > switchTime.tv_sec || + (vid_source->buf.timestamp.tv_sec == switchTime.tv_sec && vid_source->buf.timestamp.tv_usec > switchTime.tv_usec)) break; MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: got frame before " - " switch timestamp=%ld:%ld", - vid_source->buf.timestamp.tv_sec, + " switch timestamp=%ld:%ld", + vid_source->buf.timestamp.tv_sec, vid_source->buf.timestamp.tv_usec); } } @@ -940,18 +940,18 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char } } -/** +/** * v4l2_next - */ -int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, + */ +int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height) { sigset_t set, old; src_v4l2_t *vid_source = (src_v4l2_t *) viddev->v4l2_private; - if (viddev->v4l_fmt != VIDEO_PALETTE_YUV420P) + if (viddev->v4l_fmt != VIDEO_PALETTE_YUV420P) return V4L_FATAL_ERROR; - + /* Block signals during IOCTL */ sigemptyset(&set); sigaddset(&set, SIGCHLD); @@ -961,7 +961,7 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, sigaddset(&set, SIGHUP); pthread_sigmask(SIG_BLOCK, &set, &old); - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 1) vid_source->pframe %i", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: 1) vid_source->pframe %i", vid_source->pframe); if (vid_source->pframe >= 0) { @@ -979,15 +979,15 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, if (xioctl(vid_source->fd, VIDIOC_DQBUF, &vid_source->buf) == -1) { int ret; - /* - * Some drivers return EIO when there is no signal, + /* + * Some drivers return EIO when there is no signal, * driver might dequeue an (empty) buffer despite * returning an error, or even stop capturing. */ if (errno == EIO) { - vid_source->pframe++; + vid_source->pframe++; - if ((u32)vid_source->pframe >= vid_source->req.count) + if ((u32)vid_source->pframe >= vid_source->req.count) vid_source->pframe = 0; vid_source->buf.index = vid_source->pframe; @@ -1007,16 +1007,16 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, return ret; } - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 2) vid_source->pframe %i", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: 2) vid_source->pframe %i", 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; - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 3) vid_source->pframe %i " + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: 3) vid_source->pframe %i " "vid_source->buf.index %i", vid_source->pframe, vid_source->buf.index); - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: vid_source->buf.bytesused %i", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: vid_source->buf.bytesused %i", vid_source->buf.bytesused); pthread_sigmask(SIG_UNBLOCK, &old, NULL); /*undo the signal blocking */ @@ -1024,7 +1024,7 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, { video_buff *the_buffer = &vid_source->buffers[vid_source->buf.index]; - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: the_buffer index %d Address (%x)", + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: the_buffer index %d Address (%x)", vid_source->buf.index, the_buffer->ptr); switch (vid_source->dst_fmt.fmt.pix.pixelformat) { @@ -1045,23 +1045,23 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, memcpy(map, the_buffer->ptr, viddev->v4l_bufsize); return 0; - case V4L2_PIX_FMT_PJPG: - case V4L2_PIX_FMT_JPEG: + case V4L2_PIX_FMT_PJPG: + case V4L2_PIX_FMT_JPEG: case V4L2_PIX_FMT_MJPEG: - return mjpegtoyuv420p(map, the_buffer->ptr, width, height, + return mjpegtoyuv420p(map, the_buffer->ptr, width, height, vid_source->buffers[vid_source->buf.index].content_length); - - /* FIXME: quick hack to allow work all bayer formats */ - case V4L2_PIX_FMT_SBGGR16: - case V4L2_PIX_FMT_SGBRG8: - case V4L2_PIX_FMT_SGRBG8: - /* case V4L2_PIX_FMT_SPCA561: */ + + /* FIXME: quick hack to allow work all bayer formats */ + case V4L2_PIX_FMT_SBGGR16: + case V4L2_PIX_FMT_SGBRG8: + case V4L2_PIX_FMT_SGRBG8: + /* case V4L2_PIX_FMT_SPCA561: */ case V4L2_PIX_FMT_SBGGR8: /* bayer */ bayer2rgb24(cnt->imgs.common_buffer, the_buffer->ptr, width, height); conv_rgb24toyuv420p(map, cnt->imgs.common_buffer, width, height); return 0; - case V4L2_PIX_FMT_SPCA561: + case V4L2_PIX_FMT_SPCA561: case V4L2_PIX_FMT_SN9C10X: sonix_decompress(map, the_buffer->ptr, width, height); bayer2rgb24(cnt->imgs.common_buffer, map, width, height); @@ -1089,7 +1089,7 @@ void v4l2_close(struct video_dev *viddev) /** * v4l2_cleanup - */ + */ void v4l2_cleanup(struct video_dev *viddev) { src_v4l2_t *vid_source = (src_v4l2_t *) viddev->v4l2_private; @@ -1112,4 +1112,4 @@ void v4l2_cleanup(struct video_dev *viddev) free(vid_source); viddev->v4l2_private = NULL; } -#endif /* !WITHOUT_V4L && MOTION_V4L2 */ +#endif /* !WITHOUT_V4L && MOTION_V4L2 */ diff --git a/video_common.c b/video_common.c index 0489d25..2078f21 100644 --- a/video_common.c +++ b/video_common.c @@ -2,8 +2,8 @@ * * Video stream functions for motion. * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org) - * 2006 by Krzysztof Blaszkowski (kb@sysmikro.com.pl) - * 2007 by Angel Carpintero (ack@telefonica.net) + * 2006 by Krzysztof Blaszkowski (kb@sysmikro.com.pl) + * 2007 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * @@ -173,7 +173,7 @@ int sonix_decompress(unsigned char *outp, unsigned char *inp, int width, int hei } /** - * bayer2rgb24 + * bayer2rgb24 * BAYER2RGB24 ROUTINE TAKEN FROM: * * Sonix SN9C10x based webcam basic I/F routines @@ -196,9 +196,9 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in /* B */ if ((i > width) && ((i % width) > 0)) { *scanpt++ = *rawpt; /* B */ - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + + *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + *(rawpt + width) + *(rawpt - width)) / 4; /* G */ - *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + + *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + *(rawpt + width - 1) + *(rawpt + width + 1)) / 4; /* R */ } else { /* First line or left column. */ @@ -235,9 +235,9 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in } else { /* R */ if (i < (width * (height - 1)) && ((i % width) < (width - 1))) { - *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + + *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + *(rawpt + width - 1) + *(rawpt + width + 1)) / 4; /* B */ - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + + *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + *(rawpt - width) + *(rawpt + width)) / 4; /* G */ *scanpt++ = *rawpt; /* R */ } else { @@ -257,7 +257,7 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in * conv_yuv422to420p * * - */ + */ void conv_yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, int height) { unsigned char *src, *dest, *src2, *dest2; @@ -295,7 +295,7 @@ void conv_yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, in * conv_uyvyto420p * * - */ + */ void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int width, unsigned int height) { uint8_t *pY = map; @@ -335,7 +335,7 @@ void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int wi * conv_rgb24toyuv420p * * - */ + */ void conv_rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height) { unsigned char *y, *u, *v; @@ -382,7 +382,7 @@ void conv_rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, * Return values * -1 on fatal error * 0 on success - * 2 if jpeg lib threw a "corrupt jpeg data" warning. + * 2 if jpeg lib threw a "corrupt jpeg data" warning. * in this case, "a damaged output image is likely." */ int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height, unsigned int size) @@ -399,7 +399,7 @@ 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) { - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Corrupt image ... continue"); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Corrupt image ... continue"); ret = 2; } @@ -410,13 +410,13 @@ int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int he memset(u, 0, width * height / 4); memset(v, 0, width * height / 4); - for(loop = 0; loop < width * height; loop++) + for(loop = 0; loop < width * height; loop++) *map++ = yuv[0][loop]; - - for(loop = 0; loop < width * height / 4; loop++) + + for(loop = 0; loop < width * height / 4; loop++) *map++ = yuv[1][loop]; - - for(loop = 0; loop < width * height / 4; loop++) + + for(loop = 0; loop < width * height / 4; loop++) *map++ = yuv[2][loop]; free(yuv[0]); @@ -451,7 +451,7 @@ int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int he /** * vid_do_autobright - */ + */ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) { @@ -488,7 +488,7 @@ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) } else if (avg < brightness_window_low) { /* Average is below window - turn up brightness - go for the target. */ step = MIN2((brightness_target - avg) / AUTOBRIGHT_DAMPER + 1, AUTOBRIGHT_MAX - viddev->brightness); - + if (viddev->brightness < AUTOBRIGHT_MAX - step) { viddev->brightness += step; make_change = 1; @@ -504,12 +504,12 @@ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) #ifndef WITHOUT_V4L /* - * Big lock for vid_start to ensure exclusive access to viddevs while adding + * Big lock for vid_start to ensure exclusive access to viddevs while adding * devices during initialization of each thread. */ static pthread_mutex_t vid_mutex; -/* +/* * Here we setup the viddevs structure which is used globally in the vid_* * functions. */ @@ -548,7 +548,7 @@ void vid_close(struct context *cnt) #ifndef WITHOUT_V4L struct video_dev *dev = viddevs; struct video_dev *prev = NULL; -#endif /* WITHOUT_V4L */ +#endif /* WITHOUT_V4L */ /* Cleanup the netcam part */ if (cnt->netcam) { @@ -574,12 +574,12 @@ void vid_close(struct context *cnt) cnt->video_dev = -1; if (dev == NULL) { - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); return; } if (--dev->usage_count == 0) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", dev->video_device); #ifdef MOTION_V4L2 if (dev->v4l2) { @@ -605,10 +605,10 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, so we don't close it now", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, so we don't close it now", dev->usage_count, dev->video_device); - /* - * There is still at least one thread using this device + /* + * There is still at least one thread using this device * If we own it, release it. */ if (dev->owner == cnt->threadnr) { @@ -627,8 +627,8 @@ void vid_close(struct context *cnt) * * Called from vid_start setup the V4L/V4L2 capture device * The function does the following: - * - * - Setup basic V4L/V4L2 properties incl palette incl setting + * + * - Setup basic V4L/V4L2 properties incl palette incl setting * - Open the device * - Returns the device number. * @@ -657,19 +657,19 @@ static int vid_v4lx_start(struct context *cnt) /* * 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 + * 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 is a multiple of 16 so we check * for this first. */ if (conf->width % 16) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%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", conf->width); return -3; } if (conf->height % 16) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%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", conf->height); return -3; } @@ -683,7 +683,7 @@ static int vid_v4lx_start(struct context *cnt) pthread_mutex_lock(&vid_mutex); - /* + /* * 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. @@ -691,7 +691,7 @@ static int vid_v4lx_start(struct context *cnt) cnt->imgs.width = width; cnt->imgs.height = height; - /* + /* * 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 @@ -722,7 +722,7 @@ static int vid_v4lx_start(struct context *cnt) dev = dev->next; } - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using videodevice %s and input %d", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using videodevice %s and input %d", conf->video_device, conf->input); dev = mymalloc(sizeof(struct video_dev)); @@ -733,7 +733,7 @@ static int vid_v4lx_start(struct context *cnt) fd = open(dev->video_device, O_RDWR); if (fd < 0) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open video device %s", + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open video device %s", conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -752,7 +752,7 @@ static int vid_v4lx_start(struct context *cnt) dev->freq = frequency; dev->tuner_number = tuner_number; - /* + /* * We set brightness, contrast, saturation and hue = 0 so that they only get * set if the config is not zero. */ @@ -769,7 +769,7 @@ static int vid_v4lx_start(struct context *cnt) dev->v4l2 = 1; if (!v4l2_start(cnt, dev, width, height, input, norm, frequency, tuner_number)) { - /* + /* * Restore width & height before test with v4l * because could be changed in v4l2_start(). */ @@ -791,9 +791,9 @@ static int vid_v4lx_start(struct context *cnt) } #endif if (dev->v4l2 == 0) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L1"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L1"); } else { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L2"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L2"); /* Update width & height because could be changed in v4l2_start(). */ width = dev->width; height = dev->height; @@ -839,8 +839,8 @@ static int vid_v4lx_start(struct context *cnt) * only copied to the from the conf struct to the imgs struct during program startup * The width and height can no later be changed via http remote control as this would * require major re-memory allocations of all image buffers. - * - * - if the camera is V4L/V4L2 vid_v4lx_start is called + * + * - if the camera is V4L/V4L2 vid_v4lx_start is called * * Parameters: * cnt Pointer to the context for this thread @@ -863,8 +863,8 @@ int vid_start(struct context *cnt) } } #ifdef WITHOUT_V4L - else - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); + else + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); #else else dev = vid_v4lx_start(cnt); @@ -905,7 +905,7 @@ int vid_next(struct context *cnt, unsigned char *map) return netcam_next(cnt, map); } #ifndef WITHOUT_V4L - /* + /* * We start a new block so we can make declarations without breaking * gcc 2.95 or older. */ @@ -952,9 +952,9 @@ int vid_next(struct context *cnt, unsigned char *map) } /* Rotate the image as specified. */ - if (cnt->rotate_data.degrees > 0) + if (cnt->rotate_data.degrees > 0) rotate_map(cnt, map); - + } #endif /*WITHOUT_V4L */ return ret; diff --git a/video_freebsd.c b/video_freebsd.c index f806e79..559229e 100644 --- a/video_freebsd.c +++ b/video_freebsd.c @@ -1,7 +1,7 @@ /* video_freebsd.c * * BSD Video stream functions for motion. - * Copyright 2004 by Angel Carpintero (ack@telefonica.net) + * Copyright 2004 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * @@ -108,8 +108,8 @@ static void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, } /** - * rgb24toyuv420p - * FIXME seems no work with METEOR_GEO_RGB24 , check BPP as well ? + * rgb24toyuv420p + * 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) { @@ -159,11 +159,11 @@ static void rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width /* NOT TESTED YET FIXME */ /* -static int camparam_normalize(int param, int cfg_value, int *ioctl_val) +static int camparam_normalize(int param, int cfg_value, int *ioctl_val) { int val; - cfg_value = MIN(CamParams[ param ].max, MAX(CamParams[ param ].min, cfg_value)); + cfg_value = MIN(CamParams[ param ].max, MAX(CamParams[ param ].min, cfg_value)); val = (cfg_value - CamParams[ param ].min) / (CamParams[ param ].range + 0.01) * CamParams[param].drv_range + CamParams[param].drv_min; val = MAX(CamParams[ param ].min, @@ -178,7 +178,7 @@ static int set_hue(int viddev, int new_hue) signed char ioctlval = new_hue; if (ioctl(viddev, METEORSHUE, &ioctlval) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSHUE Error setting hue [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSHUE Error setting hue [%d]", new_hue); return -1; } @@ -198,17 +198,17 @@ static int get_hue(int viddev , int *hue) } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); - - *hue = ioctlval; + + *hue = ioctlval; return ioctlval; } -static int set_saturation(int viddev, int new_saturation) +static int set_saturation(int viddev, int new_saturation) { unsigned char ioctlval= new_saturation; if (ioctl(viddev, METEORSCSAT, &ioctlval) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCSAT Error setting saturation [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCSAT Error setting saturation [%d]", new_saturation); return -1; } @@ -228,17 +228,17 @@ static int get_saturation(int viddev , int *saturation) } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); - + *saturation = ioctlval; return ioctlval; } -static int set_contrast(int viddev, int new_contrast) +static int set_contrast(int viddev, int new_contrast) { unsigned char ioctlval = new_contrast; if (ioctl(viddev, METEORSCONT, &ioctlval) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCONT Error setting contrast [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCONT Error setting contrast [%d]", new_contrast); return 0; } @@ -258,8 +258,8 @@ static int get_contrast(int viddev, int *contrast) } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); - - *contrast = ioctlval; + + *contrast = ioctlval; return ioctlval; } @@ -269,13 +269,13 @@ static int set_brightness(int viddev, int new_bright) unsigned char ioctlval = new_bright; if (ioctl(viddev, METEORSBRIG, &ioctlval) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSBRIG brightness [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSBRIG brightness [%d]", new_bright); return -1; } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); - + return ioctlval; } @@ -290,14 +290,14 @@ static int get_brightness(int viddev, int *brightness) } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); - + *brightness = ioctlval; return ioctlval; } -// Set channel needed ? FIXME +// Set channel needed ? FIXME /* -static int set_channel(struct video_dev *viddev, int new_channel) +static int set_channel(struct video_dev *viddev, int new_channel) { int ioctlval; @@ -306,18 +306,18 @@ static int set_channel(struct video_dev *viddev, int new_channel) MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error channel %d", ioctlval); return -1; } else { - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: channel set to %d", ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: channel set to %d", ioctlval); } viddev->channel = new_channel; - + return 0; } */ /** - * set_freq - * Sets frequency to tuner + * set_freq + * Sets frequency to tuner */ static int set_freq(struct video_dev *viddev, unsigned long freq) { @@ -325,16 +325,16 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) int old_audio; MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Not implemented"); - return 0; - + 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(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_GAUDIO"); return -1; } - + if (ioctl(tuner_fd, TVTUNER_SETFREQ, &freq) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Tuning (TVTUNER_SETFREQ) failed, ", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Tuning (TVTUNER_SETFREQ) failed, ", "freq [%lu]", freq); return -1; } @@ -343,20 +343,20 @@ 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(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_SAUDIO %i", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_SAUDIO %i", old_audio); return -1; } } - + return 0; } /** * set_input * Sets the input to capture images , could be tuner (METEOR_INPUT_DEV1) - * or any of others input : - * RCA/COMPOSITE1 (METEOR_INPUT_DEV0) + * 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) @@ -369,7 +369,7 @@ static int set_input(struct video_dev *viddev, unsigned input) METEOR_INPUT_DEV_SVIDEO }; if (input >= array_elem(portdata)) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%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)", input); return -1; } @@ -377,24 +377,24 @@ 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(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d invalid -" + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d invalid -" "Trying default %d", input, IN_DEFAULT); input = IN_DEFAULT; actport = portdata[ input ]; if (ioctl(viddev->fd_bktr, METEORSINPUT, &actport) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", input); return -1; } } else { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", input); return -1; } } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", input); - + return input; } @@ -408,20 +408,20 @@ static int set_geometry(struct video_dev *viddev, int width, int height) geom.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; switch (viddev->norm) { - case PAL: + case PAL: h_max = PAL_HEIGHT; - break; - case NTSC: - h_max = NTSC_HEIGHT; break; - case SECAM: + case NTSC: + h_max = NTSC_HEIGHT; + break; + case SECAM: h_max = SECAM_HEIGHT; break; - default: + default: h_max = PAL_HEIGHT; } - if (height <= h_max / 2) + if (height <= h_max / 2) geom.oformat |= METEOR_GEO_EVEN_ONLY; geom.frames = 1; @@ -431,9 +431,9 @@ static int set_geometry(struct video_dev *viddev, int width, int height) return -1; } - MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d/%d] Norm %d", - width, height, viddev->norm); - + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d/%d] Norm %d", + width, height, viddev->norm); + return 0; } @@ -441,34 +441,34 @@ static int set_geometry(struct video_dev *viddev, int width, int height) * set_input_format * Sets input format ( PAL, NTSC, SECAM, etc ... ) */ -static int set_input_format(struct video_dev *viddev, unsigned newformat) +static int set_input_format(struct video_dev *viddev, unsigned newformat) { int input_format[] = { NORM_PAL_NEW, NORM_NTSC_NEW, NORM_SECAM_NEW, NORM_DEFAULT_NEW}; int format; - + if (newformat >= array_elem(input_format)) { - MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%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)", newformat); return -1; - } + } - format = input_format[newformat]; + format = input_format[newformat]; if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format, " "try again with default"); format = NORM_DEFAULT_NEW; newformat = 3; - + if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { - MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%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"); return -1; } } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to %d", newformat); - + return newformat; } @@ -484,32 +484,32 @@ statict int setup_pixelformat(int bktr) if (ioctl(bktr, METEORGSUPPIXFMT, &p) < 0) { if (errno == EINVAL) break; - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGSUPPIXFMT getting pixformat %d", i); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGSUPPIXFMT getting pixformat %d", i); return -1; } - // Hack from xawtv 4.x + // Hack from xawtv 4.x switch (p.type) { case METEOR_PIXTYPE_RGB: - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB"); switch (p.masks[0]) { - case 31744: // 15 bpp + case 31744: // 15 bpp format = p.swap_bytes ? VIDEO_RGB15_LE : VIDEO_RGB15_BE; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); break; - case 63488: // 16 bpp + case 63488: // 16 bpp format = p.swap_bytes ? VIDEO_RGB16_LE : VIDEO_RGB16_BE; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); break; - case 16711680: // 24/32 bpp + case 16711680: // 24/32 bpp if (p.Bpp == 3 && p.swap_bytes == 1) { format = VIDEO_BGR24; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 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(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 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(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); @@ -518,26 +518,26 @@ statict int setup_pixelformat(int bktr) break; case METEOR_PIXTYPE_YUV: format = VIDEO_YUV422P; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV"); break; case METEOR_PIXTYPE_YUV_12: format = VIDEO_YUV422P; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_12"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_12"); break; case METEOR_PIXTYPE_YUV_PACKED: format = VIDEO_YUV422P; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); break; - + } if (p.type == METEOR_PIXTYPE_RGB && p.Bpp == 3) { - // Found a good pixeltype -- set it up + // Found a good pixeltype -- set it up if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3"); - // Not immediately fatal + // Not immediately fatal } - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_RGB %i", i); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_RGB %i", i); format = i; } @@ -546,8 +546,8 @@ statict int setup_pixelformat(int bktr) if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED"); // Not immediately fatal - } - MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_YUV_PACKED %i", i); + } + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_YUV_PACKED %i", i); format = i; } @@ -562,23 +562,23 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) { int dev = viddev->fd_bktr; - if ((cnt->conf.contrast) && (cnt->conf.contrast != viddev->contrast)) { + if ((cnt->conf.contrast) && (cnt->conf.contrast != viddev->contrast)) { set_contrast(dev, cnt->conf.contrast); - viddev->contrast = cnt->conf.contrast; + viddev->contrast = cnt->conf.contrast; } if ((cnt->conf.hue) && (cnt->conf.hue != viddev->hue)) { set_hue(dev, cnt->conf.hue); - viddev->hue = cnt->conf.hue; + viddev->hue = cnt->conf.hue; } - if ((cnt->conf.brightness) && + if ((cnt->conf.brightness) && (cnt->conf.brightness != viddev->brightness)) { set_brightness(dev, cnt->conf.brightness); - viddev->brightness = cnt->conf.brightness; + viddev->brightness = cnt->conf.brightness; } - if ((cnt->conf.saturation) && + if ((cnt->conf.saturation) && (cnt->conf.saturation != viddev->saturation)) { set_saturation(dev, cnt->conf.saturation); viddev->saturation = cnt->conf.saturation; @@ -593,7 +593,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) - setup_pixelformat - set_geometry - - set_brightness + - set_brightness - set_chroma - set_contrast - set_channelset @@ -601,13 +601,13 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) - set_capture_mode */ -static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, +static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, unsigned input, unsigned norm, unsigned long freq) { int dev_bktr = viddev->fd_bktr; struct sigaction act, old; //int dev_tunner = viddev->fd_tuner; - /* to ensure that all device will be support the capture mode + /* to ensure that all device will be support the capture mode _TODO_ : Autodected the best capture mode . */ int dummy = 1; @@ -618,26 +618,26 @@ 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(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for " + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for " "Source input [%i]", freq, input); return NULL; } else if (set_freq(viddev, freq) == -1) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]", 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(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", input); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", input); return NULL; } viddev->input = dummy; if ((dummy = set_input_format(viddev, norm)) == -1) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]", norm); return NULL; } @@ -645,18 +645,18 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, viddev->norm = dummy; if (set_geometry(viddev, width, height) == -1) { - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]", width, height); return NULL; } /* if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: set encoding method BSD_VIDFMT_I420"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: set encoding method BSD_VIDFMT_I420"); return NULL; } - NEEDED !? FIXME + NEEDED !? FIXME if (setup_pixelformat(viddev) == -1) return NULL; @@ -675,23 +675,23 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, } /* - * Set capture mode and capture buffers + * Set capture mode and capture buffers * That is the buffer size for capture images , - * so is dependent of color space of input format / FIXME + * 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; - - map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, + + map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev_bktr, (off_t)0); if (map == MAP_FAILED) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed"); return NULL; } - /* FIXME double buffer */ + /* FIXME double buffer */ if (0) { viddev->v4l_maxbuffer = 2; viddev->v4l_buffers[0] = map; @@ -715,25 +715,24 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, sigemptyset(&act.sa_mask); act.sa_handler = catchsignal; sigaction(SIGUSR2, &act, &old); - + dummy = SIGUSR2; //viddev->capture_method = METEOR_CAP_CONTINOUS; //viddev->capture_method = METEOR_CAP_SINGLE; - - if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && + + if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) { - MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSSIGNAL"); - MOTION_LOG(ERR, TYPE_VIDEO, TYPE_VIDEO, NO_ERRNO, "%s: METEORSSIGNAL"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: METEORSSIGNAL"); viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing"); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing"); - } + } } else { if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { viddev->capture_method = METEOR_CAP_SINGLE; @@ -741,17 +740,15 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " "Error capturing"); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " - "Error capturing"); - } - } - } - + } + } + } + if (viddev->capture_method == METEOR_CAP_CONTINOUS) - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS"); - else - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_SINGLE"); - + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS"); + else + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_SINGLE"); + // settle , sleep(1) replaced SLEEP(1, 0); @@ -770,16 +767,16 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, viddev->v4l_bufsize = width * height; break; } - - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: HUE [%d]", + + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: HUE [%d]", get_hue(dev_bktr, &dummy)); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: SATURATION [%d]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: SATURATION [%d]", get_saturation(dev_bktr, &dummy)); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: BRIGHTNESS [%d]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy)); - MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: CONTRAST [%d]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: CONTRAST [%d]", get_contrast(dev_bktr, &dummy)); - + return map; } @@ -807,9 +804,9 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int /* ONLY MMAP method is used to Capture */ - /* - * Allocates a new mmap buffer - * Block signals during IOCTL + /* + * Allocates a new mmap buffer + * Block signals during IOCTL */ sigemptyset (&set); sigaddset (&set, SIGCHLD); @@ -825,11 +822,11 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int viddev->v4l_curbuffer = 0; /* Capture */ - + if (viddev->capture_method == METEOR_CAP_CONTINOUS) { - if (bktr_frame_waiting) - bktr_frame_waiting = 0; - + if (bktr_frame_waiting) + bktr_frame_waiting = 0; + } else if (ioctl(dev_bktr, METEORCAPTUR, &single) < 0) { MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error capturing using single method"); sigprocmask(SIG_UNBLOCK, &old, NULL); @@ -838,7 +835,7 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int /* Undo the signal blocking */ pthread_sigmask(SIG_UNBLOCK, &old, NULL); - + switch (viddev->v4l_fmt) { case VIDEO_PALETTE_RGB24: rgb24toyuv420p(map, cap_map, width, height); @@ -849,34 +846,34 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int default: memcpy(map, cap_map, viddev->v4l_bufsize); } - + return 0; } /** - * v4l_set_input + * 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, +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; - + if ((dummy = set_input(viddev, input)) == -1) return; viddev->input = dummy; - + if ((dummy = set_input_format(viddev, norm)) == -1) return; - + viddev->norm = dummy; - - if ((viddev->tuner_device != NULL) && (viddev->input == IN_TV) && + + if ((viddev->tuner_device != NULL) && (viddev->input == IN_TV) && (frequnits > 0)) { if (set_freq(viddev, freq) == -1) return; @@ -891,8 +888,8 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne if (set_geometry(viddev, width, height) == -1) return; - */ - + */ + v4l_picture_controls(cnt, viddev); viddev->freq = freq; @@ -914,22 +911,22 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne vid_init - Initi vid_mutex. vid_start - Setup Device parameters ( device , channel , freq , contrast , hue , saturation , brightness ) and open it. -vid_next - Capture a frame and set input , contrast , hue , saturation and brightness if necessary. -vid_close - close devices. +vid_next - Capture a frame and set input , contrast , hue , saturation and brightness if necessary. +vid_close - close devices. vid_cleanup - Destroy vid_mutex. */ -/* +/* * Big lock for vid_start to ensure exclusive access to viddevs while adding * devices during initialization of each thread. */ 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; /** @@ -942,7 +939,7 @@ void vid_init(void) { pthread_mutex_init(&vid_mutex, NULL); } - + /** * vid_cleanup * @@ -960,7 +957,7 @@ void vid_cleanup(void) * * vid_close is called from motion.c when a Motion thread is stopped or restarted. */ -void vid_close(struct context *cnt) +void vid_close(struct context *cnt) { #ifndef WITHOUT_V4L struct video_dev *dev = viddevs; @@ -972,7 +969,7 @@ void vid_close(struct context *cnt) netcam_cleanup(cnt->netcam, 0); cnt->netcam = NULL; return; - } + } #ifndef WITHOUT_V4L @@ -987,23 +984,23 @@ void vid_close(struct context *cnt) } pthread_mutex_unlock(&vid_mutex); - + /* Set it as closed in thread context. */ cnt->video_dev = -1; - + if (dev == NULL) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); return; } if (--dev->usage_count == 0) { - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", dev->video_device); if (dev->fd_tuner > 0) close(dev->fd_tuner); - if (dev->fd_bktr > 0) { + if (dev->fd_bktr > 0) { if (dev->capture_method == METEOR_CAP_CONTINOUS) { dev->fd_tuner = METEOR_CAP_STOP_CONT; ioctl(dev->fd_bktr, METEORCAPTUR, &dev->fd_tuner); @@ -1031,10 +1028,10 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, " - "so we don't close it now", dev->usage_count, + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, " + "so we don't close it now", dev->usage_count, dev->video_device); - /* + /* * There is still at least one thread using this device * If we own it, release it. */ @@ -1051,7 +1048,7 @@ void vid_close(struct context *cnt) /** * vid_start * - */ + */ int vid_start(struct context *cnt) { struct config *conf = &cnt->conf; @@ -1063,10 +1060,10 @@ int vid_start(struct context *cnt) netcam_cleanup(cnt->netcam, 1); cnt->netcam = NULL; } - } + } #ifdef WITHOUT_V4L - else - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); + else + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); #else else { struct video_dev *dev; @@ -1076,12 +1073,12 @@ int vid_start(struct context *cnt) unsigned long frequency; - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: [%s]", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: [%s]", conf->video_device); - /* + /* * We use width and height from conf in this function. They will be assigned - * to width and height in imgs here, and cap_width and cap_height in + * 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. */ @@ -1105,7 +1102,7 @@ int vid_start(struct context *cnt) norm = conf->norm; frequency = conf->frequency; capture_method = METEOR_CAP_CONTINOUS; - + pthread_mutex_lock(&vid_mutex); /* @@ -1123,23 +1120,23 @@ int vid_start(struct context *cnt) * and return the file descriptor. */ dev = viddevs; - while (dev) { + while (dev) { if (!strcmp(conf->video_device, dev->video_device)) { int dummy = METEOR_CAP_STOP_CONT; dev->usage_count++; cnt->imgs.type = dev->v4l_fmt; if (ioctl(dev->fd_bktr, METEORCAPTUR, &dummy) < 0) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s Stopping capture"); - return -1; - } - - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s Reusing [%s] inputs [%d,%d] Change " - "capture method METEOR_CAP_SINGLE", dev->video_device, + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s Stopping capture"); + return -1; + } + + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s Reusing [%s] inputs [%d,%d] Change " + "capture method METEOR_CAP_SINGLE", dev->video_device, dev->input, conf->input); dev->capture_method = METEOR_CAP_SINGLE; - + switch (cnt->imgs.type) { case VIDEO_PALETTE_GREY: cnt->imgs.motionsize = width * height; @@ -1149,7 +1146,7 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s VIDEO_PALETTE_YUV420P setting" + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s VIDEO_PALETTE_YUV420P setting" " imgs.size and imgs.motionsize"); cnt->imgs.motionsize = width * height; cnt->imgs.size = (width * height * 3) / 2; @@ -1168,8 +1165,8 @@ int vid_start(struct context *cnt) fd_bktr = open(conf->video_device, O_RDWR); - if (fd_bktr < 0) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: open video device %s", + if (fd_bktr < 0) { + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: open video device %s", conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -1180,8 +1177,8 @@ int vid_start(struct context *cnt) /* Only open tuner if conf->tuner_device has set , freq and input is 1. */ if ((conf->tuner_device != NULL) && (frequency > 0) && (input == IN_TV)) { fd_tuner = open(conf->tuner_device, O_RDWR); - if (fd_tuner < 0) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: open tuner device %s", + if (fd_tuner < 0) { + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: open tuner device %s", conf->tuner_device); free(dev); pthread_mutex_unlock(&vid_mutex); @@ -1203,24 +1200,24 @@ int vid_start(struct context *cnt) dev->freq = frequency; dev->owner = -1; dev->capture_method = capture_method; - + /* * We set brightness, contrast, saturation and hue = 0 so that they only get * set if the config is not zero. */ - + dev->brightness = 0; dev->contrast = 0; dev->saturation = 0; dev->hue = 0; dev->owner = -1; - /* Default palette */ + /* Default palette */ dev->v4l_fmt = VIDEO_PALETTE_YUV420P; dev->v4l_curbuffer = 0; dev->v4l_maxbuffer = 1; - if (!v4l_start(dev, width, height, input, norm, frequency)) { + if (!v4l_start(dev, width, height, input, norm, frequency)) { close(dev->fd_bktr); pthread_mutexattr_destroy(&dev->attr); pthread_mutex_destroy(&dev->mutex); @@ -1229,10 +1226,10 @@ int vid_start(struct context *cnt) pthread_mutex_unlock(&vid_mutex); return -1; } - + cnt->imgs.type = dev->v4l_fmt; - - switch (cnt->imgs.type) { + + switch (cnt->imgs.type) { case VIDEO_PALETTE_GREY: cnt->imgs.size = width * height; cnt->imgs.motionsize = width * height; @@ -1241,7 +1238,7 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: VIDEO_PALETTE_YUV420P imgs.type"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: VIDEO_PALETTE_YUV420P imgs.type"); cnt->imgs.size = (width * height * 3) / 2; cnt->imgs.motionsize = width * height; break; @@ -1250,7 +1247,7 @@ int vid_start(struct context *cnt) /* Insert into linked list */ dev->next = viddevs; viddevs = dev; - + pthread_mutex_unlock(&vid_mutex); } #endif /* !WITHOUT_V4L */ @@ -1288,29 +1285,29 @@ int vid_next(struct context *cnt, unsigned char *map) #ifndef WITHOUT_V4L - struct video_dev *dev; + struct video_dev *dev; int width, height; int dev_bktr = cnt->video_dev; /* NOTE: Since this is a capture, we need to use capture dimensions. */ width = cnt->rotate_data.cap_width; height = cnt->rotate_data.cap_height; - + pthread_mutex_lock(&vid_mutex); - dev = viddevs; + dev = viddevs; while (dev) { if (dev->fd_bktr == dev_bktr) break; dev = dev->next; } - + pthread_mutex_unlock(&vid_mutex); if (dev == NULL) return V4L_FATAL_ERROR; - if (dev->owner != cnt->threadnr) { + if (dev->owner != cnt->threadnr) { pthread_mutex_lock(&dev->mutex); dev->owner = cnt->threadnr; dev->frames = conf->roundrobin_frames; @@ -1319,20 +1316,20 @@ int vid_next(struct context *cnt, unsigned char *map) v4l_set_input(cnt, dev, map, width, height, conf->input, conf->norm, conf->roundrobin_skip, conf->frequency); - + ret = v4l_next(dev, map, width, height); - if (--dev->frames <= 0) { + if (--dev->frames <= 0) { dev->owner = -1; dev->frames = 0; pthread_mutex_unlock(&dev->mutex); } - + /* Rotate the image as specified */ - if (cnt->rotate_data.degrees > 0) + if (cnt->rotate_data.degrees > 0) rotate_map(cnt, map); - - + + #endif /* !WITHOUT_V4L */ return ret; } diff --git a/video_freebsd.h b/video_freebsd.h index 7da9acb..c75692f 100644 --- a/video_freebsd.h +++ b/video_freebsd.h @@ -2,7 +2,7 @@ * video_freebsd.h * * Include file for video_freebsd.c - * Copyright 2004 by Angel Carpintero (ack@telefonica.net) + * Copyright 2004 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * @@ -31,7 +31,7 @@ /* not used yet FIXME ! only needed for tuner use */ /* -#define TV_INPUT_NTSCM BT848_IFORM_F_NTSCM +#define TV_INPUT_NTSCM BT848_IFORM_F_NTSCM #define TV_INPUT_NTSCJ BT848_IFORM_F_NTSCJ #define TV_INPUT_PALBDGHI BT848_IFORM_F_PALBDGHI #define TV_INPUT_PALM BT848_IFORM_F_PALM @@ -45,22 +45,22 @@ #define V4L_BTTVLOST_ERROR 0x05 /* binary 000101 */ #define V4L_FATAL_ERROR -1 -#define NORM_DEFAULT 0x00800 // METEOR_FMT_AUTOMODE -#define NORM_PAL 0x00200 // METEOR_FMT_PAL -#define NORM_NTSC 0x00100 // METEOR_FMT_NTSC +#define NORM_DEFAULT 0x00800 // METEOR_FMT_AUTOMODE +#define NORM_PAL 0x00200 // METEOR_FMT_PAL +#define NORM_NTSC 0x00100 // METEOR_FMT_NTSC #define NORM_SECAM 0x00400 // METEOR_FMT_SECAM #define NORM_PAL_NC 0x00200 // METEOR_FMT_PAL /* Greyscale howto ?! FIXME */ -#define NORM_DEFAULT_NEW BT848_IFORM_F_AUTO -#define NORM_PAL_NEW BT848_IFORM_F_PALBDGHI +#define NORM_DEFAULT_NEW BT848_IFORM_F_AUTO +#define NORM_PAL_NEW BT848_IFORM_F_PALBDGHI #define NORM_NTSC_NEW BT848_IFORM_F_NTSCM -#define NORM_SECAM_NEW BT848_IFORM_F_SECAM -#define NORM_PAL_NC_NEW BT848_IFORM_F_AUTO /* FIXME */ +#define NORM_SECAM_NEW BT848_IFORM_F_SECAM +#define NORM_PAL_NC_NEW BT848_IFORM_F_AUTO /* FIXME */ #define PAL 0 #define NTSC 1 #define SECAM 2 -#define PAL_NC 3 +#define PAL_NC 3 #define PAL_HEIGHT 576 #define SECAM_HEIGHT 576 @@ -77,7 +77,7 @@ #define BSD_VIDFMT_LAST 8 -#define IN_DEFAULT 0 +#define IN_DEFAULT 0 #define IN_COMPOSITE 0 #define IN_TV 1 #define IN_COMPOSITE2 2 @@ -112,10 +112,10 @@ struct video_dev { pthread_mutexattr_t attr; int owner; int frames; - + /* Device type specific stuff: */ -#ifndef WITHOUT_V4L - int capture_method; +#ifndef WITHOUT_V4L + int capture_method; int v4l_fmt; unsigned char *v4l_buffers[2]; int v4l_curbuffer; diff --git a/vloopback_motion.c b/vloopback_motion.c index d014017..5cd28ad 100644 --- a/vloopback_motion.c +++ b/vloopback_motion.c @@ -3,7 +3,7 @@ * * Video loopback functions for motion. * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org) - * Copyright 2008 by Angel Carpintero (ack@telefonica.net) + * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * @@ -16,7 +16,7 @@ /** * v4l_open_vidpipe * - */ + */ static int v4l_open_vidpipe(void) { int pipe_fd = -1; @@ -27,15 +27,15 @@ static int v4l_open_vidpipe(void) struct utsname uts; if (uname(&uts) < 0) { - MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname"); - return -1; + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname"); + return -1; } major = strtok(uts.release, "."); minor = strtok(NULL, "."); if ((major == NULL) || (minor == NULL) || (strcmp(major, "2"))) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version"); + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version"); return -1; } @@ -50,27 +50,27 @@ static int v4l_open_vidpipe(void) vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r"); if (!vloopbacks) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open " + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open " "'/proc/video/vloopback/vloopbacks'"); return -1; } - + /* Read vloopback version*/ if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version"); + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version"); return -1; } - + fprintf(stderr, "\t%s", buffer); - + /* Read explanation line */ - + if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback" + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback" " explanation line"); return -1; } - + while (fgets(buffer, sizeof(buffer), vloopbacks)) { if (strlen(buffer) > 1) { buffer[strlen(buffer)-1] = 0; @@ -85,7 +85,7 @@ static int v4l_open_vidpipe(void) pipe_fd = open(pipepath, O_RDWR); if (pipe_fd >= 0) { - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s " + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s " "\tOutput: /dev/%s", input, output); break; } @@ -105,7 +105,7 @@ static int v4l_open_vidpipe(void) int tnum; if ((dir = opendir(prefix)) == NULL) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'", + MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'", prefix); return -1; } @@ -132,7 +132,7 @@ static int v4l_open_vidpipe(void) major = strtok(NULL, " "); minor = strtok(NULL, " "); io = strtok(NULL, " \n"); - + if (strcmp(major, "loopback") || strcmp(io, "input")) { close(fd); continue; @@ -151,9 +151,9 @@ static int v4l_open_vidpipe(void) if ((tfd = open(buffer, O_RDWR)) >= 0) { strncpy(pipepath, buffer, sizeof(pipepath)); - if (pipe_fd >= 0) + if (pipe_fd >= 0) close(pipe_fd); - + pipe_fd = tfd; low = tnum; } @@ -166,7 +166,7 @@ static int v4l_open_vidpipe(void) closedir(dir); if (pipe_fd >= 0) - MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", pipepath); } @@ -176,7 +176,7 @@ static int v4l_open_vidpipe(void) /** * v4l_startpipe * - */ + */ static int v4l_startpipe(const char *dev_name, int width, int height, int type) { int dev; @@ -187,30 +187,30 @@ 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(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", dev_name); } if (dev < 0) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed", + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed", dev_name); return -1; } if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); return -1; } vid_pic.palette = type; if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)"); return -1; } if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) { - MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)"); return -1; } @@ -218,7 +218,7 @@ 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(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)"); return -1; } @@ -228,7 +228,7 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type) /** * v4l_putpipe * - */ + */ static int v4l_putpipe(int dev, unsigned char *image, int size) { return write(dev, image, size); diff --git a/vloopback_motion.h b/vloopback_motion.h index 4f1a347..dc0016b 100644 --- a/vloopback_motion.h +++ b/vloopback_motion.h @@ -2,7 +2,7 @@ * * Include file for vloopback_motion.c * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org) - * Copyright 2008 by Angel Carpintero (ack@telefonica.net) + * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU public license version 2 * See also the file 'COPYING'. * diff --git a/webhttpd.c b/webhttpd.c index 94e06df..af6a387 100644 --- a/webhttpd.c +++ b/webhttpd.c @@ -5,7 +5,7 @@ * * Specs : http://www.lavrsen.dk/twiki/bin/view/Motion/MotionHttpAPI * - * Copyright 2004-2005 by Angel Carpintero (ack@telefonica.net) + * Copyright 2004-2005 by Angel Carpintero (motiondevelop@gmail.com) * This software is distributed under the GNU Public License Version 2 * See also the file 'COPYING'. * @@ -153,7 +153,7 @@ static const char *error_value_raw = "HTTP/1.0 200 OK\r\n" "Content-type: text/plain\r\n\r\n" "Value Error"; - + static const char *not_found_response_valid_command = "HTTP/1.0 404 Not Valid Command\r\n" "Content-type: text/html\r\n\r\n" @@ -249,7 +249,7 @@ 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(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -260,7 +260,7 @@ 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(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -271,7 +271,7 @@ 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(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -336,10 +336,10 @@ static char *replace(const char *str, const char *old, const char *new) strcpy(r, p); return ret; -} +} /** - * url_decode + * url_decode * This function decode the values from GET request following the http RFC. * * Returns nothing. @@ -372,7 +372,7 @@ static void url_decode(char *urlencoded, size_t length) } else if (*data == '+') { *urldecoded++ = ' '; - + } else { *urldecoded++ = *data; } @@ -385,12 +385,12 @@ static void url_decode(char *urlencoded, size_t length) /** - * config + * config * Manages/parses the config action for motion ( set , get , write , list ). * * Returns 1 to exit from function. */ -static unsigned int config(char *pointer, char *res, unsigned int length_uri, +static unsigned int config(char *pointer, char *res, unsigned int length_uri, unsigned int thread, int client_socket, void *userdata) { char question='\0'; @@ -408,28 +408,28 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, /*call list*/ if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); - sprintf(res, "<– back

\nThread %hu\n
    ", + sprintf(res, "<– back

    \nThread %hu\n
      ", thread, thread); send_template(client_socket, res); for (i=0; config_params[i].param_name != NULL; i++) { - if ((thread != 0) && (config_params[i].main_thread)) + if ((thread != 0) && (config_params[i].main_thread)) continue; value = config_params[i].print(cnt, NULL, i, thread); if (value == NULL) { retval = NULL; - - /* Only get the thread value for main thread */ + + /* Only get the thread value for main thread */ if (thread == 0) config_params[i].print(cnt, &retval, i, thread); - + /* thread value*/ - + if (retval) { - + if (!strcmp(retval,"")) { free(retval); retval = mystrdup("No threads"); @@ -439,7 +439,7 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, size_t retval_len = strlen(retval); unsigned int ind = 0; char thread_strings[1024] = {'\0'}; - + while (retval_miss != retval_len) { while (*temp != '\n') { thread_strings[ind++] = *temp; @@ -457,14 +457,14 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, retval = NULL; retval = mystrdup(thread_strings); } - + sprintf(res, "
    • %s = %s
    • \n", thread, config_params[i].param_name, config_params[i].param_name, retval); free(retval); } else if (thread != 0) { /* get the value from main thread for the rest of threads */ value = config_params[i].print(cnt, NULL, i, 0); - + sprintf(res, "
    • %s = %s
    • \n", thread, config_params[i].param_name, config_params[i].param_name, value ? value : "(not defined)"); @@ -473,7 +473,7 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, config_params[i].param_name, config_params[i].param_name, "(not defined)"); } - + } else { sprintf(res, "
    • %s = %s
    • \n", thread, config_params[i].param_name, config_params[i].param_name, value); @@ -543,7 +543,7 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, "
    Done", thread, thread, thread, config_params[i].param_name, config_params[i].param_name, Value); - + send_template_ini_client(client_socket, ini_template); send_template(client_socket, res); send_template_end_client(client_socket); @@ -584,10 +584,10 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, if (cnt[0]->conf.webcontrol_html_output) { sprintf(res, "<– back

    \n" - "Thread %hu\n
    • %s" - "= %s

    Done", thread, thread, thread, + "Thread %hu\n
    • %s" + "= %s

    Done", thread, thread, thread, config_params[i].param_name, config_params[i].param_name, type); - + send_template_ini_client(client_socket, ini_template); send_template(client_socket, res); send_template_end_client(client_socket); @@ -623,10 +623,10 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, } /* param_name exists */ if (config_params[i].param_name) { - const char *value = NULL; + const char *value = NULL; char *text_help = NULL; char *sharp = NULL; - + value = config_params[i].print(cnt, NULL, i, thread); sharp = strstr(config_params[i].param_help, "#\n\n#"); @@ -635,21 +635,21 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, sharp++; text_help = replace(sharp, "\n#", "
    "); - + send_template_ini_client(client_socket, ini_template); if (!strcmp ("bool", config_type(&config_params[i]))) { char option[80] = {'\0'}; - + if ((value == NULL) && (thread != 0)) value = config_params[i].print(cnt, NULL, i, 0); - + if (!strcmp ("on", value)) sprintf(option, "\n" "\n"); else sprintf(option, "\n" "\n"); - + sprintf(res, "<– back

    \n" "Thread %hu\n" "
    \n" @@ -662,11 +662,11 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, config_params[i].param_name, config_params[i].param_name, option, TWIKI_URL, config_params[i].param_name, text_help); } else { - + if (value == NULL) { if (thread != 0) /* get the value from main thread for the rest of threads */ - value = config_params[i].print(cnt, NULL, i, 0); + value = config_params[i].print(cnt, NULL, i, 0); if (value == NULL) value = ""; } sprintf(res, "<– back

    \n" @@ -761,7 +761,7 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, break; i++; } - /* + /* * FIXME bool values or commented values maybe that should be * solved with config_type */ @@ -795,8 +795,8 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, sprintf(res, "<– back

    \n" "Thread %hu
    \n
    %s", - thread, thread, config_params[i].param_name, value, + "[help]

%s", + thread, thread, config_params[i].param_name, value, TWIKI_URL, config_params[i].param_name, text_help); send_template(client_socket, res); @@ -827,7 +827,7 @@ static unsigned int config(char *pointer, char *res, unsigned int length_uri, } else if (length_uri == 0) { if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); - sprintf(res, "<– back

\nThread %hu
\n" + sprintf(res, "<– back

\nThread %hu
\n" "\n" "