diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 53894f782..d5590333b 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -111,9 +111,14 @@ Monitor::~Monitor() shared_data->state = state = IDLE; shared_data->last_read_index = image_buffer_count; } + else if ( purpose == CAPTURE ) + { + shared_data->valid = false; + memset( shm_ptr, 0, shm_size ); + } struct shmid_ds shm_data; - if ( shmctl( shmid, IPC_STAT, &shm_data ) ) + if ( shmctl( shm_id, IPC_STAT, &shm_data ) ) { Error(( "Can't shmctl: %s", strerror(errno))); exit( -1 ); @@ -121,7 +126,7 @@ Monitor::~Monitor() if ( shm_data.shm_nattch <= 1 ) { - if ( shmctl( shmid, IPC_RMID, 0 ) ) + if ( shmctl( shm_id, IPC_RMID, 0 ) ) { Error(( "Can't shmctl: %s", strerror(errno))); exit( -1 ); @@ -148,19 +153,19 @@ void Monitor::Setup() Debug( 1, ( "monitor purpose=%d", purpose )); - int shared_data_size = sizeof(SharedData) - + sizeof(TriggerData) - + (image_buffer_count*sizeof(struct timeval)) - + (image_buffer_count*camera->ImageSize()); + shm_size = sizeof(SharedData) + + sizeof(TriggerData) + + (image_buffer_count*sizeof(struct timeval)) + + (image_buffer_count*camera->ImageSize()); - Debug( 1, ( "shm.size=%d", shared_data_size )); - shmid = shmget( (config.shm_key&0xffffff00)|id, shared_data_size, IPC_CREAT|0700 ); - if ( shmid < 0 ) + Debug( 1, ( "shm.size=%d", shm_size )); + shm_id = shmget( (config.shm_key&0xffffff00)|id, shm_size, IPC_CREAT|0700 ); + if ( shm_id < 0 ) { Error(( "Can't shmget, probably not enough shared memory space free: %s", strerror(errno))); exit( -1 ); } - unsigned char *shm_ptr = (unsigned char *)shmat( shmid, 0, 0 ); + shm_ptr = (unsigned char *)shmat( shm_id, 0, 0 ); if ( shm_ptr < 0 ) { Error(( "Can't shmat: %s", strerror(errno))); @@ -174,7 +179,7 @@ void Monitor::Setup() if ( purpose == CAPTURE ) { - memset( shared_data, 0, shared_data_size ); + memset( shm_ptr, 0, shm_size ); shared_data->size = sizeof(SharedData); shared_data->valid = true; shared_data->active = enabled; diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 88c9bf065..77a67f927 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -72,6 +72,46 @@ public: TAPE } State; +protected: + typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action; + + typedef struct + { + int size; + bool valid; + bool active; + bool signal; + State state; + int last_write_index; + int last_read_index; + time_t last_image_time; + int last_event; + int action; + int brightness; + int hue; + int colour; + int contrast; + int alarm_x; + int alarm_y; + } SharedData; + + typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState; + typedef struct + { + int size; + TriggerState trigger_state; + int trigger_score; + char trigger_cause[32]; + char trigger_text[256]; + char trigger_showtext[32]; + } TriggerData; + + typedef struct Snapshot + { + struct timeval *timestamp; + Image *image; + }; + protected: // These are read from the DB and thereafter remain unchanged int id; @@ -119,52 +159,17 @@ protected: time_t start_time; time_t last_fps_time; time_t auto_resume_time; - int shmid; - typedef struct Snapshot - { - struct timeval *timestamp; - Image *image; - }; + int shm_id; + int shm_size; + unsigned char *shm_ptr; - Snapshot *image_buffer; + SharedData *shared_data; + TriggerData *trigger_data; - typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action; - typedef struct - { - int size; - bool valid; - bool active; - bool signal; - State state; - int last_write_index; - int last_read_index; - time_t last_image_time; - int last_event; - int action; - int brightness; - int hue; - int colour; - int contrast; - int alarm_x; - int alarm_y; - } SharedData; + Snapshot *image_buffer; - typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState; - typedef struct - { - int size; - TriggerState trigger_state; - int trigger_score; - char trigger_cause[32]; - char trigger_text[256]; - char trigger_showtext[32]; - } TriggerData; - - SharedData *shared_data; - TriggerData *trigger_data; - - Camera *camera; + Camera *camera; public: Monitor( int p_id, char *p_name, int p_function, bool p_enabled, Camera *p_camera, int p_orientation, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_alarm_frame_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, bool p_track_motion, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );