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

Commit de20f54

Browse files
committed
Move extpipe to movie module
1 parent dd99517 commit de20f54

4 files changed

Lines changed: 150 additions & 203 deletions

File tree

src/event.cpp

Lines changed: 66 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -374,149 +374,12 @@ static void event_camera_found(ctx_dev *cam, char *fname)
374374
}
375375
}
376376

377-
static void event_extpipe_end(ctx_dev *cam, char *fname)
378-
{
379-
int retcd;
380-
381-
(void)fname;
382-
383-
if (cam->extpipe_open) {
384-
MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO,_("Closing extpipe"));
385-
cam->extpipe_open = 0;
386-
fflush(cam->extpipe);
387-
pclose(cam->extpipe);
388-
389-
cam->filetype = FTYPE_MOVIE;
390-
if ((cam->conf->movie_retain == "secondary") && (cam->algsec_inuse)) {
391-
if (cam->algsec->isdetected == false) {
392-
retcd = remove(cam->extpipefilename);
393-
if (retcd != 0) {
394-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
395-
, _("Unable to remove file %s"), cam->extpipefilename);
396-
}
397-
} else {
398-
on_movie_end_command(cam, cam->extpipefilename);
399-
dbse_exec(cam, cam->extpipefilename, "movie_end");
400-
}
401-
} else {
402-
on_movie_end_command(cam, cam->extpipefilename);
403-
dbse_exec(cam, cam->extpipefilename, "movie_end");
404-
}
405-
cam->extpipe = NULL;
406-
}
407-
}
408-
409-
static void event_extpipe_start(ctx_dev *cam, char *fname)
410-
{
411-
int retcd;
412-
char stamp[PATH_MAX] = "";
413-
414-
(void)fname;
415-
416-
if ((cam->conf->movie_extpipe_use) && (cam->conf->movie_extpipe != "" )) {
417-
mystrftime(cam, stamp, sizeof(stamp)
418-
, cam->conf->movie_filename.c_str()
419-
, &cam->current_image->imgts, NULL, 0);
420-
retcd = snprintf(cam->extpipefilename, PATH_MAX - 4, "%s/%s"
421-
, cam->conf->target_dir.c_str(), stamp);
422-
if (retcd < 0) {
423-
MOTPLS_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error %d"), retcd);
424-
}
425-
426-
if (access(cam->conf->target_dir.c_str(), W_OK)!= 0) {
427-
/* Permission denied */
428-
if (errno == EACCES) {
429-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
430-
,_("no write access to target directory %s")
431-
, cam->conf->target_dir.c_str());
432-
return ;
433-
/* Path not found - create it */
434-
} else if (errno == ENOENT) {
435-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
436-
,_("path not found, trying to create it %s ...")
437-
, cam->conf->target_dir.c_str());
438-
if (mycreate_path(cam->extpipefilename) == -1) {
439-
return ;
440-
}
441-
}
442-
else {
443-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
444-
,_("error accesing path %s"), cam->conf->target_dir.c_str());
445-
return ;
446-
}
447-
}
448-
449-
/* Always create any path specified as file name */
450-
if (mycreate_path(cam->extpipefilename) == -1) {
451-
return ;
452-
}
453-
454-
mystrftime(cam, stamp, sizeof(stamp), cam->conf->movie_extpipe.c_str()
455-
, &cam->current_image->imgts, cam->extpipefilename, 0);
456-
457-
retcd = snprintf(cam->extpipecmdline, PATH_MAX, "%s", stamp);
458-
if ((retcd < 0 ) || (retcd >= PATH_MAX)) {
459-
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO
460-
, _("Error specifying command line: %s"), cam->extpipecmdline);
461-
return;
462-
}
463-
MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO
464-
, _("fps %d pipe: %s"), cam->movie_fps, cam->extpipecmdline);
465-
466-
cam->filetype = FTYPE_MOVIE;
467-
on_movie_start_command(cam, cam->extpipefilename);
468-
dbse_exec(cam, cam->extpipefilename, "movie_start");
469-
cam->extpipe = popen(cam->extpipecmdline, "we");
470-
471-
if (cam->extpipe == NULL) {
472-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, _("popen failed"));
473-
return;
474-
}
475-
476-
setbuf(cam->extpipe, NULL);
477-
cam->extpipe_open = 1;
478-
}
479-
}
480-
481-
static void event_extpipe_put(ctx_dev *cam, char *fname)
482-
{
483-
(void)fname;
484-
int passthrough;
485-
486-
/* Check use_extpipe enabled and ext_pipe not NULL */
487-
if ((cam->conf->movie_extpipe_use) &&
488-
(cam->extpipe != NULL) &&
489-
(cam->finish_dev == false)) {
490-
passthrough = mycheck_passthrough(cam);
491-
/* Check that is open */
492-
if ((cam->extpipe_open) && (fileno(cam->extpipe) > 0)) {
493-
if ((cam->imgs.size_high > 0) && (!passthrough)) {
494-
if (!fwrite(cam->current_image->image_high
495-
, cam->imgs.size_high, 1, cam->extpipe)) {
496-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
497-
,_("Error writing in pipe , state error %d"), ferror(cam->extpipe));
498-
}
499-
} else {
500-
if (!fwrite(cam->current_image->image_norm
501-
, cam->imgs.size_norm, 1, cam->extpipe)) {
502-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
503-
,_("Error writing in pipe , state error %d"), ferror(cam->extpipe));
504-
}
505-
}
506-
} else {
507-
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO
508-
,_("pipe %s not created or closed already "), cam->extpipecmdline);
509-
}
510-
}
511-
}
512-
513377
static void event_movie_start(ctx_dev *cam, char *fname)
514378
{
515379
int retcd;
516380

517381
(void)fname;
518382

519-
/* This will cascade to extpipe_start*/
520383
cam->movie_start_time = cam->frame_curr_ts.tv_sec;
521384

522385
if (cam->lastrate < 2) {
@@ -529,7 +392,7 @@ static void event_movie_start(ctx_dev *cam, char *fname)
529392
retcd = movie_init_norm(cam);
530393
if (retcd < 0) {
531394
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO
532-
,_("Error initializing movie output."));
395+
,_("Error initializing movie."));
533396
myfree(&cam->movie_norm);
534397
return;
535398
}
@@ -542,10 +405,25 @@ static void event_movie_start(ctx_dev *cam, char *fname)
542405
retcd = movie_init_motion(cam);
543406
if (retcd < 0) {
544407
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO
545-
,_("Error creating motion file [%s]"), cam->movie_motion->full_nm);
408+
,_("Error initializing motion movie"));
546409
myfree(&cam->movie_motion);
547410
return;
548411
}
412+
cam->filetype = FTYPE_MOVIE;
413+
on_movie_start_command(cam, cam->movie_motion->full_nm);
414+
dbse_exec(cam, cam->movie_motion->full_nm, "movie_start");
415+
}
416+
417+
if ((cam->conf->movie_extpipe_use) && (cam->conf->movie_extpipe != "" )) {
418+
retcd = movie_init_extpipe(cam);
419+
if (retcd < 0) {
420+
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO
421+
,_("Error initializing extpipe movie."));
422+
return;
423+
}
424+
cam->filetype = FTYPE_MOVIE;
425+
on_movie_start_command(cam, cam->extpipe_filename);
426+
dbse_exec(cam, cam->extpipe_filename, "movie_start");
549427
}
550428
}
551429

@@ -567,6 +445,13 @@ static void event_movie_put(ctx_dev *cam, char *fname)
567445
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO, _("Error encoding image"));
568446
}
569447
}
448+
449+
if (cam->extpipe_isopen) {
450+
if (movie_put_extpipe(cam) == -1) {
451+
MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO, _("Error encoding image"));
452+
}
453+
}
454+
570455
}
571456

572457
static void event_movie_end(ctx_dev *cam, char *fname)
@@ -575,60 +460,70 @@ static void event_movie_end(ctx_dev *cam, char *fname)
575460

576461
(void)fname;
577462

578-
579463
if (cam->movie_norm) {
580464
cam->filetype = FTYPE_MOVIE;
581-
if ((cam->conf->movie_retain == "secondary") && (cam->algsec_inuse)) {
582-
if (cam->algsec->isdetected == false) {
583-
retcd = remove(cam->movie_norm->full_nm);
584-
if (retcd != 0) {
585-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
586-
, _("Unable to remove file %s")
587-
, cam->movie_norm->full_nm);
588-
}
465+
on_movie_end_command(cam, cam->movie_norm->full_nm);
466+
dbse_exec(cam, cam->movie_norm->full_nm, "movie_end");
467+
if ((cam->conf->movie_retain == "secondary") &&
468+
(cam->algsec_inuse) && (cam->algsec->isdetected == false)) {
469+
if (remove(cam->movie_norm->full_nm) != 0) {
470+
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
471+
, _("Unable to remove file %s"), cam->movie_norm->full_nm);
589472
} else {
590-
on_movie_end_command(cam, cam->movie_norm->full_nm);
591-
dbse_exec(cam, cam->movie_norm->full_nm, "movie_end");
592473
dbse_movies_addrec(cam, cam->movie_norm
593474
, &cam->current_image->imgts);
594475
}
595476
} else {
596-
on_movie_end_command(cam, cam->movie_norm->full_nm);
597-
dbse_exec(cam, cam->movie_norm->full_nm, "movie_end");
598-
dbse_movies_addrec(cam, cam->movie_norm
599-
, &cam->current_image->imgts);
477+
dbse_movies_addrec(cam, cam->movie_norm, &cam->current_image->imgts);
600478
}
601479
movie_close(cam->movie_norm);
602480
myfree(&cam->movie_norm);
603-
604481
}
605482

606483
if (cam->movie_motion) {
607484
cam->filetype = FTYPE_MOVIE;
608-
if ((cam->conf->movie_retain == "secondary") && (cam->algsec_inuse)) {
609-
if (cam->algsec->isdetected == false) {
610-
retcd = remove(cam->movie_motion->full_nm);
611-
if (retcd != 0) {
612-
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
613-
, _("Unable to remove file %s")
614-
, cam->movie_motion->full_nm);
615-
}
485+
on_movie_end_command(cam, cam->movie_motion->full_nm);
486+
dbse_exec(cam, cam->movie_motion->full_nm, "movie_end");
487+
488+
if ((cam->conf->movie_retain == "secondary") &&
489+
(cam->algsec_inuse) && (cam->algsec->isdetected == false)) {
490+
if (remove(cam->movie_motion->full_nm) != 0) {
491+
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
492+
, _("Unable to remove file %s")
493+
, cam->movie_motion->full_nm);
616494
} else {
617-
on_movie_end_command(cam, cam->movie_motion->full_nm);
618-
dbse_exec(cam, cam->movie_motion->full_nm, "movie_end");
619-
dbse_movies_addrec(cam, cam->movie_motion
620-
, &cam->imgs.image_motion.imgts);
495+
dbse_movies_addrec(cam, cam->movie_motion, &cam->imgs.image_motion.imgts);
621496
}
622497
} else {
623-
on_movie_end_command(cam, cam->movie_motion->full_nm);
624-
dbse_exec(cam, cam->movie_motion->full_nm, "movie_end");
625-
dbse_movies_addrec(cam, cam->movie_motion
626-
, &cam->imgs.image_motion.imgts);
498+
dbse_movies_addrec(cam, cam->movie_motion, &cam->imgs.image_motion.imgts);
627499
}
628500
movie_close(cam->movie_motion);
629501
myfree(&cam->movie_motion);
630502
}
631503

504+
if (cam->extpipe_isopen) {
505+
MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO,_("Closing extpipe"));
506+
cam->extpipe_isopen = false;
507+
fflush(cam->extpipe_stream);
508+
pclose(cam->extpipe_stream);
509+
cam->extpipe_stream = NULL;
510+
511+
cam->filetype = FTYPE_MOVIE;
512+
on_movie_end_command(cam, cam->extpipe_filename);
513+
dbse_exec(cam, cam->extpipe_filename, "movie_end");
514+
515+
if ((cam->conf->movie_retain == "secondary") &&
516+
(cam->algsec_inuse) && (cam->algsec->isdetected == false)) {
517+
if (remove(cam->extpipe_filename) != 0) {
518+
MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
519+
, _("Unable to remove file %s"), cam->extpipe_filename);
520+
} else {
521+
MOTPLS_LOG(INF, TYPE_EVENTS, NO_ERRNO
522+
, _("No secondary detection. Removed file %s. ")
523+
, cam->extpipe_filename);
524+
}
525+
}
526+
}
632527
}
633528

634529
static void event_tlapse_start(ctx_dev *cam, char *fname)
@@ -693,10 +588,6 @@ struct event_handlers event_handlers[] = {
693588
event_movie_start
694589
},
695590
{
696-
EVENT_START,
697-
event_extpipe_start
698-
},
699-
{
700591
EVENT_END,
701592
on_event_end_command
702593
},
@@ -705,10 +596,6 @@ struct event_handlers event_handlers[] = {
705596
event_movie_end
706597
},
707598
{
708-
EVENT_END,
709-
event_extpipe_end
710-
},
711-
{
712599
EVENT_IMAGE_DETECTED,
713600
event_image_detect
714601
},
@@ -717,10 +604,6 @@ struct event_handlers event_handlers[] = {
717604
event_movie_put
718605
},
719606
{
720-
EVENT_IMAGE_DETECTED,
721-
event_extpipe_put
722-
},
723-
{
724607
EVENT_IMAGEM_DETECTED,
725608
event_imagem_detect
726609
},
@@ -749,10 +632,6 @@ struct event_handlers event_handlers[] = {
749632
event_movie_put
750633
},
751634
{
752-
EVENT_MOVIE_PUT,
753-
event_extpipe_put
754-
},
755-
{
756635
EVENT_TLAPSE_START,
757636
event_tlapse_start
758637
},
@@ -765,22 +644,10 @@ struct event_handlers event_handlers[] = {
765644
event_movie_start
766645
},
767646
{
768-
EVENT_MOVIE_START,
769-
event_extpipe_start
770-
},
771-
{
772647
EVENT_MOVIE_END,
773648
event_movie_end
774649
},
775650
{
776-
EVENT_MOVIE_END,
777-
event_extpipe_end
778-
},
779-
{
780-
EVENT_END,
781-
event_extpipe_end
782-
},
783-
{
784651
EVENT_CAMERA_LOST,
785652
event_camera_lost
786653
},

src/motionplus.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ struct ctx_dev {
411411

412412
cls_libcam *libcam;
413413

414-
FILE *extpipe;
415-
int extpipe_open;
416414
bool algsec_inuse; /*Bool for whether we have secondary detection*/
417415
int track_posx;
418416
int track_posy;
@@ -468,9 +466,12 @@ struct ctx_dev {
468466
char action_user[40];
469467

470468
int movie_fps;
471-
char extpipefilename[PATH_MAX];
472-
char extpipecmdline[PATH_MAX];
473469
bool movie_passthrough;
470+
471+
char extpipe_filename[PATH_MAX];
472+
char extpipe_cmdline[PATH_MAX];
473+
FILE *extpipe_stream;
474+
bool extpipe_isopen;
474475
int filetype;
475476

476477
int area_minx[9], area_miny[9], area_maxx[9], area_maxy[9];

0 commit comments

Comments
 (0)