From 05c2fb5dfd9a844044287c497a4c9f3c12832ac8 Mon Sep 17 00:00:00 2001 From: stan Date: Thu, 22 Dec 2005 16:46:25 +0000 Subject: [PATCH] Bug 238 - Changes to do with the various enabled/disable/suspend/trigger modes. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1720 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zm_config.h.in | 1 + src/zm_monitor.cpp | 1097 +++++++++++++++++++++++++++----------------- src/zm_monitor.h | 223 +++------ src/zma.cpp | 32 +- src/zmu.cpp | 84 +++- 5 files changed, 827 insertions(+), 610 deletions(-) diff --git a/src/zm_config.h.in b/src/zm_config.h.in index 9898f0858..e5f4a88ad 100644 --- a/src/zm_config.h.in +++ b/src/zm_config.h.in @@ -34,6 +34,7 @@ #define ZM_MAX_FPS 30 // The maximum frame rate we expect to handle #define ZM_SAMPLE_RATE int(1000000/ZM_MAX_FPS) // A general nyquist sample frequency for delays etc +#define ZM_SUSPENDED_RATE int(1000000/4) // A slower rate for when disabled etc extern char *ZM_DB_HOST, *ZM_DB_NAME, *ZM_DB_USER, *ZM_DB_PASS, *ZM_PATH_WEB; extern void zmLoadConfig(); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index ef6c163a8..926e7d77c 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -32,6 +32,7 @@ Monitor::Monitor( int p_id, char *p_name, int p_function, + bool p_enabled, Camera *p_camera, int p_orientation, char *p_event_prefix, @@ -53,6 +54,7 @@ Monitor::Monitor( Zone *p_zones[] ) : id( p_id ), function( (Function)p_function ), + enabled( p_enabled ), camera( p_camera ), orientation( (Orientation)p_orientation ), width( (p_orientation==ROTATE_90||p_orientation==ROTATE_270)?p_camera->Height():p_camera->Width() ), @@ -86,14 +88,8 @@ Monitor::Monitor( Monitor::~Monitor() { - if ( event ) - { - if ( function == RECORD || function == MOCORD ) - { - gettimeofday( &(event->EndTime()), &dummy_tz ); - } - delete event; - } + closeEvent(); + for ( int i = 0; i < image_buffer_count; i++ ) { delete image_buffer[i].image; @@ -138,8 +134,7 @@ void Monitor::Setup() fps = 0.0; event_count = 0; image_count = 0; - activity_state = ACTIVE; - resume_image_count = 0; + ready_count = warmup_count; first_alarm_count = 0; last_alarm_count = 0; state = IDLE; @@ -149,6 +144,8 @@ void Monitor::Setup() else if ( alarm_frame_count > MAX_PRE_ALARM_FRAMES ) alarm_frame_count = MAX_PRE_ALARM_FRAMES; + auto_resume_time = 0; + Debug( 1, ( "monitor purpose=%d", purpose )); int shared_data_size = sizeof(SharedData) @@ -180,6 +177,7 @@ void Monitor::Setup() memset( shared_data, 0, shared_data_size ); shared_data->size = sizeof(SharedData); shared_data->valid = true; + shared_data->active = enabled; shared_data->state = IDLE; shared_data->last_write_index = image_buffer_count; shared_data->last_read_index = image_buffer_count; @@ -407,17 +405,48 @@ void Monitor::CancelForced() trigger_data->trigger_state = TRIGGER_CANCEL; } -void Monitor::Suspend() +void Monitor::actionReload() +{ + shared_data->action |= RELOAD; +} + +void Monitor::actionEnable() +{ + shared_data->action |= RELOAD; + + static char sql[BUFSIZ]; + snprintf( sql, sizeof(sql), "update Monitors set Enabled = 1 where Id = '%d'", id ); + if ( mysql_query( &dbconn, sql ) ) + { + Error(( "Can't run query: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } +} + +void Monitor::actionDisable() +{ + shared_data->action |= RELOAD; + + static char sql[BUFSIZ]; + snprintf( sql, sizeof(sql), "update Monitors set Enabled = 0 where Id = '%d'", id ); + if ( mysql_query( &dbconn, sql ) ) + { + Error(( "Can't run query: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } +} + +void Monitor::actionSuspend() { shared_data->action |= SUSPEND; } -void Monitor::Resume() +void Monitor::actionResume() { shared_data->action |= RESUME; } -int Monitor::Brightness( int p_brightness ) +int Monitor::actionBrightness( int p_brightness ) { if ( purpose != CAPTURE ) { @@ -451,7 +480,7 @@ int Monitor::Brightness( int p_brightness ) return( camera->Brightness( p_brightness ) ); } -int Monitor::Contrast( int p_contrast ) +int Monitor::actionContrast( int p_contrast ) { if ( purpose != CAPTURE ) { @@ -485,7 +514,7 @@ int Monitor::Contrast( int p_contrast ) return( camera->Contrast( p_contrast ) ); } -int Monitor::Hue( int p_hue ) +int Monitor::actionHue( int p_hue ) { if ( purpose != CAPTURE ) { @@ -519,7 +548,7 @@ int Monitor::Hue( int p_hue ) return( camera->Hue( p_hue ) ); } -int Monitor::Colour( int p_colour ) +int Monitor::actionColour( int p_colour ) { if ( purpose != CAPTURE ) { @@ -682,315 +711,386 @@ bool Monitor::Analyse() struct timeval *timestamp = snap->timestamp; Image *snap_image = snap->image; + if ( shared_data->action ) + { + if ( shared_data->action & RELOAD ) + { + Info(( "Received reload indication at count %d", image_count )); + shared_data->action &= ~RELOAD; + Reload(); + } + if ( shared_data->action & SUSPEND ) + { + if ( Active() ) + { + Info(( "Received suspend indication at count %d", image_count )); + shared_data->active = false; + closeEvent(); + } + if ( config.max_suspend_time ) + { + auto_resume_time = now.tv_sec + config.max_suspend_time; + } + shared_data->action &= ~SUSPEND; + } + if ( shared_data->action & RESUME ) + { + if ( Enabled() && !Active() ) + { + Info(( "Received resume indication at count %d", image_count )); + shared_data->active = true; + ref_image = *snap_image; + ready_count = image_count+(warmup_count/2); + shared_data->alarm_x = shared_data->alarm_y = -1; + } + shared_data->action &= ~RESUME; + } + } + if ( auto_resume_time && (now.tv_sec >= auto_resume_time) ) + { + Info(( "Auto resuming at count %d", image_count )); + shared_data->active = true; + ref_image = *snap_image; + ready_count = image_count+(warmup_count/2); + auto_resume_time = 0; + } + static struct timeval **timestamps; static Image **images; static int last_section_mod = 0; - if ( shared_data->action & SUSPEND ) + if ( Enabled() ) { - Info(( "Received suspend indication at count %d", image_count )); - - activity_state = SUSPENDED; - shared_data->action &= ~SUSPEND; - //shared_data->alarm_x = shared_data->alarm_y = -1; - } - if ( shared_data->action & RESUME ) - { - Info(( "Received resume indication at count %d", image_count )); - - activity_state = RESUMING; - //ref_image.Clear(); - ref_image = *snap_image; - resume_image_count = image_count+(warmup_count/2); - shared_data->action &= ~RESUME; - shared_data->alarm_x = shared_data->alarm_y = -1; - } - else if ( activity_state == RESUMING ) - { - if ( resume_image_count && (image_count >= resume_image_count) ) + if ( trigger_data->trigger_state != TRIGGER_OFF ) { - activity_state = ACTIVE; - resume_image_count = 0; - } - } - unsigned int score = 0; - if ( Ready() ) - { - const char *cause = "Undefined"; - const char *text = ""; - - //Info(( "St:%d, Sc:%d, Ca:%s, Te:%s", trigger_data->trigger_state, trigger_data->trigger_score, trigger_data->trigger_cause, trigger_data->trigger_text )); - if ( function != RECORD && function != NODECT && trigger_data->trigger_state != TRIGGER_OFF ) - { - score = Compare( *snap_image ); - cause = "Motion"; - } - if ( trigger_data->trigger_state == TRIGGER_ON ) - { - score = trigger_data->trigger_score; - cause = trigger_data->trigger_cause; - text = trigger_data->trigger_text; - } - if ( function == RECORD || function == MOCORD ) - { - if ( event ) + unsigned int score = 0; + if ( Ready() ) { - int section_mod = timestamp->tv_sec%section_length; - if ( section_mod < last_section_mod ) + const char *cause = "Undefined"; + const char *text = ""; + + //Info(( "St:%d, Sc:%d, Ca:%s, Te:%s", trigger_data->trigger_state, trigger_data->trigger_score, trigger_data->trigger_cause, trigger_data->trigger_text )); + if ( trigger_data->trigger_state == TRIGGER_ON ) { - if ( state == IDLE || state == TAPE || config.force_close_events ) + score = trigger_data->trigger_score; + cause = trigger_data->trigger_cause; + text = trigger_data->trigger_text; + } + else if ( Active() && function != RECORD && function != NODECT ) + { + score = Compare( *snap_image ); + cause = "Motion"; + } + if ( function == RECORD || function == MOCORD ) + { + if ( event ) { - if ( state == IDLE || state == TAPE ) + int section_mod = timestamp->tv_sec%section_length; + if ( section_mod < last_section_mod ) { - Info(( "Ended event" )); + if ( state == IDLE || state == TAPE || config.force_close_events ) + { + if ( state == IDLE || state == TAPE ) + { + Info(( "Ended event" )); + } + else + { + Info(( "Force closed event" )); + } + closeEvent(); + last_section_mod = 0; + } } else { - Info(( "Force closed event" )); - } - gettimeofday( &(event->EndTime()), &dummy_tz ); - delete event; - event = 0; - last_section_mod = 0; - } - } - else - { - last_section_mod = section_mod; - } - } - if ( !event ) - { - // Create event - event = new Event( this, *timestamp, "Continuous" ); - - Info(( "%s: %03d - Starting new event %d", name, image_count, event->Id() )); - - //if ( config.overlap_timed_events ) - if ( true ) - { - int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; - if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; - if ( !images ) images = new Image *[pre_event_count]; - for ( int i = 0; i < pre_event_count; i++ ) - { - timestamps[i] = image_buffer[pre_index].timestamp; - images[i] = image_buffer[pre_index].image; - - pre_index = (pre_index+1)%image_buffer_count; - } - event->AddFrames( pre_event_count, images, timestamps ); - } - shared_data->state = state = TAPE; - } - } - if ( score ) - { - if ( config.opt_control && track_motion && (activity_state != ACTIVE) ) - { - // Do nothing - } - else if ( (state == IDLE || state == TAPE || state == PREALARM ) ) - { - if ( Event::PreAlarmCount() >= (alarm_frame_count-1) ) - { - Info(( "%s: %03d - Gone into alarm state", name, image_count )); - if ( function != MOCORD && state != ALERT ) - { - int pre_index; - - if ( alarm_frame_count > 1 ) - { - int ts_index = ((index+image_buffer_count)-(alarm_frame_count-1))%image_buffer_count; - event = new Event( this, *(image_buffer[ts_index].timestamp), cause, text ); - pre_index = ((index+image_buffer_count)-((alarm_frame_count-1)+pre_event_count))%image_buffer_count; - } - else - { - event = new Event( this, *timestamp, cause, text ); - pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; - } - - if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; - if ( !images ) images = new Image *[pre_event_count]; - for ( int i = 0; i < pre_event_count; i++ ) - { - timestamps[i] = image_buffer[pre_index].timestamp; - images[i] = image_buffer[pre_index].image; - - pre_index = (pre_index+1)%image_buffer_count; - } - event->AddFrames( pre_event_count, images, timestamps ); - if ( alarm_frame_count ) - { - event->SavePreAlarmFrames(); + last_section_mod = section_mod; } } - shared_data->state = state = ALARM; - } - else if ( state != PREALARM ) - { - Info(( "%s: %03d - Gone into prealarm state", name, image_count )); - shared_data->state = state = PREALARM; - } - } - else if ( state == ALERT ) - { - Info(( "%s: %03d - Gone back into alarm state", name, image_count )); - shared_data->state = state = ALARM; - } - last_alarm_count = image_count; - } - else - { - if ( config.opt_control && track_motion && (activity_state != ACTIVE) ) - { - // Do nothing - } - else if ( state == ALARM ) - { - Info(( "%s: %03d - Gone into alert state", name, image_count )); - shared_data->state = state = ALERT; - } - else if ( state == ALERT ) - { - if ( image_count-last_alarm_count > post_event_count ) - { - Info(( "%s: %03d - Left alarm state (%d) - %d(%d) images", name, image_count, event->Id(), event->Frames(), event->AlarmFrames() )); - shared_data->last_event = event->Id(); - if ( function != MOCORD ) - { - shared_data->state = state = IDLE; - delete event; - event = 0; - } - else + if ( !event ) { + // Create event + event = new Event( this, *timestamp, "Continuous" ); + + Info(( "%s: %03d - Starting new event %d", name, image_count, event->Id() )); + + //if ( config.overlap_timed_events ) + if ( true ) + { + int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; + if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; + if ( !images ) images = new Image *[pre_event_count]; + for ( int i = 0; i < pre_event_count; i++ ) + { + timestamps[i] = image_buffer[pre_index].timestamp; + images[i] = image_buffer[pre_index].image; + + pre_index = (pre_index+1)%image_buffer_count; + } + event->AddFrames( pre_event_count, images, timestamps ); + } shared_data->state = state = TAPE; } } - } - if ( state == PREALARM ) - { - if ( function != MOCORD ) + if ( score ) { - shared_data->state = state = IDLE; - } - else - { - shared_data->state = state = TAPE; - } - } - if ( Event::PreAlarmCount() ) - Event::EmptyPreAlarmFrames(); - } - if ( state != IDLE ) - { - if ( state == PREALARM || state == ALARM ) - { - if ( config.create_analysis_images ) - { - bool got_anal_image = false; - Image alarm_image( *snap_image ); - for( int i = 0; i < n_zones; i++ ) + if ( (state == IDLE || state == TAPE || state == PREALARM ) ) { - if ( zones[i]->Alarmed() ) + if ( Event::PreAlarmCount() >= (alarm_frame_count-1) ) { - if ( zones[i]->AlarmImage() ) + Info(( "%s: %03d - Gone into alarm state", name, image_count )); + if ( function != MOCORD && state != ALERT ) { - alarm_image.Overlay( *(zones[i]->AlarmImage()) ); - got_anal_image = true; - } - if ( config.record_event_stats && state == ALARM ) - { - zones[i]->RecordStats( event ); + int pre_index; + + if ( alarm_frame_count > 1 ) + { + int ts_index = ((index+image_buffer_count)-(alarm_frame_count-1))%image_buffer_count; + event = new Event( this, *(image_buffer[ts_index].timestamp), cause, text ); + pre_index = ((index+image_buffer_count)-((alarm_frame_count-1)+pre_event_count))%image_buffer_count; + } + else + { + event = new Event( this, *timestamp, cause, text ); + pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; + } + + if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; + if ( !images ) images = new Image *[pre_event_count]; + for ( int i = 0; i < pre_event_count; i++ ) + { + timestamps[i] = image_buffer[pre_index].timestamp; + images[i] = image_buffer[pre_index].image; + + pre_index = (pre_index+1)%image_buffer_count; + } + event->AddFrames( pre_event_count, images, timestamps ); + if ( alarm_frame_count ) + { + event->SavePreAlarmFrames(); + } } + shared_data->state = state = ALARM; + } + else if ( state != PREALARM ) + { + Info(( "%s: %03d - Gone into prealarm state", name, image_count )); + shared_data->state = state = PREALARM; } } - if ( got_anal_image ) + else if ( state == ALERT ) { - if ( state == PREALARM ) - Event::AddPreAlarmFrame( snap_image, *timestamp, score, &alarm_image ); - else - event->AddFrame( snap_image, *timestamp, score, &alarm_image ); - } - else - { - if ( state == PREALARM ) - Event::AddPreAlarmFrame( snap_image, *timestamp, score ); - else - event->AddFrame( snap_image, *timestamp, score ); + Info(( "%s: %03d - Gone back into alarm state", name, image_count )); + shared_data->state = state = ALARM; } + last_alarm_count = image_count; } else { - for( int i = 0; i < n_zones; i++ ) + if ( state == ALARM ) { - if ( zones[i]->Alarmed() ) + Info(( "%s: %03d - Gone into alert state", name, image_count )); + shared_data->state = state = ALERT; + } + else if ( state == ALERT ) + { + if ( image_count-last_alarm_count > post_event_count ) { - if ( config.record_event_stats && state == ALARM ) + Info(( "%s: %03d - Left alarm state (%d) - %d(%d) images", name, image_count, event->Id(), event->Frames(), event->AlarmFrames() )); + shared_data->last_event = event->Id(); + if ( function != MOCORD ) { - zones[i]->RecordStats( event ); + shared_data->state = state = IDLE; + delete event; + event = 0; + } + else + { + shared_data->state = state = TAPE; } } } if ( state == PREALARM ) - Event::AddPreAlarmFrame( snap_image, *timestamp, score ); - else - event->AddFrame( snap_image, *timestamp, score ); - } - } - else if ( state == ALERT ) - { - event->AddFrame( snap_image, *timestamp ); - } - else if ( state == TAPE ) - { - if ( !(image_count%(frame_skip+1)) ) - { - if ( config.bulk_frame_interval > 1 ) { - event->AddFrame( snap_image, *timestamp, -1 ); + if ( function != MOCORD ) + { + shared_data->state = state = IDLE; + } + else + { + shared_data->state = state = TAPE; + } } - else + if ( Event::PreAlarmCount() ) + Event::EmptyPreAlarmFrames(); + } + if ( state != IDLE ) + { + if ( state == PREALARM || state == ALARM ) { - event->AddFrame( snap_image, *timestamp ); + if ( config.create_analysis_images ) + { + bool got_anal_image = false; + Image alarm_image( *snap_image ); + for( int i = 0; i < n_zones; i++ ) + { + if ( zones[i]->Alarmed() ) + { + if ( zones[i]->AlarmImage() ) + { + alarm_image.Overlay( *(zones[i]->AlarmImage()) ); + got_anal_image = true; + } + if ( config.record_event_stats && state == ALARM ) + { + zones[i]->RecordStats( event ); + } + } + } + if ( got_anal_image ) + { + if ( state == PREALARM ) + Event::AddPreAlarmFrame( snap_image, *timestamp, score, &alarm_image ); + else + event->AddFrame( snap_image, *timestamp, score, &alarm_image ); + } + else + { + if ( state == PREALARM ) + Event::AddPreAlarmFrame( snap_image, *timestamp, score ); + else + event->AddFrame( snap_image, *timestamp, score ); + } + } + else + { + for( int i = 0; i < n_zones; i++ ) + { + if ( zones[i]->Alarmed() ) + { + if ( config.record_event_stats && state == ALARM ) + { + zones[i]->RecordStats( event ); + } + } + } + if ( state == PREALARM ) + Event::AddPreAlarmFrame( snap_image, *timestamp, score ); + else + event->AddFrame( snap_image, *timestamp, score ); + } + } + else if ( state == ALERT ) + { + event->AddFrame( snap_image, *timestamp ); + } + else if ( state == TAPE ) + { + if ( !(image_count%(frame_skip+1)) ) + { + if ( config.bulk_frame_interval > 1 ) + { + event->AddFrame( snap_image, *timestamp, -1 ); + } + else + { + event->AddFrame( snap_image, *timestamp ); + } + } + } + } + if ( function == RECORD || function == MOCORD ) + { + if ( state == IDLE || state == TAPE ) + { + int section_mod = timestamp->tv_sec%section_length; + if ( section_mod < last_section_mod ) + { + Info(( "Ended event" )); + closeEvent(); + last_section_mod = 0; + } + else + { + last_section_mod = section_mod; + } } } } } - if ( function == RECORD || function == MOCORD ) + if ( (function == MODECT || function == MOCORD) && (config.blend_alarmed_images || state != ALARM) ) { - if ( state == IDLE || state == TAPE ) - { - int section_mod = timestamp->tv_sec%section_length; - if ( section_mod < last_section_mod ) - { - Info(( "Ended event" )); - gettimeofday( &(event->EndTime()), &dummy_tz ); - delete event; - event = 0; - last_section_mod = 0; - } - else - { - last_section_mod = section_mod; - } - } + ref_image.Blend( *snap_image, ref_blend_perc ); } } - if ( (function == MODECT || function == MOCORD) && (config.blend_alarmed_images || state != ALARM) ) - { - ref_image.Blend( *snap_image, ref_blend_perc ); - } - shared_data->last_read_index = index%image_buffer_count; image_count++; return( true ); } +void Monitor::Reload() +{ + Debug( 1, ( "Reloading monitor %s", name )); + + static char sql[BUFSIZ]; + snprintf( sql, sizeof(sql), "select Function+0, Enabled, EventPrefix, LabelFormat, LabelX, LabelY, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Id = '%d'", id ); + if ( mysql_query( &dbconn, sql ) ) + { + Error(( "Can't run query: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } + + MYSQL_RES *result = mysql_store_result( &dbconn ); + if ( !result ) + { + Error(( "Can't use query result: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } + int n_monitors = mysql_num_rows( result ); + if ( n_monitors != 1 ) + { + Error(( "Bogus number of monitors, %d, returned. Can't reload", n_monitors )); + return; + } + if ( MYSQL_ROW dbrow = mysql_fetch_row( result ) ) + { + int index = 0; + function = (Function)atoi(dbrow[index++]); + enabled = atoi(dbrow[index++]); + strncpy( event_prefix, dbrow[index++], sizeof(event_prefix) ); + strncpy( label_format, dbrow[index++], sizeof(label_format) ); + label_coord = Coord( atoi(dbrow[index]), atoi(dbrow[index+1]) ); index += 2; + warmup_count = atoi(dbrow[index++]); + pre_event_count = atoi(dbrow[index++]); + post_event_count = atoi(dbrow[index++]); + alarm_frame_count = atoi(dbrow[index++]); + section_length = atoi(dbrow[index++]); + frame_skip = atoi(dbrow[index++]); + capture_delay = atof(dbrow[index])>0.0?int(DT_PREC_3/atof(dbrow[index])):0; index++; + fps_report_interval = atoi(dbrow[index++]); + ref_blend_perc = atoi(dbrow[index++]); + track_motion = atoi(dbrow[index++]); + + closeEvent(); + + shared_data->state = state = IDLE; + shared_data->alarm_x = shared_data->alarm_y = -1; + if ( enabled ) + shared_data->active = true; + ready_count = image_count+warmup_count; + } + if ( mysql_errno( &dbconn ) ) + { + Error(( "Can't fetch row: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } + mysql_free_result( result ); + + ReloadZones(); +} + void Monitor::ReloadZones() { Debug( 1, ( "Reloading zones for monitor %s", name )); @@ -998,9 +1098,10 @@ void Monitor::ReloadZones() { delete zones[i]; } - //delete[] zones; + delete[] zones; + zones = 0; n_zones = Zone::Load( this, zones ); - DumpZoneImage(); + //DumpZoneImage(); } int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose purpose ) @@ -1008,11 +1109,11 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose static char sql[BUFSIZ]; if ( !device[0] ) { - strncpy( sql, "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local'", sizeof(sql) ); + strncpy( sql, "select Id, Name, Function+0, Enabled, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local'", sizeof(sql) ); } else { - snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local' and Device = '%s'", device ); + snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local' and Device = '%s'", device ); } if ( mysql_query( &dbconn, sql ) ) { @@ -1032,22 +1133,22 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose monitors = new Monitor *[n_monitors]; for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) { - int width = atoi(dbrow[6]); - int height = atoi(dbrow[7]); - int palette = atoi(dbrow[8]); - Orientation orientation = (Orientation)atoi(dbrow[9]); - int brightness = atoi(dbrow[10]); - int contrast = atoi(dbrow[11]); - int hue = atoi(dbrow[12]); - int colour = atoi(dbrow[13]); + int width = atoi(dbrow[7]); + int height = atoi(dbrow[8]); + int palette = atoi(dbrow[9]); + Orientation orientation = (Orientation)atoi(dbrow[10]); + int brightness = atoi(dbrow[11]); + int contrast = atoi(dbrow[12]); + int hue = atoi(dbrow[13]); + int colour = atoi(dbrow[14]); int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width); int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height); Camera *camera = new LocalCamera( - dbrow[3], // Device - atoi(dbrow[4]), // Channel - atoi(dbrow[5]), // Format + dbrow[4], // Device + atoi(dbrow[5]), // Channel + atoi(dbrow[6]), // Format cam_width, cam_height, palette, @@ -1062,22 +1163,23 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose atoi(dbrow[0]), // Id dbrow[1], // Name atoi(dbrow[2]), // Function + atoi(dbrow[3]), // Enabled camera, orientation, - dbrow[14], // EventPrefix - dbrow[15], // LabelFormat - Coord( atoi(dbrow[16]), atoi(dbrow[17]) ), // LabelX, LabelY - atoi(dbrow[18]), // ImageBufferCount - atoi(dbrow[19]), // WarmupCount - atoi(dbrow[20]), // PreEventCount - atoi(dbrow[21]), // PostEventCount - atoi(dbrow[22]), // AlarmFrameCount - atoi(dbrow[23]), // SectionLength - atoi(dbrow[24]), // FrameSkip - atof(dbrow[25])>0.0?int(DT_PREC_3/atof(dbrow[25])):0, // MaxFPS - atoi(dbrow[26]), // FPSReportInterval - atoi(dbrow[27]), // RefBlendPerc - atoi(dbrow[28]), // TrackMotion + dbrow[15], // EventPrefix + dbrow[16], // LabelFormat + Coord( atoi(dbrow[17]), atoi(dbrow[18]) ), // LabelX, LabelY + atoi(dbrow[19]), // ImageBufferCount + atoi(dbrow[20]), // WarmupCount + atoi(dbrow[21]), // PreEventCount + atoi(dbrow[22]), // PostEventCount + atoi(dbrow[23]), // AlarmFrameCount + atoi(dbrow[24]), // SectionLength + atoi(dbrow[25]), // FrameSkip + atof(dbrow[26])>0.0?int(DT_PREC_3/atof(dbrow[26])):0, // MaxFPS + atoi(dbrow[27]), // FPSReportInterval + atoi(dbrow[28]), // RefBlendPerc + atoi(dbrow[29]), // TrackMotion purpose ); Zone **zones = 0; @@ -1101,11 +1203,11 @@ int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char * static char sql[BUFSIZ]; if ( !host ) { - strncpy( sql, "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) ); + strncpy( sql, "select Id, Name, Function+0, Enabled, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) ); } else { - snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", host, port, path ); + snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", host, port, path ); } if ( mysql_query( &dbconn, sql ) ) { @@ -1125,22 +1227,22 @@ int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char * monitors = new Monitor *[n_monitors]; for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) { - int width = atoi(dbrow[6]); - int height = atoi(dbrow[7]); - int palette = atoi(dbrow[8]); - Orientation orientation = (Orientation)atoi(dbrow[9]); - int brightness = atoi(dbrow[10]); - int contrast = atoi(dbrow[11]); - int hue = atoi(dbrow[12]); - int colour = atoi(dbrow[13]); + int width = atoi(dbrow[7]); + int height = atoi(dbrow[8]); + int palette = atoi(dbrow[9]); + Orientation orientation = (Orientation)atoi(dbrow[10]); + int brightness = atoi(dbrow[11]); + int contrast = atoi(dbrow[12]); + int hue = atoi(dbrow[13]); + int colour = atoi(dbrow[14]); int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width); int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height); Camera *camera = new RemoteCamera( - dbrow[3], // Host - dbrow[4], // Port - dbrow[5], // Path + dbrow[4], // Host + dbrow[5], // Port + dbrow[6], // Path cam_width, cam_height, palette, @@ -1155,22 +1257,23 @@ int Monitor::LoadRemoteMonitors( const char *host, const char*port, const char * atoi(dbrow[0]), // Id dbrow[1], // Name atoi(dbrow[2]), // Function + atoi(dbrow[3]), // Enabled camera, - atoi(dbrow[9]), // Orientation - dbrow[14], // EventPrefix - dbrow[15], // LabelFormat - Coord( atoi(dbrow[16]), atoi(dbrow[17]) ), // LabelX, LabelY - atoi(dbrow[18]), // ImageBufferCount - atoi(dbrow[19]), // WarmupCount - atoi(dbrow[20]), // PreEventCount - atoi(dbrow[21]), // PostEventCount - atoi(dbrow[22]), // AlarmFrameCount - atoi(dbrow[23]), // SectionLength - atoi(dbrow[24]), // FrameSkip - atof(dbrow[25])>0.0?int(DT_PREC_3/atof(dbrow[25])):0, // MaxFPS - atoi(dbrow[26]), // FPSReportInterval - atoi(dbrow[27]), // RefBlendPerc - atoi(dbrow[28]), // TrackMotion + atoi(dbrow[10]), // Orientation + dbrow[15], // EventPrefix + dbrow[16], // LabelFormat + Coord( atoi(dbrow[17]), atoi(dbrow[18]) ), // LabelX, LabelY + atoi(dbrow[19]), // ImageBufferCount + atoi(dbrow[20]), // WarmupCount + atoi(dbrow[21]), // PreEventCount + atoi(dbrow[22]), // PostEventCount + atoi(dbrow[23]), // AlarmFrameCount + atoi(dbrow[24]), // SectionLength + atoi(dbrow[25]), // FrameSkip + atof(dbrow[26])>0.0?int(DT_PREC_3/atof(dbrow[26])):0, // MaxFPS + atoi(dbrow[27]), // FPSReportInterval + atoi(dbrow[28]), // RefBlendPerc + atoi(dbrow[29]), // TrackMotion purpose ); Zone **zones = 0; @@ -1194,11 +1297,11 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu static char sql[BUFSIZ]; if ( !file[0] ) { - strncpy( sql, "select Id, Name, Function+0, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File'", sizeof(sql) ); + strncpy( sql, "select Id, Name, Function+0, Enabled, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File'", sizeof(sql) ); } else { - snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File' and Path = '%s'", file ); + snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Enabled, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File' and Path = '%s'", file ); } if ( mysql_query( &dbconn, sql ) ) { @@ -1218,20 +1321,20 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu monitors = new Monitor *[n_monitors]; for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) { - int width = atoi(dbrow[4]); - int height = atoi(dbrow[5]); - int palette = atoi(dbrow[6]); - Orientation orientation = (Orientation)atoi(dbrow[7]); - int brightness = atoi(dbrow[8]); - int contrast = atoi(dbrow[9]); - int hue = atoi(dbrow[10]); - int colour = atoi(dbrow[11]); + int width = atoi(dbrow[5]); + int height = atoi(dbrow[6]); + int palette = atoi(dbrow[7]); + Orientation orientation = (Orientation)atoi(dbrow[8]); + int brightness = atoi(dbrow[9]); + int contrast = atoi(dbrow[10]); + int hue = atoi(dbrow[11]); + int colour = atoi(dbrow[12]); int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width); int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height); Camera *camera = new FileCamera( - dbrow[3], // File + dbrow[4], // File cam_width, cam_height, palette, @@ -1246,22 +1349,23 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu atoi(dbrow[0]), // Id dbrow[1], // Name atoi(dbrow[2]), // Function + atoi(dbrow[3]), // Enabled camera, - atoi(dbrow[7]), // Orientation - dbrow[12], // EventPrefix - dbrow[13], // LabelFormat - Coord( atoi(dbrow[14]), atoi(dbrow[15]) ), // LabelX, LabelY - atoi(dbrow[16]), // ImageBufferCount - atoi(dbrow[17]), // WarmupCount - atoi(dbrow[18]), // PreEventCount - atoi(dbrow[19]), // PostEventCount - atoi(dbrow[20]), // AlarmFrameCount - atoi(dbrow[21]), // SectionLength - atoi(dbrow[22]), // FrameSkip - atof(dbrow[23])>0.0?int(DT_PREC_3/atof(dbrow[23])):0, // MaxFPS - atoi(dbrow[24]), // FPSReportInterval - atoi(dbrow[25]), // RefBlendPerc - atoi(dbrow[26]), // TrackMotion + atoi(dbrow[8]), // Orientation + dbrow[13], // EventPrefix + dbrow[14], // LabelFormat + Coord( atoi(dbrow[15]), atoi(dbrow[16]) ), // LabelX, LabelY + atoi(dbrow[17]), // ImageBufferCount + atoi(dbrow[18]), // WarmupCount + atoi(dbrow[19]), // PreEventCount + atoi(dbrow[20]), // PostEventCount + atoi(dbrow[21]), // AlarmFrameCount + atoi(dbrow[22]), // SectionLength + atoi(dbrow[23]), // FrameSkip + atof(dbrow[24])>0.0?int(DT_PREC_3/atof(dbrow[24])):0, // MaxFPS + atoi(dbrow[25]), // FPSReportInterval + atoi(dbrow[26]), // RefBlendPerc + atoi(dbrow[27]), // TrackMotion purpose ); Zone **zones = 0; @@ -1283,7 +1387,7 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) { static char sql[BUFSIZ]; - snprintf( sql, sizeof(sql), "select Id, Name, Type, Function+0, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Id = %d", id ); + snprintf( sql, sizeof(sql), "select Id, Name, Type, Function+0, Enabled, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Id = %d", id ); if ( mysql_query( &dbconn, sql ) ) { Error(( "Can't run query: %s", mysql_error( &dbconn ) )); @@ -1301,14 +1405,14 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) Monitor *monitor = 0; for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) { - int width = atoi(dbrow[10]); - int height = atoi(dbrow[11]); - int palette = atoi(dbrow[12]); - Orientation orientation = (Orientation)atoi(dbrow[13]); - int brightness = atoi(dbrow[14]); - int contrast = atoi(dbrow[15]); - int hue = atoi(dbrow[16]); - int colour = atoi(dbrow[17]); + int width = atoi(dbrow[11]); + int height = atoi(dbrow[12]); + int palette = atoi(dbrow[13]); + Orientation orientation = (Orientation)atoi(dbrow[14]); + int brightness = atoi(dbrow[15]); + int contrast = atoi(dbrow[16]); + int hue = atoi(dbrow[17]); + int colour = atoi(dbrow[18]); int cam_width = ((orientation==ROTATE_90||orientation==ROTATE_270)?height:width); int cam_height = ((orientation==ROTATE_90||orientation==ROTATE_270)?width:height); @@ -1317,9 +1421,9 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) if ( !strcmp( dbrow[2], "Local" ) ) { camera = new LocalCamera( - dbrow[4], // Device - atoi(dbrow[5]), // Channel - atoi(dbrow[6]), // Format + dbrow[5], // Device + atoi(dbrow[6]), // Channel + atoi(dbrow[7]), // Format cam_width, cam_height, palette, @@ -1333,9 +1437,9 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) else if ( !strcmp( dbrow[2], "Remote" ) ) { camera = new RemoteCamera( - dbrow[7], // Host - dbrow[8], // Port - dbrow[9], // Path + dbrow[8], // Host + dbrow[9], // Port + dbrow[10], // Path cam_width, cam_height, palette, @@ -1349,7 +1453,7 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) else if ( !strcmp( dbrow[2], "File" ) ) { camera = new FileCamera( - dbrow[9], // Path + dbrow[10], // Path cam_width, cam_height, palette, @@ -1369,22 +1473,23 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose ) atoi(dbrow[0]), // Id dbrow[1], // Name atoi(dbrow[3]), // Function + atoi(dbrow[4]), // Enabled camera, orientation, - dbrow[18], // EventPrefix - dbrow[19], // LabelFormat - Coord( atoi(dbrow[20]), atoi(dbrow[21]) ), // LabelX, LabelY - atoi(dbrow[22]), // ImageBufferCount - atoi(dbrow[23]), // WarmupCount - atoi(dbrow[24]), // PreEventCount - atoi(dbrow[25]), // PostEventCount - atoi(dbrow[26]), // AlarmFrameCount - atoi(dbrow[27]), // SectionLength - atoi(dbrow[28]), // FrameSkip - atof(dbrow[29])>0.0?int(DT_PREC_3/atof(dbrow[29])):0, // MaxFPS - atoi(dbrow[30]), // FPSReportInterval - atoi(dbrow[31]), // RefBlendPerc - atoi(dbrow[32]), // TrackMotion + dbrow[19], // EventPrefix + dbrow[20], // LabelFormat + Coord( atoi(dbrow[21]), atoi(dbrow[22]) ), // LabelX, LabelY + atoi(dbrow[23]), // ImageBufferCount + atoi(dbrow[24]), // WarmupCount + atoi(dbrow[25]), // PreEventCount + atoi(dbrow[26]), // PostEventCount + atoi(dbrow[27]), // AlarmFrameCount + atoi(dbrow[28]), // SectionLength + atoi(dbrow[29]), // FrameSkip + atof(dbrow[30])>0.0?int(DT_PREC_3/atof(dbrow[30])):0, // MaxFPS + atoi(dbrow[31]), // FPSReportInterval + atoi(dbrow[32]), // RefBlendPerc + atoi(dbrow[33]), // TrackMotion purpose ); @@ -1481,8 +1586,7 @@ void Monitor::StreamImages( int scale, int maxfps, time_t ttl ) if ( ttl ) { - time_t now; - time( &now ); + time_t now = time ( 0 ); if ( (now - stream_start_time) > ttl ) { break; @@ -1565,9 +1669,7 @@ void Monitor::StreamImagesRaw( int scale, int maxfps, time_t ttl ) if ( ttl ) { - time_t now; - time( &now ); - if ( (now - stream_start_time) > ttl ) + if ( (time(0) - stream_start_time) > ttl ) { break; } @@ -1712,55 +1814,136 @@ void Monitor::StreamMpeg( const char *format, int scale, int maxfps, int bitrate } #endif // HAVE_LIBAVCODEC -bool Monitor::DumpSettings( char *output, bool verbose ) +int Monitor::PostCapture() { - output[0] = 0; + if ( camera->PostCapture( image ) == 0 ) + { + if ( orientation != ROTATE_0 ) + { + switch ( orientation ) + { + case ROTATE_90 : + case ROTATE_180 : + case ROTATE_270 : + { + image.Rotate( (orientation-1)*90 ); + break; + } + case FLIP_HORI : + case FLIP_VERT : + { + image.Flip( orientation==FLIP_HORI ); + break; + } + } + } - sprintf( output+strlen(output), "Id : %d\n", id ); - sprintf( output+strlen(output), "Name : %s\n", name ); - sprintf( output+strlen(output), "Type : %s\n", camera->IsLocal()?"Local":"Remote" ); - if ( camera->IsLocal() ) - { - sprintf( output+strlen(output), "Device : %s\n", ((LocalCamera *)camera)->Device() ); - sprintf( output+strlen(output), "Channel : %d\n", ((LocalCamera *)camera)->Channel() ); - sprintf( output+strlen(output), "Format : %d\n", ((LocalCamera *)camera)->Format() ); + int index = image_count%image_buffer_count; + + if ( index == shared_data->last_read_index && function > MONITOR ) + { + Warning(( "Buffer overrun at index %d, slow down capture, speed up analysis or increase ring buffer size", index )); + } + + gettimeofday( image_buffer[index].timestamp, &dummy_tz ); + if ( config.timestamp_on_capture ) + { + TimestampImage( &image, image_buffer[index].timestamp->tv_sec ); + } + image_buffer[index].image->CopyBuffer( image ); + + shared_data->last_write_index = index; + shared_data->last_image_time = image_buffer[index].timestamp->tv_sec; + + image_count++; + + if ( image_count && !(image_count%fps_report_interval) ) + { + time_t now = image_buffer[index].timestamp->tv_sec; + fps = double(fps_report_interval)/(now-last_fps_time); + //Info(( "%d -> %d -> %d", fps_report_interval, now, last_fps_time )); + //Info(( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps )); + Info(( "%s: %d - Capturing at %.2lf fps", name, image_count, fps )); + last_fps_time = now; + } + + if ( shared_data->action & GET_SETTINGS ) + { + shared_data->brightness = camera->Brightness(); + shared_data->hue = camera->Hue(); + shared_data->colour = camera->Colour(); + shared_data->contrast = camera->Contrast(); + shared_data->action &= ~GET_SETTINGS; + } + if ( shared_data->action & SET_SETTINGS ) + { + camera->Brightness( shared_data->brightness ); + camera->Hue( shared_data->hue ); + camera->Colour( shared_data->colour ); + camera->Contrast( shared_data->contrast ); + shared_data->action &= ~SET_SETTINGS; + } + return( 0 ); } - else + return( -1 ); +} + +void Monitor::TimestampImage( Image *ts_image, time_t ts_time ) const +{ + if ( label_format[0] ) { - sprintf( output+strlen(output), "Host : %s\n", ((RemoteCamera *)camera)->Host() ); - sprintf( output+strlen(output), "Port : %s\n", ((RemoteCamera *)camera)->Port() ); - sprintf( output+strlen(output), "Path : %s\n", ((RemoteCamera *)camera)->Path() ); + static int token_count = -1; + static char label_time_text[256]; + static char label_text[256]; + + if ( token_count < 0 ) + { + const char *token_ptr = label_format; + const char *token_string = "%%s"; + token_count = 0; + while( token_ptr = strstr( token_ptr, token_string ) ) + { + token_count++; + token_ptr += strlen(token_string); + } + } + strftime( label_time_text, sizeof(label_time_text), label_format, localtime( &ts_time ) ); + switch ( token_count ) + { + case 0: + { + strncpy( label_text, label_time_text, sizeof(label_text) ); + break; + } + case 1: + { + snprintf( label_text, sizeof(label_text), label_time_text, name ); + break; + } + case 2: + { + snprintf( label_text, sizeof(label_text), label_time_text, name, trigger_data->trigger_showtext ); + break; + } + } + + ts_image->Annotate( label_text, label_coord ); } - sprintf( output+strlen(output), "Width : %d\n", camera->Width() ); - sprintf( output+strlen(output), "Height : %d\n", camera->Height() ); - sprintf( output+strlen(output), "Palette : %d\n", camera->Palette() ); - sprintf( output+strlen(output), "Colours : %d\n", camera->Colours() ); - sprintf( output+strlen(output), "Event Prefix : %s\n", event_prefix ); - sprintf( output+strlen(output), "Label Format : %s\n", label_format ); - sprintf( output+strlen(output), "Label Coord : %d,%d\n", label_coord.X(), label_coord.Y() ); - sprintf( output+strlen(output), "Image Buffer Count : %d\n", image_buffer_count ); - sprintf( output+strlen(output), "Warmup Count : %d\n", warmup_count ); - sprintf( output+strlen(output), "Pre Event Count : %d\n", pre_event_count ); - sprintf( output+strlen(output), "Post Event Count : %d\n", post_event_count ); - sprintf( output+strlen(output), "Alarm Frame Count : %d\n", alarm_frame_count ); - sprintf( output+strlen(output), "Section Length : %d\n", section_length ); - sprintf( output+strlen(output), "Maximum FPS : %.2f\n", capture_delay?DT_PREC_3/capture_delay:0.0 ); - sprintf( output+strlen(output), "Reference Blend %%ge : %d\n", ref_blend_perc ); - sprintf( output+strlen(output), "Track Motion : %d\n", track_motion ); - sprintf( output+strlen(output), "Function: %d - %s\n", function, - function==OFF?"None":( - function==MONITOR?"Monitor":( - function==MODECT?"Motion Detection":( - function==RECORD?"Continuous Record":( - function==MOCORD?"Continuous Record with Motion Detection":( - function==NODECT?"Externally Triggered only, no Motion Detection":"Unknown" - )))))); - sprintf( output+strlen(output), "Zones : %d\n", n_zones ); - for ( int i = 0; i < n_zones; i++ ) +} + +bool Monitor::closeEvent() +{ + if ( event ) { - zones[i]->DumpSettings( output+strlen(output), verbose ); + if ( function == RECORD || function == MOCORD ) + { + gettimeofday( &(event->EndTime()), &dummy_tz ); + } + delete event; + event = 0; + return( true ); } - return( true ); + return( false ); } unsigned int Monitor::Compare( const Image &comp_image ) @@ -1908,7 +2091,7 @@ unsigned int Monitor::Compare( const Image &comp_image ) } } - if ( (activity_state == ACTIVE) && (top_score > 0) ) + if ( top_score > 0 ) { shared_data->alarm_x = alarm_centre.X(); shared_data->alarm_y = alarm_centre.Y(); @@ -1924,3 +2107,55 @@ unsigned int Monitor::Compare( const Image &comp_image ) // This is a small and innocent hack to prevent scores of 0 being returned in alarm state return( score?score:alarm ); } + +bool Monitor::DumpSettings( char *output, bool verbose ) +{ + output[0] = 0; + + sprintf( output+strlen(output), "Id : %d\n", id ); + sprintf( output+strlen(output), "Name : %s\n", name ); + sprintf( output+strlen(output), "Type : %s\n", camera->IsLocal()?"Local":"Remote" ); + if ( camera->IsLocal() ) + { + sprintf( output+strlen(output), "Device : %s\n", ((LocalCamera *)camera)->Device() ); + sprintf( output+strlen(output), "Channel : %d\n", ((LocalCamera *)camera)->Channel() ); + sprintf( output+strlen(output), "Format : %d\n", ((LocalCamera *)camera)->Format() ); + } + else + { + sprintf( output+strlen(output), "Host : %s\n", ((RemoteCamera *)camera)->Host() ); + sprintf( output+strlen(output), "Port : %s\n", ((RemoteCamera *)camera)->Port() ); + sprintf( output+strlen(output), "Path : %s\n", ((RemoteCamera *)camera)->Path() ); + } + sprintf( output+strlen(output), "Width : %d\n", camera->Width() ); + sprintf( output+strlen(output), "Height : %d\n", camera->Height() ); + sprintf( output+strlen(output), "Palette : %d\n", camera->Palette() ); + sprintf( output+strlen(output), "Colours : %d\n", camera->Colours() ); + sprintf( output+strlen(output), "Event Prefix : %s\n", event_prefix ); + sprintf( output+strlen(output), "Label Format : %s\n", label_format ); + sprintf( output+strlen(output), "Label Coord : %d,%d\n", label_coord.X(), label_coord.Y() ); + sprintf( output+strlen(output), "Image Buffer Count : %d\n", image_buffer_count ); + sprintf( output+strlen(output), "Warmup Count : %d\n", warmup_count ); + sprintf( output+strlen(output), "Pre Event Count : %d\n", pre_event_count ); + sprintf( output+strlen(output), "Post Event Count : %d\n", post_event_count ); + sprintf( output+strlen(output), "Alarm Frame Count : %d\n", alarm_frame_count ); + sprintf( output+strlen(output), "Section Length : %d\n", section_length ); + sprintf( output+strlen(output), "Maximum FPS : %.2f\n", capture_delay?DT_PREC_3/capture_delay:0.0 ); + sprintf( output+strlen(output), "Reference Blend %%ge : %d\n", ref_blend_perc ); + sprintf( output+strlen(output), "Track Motion : %d\n", track_motion ); + sprintf( output+strlen(output), "Function: %d - %s\n", function, + function==NONE?"None":( + function==MONITOR?"Monitor":( + function==MODECT?"Motion Detection":( + function==RECORD?"Continuous Record":( + function==MOCORD?"Continuous Record with Motion Detection":( + function==NODECT?"Externally Triggered only, no Motion Detection":"Unknown" + )))))); + sprintf( output+strlen(output), "Zones : %d\n", n_zones ); + for ( int i = 0; i < n_zones; i++ ) + { + zones[i]->DumpSettings( output+strlen(output), verbose ); + } + return( true ); +} + diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 0ad31e8e0..4d244a646 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -45,13 +45,7 @@ public: typedef enum { - CONTINUOUS=0, - TRIGGERED - } RunMode; - - typedef enum - { - OFF=1, + NONE=1, MONITOR, MODECT, RECORD, @@ -59,20 +53,33 @@ public: NODECT } Function; - typedef enum { ROTATE_0=1, ROTATE_90, ROTATE_180, ROTATE_270, FLIP_HORI, FLIP_VERT } Orientation; + typedef enum + { + ROTATE_0=1, + ROTATE_90, + ROTATE_180, + ROTATE_270, + FLIP_HORI, + FLIP_VERT + } Orientation; - typedef enum { IDLE, PREALARM, ALARM, ALERT, TAPE } State; - - typedef enum { ACTIVE, SUSPENDED, RESUMING } ActivityState; + typedef enum + { + IDLE, + PREALARM, + ALARM, + ALERT, + TAPE + } State; protected: // These are read from the DB and thereafter remain unchanged int id; char *name; Function function; // What the monitor is doing + bool enabled; // Whether the monitor is enabled or asleep unsigned int width; // Normally the same as the camera, but not if partly rotated unsigned int height; // Normally the same as the camera, but not if partly rotated - RunMode run_mode; // Whether the monitor is running continuously or is triggered Orientation orientation; // Whether the image has to be rotated at all int brightness; // The statically saved brightness of the camera int contrast; // The statically saved contrast of the camera @@ -98,10 +105,9 @@ protected: Image ref_image; Purpose purpose; // What this monitor has been created to do - ActivityState activity_state; int event_count; int image_count; - int resume_image_count; + int ready_count; int first_alarm_count; int last_alarm_count; int buffer_count; @@ -112,6 +118,7 @@ protected: Event *event; time_t start_time; time_t last_fps_time; + time_t auto_resume_time; int shmid; typedef struct Snapshot @@ -122,11 +129,12 @@ protected: Snapshot *image_buffer; - typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, SUSPEND=0x4, RESUME=0x8 } Action; + typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action; typedef struct { int size; bool valid; + bool active; State state; int last_write_index; int last_read_index; @@ -158,7 +166,7 @@ protected: Camera *camera; public: - Monitor( int p_id, char *p_name, int p_function, 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 ); + 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 ); ~Monitor(); void Setup(); @@ -178,10 +186,36 @@ public: { return( name ); } + inline Function GetFunction() const + { + return( function ); + } inline const char *EventPrefix() const { return( event_prefix ); } + inline bool Ready() + { + if ( function <= MONITOR ) + return( false ); + return( image_count > ready_count ); + } + inline bool Enabled() + { + if ( function <= MONITOR ) + return( false ); + return( enabled ); + } + inline bool Active() + { + if ( function <= MONITOR ) + return( false ); + return( enabled && shared_data->active ); + } + + unsigned int Width() const { return( width ); } + unsigned int Height() const { return( height ); } + State GetState() const; int GetImage( int index=-1, int scale=100 ) const; struct timeval GetTimestamp( int index=-1 ) const; @@ -194,153 +228,36 @@ public: void ForceAlarmOff(); void CancelForced(); TriggerState GetTriggerState() const { return( trigger_data?trigger_data->trigger_state:TRIGGER_CANCEL ); } - void Suspend(); - void Resume(); - inline void TimestampImage( Image *ts_image, time_t ts_time ) const - { - if ( label_format[0] ) - { - static int token_count = -1; - static char label_time_text[256]; - static char label_text[256]; + void actionReload(); + void actionEnable(); + void actionDisable(); + void actionSuspend(); + void actionResume(); - if ( token_count < 0 ) - { - const char *token_ptr = label_format; - const char *token_string = "%%s"; - token_count = 0; - while( token_ptr = strstr( token_ptr, token_string ) ) - { - token_count++; - token_ptr += strlen(token_string); - } - } - strftime( label_time_text, sizeof(label_time_text), label_format, localtime( &ts_time ) ); - switch ( token_count ) - { - case 0: - { - strncpy( label_text, label_time_text, sizeof(label_text) ); - break; - } - case 1: - { - snprintf( label_text, sizeof(label_text), label_time_text, name ); - break; - } - case 2: - { - snprintf( label_text, sizeof(label_text), label_time_text, name, trigger_data->trigger_showtext ); - break; - } - } + int actionBrightness( int p_brightness=-1 ); + int actionHue( int p_hue=-1 ); + int actionColour( int p_colour=-1 ); + int actionContrast( int p_contrast=-1 ); - ts_image->Annotate( label_text, label_coord ); - } - } - int Brightness( int p_brightness=-1 ); - int Hue( int p_hue=-1 ); - int Colour( int p_colour=-1 ); - int Contrast( int p_contrast=-1 ); - - bool DumpSettings( char *output, bool verbose ); - void DumpZoneImage( const char *zone_string=0 ); - - unsigned int Width() const { return( width ); } - unsigned int Height() const { return( height ); } inline int PreCapture() { return( camera->PreCapture() ); } - inline int PostCapture() - { - if ( camera->PostCapture( image ) == 0 ) - { - if ( orientation != ROTATE_0 ) - { - switch ( orientation ) - { - case ROTATE_90 : - case ROTATE_180 : - case ROTATE_270 : - { - image.Rotate( (orientation-1)*90 ); - break; - } - case FLIP_HORI : - case FLIP_VERT : - { - image.Flip( orientation==FLIP_HORI ); - break; - } - } - } - - int index = image_count%image_buffer_count; - - if ( index == shared_data->last_read_index && function > MONITOR ) - { - Warning(( "Buffer overrun at index %d, slow down capture, speed up analysis or increase ring buffer size", index )); - } - - gettimeofday( image_buffer[index].timestamp, &dummy_tz ); - if ( config.timestamp_on_capture ) - { - TimestampImage( &image, image_buffer[index].timestamp->tv_sec ); - } - image_buffer[index].image->CopyBuffer( image ); - - shared_data->last_write_index = index; - shared_data->last_image_time = image_buffer[index].timestamp->tv_sec; - - image_count++; - - if ( image_count && !(image_count%fps_report_interval) ) - { - time_t now = image_buffer[index].timestamp->tv_sec; - fps = double(fps_report_interval)/(now-last_fps_time); - //Info(( "%d -> %d -> %d", fps_report_interval, now, last_fps_time )); - //Info(( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps )); - Info(( "%s: %d - Capturing at %.2lf fps", name, image_count, fps )); - last_fps_time = now; - } - - if ( shared_data->action & GET_SETTINGS ) - { - shared_data->brightness = camera->Brightness(); - shared_data->hue = camera->Hue(); - shared_data->colour = camera->Colour(); - shared_data->contrast = camera->Contrast(); - shared_data->action &= ~GET_SETTINGS; - } - if ( shared_data->action & SET_SETTINGS ) - { - camera->Brightness( shared_data->brightness ); - camera->Hue( shared_data->hue ); - camera->Colour( shared_data->colour ); - camera->Contrast( shared_data->contrast ); - shared_data->action &= ~SET_SETTINGS; - } - return( 0 ); - } - return( -1 ); - } - - inline bool Ready() - { - if ( function <= MONITOR ) - return( false ); - if ( image_count <= warmup_count ) - return( false ); - return( true ); - } - - void DumpImage( Image *dump_image ) const; - bool Analyse(); + int PostCapture(); unsigned int Compare( const Image &comp_image ); + bool Analyse(); + void DumpImage( Image *dump_image ) const; + void TimestampImage( Image *ts_image, time_t ts_time ) const; + bool closeEvent(); + + void Reload(); void ReloadZones(); + + bool DumpSettings( char *output, bool verbose ); + void DumpZoneImage( const char *zone_string=0 ); + static int LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose purpose=QUERY ); static int LoadRemoteMonitors( const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose=QUERY ); static int LoadFileMonitors( const char *file, Monitor **&monitors, Purpose purpose=QUERY ); diff --git a/src/zma.cpp b/src/zma.cpp index 0722490be..a21be6216 100644 --- a/src/zma.cpp +++ b/src/zma.cpp @@ -58,6 +58,24 @@ void zm_term_handler( int signal ) zma_terminate = true; } +bool zma_reload = false; + +void zm_hup_handler( int signal ) +{ +#if HAVE_DECL_STRSIGNAL + char * error = strsignal(signal); + size_t errorStringSize = strlen(error) + strlen("Got signal (), reloading."); + char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char. + (void) snprintf(errorString, errorStringSize, "Got signal (%s), reloading.", error); + + Info(( (const char *)errorString )); + free(errorString); +#else /* HAVE_DECL_STRSIGNAL */ + Info(( "Got HUP signal, reloading" )); +#endif /* HAVE_DECL_STRSIGNAL */ + zma_reload = true; +} + void Usage() { fprintf( stderr, "zma -m \n" ); @@ -129,7 +147,7 @@ int main( int argc, char *argv[] ) if ( monitor ) { - Info(( "Warming up" )); + Info(( "In mode %d/%d, warming up", monitor->GetFunction(), monitor->Enabled() )); if ( config.opt_frame_server ) { @@ -140,6 +158,11 @@ int main( int argc, char *argv[] ) sigemptyset( &block_set ); struct sigaction action, old_action; + action.sa_handler = zm_hup_handler; + action.sa_mask = block_set; + action.sa_flags = 0; + sigaction( SIGHUP, &action, &old_action ); + action.sa_handler = zm_term_handler; action.sa_mask = block_set; action.sa_flags = 0; @@ -157,7 +180,12 @@ int main( int argc, char *argv[] ) sigprocmask( SIG_BLOCK, &block_set, 0 ); if ( !monitor->Analyse() ) { - usleep( ZM_SAMPLE_RATE ); // Nyquist sampling rate at 30fps, wouldn't expect any more than this + usleep( monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE ); + } + if ( zma_reload ) + { + monitor->Reload(); + zma_reload = false; } sigprocmask( SIG_UNBLOCK, &block_set, 0 ); } diff --git a/src/zmu.cpp b/src/zmu.cpp index c29dd99e1..4e7c8f165 100644 --- a/src/zmu.cpp +++ b/src/zmu.cpp @@ -58,6 +58,9 @@ void Usage( int status=-1 ) fprintf( stderr, " -a, --alarm : Force alarm in monitor, this will trigger recording until cancelled with -c\n" ); fprintf( stderr, " -n, --noalarm : Force no alarms in monitor, this will prevent alarms until cancelled with -c\n" ); fprintf( stderr, " -c, --cancel : Cancel a forced alarm/noalarm in monitor, required after being enabled with -a or -n\n" ); + fprintf( stderr, " -L, --reload : Signal monitor to reload settings\n" ); + fprintf( stderr, " -E, --enable : Enable detection, wake monitor up\n" ); + fprintf( stderr, " -D, --disable : Disble detection, put monitor to sleep\n" ); fprintf( stderr, " -u, --suspend : Suspend detection, useful to prevent bogus alarms when panning etc\n" ); fprintf( stderr, " -r, --resume : Resume detection after a suspend\n" ); fprintf( stderr, " -U, --username : When running in authenticated mode the username and\n" ); @@ -85,8 +88,11 @@ typedef enum { CONTRAST = 0x00002000, HUE = 0x00004000, COLOUR = 0x00008000, - SUSPEND = 0x00010000, - RESUME = 0x00020000, + RELOAD = 0x00010000, + ENABLE = 0x00100000, + DISABLE = 0x00200000, + SUSPEND = 0x00400000, + RESUME = 0x00800000, LIST = 0x10000000, } Function; @@ -108,7 +114,7 @@ bool ValidateAccess( User *user, int mon_id, int function ) if ( user->getMonitors() < User::PERM_VIEW ) allowed = false; } - if ( function & (ALARM|NOALARM|CANCEL|SUSPEND|RESUME|BRIGHTNESS|CONTRAST|HUE|COLOUR) ) + if ( function & (ALARM|NOALARM|CANCEL|RELOAD|ENABLE|DISABLE|SUSPEND|RESUME|BRIGHTNESS|CONTRAST|HUE|COLOUR) ) { if ( user->getMonitors() < User::PERM_EDIT ) allowed = false; @@ -150,6 +156,9 @@ int main( int argc, char *argv[] ) {"alarm", 0, 0, 'a'}, {"noalarm", 0, 0, 'n'}, {"cancel", 0, 0, 'c'}, + {"reload", 0, 0, 'L'}, + {"enable", 0, 0, 'E'}, + {"disable", 0, 0, 'D'}, {"suspend", 0, 0, 'u'}, {"resume", 0, 0, 'r'}, {"query", 0, 0, 'q'}, @@ -179,7 +188,7 @@ int main( int argc, char *argv[] ) { int option_index = 0; - int c = getopt_long (argc, argv, "d:m:vsurwei::S:t::fz::ancqhlB::C::H::O::U:P:A:", long_options, &option_index); + int c = getopt_long (argc, argv, "d:m:vsEDurwei::S:t::fz::ancqhlB::C::H::O::U:P:A:", long_options, &option_index); if (c == -1) { break; @@ -244,6 +253,15 @@ int main( int argc, char *argv[] ) case 'c': function |= CANCEL; break; + case 'L': + function |= RELOAD; + break; + case 'E': + function |= ENABLE; + break; + case 'D': + function |= DISABLE; + break; case 'u': function |= SUSPEND; break; @@ -498,17 +516,35 @@ int main( int argc, char *argv[] ) printf( "Cancelling forced alarm on/off\n" ); monitor->CancelForced(); } + if ( function & RELOAD ) + { + if ( verbose ) + printf( "Reloading monitor settings\n" ); + monitor->actionReload(); + } + if ( function & ENABLE ) + { + if ( verbose ) + printf( "Enabling event generation\n" ); + monitor->actionEnable(); + } + if ( function & DISABLE ) + { + if ( verbose ) + printf( "Disabling event generation\n" ); + monitor->actionDisable(); + } if ( function & SUSPEND ) { if ( verbose ) - printf( "Suspending motion detection\n" ); - monitor->Suspend(); + printf( "Suspending event generation\n" ); + monitor->actionSuspend(); } if ( function & RESUME ) { if ( verbose ) - printf( "Resuming motion detection\n" ); - monitor->Resume(); + printf( "Resuming event generation\n" ); + monitor->actionResume(); } if ( function & QUERY ) { @@ -521,17 +557,17 @@ int main( int argc, char *argv[] ) if ( verbose ) { if ( brightness >= 0 ) - printf( "New brightness: %d\n", monitor->Brightness( brightness ) ); + printf( "New brightness: %d\n", monitor->actionBrightness( brightness ) ); else - printf( "Current brightness: %d\n", monitor->Brightness() ); + printf( "Current brightness: %d\n", monitor->actionBrightness() ); } else { if ( have_output ) printf( "%c", separator ); if ( brightness >= 0 ) - printf( "%d", monitor->Brightness( brightness ) ); + printf( "%d", monitor->actionBrightness( brightness ) ); else - printf( "%d", monitor->Brightness() ); + printf( "%d", monitor->actionBrightness() ); have_output = true; } } @@ -540,17 +576,17 @@ int main( int argc, char *argv[] ) if ( verbose ) { if ( contrast >= 0 ) - printf( "New brightness: %d\n", monitor->Contrast( contrast ) ); + printf( "New brightness: %d\n", monitor->actionContrast( contrast ) ); else - printf( "Current contrast: %d\n", monitor->Contrast() ); + printf( "Current contrast: %d\n", monitor->actionContrast() ); } else { if ( have_output ) printf( "%c", separator ); if ( contrast >= 0 ) - printf( "%d", monitor->Contrast( contrast ) ); + printf( "%d", monitor->actionContrast( contrast ) ); else - printf( "%d", monitor->Contrast() ); + printf( "%d", monitor->actionContrast() ); have_output = true; } } @@ -559,17 +595,17 @@ int main( int argc, char *argv[] ) if ( verbose ) { if ( hue >= 0 ) - printf( "New hue: %d\n", monitor->Hue( hue ) ); + printf( "New hue: %d\n", monitor->actionHue( hue ) ); else - printf( "Current hue: %d\n", monitor->Hue() ); + printf( "Current hue: %d\n", monitor->actionHue() ); } else { if ( have_output ) printf( "%c", separator ); if ( hue >= 0 ) - printf( "%d", monitor->Hue( hue ) ); + printf( "%d", monitor->actionHue( hue ) ); else - printf( "%d", monitor->Hue() ); + printf( "%d", monitor->actionHue() ); have_output = true; } } @@ -578,17 +614,17 @@ int main( int argc, char *argv[] ) if ( verbose ) { if ( colour >= 0 ) - printf( "New colour: %d\n", monitor->Colour( colour ) ); + printf( "New colour: %d\n", monitor->actionColour( colour ) ); else - printf( "Current colour: %d\n", monitor->Colour() ); + printf( "Current colour: %d\n", monitor->actionColour() ); } else { if ( have_output ) printf( "%c", separator ); if ( colour >= 0 ) - printf( "%d", monitor->Colour( colour ) ); + printf( "%d", monitor->actionColour( colour ) ); else - printf( "%d", monitor->Colour() ); + printf( "%d", monitor->actionColour() ); have_output = true; } }