Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 6f2526c

Browse files
committed
Use time from current_image for format
1 parent 7774f5d commit 6f2526c

6 files changed

Lines changed: 47 additions & 58 deletions

File tree

src/dbse.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,24 +1293,19 @@ void dbse_exec(ctx_dev *cam, char *filename, const char *cmd)
12931293

12941294
if (mystrceq(cmd,"pic_save")) {
12951295
mystrftime(cam, sqlquery, sizeof(sqlquery)
1296-
, cam->conf->sql_pic_save.c_str()
1297-
, &cam->current_image->imgts, filename);
1296+
, cam->conf->sql_pic_save.c_str(), filename);
12981297
} else if (mystrceq(cmd,"movie_start")) {
12991298
mystrftime(cam, sqlquery, sizeof(sqlquery)
1300-
, cam->conf->sql_movie_start.c_str()
1301-
, &cam->current_image->imgts, filename);
1299+
, cam->conf->sql_movie_start.c_str(), filename);
13021300
} else if (mystrceq(cmd,"movie_end")) {
13031301
mystrftime(cam, sqlquery, sizeof(sqlquery)
1304-
, cam->conf->sql_movie_end.c_str()
1305-
, &cam->current_image->imgts, filename);
1302+
, cam->conf->sql_movie_end.c_str(), filename);
13061303
} else if (mystrceq(cmd,"event_start")) {
13071304
mystrftime(cam, sqlquery, sizeof(sqlquery)
1308-
, cam->conf->sql_event_start.c_str()
1309-
, &cam->current_image->imgts, filename);
1305+
, cam->conf->sql_event_start.c_str(), filename);
13101306
} else if (mystrceq(cmd,"event_end")) {
13111307
mystrftime(cam, sqlquery, sizeof(sqlquery)
1312-
, cam->conf->sql_event_end.c_str()
1313-
, &cam->current_image->imgts, filename);
1308+
, cam->conf->sql_event_end.c_str(), filename);
13141309
}
13151310

13161311
if (strlen(sqlquery) <= 0) {

src/exif.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam,
205205

206206
if (cam->conf->picture_exif != "") {
207207
description =(char*) malloc(PATH_MAX);
208-
mystrftime(cam, description, PATH_MAX-1, cam->conf->picture_exif.c_str(), &ts1, NULL);
208+
mystrftime(cam, description, PATH_MAX-1, cam->conf->picture_exif.c_str(), NULL);
209209
} else {
210210
description = NULL;
211211
}

src/motion_loop.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,19 @@ static void mlp_ring_process_debug(ctx_dev *cam)
103103
char tmp[32];
104104
const char *t;
105105

106-
if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER) {
106+
if (cam->current_image->flags & IMAGE_TRIGGER) {
107107
t = "Trigger";
108-
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION) {
108+
} else if (cam->current_image->flags & IMAGE_MOTION) {
109109
t = "Motion";
110-
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP) {
110+
} else if (cam->current_image->flags & IMAGE_PRECAP) {
111111
t = "Precap";
112-
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP) {
112+
} else if (cam->current_image->flags & IMAGE_POSTCAP) {
113113
t = "Postcap";
114114
} else {
115115
t = "Other";
116116
}
117117

118-
mystrftime(cam, tmp, sizeof(tmp), "%H%M%S-%q",
119-
&cam->imgs.image_ring[cam->imgs.ring_out].imgts, NULL);
118+
mystrftime(cam, tmp, sizeof(tmp), "%H%M%S-%q", NULL);
120119
draw_text(cam->imgs.image_ring[cam->imgs.ring_out].image_norm,
121120
cam->imgs.width, cam->imgs.height, 10, 20, tmp, cam->text_scale);
122121
draw_text(cam->imgs.image_ring[cam->imgs.ring_out].image_norm,
@@ -202,8 +201,7 @@ static void mlp_detected_trigger(ctx_dev *cam)
202201

203202
mystrftime(cam, cam->text_event_string
204203
, sizeof(cam->text_event_string)
205-
, cam->conf->text_event.c_str()
206-
, &cam->current_image->imgts, NULL);
204+
, cam->conf->text_event.c_str(), NULL);
207205

208206
event(cam, EVENT_START);
209207
dbse_exec(cam, NULL, "event_start");
@@ -877,8 +875,8 @@ static int mlp_capture(ctx_dev *cam)
877875
}
878876

879877
memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm);
880-
mystrftime(cam, tmpout, sizeof(tmpout)
881-
, tmpin, &cam->connectionlosttime, NULL);
878+
cam->current_image->imgts =cam->connectionlosttime;
879+
mystrftime(cam, tmpout, sizeof(tmpout), tmpin, NULL);
882880
draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height,
883881
10, 20 * cam->text_scale, tmpout, cam->text_scale);
884882
cam->current_image->imgts = cam->connectionlosttime;
@@ -1011,16 +1009,14 @@ static void mlp_overlay(ctx_dev *cam)
10111009

10121010
/* Add text in lower left corner of the pictures */
10131011
if (cam->conf->text_left != "") {
1014-
mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_left.c_str(),
1015-
&cam->current_image->imgts, NULL);
1012+
mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_left.c_str(), NULL);
10161013
draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height,
10171014
10, cam->imgs.height - (10 * cam->text_scale), tmp, cam->text_scale);
10181015
}
10191016

10201017
/* Add text in lower right corner of the pictures */
10211018
if (cam->conf->text_right != "") {
1022-
mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_right.c_str(),
1023-
&cam->current_image->imgts, NULL);
1019+
mystrftime(cam, tmp, sizeof(tmp), cam->conf->text_right.c_str(), NULL);
10241020
draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height,
10251021
cam->imgs.width - 10, cam->imgs.height - (10 * cam->text_scale),
10261022
tmp, cam->text_scale);

src/movie.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,7 @@ int movie_init_norm(ctx_dev *cam)
15451545
cam->movie_norm =(ctx_movie*) mymalloc(sizeof(ctx_movie));
15461546

15471547
mystrftime(cam, tmp, sizeof(tmp)
1548-
, cam->conf->movie_filename.c_str()
1549-
, &cam->current_image->imgts, NULL);
1548+
, cam->conf->movie_filename.c_str(), NULL);
15501549

15511550
container = movie_init_container(cam);
15521551

@@ -1615,18 +1614,23 @@ int movie_init_motion(ctx_dev *cam)
16151614
{
16161615
char tmp[PATH_MAX];
16171616
const char *container;
1617+
ctx_image_data save_data;
16181618
int retcd, len;
16191619

16201620
cam->movie_motion =(ctx_movie*)mymalloc(sizeof(ctx_movie));
16211621

1622-
mystrftime(cam, tmp, sizeof(tmp)
1623-
, cam->conf->movie_filename.c_str()
1624-
, &cam->imgs.image_motion.imgts, NULL);
1622+
/* copy pointers and meta data to current image for use in format*/
1623+
memcpy(&save_data, cam->current_image, sizeof(ctx_image_data));
1624+
memcpy(cam->current_image, &cam->imgs.image_motion, sizeof(ctx_image_data));
1625+
mystrftime(cam, tmp, sizeof(tmp)
1626+
, cam->conf->movie_filename.c_str(), NULL);
1627+
memcpy(cam->current_image, &save_data, sizeof(ctx_image_data));
1628+
16251629
container = movie_init_container(cam);
16261630

16271631
/* The increment of 10 is to allow for the extension and other chars*/
16281632
len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10);
1629-
cam->movie_norm->full_nm = (char*)mymalloc(len);
1633+
cam->movie_motion->full_nm = (char*)mymalloc(len);
16301634
if (mystreq(container, "test")) {
16311635
retcd = snprintf(cam->movie_motion->full_nm, len, "%s/%s_%sm"
16321636
, cam->conf->target_dir.c_str(), container, tmp);
@@ -1636,13 +1640,13 @@ int movie_init_motion(ctx_dev *cam)
16361640
}
16371641

16381642
len = (int)cam->conf->target_dir.length() + 10;
1639-
cam->movie_norm->movie_dir = (char*)mymalloc(len);
1640-
retcd = snprintf(cam->movie_norm->movie_dir,len,"%s"
1643+
cam->movie_motion->movie_dir = (char*)mymalloc(len);
1644+
retcd = snprintf(cam->movie_motion->movie_dir,len,"%s"
16411645
,cam->conf->target_dir.c_str());
16421646

16431647
len = (int)strlen(tmp) + 10;
1644-
cam->movie_norm->movie_nm = (char*)mymalloc(len);
1645-
retcd = snprintf(cam->movie_norm->movie_nm, len, "%s", tmp);
1648+
cam->movie_motion->movie_nm = (char*)mymalloc(len);
1649+
retcd = snprintf(cam->movie_motion->movie_nm, len, "%s", tmp);
16461650

16471651
if (retcd < 0) {
16481652
MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO
@@ -1688,8 +1692,7 @@ int movie_init_timelapse(ctx_dev *cam)
16881692

16891693
cam->movie_timelapse =(ctx_movie*)mymalloc(sizeof(ctx_movie));
16901694
mystrftime(cam, tmp, sizeof(tmp)
1691-
, cam->conf->timelapse_filename.c_str()
1692-
, &cam->current_image->imgts, NULL);
1695+
, cam->conf->timelapse_filename.c_str(), NULL);
16931696

16941697
/* The increment of 10 is to allow for the extension and other chars*/
16951698
len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10);
@@ -1760,8 +1763,7 @@ int movie_init_extpipe(ctx_dev *cam)
17601763
char filename[PATH_MAX] = "";
17611764

17621765
mystrftime(cam, filename, sizeof(filename)
1763-
, cam->conf->movie_filename.c_str()
1764-
, &cam->current_image->imgts, NULL);
1766+
, cam->conf->movie_filename.c_str(), NULL);
17651767
if (cam->conf->movie_output) {
17661768
MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO
17671769
, _("Requested extpipe in addition to movie_output."));
@@ -1782,8 +1784,7 @@ int movie_init_extpipe(ctx_dev *cam)
17821784
}
17831785

17841786
mystrftime(cam, cam->extpipe_cmdline, sizeof(cam->extpipe_cmdline)
1785-
, cam->conf->movie_extpipe.c_str()
1786-
, &cam->current_image->imgts, cam->extpipe_filename);
1787+
, cam->conf->movie_extpipe.c_str(), cam->extpipe_filename);
17871788

17881789
MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO
17891790
, _("fps %d pipe cmd: %s")

src/util.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,24 +379,29 @@ static void mystrftime_long (const ctx_dev *cam,
379379
* s - destination string
380380
* max - max number of bytes to write
381381
* userformat - format string
382-
* tm - time information
383382
* filename - string containing full path of filename
384383
* set this to NULL if not relevant
385-
* sqltype - Filetype as used in SQL feature, set to 0 if not relevant
386384
*
387385
* Returns: number of bytes written to the string s
388386
*/
389-
size_t mystrftime(ctx_dev *cam, char *s, size_t max, const char *userformat,
390-
const struct timespec *ts1, const char *filename)
387+
size_t mystrftime(ctx_dev *cam, char *s, size_t max
388+
, const char *userformat, const char *filename)
391389
{
392390
char formatstring[PATH_MAX] = "";
393391
char tempstring[PATH_MAX] = "";
394392
char *format, *tempstr;
395393
const char *pos_userformat;
396394
int width;
397395
struct tm timestamp_tm;
396+
timespec ts1;
398397

399-
localtime_r(&ts1->tv_sec, &timestamp_tm);
398+
if (cam->current_image == NULL) {
399+
clock_gettime(CLOCK_REALTIME, &ts1);
400+
} else {
401+
ts1 = cam->current_image->imgts;
402+
}
403+
404+
localtime_r(&ts1.tv_sec, &timestamp_tm);
400405

401406
format = formatstring;
402407

@@ -565,7 +570,7 @@ void mypicname(ctx_dev *cam
565570
int retcd;
566571

567572
mystrftime(cam, filename, sizeof(filename)
568-
, basename.c_str(), &cam->current_image->imgts, NULL);
573+
, basename.c_str(), NULL);
569574
retcd = snprintf(fullname, PATH_MAX, fmtstr.c_str()
570575
, cam->conf->target_dir.c_str(), filename, extname.c_str());
571576
if ((retcd < 0) || (retcd >= PATH_MAX)) {
@@ -1297,17 +1302,9 @@ void util_parms_update(ctx_params *params, std::string &confline)
12971302
void util_exec_command(ctx_dev *cam, const char *command, char *filename)
12981303
{
12991304
char stamp[PATH_MAX];
1300-
timespec tmpts;
13011305
int pid;
13021306

1303-
if (cam->current_image == NULL) {
1304-
clock_gettime(CLOCK_REALTIME, &tmpts);
1305-
mystrftime(cam, stamp, sizeof(stamp), command
1306-
, &tmpts, filename);
1307-
} else {
1308-
mystrftime(cam, stamp, sizeof(stamp)
1309-
, command, &cam->current_image->imgts, filename);
1310-
}
1307+
mystrftime(cam, stamp, sizeof(stamp), command, filename);
13111308

13121309
pid = fork();
13131310
if (!pid) {

src/util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
int mycreate_path(const char *path);
107107
FILE *myfopen(const char *path, const char *mode);
108108
int myfclose(FILE *fh);
109-
size_t mystrftime(ctx_dev *cam, char *s, size_t max, const char *userformat,
110-
const struct timespec *ts1, const char *filename);
109+
size_t mystrftime(ctx_dev *cam, char *s, size_t max
110+
, const char *userformat, const char *filename);
111111
void mypicname(ctx_dev *cam
112112
, char* fullname, std::string fmtstr
113113
, std::string basename, std::string extname);

0 commit comments

Comments
 (0)