From 0aafd9d30bcd5d8608de779b98ad54f05cb93e2a Mon Sep 17 00:00:00 2001 From: stan Date: Wed, 14 Jan 2004 21:26:47 +0000 Subject: [PATCH] Applied Ian@zestysoft changes. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@744 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/Makefile.am | 2 +- src/Makefile.in | 2 +- src/zm_camera.h | 8 ++--- src/zm_config.cpp | 4 +-- src/zm_debug.c | 38 +++++++++++------------ src/zm_debug.h | 46 ++++++++++++++++------------ src/zm_event.cpp | 19 +++++++++--- src/zm_image.cpp | 3 -- src/zm_image.h | 17 +++++------ src/zm_jpeg.c | 6 ++-- src/zm_jpeg.h | 26 ++++++++++++++++ src/zm_monitor.cpp | 65 +++++++++++++++++++++------------------- src/zm_monitor.h | 9 +++--- src/zm_remote_camera.cpp | 11 ++++--- src/zm_zone.cpp | 2 +- src/zma.cpp | 16 ++++++++-- src/zmc.cpp | 18 ++++++----- src/zmf.cpp | 30 +++++++++++++------ src/zmf.h | 8 ++--- src/zms.cpp | 6 ++-- src/zmu.cpp | 4 +-- 21 files changed, 204 insertions(+), 136 deletions(-) create mode 100644 src/zm_jpeg.h diff --git a/src/Makefile.am b/src/Makefile.am index b6188c448..4ea1d1023 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ zmu_SOURCES = zmu.cpp $(zm_SOURCES) zmf_SOURCES = zmf.cpp $(zm_SOURCES) zmfix_SOURCES = zmfix.cpp zm_debug.c zm_db.cpp zm.cpp -noinst_HEADERS = zm.h zm_db.h zm_font.h zm_rgb.h zm_config.h zm_config_defines.h zm_debug.h zm_coord.h zm_box.h zm_image.h zm_event.h zm_zone.h zm_camera.h zm_local_camera.h zm_remote_camera.h zm_monitor.h zm_font.h jinclude.h zmf.h +noinst_HEADERS = zm.h zm_db.h zm_font.h zm_rgb.h zm_config.h zm_config_defines.h zm_debug.h zm_coord.h zm_box.h zm_image.h zm_event.h zm_zone.h zm_camera.h zm_local_camera.h zm_remote_camera.h zm_monitor.h zm_font.h jinclude.h zmf.h zm_jpeg.h EXTRA_DIST = zm_config.h.z diff --git a/src/Makefile.in b/src/Makefile.in index a8c6b412f..51bdb5332 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -136,7 +136,7 @@ zmu_SOURCES = zmu.cpp $(zm_SOURCES) zmf_SOURCES = zmf.cpp $(zm_SOURCES) zmfix_SOURCES = zmfix.cpp zm_debug.c zm_db.cpp zm.cpp -noinst_HEADERS = zm.h zm_db.h zm_font.h zm_rgb.h zm_config.h zm_config_defines.h zm_debug.h zm_coord.h zm_box.h zm_image.h zm_event.h zm_zone.h zm_camera.h zm_local_camera.h zm_remote_camera.h zm_monitor.h zm_font.h jinclude.h zmf.h +noinst_HEADERS = zm.h zm_db.h zm_font.h zm_rgb.h zm_config.h zm_config_defines.h zm_debug.h zm_coord.h zm_box.h zm_image.h zm_event.h zm_zone.h zm_camera.h zm_local_camera.h zm_remote_camera.h zm_monitor.h zm_font.h jinclude.h zmf.h zm_jpeg.h EXTRA_DIST = zm_config.h.z subdir = src diff --git a/src/zm_camera.h b/src/zm_camera.h index f4c234d84..0a32ebccc 100644 --- a/src/zm_camera.h +++ b/src/zm_camera.h @@ -55,10 +55,10 @@ public: unsigned int Colours() const { return( colours ); } unsigned int ImageSize() const { return( colours*width*height ); } - virtual int Brightness( int p_brightness=-1 ) { return( -1 ); } - virtual int Hue( int p_hue=-1 ) { return( -1 ); } - virtual int Colour( int p_colour=-1 ) { return( -1 ); } - virtual int Contrast( int p_contrast=-1 ) { return( -1 ); } + virtual int Brightness( int/*p_brightness*/=-1 ) { return( -1 ); } + virtual int Hue( int/*p_hue*/=-1 ) { return( -1 ); } + virtual int Colour( int/*p_colour*/=-1 ) { return( -1 ); } + virtual int Contrast( int/*p_contrast*/=-1 ) { return( -1 ); } bool CanCapture() const { return( capture ); } diff --git a/src/zm_config.cpp b/src/zm_config.cpp index dee4999e1..930abee58 100644 --- a/src/zm_config.cpp +++ b/src/zm_config.cpp @@ -49,7 +49,7 @@ void ConfigItem::ConvertValue() const if ( !strcmp( type, "boolean" ) ) { cfg_type = CFG_BOOLEAN; - cfg_value.boolean_value = strtol( value, 0, 2 ); + cfg_value.boolean_value = (bool)strtol( value, 0, 2 ); } else if ( !strcmp( type, "integer" ) ) { @@ -64,7 +64,7 @@ void ConfigItem::ConvertValue() const else if ( !strcmp( type, "decimal" ) ) { cfg_type = CFG_DECIMAL; - cfg_value.decimal_value = atof( value ); + cfg_value.decimal_value = strtod( value, 0 ); } else { diff --git a/src/zm_debug.c b/src/zm_debug.c index 0e0a795f2..db6a64efc 100644 --- a/src/zm_debug.c +++ b/src/zm_debug.c @@ -1,21 +1,21 @@ -// -// ZoneMinder Debug Implementation, $Date$, $Revision$ -// Copyright (C) 2003 Philip Coombes -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +/* + * ZoneMinder Debug Implementation, $Date$, $Revision$ + * Copyright (C) 2003 Philip Coombes + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ #include #include @@ -346,7 +346,7 @@ int zmDbgOutput( const char *fstring, ... ) log_code = LOG_CRIT; break; default: - //log_code = LOG_DEBUG; + /* log_code = LOG_DEBUG; */ log_code = LOG_INFO; break; } diff --git a/src/zm_debug.h b/src/zm_debug.h index f98241013..2f2d5b63b 100644 --- a/src/zm_debug.h +++ b/src/zm_debug.h @@ -1,21 +1,21 @@ -// -// ZoneMinder Debug Interface, $Date$, $Revision$ -// Copyright (C) 2003 Philip Coombes -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// +/* + * ZoneMinder Debug Interface, $Date$, $Revision$ + * Copyright (C) 2003 Philip Coombes + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ #include @@ -94,6 +94,14 @@ extern "C" { #endif +/* function declarations */ +void zmUsrHandler( int sig ); +int zmGetDebugEnv( const char * const command ); +int zmDebugInitialise( void ); +int zmDebugTerminate( void ); +void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 ); + + #if defined(__STDC__) || defined(__cplusplus) int zmDbgInit(void); int zmDbgTerm(void); @@ -119,7 +127,7 @@ extern int zm_dbg_flush; extern int zm_dbg_add_log_id; #ifdef __cplusplus -} //extern "C" +} /* extern "C" */ #endif #else diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 9284cf139..5086884aa 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -167,15 +167,26 @@ bool Event::SendFrameImage( const Image *image, bool alarm_frame ) iovecs[1].iov_base = jpg_buffer; iovecs[1].iov_len = jpg_buffer_size; - if ( writev( sd, iovecs, sizeof(iovecs)/sizeof(*iovecs) ) != sizeof(frame_header)+jpg_buffer_size ) + ssize_t writev_size = sizeof(frame_header)+jpg_buffer_size; + ssize_t writev_result = writev( sd, iovecs, sizeof(iovecs)/sizeof(*iovecs)); + if ( writev_result != writev_size ) { - if ( errno == EAGAIN ) + if ( writev_result < 0 ) { - Warning(( "Blocking write detected" )); + if ( errno == EAGAIN ) + { + Warning(( "Blocking write detected" )); + } + else + { + Error(( "Can't write frame: %s", strerror(errno) )); + close( sd ); + sd = -1; + } } else { - Error(( "Can't write frame: %s", strerror(errno) )); + Error(( "Incomplete frame write: %d of %d bytes written", writev_result, writev_size )); close( sd ); sd = -1; } diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 839ec769e..4bb2773a1 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -16,7 +16,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // - #include "zm.h" #include "zm_font.h" #include "zm_image.h" @@ -454,8 +453,6 @@ Image *Image::Delta( const Image &image ) const Image *result = new Image( width, height, 1 ); - typedef JSAMPLE IMAGE[width][height][colours]; - unsigned char *psrc = buffer; unsigned char *pref = image.buffer; unsigned char *pdiff = result->buffer; diff --git a/src/zm_image.h b/src/zm_image.h index 49cd99474..18d9c3303 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -30,14 +30,11 @@ extern "C" { -#include - #if !HAVE_DECL_ROUND double round(double); #endif -void jpeg_mem_src(j_decompress_ptr cinfo, JOCTET *inbuffer, int inbuffer_size ); -void jpeg_mem_dest(j_compress_ptr cinfo, JOCTET *outbuffer, int *outbuffer_size ); +#include "zm_jpeg.h" } #include "zm_rgb.h" @@ -78,17 +75,17 @@ public: height = p_height; colours = p_colours; size = width*height*colours; - if ( !p_buffer ) + if ( p_buffer ) + { + our_buffer = false; + buffer = p_buffer; + } + else { our_buffer = true; buffer = new JSAMPLE[size]; memset( buffer, 0, size ); } - else - { - our_buffer = false; - buffer = p_buffer; - } blend_buffer = 0; } Image( const Image &p_image ) diff --git a/src/zm_jpeg.c b/src/zm_jpeg.c index a54837d89..23672e2d8 100644 --- a/src/zm_jpeg.c +++ b/src/zm_jpeg.c @@ -17,9 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "jinclude.h" -#include "jpeglib.h" -#include "jerror.h" +#include "zm_jpeg.h" /* Expanded data destination object for memory */ @@ -218,7 +216,7 @@ static boolean fill_input_buffer (j_decompress_ptr cinfo) mem_src_ptr src = (mem_src_ptr) cinfo->src; size_t nbytes; - memcpy( src->buffer, src->inbuffer, src->inbuffer_size ); + memcpy( src->buffer, src->inbuffer, (size_t) src->inbuffer_size ); nbytes = src->inbuffer_size; if (nbytes <= 0) { diff --git a/src/zm_jpeg.h b/src/zm_jpeg.h new file mode 100644 index 000000000..e6c469318 --- /dev/null +++ b/src/zm_jpeg.h @@ -0,0 +1,26 @@ +/* + * ZoneMinder Jpeg Interface, $Date$, $Revision$ + * Copyright (C) 2003 Philip Coombes + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "jinclude.h" +#include "jpeglib.h" +#include "jerror.h" + +// Prototypes for memory compress/descompression object */ +void jpeg_mem_src(j_decompress_ptr cinfo, JOCTET *inbuffer, int inbuffer_size ); +void jpeg_mem_dest(j_compress_ptr cinfo, JOCTET *outbuffer, int *outbuffer_size ); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 15380a5a4..a6ea95d3b 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -301,11 +301,11 @@ int Monitor::GetImage( int index ) const index = shared_data->last_write_index; } Snapshot *snap = &image_buffer[index]; - Image *image = snap->image; + Image *snap_image = snap->image; char filename[64]; sprintf( filename, "%s.jpg", name ); - image->WriteJpeg( filename ); + snap_image->WriteJpeg( filename ); return( 0 ); } @@ -316,8 +316,8 @@ struct timeval Monitor::GetTimestamp( int index ) const index = shared_data->last_write_index; } - Info(( "Index %d = %x", index, image_buffer[index].timestamp )); - Info(( "Timestamp %d.%d", image_buffer[index].timestamp->tv_sec, image_buffer[index].timestamp->tv_usec )); + Info(( "Index %d = %p", index, (void *) image_buffer[index].timestamp )); + Info(( "Timestamp %ld.%ld", image_buffer[index].timestamp->tv_sec, image_buffer[index].timestamp->tv_usec )); Snapshot *snap = &image_buffer[index]; return( *(snap->timestamp) ); @@ -350,9 +350,9 @@ double Monitor::GetFPS() const Snapshot *snap2 = &image_buffer[index2]; time_t time2 = snap2->timestamp->tv_sec; - double fps = double(image_buffer_count)/(time1-time2); + double curr_fps = double(image_buffer_count)/(time1-time2); - return( fps ); + return( curr_fps ); } void Monitor::ForceAlarmOn() @@ -510,9 +510,9 @@ void Monitor::DumpZoneImage() { int index = shared_data->last_write_index; Snapshot *snap = &image_buffer[index]; - Image *image = snap->image; + Image *snap_image = snap->image; - Image zone_image( *image ); + Image zone_image( *snap_image ); zone_image.Colourise(); for( int i = 0; i < n_zones; i++ ) { @@ -544,7 +544,7 @@ void Monitor::DumpZoneImage() zone_image.WriteJpeg( filename ); } -void Monitor::DumpImage( Image *image ) const +void Monitor::DumpImage( Image *dump_image ) const { if ( image_count && !(image_count%10) ) { @@ -552,7 +552,7 @@ void Monitor::DumpImage( Image *image ) const static char filename[64]; sprintf( filename, "%s.jpg", name ); sprintf( new_filename, "%s-new.jpg", name ); - image->WriteJpeg( new_filename ); + dump_image->WriteJpeg( new_filename ); rename( new_filename, filename ); } } @@ -610,13 +610,16 @@ bool Monitor::Analyse() Snapshot *snap = &image_buffer[index]; struct timeval *timestamp = snap->timestamp; - Image *image = snap->image; + Image *snap_image = snap->image; + + static struct timeval **timestamps; + static const Image **images; unsigned int score = 0; if ( Ready() ) { if ( function != RECORD && shared_data->force_state != FORCE_OFF ) - score = Compare( *image ); + score = Compare( *snap_image ); if ( shared_data->force_state == FORCE_ON ) score = (int)config.Item( ZM_FORCED_ALARM_SCORE ); @@ -633,8 +636,8 @@ bool Monitor::Analyse() if ( 1 ) { int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; - struct timeval *timestamps[pre_event_count]; - const Image *images[pre_event_count]; + if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; + if ( !images ) images = new const Image *[pre_event_count]; for ( int i = 0; i < pre_event_count; i++ ) { timestamps[i] = image_buffer[pre_index].timestamp; @@ -657,8 +660,8 @@ bool Monitor::Analyse() event = new Event( this, *timestamp ); int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; - struct timeval *timestamps[pre_event_count]; - const Image *images[pre_event_count]; + if ( !timestamps ) timestamps = new struct timeval *[pre_event_count]; + if ( !images ) images = new const Image *[pre_event_count]; for ( int i = 0; i < pre_event_count; i++ ) { timestamps[i] = image_buffer[pre_index].timestamp; @@ -703,7 +706,7 @@ bool Monitor::Analyse() { if ( (bool)config.Item( ZM_CREATE_ANALYSIS_IMAGES ) ) { - Image alarm_image( *image ); + Image alarm_image( *snap_image ); for( int i = 0; i < n_zones; i++ ) { if ( zones[i]->Alarmed() ) @@ -715,22 +718,22 @@ bool Monitor::Analyse() } } } - event->AddFrame( *timestamp, image, score, &alarm_image ); + event->AddFrame( *timestamp, snap_image, score, &alarm_image ); } else { - event->AddFrame( *timestamp, image, score ); + event->AddFrame( *timestamp, snap_image, score ); } } else if ( state == ALERT ) { - event->AddFrame( *timestamp, image ); + event->AddFrame( *timestamp, snap_image ); } else if ( state == TAPE ) { if ( !(image_count%(frame_skip+1)) ) { - event->AddFrame( *timestamp, image ); + event->AddFrame( *timestamp, snap_image ); } } } @@ -751,8 +754,8 @@ bool Monitor::Analyse() if ( (bool)config.Item( ZM_BLEND_ALARMED_IMAGES ) || state != ALARM ) { - ref_image.Blend( *image, ref_blend_perc ); - //DumpImage( image ); + ref_image.Blend( *snap_image, ref_blend_perc ); + //DumpImage( snap_image ); } shared_data->last_read_index = index%image_buffer_count; @@ -1030,8 +1033,8 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, time_t tt int img_buffer_size = 0; int loop_count = (idle/refresh)-1; - time_t start_time; - time( &start_time ); + time_t stream_start_time; + time( &stream_start_time ); while ( true ) { @@ -1046,15 +1049,15 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, time_t tt int index = shared_data->last_write_index%image_buffer_count; //Info(( "%d: %x - %x", index, image_buffer[index].image, image_buffer[index].image->buffer )); Snapshot *snap = &image_buffer[index]; - Image *image = snap->image; + Image *snap_image = snap->image; if ( scale == 1 ) { - image->EncodeJpeg( img_buffer, &img_buffer_size ); + snap_image->EncodeJpeg( img_buffer, &img_buffer_size ); } else { - Image scaled_image( *image ); + Image scaled_image( *snap_image ); scaled_image.Scale( scale ); @@ -1075,7 +1078,7 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, time_t tt if ( ttl ) { time( &now ); - if ( (now - start_time) > ttl ) + if ( (now - stream_start_time) > ttl ) { break; } @@ -1130,14 +1133,14 @@ bool Monitor::DumpSettings( char *output, bool verbose ) return( true ); } -unsigned int Monitor::Compare( const Image &image ) +unsigned int Monitor::Compare( const Image &comp_image ) { bool alarm = false; unsigned int score = 0; if ( n_zones <= 0 ) return( alarm ); - Image *delta_image = ref_image.Delta( image ); + Image *delta_image = ref_image.Delta( comp_image ); // Blank out all exclusion zones for ( int n_zone = 0; n_zone < n_zones; n_zone++ ) diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 11ac948bd..2a783cbcc 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -83,12 +83,13 @@ protected: int fps_report_interval;// How many images should be captured/processed between reporting the current FPS int ref_blend_perc; // Percentage of new image going into reference image. - Image ref_image; - Purpose purpose; // What this monitor has been created to do double fps; Image image; + Image ref_image; + + Purpose purpose; // What this monitor has been created to do int event_count; int image_count; int first_alarm_count; @@ -251,7 +252,7 @@ public: return( function > MONITOR && image_count > warmup_count ); } - void DumpImage( Image *image ) const; + void DumpImage( Image *dump_image ) const; bool Analyse(); void Adjust( double ratio ) @@ -259,7 +260,7 @@ public: ref_image.Blend( image, 0.1 ); } - unsigned int Compare( const Image &image ); + unsigned int Compare( const Image &comp_image ); void ReloadZones(); static int Load( int device, Monitor **&monitors, Purpose purpose=QUERY ); static int Load( const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose=QUERY ); diff --git a/src/zm_remote_camera.cpp b/src/zm_remote_camera.cpp index 5328c1efd..412491d4c 100644 --- a/src/zm_remote_camera.cpp +++ b/src/zm_remote_camera.cpp @@ -156,14 +156,13 @@ int RemoteCamera::GetHeader( const char *content, const char *header, char *valu strcat( header_string, ":" ); char *header_ptr = strstr( content, header_string ); - if ( !header_ptr ) + int result = -1; + if ( header_ptr ) { - return( -1 ); + strcat( header_string, " %s" ); + result = sscanf( header_ptr, header_string, value ); + //Debug( 3, ( "R:%d, %s\n", result, value ); } - - strcat( header_string, " %s" ); - int result = sscanf( header_ptr, header_string, value ); - //Debug( 3, ( "R:%d, %s\n", result, value ); return( result ); } diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index d7b069e7f..be96d9994 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -466,7 +466,7 @@ int Zone::Load( Monitor *monitor, Zone **&zones ) return( n_zones ); } -bool Zone::DumpSettings( char *output, bool verbose ) +bool Zone::DumpSettings( char *output, bool /*verbose*/ ) { output[0] = 0; diff --git a/src/zma.cpp b/src/zma.cpp index df3bdd81b..9ea00e06e 100644 --- a/src/zma.cpp +++ b/src/zma.cpp @@ -26,7 +26,13 @@ void zm_die_handler( int signal ) { - Info(( "Got signal %d, crashing", signal )); + char * error = strsignal(signal); + size_t errorStringSize = strlen(error) + strlen("Got signal (), crashing."); + char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char. + (void) snprintf(errorString, errorStringSize, "Got signal (%s), crashing.", error); + + Info(( (const char *)errorString )); + free(errorString); exit( signal ); } @@ -34,7 +40,13 @@ bool zma_terminate = false; void zm_term_handler( int signal ) { - Info(( "Got TERM signal, exiting" )); + char * error = strsignal(signal); + size_t errorStringSize = strlen(error) + strlen("Got signal (), exiting."); + char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char. + (void) snprintf(errorString, errorStringSize, "Got signal (%s), exiting.", error); + + Info(( (const char *)errorString )); + free(errorString); zma_terminate = true; } diff --git a/src/zmc.cpp b/src/zmc.cpp index 33386fb85..bc9ff3bbc 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -27,7 +27,7 @@ bool zmc_terminate = false; -void zmc_term_handler( int signal ) +void zmc_term_handler( int /* signal */ ) { Info(( "Got TERM signal, exiting" )); zmc_terminate = true; @@ -46,9 +46,9 @@ void Usage() int main( int argc, char *argv[] ) { int device = -1; - char *host = ""; - char *port = ""; - char *path = ""; + const char *host = ""; + const char *port = ""; + const char *path = ""; static struct option long_options[] = { {"device", 1, 0, 'd'}, @@ -169,9 +169,9 @@ int main( int argc, char *argv[] ) monitors[0]->PreCapture(); } - long capture_delays[n_monitors]; - long next_delays[n_monitors]; - struct timeval last_capture_times[n_monitors]; + long *capture_delays = new long[n_monitors]; + long *next_delays = new long[n_monitors]; + struct timeval * last_capture_times = new struct timeval[n_monitors]; for ( int i = 0; i < n_monitors; i++ ) { last_capture_times[i].tv_sec = last_capture_times[i].tv_usec = 0; @@ -239,5 +239,9 @@ int main( int argc, char *argv[] ) { delete monitors[i]; } + delete [] capture_delays; + delete [] next_delays; + delete [] last_capture_times; + return( 0 ); } diff --git a/src/zmf.cpp b/src/zmf.cpp index faada2fce..71970a8b8 100644 --- a/src/zmf.cpp +++ b/src/zmf.cpp @@ -33,20 +33,32 @@ #include "zm.h" #include "zm_db.h" -#include "zm_debug.h" +//#include "zm_debug.h" #include "zm_monitor.h" #include "zmf.h" void zm_die_handler( int signal ) { - Info(( "Got signal %d, crashing", signal )); + char * error = strsignal(signal); + size_t errorStringSize = strlen(error) + strlen("Got signal (), crashing."); + char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char. + (void) snprintf(errorString, errorStringSize, "Got signal (%s), crashing.", error); + + Info(( (const char *)errorString )); + free(errorString); exit( signal ); } void zm_term_handler( int signal ) { - Info(( "Got TERM signal, exiting" )); + char * error = strsignal(signal); + size_t errorStringSize = strlen(error) + strlen("Got signal (), exiting."); + char * errorString =(char *) malloc(errorStringSize + 1); // plus 1 for termination char. + (void) snprintf(errorString, errorStringSize, "Got signal (%s), exiting.", error); + + Info(( (const char *)errorString )); + free(errorString); exit( 0 ); } @@ -200,8 +212,8 @@ int main( int argc, char *argv[] ) int sd = OpenSocket( monitor->Id() ); - FrameHeader frame_header = { -1, -1, false, -1 }; - unsigned char *image_data = 0; + FrameHeader frame_header = { 0, 0, false, 0 }; + //unsigned char *image_data = 0; fd_set rfds; @@ -233,15 +245,15 @@ int main( int argc, char *argv[] ) Error(( "Can't read frame header: %s", strerror(errno) )); ReopenSocket( sd, monitor->Id() ); } - Debug( 1, ( "Read frame header, expecting %d bytes of image", frame_header.image_length )); + Debug( 1, ( "Read frame header, expecting %ld bytes of image", frame_header.image_length )); static unsigned char image_data[ZM_MAX_IMAGE_SIZE]; - if ( read( sd, image_data, frame_header.image_length ) != frame_header.image_length ) + if ( read( sd, image_data, frame_header.image_length ) != (ssize_t)frame_header.image_length ) { Error(( "Can't read frame image data: %s", strerror(errno) )); ReopenSocket( sd, monitor->Id() ); } static char path[PATH_MAX] = ""; - sprintf( path, "%s//%s/%d/%s-%03d.jpg", (const char *)config.Item( ZM_DIR_EVENTS ), monitor->Name(), frame_header.event_id, frame_header.alarm_frame?"analyse":"capture", frame_header.frame_id ); + sprintf( path, "%s/%s/%ld/%s-%03ld.jpg", (const char *)config.Item( ZM_DIR_EVENTS ), monitor->Name(), frame_header.event_id, frame_header.alarm_frame?"analyse":"capture", frame_header.frame_id ); Debug( 1, ( "Got image, writing to %s", path )); FILE *fd = 0; @@ -250,7 +262,7 @@ int main( int argc, char *argv[] ) Error(( "Can't fopen '%s': %s", path, strerror(errno) )); exit( -1 ); } - if ( fwrite( image_data, frame_header.image_length, 1, fd ) < 0 ) + if ( 0 == fwrite( image_data, frame_header.image_length, 1, fd ) ) { Error(( "Can't fwrite image data: %s", strerror(errno) )); exit( -1 ); diff --git a/src/zmf.h b/src/zmf.h index 33f848476..a514d6189 100644 --- a/src/zmf.h +++ b/src/zmf.h @@ -16,16 +16,16 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // - +#include #ifndef ZMFILE_H #define ZMFILE_H struct FrameHeader { - int event_id; - int frame_id; + unsigned long event_id; + unsigned long frame_id; bool alarm_frame; - int image_length; + unsigned long image_length; }; #endif // ZMFILE_H diff --git a/src/zms.cpp b/src/zms.cpp index 799dd4517..865ed0347 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -21,7 +21,7 @@ #include "zm_db.h" #include "zm_monitor.h" -int main( int argc, const char *argv[] ) +int main(void ) { int id = 1; unsigned long idle = 5000; @@ -29,7 +29,7 @@ int main( int argc, const char *argv[] ) unsigned int rate = 1; unsigned int scale = 1; int event = 0; - char *path = "."; + const char *path = "."; unsigned int ttl = 0; //setbuf( fd, 0 ); @@ -65,7 +65,7 @@ int main( int argc, const char *argv[] ) else if ( !strcmp( name, "monitor" ) ) id = atoi( value ); else if ( !strcmp( name, "event" ) ) - event = atoi( value ); + event = strtoull( value, (char **)NULL, 10 ); else if ( !strcmp( name, "path" ) ) path = value; else if ( !strcmp( name, "ttl" ) ) diff --git a/src/zmu.cpp b/src/zmu.cpp index d666f4dea..6c733799e 100644 --- a/src/zmu.cpp +++ b/src/zmu.cpp @@ -119,7 +119,7 @@ bool ValidateAccess( const char *username, const char *password, int mon_id, Fun int stream = atoi(dbrow[1]); int events = atoi(dbrow[2]); int monitors = atoi(dbrow[3]); - int system = atoi(dbrow[4]); + //int system = atoi(dbrow[4]); const char *monitor_ids = dbrow[5]; if ( function & (STATE|IMAGE|TIME|READ_IDX|WRITE_IDX|FPS) ) { @@ -148,7 +148,7 @@ bool ValidateAccess( const char *username, const char *password, int mon_id, Fun char *mon_id_str_ptr = mon_id_str; char *mon_id_ptr = 0; bool found_mon_id = false; - while( mon_id_ptr = strtok( mon_id_str_ptr, "," ) ) + while( (mon_id_ptr = strtok( mon_id_str_ptr, "," )) ) { mon_id_str_ptr = 0; if ( mon_id == atoi( mon_id_ptr ) )