From e3bb21d4e05577da29897e75409065b91e538845 Mon Sep 17 00:00:00 2001 From: Angel Carpintero Date: Thu, 3 Feb 2011 16:53:25 +0100 Subject: [PATCH] * Input for webcams has to be set to -1 http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2011x01x21x162309 * Postgresql close. --- CHANGELOG | 3 +++ CREDITS | 2 +- conf.c | 12 ++++++++++-- event.c | 31 +++++++++++++++++++++++++++---- motion-dist.conf.in | 14 +++++++++++--- motion.1 | 4 ++-- motion.c | 4 +++- thread1.conf.in | 6 +++--- thread2.conf.in | 4 ++-- thread3.conf.in | 6 +++--- video2.c | 4 ---- 11 files changed, 65 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d4bc868..07e67ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -55,6 +55,9 @@ Bugfixes * Avoid segfault when motion cannot create a logfile. (Angel Carpintero) * No mysql_close http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2010x11x22x033859 + * No PQfinish() (Angel Carpintero) + * Input for webcams has to be set to -1 + http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2011x01x21x162309 3.2.12 Summary of Changes diff --git a/CREDITS b/CREDITS index 6e2382c..17fd328 100644 --- a/CREDITS +++ b/CREDITS @@ -429,7 +429,7 @@ Angel Carpintero * Only use post capture when we setup to record videos with external pipe or ffmpeg. * Fixed FFV1 codec encode with ffmpeg. http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2010x04x13x032553 - + * No PQfinish(). Jared D * Change bayer2rgb24() to fix a problem with sn9c102 driver diff --git a/conf.c b/conf.c index 87d5ced..75d9993 100644 --- a/conf.c +++ b/conf.c @@ -292,8 +292,8 @@ config_param config_params[] = { #endif { "input", - "# The video input to be used (default: 8)\n" - "# Should normally be set to 0 or 1 for video/TV cards, and 8 for USB cameras", + "# The video input to be used (default: -1)\n" + "# Should normally be set to 0 or 1 for video/TV cards, and -1 for USB cameras", 0, CONF_OFFSET(input), copy_int, @@ -1398,6 +1398,14 @@ config_param config_params[] = { "# Additional special conversion specifiers are\n" "# %n = the number representing the file_type\n" "# %f = filename with full path\n" + "# Create tables :\n" + "##\n" + "# Mysql\n" + "# CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), event_time_stamp timestamp(14));\n" + "#\n" + "# Postgresql\n" + "# CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp without time zone, event_time_stamp timestamp without time zone);\n" + "#\n" "# Default value:\n" "# insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')", 0, diff --git a/event.c b/event.c index 63b400e..5e3b9df 100644 --- a/event.c +++ b/event.c @@ -155,7 +155,13 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, cnt->conf.database_host, cnt->conf.database_user, mysql_error(cnt->database)); } else { - mysql_query(cnt->database, sqlquery); + MOTION_LOG(INF, TYPE_DB, NO_ERRNO, "%s: Re-Connection to Mysql database '%s' Succeed", + cnt->conf.database_dbname); + if (mysql_query(cnt->database, sqlquery) != 0) { + int error_code = mysql_errno(cnt->database); + MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, "%s: after re-connection Mysql query failed %s error code %d", + mysql_error(cnt->database), error_code); + } } } } @@ -168,10 +174,27 @@ 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(ERR, TYPE_DB, SHOW_ERRNO, "%s: PGSQL query failed"); + if (PQstatus(cnt->database_pg) == CONNECTION_BAD) { + + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Connection to PostgreSQL database '%s' failed: %s", + cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); + + // This function will close the connection to the server and attempt to reestablish a new connection to the same server, + // using all the same parameters previously used. This may be useful for error recovery if a working connection is lost + PQreset(cnt->database_pg); + + if (PQstatus(cnt->database_pg) == CONNECTION_BAD) { + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Re-Connection to PostgreSQL database '%s' failed: %s", + cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); + } else { + MOTION_LOG(INF, TYPE_DB, NO_ERRNO, "%s: Re-Connection to PostgreSQL database '%s' Succeed", + cnt->conf.database_dbname); + } + + } else if (PQresultStatus(res) != PGRES_COMMAND_OK) { + MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, "%s: PGSQL query [%s] failed", sqlquery); PQclear(res); - } + } } #endif /* HAVE_PGSQL */ diff --git a/motion-dist.conf.in b/motion-dist.conf.in index d132c0e..2946805 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -71,9 +71,9 @@ v4l2_palette 17 # This is ONLY used for FreeBSD. Leave it commented out for Linux ; tunerdevice /dev/tuner0 -# The video input to be used (default: 8) -# Should normally be set to 0 or 1 for video/TV cards, and 8 for USB cameras -input 8 +# The video input to be used (default: -1) +# Should normally be set to 0 or 1 for video/TV cards, and -1 for USB cameras +input -1 # The video norm to use (only for video capture and TV tuner cards) # Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL) @@ -649,6 +649,14 @@ quiet on # %n = the number representing the file_type # %f = filename with full path # Default value: +# Create tables : +## +# Mysql +# CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), event_time_stamp timestamp(14)); +# +# Postgresql +# CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp without time zone, event_time_stamp timestamp without time zone); +# # insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C') ; sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C') diff --git a/motion.1 b/motion.1 index 9559ed7..26f09af 100644 --- a/motion.1 +++ b/motion.1 @@ -181,9 +181,9 @@ Values: 0 - 255 / Default: 0 (disabled) The hue level for the video device. .TP .B input integer -Values: 0 - 7, 8 = disabled / Default: 8 (disabled) +Values: -1 - 64, -1 = disabled / Default: -1 (disabled) .br -Input channel to use expressed as an integer number starting from 0. Should normally be set to 1 for video/TV cards, and 8 for USB cameras. +Input channel to use expressed as an integer number starting from -1. Should normally be set to 1 for video/TV cards, and -1 for USB cameras. .TP .B ipv6_enabled boolean Values: on, off / Default: off diff --git a/motion.c b/motion.c index 6399435..1182c2f 100644 --- a/motion.c +++ b/motion.c @@ -1055,7 +1055,9 @@ static void motion_cleanup(struct context *cnt) #endif /* HAVE_MYSQL */ #ifdef HAVE_PGSQL - + if ((!strcmp(cnt->conf.database_type, "postgresql")) && (cnt->conf.database_dbname)) { + PQfinish(cnt->database_pg); + } #endif /* HAVE_PGSQL */ #ifdef HAVE_SQLITE3 diff --git a/thread1.conf.in b/thread1.conf.in index 46ca13e..f6d5fe8 100644 --- a/thread1.conf.in +++ b/thread1.conf.in @@ -12,9 +12,9 @@ # for FreeBSD default is /dev/bktr0 videodevice /dev/video0 -# The video input to be used (default: 8) -# Should normally be set to 1 for video/TV cards, and 8 for USB cameras -input 8 +# The video input to be used (default: -1) +# Should normally be set to 1 for video/TV cards, and -1 for USB cameras +input -1 # Draw a user defined text on the images using same options as C function strftime(3) # Default: Not defined = no text diff --git a/thread2.conf.in b/thread2.conf.in index e552391..d0b8b2a 100644 --- a/thread2.conf.in +++ b/thread2.conf.in @@ -12,8 +12,8 @@ # for FreeBSD default is /dev/bktr0 videodevice /dev/video1 -# The video input to be used (default: 8) -# Should normally be set to 1 for video/TV cards, and 8 for USB cameras +# The video input to be used (default: -1) +# Should normally be set to 1 for video/TV cards, and -1 for USB cameras input 1 # Draw a user defined text on the images using same options as C function strftime(3) diff --git a/thread3.conf.in b/thread3.conf.in index 6138ab7..2192805 100644 --- a/thread3.conf.in +++ b/thread3.conf.in @@ -12,9 +12,9 @@ # for FreeBSD default is /dev/bktr0 videodevice /dev/video2 -# The video input to be used (default: 8) -# Should normally be set to 1 for video/TV cards, and 8 for USB cameras -input 8 +# The video input to be used (default: -1) +# Should normally be set to 1 for video/TV cards, and -1 for USB cameras +input -1 # Draw a user defined text on the images using same options as C function strftime(3) # Default: Not defined = no text diff --git a/video2.c b/video2.c index 4dbcb1a..f413b14 100644 --- a/video2.c +++ b/video2.c @@ -252,10 +252,6 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, struct v4l2_standard standard; v4l2_std_id std_id; - /*if (in == IN_DEFAULT) - in = IN_TV; - */ - /* Set the input. */ memset(&input, 0, sizeof (input)); if (in == IN_DEFAULT)