Update log adding function name , remove setup_mode as a login level. Added servo_position() and check limits to avoid overflow maxN , minN

This commit is contained in:
AngelCarpintero
2008-07-07 13:53:42 +00:00
parent 612e08cd36
commit dc27136cbe
17 changed files with 775 additions and 632 deletions

24
conf.c
View File

@@ -1459,7 +1459,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
}
/* We reached the end of config_params without finding a matching option */
motion_log(LOG_ERR, 0, "Unknown config option \"%s\"", cmd);
motion_log(LOG_ERR, 0, "%s: Unknown config option \"%s\"", __FUNCTION__, cmd);
return cnt;
}
@@ -1550,7 +1550,8 @@ void conf_print(struct context **cnt)
FILE *conffile;
for (thread = 0; cnt[thread]; thread++) {
motion_log(LOG_INFO, 0, "Writing config file to %s", cnt[thread]->conf_filename);
motion_log(LOG_INFO, 0, "%s: Writing config file to %s",
__FUNCTION__, cnt[thread]->conf_filename);
conffile = myfopen(cnt[thread]->conf_filename, "w");
if (!conffile)
continue;
@@ -1658,9 +1659,10 @@ struct context ** conf_load (struct context **cnt)
if (!fp) { /* Commandline didn't work, try current dir */
char *path = NULL;
if (cnt[0]->conf_filename[0])
motion_log(-1, 1, "Configfile %s not found - trying defaults.", filename);
motion_log(-1, 1, "%s: Configfile %s not found - trying defaults.",
__FUNCTION__, filename);
if ( (path = get_current_dir_name()) == NULL) {
motion_log(LOG_ERR, 1, "Error get_current_dir_name");
motion_log(LOG_ERR, 1, "%s: Error get_current_dir_name", __FUNCTION__);
exit(-1);
}
snprintf(filename, PATH_MAX, "%s/motion.conf", path);
@@ -1674,18 +1676,21 @@ struct context ** conf_load (struct context **cnt)
snprintf(filename, PATH_MAX, "%s/motion.conf", sysconfdir);
fp = fopen(filename, "r");
if (!fp) /* there is no config file.... use defaults */
motion_log(-1, 1, "could not open configfile %s", filename);
motion_log(-1, 1, "%s: could not open configfile %s",
__FUNCTION__, filename);
}
}
/* Now we process the motion.conf config file and close it*/
if (fp) {
strcpy(cnt[0]->conf_filename, filename);
motion_log(LOG_INFO, 0, "Processing thread 0 - config file %s", filename);
motion_log(LOG_INFO, 0, "%s: Processing thread 0 - config file %s",
__FUNCTION__, filename);
cnt = conf_process(cnt, fp);
fclose(fp);
} else {
motion_log(LOG_INFO, 0, "Not config file to process using default values");
motion_log(LOG_INFO, 0, "%s: Not config file to process using default values",
__FUNCTION__);
}
@@ -2032,7 +2037,8 @@ static struct context **config_thread(struct context **cnt, const char *str,
fp = fopen(str, "r");
if (!fp) {
motion_log(LOG_ERR, 1, "Thread config file %s not found", str);
motion_log(LOG_ERR, 1, "%s: Thread config file %s not found",
__FUNCTION__, str);
return cnt;
}
@@ -2066,7 +2072,7 @@ static struct context **config_thread(struct context **cnt, const char *str,
/* process the thread's config file and notify user on console */
strcpy(cnt[i]->conf_filename, str);
motion_log(LOG_INFO, 0, "Processing config file %s", str);
motion_log(LOG_INFO, 0, "%s: Processing config file %s", __FUNCTION__, str);
conf_process(cnt+i, fp);
/* Finally we close the thread config file */

18
configure vendored
View File

@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for motion trunk-r374.
# Generated by GNU Autoconf 2.61 for motion trunk-r375.
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
@@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='motion'
PACKAGE_TARNAME='motion'
PACKAGE_VERSION='trunk-r374'
PACKAGE_STRING='motion trunk-r374'
PACKAGE_VERSION='trunk-r375'
PACKAGE_STRING='motion trunk-r375'
PACKAGE_BUGREPORT=''
ac_unique_file="motion.c"
@@ -1177,7 +1177,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures motion trunk-r374 to adapt to many kinds of systems.
\`configure' configures motion trunk-r375 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1238,7 +1238,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of motion trunk-r374:";;
short | recursive ) echo "Configuration of motion trunk-r375:";;
esac
cat <<\_ACEOF
@@ -1374,7 +1374,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
motion configure trunk-r374
motion configure trunk-r375
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1388,7 +1388,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by motion $as_me trunk-r374, which was
It was created by motion $as_me trunk-r375, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -8666,7 +8666,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by motion $as_me trunk-r374, which was
This file was extended by motion $as_me trunk-r375, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -8715,7 +8715,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
motion config.status trunk-r374
motion config.status trunk-r375
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"

38
event.c
View File

@@ -47,12 +47,12 @@ static void exec_command(struct context *cnt, char *command, char *filename, int
execl("/bin/sh", "sh", "-c", stamp, " &", NULL);
/* if above function succeeds the program never reach here */
motion_log(LOG_ERR, 1, "Unable to start external command '%s'", stamp);
motion_log(LOG_ERR, 1, "%s: Unable to start external command '%s'", __FUNCTION__, stamp);
exit(1);
}
else if (cnt->conf.setup_mode)
motion_log(-1, 0, "Executing external command '%s'", stamp);
else if (debug_level >= CAMERA_VERBOSE)
motion_log(-1, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp);
}
/*
@@ -63,7 +63,8 @@ static void event_newfile(struct context *cnt ATTRIBUTE_UNUSED,
int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED,
char *filename, void *ftype, struct tm *tm ATTRIBUTE_UNUSED)
{
motion_log(-1, 0, "File of type %ld saved to: %s", (unsigned long)ftype, filename);
motion_log(-1, 0, "%s: File of type %ld saved to: %s", __FUNCTION__,
(unsigned long)ftype, filename);
}
@@ -130,17 +131,20 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
if (mysql_query(cnt->database, sqlquery) != 0){
int error_code = mysql_errno(cnt->database);
motion_log(LOG_ERR, 1, "Mysql query failed %s error code %d",
mysql_error(cnt->database), error_code);
motion_log(LOG_ERR, 1, "%s: Mysql query failed %s error code %d",
__FUNCTION__, mysql_error(cnt->database), error_code);
/* Try to reconnect ONCE if fails continue and discard this sql query */
if (error_code >= 2000){
cnt->database = (MYSQL *) mymalloc(sizeof(MYSQL));
mysql_init(cnt->database);
if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user,
cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) {
motion_log(LOG_ERR, 0, "Cannot reconnect to MySQL database %s on host %s with user %s",
cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user);
motion_log(LOG_ERR, 0, "MySQL error was %s", mysql_error(cnt->database));
motion_log(LOG_ERR, 0, "%s: Cannot reconnect to MySQL database "
"%s on host %s with user %s MySQL error was %s",
__FUNCTION__, cnt->conf.database_dbname,
cnt->conf.database_host, cnt->conf.database_user,
mysql_error(cnt->database));
}else mysql_query(cnt->database, sqlquery);
}
}
@@ -154,7 +158,7 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
res = PQexec(cnt->database_pg, sqlquery);
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
motion_log(LOG_ERR, 1, "PGSQL query failed");
motion_log(LOG_ERR, 1, "%s: PGSQL query failed", __FUNCTION__);
PQclear(res);
}
}
@@ -216,7 +220,7 @@ static void event_vid_putpipe(struct context *cnt, int type ATTRIBUTE_UNUSED,
{
if (*(int *)devpipe >= 0) {
if (vid_putpipe(*(int *)devpipe, img, cnt->imgs.size) == -1)
motion_log(LOG_ERR, 1, "Failed to put image into video pipe");
motion_log(LOG_ERR, 1, "%s: Failed to put image into video pipe", __FUNCTION__);
}
}
#endif /* BSD */
@@ -310,7 +314,8 @@ static void event_image_snapshot(struct context *cnt, int type ATTRIBUTE_UNUSED,
snprintf(linkpath, PATH_MAX, "%s/lastsnap.%s", cnt->conf.filepath, imageext(cnt));
remove(linkpath);
if (symlink(filename, linkpath)) {
motion_log(LOG_ERR, 1, "Could not create symbolic link [%s]", filename);
motion_log(LOG_ERR, 1, "%s: Could not create symbolic link [%s]",
__FUNCTION__, filename);
return;
}
} else {
@@ -402,7 +407,8 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->newfilename, y, u, v,
cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps,
cnt->conf.ffmpeg_vbr)) == NULL) {
motion_log(LOG_ERR, 1, "ffopen_open error creating (new) file [%s]", cnt->newfilename);
motion_log(LOG_ERR, 1, "s%: ffopen_open error creating (new) file [%s]",
__FUNCTION__, cnt->newfilename);
cnt->finish = 1;
return;
}
@@ -427,7 +433,8 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->motionfilename, y, u, v,
cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps,
cnt->conf.ffmpeg_vbr)) == NULL){
motion_log(LOG_ERR, 1, "ffopen_open error creating (motion) file [%s]", cnt->motionfilename);
motion_log(LOG_ERR, 1, "%s: ffopen_open error creating (motion) file [%s]",
__FUNCTION__, cnt->motionfilename);
cnt->finish = 1;
return;
}
@@ -478,7 +485,8 @@ static void event_ffmpeg_timelapse(struct context *cnt,
ffmpeg_open((char *)TIMELAPSE_CODEC, cnt->timelapsefilename, y, u, v,
cnt->imgs.width, cnt->imgs.height, 24, cnt->conf.ffmpeg_bps,
cnt->conf.ffmpeg_vbr)) == NULL) {
motion_log(LOG_ERR, 1, "ffopen_open error creating (timelapse) file [%s]", cnt->timelapsefilename);
motion_log(LOG_ERR, 1, "%s: ffopen_open error creating (timelapse) file [%s]",
__FUNCTION__, cnt->timelapsefilename);
cnt->finish = 1;
return;
}

View File

@@ -206,7 +206,8 @@ static int mpeg1_write_trailer(AVFormatContext *s)
/* ffmpeg_init initializes for libavformat. */
void ffmpeg_init()
{
motion_log(LOG_INFO, 0, "ffmpeg LIBAVCODEC_BUILD %d LIBAVFORMAT_BUILD %d", LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD);
motion_log(LOG_INFO, 0, "%s: ffmpeg LIBAVCODEC_BUILD %d LIBAVFORMAT_BUILD %d",
__FUNCTION__, LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD);
av_register_all();
#if LIBAVCODEC_BUILD > 4680
@@ -255,7 +256,8 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename)
}
#ifdef FFMPEG_NO_NONSTD_MPEG1
} else if (strcmp(codec, "mpeg1") == 0) {
motion_log(LOG_ERR, 0, "*** mpeg1 support for normal videos has been disabled ***");
motion_log(LOG_ERR, 0, "%s: *** mpeg1 support for normal videos has been disabled ***",
__FUNCTION__);
return NULL;
#endif
} else if (strcmp(codec, "mpeg4") == 0) {
@@ -286,12 +288,13 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename)
ext = ".mov";
of = guess_format("mov", NULL, NULL);
} else {
motion_log(LOG_ERR, 0, "ffmpeg_video_codec option value %s is not supported", codec);
motion_log(LOG_ERR, 0, "%s: ffmpeg_video_codec option value %s is not supported",
__FUNCTION__, codec);
return NULL;
}
if (!of) {
motion_log(LOG_ERR, 0, "Could not guess format for %s", codec);
motion_log(LOG_ERR, 0, "%s: Could not guess format for %s", __FUNCTION__, codec);
return NULL;
}
@@ -331,7 +334,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
/* allocation the output media context */
ffmpeg->oc = av_mallocz(sizeof(AVFormatContext));
if (!ffmpeg->oc) {
motion_log(LOG_ERR, 1, "Memory error while allocating output media context");
motion_log(LOG_ERR, 1, "%s: Memory error while allocating output media context", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -350,13 +353,13 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
if (ffmpeg->oc->oformat->video_codec != CODEC_ID_NONE) {
ffmpeg->video_st = av_new_stream(ffmpeg->oc, 0);
if (!ffmpeg->video_st) {
motion_log(LOG_ERR, 1, "av_new_stream - could not alloc stream");
motion_log(LOG_ERR, 1, "%s: av_new_stream - could not alloc stream", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
} else {
/* We did not get a proper video codec. */
motion_log(LOG_ERR, 0, "Failed to obtain a proper video codec");
motion_log(LOG_ERR, 0, "%s: Failed to obtain a proper video codec", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -404,7 +407,8 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
/* set the output parameters (must be done even if no parameters). */
if (av_set_parameters(ffmpeg->oc, NULL) < 0) {
motion_log(LOG_ERR, 0, "ffmpeg av_set_parameters error: Invalid output format parameters");
motion_log(LOG_ERR, 0, "%s: av_set_parameters error: Invalid output format parameters",
__FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -416,7 +420,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
codec and allocate the necessary encode buffers */
codec = avcodec_find_encoder(c->codec_id);
if (!codec) {
motion_log(LOG_ERR, 1, "Codec not found");
motion_log(LOG_ERR, 1, "%s: Codec not found", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -431,7 +435,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(LOG_ERR, 1, "avcodec_open - could not open codec");
motion_log(LOG_ERR, 1, "%s: avcodec_open - could not open codec", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -452,7 +456,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
/* allocate the encoded raw picture */
ffmpeg->picture = avcodec_alloc_frame();
if (!ffmpeg->picture) {
motion_log(LOG_ERR, 1, "avcodec_alloc_frame - could not alloc frame");
motion_log(LOG_ERR, 1, "%s: avcodec_alloc_frame - could not alloc frame", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -494,20 +498,22 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
/* and retry opening the file (use file_proto) */
if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) {
motion_log(LOG_ERR, 1, "url_fopen - error opening file %s", filename);
motion_log(LOG_ERR, 1, "%s: url_fopen - error opening file %s",
__FUNCTION__, filename);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
/* Permission denied */
} else if (errno == EACCES) {
motion_log(LOG_ERR, 1,
"url_fopen - error opening file %s"
" ... check access rights to target directory", filename);
"%s: url_fopen - error opening file %s"
" ... check access rights to target directory",
__FUNCTION__, filename);
/* create path for file... */
ffmpeg_cleanups(ffmpeg);
return (NULL);
} else {
motion_log(LOG_ERR, 1, "Error opening file %s", filename);
motion_log(LOG_ERR, 1, "%s: Error opening file %s", __FUNCTION__, filename);
ffmpeg_cleanups(ffmpeg);
return (NULL);
}
@@ -673,7 +679,7 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic)
}
if (ret != 0) {
motion_log(LOG_ERR, 1, "Error while writing video frame");
motion_log(LOG_ERR, 1, "%s: Error while writing video frame", __FUNCTION__);
ffmpeg_cleanups(ffmpeg);
return (-1);
}
@@ -695,7 +701,7 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y,
picture = avcodec_alloc_frame();
if (!picture) {
motion_log(LOG_ERR, 1, "Could not alloc frame");
motion_log(LOG_ERR, 1, "%s: Could not alloc frame", __FUNCTION__);
return NULL;
}
@@ -735,7 +741,7 @@ void ffmpeg_deinterlace(unsigned char *img, int width, int height)
picture = avcodec_alloc_frame();
if (!picture) {
motion_log(LOG_ERR, 1, "Could not alloc frame");
motion_log(LOG_ERR, 1, "%s: Could not alloc frame", __FUNCTION__);
return;
}
@@ -777,7 +783,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(LOG_ERR, 0, "ffmpeg_avcodec_log: %s - flag %d", buf, errno_flag);
motion_log(LOG_ERR, 0, "%s: %s - flag %d", __FUNCTION__, buf, errno_flag);
}
}

233
motion.c
View File

@@ -105,7 +105,8 @@ static void image_ring_resize(struct context *cnt, int new_size)
smallest = cnt->imgs.image_ring_size;
}
if (cnt->imgs.image_ring_in == smallest - 1 || smallest == 0) {
motion_log(LOG_INFO, 0, "Resizing pre_capture buffer to %d items", new_size);
motion_log(LOG_INFO, 0, "%s: Resizing pre_capture buffer to %d items",
__FUNCTION__, new_size);
/* Create memory for new ring buffer */
struct image_data *tmp;
@@ -356,9 +357,9 @@ static void motion_remove_pid(void)
{
if ((cnt_list[0]->daemon) && (cnt_list[0]->conf.pid_file) && (restart == 0)) {
if (!unlink(cnt_list[0]->conf.pid_file))
motion_log(LOG_INFO, 0, "Removed process id file (pid file).");
motion_log(LOG_INFO, 0, "%s: Removed process id file (pid file).", __FUNCTION__);
else
motion_log(LOG_INFO, 1, "Error removing pid file");
motion_log(LOG_INFO, 1, "%s: Error removing pid file", __FUNCTION__);
}
}
@@ -420,8 +421,9 @@ static void motion_detected(struct context *cnt, int dev, struct image_data *img
/* EVENT_FIRSTMOTION triggers on_event_start_command and event_ffmpeg_newfile */
event(cnt, EVENT_FIRSTMOTION, img->image, NULL, NULL, &img->timestamp_tm);
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Motion detected - starting event %d", cnt->event_nr);
if (debug_level >= CAMERA_INFO)
motion_log(-1, 0, "%s: Motion detected - starting event %d",
__FUNCTION__, cnt->event_nr);
/* always save first motion frame as preview-shot, may be changed to an other one later */
if (cnt->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) {
@@ -523,7 +525,8 @@ static void process_image_ring(struct context *cnt, unsigned int max_images)
int frames = cnt->movie_fps - (cnt->movie_last_shot + 1);
if (frames > 0) {
char tmp[15];
motion_log(LOG_DEBUG, 0, "Added %d fillerframes into movie", frames );
motion_log(LOG_DEBUG, 0, "%s: Added %d fillerframes into movie",
__FUNCTION__, frames );
sprintf(tmp, "Fillerframes %d", frames);
draw_text(cnt->imgs.image_ring[cnt->imgs.image_ring_out].image, 10, 40,
cnt->imgs.width, tmp, cnt->conf.text_double);
@@ -626,7 +629,8 @@ static int motion_init(struct context *cnt)
cnt->detecting_motion = 0;
cnt->makemovie = 0;
motion_log(LOG_DEBUG, 0, "Thread %d started", (unsigned long)pthread_getspecific(tls_key_threadnr));
motion_log(LOG_DEBUG, 0, "%s: Thread %d started",
__FUNCTION__, (unsigned long)pthread_getspecific(tls_key_threadnr));
if (!cnt->conf.filepath)
cnt->conf.filepath = mystrdup(".");
@@ -639,8 +643,9 @@ static int motion_init(struct context *cnt)
* file options.
*/
if (cnt->video_dev < 0) {
motion_log(LOG_ERR, 0, "Could not fetch initial image from camera");
motion_log(LOG_ERR, 0, "Motion continues using width and height from config file(s)");
motion_log(LOG_ERR, 0, "%s: Could not fetch initial image from camera\n"
"Motion continues using width and height from config file(s)",
__FUNCTION__);
cnt->imgs.width = cnt->conf.width;
cnt->imgs.height = cnt->conf.height;
cnt->imgs.size = cnt->conf.width * cnt->conf.height * 3 / 2;
@@ -697,7 +702,7 @@ static int motion_init(struct context *cnt)
memset(cnt->imgs.image_virgin, 0x80, cnt->imgs.size); /* initialize to grey */
draw_text(cnt->imgs.image_virgin, 10, 20, cnt->imgs.width,
"Error capturing first image", cnt->conf.text_double);
motion_log(LOG_ERR, 0, "Error capturing first image");
motion_log(LOG_ERR, 0, "%s: Error capturing first image", __FUNCTION__);
}
}
@@ -708,26 +713,26 @@ static int motion_init(struct context *cnt)
#if (!defined(BSD))
/* open video loopback devices if enabled */
if (cnt->conf.vidpipe) {
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Opening video loopback device for normal pictures");
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Opening video loopback device for normal pictures", __FUNCTION__);
else
motion_log(LOG_INFO, 0, "Opening video loopback device for normal pictures");
motion_log(LOG_INFO, 0, "%s: Opening video loopback device for normal pictures", __FUNCTION__);
/* vid_startpipe should get the output dimensions */
cnt->pipe = vid_startpipe(cnt->conf.vidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type);
if (cnt->pipe < 0) {
motion_log(LOG_ERR, 0, "Failed to open video loopback");
motion_log(LOG_ERR, 0, "%s: Failed to open video loopback", __FUNCTION__);
return -1;
}
}
if (cnt->conf.motionvidpipe) {
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Opening video loopback device for motion pictures");
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Opening video loopback device for motion pictures", __FUNCTION__);
else
motion_log(LOG_INFO, 0, "Opening video loopback device for motion pictures");
motion_log(LOG_INFO, 0, "%s: Opening video loopback device for motion pictures", __FUNCTION__);
/* vid_startpipe should get the output dimensions */
cnt->mpipe = vid_startpipe(cnt->conf.motionvidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type);
if (cnt->mpipe < 0) {
motion_log(LOG_ERR, 0, "Failed to open video loopback");
motion_log(LOG_ERR, 0, "%s: Failed to open video loopback", __FUNCTION__);
return -1;
}
}
@@ -743,9 +748,10 @@ static int motion_init(struct context *cnt)
mysql_init(cnt->database);
if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user,
cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) {
motion_log(LOG_ERR, 0, "Cannot connect to MySQL database %s on host %s with user %s",
cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user);
motion_log(LOG_ERR, 0, "MySQL error was %s", mysql_error(cnt->database));
motion_log(LOG_ERR, 0, "%s: Cannot connect to MySQL database %s on host %s with user %s",
__FUNCTION__, cnt->conf.database_dbname, cnt->conf.database_host,
cnt->conf.database_user);
motion_log(LOG_ERR, 0, "%s: MySQL error was %s", __FUNCTION__, mysql_error(cnt->database));
return -2;
}
#if (defined(MYSQL_VERSION_ID)) && (MYSQL_VERSION_ID > 50012)
@@ -772,8 +778,8 @@ static int motion_init(struct context *cnt)
cnt->database_pg = PQconnectdb(connstring);
if (PQstatus(cnt->database_pg) == CONNECTION_BAD) {
motion_log(LOG_ERR, 0, "Connection to PostgreSQL database '%s' failed: %s",
cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg));
motion_log(LOG_ERR, 0, "%s: Connection to PostgreSQL database '%s' failed: %s",
__FUNCTION__, cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg));
return -2;
}
}
@@ -800,18 +806,22 @@ static int motion_init(struct context *cnt)
cnt->imgs.mask = get_pgm(picture, cnt->imgs.width, cnt->imgs.height);
fclose(picture);
} else {
motion_log(LOG_ERR, 1, "Error opening mask file %s", cnt->conf.mask_file);
motion_log(LOG_ERR, 1, "%s: Error opening mask file %s",
__FUNCTION__, cnt->conf.mask_file);
/* Try to write an empty mask file to make it easier
for the user to edit it */
put_fixed_mask(cnt, cnt->conf.mask_file);
}
if (!cnt->imgs.mask) {
motion_log(LOG_ERR, 0, "Failed to read mask image. Mask feature disabled.");
motion_log(LOG_ERR, 0, "%s: Failed to read mask image. Mask feature disabled.",
__FUNCTION__);
} else {
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Maskfile \"%s\" loaded.", cnt->conf.mask_file);
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Maskfile \"%s\" loaded.",
__FUNCTION__, cnt->conf.mask_file);
else
motion_log(LOG_INFO, 0, "Maskfile \"%s\" loaded.", cnt->conf.mask_file);
motion_log(LOG_INFO, 0, "%s: Maskfile \"%s\" loaded.",
__FUNCTION__, cnt->conf.mask_file);
}
} else
cnt->imgs.mask = NULL;
@@ -830,9 +840,11 @@ static int motion_init(struct context *cnt)
/* Initialize stream server if stream port is specified to not 0 */
if (cnt->conf.stream_port) {
if ( stream_init(cnt) == -1 ) {
motion_log(LOG_ERR, 1, "Problem enabling motion-stream server in port %d", cnt->conf.stream_port);
motion_log(LOG_ERR, 1, "%s: Problem enabling motion-stream server in port %d",
__FUNCTION__, cnt->conf.stream_port);
cnt->finish = 1;
}else motion_log(LOG_DEBUG, 0, "Started motion-stream server in port %d", cnt->conf.stream_port);
}else motion_log(LOG_DEBUG, 0, "%s: Started motion-stream server in port %d",
__FUNCTION__, cnt->conf.stream_port);
}
/* Prevent first few frames from triggering motion... */
@@ -861,7 +873,7 @@ static void motion_cleanup(struct context *cnt)
event(cnt, EVENT_STOP, NULL, NULL, NULL, NULL);
if (cnt->video_dev >= 0){
motion_log(LOG_DEBUG, 0, "Calling vid_close() from motion_cleanup");
motion_log(LOG_DEBUG, 0, "%s: Calling vid_close() from motion_cleanup", __FUNCTION__);
vid_close(cnt);
}
@@ -1127,18 +1139,18 @@ static void *motion_loop(void *arg)
if (cnt->video_dev < 0 &&
cnt->currenttime % 10 == 0 && cnt->shots == 0) {
motion_log(LOG_ERR, 0,
"Retrying until successful connection with camera");
"%s: Retrying until successful connection with camera", __FUNCTION__);
cnt->video_dev = vid_start(cnt);
/* if the netcam has different dimensions than in the config file
* we need to restart Motion to re-allocate all the buffers
*/
if (cnt->imgs.width != cnt->conf.width || cnt->imgs.height != cnt->conf.height) {
motion_log(LOG_ERR, 0, "Camera has finally become available");
motion_log(LOG_ERR, 0, "Camera image has different width and height "
"from what is in the config file. You should fix that");
motion_log(LOG_ERR, 0, "Restarting Motion thread to reinitialize all "
"image buffers to new picture dimensions");
motion_log(LOG_ERR, 0, "%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 "
"image buffers to new picture dimensions", __FUNCTION__);
cnt->conf.width = cnt->imgs.width;
cnt->conf.height = cnt->imgs.height;
/* Break out of main loop terminating thread
@@ -1170,7 +1182,7 @@ static void *motion_loop(void *arg)
/* If all is well reset missing_frame_counter */
if (cnt->missing_frame_counter >= MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) {
/* If we previously logged starting a grey image, now log video re-start */
motion_log(LOG_ERR, 0, "Video signal re-acquired");
motion_log(LOG_ERR, 0, "%s: Video signal re-acquired", __FUNCTION__);
// event for re-acquired video signal can be called here
}
cnt->missing_frame_counter = 0;
@@ -1199,7 +1211,8 @@ static void *motion_loop(void *arg)
// FATAL ERROR - leave the thread by breaking out of the main loop
} else if (vid_return_code < 0) {
/* Fatal error - Close video device */
motion_log(LOG_ERR, 0, "Video device fatal error - Closing video device");
motion_log(LOG_ERR, 0, "%s: Video device fatal error - Closing video device",
__FUNCTION__);
vid_close(cnt);
/* Use virgin image, if we are not able to open it again next loop
* a gray image with message is applied
@@ -1217,7 +1230,7 @@ static void *motion_loop(void *arg)
} else {
if (debug_level >= CAMERA_VERBOSE)
motion_log(-1, 0, "vid_return_code %d", vid_return_code);
motion_log(-1, 0, "%s: vid_return_code %d", __FUNCTION__, vid_return_code);
/* Netcams that change dimensions while Motion is running will
* require that Motion restarts to reinitialize all the many
@@ -1225,8 +1238,8 @@ static void *motion_loop(void *arg)
* other way
*/
if (vid_return_code == NETCAM_RESTART_ERROR) {
motion_log(LOG_ERR, 0, "Restarting Motion thread to reinitialize all "
"image buffers");
motion_log(LOG_ERR, 0, "%s: Restarting Motion thread to reinitialize all "
"image buffers", __FUNCTION__);
/* Break out of main loop terminating thread
* watchdog will start us again
* Set lost_connection flag on */
@@ -1268,7 +1281,8 @@ static void *motion_loop(void *arg)
/* Write error message only once */
if (cnt->missing_frame_counter == MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) {
motion_log(LOG_ERR, 0, "Video signal lost - Adding grey image");
motion_log(LOG_ERR, 0, "%s: Video signal lost - Adding grey image",
__FUNCTION__);
// Event for lost video signal can be called from here
event(cnt, EVENT_CAMERA_LOST, NULL, NULL,
NULL, cnt->currenttime_tm);
@@ -1278,7 +1292,8 @@ static void *motion_loop(void *arg)
* Only try this when a device is open */
if ( (cnt->video_dev > 0) &&
(cnt->missing_frame_counter == (MISSING_FRAMES_TIMEOUT * 4) * cnt->conf.frame_limit) ) {
motion_log(LOG_ERR, 0, "Video signal still lost - Trying to close video device");
motion_log(LOG_ERR, 0, "%s: Video signal still lost - "
"Trying to close video device",__FUNCTION__);
vid_close(cnt);
}
}
@@ -1314,8 +1329,8 @@ static void *motion_loop(void *arg)
*/
if (cnt->conf.lightswitch && !cnt->lost_connection) {
if (alg_lightswitch(cnt, cnt->current_image->diffs)) {
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Lightswitch detected");
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Lightswitch detected", __FUNCTION__);
if (cnt->moved < 5)
cnt->moved = 5;
cnt->current_image->diffs = 0;
@@ -1335,8 +1350,8 @@ static void *motion_loop(void *arg)
cnt->current_image->diffs = alg_switchfilter(cnt, cnt->current_image->diffs, cnt->current_image->image);
if (cnt->current_image->diffs <= cnt->threshold) {
cnt->current_image->diffs = 0;
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Switchfilter detected");
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Switchfilter detected", __FUNCTION__);
}
}
@@ -1427,8 +1442,8 @@ static void *motion_loop(void *arg)
alg_update_reference_frame(cnt, RESET_REF_FRAME);
cnt->current_image->diffs = 0;
cnt->lightswitch_framecounter = 0;
if (cnt->conf.setup_mode)
motion_log(-1, 0, "micro-lightswitch!");
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: micro-lightswitch!", __FUNCTION__);
} else {
alg_update_reference_frame(cnt, UPDATE_REF_FRAME);
}
@@ -1481,7 +1496,7 @@ static void *motion_loop(void *arg)
/* Add changed pixels to motion-images (for stream) in setup_mode
and always overlay smartmask (not only when motion is detected) */
if (cnt->conf.setup_mode) {
if (debug_level >= CAMERA_DEBUG) {
char tmp[PATH_MAX];
sprintf(tmp, "D:%5d L:%3d N:%3d", cnt->current_image->diffs, cnt->current_image->total_labels, cnt->noise);
draw_text(cnt->imgs.out, cnt->imgs.width - 10, cnt->imgs.height - 30 * text_size_factor,
@@ -1596,7 +1611,7 @@ static void *motion_loop(void *arg)
event(cnt, EVENT_AREA_DETECTED, NULL, NULL,
NULL, cnt->currenttime_tm);
area_once = cnt->event_nr; /* Fire script only once per event */
if (cnt->conf.setup_mode)
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "Motion in area %d detected.\n", z+1);
break;
}
@@ -1634,8 +1649,9 @@ static void *motion_loop(void *arg)
if (cnt->track.type)
cnt->moved = track_center(cnt, cnt->video_dev, 0, 0, 0);
if (cnt->conf.setup_mode)
motion_log(-1, 0, "End of event %d", cnt->event_nr);
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: End of event %d",
__FUNCTION__, cnt->event_nr);
cnt->makemovie = 0;
/* Reset post capture */
@@ -1658,7 +1674,7 @@ static void *motion_loop(void *arg)
/***** MOTION LOOP - SETUP MODE CONSOLE OUTPUT SECTION *****/
/* If setup_mode enabled output some numbers to console */
if (cnt->conf.setup_mode){
if (debug_level >= CAMERA_DEBUG){
char msg[1024] = "\0";
char part[100];
@@ -1757,9 +1773,10 @@ static void *motion_loop(void *arg)
/* If invalid we report in syslog once and continue in manual mode */
else {
motion_log(LOG_ERR, 0, "Invalid timelapse_mode argument '%s'",
cnt->conf.timelapse_mode);
motion_log(LOG_ERR, 0, "Defaulting to manual timelapse mode");
motion_log(LOG_ERR, 0, "%s: Invalid timelapse_mode argument '%s'",
__FUNCTION__, cnt->conf.timelapse_mode);
motion_log(LOG_ERR, 0, "%:s Defaulting to manual timelapse mode",
__FUNCTION__);
conf_cmdparse(&cnt, (char *)"ffmpeg_timelapse_mode",(char *)"manual");
}
}
@@ -1925,7 +1942,7 @@ err:
free(rolling_average_data);
cnt->lost_connection = 1;
motion_log(-1, 0, "Thread exiting");
motion_log(-1, 0, "%s: Thread exiting", __FUNCTION__);
motion_cleanup(cnt);
@@ -1973,7 +1990,7 @@ static void become_daemon(void)
/* fork */
if (fork()) {
motion_log(-1, 0, "Motion going to daemon mode");
motion_log(-1, 0, "%s: Motion going to daemon mode", __FUNCTION__);
exit(0);
}
@@ -1989,8 +2006,8 @@ static void become_daemon(void)
(void)fprintf(pidf, "%d\n", getpid());
fclose(pidf);
} else {
motion_log(LOG_ERR, 1, "Exit motion, cannot create process id file (pid file) %s",
cnt_list[0]->conf.pid_file);
motion_log(LOG_ERR, 1, "%s: Exit motion, cannot create process id file (pid file) %s",
__FUNCTION__, cnt_list[0]->conf.pid_file);
exit(0);
}
}
@@ -1998,7 +2015,7 @@ static void become_daemon(void)
/* changing dir to root enables people to unmount a disk
without having to stop Motion */
if (chdir("/")) {
motion_log(LOG_ERR, 1, "Could not change directory");
motion_log(LOG_ERR, 1, "%s: Could not change directory", __FUNCTION__);
}
#if (defined(BSD))
@@ -2031,8 +2048,8 @@ static void become_daemon(void)
/* Now it is safe to add the PID creation to the logs */
if ( pidf )
motion_log(LOG_INFO, 0, "Created process id file %s. Process ID is %d",
cnt_list[0]->conf.pid_file, getpid());
motion_log(LOG_INFO, 0, "%s: Created process id file %s. Process ID is %d",
__FUNCTION__, cnt_list[0]->conf.pid_file, getpid());
sigaction(SIGTTOU, &sig_ign_action, NULL);
sigaction(SIGTTIN, &sig_ign_action, NULL);
@@ -2131,7 +2148,7 @@ static void motion_startup(int daemonize, int argc, char *argv[])
*/
cntlist_create(argc, argv);
motion_log(LOG_INFO, 0, "Motion "VERSION" Started");
motion_log(LOG_INFO, 0, "%s: Motion "VERSION" Started", __FUNCTION__);
initialize_chars();
@@ -2141,7 +2158,7 @@ static void motion_startup(int daemonize, int argc, char *argv[])
*/
if (cnt_list[0]->daemon && cnt_list[0]->conf.setup_mode == 0) {
become_daemon();
motion_log(LOG_INFO, 0, "Motion running as daemon process");
motion_log(LOG_INFO, 0, "%s: Motion running as daemon process", __FUNCTION__);
}
}
@@ -2214,9 +2231,10 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr
/* Compare against the control port. */
if (cnt_list[0]->conf.webcontrol_port == cnt->conf.stream_port) {
motion_log(LOG_ERR, 0,
"Stream port number %d for thread %d conflicts with the control port",
cnt->conf.stream_port, cnt->threadnr);
motion_log(LOG_ERR, 0, "Stream feature for thread %d is disabled.", cnt->threadnr);
"%s: Stream port number %d for thread %d conflicts with the control port",
__FUNCTION__, cnt->conf.stream_port, cnt->threadnr);
motion_log(LOG_ERR, 0, "%s: Stream feature for thread %d is disabled.",
__FUNCTION__, cnt->threadnr);
cnt->conf.stream_port = 0;
}
@@ -2226,10 +2244,11 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr
continue;
if (cnt_list[i]->conf.stream_port == cnt->conf.stream_port) {
motion_log(LOG_ERR, 0,
"Stream port number %d for thread %d conflicts with thread %d",
cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr);
"%s: Stream port number %d for thread %d conflicts with thread %d",
__FUNCTION__, cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr);
motion_log(LOG_ERR, 0,
"Stream feature for thread %d is disabled.", cnt->threadnr);
"%s: Stream feature for thread %d is disabled.",
__FUNCTION__, cnt->threadnr);
cnt->conf.stream_port = 0;
}
}
@@ -2297,7 +2316,7 @@ int main (int argc, char **argv)
* optimize motion detection and stuff.
*/
if(cnt_list[0]->conf.setup_mode)
motion_log(-1, 0, "Motion running in setup mode.");
motion_log(-1, 0, "%s: Motion running in setup mode.", __FUNCTION__);
/* Create and a thread attribute for the threads we spawn later on.
* PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
@@ -2317,7 +2336,7 @@ int main (int argc, char **argv)
*/
motion_shutdown();
restart = 0; /* only one reset for now */
motion_log(LOG_INFO, 0, "motion restarted");
motion_log(LOG_INFO, 0, "%s: motion restarted", __FUNCTION__);
#ifndef WITHOUT_V4L
SLEEP(5, 0); // maybe some cameras needs less time
#endif
@@ -2333,17 +2352,19 @@ int main (int argc, char **argv)
cnt_list[i]->threadnr = i ? i : 1;
if ( strcmp(cnt_list[i]->conf_filename, "") )
motion_log(LOG_INFO, 0, "Thread %d is from %s", cnt_list[i]->threadnr, cnt_list[i]->conf_filename );
motion_log(LOG_INFO, 0, "%s: Thread %d is from %s",
__FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf_filename );
if (cnt_list[0]->conf.setup_mode) {
motion_log(-1, 0, "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
);
if (debug_level >= CAMERA_DEBUG) {
motion_log(-1, 0, "%s: Thread %d is device: %s input %d", __FUNCTION__,
cnt_list[i]->threadnr, cnt_list[i]->conf.netcam_url ?
cnt_list[i]->conf.netcam_url : cnt_list[i]->conf.video_device,
cnt_list[i]->conf.netcam_url ? -1 : cnt_list[i]->conf.input);
}
if (cnt_list[0]->conf.setup_mode)
motion_log(LOG_ERR, 0, "Stream port %d", cnt_list[i]->conf.stream_port);
if (debug_level >= CAMERA_DEBUG)
motion_log(LOG_ERR, 0, "%s: Stream port %d",
__FUNCTION__, cnt_list[i]->conf.stream_port);
start_motion_thread(cnt_list[i], &thread_attr);
}
@@ -2354,8 +2375,8 @@ int main (int argc, char **argv)
if (cnt_list[0]->conf.webcontrol_port)
pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list);
if (cnt_list[0]->conf.setup_mode)
motion_log(-1, 0, "Waiting for threads to finish, pid: %d", getpid());
if (debug_level >= CAMERA_DEBUG)
motion_log(-1, 0, "%s: Waiting for threads to finish, pid: %d", __FUNCTION__, getpid());
/* Crude way of waiting for all threads to finish - check the thread
* counter (because we cannot do join on the detached threads).
@@ -2374,27 +2395,28 @@ int main (int argc, char **argv)
if ( ((motion_threads_running == 0 ) && finish ) ||
((motion_threads_running == 0 ) && (threads_running == 0)) ){
if (debug_level >= CAMERA_DEBUG)
motion_log(LOG_INFO, 0, "DEBUG-1 threads_running %d motion_threads_running %d , finish %d",
threads_running, motion_threads_running, finish);
motion_log(LOG_INFO, 0, "%s: DEBUG-1 threads_running %d motion_threads_running %d , finish %d",
__FUNCTION__, threads_running, motion_threads_running, finish);
break;
}
for (i = (cnt_list[1] != NULL ? 1 : 0); cnt_list[i]; i++) {
/* Check if threads wants to be restarted */
if ( (!cnt_list[i]->running) && (cnt_list[i]->restart) ) {
motion_log(LOG_INFO, 0, "Motion thread %d restart", cnt_list[i]->threadnr);
motion_log(LOG_INFO, 0, "%s: Motion thread %d restart",
__FUNCTION__, cnt_list[i]->threadnr);
start_motion_thread(cnt_list[i], &thread_attr);
}
if (cnt_list[i]->watchdog > WATCHDOG_OFF) {
cnt_list[i]->watchdog--;
if (cnt_list[i]->watchdog == 0) {
motion_log(LOG_ERR, 0, "Thread %d - Watchdog timeout, trying to do a graceful restart",
cnt_list[i]->threadnr);
motion_log(LOG_ERR, 0, "%s: Thread %d - Watchdog timeout, trying to do "
"a graceful restart", __FUNCTION__, cnt_list[i]->threadnr);
cnt_list[i]->finish = 1;
}
if (cnt_list[i]->watchdog == -60) {
motion_log(LOG_ERR, 0, "Thread %d - Watchdog timeout, did NOT restart graceful,"
"killing it!", cnt_list[i]->threadnr);
motion_log(LOG_ERR, 0, "%s: Thread %d - Watchdog timeout, did NOT restart graceful,"
"killing it!", __FUNCTION__, cnt_list[i]->threadnr);
pthread_cancel(cnt_list[i]->thread_id);
pthread_mutex_lock(&global_lock);
threads_running--;
@@ -2406,14 +2428,14 @@ int main (int argc, char **argv)
}
}
if (debug_level >= CAMERA_DEBUG)
motion_log(LOG_INFO, 0, "DEBUG-2 threads_running %d motion_threads_running %d finish %d",
threads_running, motion_threads_running, finish);
motion_log(LOG_INFO, 0, "%s: DEBUG-2 threads_running %d motion_threads_running %d finish %d",
__FUNCTION__, threads_running, motion_threads_running, finish);
}
/* Reset end main loop flag */
finish = 0;
if (cnt_list[0]->conf.setup_mode)
motion_log(LOG_DEBUG, 0, "Threads finished");
if (debug_level >= CAMERA_DEBUG)
motion_log(LOG_DEBUG, 0, "%s: Threads finished", __FUNCTION__);
/* Rest for a while if we're supposed to restart. */
if (restart)
@@ -2424,7 +2446,7 @@ int main (int argc, char **argv)
// Be sure that http control exits fine
cnt_list[0]->finish = 1;
SLEEP(1, 0);
motion_log(LOG_INFO, 0, "Motion terminating");
motion_log(LOG_INFO, 0, "%s: Motion terminating", __FUNCTION__);
/* Perform final cleanup. */
pthread_key_delete(tls_key_threadnr);
@@ -2458,7 +2480,8 @@ void * mymalloc(size_t nbytes)
{
void *dummy = malloc(nbytes);
if (!dummy) {
motion_log(LOG_EMERG, 1, "Could not allocate %llu bytes of memory!", (unsigned long long)nbytes);
motion_log(LOG_EMERG, 1, "%s: Could not allocate %llu bytes of memory!",
__FUNCTION__, (unsigned long long)nbytes);
motion_remove_pid();
exit(1);
}
@@ -2489,14 +2512,14 @@ void *myrealloc(void *ptr, size_t size, const char *desc)
if (size == 0) {
free(ptr);
motion_log(LOG_WARNING, 0,
"Warning! Function %s tries to resize memoryblock at %p to 0 bytes!",
desc, ptr);
"%s: Warning! Function %s tries to resize memoryblock at %p to 0 bytes!",
__FUNCTION__, desc, ptr);
} else {
dummy = realloc(ptr, size);
if (!dummy) {
motion_log(LOG_EMERG, 0,
"Could not resize memory-block at offset %p to %llu bytes (function %s)!",
ptr, (unsigned long long)size, desc);
"%s: Could not resize memory-block at offset %p to %llu bytes (function %s)!",
__FUNCTION__, ptr, (unsigned long long)size, desc);
motion_remove_pid();
exit(1);
}
@@ -2536,7 +2559,8 @@ int create_path(const char *path)
buffer[start-path] = 0x00;
if (mkdir(buffer, mode) == -1 && errno != EEXIST) {
motion_log(LOG_ERR, 1, "Problem creating directory %s", buffer);
motion_log(LOG_ERR, 1, "%s: Problem creating directory %s",
__FUNCTION__, buffer);
free(buffer);
return -1;
}
@@ -2590,7 +2614,8 @@ FILE * myfopen(const char *path, const char *mode)
* 1: there was an other error while trying to open the file for the first time
* 2: could still not open the file after the path was created
*/
motion_log(LOG_ERR, 1, "Error opening file %s with mode %s", path, mode);
motion_log(LOG_ERR, 1, "%s: Error opening file %s with mode %s",
__FUNCTION__, path, mode);
return NULL;
}

View File

@@ -105,6 +105,7 @@
#define CAMERA_WARNINGS 3 /* warnings only */
#define TRACK_DEBUG 4 /* track debug */
#define CAMERA_INFO 5 /* info debug */
#define CAMERA_VIDEO 6 /* debug video not verbose */
#define CAMERA_DEBUG 7 /* debug but not verbose */
#define CAMERA_VERBOSE 8 /* verbose level */
#define CAMERA_ALL 9 /* everything */

435
netcam.c
View File

File diff suppressed because it is too large Load Diff

View File

@@ -172,7 +172,7 @@ static int ftp_get_more(ftp_context_pointer ctxt) {
if ((len = recv(ctxt->control_file_desc,
&ctxt->control_buffer[ctxt->control_buffer_index],
size, 0)) < 0) {
motion_log(LOG_ERR, 1, "recv failed in ftp_get_more");
motion_log(LOG_ERR, 1, "%s: recv failed in ftp_get_more", __FUNCTION__);
close(ctxt->control_file_desc);
ctxt->control_file_desc = -1;
return(-1);
@@ -265,7 +265,7 @@ static int ftp_send_user(ftp_context_pointer ctxt) {
len = strlen(buf);
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_send_user");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_send_user", __FUNCTION__);
return(res);
}
return(0);
@@ -288,7 +288,7 @@ static int ftp_send_passwd(ftp_context_pointer ctxt) {
len = strlen(buf);
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_send_passwd");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_send_passwd", __FUNCTION__);
return(res);
}
return(0);
@@ -318,7 +318,7 @@ static int ftp_quit(ftp_context_pointer ctxt) {
len = strlen(buf);
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_quit");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_quit", __FUNCTION__);
return(res);
}
return(0);
@@ -362,13 +362,13 @@ int ftp_connect(netcam_context_ptr netcam) {
hp = gethostbyname (netcam->connect_host);
if (hp == NULL) {
motion_log(LOG_ERR, 1, "gethostbyname failed in ftp_connect");
motion_log(LOG_ERR, 1, "%s: gethostbyname failed in ftp_connect", __FUNCTION__);
return (-1);
}
if ((unsigned int) hp->h_length >
sizeof(((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr)) {
motion_log(LOG_ERR, 1, "gethostbyname address mismatch "
"in ftp_connect");
motion_log(LOG_ERR, 1, "%s: gethostbyname address mismatch "
"in ftp_connect", __FUNCTION__);
return (-1);
}
@@ -382,7 +382,7 @@ int ftp_connect(netcam_context_ptr netcam) {
addrlen = sizeof (struct sockaddr_in);
if (ctxt->control_file_desc < 0) {
motion_log(LOG_ERR, 1, "socket failed");
motion_log(LOG_ERR, 1, "%s: socket failed", __FUNCTION__);
return(-1);
}
@@ -391,7 +391,7 @@ int ftp_connect(netcam_context_ptr netcam) {
*/
if (connect(ctxt->control_file_desc, (struct sockaddr *) &ctxt->ftp_address,
addrlen) < 0) {
motion_log(LOG_ERR, 1, "Failed to create a connection");
motion_log(LOG_ERR, 1, "%s: Failed to create a connection", __FUNCTION__);
close(ctxt->control_file_desc);
ctxt->control_file_desc = -1;
return(-1);
@@ -442,7 +442,7 @@ int ftp_connect(netcam_context_ptr netcam) {
case 2:
break;
case 3:
motion_log(LOG_ERR, 0, "FTP server asking for ACCT on anonymous");
motion_log(LOG_ERR, 0, "%s: FTP server asking for ACCT on anonymous", __FUNCTION__);
case 1:
case 4:
case 5:
@@ -487,13 +487,13 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
memset (&data_address, 0, sizeof(data_address));
ctxt->data_file_desc = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ctxt->data_file_desc < 0) {
motion_log(LOG_ERR, 1, "socket failed");
motion_log(LOG_ERR, 1, "%s: socket failed", __FUNCTION__);
return (-1);
}
on = 1;
if (setsockopt(ctxt->data_file_desc, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on)) < 0) {
motion_log(LOG_ERR, 1, "setting socket option SO_REUSEADDR");
motion_log(LOG_ERR, 1, "%s: setting socket option SO_REUSEADDR", __FUNCTION__);
return -1;
}
@@ -506,7 +506,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
len = strlen (buf);
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_get_connection");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_connection", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return(res);
@@ -533,7 +533,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
cur++;
if (sscanf (cur, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2],
&temp[3], &temp[4], &temp[5]) != 6) {
motion_log(LOG_ERR, 0, "Invalid answer to PASV");
motion_log(LOG_ERR, 0, "%s: Invalid answer to PASV", __FUNCTION__);
if (ctxt->data_file_desc != -1) {
close (ctxt->data_file_desc);
ctxt->data_file_desc = -1;
@@ -548,7 +548,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
/* Now try to connect to the data port */
if (connect(ctxt->data_file_desc, (struct sockaddr *) &data_address,
data_address_length) < 0) {
motion_log(LOG_ERR, 1, "Failed to create a data connection");
motion_log(LOG_ERR, 1, "%s: Failed to create a data connection", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return (-1);
@@ -567,7 +567,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
/* bind to the socket - should give us a unique port */
if (bind(ctxt->data_file_desc, (struct sockaddr *) &data_address,
data_address_length) < 0) {
motion_log(LOG_ERR, 1, "bind failed");
motion_log(LOG_ERR, 1, "%s: bind failed", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return (-1);
@@ -579,7 +579,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
/* set up a 'listen' on the port to get the server's connection */
if (listen(ctxt->data_file_desc, 1) < 0) {
motion_log(LOG_ERR, 1, "listen failed");
motion_log(LOG_ERR, 1, "%s: listen failed", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return (-1);
@@ -599,7 +599,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_get_connection");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_connection", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return(res);
@@ -707,7 +707,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) {
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_get_socket");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_socket", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return(res);
@@ -732,7 +732,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) {
if ((acfd = accept(ctxt->data_file_desc, (struct sockaddr *)&data_address,
&data_address_length)) < 0) {
motion_log(LOG_ERR, 1, "accept in ftp_get_socket");
motion_log(LOG_ERR, 1, "%s: accept in ftp_get_socket", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return -1;
@@ -768,7 +768,7 @@ int ftp_send_type(ftp_context_pointer ctxt, char type) {
res = send(ctxt->control_file_desc, buf, len, 0);
if (res < 0) {
motion_log(LOG_ERR, 1, "send failed in ftp_get_socket");
motion_log(LOG_ERR, 1, "%s: send failed in ftp_get_socket", __FUNCTION__);
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
return(res);
@@ -817,7 +817,7 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len) {
if (len <= 0) {
if (len < 0)
motion_log(LOG_ERR, 1, "recv failed in ftp_read");
motion_log(LOG_ERR, 1, "%s: recv failed in ftp_read", __FUNCTION__);
ftp_close_connection(ctxt);
}

View File

@@ -519,14 +519,15 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp
/* Report to syslog - suggest solution if the problem is access rights to target dir */
if (errno == EACCES) {
motion_log(LOG_ERR, 1,
"Can't write picture to file %s - check access rights to target directory", file);
motion_log(LOG_ERR, 1, "Thread is going to finish due to this fatal error");
"%s: Can't write picture to file %s - check access rights to target directory"
"Thread is going to finish due to this fatal error",
__FUNCTION__, file);
cnt->finish = 1;
cnt->restart = 0;
return;
} else {
/* If target dir is temporarily unavailable we may survive */
motion_log(LOG_ERR, 1, "Can't write picture to file %s", file);
motion_log(LOG_ERR, 1, "%s: Can't write picture to file %s", __FUNCTION__, file);
return;
}
}
@@ -546,12 +547,13 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
line[255] = 0;
if (!fgets(line, 255, picture)) {
motion_log(LOG_ERR, 1, "Could not read from ppm file");
motion_log(LOG_ERR, 1, "%s: Could not read from ppm file", __FUNCTION__);
return NULL;
}
if (strncmp(line, "P5", 2)) {
motion_log(LOG_ERR, 1, "This is not a ppm file, starts with '%s'", line);
motion_log(LOG_ERR, 1, "%s: This is not a ppm file, starts with '%s'",
__FUNCTION__, line);
return NULL;
}
@@ -563,12 +565,13 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
/* check size */
if (sscanf(line, "%d %d", &x, &y) != 2) {
motion_log(LOG_ERR, 1, "Failed reading size in pgm file");
motion_log(LOG_ERR, 1, "%s: Failed reading size in pgm file", __FUNCTION__);
return NULL;
}
if (x != width || y != height) {
motion_log(LOG_ERR, 1, "Wrong image size %dx%d should be %dx%d", x, y, width, height);
motion_log(LOG_ERR, 1, "%s: Wrong image size %dx%d should be %dx%d",
__FUNCTION__, x, y, width, height);
return NULL;
}
@@ -579,7 +582,7 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
return NULL;
if (sscanf(line, "%d", &maxval) != 1) {
motion_log(LOG_ERR, 1, "Failed reading maximum value in pgm file");
motion_log(LOG_ERR, 1, "%s: Failed reading maximum value in pgm file", __FUNCTION__);
return NULL;
}
@@ -589,7 +592,7 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
for (y = 0; y < height; y++) {
if ((int)fread(&image[y * width], 1, width, picture) != width)
motion_log(LOG_ERR, 1, "Failed reading image data from pgm file");
motion_log(LOG_ERR, 1, "%s: Failed reading image data from pgm file", __FUNCTION__);
for (x = 0; x < width; x++) {
image[y * width + x] = (int)image[y * width + x] * 255 / maxval;
@@ -612,10 +615,11 @@ 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(LOG_ERR, 1,
"can't write mask file %s - check access rights to target directory", file);
"%s: can't write mask file %s - check access rights to target directory",
__FUNCTION__, file);
} else {
/* If target dir is temporarily unavailable we may survive */
motion_log(LOG_ERR, 1, "can't write mask file %s", file);
motion_log(LOG_ERR, 1, "%s: can't write mask file %s", __FUNCTION__, file);
}
return;
}
@@ -628,14 +632,14 @@ void put_fixed_mask(struct context *cnt, const char *file)
/* write pgm image data at once */
if ((int)fwrite(cnt->imgs.out, cnt->conf.width, cnt->conf.height, picture) != cnt->conf.height) {
motion_log(LOG_ERR, 1, "Failed writing default mask as pgm file");
motion_log(LOG_ERR, 1, "%s: Failed writing default mask as pgm file", __FUNCTION__);
return;
}
fclose(picture);
motion_log(LOG_ERR, 0, "Creating empty mask %s",cnt->conf.mask_file);
motion_log(LOG_ERR, 0, "Please edit this file and re-run motion to enable mask feature");
motion_log(LOG_ERR, 0, "%s: Creating empty mask %s\nPlease edit this file and "
"re-run motion to enable mask feature", __FUNCTION__, cnt->conf.mask_file);
}
/* save preview_shot */

View File

@@ -237,8 +237,8 @@ void rotate_init(struct context *cnt)
* we have a value that is safe from changes caused by motion-control.
*/
if((cnt->conf.rotate_deg % 90) > 0) {
motion_log(LOG_ERR, 0, "Config option \"rotate\" not a multiple of 90: %d",
cnt->conf.rotate_deg);
motion_log(LOG_ERR, 0, "%s: Config option \"rotate\" not a multiple of 90: %d",
__FUNCTION__, cnt->conf.rotate_deg);
cnt->conf.rotate_deg = 0; /* disable rotation */
cnt->rotate_data.degrees = 0; /* force return below */
} else {
@@ -268,37 +268,35 @@ 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:
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.
*/
size = cnt->imgs.width * cnt->imgs.height * 3 / 2;
size = cnt->imgs.width * cnt->imgs.height * 3 / 2;
break;
case VIDEO_PALETTE_GREY:
case VIDEO_PALETTE_GREY:
/* For greyscale, the memory block used for 90/270 degrees rotation
* needs to be width x height bytes large.
*/
size = cnt->imgs.width * cnt->imgs.height;
size = cnt->imgs.width * cnt->imgs.height;
break;
default:
cnt->rotate_data.degrees = 0;
motion_log(LOG_ERR, 0, "Unsupported palette (%d), rotation is disabled",
cnt->imgs.type);
default:
cnt->rotate_data.degrees = 0;
motion_log(LOG_ERR, 0, "%s: Unsupported palette (%d), rotation is disabled",
__FUNCTION__, cnt->imgs.type);
return;
}
/* 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);
}
}
/**
@@ -314,9 +312,8 @@ void rotate_init(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);
}
}
/**

View File

@@ -51,7 +51,8 @@ int http_bindsock(int port, int local)
optval = getaddrinfo(local ? "localhost" : NULL, portnumber, &hints, &res);
if (optval != 0) {
motion_log(LOG_ERR, 1, "getaddrinfo() for motion-stream socket failed: %s", gai_strerror(optval));
motion_log(LOG_ERR, 1, "%s: getaddrinfo() for motion-stream socket failed: %s",
__FUNCTION__, gai_strerror(optval));
freeaddrinfo(res);
return -1;
}
@@ -70,33 +71,33 @@ int http_bindsock(int port, int local)
/* Reuse Address */
setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( int ) );
motion_log(LOG_INFO, 0, "motion-stream testing : %s addr: %s port: %s",
res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
motion_log(LOG_INFO, 0, "%s: motion-stream testing : %s addr: %s port: %s",
__FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
if (bind(sl, res->ai_addr, res->ai_addrlen) == 0){
motion_log(LOG_INFO, 0, "motion-stream Bound : %s addr: %s port: %s",
res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
motion_log(LOG_INFO, 0, "%s: motion-stream Bound : %s addr: %s port: %s",
__FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
break;
}
motion_log(LOG_ERR, 1, "motion-stream bind() failed, retrying ");
motion_log(LOG_ERR, 1, "%s: motion-stream bind() failed, retrying", __FUNCTION__);
close(sl);
sl = -1;
}
motion_log(LOG_ERR, 1, "motion-stream socket failed, retrying");
motion_log(LOG_ERR, 1, "%s: motion-stream socket failed, retrying", __FUNCTION__);
res = res->ai_next;
}
freeaddrinfo(ressave);
if (sl < 0) {
motion_log(LOG_ERR, 1, "motion-stream creating socket/bind ERROR");
motion_log(LOG_ERR, 1, "%s: motion-stream creating socket/bind ERROR", __FUNCTION__);
return -1;
}
if (listen(sl, DEF_MAXWEBQUEUE) == -1) {
motion_log(LOG_ERR, 1, "motion-stream listen() ERROR");
motion_log(LOG_ERR, 1, "%s: motion-stream listen() ERROR", __FUNCTION__);
close(sl);
sl = -1;
}
@@ -118,7 +119,7 @@ static int http_acceptsock(int sl)
return sc;
}
motion_log(LOG_ERR, 1, "motion-stream accept()");
motion_log(LOG_ERR, 1, "%s: motion-stream accept()", __FUNCTION__);
return -1;
}
@@ -254,7 +255,7 @@ static void stream_add_client(struct stream *list, int sc)
new->socket = sc;
if ((new->tmpbuffer = stream_tmpbuffer(sizeof(header))) == NULL) {
motion_log(LOG_ERR, 1, "Error creating tmpbuffer in stream_add_client");
motion_log(LOG_ERR, 1, "%s: Error creating tmpbuffer in stream_add_client", __FUNCTION__);
} else {
memcpy(new->tmpbuffer->ptr, header, sizeof(header)-1);
new->tmpbuffer->size = sizeof(header)-1;
@@ -333,10 +334,12 @@ void stream_stop(struct context *cnt)
struct stream *list;
struct stream *next = cnt->stream.next;
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Closing motion-stream listen socket & active motion-stream sockets");
if (debug_level >= CAMERA_VERBOSE)
motion_log(-1, 0, "%s: Closing motion-stream listen socket"
" & active motion-stream sockets", __FUNCTION__);
else
motion_log(LOG_INFO, 0, "Closing motion-stream listen socket & active motion-stream sockets");
motion_log(LOG_INFO, 0, "%s: Closing motion-stream listen socket"
" & active motion-stream sockets", __FUNCTION__);
close(cnt->stream.socket);
cnt->stream.socket = -1;
@@ -354,10 +357,12 @@ void stream_stop(struct context *cnt)
free(list);
}
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Closed motion-stream listen socket & active motion-stream sockets");
if (debug_level >= CAMERA_VERBOSE)
motion_log(-1, 0, "%s: Closed motion-stream listen socket"
" & active motion-stream sockets", __FUNCTION__);
else
motion_log(LOG_INFO, 0, "Closed motion-stream listen socket & active motion-stream sockets");
motion_log(LOG_INFO, 0, "%s: Closed motion-stream listen socket"
" & active motion-stream sockets", __FUNCTION__);
}
/* stream_put is the starting point of the stream loop. It is called from
@@ -463,7 +468,7 @@ void stream_put(struct context *cnt, unsigned char *image)
*/
stream_add_write(&cnt->stream, tmpbuffer, cnt->conf.stream_maxrate);
} else {
motion_log(LOG_ERR, 1, "Error creating tmpbuffer");
motion_log(LOG_ERR, 1, "%s: Error creating tmpbuffer", __FUNCTION__);
}
}

85
track.c
View File

@@ -41,6 +41,7 @@ struct trackoptions track_template = {
/* Add your own center and move functions here: */
static unsigned short int servo_position(struct context *cnt, short unsigned int motor);
static unsigned short int servo_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED);
static unsigned short int stepper_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED);
@@ -232,12 +233,15 @@ static unsigned short int stepper_move(struct context *cnt, struct coord *cent,
unsigned short int command = 0, data = 0;
if (cnt->track.dev < 0) {
motion_log(LOG_INFO, 0, "No device %s started yet , trying stepper_center()", cnt->track.port);
if (!stepper_center(cnt, 0, 0)){
motion_log(LOG_INFO, 0, "%s: No device %s started yet , trying stepper_center()",
__FUNCTION__, cnt->track.port);
if (!stepper_center(cnt, 0, 0)) {
motion_log(LOG_ERR, 1, "%s: failed to initialize stepper device on %s , fd [%i].",
__FUNCTION__, cnt->track.port, cnt->track.dev);
return 0;
}
motion_log(LOG_INFO, 0, "%s: succeed , device started %s , fd [%i]",
__FUNCTION__, cnt->track.port, cnt->track.dev);
}
@@ -354,6 +358,18 @@ static unsigned short int servo_command(struct context *cnt, unsigned short int
return buffer[0];
}
static unsigned short int servo_position(struct context *cnt, short unsigned int motor)
{
unsigned short int ret = 0;
ret = servo_command(cnt, motor, SERVO_COMMAND_POSITION, 0);
return ret;
}
/*
* servo_move()
*
@@ -382,9 +398,10 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
if (manual) {
int offset;
int position;
if (cent->x) {
position = servo_position(cnt, cnt->track.motorx);
offset = cent->x * cnt->track.stepsize;
@@ -394,14 +411,14 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
else
command = SERVO_COMMAND_RIGHT_N;
// TODO: need to get position to avoid overflow limits
/*if ((offset > cnt->track.maxx) || (offset < cnt->track.minx)){
motion_log(LOG_INFO, 0, "%s: x %d value out of range!",
__FUNCTION__, offset);
return 0;
}*/
data = abs(offset);
if ((data + position > cnt->track.maxx) || (position - offset < cnt->track.minx)) {
motion_log(LOG_INFO, 0, "%s: x %d value out of range! (%d - %d)",
__FUNCTION__, data, cnt->track.minx, cnt->track.maxx);
return 0;
}
data = abs(offset);
/* Set Speed , TODO : it should be done only when speed changes */
servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed);
@@ -410,7 +427,7 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
if (cent->y) {
position = servo_position(cnt, cnt->track.motory);
offset = cent->y * cnt->track.stepsize;
if ( (cnt->track.motory_reverse && (offset > 0)) ||
@@ -419,14 +436,14 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
else
command = SERVO_COMMAND_DOWN_N;
// TODO: need to get position to avoid overflow limits
/*if ((offset > cnt->track.maxy) || (offset < cnt->track.miny)) {
motion_log(LOG_INFO, 0, "%s: y %d value out of range!",
__FUNCTION__, offset);
return 0;
}*/
data = abs(offset);
if ((data + position > cnt->track.maxy) || (position - offset < cnt->track.miny)) {
motion_log(LOG_INFO, 0, "%s: y %d value out of range! (%d - %d)",
__FUNCTION__, data, cnt->track.miny, cnt->track.maxy);
return 0;
}
/* Set Speed , TODO : it should be done only when speed changes */
servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed);
@@ -434,6 +451,7 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
}
} else {
int position;
/***** x-axis *****/
@@ -462,13 +480,15 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
data = data * cnt->track.stepsize / imgs->width;
if (data && command) {
// TODO: need to get position to avoid overflow limits
/*
if (data > cnt->track.maxx)
data = cnt->track.maxx;
else if (data < cnt->track.minx)
data = cnt->track.minx;
*/
position = servo_position(cnt, cnt->track.motorx);
if ((position + data > cnt->track.maxx) || (position - data < cnt->track.minx)) {
motion_log(LOG_INFO, 0, "%s: x %d value out of range! (%d - %d)",
__FUNCTION__, data, cnt->track.minx, cnt->track.maxx);
return 0;
}
/* Set Speed , TODO : it should be done only when speed changes */
@@ -508,15 +528,16 @@ static unsigned short int servo_move(struct context *cnt, struct coord *cent, st
data = data * cnt->track.stepsize / imgs->height;
if (data && command) {
// TODO: need to get position to avoid overflow limits
/*
if (data > cnt->track.maxy)
data = cnt->track.maxy;
else if (data < cnt->track.miny)
data = cnt->track.miny;
*/
position = servo_position(cnt, cnt->track.motory);
if ((position + data > cnt->track.maxy) || (position - data < cnt->track.miny)) {
motion_log(LOG_INFO, 0, "%s: y %d value out of range! (%d - %d)",
__FUNCTION__, data, cnt->track.miny, cnt->track.maxy);
return 0;
}
/* 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);

115
video.c
View File

@@ -29,7 +29,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
if (cnt->conf.contrast && cnt->conf.contrast != viddev->contrast) {
if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
make_change = 1;
vid_pic.contrast = cnt->conf.contrast * 256;
@@ -40,7 +40,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
if (!make_change) {
if (ioctl(dev, VIDIOCGPICT, &vid_pic)==-1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
}
make_change = 1;
@@ -52,7 +52,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
if (!make_change) {
if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
}
make_change = 1;
@@ -66,7 +66,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
/* If we already read the VIDIOGPICT - we should not do it again */
if (!make_change) {
if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
}
vid_pic.brightness = viddev->brightness * 256;
@@ -77,7 +77,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
if (cnt->conf.brightness && cnt->conf.brightness != viddev->brightness) {
if (!make_change) {
if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
}
make_change = 1;
@@ -88,7 +88,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
if (make_change) {
if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1)
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__);
}
}
@@ -99,8 +99,8 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
*/
unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
int input, int norm, unsigned long freq, int tuner_number)
unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int input,
int norm, unsigned long freq, int tuner_number)
{
int dev = viddev->fd;
struct video_capability vid_caps;
@@ -111,7 +111,7 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
void *map;
if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGCAP)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCAP)", __FUNCTION__);
return (NULL);
}
@@ -123,12 +123,12 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
vid_chnl.channel = input;
if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGCHAN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCHAN)", __FUNCTION__);
} else {
vid_chnl.channel = input;
vid_chnl.norm = norm;
if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSCHAN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSCHAN)", __FUNCTION__);
return (NULL);
}
}
@@ -138,7 +138,7 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
memset(&vid_tuner, 0, sizeof(struct video_tuner));
vid_tuner.tuner = tuner_number;
if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGTUNER)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGTUNER)", __FUNCTION__);
} else {
if (vid_tuner.flags & VIDEO_TUNER_LOW) {
freq = freq*16; /* steps of 1/16 KHz */
@@ -146,18 +146,17 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
freq = (freq*10)/625;
}
if (ioctl(dev, VIDIOCSFREQ, &freq) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSFREQ)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSFREQ)", __FUNCTION__);
return (NULL);
}
if (cnt->conf.setup_mode)
motion_log(-1, 0, "Frequency set");
if (debug_level >= CAMERA_VERBOSE)
motion_log(-1, 0, "%s: Frequency set", __FUNCTION__);
}
}
if (ioctl (dev, VIDIOCGMBUF, &vid_buf) == -1) {
motion_log(LOG_ERR, 0, "ioctl(VIDIOCGMBUF) - Error device does not support memory map");
motion_log(LOG_ERR, 0, "V4L capturing using read is deprecated!");
motion_log(LOG_ERR, 0, "Motion only supports mmap.");
motion_log(LOG_ERR, 0, "%s: ioctl(VIDIOCGMBUF) - Error device does not support memory map\n",
"V4L capturing using read is deprecated!\nMotion only supports mmap.", __FUNCTION__);
return NULL;
} else {
map = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
@@ -172,7 +171,7 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
}
if (MAP_FAILED == map) {
motion_log(LOG_ERR, 1, "MAP_FAILED");
motion_log(LOG_ERR, 1, "%s: MAP_FAILED", __FUNCTION__);
return (NULL);
}
viddev->v4l_curbuffer = 0;
@@ -181,29 +180,33 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
vid_mmap.width = width;
vid_mmap.height = height;
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_DEBUG, 1, "Failed with YUV420P, trying YUV422 palette");
motion_log(LOG_DEBUG, 1, "%s: Failed with YUV420P, trying YUV422 palette",
__FUNCTION__);
viddev->v4l_fmt = VIDEO_PALETTE_YUV422;
vid_mmap.format = viddev->v4l_fmt;
/* Try again... */
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_DEBUG, 1, "Failed with YUV422, trying YUYV palette");
motion_log(LOG_DEBUG, 1, "%s: Failed with YUV422, trying YUYV palette",
__FUNCTION__);
viddev->v4l_fmt = VIDEO_PALETTE_YUYV;
vid_mmap.format = viddev->v4l_fmt;
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_DEBUG, 1, "Failed with YUYV, trying RGB24 palette");
motion_log(LOG_DEBUG, 1, "%s: Failed with YUYV, trying RGB24 palette",
__FUNCTION__);
viddev->v4l_fmt = VIDEO_PALETTE_RGB24;
vid_mmap.format = viddev->v4l_fmt;
/* Try again... */
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_DEBUG, 1, "Failed with RGB24, trying GREYSCALE palette");
motion_log(LOG_DEBUG, 1, "%s: Failed with RGB24, trying"
"GREYSCALE palette", __FUNCTION__);
viddev->v4l_fmt = VIDEO_PALETTE_GREY;
vid_mmap.format = viddev->v4l_fmt;
/* Try one last time... */
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_ERR, 1, "Failed with all supported palettes "
"- giving up");
motion_log(LOG_ERR, 1, "%s: Failed with all supported palettes "
"- giving up", __FUNCTION__);
return (NULL);
}
}
@@ -214,24 +217,24 @@ unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int widt
switch (viddev->v4l_fmt) {
case VIDEO_PALETTE_YUV420P:
viddev->v4l_bufsize = (width*height*3)/2;
motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_YUV420P palette");
viddev->v4l_bufsize = (width * height * 3) / 2;
motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUV420P palette", __FUNCTION__);
break;
case VIDEO_PALETTE_YUV422:
viddev->v4l_bufsize = (width*height*2);
motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_YUV422 palette");
viddev->v4l_bufsize = (width * height * 2);
motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUV422 palette", __FUNCTION__);
break;
case VIDEO_PALETTE_YUYV:
viddev->v4l_bufsize = (width*height*2);
motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_YUYV palette");
viddev->v4l_bufsize = (width * height * 2);
motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_YUYV palette", __FUNCTION__);
break;
case VIDEO_PALETTE_RGB24:
viddev->v4l_bufsize = (width*height*3);
motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_RGB24 palette");
viddev->v4l_bufsize = (width * height * 3);
motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_RGB24 palette", __FUNCTION__);
break;
case VIDEO_PALETTE_GREY:
viddev->v4l_bufsize = width*height;
motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_GREY palette");
viddev->v4l_bufsize = width * height;
motion_log(LOG_DEBUG, 0, "%s: Using VIDEO_PALETTE_GREY palette", __FUNCTION__);
break;
}
return map;
@@ -286,7 +289,7 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height
vid_mmap.frame = viddev->v4l_curbuffer;
if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
motion_log(LOG_ERR, 1, "mcapture error in proc %d", getpid());
motion_log(LOG_ERR, 1, "%s: mcapture error in proc %d", __FUNCTION__, getpid());
sigprocmask (SIG_UNBLOCK, &old, NULL);
return V4L_FATAL_ERROR;
}
@@ -294,7 +297,7 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height
vid_mmap.frame = frame;
if (ioctl(dev, VIDIOCSYNC, &vid_mmap.frame) == -1) {
motion_log(LOG_ERR, 1, "sync error in proc %d", getpid());
motion_log(LOG_ERR, 1, "%s: sync error in proc %d", __FUNCTION__, getpid());
sigprocmask (SIG_UNBLOCK, &old, NULL);
}
@@ -332,7 +335,7 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
vid_tuner.tuner = tuner_number;
if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGTUNER)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGTUNER)", __FUNCTION__);
} else {
if (vid_tuner.flags & VIDEO_TUNER_LOW) {
frequnits = freq*16; /* steps of 1/16 KHz */
@@ -340,7 +343,7 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
frequnits = (freq*10)/625;
}
if (ioctl(dev, VIDIOCSFREQ, &frequnits) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSFREQ)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSFREQ)", __FUNCTION__);
return;
}
}
@@ -350,12 +353,12 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
vid_chnl.channel = input;
if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGCHAN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGCHAN)", __FUNCTION__);
} else {
vid_chnl.channel = input;
vid_chnl.norm = norm;
if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSCHAN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSCHAN)", __FUNCTION__);
return;
}
}
@@ -384,13 +387,13 @@ static int v4l_open_vidpipe(void)
struct utsname uts;
if (uname(&uts) < 0) {
motion_log(LOG_ERR, 1, "Unable to execute uname");
motion_log(LOG_ERR, 1, "%s: Unable to execute uname", __FUNCTION__);
return -1;
}
major = strtok(uts.release, ".");
minor = strtok(NULL, ".");
if ((major == NULL) || (minor == NULL) || (strcmp(major, "2"))) {
motion_log(LOG_ERR, 1, "Unable to decipher OS version");
motion_log(LOG_ERR, 1, "%s: Unable to decipher OS version", __FUNCTION__);
return -1;
}
if (strcmp(minor, "5") < 0) {
@@ -403,13 +406,14 @@ static int v4l_open_vidpipe(void)
vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r");
if (!vloopbacks) {
motion_log(LOG_ERR, 1, "Failed to open '/proc/video/vloopback/vloopbacks'");
motion_log(LOG_ERR, 1, "%s: Failed to open '/proc/video/vloopback/vloopbacks'",
__FUNCTION__);
return -1;
}
/* Read vloopback version*/
if (!fgets(buffer, 255, vloopbacks)) {
motion_log(LOG_ERR, 1, "Unable to read vloopback version");
motion_log(LOG_ERR, 1, "%s: Unable to read vloopback version", __FUNCTION__);
return -1;
}
@@ -418,7 +422,8 @@ static int v4l_open_vidpipe(void)
/* Read explanation line */
if (!fgets(buffer, 255, vloopbacks)) {
motion_log(LOG_ERR, 1, "Unable to read vloopback explanation line");
motion_log(LOG_ERR, 1, "%s: Unable to read vloopback explanation line",
__FUNCTION__);
return -1;
}
@@ -434,8 +439,8 @@ static int v4l_open_vidpipe(void)
snprintf(pipepath, 255, "/dev/%s", input);
pipe_fd = open(pipepath, O_RDWR);
if (pipe_fd >= 0) {
motion_log(-1, 0, "\tInput: /dev/%s", input);
motion_log(-1, 0, "\tOutput: /dev/%s", output);
motion_log(-1, 0, "%s: \tInput: /dev/%s \tOutput: /dev/%s",
__FUNCTION__, input, output);
break;
}
}
@@ -453,7 +458,7 @@ static int v4l_open_vidpipe(void)
int tnum;
if ((dir = opendir(prefix)) == NULL) {
motion_log(LOG_ERR, 1, "Failed to open '%s'", prefix);
motion_log(LOG_ERR, 1, "%s: Failed to open '%s'", __FUNCTION__, prefix);
return -1;
}
while ((dirp = readdir(dir)) != NULL) {
@@ -501,7 +506,7 @@ static int v4l_open_vidpipe(void)
}
closedir(dir);
if (pipe_fd >= 0)
motion_log(-1, 0, "Opened input of %s", pipepath);
motion_log(-1, 0, "%s: Opened input of %s", __FUNCTION__, pipepath);
}
return pipe_fd;
}
@@ -521,22 +526,22 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type)
return(-1);
if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__);
return(-1);
}
vid_pic.palette = type;
if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSPICT)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__);
return(-1);
}
if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCGWIN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCGWIN)", __FUNCTION__);
return(-1);
}
vid_win.height = height;
vid_win.width = width;
if (ioctl(dev, VIDIOCSWIN, &vid_win) == -1) {
motion_log(LOG_ERR, 1, "ioctl (VIDIOCSWIN)");
motion_log(LOG_ERR, 1, "%s: ioctl (VIDIOCSWIN)", __FUNCTION__);
return(-1);
}
return dev;
@@ -550,7 +555,7 @@ static int v4l_putpipe (int dev, unsigned char *image, int size)
int vid_startpipe(const char *dev_name, int width, int height, int type)
{
return v4l_startpipe( dev_name, width, height, type);
return v4l_startpipe(dev_name, width, height, type);
}
int vid_putpipe (int dev, unsigned char *image, int size)

View File

@@ -90,7 +90,7 @@ void mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int h
/* video functions, video.c */
int vid_startpipe(const char *dev_name, int width, int height, int);
int vid_putpipe(int dev, unsigned char *image, int);
unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
unsigned char *v4l_start(struct video_dev *viddev, int width, int height,
int input, int norm, unsigned long freq, int tuner_number);
void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height, int input,
int norm, int skip, unsigned long freq, int tuner_number);

142
video2.c
View File

@@ -149,14 +149,15 @@ static int v4l2_get_capability(src_v4l2_t * s)
{
if (xioctl(s->fd, VIDIOC_QUERYCAP, &s->cap) < 0) {
motion_log(LOG_ERR, 0, "Not a V4L2 device?");
motion_log(LOG_ERR, 0, "%s: Not a V4L2 device?", __FUNCTION__);
return (-1);
}
motion_log(LOG_INFO, 0, "cap.driver: \"%s\"", s->cap.driver);
motion_log(LOG_INFO, 0, "cap.card: \"%s\"", s->cap.card);
motion_log(LOG_INFO, 0, "cap.bus_info: \"%s\"", s->cap.bus_info);
motion_log(LOG_INFO, 0, "cap.capabilities=0x%08X", s->cap.capabilities);
motion_log(LOG_INFO, 0, "%s: \n------------------------\ncap.driver: \"%s\"\n"
"cap.card: \"%s\"\n"
"cap.bus_info: \"%s\"\n"
"cap.capabilities=0x%08X\n------------------------", __FUNCTION__,
s->cap.driver, s->cap.card, s->cap.bus_info, s->cap.capabilities);
if (s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
motion_log(LOG_INFO, 0, "- VIDEO_CAPTURE");
@@ -184,7 +185,7 @@ static int v4l2_get_capability(src_v4l2_t * s)
motion_log(LOG_INFO, 0, "- TIMEPERFRAME");
if (!s->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
motion_log(LOG_ERR, 0, "Device does not support capturing.");
motion_log(LOG_ERR, 0, "%s: Device does not support capturing.", __FUNCTION__);
return (-1);
}
@@ -204,31 +205,31 @@ static int v4l2_select_input(src_v4l2_t * s, int in, int norm, unsigned long fre
memset (&input, 0, sizeof (input));
input.index = in;
if (xioctl(s->fd, VIDIOC_ENUMINPUT, &input) == -1) {
motion_log(LOG_ERR, 0, "Unable to query input %d.", in);
motion_log(LOG_ERR, 0, "VIDIOC_ENUMINPUT: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Unable to query input %d.\nVIDIOC_ENUMINPUT: %s",
__FUNCTION__, in, strerror(errno));
return (-1);
}
if (debug_level > 5)
if (debug_level >= CAMERA_VIDEO)
motion_log(LOG_INFO, 0, "%s: name = \"%s\", type 0x%08X, status %08x", __FUNCTION__, input.name,
input.type, input.status);
if ((input.type & V4L2_INPUT_TYPE_TUNER) && (debug_level > 5))
if ((input.type & V4L2_INPUT_TYPE_TUNER) && (debug_level >= CAMERA_VIDEO))
motion_log(LOG_INFO, 0, "- TUNER");
if ((input.type & V4L2_INPUT_TYPE_CAMERA) && (debug_level > 5))
if ((input.type & V4L2_INPUT_TYPE_CAMERA) && (debug_level >= CAMERA_VIDEO))
motion_log(LOG_INFO, 0, "- CAMERA");
if (xioctl(s->fd, VIDIOC_S_INPUT, &in) == -1) {
motion_log(LOG_ERR, 0, "Error selecting input %d", in);
motion_log(LOG_ERR, 0, "VIDIOC_S_INPUT: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error selecting input %d\nVIDIOC_S_INPUT: %s",
__FUNCTION__, in, strerror(errno));
return (-1);
}
/* Set video standard usually webcams doesn't support the ioctl or return V4L2_STD_UNKNOWN */
if (xioctl(s->fd, VIDIOC_G_STD, &std_id) == -1) {
if (debug_level > 5)
motion_log(LOG_INFO, 0, "Device doesn't support VIDIOC_G_STD ");
if (debug_level >= CAMERA_VIDEO)
motion_log(LOG_INFO, 0, "%s: Device doesn't support VIDIOC_G_STD", __FUNCTION__);
std_id = 0; // V4L2_STD_UNKNOWN = 0
}
@@ -237,9 +238,9 @@ static int v4l2_select_input(src_v4l2_t * s, int in, int norm, unsigned long fre
standard.index = 0;
while (xioctl(s->fd, VIDIOC_ENUMSTD, &standard) == 0) {
if ((standard.id & std_id) && (debug_level > 5)) {
if ((standard.id & std_id) && (debug_level >= CAMERA_VIDEO))
motion_log(LOG_INFO, 0, "- video standard %s", standard.name);
}
standard.index++;
}
@@ -254,10 +255,10 @@ static int v4l2_select_input(src_v4l2_t * s, int in, int norm, unsigned long fre
std_id = V4L2_STD_PAL;
}
if (xioctl(s->fd, VIDIOC_S_STD, &std_id) == -1) {
motion_log(LOG_ERR, 0, "Error selecting standard method %d", std_id);
motion_log(LOG_ERR, 0, "VIDIOC_S_STD: %s", strerror(errno));
}
if (xioctl(s->fd, VIDIOC_S_STD, &std_id) == -1)
motion_log(LOG_ERR, 0, "%s: Error selecting standard method %d\nVIDIOC_S_STD: %s",
__FUNCTION__, std_id, strerror(errno));
}
/* If this input is attached to a tuner, set the frequency. */
@@ -271,7 +272,7 @@ static int v4l2_select_input(src_v4l2_t * s, int in, int norm, unsigned long fre
tuner.index = input.tuner;
if (xioctl(s->fd, VIDIOC_G_TUNER, &tuner) == -1) {
motion_log(LOG_ERR, 0, "VIDIOC_G_TUNER: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: VIDIOC_G_TUNER: %s", __FUNCTION__,strerror(errno));
return (0);
}
@@ -282,7 +283,7 @@ static int v4l2_select_input(src_v4l2_t * s, int in, int norm, unsigned long fre
freq.frequency = (freq_ / 1000) * 16;
if (xioctl(s->fd, VIDIOC_S_FREQUENCY, &freq) == -1) {
motion_log(LOG_ERR, 0, "VIDIOC_S_FREQUENCY: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: VIDIOC_S_FREQUENCY: %s", __FUNCTION__,strerror(errno));
return (0);
}
}
@@ -314,7 +315,7 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
fmt.index = v4l2_pal = 0;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
motion_log(LOG_INFO, 0, "Supported palettes:");
motion_log(LOG_INFO, 0, "%s: Supported palettes:", __FUNCTION__);
while (xioctl(s->fd, VIDIOC_ENUM_FMT, &fmt) != -1) {
short int i;
@@ -357,51 +358,56 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
s->fmt.fmt.pix.field = V4L2_FIELD_ANY;
if (xioctl(s->fd, VIDIOC_TRY_FMT, &s->fmt) != -1 && s->fmt.fmt.pix.pixelformat == pixformat) {
motion_log(LOG_INFO, 0, "index_format %d Test palette %c%c%c%c (%dx%d)",
index_format, pixformat >> 0, pixformat >> 8,
pixformat >> 16, pixformat >> 24, *width, *height);
motion_log(LOG_INFO, 0, "%s: index_format %d Test palette %c%c%c%c (%dx%d)",
__FUNCTION__, index_format, pixformat >> 0, pixformat >> 8,
pixformat >> 16, pixformat >> 24, *width, *height);
if (s->fmt.fmt.pix.width != (unsigned int) *width
|| s->fmt.fmt.pix.height != (unsigned int) *height) {
motion_log(LOG_INFO, 0, "Adjusting resolution from %ix%i to %ix%i.", *width, *height,
s->fmt.fmt.pix.width, s->fmt.fmt.pix.height);
motion_log(LOG_INFO, 0, "%s: Adjusting resolution from %ix%i to %ix%i.",
__FUNCTION__, *width, *height, s->fmt.fmt.pix.width, s->fmt.fmt.pix.height);
*width = s->fmt.fmt.pix.width;
*height = s->fmt.fmt.pix.height;
}
if (xioctl(s->fd, VIDIOC_S_FMT, &s->fmt) == -1) {
motion_log(LOG_ERR, 0, "Error setting pixel format.");
motion_log(LOG_ERR, 0, "VIDIOC_S_FMT: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error setting pixel format.\nVIDIOC_S_FMT: %s",
__FUNCTION__, strerror(errno));
return (-1);
}
motion_log(LOG_INFO, 0, "Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage %d colorspace %08x",
pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height,
s->fmt.fmt.pix.bytesperline, s->fmt.fmt.pix.sizeimage, s->fmt.fmt. pix.colorspace);
motion_log(LOG_INFO, 0, "%s: Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage "
"%d colorspace %08x", __FUNCTION__, pixformat >> 0, pixformat >> 8, pixformat >> 16,
pixformat >> 24, *width, *height, s->fmt.fmt.pix.bytesperline, s->fmt.fmt.pix.sizeimage,
s->fmt.fmt. pix.colorspace);
/* TODO: Review when it has been tested */
if (pixformat == V4L2_PIX_FMT_MJPEG) {
struct v4l2_jpegcompression v4l2_jpeg;
if (xioctl(s->fd, VIDIOC_G_JPEGCOMP, &v4l2_jpeg) == -1) {
motion_log(LOG_ERR, 0, "VIDIOC_G_JPEGCOMP not supported but it should");
motion_log(LOG_ERR, 0, "%s: VIDIOC_G_JPEGCOMP not supported but it should",
__FUNCTION__);
} else {
v4l2_jpeg.jpeg_markers |= V4L2_JPEG_MARKER_DHT;
if (xioctl(s->fd, VIDIOC_S_JPEGCOMP, &v4l2_jpeg) == -1)
motion_log(LOG_ERR, 0, "VIDIOC_S_JPEGCOMP %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: VIDIOC_S_JPEGCOMP %s",
__FUNCTION__, strerror(errno));
}
}
return 0;
}
motion_log(LOG_ERR, 0, "VIDIOC_TRY_FMT failed for format %c%c%c%c (%s).", pixformat >> 0,
pixformat >> 8, pixformat >> 16, pixformat >> 24, strerror(errno));
motion_log(LOG_ERR, 0, "%s: VIDIOC_TRY_FMT failed for format %c%c%c%c (%s).", __FUNCTION__,
pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, strerror(errno));
return -1;
}
motion_log(LOG_ERR, 0, "Unable to find a compatible palette format.");
motion_log(LOG_ERR, 0, "%s: Unable to find a compatible palette format.", __FUNCTION__);
return (-1);
}
@@ -437,16 +443,15 @@ static int v4l2_set_mmap(src_v4l2_t * s)
s->req.memory = V4L2_MEMORY_MMAP;
if (xioctl(s->fd, VIDIOC_REQBUFS, &s->req) == -1) {
motion_log(LOG_ERR, 1, "Error requesting buffers for memory map.");
motion_log(LOG_ERR, 0, "VIDIOC_REQBUFS: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error requesting buffers for memory map.\nVIDIOC_REQBUFS: %s",
__FUNCTION__, strerror(errno));
return (-1);
}
motion_log(LOG_DEBUG, 0, "mmap information:");
motion_log(LOG_DEBUG, 0, "frames=%d", s->req.count);
motion_log(LOG_DEBUG, 0, "%s: mmap information: frames=%d", __FUNCTION__, s->req.count);
if (s->req.count < MIN_MMAP_BUFFERS) {
motion_log(LOG_ERR, 0, "Insufficient buffer memory.");
motion_log(LOG_ERR, 0, "%s: Insufficient buffer memory.", __FUNCTION__);
return (-1);
}
@@ -466,8 +471,8 @@ static int v4l2_set_mmap(src_v4l2_t * s)
buf.index = b;
if (xioctl(s->fd, VIDIOC_QUERYBUF, &buf) == -1) {
motion_log(LOG_ERR, 0, "Error querying buffer %i", b);
motion_log(LOG_ERR, 0, "VIDIOC_QUERYBUF: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error querying buffer %i\nVIDIOC_QUERYBUF: %s",
__FUNCTION__, b, strerror(errno));
free(s->buffers);
return (-1);
}
@@ -476,13 +481,13 @@ static int v4l2_set_mmap(src_v4l2_t * s)
s->buffers[b].ptr = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset);
if (s->buffers[b].ptr == MAP_FAILED) {
motion_log(LOG_ERR, 0, "Error mapping buffer %i", b);
motion_log(LOG_ERR, 0, "mmap: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error mapping buffer %i\nmmap: %s",
__FUNCTION__, b, strerror(errno));
free(s->buffers);
return (-1);
}
motion_log(LOG_DEBUG, 0, "%i length=%d", b, buf.length);
motion_log(LOG_DEBUG, 0, "%s: %i length=%d", __FUNCTION__, b, buf.length);
}
s->map = -1;
@@ -495,7 +500,7 @@ static int v4l2_set_mmap(src_v4l2_t * s)
s->buf.index = b;
if (xioctl(s->fd, VIDIOC_QBUF, &s->buf) == -1) {
motion_log(LOG_ERR, 0, "VIDIOC_QBUF: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: VIDIOC_QBUF: %s", __FUNCTION__, strerror(errno));
return (-1);
}
}
@@ -503,8 +508,8 @@ static int v4l2_set_mmap(src_v4l2_t * s)
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(s->fd, VIDIOC_STREAMON, &type) == -1) {
motion_log(LOG_ERR, 0, "Error starting stream.");
motion_log(LOG_ERR, 0, "VIDIOC_STREAMON: %s", strerror(errno));
motion_log(LOG_ERR, 0, "%s: Error starting stream.\nVIDIOC_STREAMON: %s",
__FUNCTION__, strerror(errno));
return (-1);
}
@@ -545,15 +550,15 @@ static int v4l2_scan_controls(src_v4l2_t * s)
memcpy(ctrl, &queryctrl, sizeof(struct v4l2_queryctrl));
motion_log(LOG_INFO, 0, "found control 0x%08x, \"%s\", range %d,%d %s", ctrl->id,
ctrl->name, ctrl->minimum, ctrl->maximum,
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : "");
motion_log(LOG_INFO, 0, "%s: found control 0x%08x, \"%s\", range %d,%d %s",
__FUNCTION__,ctrl->id, ctrl->name, ctrl->minimum, ctrl->maximum,
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : "");
memset (&control, 0, sizeof (control));
control.id = queried_ctrls[i];
xioctl(s->fd, VIDIOC_G_CTRL, &control);
motion_log(LOG_INFO, 0, "\t\"%s\", default %d, current %d", ctrl->name,
ctrl->default_value, control.value);
motion_log(LOG_INFO, 0, "%s: \t\"%s\", default %d, current %d", __FUNCTION__,
ctrl->name, ctrl->default_value, control.value);
ctrl++;
}
@@ -593,14 +598,13 @@ static int v4l2_set_control(src_v4l2_t * s, u32 cid, int value)
break;
default:
motion_log(LOG_ERR, 0, "%s: control type not supported yet");
motion_log(LOG_ERR, 0, "%s: control type not supported yet", __FUNCTION__);
return -1;
}
if (debug_level > 5)
motion_log(LOG_INFO, 0, "setting control \"%s\" to %d (ret %d %s) %s", ctrl->name,
value, ret, ret ? strerror(errno) : "",
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ?
"Control is DISABLED!" : "");
if (debug_level >= CAMERA_VIDEO)
motion_log(LOG_INFO, 0, "%s: setting control \"%s\" to %d (ret %d %s) %s",
__FUNCTION__, ctrl->name, value, ret, ret ? strerror(errno) : "",
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "Control is DISABLED!" : "");
return 0;
}
@@ -741,9 +745,9 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
{
src_v4l2_t *s = (src_v4l2_t *) viddev->v4l2_private;
unsigned int counter = 0;
if (debug_level > 5)
motion_log(LOG_DEBUG, 0, "set_input_skip_frame switch_time=%ld:%ld",
switchTime.tv_sec, switchTime.tv_usec);
if (debug_level >= CAMERA_VIDEO)
motion_log(LOG_DEBUG, 0, "%s: set_input_skip_frame switch_time=%ld:%ld",
__FUNCTION__, switchTime.tv_sec, switchTime.tv_usec);
/* Avoid hang using the number of mmap buffers */
while(counter < s->req.count)
@@ -754,9 +758,9 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
if (s->buf.timestamp.tv_sec > switchTime.tv_sec ||
(s->buf.timestamp.tv_sec == switchTime.tv_sec && s->buf.timestamp.tv_usec > switchTime.tv_usec))
break;
if (debug_level > 5)
motion_log(LOG_DEBUG, 0, "got frame before switch timestamp=%ld:%ld",
s->buf.timestamp.tv_sec, s->buf.timestamp.tv_usec);
if (debug_level >= CAMERA_VIDEO)
motion_log(LOG_DEBUG, 0, "%s: got frame before switch timestamp=%ld:%ld",
__FUNCTION__, s->buf.timestamp.tv_sec, s->buf.timestamp.tv_usec);
}
}

View File

@@ -552,7 +552,7 @@ void vid_close(struct context *cnt)
/* Cleanup the netcam part */
if(cnt->netcam) {
motion_log(LOG_DEBUG, 0, "vid_close: calling netcam_cleanup");
motion_log(LOG_DEBUG, 0, "%s: calling netcam_cleanup", __FUNCTION__);
netcam_cleanup(cnt->netcam, 0);
cnt->netcam = NULL;
return;
@@ -574,12 +574,12 @@ void vid_close(struct context *cnt)
cnt->video_dev = -1;
if (dev == NULL) {
motion_log(LOG_ERR, 0, "vid_close: Unable to find video device");
motion_log(LOG_ERR, 0, "%s: Unable to find video device", __FUNCTION__);
return;
}
if( --dev->usage_count == 0) {
motion_log(LOG_INFO, 0, "Closing video device %s", dev->video_device);
motion_log(LOG_INFO, 0, "%s: Closing video device %s", __FUNCTION__, dev->video_device);
#ifdef MOTION_V4L2
if (dev->v4l2) {
v4l2_close(dev);
@@ -605,7 +605,8 @@ void vid_close(struct context *cnt)
pthread_mutex_destroy(&dev->mutex);
free(dev);
} else {
motion_log(LOG_INFO, 0, "Still %d users of video device %s, so we don't close it now", dev->usage_count, dev->video_device);
motion_log(LOG_INFO, 0, "%s: Still %d users of video device %s, so we don't close it now",
__FUNCTION__, dev->usage_count, dev->video_device);
/* There is still at least one thread using this device
* If we own it, release it
*/
@@ -659,12 +660,14 @@ static int vid_v4lx_start(struct context *cnt)
* for this first.
*/
if (conf->width % 16) {
motion_log(LOG_ERR, 0, "config image width (%d) is not modulo 16", conf->width);
motion_log(LOG_ERR, 0, "%s: config image width (%d) is not modulo 16",
__FUNCTION__, conf->width);
return -1;
}
if (conf->height % 16) {
motion_log(LOG_ERR, 0, "config image height (%d) is not modulo 16", conf->height);
motion_log(LOG_ERR, 0, "%s: config image height (%d) is not modulo 16",
__FUNCTION__, conf->height);
return -1;
}
@@ -722,7 +725,8 @@ static int vid_v4lx_start(struct context *cnt)
fd = open(dev->video_device, O_RDWR);
if (fd < 0) {
motion_log(LOG_ERR, 1, "Failed to open video device %s", conf->video_device);
motion_log(LOG_ERR, 1, "%s: Failed to open video device %s",
__FUNCTION__, conf->video_device);
free(dev);
pthread_mutex_unlock(&vid_mutex);
return -1;
@@ -761,7 +765,7 @@ static int vid_v4lx_start(struct context *cnt)
dev->height = height;
#endif
if (!v4l_start(cnt, dev, width, height, input, norm, frequency, tuner_number)) {
if (!v4l_start(dev, width, height, input, norm, frequency, tuner_number)) {
close(dev->fd);
pthread_mutexattr_destroy(&dev->attr);
pthread_mutex_destroy(&dev->mutex);
@@ -775,9 +779,9 @@ static int vid_v4lx_start(struct context *cnt)
}
#endif
if (dev->v4l2 == 0) {
motion_log(-1, 0, "Using V4L1");
motion_log(-1, 0, "%s: Using V4L1", __FUNCTION__);
} else {
motion_log(-1, 0, "Using V4L2");
motion_log(-1, 0, "%s: Using V4L2", __FUNCTION__);
/* Update width & height because could be changed in v4l2_start () */
width = dev->width;
height = dev->height;
@@ -850,7 +854,7 @@ int vid_start(struct context *cnt)
}
#ifdef WITHOUT_V4L
else
motion_log(LOG_ERR, 0, "You must setup netcam_url");
motion_log(LOG_ERR, 0, "%s: You must setup netcam_url", __FUNCTION__);
#else
else
dev = vid_v4lx_start(cnt);

View File

@@ -189,7 +189,6 @@ static const char *request_auth_response_template=
"WWW-Authenticate: Basic realm=\"Motion Security Access\"\r\n";
static ssize_t write_nonblock(int fd, const void *buf, size_t size)
{
ssize_t nwrite = -1;
@@ -211,7 +210,6 @@ static ssize_t write_nonblock(int fd, const void *buf, size_t size)
}
return nwrite;
}
@@ -234,20 +232,18 @@ static ssize_t read_nonblock(int fd ,void *buf, ssize_t size)
}
}
}
return nread;
}
static void send_template_ini_client(int client_socket, const char *template)
{
ssize_t nwrite = 0;
nwrite = write_nonblock(client_socket, ok_response, strlen (ok_response));
nwrite += write_nonblock(client_socket, template, strlen(template));
if (nwrite != (ssize_t)(strlen(ok_response) + strlen(template)))
motion_log(LOG_ERR, 1, "httpd send_template_ini_client");
motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__);
}
static void send_template_ini_client_raw(int client_socket)
@@ -255,7 +251,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(LOG_ERR, 1, "httpd send_template_ini_client_raw");
motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__);
}
static void send_template(int client_socket, char *res)
@@ -263,7 +259,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(LOG_ERR, 1, "httpd send_template failure write");
motion_log(LOG_ERR, 1, "%s: failure write", __FUNCTION__);
}
static void send_template_raw(int client_socket, char *res)
@@ -322,7 +318,6 @@ static char *replace(const char *str, const char *old, const char *new)
/*
This function decode the values from GET request following the http RFC.
*/
static void url_decode(char *urlencoded, size_t length)
{
char *data = urlencoded;
@@ -369,7 +364,7 @@ static void url_decode(char *urlencoded, size_t length)
static unsigned short int config(char *pointer, char *res, unsigned short int length_uri,
unsigned short int thread, int client_socket, void *userdata)
{
char question;
char question='\0';
char command[256] = {'\0'};
unsigned short int i;
struct context **cnt = userdata;
@@ -979,7 +974,7 @@ static unsigned short int action(char *pointer, char *res, unsigned short int le
/*call restart*/
if (thread == 0) {
motion_log(LOG_DEBUG, 0, "httpd restart");
motion_log(LOG_DEBUG, 0, "%s: httpd restart", __FUNCTION__);
kill(getpid(),SIGHUP);
if (cnt[0]->conf.webcontrol_html_output) {
send_template_ini_client(client_socket, ini_template);
@@ -993,7 +988,7 @@ static unsigned short int action(char *pointer, char *res, unsigned short int le
}
return 0; // to restart
} else {
motion_log(LOG_DEBUG, 0, "httpd restart thread %d", thread);
motion_log(LOG_DEBUG, 0, "%s: httpd restart thread %d", __FUNCTION__, thread);
if (cnt[thread]->running) {
cnt[thread]->makemovie = 1;
cnt[thread]->finish = 1;
@@ -1024,7 +1019,7 @@ static unsigned short int action(char *pointer, char *res, unsigned short int le
/*call quit*/
if (thread == 0) {
motion_log(LOG_DEBUG, 0, "httpd quit");
motion_log(LOG_DEBUG, 0, "%s: httpd quit", __FUNCTION__);
kill(getpid(),SIGQUIT);
if (cnt[0]->conf.webcontrol_html_output) {
send_template_ini_client(client_socket, ini_template);
@@ -1038,7 +1033,7 @@ static unsigned short int action(char *pointer, char *res, unsigned short int le
}
return 0; // to quit
} else {
motion_log(LOG_DEBUG, 0, "httpd quit thread %d", thread);
motion_log(LOG_DEBUG, 0, "%s: httpd quit thread %d", __FUNCTION__, thread);
cnt[thread]->restart = 0;
cnt[thread]->makemovie = 1;
cnt[thread]->finish = 1;
@@ -1272,7 +1267,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
if (( question != '=' ) || (command[0] == '\0')) {
/* no valid syntax */
motion_log(LOG_WARNING, 0, "httpd debug race 1");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 1", __FUNCTION__);
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
else
@@ -1322,7 +1317,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
}
} else {
/* no valid syntax */
motion_log(LOG_WARNING, 0, "httpd debug race 2");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 2", __FUNCTION__);
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
else
@@ -1333,7 +1328,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
/* first value check for error */
if ( !warningkill ) {
motion_log(LOG_WARNING, 0, "httpd debug race 3");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 3", __FUNCTION__);
/* error value */
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, error_value, NULL);
@@ -1486,7 +1481,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
warningkill = sscanf(pointer, "%c%255[a-z]" , &question, command);
if ( ( question != '&' ) || (command[0] == '\0') ) {
motion_log(LOG_WARNING, 0, "httpd debug race 4");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 4", __FUNCTION__);
if ( strstr(pointer, "&")) {
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, error_value, NULL);
@@ -1510,7 +1505,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
pointer = pointer + 3;
length_uri = length_uri - 3;
if ( (pan) || (!tilt) || (X) || (Y) ) {
motion_log(LOG_WARNING, 0, "httpd debug race 5");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 5", __FUNCTION__);
/* no valid syntax */
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
@@ -1526,7 +1521,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
length_uri = length_uri - 4;
if ( (tilt) || (!pan) || (X) || (Y) ) {
/* no valid syntax */
motion_log(LOG_WARNING, 0, "httpd debug race 6");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 6", __FUNCTION__);
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
else
@@ -1540,7 +1535,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
pointer++;
length_uri--;
if ( (X) || (!Y) || (pan) || (tilt) ) {
motion_log(LOG_WARNING, 0, "httpd debug race 7");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 7", __FUNCTION__);
/* no valid syntax */
if (cnt[0]->conf.webcontrol_html_output)
@@ -1556,7 +1551,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
pointer++;
length_uri--;
if ( (Y) || (!X) || (pan) || (tilt) ) {
motion_log(LOG_WARNING, 0, "httpd debug race 8");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 8", __FUNCTION__);
/* no valid syntax */
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
@@ -1567,7 +1562,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
Y = 2;
warningkill = sscanf(pointer, "%c%10[-0-9]" , &question, y_value);
} else {
motion_log(LOG_WARNING, 0, "httpd debug race 9");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 9", __FUNCTION__);
/* no valid syntax */
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
@@ -1579,7 +1574,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
/* Second value check */
if ( ( warningkill < 2 ) && (question != '=') ) {
motion_log(LOG_WARNING, 0, "httpd debug race 10");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 10", __FUNCTION__);
/* no valid syntax */
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, not_valid_syntax, NULL);
@@ -1587,7 +1582,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
response_client(client_socket, not_valid_syntax_raw, NULL);
return 1;
}else if (( question == '=') && ( warningkill == 1)) {
motion_log(LOG_WARNING, 0, "httpd debug race 11");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 11", __FUNCTION__);
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, error_value, NULL);
else
@@ -1616,7 +1611,7 @@ static unsigned short int track(char *pointer, char *res, unsigned short int len
if (length_uri != 0) {
motion_log(LOG_WARNING, 0, "httpd debug race 12");
motion_log(LOG_WARNING, 0, "%s: httpd debug race 12", __FUNCTION__);
if (cnt[0]->conf.webcontrol_html_output)
response_client(client_socket, error_value, NULL);
else
@@ -2191,7 +2186,7 @@ static unsigned short int read_client(int client_socket, void *userdata, char *a
nread = read_nonblock(client_socket, buffer, length);
if (nread <= 0) {
motion_log(LOG_ERR, 1, "motion-httpd First Read Error");
motion_log(LOG_ERR, 1, "%s: motion-httpd First Read Error", __FUNCTION__);
pthread_mutex_unlock(&httpd_mutex);
return 1;
}
@@ -2227,7 +2222,8 @@ static unsigned short int read_client(int client_socket, void *userdata, char *a
nread += readb;
if (nread > length) {
motion_log(LOG_ERR, 1, "motion-httpd End buffer reached waiting for buffer ending");
motion_log(LOG_ERR, 1, "%s: motion-httpd End buffer reached waiting "
"for buffer ending", __FUNCTION__);
break;
}
buffer[nread] = '\0';
@@ -2236,7 +2232,7 @@ static unsigned short int read_client(int client_socket, void *userdata, char *a
/* Make sure the last read didn't fail. If it did, there's a
problem with the connection, so give up. */
if (nread == -1) {
motion_log(LOG_ERR, 1, "motion-httpd READ give up!");
motion_log(LOG_ERR, 1, "%s: motion-httpd READ give up!", __FUNCTION__);
pthread_mutex_unlock(&httpd_mutex);
return 1;
}
@@ -2390,7 +2386,8 @@ void httpd_run(struct context **cnt)
/* check != 0 to allow FreeBSD compatibility */
if (val != 0) {
motion_log(LOG_ERR, 1, "getaddrinfo() for httpd socket failed: %s", gai_strerror(val));
motion_log(LOG_ERR, 1, "%s: getaddrinfo() for httpd socket failed: %s",
__FUNCTION__, gai_strerror(val));
freeaddrinfo(res);
return;
}
@@ -2404,8 +2401,8 @@ void httpd_run(struct context **cnt)
getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
motion_log(LOG_INFO, 0, "motion-httpd testing : %s addr: %s port: %s",
res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
motion_log(LOG_INFO, 0, "%s: motion-httpd testing : %s addr: %s port: %s",
__FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
if (sd >= 0) {
val = 1;
@@ -2413,36 +2410,40 @@ void httpd_run(struct context **cnt)
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( int ) );
if (bind(sd, res->ai_addr, res->ai_addrlen) == 0) {
motion_log(LOG_INFO, 0, "motion-httpd Bound : %s addr: %s port: %s",
res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
motion_log(LOG_INFO, 0, "%s: motion-httpd Bound : %s addr: %s port: %s",
__FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
break;
}
motion_log(LOG_ERR, 1, "motion-httpd failed bind() interface %s / port %s, retrying", hbuf, sbuf);
motion_log(LOG_ERR, 1, "%s: motion-httpd failed bind() interface %s / port %s, retrying",
__FUNCTION__, hbuf, sbuf);
close(sd);
sd = -1;
}
motion_log(LOG_ERR, 1, "motion-httpd socket failed interface %s / port %s, retrying", hbuf, sbuf);
motion_log(LOG_ERR, 1, "%s: motion-httpd socket failed interface %s / port %s, retrying",
__FUNCTION__, hbuf, sbuf);
res = res->ai_next;
}
freeaddrinfo(ressave);
if (sd < 0) {
motion_log(LOG_ERR, 1, "motion-httpd ERROR bind() [interface %s port %s]", hbuf, sbuf);
motion_log(LOG_ERR, 1, "%s: motion-httpd ERROR bind() [interface %s port %s]",
__FUNCTION__, hbuf, sbuf);
return;
}
if (listen(sd,5) == -1) {
motion_log(LOG_ERR, 1, "motion-httpd ERROR listen() [interface %s port %s]", hbuf, sbuf);
motion_log(LOG_ERR, 1, "%s: motion-httpd ERROR listen() [interface %s port %s]",
__FUNCTION__, hbuf, sbuf);
close(sd);
return;
}
motion_log(LOG_DEBUG, 0, "motion-httpd/"VERSION" running, accepting connections");
motion_log(LOG_DEBUG, 0, "motion-httpd: waiting for data on %s port TCP %s", hbuf, sbuf);
motion_log(LOG_DEBUG, 0, "%s: motion-httpd/"VERSION" running, accepting connections", __FUNCTION__);
motion_log(LOG_DEBUG, 0, "%s: motion-httpd: waiting for data on %s port TCP %s", __FUNCTION__, hbuf, sbuf);
if (cnt[0]->conf.webcontrol_authentication != NULL ) {
if (cnt[0]->conf.webcontrol_authentication != NULL) {
char *userpass = NULL;
size_t auth_size = strlen(cnt[0]->conf.webcontrol_authentication);
@@ -2461,13 +2462,13 @@ void httpd_run(struct context **cnt)
if (client_socket_fd < 0) {
if ((!cnt[0]) || (cnt[0]->finish)) {
motion_log(-1, 0, "motion-httpd - Finishing");
motion_log(-1, 0, "%s: motion-httpd - Finishing", __FUNCTION__);
closehttpd = 1;
}
} else {
/* Get the Client request */
client_sent_quit_message = read_client (client_socket_fd, cnt, authentication);
motion_log(-1, 0, "motion-httpd - Read from client");
motion_log(-1, 0, "%s: motion-httpd - Read from client", __FUNCTION__);
/* Close Connection */
if (client_socket_fd)
@@ -2476,9 +2477,10 @@ void httpd_run(struct context **cnt)
}
if (authentication != NULL) free(authentication);
if (authentication != NULL)
free(authentication);
close(sd);
motion_log(LOG_DEBUG, 0, "motion-httpd Closing");
motion_log(LOG_DEBUG, 0, "%s: motion-httpd Closing", __FUNCTION__);
pthread_mutex_destroy(&httpd_mutex);
}
@@ -2486,6 +2488,6 @@ void *motion_web_control(void *arg)
{
struct context **cnt = arg;
httpd_run(cnt);
motion_log(LOG_DEBUG, 0, "motion-httpd thread exit");
motion_log(LOG_DEBUG, 0, "%s: motion-httpd thread exit", __FUNCTION__);
pthread_exit(NULL);
}