"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "event.c" between
motion-release-4.2.2.tar.gz and motion-Release-4.3.0.tar.gz

About: Motion monitors the video signal from one or more cameras and is able to detect motion.

event.c  (motion-release-4.2.2):event.c  (motion-Release-4.3.0)
skipping to change at line 18 skipping to change at line 18
see also the file 'COPYING'. see also the file 'COPYING'.
*/ */
#include "picture.h" /* already includes motion.h */ #include "picture.h" /* already includes motion.h */
#include "translate.h" #include "translate.h"
#include "netcam_rtsp.h" #include "netcam_rtsp.h"
#include "ffmpeg.h" #include "ffmpeg.h"
#include "event.h" #include "event.h"
#include "video_loopback.h" #include "video_loopback.h"
#include "video_common.h" #include "video_common.h"
/* Various functions (most doing the actual action) */ /* Various functions (most doing the actual action)
* TODO Items:
* Rework the snprintf uses.
* Edit directories so they can never be null and eliminate defaults from here
* Move the ffmpeg initialize stuff to ffmpeg module
* eliminate #if for v4l2
* Eliminate #IF for database items
* Move database functions out of here.
* Move stream stuff to webu_stream
* Use (void) alternative for ATTRIBUTE_UNUSED
*/
const char *eventList[] = { const char *eventList[] = {
"NULL", "NULL",
"EVENT_FILECREATE", "EVENT_FILECREATE",
"EVENT_MOTION", "EVENT_MOTION",
"EVENT_FIRSTMOTION", "EVENT_FIRSTMOTION",
"EVENT_ENDMOTION", "EVENT_ENDMOTION",
"EVENT_STOP", "EVENT_STOP",
"EVENT_TIMELAPSE", "EVENT_TIMELAPSE",
"EVENT_TIMELAPSEEND", "EVENT_TIMELAPSEEND",
skipping to change at line 154 skipping to change at line 164
static void on_motion_detected_command(struct context *cnt, static void on_motion_detected_command(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *dummy1 ATTRIBUTE_UNUSED, struct image_data *dummy1 ATTRIBUTE_UNUSED,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED, char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED) struct timeval *tv1 ATTRIBUTE_UNUSED)
{ {
if (cnt->conf.on_motion_detected) if (cnt->conf.on_motion_detected)
exec_command(cnt, cnt->conf.on_motion_detected, NULL, 0); exec_command(cnt, cnt->conf.on_motion_detected, NULL, 0);
} }
#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || defin ed(HAVE_MARIADB)
static void do_sql_query(char *sqlquery, struct context *cnt, int save_id) static void do_sql_query(char *sqlquery, struct context *cnt, int save_id)
{ {
if (strlen(sqlquery) <= 0) { if (strlen(sqlquery) <= 0) {
/* don't try to execute empty queries */ /* don't try to execute empty queries */
MOTION_LOG(WRN, TYPE_DB, NO_ERRNO, "Ignoring empty sql query"); MOTION_LOG(WRN, TYPE_DB, NO_ERRNO, _("Ignoring empty sql query"));
return; return;
} }
#ifdef HAVE_MYSQL #if defined(HAVE_MYSQL) || defined(HAVE_MARIADB)
if (!strcmp(cnt->conf.database_type, "mysql")) { if (!strcmp(cnt->conf.database_type, "mysql")) {
MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, "Executing mysql query"); MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, _("Executing mysql query"));
if (mysql_query(cnt->database, sqlquery) != 0) { if (mysql_query(cnt->database, sqlquery) != 0) {
int error_code = mysql_errno(cnt->database); int error_code = mysql_errno(cnt->database);
MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO
,_("Mysql query failed %s error code %d") ,_("Mysql query failed %s error code %d")
,mysql_error(cnt->database), error_code); ,mysql_error(cnt->database), error_code);
/* Try to reconnect ONCE if fails continue and discard this sql quer y */ /* Try to reconnect ONCE if fails continue and discard this sql quer y */
if (error_code >= 2000) { if (error_code >= 2000) {
// Close connection before start a new connection // Close connection before start a new connection
mysql_close(cnt->database); mysql_close(cnt->database);
skipping to change at line 208 skipping to change at line 218
,_("after re-connection Mysql query failed %s error code %d") ,_("after re-connection Mysql query failed %s error code %d")
,mysql_error(cnt->database), error_my); ,mysql_error(cnt->database), error_my);
} }
} }
} }
} }
if (save_id) { if (save_id) {
cnt->database_event_id = (unsigned long long) mysql_insert_id(cnt->d atabase); cnt->database_event_id = (unsigned long long) mysql_insert_id(cnt->d atabase);
} }
} }
#endif /* HAVE_MYSQL */ #endif /* HAVE_MYSQL HAVE_MARIADB*/
#ifdef HAVE_PGSQL #ifdef HAVE_PGSQL
if (!strcmp(cnt->conf.database_type, "postgresql")) { if (!strcmp(cnt->conf.database_type, "postgresql")) {
MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, "Executing postgresql query"); MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, _("Executing postgresql query"));
PGresult *res; PGresult *res;
res = PQexec(cnt->database_pg, sqlquery); res = PQexec(cnt->database_pg, sqlquery);
if (PQstatus(cnt->database_pg) == CONNECTION_BAD) { if (PQstatus(cnt->database_pg) == CONNECTION_BAD) {
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO MOTION_LOG(ERR, TYPE_DB, NO_ERRNO
,_("Connection to PostgreSQL database '%s' failed: %s") ,_("Connection to PostgreSQL database '%s' failed: %s")
,cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); ,cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg));
skipping to change at line 238 skipping to change at line 248
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO MOTION_LOG(ERR, TYPE_DB, NO_ERRNO
,_("Re-Connection to PostgreSQL database '%s' failed: %s") ,_("Re-Connection to PostgreSQL database '%s' failed: %s")
,cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg) ); ,cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg) );
} else { } else {
MOTION_LOG(INF, TYPE_DB, NO_ERRNO MOTION_LOG(INF, TYPE_DB, NO_ERRNO
,_("Re-Connection to PostgreSQL database '%s' Succeed") ,_("Re-Connection to PostgreSQL database '%s' Succeed")
,cnt->conf.database_dbname); ,cnt->conf.database_dbname);
} }
} else if (!(PQresultStatus(res) == PGRES_COMMAND_OK || PQresultStatus(r es) == PGRES_TUPLES_OK)) { } else if (!(PQresultStatus(res) == PGRES_COMMAND_OK || PQresultStatus(r es) == PGRES_TUPLES_OK)) {
MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, "PGSQL query failed: [%s] %s % s", MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, _("PGSQL query failed: [%s] %s %s"),
sqlquery, PQresStatus(PQresultStatus(res)), PQresultError Message(res)); sqlquery, PQresStatus(PQresultStatus(res)), PQresultError Message(res));
} }
if (save_id) { if (save_id) {
//ToDO: Find the equivalent option for pgsql //ToDO: Find the equivalent option for pgsql
cnt->database_event_id = 0; cnt->database_event_id = 0;
} }
PQclear(res); PQclear(res);
} }
#endif /* HAVE_PGSQL */ #endif /* HAVE_PGSQL */
#ifdef HAVE_SQLITE3 #ifdef HAVE_SQLITE3
if ((!strcmp(cnt->conf.database_type, "sqlite3")) && (cnt->conf.database_dbn ame)) { if ((!strcmp(cnt->conf.database_type, "sqlite3")) && (cnt->conf.database_dbn ame)) {
int res; int res;
char *errmsg = 0; char *errmsg = 0;
MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, "Executing sqlite query"); MOTION_LOG(DBG, TYPE_DB, NO_ERRNO, _("Executing sqlite query"));
res = sqlite3_exec(cnt->database_sqlite3, sqlquery, NULL, 0, &errmsg); res = sqlite3_exec(cnt->database_sqlite3, sqlquery, NULL, 0, &errmsg);
if (res != SQLITE_OK ) { if (res != SQLITE_OK ) {
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, _("SQLite error was %s"), errmsg) ; MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, _("SQLite error was %s"), errmsg) ;
sqlite3_free(errmsg); sqlite3_free(errmsg);
} }
if (save_id) { if (save_id) {
//ToDO: Find the equivalent option for sqlite3 //ToDO: Find the equivalent option for sqlite3
cnt->database_event_id = 0; cnt->database_event_id = 0;
} }
skipping to change at line 341 skipping to change at line 351
{ {
char sqlquery[PATH_MAX]; char sqlquery[PATH_MAX];
mystrftime(cnt, sqlquery, sizeof(sqlquery), cnt->conf.sql_query_stop, mystrftime(cnt, sqlquery, sizeof(sqlquery), cnt->conf.sql_query_stop,
currenttime_tv, filename, sqltype); currenttime_tv, filename, sqltype);
do_sql_query(sqlquery, cnt, 0); do_sql_query(sqlquery, cnt, 0);
} }
} }
#endif /* defined HAVE_MYSQL || defined HAVE_PGSQL || defined(HAVE_SQLITE3) */ #endif /* defined HAVE_MYSQL || defined HAVE_PGSQL || defined(HAVE_SQLITE3) || d efined(HAVE_MARIADB) */
static void on_area_command(struct context *cnt, static void on_area_command(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *dummy1 ATTRIBUTE_UNUSED, struct image_data *dummy1 ATTRIBUTE_UNUSED,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED, char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED) struct timeval *tv1 ATTRIBUTE_UNUSED)
{ {
if (cnt->conf.on_area_detected) if (cnt->conf.on_area_detected)
exec_command(cnt, cnt->conf.on_area_detected, NULL, 0); exec_command(cnt, cnt->conf.on_area_detected, NULL, 0);
} }
skipping to change at line 428 skipping to change at line 438
,cnt->imgs.substream_image); ,cnt->imgs.substream_image);
cnt->stream_sub.jpeg_size = put_picture_memory(cnt cnt->stream_sub.jpeg_size = put_picture_memory(cnt
,cnt->stream_sub.jpeg_data ,cnt->stream_sub.jpeg_data
,subsize ,subsize
,cnt->imgs.substream_image ,cnt->imgs.substream_image
,cnt->conf.stream_quality ,cnt->conf.stream_quality
,(cnt->imgs.width / 2) ,(cnt->imgs.width / 2)
,(cnt->imgs.height / 2)); ,(cnt->imgs.height / 2));
} else { } else {
/* Substream was not multiple of 8 so send full image*/ /* Substream was not multiple of 8 so send full image*/
cnt->stream_norm.jpeg_size = put_picture_memory(cnt cnt->stream_sub.jpeg_size = put_picture_memory(cnt
,cnt->stream_norm.jpeg_data ,cnt->stream_sub.jpeg_data
,cnt->imgs.size_norm ,cnt->imgs.size_norm
,img_data->image_norm ,img_data->image_norm
,cnt->conf.stream_quality ,cnt->conf.stream_quality
,cnt->imgs.width ,cnt->imgs.width
,cnt->imgs.height); ,cnt->imgs.height);
} }
} }
} }
/* Motion stream processing */ /* Motion stream processing */
skipping to change at line 474 skipping to change at line 484
,cnt->imgs.image_virgin.image_norm ,cnt->imgs.image_virgin.image_norm
,cnt->conf.stream_quality ,cnt->conf.stream_quality
,cnt->imgs.width ,cnt->imgs.width
,cnt->imgs.height); ,cnt->imgs.height);
} }
} }
pthread_mutex_unlock(&cnt->mutex_stream); pthread_mutex_unlock(&cnt->mutex_stream);
} }
} }
#if defined(HAVE_V4L2) && !defined(__FreeBSD__) #if defined(HAVE_V4L2) && !defined(BSD)
static void event_vlp_putpipe(struct context *cnt, static void event_vlp_putpipe(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *img_data, char *dummy ATTRIBUTE_UNUSED, void *dev pipe, struct image_data *img_data, char *dummy ATTRIBUTE_UNUSED, void *dev pipe,
struct timeval *tv1 ATTRIBUTE_UNUSED) struct timeval *tv1 ATTRIBUTE_UNUSED)
{ {
if (*(int *)devpipe >= 0) { if (*(int *)devpipe >= 0) {
if (vlp_putpipe(*(int *)devpipe, img_data->image_norm, cnt->imgs.size_no rm) == -1) if (vlp_putpipe(*(int *)devpipe, img_data->image_norm, cnt->imgs.size_no rm) == -1)
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Failed to put image into video pipe")); ,_("Failed to put image into video pipe"));
} }
} }
#endif /* defined(HAVE_V4L2) && !__FreeBSD__ */ #endif /* defined(HAVE_V4L2) && !defined(BSD) */
const char *imageext(struct context *cnt) const char *imageext(struct context *cnt)
{ {
if (cnt->imgs.picture_type == IMAGE_TYPE_PPM) if (cnt->imgs.picture_type == IMAGE_TYPE_PPM)
return "ppm"; return "ppm";
if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP) if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP)
return "webp"; return "webp";
return "jpg"; return "jpg";
skipping to change at line 611 skipping to change at line 621
mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tv, NU LL, 0); mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tv, NU LL, 0);
snprintf(filename, PATH_MAX, "%.*s.%s" snprintf(filename, PATH_MAX, "%.*s.%s"
, (int)(PATH_MAX-1-strlen(filepath)-strlen(imageext(cnt))) , (int)(PATH_MAX-1-strlen(filepath)-strlen(imageext(cnt)))
, filepath, imageext(cnt)); , filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s" snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
, (int)(PATH_MAX-1-strlen(filename)) , (int)(PATH_MAX-1-strlen(filename))
, cnt->conf.target_dir , cnt->conf.target_dir
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir)) , (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
, filename); , filename);
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHO T); put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHO T);
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, cu rrenttime_tv); event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE_SNA PSHOT, currenttime_tv);
/* /*
* Update symbolic link *after* image has been written so that * Update symbolic link *after* image has been written so that
* the link always points to a valid file. * the link always points to a valid file.
*/ */
snprintf(linkpath, PATH_MAX, "%.*s/lastsnap.%s" snprintf(linkpath, PATH_MAX, "%.*s/lastsnap.%s"
, (int)(PATH_MAX-strlen("/lastsnap.")-strlen(imageext(cnt))) , (int)(PATH_MAX-strlen("/lastsnap.")-strlen(imageext(cnt)))
, cnt->conf.target_dir, imageext(cnt)); , cnt->conf.target_dir, imageext(cnt));
remove(linkpath); remove(linkpath);
skipping to change at line 640 skipping to change at line 650
snprintf(filename, PATH_MAX, "%.*s.%s" snprintf(filename, PATH_MAX, "%.*s.%s"
, (int)(PATH_MAX-1-strlen(imageext(cnt))) , (int)(PATH_MAX-1-strlen(imageext(cnt)))
, filepath, imageext(cnt)); , filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s" snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
, (int)(PATH_MAX-1-strlen(filename)) , (int)(PATH_MAX-1-strlen(filename))
, cnt->conf.target_dir , cnt->conf.target_dir
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir)) , (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
, filename); , filename);
remove(fullfilename); remove(fullfilename);
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHO T); put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHO T);
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, cu rrenttime_tv); event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE_SNA PSHOT, currenttime_tv);
} }
cnt->snapshot = 0; cnt->snapshot = 0;
} }
/** /**
* event_image_preview * event_image_preview
* event_image_preview * event_image_preview
* *
* Returns nothing. * Returns nothing.
*/ */
static void event_image_preview(struct context *cnt, static void event_image_preview(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *img_data ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE _UNUSED, struct image_data *img_data ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE _UNUSED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv) void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv)
{ {
int use_imagepath; int use_imagepath;
int basename_len;
const char *imagepath; const char *imagepath;
char previewname[PATH_MAX]; char previewname[PATH_MAX];
char filename[PATH_MAX]; char filename[PATH_MAX];
struct image_data *saved_current_image; struct image_data *saved_current_image;
int passthrough; int passthrough, retcd;
if (cnt->imgs.preview_image.diffs) { if (cnt->imgs.preview_image.diffs) {
/* Save current global context. */
saved_current_image = cnt->current_image; saved_current_image = cnt->current_image;
/* Set global context to the image we are processing. */
cnt->current_image = &cnt->imgs.preview_image; cnt->current_image = &cnt->imgs.preview_image;
/* Use filename of movie i.o. jpeg_filename when set to 'preview'. */ /* Use filename of movie i.o. jpeg_filename when set to 'preview'. */
use_imagepath = strcmp(cnt->conf.picture_filename, "preview"); use_imagepath = strcmp(cnt->conf.picture_filename, "preview");
if ((cnt->ffmpeg_output || (cnt->conf.movie_extpipe_use && cnt->extpipe) ) && !use_imagepath) { if ((cnt->ffmpeg_output || (cnt->conf.movie_extpipe_use && cnt->extpipe) ) && !use_imagepath) {
if (cnt->conf.movie_extpipe_use && cnt->extpipe) { if (cnt->conf.movie_extpipe_use && cnt->extpipe) {
basename_len = strlen(cnt->extpipefilename) + 1; retcd = snprintf(previewname, PATH_MAX,"%s.%s"
strncpy(previewname, cnt->extpipefilename, basename_len); , cnt->extpipefilename, imageext(cnt));
previewname[basename_len - 1] = '.'; if ((retcd < 0) || (retcd >= PATH_MAX)) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("Error creating preview pipe name %d %s")
,retcd, previewname);
return;
}
} else { } else {
/* Replace avi/mpg with jpg/ppm and keep the rest of the filenam e. */ /* Replace avi/mpg with jpg/ppm and keep the rest of the filenam e. */
basename_len = strlen(cnt->newfilename) - 3; /* TODO: Hope that extensions are always 3 bytes*/
strncpy(previewname, cnt->newfilename, basename_len); /* -2 to allow for null terminating byte*/
retcd = snprintf(filename, strlen(cnt->newfilename) - 2
,"%s", cnt->newfilename);
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("Error creating file name base %d %s")
,retcd, filename);
return;
}
retcd = snprintf(previewname, PATH_MAX
,"%s%s", filename, imageext(cnt));
if ((retcd < 0) || (retcd >= PATH_MAX)) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("Error creating preview name %d %s")
, retcd, previewname);
return;
}
} }
previewname[basename_len] = '\0';
strcat(previewname, imageext(cnt));
passthrough = util_check_passthrough(cnt); passthrough = util_check_passthrough(cnt);
if ((cnt->imgs.size_high > 0) && (!passthrough)) { if ((cnt->imgs.size_high > 0) && (!passthrough)) {
put_picture(cnt, previewname, cnt->imgs.preview_image.image_high , FTYPE_IMAGE); put_picture(cnt, previewname, cnt->imgs.preview_image.image_high , FTYPE_IMAGE);
} else { } else {
put_picture(cnt, previewname, cnt->imgs.preview_image.image_norm , FTYPE_IMAGE); put_picture(cnt, previewname, cnt->imgs.preview_image.image_norm , FTYPE_IMAGE);
} }
event(cnt, EVENT_FILECREATE, NULL, previewname, (void *)FTYPE_IMAGE, currenttime_tv); event(cnt, EVENT_FILECREATE, NULL, previewname, (void *)FTYPE_IMAGE, currenttime_tv);
} else { } else {
/* /*
* Save best preview-shot also when no movies are recorded or imagep ath * Save best preview-shot also when no movies are recorded or imagep ath
skipping to change at line 771 skipping to change at line 797
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED, struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv) void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv)
{ {
if (cnt->extpipe_open) { if (cnt->extpipe_open) {
cnt->extpipe_open = 0; cnt->extpipe_open = 0;
fflush(cnt->extpipe); fflush(cnt->extpipe);
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO
,_("CLOSING: extpipe file desc %d, error state %d") ,_("CLOSING: extpipe file desc %d, error state %d")
,fileno(cnt->extpipe), ferror(cnt->extpipe)); ,fileno(cnt->extpipe), ferror(cnt->extpipe));
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "pclose return: %d", MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("pclose return: %d"),
pclose(cnt->extpipe)); pclose(cnt->extpipe));
event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MP EG, currenttime_tv); event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MP EG, currenttime_tv);
} }
} }
static void event_create_extpipe(struct context *cnt, static void event_create_extpipe(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED, struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv) void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv)
{ {
int retcd;
if ((cnt->conf.movie_extpipe_use) && (cnt->conf.movie_extpipe)) { if ((cnt->conf.movie_extpipe_use) && (cnt->conf.movie_extpipe)) {
char stamp[PATH_MAX] = ""; char stamp[PATH_MAX] = "";
const char *moviepath; const char *moviepath;
/* /*
* conf.mpegpath would normally be defined but if someone deleted it by control interface * conf.mpegpath would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail * it is better to revert to the default than fail
*/ */
if (cnt->conf.movie_filename) { if (cnt->conf.movie_filename) {
moviepath = cnt->conf.movie_filename; moviepath = cnt->conf.movie_filename;
skipping to change at line 830 skipping to change at line 858
return ; return ;
} }
} }
/* Always create any path specified as file name */ /* Always create any path specified as file name */
if (create_path(cnt->extpipefilename) == -1) if (create_path(cnt->extpipefilename) == -1)
return ; return ;
mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.movie_extpipe, currentti me_tv, cnt->extpipefilename, 0); mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.movie_extpipe, currentti me_tv, cnt->extpipefilename, 0);
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("pipe: %s"), stamp); retcd = snprintf(cnt->extpipecmdline, PATH_MAX, "%s", stamp);
if ((retcd < 0 ) || (retcd >= PATH_MAX)){
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
, _("Error specifying command line: %s"), cnt->extpipecmdline);
return;
}
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("pipe: %s"), cnt->extpipecmdlin
e);
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "cnt->moviefps: %d", cnt->movie_f ps); MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("cnt->moviefps: %d"), cnt->movi e_fps);
event(cnt, EVENT_FILECREATE, NULL, cnt->extpipefilename, (void *)FTYPE_M PEG, currenttime_tv); event(cnt, EVENT_FILECREATE, NULL, cnt->extpipefilename, (void *)FTYPE_M PEG, currenttime_tv);
cnt->extpipe = popen(stamp, "we"); cnt->extpipe = popen(cnt->extpipecmdline, "we");
if (cnt->extpipe == NULL) { if (cnt->extpipe == NULL) {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, _("popen failed")); MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, _("popen failed"));
return; return;
} }
setbuf(cnt->extpipe, NULL); setbuf(cnt->extpipe, NULL);
cnt->extpipe_open = 1; cnt->extpipe_open = 1;
} }
} }
skipping to change at line 871 skipping to change at line 905
if (!fwrite(img_data->image_high, cnt->imgs.size_high, 1, cnt->e xtpipe)) if (!fwrite(img_data->image_high, cnt->imgs.size_high, 1, cnt->e xtpipe))
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Error writing in pipe , state error %d"), ferror(cnt ->extpipe)); ,_("Error writing in pipe , state error %d"), ferror(cnt ->extpipe));
} else { } else {
if (!fwrite(img_data->image_norm, cnt->imgs.size_norm, 1, cnt->e xtpipe)) if (!fwrite(img_data->image_norm, cnt->imgs.size_norm, 1, cnt->e xtpipe))
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Error writing in pipe , state error %d"), ferror(cnt ->extpipe)); ,_("Error writing in pipe , state error %d"), ferror(cnt ->extpipe));
} }
} else { } else {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("pipe %s not created or closed already "), cnt->conf.movie_ex tpipe); ,_("pipe %s not created or closed already "), cnt->extpipecmdlin e);
} }
} }
} }
static void event_new_video(struct context *cnt, static void event_new_video(struct context *cnt,
motion_event type ATTRIBUTE_UNUSED, motion_event type ATTRIBUTE_UNUSED,
struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED, struct image_data *dummy ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UN USED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *tv1 ATTRIBUTE_UNUSED) void *dummy2 ATTRIBUTE_UNUSED, struct timeval *tv1 ATTRIBUTE_UNUSED)
{ {
cnt->movie_last_shot = -1; cnt->movie_last_shot = -1;
skipping to change at line 934 skipping to change at line 968
* that Motion permits. The container type is pre-pended to the name of the * that Motion permits. The container type is pre-pended to the name of the
* file so that we can determine which container type created what movie. * file so that we can determine which container type created what movie.
* The intent for this is be used for developer testing when the ffmpeg lib s * The intent for this is be used for developer testing when the ffmpeg lib s
* change or the code inside our ffmpeg module changes. For each event, th e * change or the code inside our ffmpeg module changes. For each event, th e
* container type will change. This way, you can turn on emulate motion, t hen * container type will change. This way, you can turn on emulate motion, t hen
* specify a maximum movie time and let Motion run for days creating all th e * specify a maximum movie time and let Motion run for days creating all th e
* different types of movies checking for crashes, warnings, etc. * different types of movies checking for crashes, warnings, etc.
*/ */
codec = cnt->conf.movie_codec; codec = cnt->conf.movie_codec;
if (strcmp(codec, "ogg") == 0) { if (strcmp(codec, "ogg") == 0) {
MOTION_LOG(WRN, TYPE_ENCODER, NO_ERRNO, "The ogg container is no longer supported. Changing to mpeg4"); MOTION_LOG(WRN, TYPE_ENCODER, NO_ERRNO, _("The ogg container is no longe r supported. Changing to mpeg4"));
codec = "mpeg4"; codec = "mpeg4";
} }
if (strcmp(codec, "test") == 0) { if (strcmp(codec, "test") == 0) {
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "Running test of the various out put formats."); MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, _("Running test of the various o utput formats."));
codenbr = cnt->event_nr % 10; codenbr = cnt->event_nr % 10;
switch (codenbr) { switch (codenbr) {
case 1: case 1:
codec = "mpeg4"; codec = "mpeg4";
break; break;
case 2: case 2:
codec = "msmpeg4"; codec = "msmpeg4";
break; break;
case 3: case 3:
codec = "swf"; codec = "swf";
skipping to change at line 1233 skipping to change at line 1267
/* /*
* Starting point for all events * Starting point for all events
*/ */
struct event_handlers { struct event_handlers {
motion_event type; motion_event type;
event_handler handler; event_handler handler;
}; };
struct event_handlers event_handlers[] = { struct event_handlers event_handlers[] = {
#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || defin ed(HAVE_MARIADB)
{ {
EVENT_FILECREATE, EVENT_FILECREATE,
event_sqlnewfile event_sqlnewfile
}, },
#endif #endif
{ {
EVENT_FILECREATE, EVENT_FILECREATE,
on_picture_save_command on_picture_save_command
}, },
{ {
skipping to change at line 1259 skipping to change at line 1293
event_beep event_beep
}, },
{ {
EVENT_MOTION, EVENT_MOTION,
on_motion_detected_command on_motion_detected_command
}, },
{ {
EVENT_AREA_DETECTED, EVENT_AREA_DETECTED,
on_area_command on_area_command
}, },
#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || defin ed(HAVE_MARIADB)
{ {
EVENT_FIRSTMOTION, EVENT_FIRSTMOTION,
event_sqlfirstmotion event_sqlfirstmotion
}, },
#endif #endif
{ {
EVENT_FIRSTMOTION, EVENT_FIRSTMOTION,
on_event_start_command on_event_start_command
}, },
{ {
skipping to change at line 1285 skipping to change at line 1319
event_image_detect event_image_detect
}, },
{ {
EVENT_IMAGEM_DETECTED, EVENT_IMAGEM_DETECTED,
event_imagem_detect event_imagem_detect
}, },
{ {
EVENT_IMAGE_SNAPSHOT, EVENT_IMAGE_SNAPSHOT,
event_image_snapshot event_image_snapshot
}, },
#if defined(HAVE_V4L2) && !defined(__FreeBSD__) #if defined(HAVE_V4L2) && !defined(BSD)
{ {
EVENT_IMAGE, EVENT_IMAGE,
event_vlp_putpipe event_vlp_putpipe
}, },
{ {
EVENT_IMAGEM, EVENT_IMAGEM,
event_vlp_putpipe event_vlp_putpipe
}, },
#endif /* defined(HAVE_V4L2) && !__FreeBSD__ */ #endif /* defined(HAVE_V4L2) && !defined(BSD) */
{ {
EVENT_IMAGE_PREVIEW, EVENT_IMAGE_PREVIEW,
event_image_preview event_image_preview
}, },
{ {
EVENT_STREAM, EVENT_STREAM,
event_stream_put event_stream_put
}, },
{ {
EVENT_FIRSTMOTION, EVENT_FIRSTMOTION,
skipping to change at line 1331 skipping to change at line 1365
event_ffmpeg_closefile event_ffmpeg_closefile
}, },
{ {
EVENT_TIMELAPSE, EVENT_TIMELAPSE,
event_ffmpeg_timelapse event_ffmpeg_timelapse
}, },
{ {
EVENT_TIMELAPSEEND, EVENT_TIMELAPSEEND,
event_ffmpeg_timelapseend event_ffmpeg_timelapseend
}, },
#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || defin ed(HAVE_MARIADB)
{ {
EVENT_FILECLOSE, EVENT_FILECLOSE,
event_sqlfileclose event_sqlfileclose
}, },
#endif #endif
{ {
EVENT_FILECLOSE, EVENT_FILECLOSE,
on_movie_end_command on_movie_end_command
}, },
{ {
 End of changes. 36 change blocks. 
40 lines changed or deleted 75 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)