Applied Ian@zestysoft changes.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@744 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2004-01-14 21:26:47 +00:00
parent 48173e6bbb
commit 0aafd9d30b
21 changed files with 204 additions and 136 deletions

View File

@ -19,7 +19,7 @@ zmu_SOURCES = zmu.cpp $(zm_SOURCES)
zmf_SOURCES = zmf.cpp $(zm_SOURCES) zmf_SOURCES = zmf.cpp $(zm_SOURCES)
zmfix_SOURCES = zmfix.cpp zm_debug.c zm_db.cpp zm.cpp 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 EXTRA_DIST = zm_config.h.z

View File

@ -136,7 +136,7 @@ zmu_SOURCES = zmu.cpp $(zm_SOURCES)
zmf_SOURCES = zmf.cpp $(zm_SOURCES) zmf_SOURCES = zmf.cpp $(zm_SOURCES)
zmfix_SOURCES = zmfix.cpp zm_debug.c zm_db.cpp zm.cpp 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 EXTRA_DIST = zm_config.h.z
subdir = src subdir = src

View File

@ -55,10 +55,10 @@ public:
unsigned int Colours() const { return( colours ); } unsigned int Colours() const { return( colours ); }
unsigned int ImageSize() const { return( colours*width*height ); } unsigned int ImageSize() const { return( colours*width*height ); }
virtual int Brightness( int p_brightness=-1 ) { return( -1 ); } virtual int Brightness( int/*p_brightness*/=-1 ) { return( -1 ); }
virtual int Hue( int p_hue=-1 ) { return( -1 ); } virtual int Hue( int/*p_hue*/=-1 ) { return( -1 ); }
virtual int Colour( int p_colour=-1 ) { return( -1 ); } virtual int Colour( int/*p_colour*/=-1 ) { return( -1 ); }
virtual int Contrast( int p_contrast=-1 ) { return( -1 ); } virtual int Contrast( int/*p_contrast*/=-1 ) { return( -1 ); }
bool CanCapture() const { return( capture ); } bool CanCapture() const { return( capture ); }

View File

@ -49,7 +49,7 @@ void ConfigItem::ConvertValue() const
if ( !strcmp( type, "boolean" ) ) if ( !strcmp( type, "boolean" ) )
{ {
cfg_type = CFG_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" ) ) else if ( !strcmp( type, "integer" ) )
{ {
@ -64,7 +64,7 @@ void ConfigItem::ConvertValue() const
else if ( !strcmp( type, "decimal" ) ) else if ( !strcmp( type, "decimal" ) )
{ {
cfg_type = CFG_DECIMAL; cfg_type = CFG_DECIMAL;
cfg_value.decimal_value = atof( value ); cfg_value.decimal_value = strtod( value, 0 );
} }
else else
{ {

View File

@ -1,21 +1,21 @@
// /*
// ZoneMinder Debug Implementation, $Date$, $Revision$ * ZoneMinder Debug Implementation, $Date$, $Revision$
// Copyright (C) 2003 Philip Coombes * Copyright (C) 2003 Philip Coombes
// *
// This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
// *
// This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. * GNU General Public License for more details.
// *
// You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -346,7 +346,7 @@ int zmDbgOutput( const char *fstring, ... )
log_code = LOG_CRIT; log_code = LOG_CRIT;
break; break;
default: default:
//log_code = LOG_DEBUG; /* log_code = LOG_DEBUG; */
log_code = LOG_INFO; log_code = LOG_INFO;
break; break;
} }

View File

@ -1,21 +1,21 @@
// /*
// ZoneMinder Debug Interface, $Date$, $Revision$ * ZoneMinder Debug Interface, $Date$, $Revision$
// Copyright (C) 2003 Philip Coombes * Copyright (C) 2003 Philip Coombes
// *
// This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
// *
// This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. * GNU General Public License for more details.
// *
// You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// */
#include <sys/types.h> #include <sys/types.h>
@ -94,6 +94,14 @@
extern "C" { extern "C" {
#endif #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) #if defined(__STDC__) || defined(__cplusplus)
int zmDbgInit(void); int zmDbgInit(void);
int zmDbgTerm(void); int zmDbgTerm(void);
@ -119,7 +127,7 @@ extern int zm_dbg_flush;
extern int zm_dbg_add_log_id; extern int zm_dbg_add_log_id;
#ifdef __cplusplus #ifdef __cplusplus
} //extern "C" } /* extern "C" */
#endif #endif
#else #else

View File

@ -167,7 +167,11 @@ bool Event::SendFrameImage( const Image *image, bool alarm_frame )
iovecs[1].iov_base = jpg_buffer; iovecs[1].iov_base = jpg_buffer;
iovecs[1].iov_len = jpg_buffer_size; 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 ( writev_result < 0 )
{ {
if ( errno == EAGAIN ) if ( errno == EAGAIN )
{ {
@ -179,6 +183,13 @@ bool Event::SendFrameImage( const Image *image, bool alarm_frame )
close( sd ); close( sd );
sd = -1; sd = -1;
} }
}
else
{
Error(( "Incomplete frame write: %d of %d bytes written", writev_result, writev_size ));
close( sd );
sd = -1;
}
return( false ); return( false );
} }
Debug( 1, ( "Wrote frame image, %d bytes", jpg_buffer_size )); Debug( 1, ( "Wrote frame image, %d bytes", jpg_buffer_size ));

View File

@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// //
#include "zm.h" #include "zm.h"
#include "zm_font.h" #include "zm_font.h"
#include "zm_image.h" #include "zm_image.h"
@ -454,8 +453,6 @@ Image *Image::Delta( const Image &image ) const
Image *result = new Image( width, height, 1 ); Image *result = new Image( width, height, 1 );
typedef JSAMPLE IMAGE[width][height][colours];
unsigned char *psrc = buffer; unsigned char *psrc = buffer;
unsigned char *pref = image.buffer; unsigned char *pref = image.buffer;
unsigned char *pdiff = result->buffer; unsigned char *pdiff = result->buffer;

View File

@ -30,14 +30,11 @@
extern "C" extern "C"
{ {
#include <jpeglib.h>
#if !HAVE_DECL_ROUND #if !HAVE_DECL_ROUND
double round(double); double round(double);
#endif #endif
void jpeg_mem_src(j_decompress_ptr cinfo, JOCTET *inbuffer, int inbuffer_size ); #include "zm_jpeg.h"
void jpeg_mem_dest(j_compress_ptr cinfo, JOCTET *outbuffer, int *outbuffer_size );
} }
#include "zm_rgb.h" #include "zm_rgb.h"
@ -78,17 +75,17 @@ public:
height = p_height; height = p_height;
colours = p_colours; colours = p_colours;
size = width*height*colours; size = width*height*colours;
if ( !p_buffer ) if ( p_buffer )
{
our_buffer = false;
buffer = p_buffer;
}
else
{ {
our_buffer = true; our_buffer = true;
buffer = new JSAMPLE[size]; buffer = new JSAMPLE[size];
memset( buffer, 0, size ); memset( buffer, 0, size );
} }
else
{
our_buffer = false;
buffer = p_buffer;
}
blend_buffer = 0; blend_buffer = 0;
} }
Image( const Image &p_image ) Image( const Image &p_image )

View File

@ -17,9 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "jinclude.h" #include "zm_jpeg.h"
#include "jpeglib.h"
#include "jerror.h"
/* Expanded data destination object for memory */ /* 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; mem_src_ptr src = (mem_src_ptr) cinfo->src;
size_t nbytes; 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; nbytes = src->inbuffer_size;
if (nbytes <= 0) { if (nbytes <= 0) {

26
src/zm_jpeg.h Normal file
View File

@ -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 );

View File

@ -301,11 +301,11 @@ int Monitor::GetImage( int index ) const
index = shared_data->last_write_index; index = shared_data->last_write_index;
} }
Snapshot *snap = &image_buffer[index]; Snapshot *snap = &image_buffer[index];
Image *image = snap->image; Image *snap_image = snap->image;
char filename[64]; char filename[64];
sprintf( filename, "%s.jpg", name ); sprintf( filename, "%s.jpg", name );
image->WriteJpeg( filename ); snap_image->WriteJpeg( filename );
return( 0 ); return( 0 );
} }
@ -316,8 +316,8 @@ struct timeval Monitor::GetTimestamp( int index ) const
index = shared_data->last_write_index; index = shared_data->last_write_index;
} }
Info(( "Index %d = %x", index, image_buffer[index].timestamp )); Info(( "Index %d = %p", index, (void *) image_buffer[index].timestamp ));
Info(( "Timestamp %d.%d", image_buffer[index].timestamp->tv_sec, image_buffer[index].timestamp->tv_usec )); Info(( "Timestamp %ld.%ld", image_buffer[index].timestamp->tv_sec, image_buffer[index].timestamp->tv_usec ));
Snapshot *snap = &image_buffer[index]; Snapshot *snap = &image_buffer[index];
return( *(snap->timestamp) ); return( *(snap->timestamp) );
@ -350,9 +350,9 @@ double Monitor::GetFPS() const
Snapshot *snap2 = &image_buffer[index2]; Snapshot *snap2 = &image_buffer[index2];
time_t time2 = snap2->timestamp->tv_sec; 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() void Monitor::ForceAlarmOn()
@ -510,9 +510,9 @@ void Monitor::DumpZoneImage()
{ {
int index = shared_data->last_write_index; int index = shared_data->last_write_index;
Snapshot *snap = &image_buffer[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(); zone_image.Colourise();
for( int i = 0; i < n_zones; i++ ) for( int i = 0; i < n_zones; i++ )
{ {
@ -544,7 +544,7 @@ void Monitor::DumpZoneImage()
zone_image.WriteJpeg( filename ); zone_image.WriteJpeg( filename );
} }
void Monitor::DumpImage( Image *image ) const void Monitor::DumpImage( Image *dump_image ) const
{ {
if ( image_count && !(image_count%10) ) if ( image_count && !(image_count%10) )
{ {
@ -552,7 +552,7 @@ void Monitor::DumpImage( Image *image ) const
static char filename[64]; static char filename[64];
sprintf( filename, "%s.jpg", name ); sprintf( filename, "%s.jpg", name );
sprintf( new_filename, "%s-new.jpg", name ); sprintf( new_filename, "%s-new.jpg", name );
image->WriteJpeg( new_filename ); dump_image->WriteJpeg( new_filename );
rename( new_filename, filename ); rename( new_filename, filename );
} }
} }
@ -610,13 +610,16 @@ bool Monitor::Analyse()
Snapshot *snap = &image_buffer[index]; Snapshot *snap = &image_buffer[index];
struct timeval *timestamp = snap->timestamp; 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; unsigned int score = 0;
if ( Ready() ) if ( Ready() )
{ {
if ( function != RECORD && shared_data->force_state != FORCE_OFF ) if ( function != RECORD && shared_data->force_state != FORCE_OFF )
score = Compare( *image ); score = Compare( *snap_image );
if ( shared_data->force_state == FORCE_ON ) if ( shared_data->force_state == FORCE_ON )
score = (int)config.Item( ZM_FORCED_ALARM_SCORE ); score = (int)config.Item( ZM_FORCED_ALARM_SCORE );
@ -633,8 +636,8 @@ bool Monitor::Analyse()
if ( 1 ) if ( 1 )
{ {
int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count;
struct timeval *timestamps[pre_event_count]; if ( !timestamps ) timestamps = new struct timeval *[pre_event_count];
const Image *images[pre_event_count]; if ( !images ) images = new const Image *[pre_event_count];
for ( int i = 0; i < pre_event_count; i++ ) for ( int i = 0; i < pre_event_count; i++ )
{ {
timestamps[i] = image_buffer[pre_index].timestamp; timestamps[i] = image_buffer[pre_index].timestamp;
@ -657,8 +660,8 @@ bool Monitor::Analyse()
event = new Event( this, *timestamp ); event = new Event( this, *timestamp );
int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; int pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count;
struct timeval *timestamps[pre_event_count]; if ( !timestamps ) timestamps = new struct timeval *[pre_event_count];
const Image *images[pre_event_count]; if ( !images ) images = new const Image *[pre_event_count];
for ( int i = 0; i < pre_event_count; i++ ) for ( int i = 0; i < pre_event_count; i++ )
{ {
timestamps[i] = image_buffer[pre_index].timestamp; timestamps[i] = image_buffer[pre_index].timestamp;
@ -703,7 +706,7 @@ bool Monitor::Analyse()
{ {
if ( (bool)config.Item( ZM_CREATE_ANALYSIS_IMAGES ) ) 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++ ) for( int i = 0; i < n_zones; i++ )
{ {
if ( zones[i]->Alarmed() ) 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 else
{ {
event->AddFrame( *timestamp, image, score ); event->AddFrame( *timestamp, snap_image, score );
} }
} }
else if ( state == ALERT ) else if ( state == ALERT )
{ {
event->AddFrame( *timestamp, image ); event->AddFrame( *timestamp, snap_image );
} }
else if ( state == TAPE ) else if ( state == TAPE )
{ {
if ( !(image_count%(frame_skip+1)) ) 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 ) if ( (bool)config.Item( ZM_BLEND_ALARMED_IMAGES ) || state != ALARM )
{ {
ref_image.Blend( *image, ref_blend_perc ); ref_image.Blend( *snap_image, ref_blend_perc );
//DumpImage( image ); //DumpImage( snap_image );
} }
shared_data->last_read_index = index%image_buffer_count; 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 img_buffer_size = 0;
int loop_count = (idle/refresh)-1; int loop_count = (idle/refresh)-1;
time_t start_time; time_t stream_start_time;
time( &start_time ); time( &stream_start_time );
while ( true ) 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; int index = shared_data->last_write_index%image_buffer_count;
//Info(( "%d: %x - %x", index, image_buffer[index].image, image_buffer[index].image->buffer )); //Info(( "%d: %x - %x", index, image_buffer[index].image, image_buffer[index].image->buffer ));
Snapshot *snap = &image_buffer[index]; Snapshot *snap = &image_buffer[index];
Image *image = snap->image; Image *snap_image = snap->image;
if ( scale == 1 ) if ( scale == 1 )
{ {
image->EncodeJpeg( img_buffer, &img_buffer_size ); snap_image->EncodeJpeg( img_buffer, &img_buffer_size );
} }
else else
{ {
Image scaled_image( *image ); Image scaled_image( *snap_image );
scaled_image.Scale( scale ); scaled_image.Scale( scale );
@ -1075,7 +1078,7 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, time_t tt
if ( ttl ) if ( ttl )
{ {
time( &now ); time( &now );
if ( (now - start_time) > ttl ) if ( (now - stream_start_time) > ttl )
{ {
break; break;
} }
@ -1130,14 +1133,14 @@ bool Monitor::DumpSettings( char *output, bool verbose )
return( true ); return( true );
} }
unsigned int Monitor::Compare( const Image &image ) unsigned int Monitor::Compare( const Image &comp_image )
{ {
bool alarm = false; bool alarm = false;
unsigned int score = 0; unsigned int score = 0;
if ( n_zones <= 0 ) return( alarm ); 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 // Blank out all exclusion zones
for ( int n_zone = 0; n_zone < n_zones; n_zone++ ) for ( int n_zone = 0; n_zone < n_zones; n_zone++ )

View File

@ -83,12 +83,13 @@ protected:
int fps_report_interval;// How many images should be captured/processed between reporting the current FPS 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. 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; double fps;
Image image; Image image;
Image ref_image;
Purpose purpose; // What this monitor has been created to do
int event_count; int event_count;
int image_count; int image_count;
int first_alarm_count; int first_alarm_count;
@ -251,7 +252,7 @@ public:
return( function > MONITOR && image_count > warmup_count ); return( function > MONITOR && image_count > warmup_count );
} }
void DumpImage( Image *image ) const; void DumpImage( Image *dump_image ) const;
bool Analyse(); bool Analyse();
void Adjust( double ratio ) void Adjust( double ratio )
@ -259,7 +260,7 @@ public:
ref_image.Blend( image, 0.1 ); ref_image.Blend( image, 0.1 );
} }
unsigned int Compare( const Image &image ); unsigned int Compare( const Image &comp_image );
void ReloadZones(); void ReloadZones();
static int Load( int device, Monitor **&monitors, Purpose purpose=QUERY ); 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 ); static int Load( const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose=QUERY );

View File

@ -156,14 +156,13 @@ int RemoteCamera::GetHeader( const char *content, const char *header, char *valu
strcat( header_string, ":" ); strcat( header_string, ":" );
char *header_ptr = strstr( content, header_string ); char *header_ptr = strstr( content, header_string );
if ( !header_ptr ) int result = -1;
if ( header_ptr )
{ {
return( -1 );
}
strcat( header_string, " %s" ); strcat( header_string, " %s" );
int result = sscanf( header_ptr, header_string, value ); result = sscanf( header_ptr, header_string, value );
//Debug( 3, ( "R:%d, %s\n", result, value ); //Debug( 3, ( "R:%d, %s\n", result, value );
}
return( result ); return( result );
} }

View File

@ -466,7 +466,7 @@ int Zone::Load( Monitor *monitor, Zone **&zones )
return( n_zones ); return( n_zones );
} }
bool Zone::DumpSettings( char *output, bool verbose ) bool Zone::DumpSettings( char *output, bool /*verbose*/ )
{ {
output[0] = 0; output[0] = 0;

View File

@ -26,7 +26,13 @@
void zm_die_handler( int signal ) 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 ); exit( signal );
} }
@ -34,7 +40,13 @@ bool zma_terminate = false;
void zm_term_handler( int 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);
zma_terminate = true; zma_terminate = true;
} }

View File

@ -27,7 +27,7 @@
bool zmc_terminate = false; bool zmc_terminate = false;
void zmc_term_handler( int signal ) void zmc_term_handler( int /* signal */ )
{ {
Info(( "Got TERM signal, exiting" )); Info(( "Got TERM signal, exiting" ));
zmc_terminate = true; zmc_terminate = true;
@ -46,9 +46,9 @@ void Usage()
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int device = -1; int device = -1;
char *host = ""; const char *host = "";
char *port = ""; const char *port = "";
char *path = ""; const char *path = "";
static struct option long_options[] = { static struct option long_options[] = {
{"device", 1, 0, 'd'}, {"device", 1, 0, 'd'},
@ -169,9 +169,9 @@ int main( int argc, char *argv[] )
monitors[0]->PreCapture(); monitors[0]->PreCapture();
} }
long capture_delays[n_monitors]; long *capture_delays = new long[n_monitors];
long next_delays[n_monitors]; long *next_delays = new long[n_monitors];
struct timeval last_capture_times[n_monitors]; struct timeval * last_capture_times = new struct timeval[n_monitors];
for ( int i = 0; i < n_monitors; i++ ) for ( int i = 0; i < n_monitors; i++ )
{ {
last_capture_times[i].tv_sec = last_capture_times[i].tv_usec = 0; 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 monitors[i];
} }
delete [] capture_delays;
delete [] next_delays;
delete [] last_capture_times;
return( 0 ); return( 0 );
} }

View File

@ -33,20 +33,32 @@
#include "zm.h" #include "zm.h"
#include "zm_db.h" #include "zm_db.h"
#include "zm_debug.h" //#include "zm_debug.h"
#include "zm_monitor.h" #include "zm_monitor.h"
#include "zmf.h" #include "zmf.h"
void zm_die_handler( int signal ) 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 ); exit( signal );
} }
void zm_term_handler( int 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 ); exit( 0 );
} }
@ -200,8 +212,8 @@ int main( int argc, char *argv[] )
int sd = OpenSocket( monitor->Id() ); int sd = OpenSocket( monitor->Id() );
FrameHeader frame_header = { -1, -1, false, -1 }; FrameHeader frame_header = { 0, 0, false, 0 };
unsigned char *image_data = 0; //unsigned char *image_data = 0;
fd_set rfds; fd_set rfds;
@ -233,15 +245,15 @@ int main( int argc, char *argv[] )
Error(( "Can't read frame header: %s", strerror(errno) )); Error(( "Can't read frame header: %s", strerror(errno) ));
ReopenSocket( sd, monitor->Id() ); 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]; 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) )); Error(( "Can't read frame image data: %s", strerror(errno) ));
ReopenSocket( sd, monitor->Id() ); ReopenSocket( sd, monitor->Id() );
} }
static char path[PATH_MAX] = ""; 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 )); Debug( 1, ( "Got image, writing to %s", path ));
FILE *fd = 0; FILE *fd = 0;
@ -250,7 +262,7 @@ int main( int argc, char *argv[] )
Error(( "Can't fopen '%s': %s", path, strerror(errno) )); Error(( "Can't fopen '%s': %s", path, strerror(errno) ));
exit( -1 ); 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) )); Error(( "Can't fwrite image data: %s", strerror(errno) ));
exit( -1 ); exit( -1 );

View File

@ -16,16 +16,16 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// //
#include <mysql/mysql.h>
#ifndef ZMFILE_H #ifndef ZMFILE_H
#define ZMFILE_H #define ZMFILE_H
struct FrameHeader struct FrameHeader
{ {
int event_id; unsigned long event_id;
int frame_id; unsigned long frame_id;
bool alarm_frame; bool alarm_frame;
int image_length; unsigned long image_length;
}; };
#endif // ZMFILE_H #endif // ZMFILE_H

View File

@ -21,7 +21,7 @@
#include "zm_db.h" #include "zm_db.h"
#include "zm_monitor.h" #include "zm_monitor.h"
int main( int argc, const char *argv[] ) int main(void )
{ {
int id = 1; int id = 1;
unsigned long idle = 5000; unsigned long idle = 5000;
@ -29,7 +29,7 @@ int main( int argc, const char *argv[] )
unsigned int rate = 1; unsigned int rate = 1;
unsigned int scale = 1; unsigned int scale = 1;
int event = 0; int event = 0;
char *path = "."; const char *path = ".";
unsigned int ttl = 0; unsigned int ttl = 0;
//setbuf( fd, 0 ); //setbuf( fd, 0 );
@ -65,7 +65,7 @@ int main( int argc, const char *argv[] )
else if ( !strcmp( name, "monitor" ) ) else if ( !strcmp( name, "monitor" ) )
id = atoi( value ); id = atoi( value );
else if ( !strcmp( name, "event" ) ) else if ( !strcmp( name, "event" ) )
event = atoi( value ); event = strtoull( value, (char **)NULL, 10 );
else if ( !strcmp( name, "path" ) ) else if ( !strcmp( name, "path" ) )
path = value; path = value;
else if ( !strcmp( name, "ttl" ) ) else if ( !strcmp( name, "ttl" ) )

View File

@ -119,7 +119,7 @@ bool ValidateAccess( const char *username, const char *password, int mon_id, Fun
int stream = atoi(dbrow[1]); int stream = atoi(dbrow[1]);
int events = atoi(dbrow[2]); int events = atoi(dbrow[2]);
int monitors = atoi(dbrow[3]); int monitors = atoi(dbrow[3]);
int system = atoi(dbrow[4]); //int system = atoi(dbrow[4]);
const char *monitor_ids = dbrow[5]; const char *monitor_ids = dbrow[5];
if ( function & (STATE|IMAGE|TIME|READ_IDX|WRITE_IDX|FPS) ) 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_str_ptr = mon_id_str;
char *mon_id_ptr = 0; char *mon_id_ptr = 0;
bool found_mon_id = false; 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; mon_id_str_ptr = 0;
if ( mon_id == atoi( mon_id_ptr ) ) if ( mon_id == atoi( mon_id_ptr ) )