diff --git a/src/dbse.cpp b/src/dbse.cpp index 9451e9c3..549cf9b3 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -1293,24 +1293,19 @@ void dbse_exec(ctx_dev *cam, char *filename, const char *cmd) if (mystrceq(cmd,"pic_save")) { mystrftime(cam, sqlquery, sizeof(sqlquery) - , cam->conf->sql_pic_save.c_str() - , &cam->current_image->imgts, filename); + , cam->conf->sql_pic_save.c_str(), filename); } else if (mystrceq(cmd,"movie_start")) { mystrftime(cam, sqlquery, sizeof(sqlquery) - , cam->conf->sql_movie_start.c_str() - , &cam->current_image->imgts, filename); + , cam->conf->sql_movie_start.c_str(), filename); } else if (mystrceq(cmd,"movie_end")) { mystrftime(cam, sqlquery, sizeof(sqlquery) - , cam->conf->sql_movie_end.c_str() - , &cam->current_image->imgts, filename); + , cam->conf->sql_movie_end.c_str(), filename); } else if (mystrceq(cmd,"event_start")) { mystrftime(cam, sqlquery, sizeof(sqlquery) - , cam->conf->sql_event_start.c_str() - , &cam->current_image->imgts, filename); + , cam->conf->sql_event_start.c_str(), filename); } else if (mystrceq(cmd,"event_end")) { mystrftime(cam, sqlquery, sizeof(sqlquery) - , cam->conf->sql_event_end.c_str() - , &cam->current_image->imgts, filename); + , cam->conf->sql_event_end.c_str(), filename); } if (strlen(sqlquery) <= 0) { diff --git a/src/exif.cpp b/src/exif.cpp index bb2cd47a..fc9e8466 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -205,7 +205,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam, if (cam->conf->picture_exif != "") { description =(char*) malloc(PATH_MAX); - mystrftime(cam, description, PATH_MAX-1, cam->conf->picture_exif.c_str(), &ts1, NULL); + mystrftime(cam, description, PATH_MAX-1, cam->conf->picture_exif.c_str(), NULL); } else { description = NULL; } diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index c7145e73..0a3aeba6 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -103,20 +103,19 @@ static void mlp_ring_process_debug(ctx_dev *cam) char tmp[32]; const char *t; - if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER) { + if (cam->current_image->flags & IMAGE_TRIGGER) { t = "Trigger"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION) { + } else if (cam->current_image->flags & IMAGE_MOTION) { t = "Motion"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP) { + } else if (cam->current_image->flags & IMAGE_PRECAP) { t = "Precap"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP) { + } else if (cam->current_image->flags & IMAGE_POSTCAP) { t = "Postcap"; } else { t = "Other"; } - mystrftime(cam, tmp, sizeof(tmp), "%H%M%S-%q", - &cam->imgs.image_ring[cam->imgs.ring_out].imgts, NULL); + mystrftime(cam, tmp, sizeof(tmp), "%H%M%S-%q", NULL); draw_text(cam->imgs.image_ring[cam->imgs.ring_out].image_norm, cam->imgs.width, cam->imgs.height, 10, 20, tmp, cam->text_scale); draw_text(cam->imgs.image_ring[cam->imgs.ring_out].image_norm, @@ -202,8 +201,7 @@ static void mlp_detected_trigger(ctx_dev *cam) mystrftime(cam, cam->text_event_string , sizeof(cam->text_event_string) - , cam->conf->text_event.c_str() - , &cam->current_image->imgts, NULL); + , cam->conf->text_event.c_str(), NULL); event(cam, EVENT_START); dbse_exec(cam, NULL, "event_start"); @@ -877,8 +875,8 @@ static int mlp_capture(ctx_dev *cam) } memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm); - mystrftime(cam, tmpout, sizeof(tmpout) - , tmpin, &cam->connectionlosttime, NULL); + cam->current_image->imgts =cam->connectionlosttime; + mystrftime(cam, tmpout, sizeof(tmpout), tmpin, NULL); draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height, 10, 20 * cam->text_scale, tmpout, cam->text_scale); cam->current_image->imgts = cam->connectionlosttime; @@ -1011,16 +1009,14 @@ static void mlp_overlay(ctx_dev *cam) /* Add text in lower left corner of the pictures */ if (cam->conf->text_left != "") { - mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_left.c_str(), - &cam->current_image->imgts, NULL); + mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_left.c_str(), NULL); draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height, 10, cam->imgs.height - (10 * cam->text_scale), tmp, cam->text_scale); } /* Add text in lower right corner of the pictures */ if (cam->conf->text_right != "") { - mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_right.c_str(), - &cam->current_image->imgts, NULL); + mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_right.c_str(), NULL); draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height, cam->imgs.width - 10, cam->imgs.height - (10 * cam->text_scale), tmp, cam->text_scale); diff --git a/src/movie.cpp b/src/movie.cpp index 241d7d89..4f8e8fd0 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1545,8 +1545,7 @@ int movie_init_norm(ctx_dev *cam) cam->movie_norm =(ctx_movie*) mymalloc(sizeof(ctx_movie)); mystrftime(cam, tmp, sizeof(tmp) - , cam->conf->movie_filename.c_str() - , &cam->current_image->imgts, NULL); + , cam->conf->movie_filename.c_str(), NULL); container = movie_init_container(cam); @@ -1615,18 +1614,23 @@ int movie_init_motion(ctx_dev *cam) { char tmp[PATH_MAX]; const char *container; + ctx_image_data save_data; int retcd, len; cam->movie_motion =(ctx_movie*)mymalloc(sizeof(ctx_movie)); - mystrftime(cam, tmp, sizeof(tmp) - , cam->conf->movie_filename.c_str() - , &cam->imgs.image_motion.imgts, NULL); + /* copy pointers and meta data to current image for use in format*/ + memcpy(&save_data, cam->current_image, sizeof(ctx_image_data)); + memcpy(cam->current_image, &cam->imgs.image_motion, sizeof(ctx_image_data)); + mystrftime(cam, tmp, sizeof(tmp) + , cam->conf->movie_filename.c_str(), NULL); + memcpy(cam->current_image, &save_data, sizeof(ctx_image_data)); + container = movie_init_container(cam); /* The increment of 10 is to allow for the extension and other chars*/ len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10); - cam->movie_norm->full_nm = (char*)mymalloc(len); + cam->movie_motion->full_nm = (char*)mymalloc(len); if (mystreq(container, "test")) { retcd = snprintf(cam->movie_motion->full_nm, len, "%s/%s_%sm" , cam->conf->target_dir.c_str(), container, tmp); @@ -1636,13 +1640,13 @@ int movie_init_motion(ctx_dev *cam) } len = (int)cam->conf->target_dir.length() + 10; - cam->movie_norm->movie_dir = (char*)mymalloc(len); - retcd = snprintf(cam->movie_norm->movie_dir,len,"%s" + cam->movie_motion->movie_dir = (char*)mymalloc(len); + retcd = snprintf(cam->movie_motion->movie_dir,len,"%s" ,cam->conf->target_dir.c_str()); len = (int)strlen(tmp) + 10; - cam->movie_norm->movie_nm = (char*)mymalloc(len); - retcd = snprintf(cam->movie_norm->movie_nm, len, "%s", tmp); + cam->movie_motion->movie_nm = (char*)mymalloc(len); + retcd = snprintf(cam->movie_motion->movie_nm, len, "%s", tmp); if (retcd < 0) { MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO @@ -1688,8 +1692,7 @@ int movie_init_timelapse(ctx_dev *cam) cam->movie_timelapse =(ctx_movie*)mymalloc(sizeof(ctx_movie)); mystrftime(cam, tmp, sizeof(tmp) - , cam->conf->timelapse_filename.c_str() - , &cam->current_image->imgts, NULL); + , cam->conf->timelapse_filename.c_str(), NULL); /* The increment of 10 is to allow for the extension and other chars*/ len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10); @@ -1760,8 +1763,7 @@ int movie_init_extpipe(ctx_dev *cam) char filename[PATH_MAX] = ""; mystrftime(cam, filename, sizeof(filename) - , cam->conf->movie_filename.c_str() - , &cam->current_image->imgts, NULL); + , cam->conf->movie_filename.c_str(), NULL); if (cam->conf->movie_output) { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Requested extpipe in addition to movie_output.")); @@ -1782,8 +1784,7 @@ int movie_init_extpipe(ctx_dev *cam) } mystrftime(cam, cam->extpipe_cmdline, sizeof(cam->extpipe_cmdline) - , cam->conf->movie_extpipe.c_str() - , &cam->current_image->imgts, cam->extpipe_filename); + , cam->conf->movie_extpipe.c_str(), cam->extpipe_filename); MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO , _("fps %d pipe cmd: %s") diff --git a/src/util.cpp b/src/util.cpp index 4aaf0bfd..14de3096 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -379,15 +379,13 @@ static void mystrftime_long (const ctx_dev *cam, * s - destination string * max - max number of bytes to write * userformat - format string - * tm - time information * filename - string containing full path of filename * set this to NULL if not relevant - * sqltype - Filetype as used in SQL feature, set to 0 if not relevant * * Returns: number of bytes written to the string s */ -size_t mystrftime(ctx_dev *cam, char *s, size_t max, const char *userformat, - const struct timespec *ts1, const char *filename) +size_t mystrftime(ctx_dev *cam, char *s, size_t max + , const char *userformat, const char *filename) { char formatstring[PATH_MAX] = ""; char tempstring[PATH_MAX] = ""; @@ -395,8 +393,15 @@ size_t mystrftime(ctx_dev *cam, char *s, size_t max, const char *userformat, const char *pos_userformat; int width; struct tm timestamp_tm; + timespec ts1; - localtime_r(&ts1->tv_sec, ×tamp_tm); + if (cam->current_image == NULL) { + clock_gettime(CLOCK_REALTIME, &ts1); + } else { + ts1 = cam->current_image->imgts; + } + + localtime_r(&ts1.tv_sec, ×tamp_tm); format = formatstring; @@ -565,7 +570,7 @@ void mypicname(ctx_dev *cam int retcd; mystrftime(cam, filename, sizeof(filename) - , basename.c_str(), &cam->current_image->imgts, NULL); + , basename.c_str(), NULL); retcd = snprintf(fullname, PATH_MAX, fmtstr.c_str() , cam->conf->target_dir.c_str(), filename, extname.c_str()); if ((retcd < 0) || (retcd >= PATH_MAX)) { @@ -1297,17 +1302,9 @@ void util_parms_update(ctx_params *params, std::string &confline) void util_exec_command(ctx_dev *cam, const char *command, char *filename) { char stamp[PATH_MAX]; - timespec tmpts; int pid; - if (cam->current_image == NULL) { - clock_gettime(CLOCK_REALTIME, &tmpts); - mystrftime(cam, stamp, sizeof(stamp), command - , &tmpts, filename); - } else { - mystrftime(cam, stamp, sizeof(stamp) - , command, &cam->current_image->imgts, filename); - } + mystrftime(cam, stamp, sizeof(stamp), command, filename); pid = fork(); if (!pid) { diff --git a/src/util.hpp b/src/util.hpp index 6ef5c498..a6cab78b 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -106,8 +106,8 @@ int mycreate_path(const char *path); FILE *myfopen(const char *path, const char *mode); int myfclose(FILE *fh); - size_t mystrftime(ctx_dev *cam, char *s, size_t max, const char *userformat, - const struct timespec *ts1, const char *filename); + size_t mystrftime(ctx_dev *cam, char *s, size_t max + , const char *userformat, const char *filename); void mypicname(ctx_dev *cam , char* fullname, std::string fmtstr , std::string basename, std::string extname);