2020#include " util.hpp"
2121#include " conf.hpp"
2222#include " logger.hpp"
23- #include " allcam.hpp"
2423#include " schedule.hpp"
2524#include " camera.hpp"
2625#include " sound.hpp"
2726#include " dbse.hpp"
2827#include " webu.hpp"
28+ #include " webu_allcam.hpp"
2929#include " video_v4l2.hpp"
3030#include " movie.hpp"
3131#include " netcam.hpp"
@@ -455,6 +455,7 @@ void cls_motapp::check_restart()
455455 webu_list[indx1]->cfg = cam_list[indx2]->cfg ;
456456 }
457457 }
458+ webu_list[indx1]->webuindx = indx1;
458459 webu_list[indx1]->startup ();
459460 webu_list[indx1]->restart = false ;
460461 MOTION_LOG (NTC, TYPE_ALL, NO_ERRNO
@@ -516,6 +517,8 @@ void cls_motapp::init_webu()
516517
517518 p_webu = nullptr ;
518519
520+ webu_list.clear ();
521+
519522 if (cfg->webcontrol_port != 0 ) {
520523 p_webu = new cls_webu (this , cfg);
521524 webu_list.push_back (p_webu);
@@ -542,6 +545,7 @@ void cls_motapp::init_webu()
542545 }
543546
544547 for (indx1=0 ; indx1<webu_cnt; indx1++) {
548+ webu_list[indx1]->webuindx = indx1;
545549 webu_list[indx1]->startup ();
546550 }
547551
@@ -563,7 +567,6 @@ void cls_motapp::init(int p_argc, char *p_argv[])
563567 conf_src = nullptr ;
564568 cfg = nullptr ;
565569 dbse = nullptr ;
566- allcam = nullptr ;
567570 schedule = nullptr ;
568571 cam_list.clear ();
569572 snd_list.clear ();
@@ -597,7 +600,6 @@ void cls_motapp::init(int p_argc, char *p_argv[])
597600 av_init ();
598601
599602 dbse = new cls_dbse (this );
600- allcam = new cls_allcam (this );
601603 schedule = new cls_schedule (this );
602604 init_webu ();
603605
@@ -624,28 +626,35 @@ void cls_motapp::deinit()
624626 av_deinit ();
625627 pid_remove ();
626628
627- mydelete (dbse);
628- mydelete (allcam)
629- mydelete (schedule)
630- mydelete (conf_src);
631- mydelete (cfg);
632-
633629 for (indx = 0 ; indx < cam_cnt;indx++) {
630+ cam_list[indx]->handler_shutdown ();
634631 mydelete (cam_list[indx]);
635632 }
636633
637634 for (indx = 0 ; indx < snd_cnt;indx++) {
635+ snd_list[indx]->handler_shutdown ();
638636 mydelete (snd_list[indx]);
639637 }
640638
641639 for (indx = 0 ; indx < webu_cnt;indx++) {
640+ webu_list[indx]->shutdown ();
642641 mydelete (webu_list[indx]);
643642 }
644643
644+ dbse->shutdown ();
645+ mydelete (dbse);
646+
647+ schedule->handler_shutdown ();
648+ mydelete (schedule)
649+
650+ mydelete (conf_src);
651+ mydelete (cfg);
652+
645653 pthread_mutex_destroy (&mutex_camlst);
646654 pthread_mutex_destroy (&mutex_post);
647655
648656}
657+
649658/* Check for whether to add a new cam */
650659void cls_motapp::camera_add ()
651660{
@@ -664,8 +673,9 @@ void cls_motapp::camera_add()
664673/* Check for whether to delete a new cam */
665674void cls_motapp::camera_delete ()
666675{
667- cls_camera *cam;
668- int indx, chk_indx;
676+ cls_camera *cam;
677+ cls_webu *webu;
678+ int indx, indx2, chk_indx;
669679
670680 if (cam_delete < 0 ) {
671681 return ;
@@ -692,54 +702,39 @@ void cls_motapp::camera_delete()
692702 return ;
693703 }
694704 MOTION_LOG (NTC, TYPE_ALL, NO_ERRNO, " Camera stopped" );
695-
696- /* Determine whether to close a webcontrol port or assign
697- a different config file for any other cameras using same port*/
698- if ((cam->cfg ->webcontrol_port != cfg->webcontrol_port ) &&
699- (cam->cfg ->webcontrol_port != 0 )) {
700- /* Determine if a web control is using this config*/
701- chk_indx = -1 ;
702- for (indx = 0 ; indx < webu_cnt; indx++) {
703- if (webu_list[indx]->cfg == cam->cfg ) {
704- chk_indx = indx;
705- }
706- }
707- if (chk_indx != -1 ) {
708- /* This config IS being used. Either change web control
709- to use a different cam for the config or shutdown the
710- webcontrol*/
705+ /* Reverse sequence so we can remove elements*/
706+ for (indx = webu_cnt-1 ; indx >=0 ; indx--) {
707+ webu = webu_list[indx];
708+ if ((cam->cfg ->webcontrol_port == webu->cfg ->webcontrol_port ) ||
709+ (webu->cfg == cfg)) {
711710 chk_indx = -1 ;
712- for (indx = 0 ; indx < cam_cnt; indx++) {
713- if ((cam_list[indx]->cfg ->webcontrol_port ==
714- cam->cfg ->webcontrol_port ) &&
715- (indx != cam_delete)) {
716- chk_indx = indx;
711+ for (indx2 = 0 ; indx2 < webu->cam_cnt ; indx2++) {
712+ if (webu->cam_list [indx2] == cam) {
713+ chk_indx = indx2;
717714 }
718715 }
719- if (chk_indx == -1 ) {
720- /* This was only cam on the web port so shut it down */
721- for (indx = 0 ; indx < webu_cnt; indx++) {
722- if (webu_list[indx]-> cfg -> webcontrol_port ==
723- cam-> cfg -> webcontrol_port ) {
724- chk_indx = indx ;
725- }
726- }
727- webu_list[chk_indx] ->shutdown ();
728- mydelete (webu_list[chk_indx] );
729- webu_list.erase (webu_list.begin () + chk_indx );
716+ if (chk_indx != -1 ) {
717+ pthread_mutex_lock (&webu-> mutex_camlst );
718+ mydelete (webu-> cam_list [chk_indx]);
719+ webu-> cam_list . erase (cam_list. begin () + chk_indx);
720+ webu-> cam_cnt --;
721+ pthread_mutex_unlock (&webu-> mutex_camlst ) ;
722+ }
723+ if (webu-> cam_cnt == 0 ) {
724+ webu ->shutdown ();
725+ mydelete (webu );
726+ webu_list.erase (webu_list.begin () + indx );
730727 webu_cnt--;
731728 } else {
732- /* The web port is being used by different cam*/
733- /* assign the config for the different cam to the webu*/
734- /* chk_indx has the index of the different cam*/
735- for (indx = 0 ; indx < webu_cnt; indx++) {
736- if (webu_list[indx]->cfg ->webcontrol_port ==
737- cam->cfg ->webcontrol_port ) {
738- webu_list[indx]->cfg = cam_list[indx]->cfg ;
739- webu_list[chk_indx]->shutdown ();
740- webu_list[chk_indx]->startup ();
741- }
729+ if (webu->cfg == cam->cfg ) {
730+ /* The cfg used was is the cam being deleted so we need
731+ to pick a different cfg for webcontrol. Just use the
732+ first camera at index 0.*/
733+ webu->cfg = webu->cam_list [0 ]->cfg ;
734+ webu->shutdown ();
735+ webu->startup ();
742736 }
737+ webu->allcam ->reset = true ;
743738 }
744739 }
745740 }
@@ -751,7 +746,6 @@ void cls_motapp::camera_delete()
751746 pthread_mutex_unlock (&mutex_camlst);
752747
753748 cam_delete = -1 ;
754- allcam->all_sizes .reset = true ;
755749
756750}
757751
0 commit comments