From 799ee78675b0d00bea05abfc4650a0997c4a564e Mon Sep 17 00:00:00 2001 From: stan Date: Thu, 13 Mar 2008 13:36:12 +0000 Subject: [PATCH] Bug 471 - Compiler warnings, sorted out types and general format tidying git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2357 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/Makefile.am | 2 +- src/zm_camera.cpp | 11 +- src/zm_config.cpp | 1 - src/zm_debug.c | 3 +- src/zm_event.cpp | 45 ++++--- src/zm_event.h | 2 +- src/zm_image.cpp | 5 +- src/zm_jpeg.c | 264 +++++++++++++++++++-------------------- src/zm_monitor.cpp | 35 +++--- src/zm_monitor.h | 6 +- src/zm_remote_camera.cpp | 16 ++- src/zm_signal.cpp | 2 +- src/zm_stream.cpp | 5 +- src/zm_zone.cpp | 12 +- src/zma.cpp | 1 - src/zmc.cpp | 7 +- src/zmf.cpp | 7 +- 17 files changed, 216 insertions(+), 208 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 49adff7d4..37dee2e04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = gnu -AM_CPPFLAGS = @MYSQL_CFLAGS@ @FFMPEG_CFLAGS@ +AM_CPPFLAGS = @MYSQL_CFLAGS@ @FFMPEG_CFLAGS@ -Wall -Wno-sign-compare # This should be set to your CGI directory cgidir = @CGI_PREFIX@ diff --git a/src/zm_camera.cpp b/src/zm_camera.cpp index ab61fd722..81c9f5935 100644 --- a/src/zm_camera.cpp +++ b/src/zm_camera.cpp @@ -20,7 +20,16 @@ #include "zm.h" #include "zm_camera.h" -Camera::Camera( SourceType p_type, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture ) : type( p_type ), width( p_width), height( p_height ), palette( p_palette ), brightness( p_brightness ), contrast( p_contrast ), hue( p_hue ), colour( p_colour ), capture( p_capture ) +Camera::Camera( SourceType p_type, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture ) : + type( p_type ), + width( p_width), + height( p_height ), + palette( p_palette ), + brightness( p_brightness ), + hue( p_hue ), + colour( p_colour ), + contrast( p_contrast ), + capture( p_capture ) { colours = (palette==VIDEO_PALETTE_GREY?1:3); size = width * height * colours; diff --git a/src/zm_config.cpp b/src/zm_config.cpp index 8e27e42a4..997f3b782 100644 --- a/src/zm_config.cpp +++ b/src/zm_config.cpp @@ -31,7 +31,6 @@ void zmLoadConfig() FILE *cfg; char line[512]; char *val; - int r; if ( (cfg = fopen( ZM_CONFIG, "r")) == NULL ) { Fatal(("Can't open %s: %s", ZM_CONFIG, strerror(errno) )); diff --git a/src/zm_debug.c b/src/zm_debug.c index 9da552a3d..6f7aaabab 100644 --- a/src/zm_debug.c +++ b/src/zm_debug.c @@ -196,6 +196,7 @@ int zmDebugPrepareLog() Error(("fopen() for %s, error = %s",zm_dbg_log,strerror(errno))); return( -1 ); } + return( 0 ); } int zmDebugInitialise( const char *name, const char *id, int level ) @@ -236,7 +237,7 @@ int zmDebugInitialise( const char *name, const char *id, int level ) Info(( "Debug Level = %d, Debug Log = %s", zm_dbg_level,zm_dbg_log[0]?zm_dbg_log:"" )); { - struct sigaction action, old_action; + struct sigaction action; memset( &action, 0, sizeof(action) ); action.sa_handler = zmUsrHandler; action.sa_flags = SA_RESTART; diff --git a/src/zm_event.cpp b/src/zm_event.cpp index abd52a98a..23d4525a9 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -42,7 +42,7 @@ char Event::analyse_file_format[PATH_MAX]; char Event::general_file_format[PATH_MAX]; int Event::pre_alarm_count = 0; -Event::PreAlarmData Event::pre_alarm_data[MAX_PRE_ALARM_FRAMES] = { 0 }; +Event::PreAlarmData Event::pre_alarm_data[MAX_PRE_ALARM_FRAMES] = { { 0 } }; Event::Event( Monitor *p_monitor, struct timeval p_start_time, const char *p_cause, const char *p_text ) : monitor( p_monitor ), start_time( p_start_time ) { @@ -151,7 +151,7 @@ Event::~Event() Debug( 1, ( "Adding closing frame %d to DB", frames )); static char sql[BUFSIZ]; - snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ( %d, %d, from_unixtime( %d ), %s%ld.%02ld )", id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec ); + snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ( %d, %d, from_unixtime( %ld ), %s%ld.%02ld )", id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec ); if ( mysql_query( &dbconn, sql ) ) { Error(( "Can't insert frame: %s", mysql_error( &dbconn ) )); @@ -351,7 +351,7 @@ void Event::AddFrames( int n_frames, Image **images, struct timeval **timestamps DELTA_TIMEVAL( delta_time, *(timestamps[i]), start_time, DT_PREC_2 ); int sql_len = strlen(sql); - snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%d), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec ); + snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec ); } Debug( 1, ( "Adding %d frames to DB", n_frames )); @@ -386,7 +386,7 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * Debug( 1, ( "Adding frame %d to DB", frames )); static char sql[BUFSIZ]; - snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %d ), %s%ld.%02ld, %d )", id, frames, frame_type, timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); + snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); if ( mysql_query( &dbconn, sql ) ) { Error(( "Can't insert frame: %s", mysql_error( &dbconn ) )); @@ -471,7 +471,7 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) { static char sql[BUFSIZ]; - snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %d and unix_timestamp( EndTime ) > %d order by Id asc limit 1", monitor_id, event_time ); + snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %d and unix_timestamp( EndTime ) > %ld order by Id asc limit 1", monitor_id, event_time ); if ( mysql_query( &dbconn, sql ) ) { @@ -505,7 +505,6 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) curr_frame_id = 1; if ( event_time >= event_data->start_time ) { - double total_delta = 0.0; for ( int i = 0; i < event_data->frame_count; i++ ) { //Info(( "eft %d > et %d", event_data->frames[i].timestamp, event_time )); @@ -517,7 +516,7 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) break; } } - Debug( 3, ( "Skipping %d frames", event_data->frame_count )); + Debug( 3, ( "Skipping %ld frames", event_data->frame_count )); } } return( true ); @@ -580,11 +579,11 @@ bool EventStream::loadEventData( int event_id ) if ( config.use_deep_storage ) { struct tm *event_time = localtime( &event_data->start_time ); - snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%d/%02d/%02d/%02d/%02d/%02d/%02d", ZM_PATH_WEB, config.dir_events, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); + snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", ZM_PATH_WEB, config.dir_events, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); } else { - snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%d/%d", ZM_PATH_WEB, config.dir_events, event_data->monitor_id, event_data->event_id ); + snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%ld", ZM_PATH_WEB, config.dir_events, event_data->monitor_id, event_data->event_id ); } event_data->frame_count = atoi(dbrow[2]); event_data->duration = atof(dbrow[4]); @@ -612,8 +611,8 @@ bool EventStream::loadEventData( int event_id ) event_data->frames = new FrameData[event_data->frame_count]; int id, last_id = 0; time_t timestamp, last_timestamp = event_data->start_time; - double delta, first_delta, last_delta = 0.0; - while ( dbrow = mysql_fetch_row( result ) ) + double delta, last_delta = 0.0; + while ( ( dbrow = mysql_fetch_row( result ) ) ) { id = atoi(dbrow[0]); timestamp = atoi(dbrow[1]); @@ -658,14 +657,14 @@ bool EventStream::loadEventData( int event_id ) else curr_stream_time = event_data->frames[event_data->frame_count-1].timestamp; } - Debug( 2, ( "Event:%d, Frames:%d, Duration: %.2f", event_data->event_id, event_data->frame_count, event_data->duration )); + Debug( 2, ( "Event:%ld, Frames:%ld, Duration: %.2f", event_data->event_id, event_data->frame_count, event_data->duration )); return( true ); } void EventStream::processCommand( const CmdMsg *msg ) { - Debug( 2, ( "Got message, type %d, msg %d", msg->msg_type, msg->msg_data[0] )) + Debug( 2, ( "Got message, type %ld, msg %d", msg->msg_type, msg->msg_data[0] )) // Check for incoming command switch( (MsgCommand)msg->msg_data[0] ) { @@ -873,6 +872,10 @@ void EventStream::processCommand( const CmdMsg *msg ) Debug( 1, ( "Got QUERY command, sending STATUS" )); break; } + default : + { + // Do nothing, for now + } } struct { int event; @@ -887,7 +890,7 @@ void EventStream::processCommand( const CmdMsg *msg ) status_data.progress = event_data->frames[curr_frame_id-1].offset; status_data.rate = replay_rate; status_data.zoom = zoom; - Debug( 2, ( "E:%d, P:%d, p:%d R:%d, Z:%d", + Debug( 2, ( "E:%d, P:%d, p:%ld R:%d, Z:%d", status_data.event, status_data.paused, status_data.progress, @@ -957,12 +960,12 @@ mysql_free_result( $result ); #endif if ( curr_frame_id <= 0 ) { - snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %d and Id < %d order by Id desc limit 1", event_data->monitor_id, event_data->event_id ); + snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %ld and Id < %ld order by Id desc limit 1", event_data->monitor_id, event_data->event_id ); reload_event = true; } else if ( curr_frame_id > event_data->frame_count ) { - snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %d and Id > %d order by Id asc limit 1", event_data->monitor_id, event_data->event_id ); + snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %ld and Id > %ld order by Id asc limit 1", event_data->monitor_id, event_data->event_id ); reload_event = true; } @@ -1046,7 +1049,7 @@ void EventStream::sendFrame( int delta_us ) fprintf( stdout, "Content-type: %s\r\n\r\n", vid_stream->MimeType() ); vid_stream->OpenStream(); } - double pts = vid_stream->EncodeFrame( send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_us*1000 ); + /* double pts = */ vid_stream->EncodeFrame( send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_us*1000 ); } else #endif // HAVE_LIBAVCODEC @@ -1096,6 +1099,9 @@ void EventStream::sendFrame( int delta_us ) send_image->Zip( img_buffer, &zip_buffer_size ); img_buffer_size = zip_buffer_size; break; + default: + Fatal(( "Unexpected frame type %d", type )); + break; } } @@ -1110,6 +1116,9 @@ void EventStream::sendFrame( int delta_us ) case STREAM_ZIP : fprintf( stdout, "Content-Type: image/x-rgbz\r\n" ); break; + default : + Fatal(( "Unexpected frame type %d", type )); + break; } fprintf( stdout, "Content-Length: %d\r\n\r\n", img_buffer_size ); fwrite( img_buffer, img_buffer_size, 1, stdout ); @@ -1141,7 +1150,7 @@ void EventStream::runStream() unsigned int delta_us = 0; while( !zm_terminate ) { - gettimeofday( &now, &dummy_tz ); + gettimeofday( &now, NULL ); checkCommandQueue(); diff --git a/src/zm_event.h b/src/zm_event.h index d65a572f4..630fe4516 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -70,7 +70,7 @@ protected: static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES]; protected: - int id; + unsigned int id; Monitor *monitor; struct timeval start_time; struct timeval end_time; diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 8e36c4433..243da3509 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -270,7 +270,7 @@ bool Image::ReadRaw( const char *filename ) if ( statbuf.st_size != size ) { - Error(( "Raw file size mismatch, expected %d bytes, found %d", size, statbuf.st_size )); + Error(( "Raw file size mismatch, expected %d bytes, found %ld", size, statbuf.st_size )); return( false ); } @@ -557,7 +557,7 @@ bool Image::Unzip( const Bytef *inbuffer, unsigned long inbuffer_size ) } if ( zip_size != size ) { - Error(( "Unzip failed, size mismatch, expected %d bytes, got %d", size, zip_size )); + Error(( "Unzip failed, size mismatch, expected %d bytes, got %ld", size, zip_size )); return( false ); } return( true ); @@ -1686,7 +1686,6 @@ void Image::Scale( unsigned int factor ) } else { - unsigned int inv_factor = (ZM_SCALE_BASE*ZM_SCALE_BASE)/factor; unsigned char *pd = scale_buffer; unsigned int wc = width*colours; unsigned int xstart = factor/2; diff --git a/src/zm_jpeg.c b/src/zm_jpeg.c index 348a813ae..151216663 100644 --- a/src/zm_jpeg.c +++ b/src/zm_jpeg.c @@ -27,6 +27,7 @@ #define MAX_JPEG_ERRS 25 static int jpeg_err_count = 0; + void zm_jpeg_error_exit( j_common_ptr cinfo ) { static char buffer[JMSG_LENGTH_MAX]; @@ -76,19 +77,19 @@ void zm_jpeg_emit_message( j_common_ptr cinfo, int msg_level ) /* Expanded data destination object for memory */ -typedef struct { - struct jpeg_destination_mgr pub; /* public fields */ +typedef struct +{ + struct jpeg_destination_mgr pub; /* public fields */ - JOCTET *outbuffer; /* target buffer */ - int *outbuffer_size; - JOCTET *buffer; /* start of buffer */ + JOCTET *outbuffer; /* target buffer */ + int *outbuffer_size; + JOCTET *buffer; /* start of buffer */ } mem_destination_mgr; typedef mem_destination_mgr * mem_dest_ptr; #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ - /* * Initialize destination --- called by jpeg_start_compress * before any data is actually written. @@ -96,17 +97,15 @@ typedef mem_destination_mgr * mem_dest_ptr; static void init_destination (j_compress_ptr cinfo) { - mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; - /* Allocate the output buffer --- it will be released when done with image */ - dest->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); + /* Allocate the output buffer --- it will be released when done with image */ + dest->buffer = (JOCTET *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); - dest->pub.next_output_byte = dest->buffer; - dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; - *(dest->outbuffer_size) = 0; + *(dest->outbuffer_size) = 0; } @@ -135,18 +134,17 @@ static void init_destination (j_compress_ptr cinfo) static boolean empty_output_buffer (j_compress_ptr cinfo) { - mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; - memcpy( dest->outbuffer+*(dest->outbuffer_size), dest->buffer, OUTPUT_BUF_SIZE ); - *(dest->outbuffer_size) += OUTPUT_BUF_SIZE; + memcpy( dest->outbuffer+*(dest->outbuffer_size), dest->buffer, OUTPUT_BUF_SIZE ); + *(dest->outbuffer_size) += OUTPUT_BUF_SIZE; - dest->pub.next_output_byte = dest->buffer; - dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; - return TRUE; + return( TRUE ); } - /* * Terminate destination --- called by jpeg_finish_compress * after all data has been written. Usually needs to flush buffer. @@ -158,13 +156,14 @@ static boolean empty_output_buffer (j_compress_ptr cinfo) static void term_destination (j_compress_ptr cinfo) { - mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; - size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; - if (datacount > 0) { - memcpy( dest->outbuffer+*(dest->outbuffer_size), dest->buffer, datacount ); - *(dest->outbuffer_size) += datacount; - } + if ( datacount > 0 ) + { + memcpy( dest->outbuffer+*(dest->outbuffer_size), dest->buffer, datacount ); + *(dest->outbuffer_size) += datacount; + } } @@ -176,46 +175,46 @@ static void term_destination (j_compress_ptr cinfo) void jpeg_mem_dest (j_compress_ptr cinfo, JOCTET *outbuffer, int *outbuffer_size ) { - mem_dest_ptr dest; + mem_dest_ptr dest; - /* The destination object is made permanent so that multiple JPEG images - * can be written to the same file without re-executing jpeg_stdio_dest. - * This makes it dangerous to use this manager and a different destination - * manager serially with the same JPEG object, because their private object - * sizes may be different. Caveat programmer. - */ - if (cinfo->dest == NULL) { /* first time for this JPEG object? */ - cinfo->dest = (struct jpeg_destination_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - SIZEOF(mem_destination_mgr)); - } + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_stdio_dest. + * This makes it dangerous to use this manager and a different destination + * manager serially with the same JPEG object, because their private object + * sizes may be different. Caveat programmer. + */ + if ( cinfo->dest == NULL ) + { + /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(mem_destination_mgr)); + } - dest = (mem_dest_ptr) cinfo->dest; - dest->pub.init_destination = init_destination; - dest->pub.empty_output_buffer = empty_output_buffer; - dest->pub.term_destination = term_destination; - dest->outbuffer = outbuffer; - dest->outbuffer_size = outbuffer_size; + dest = (mem_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->outbuffer = outbuffer; + dest->outbuffer_size = outbuffer_size; } /* Expanded data source object for memory input */ -typedef struct { - struct jpeg_source_mgr pub; /* public fields */ +typedef struct +{ + struct jpeg_source_mgr pub; /* public fields */ - JOCTET * inbuffer; /* source stream */ - int inbuffer_size; - int inbuffer_size_hwm; /* High water mark */ + JOCTET * inbuffer; /* source stream */ + int inbuffer_size; + int inbuffer_size_hwm; /* High water mark */ - JOCTET * buffer; /* start of buffer */ - boolean start_of_data; /* have we gotten any data yet? */ + JOCTET * buffer; /* start of buffer */ + boolean start_of_data; /* have we gotten any data yet? */ } mem_source_mgr; typedef mem_source_mgr * mem_src_ptr; #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ - /* * Initialize source --- called by jpeg_read_header * before any data is actually read. @@ -223,14 +222,14 @@ typedef mem_source_mgr * mem_src_ptr; static void init_source (j_decompress_ptr cinfo) { - mem_src_ptr src = (mem_src_ptr) cinfo->src; + mem_src_ptr src = (mem_src_ptr) cinfo->src; - /* We reset the empty-input-file flag for each image, - * but we don't clear the input buffer. - * This is correct behavior for reading a series of images from one source. - */ - src->start_of_data = TRUE; - src->pub.bytes_in_buffer = 0; + /* We reset the empty-input-file flag for each image, + * but we don't clear the input buffer. + * This is correct behavior for reading a series of images from one source. + */ + src->start_of_data = TRUE; + src->pub.bytes_in_buffer = 0; } @@ -269,27 +268,28 @@ static void init_source (j_decompress_ptr cinfo) static boolean fill_input_buffer (j_decompress_ptr cinfo) { - mem_src_ptr src = (mem_src_ptr) cinfo->src; - size_t nbytes; + mem_src_ptr src = (mem_src_ptr) cinfo->src; + size_t nbytes; - memcpy( src->buffer, src->inbuffer, (size_t) src->inbuffer_size ); - nbytes = src->inbuffer_size; + memcpy( src->buffer, src->inbuffer, (size_t) src->inbuffer_size ); + nbytes = src->inbuffer_size; - if (nbytes <= 0) { - if (src->start_of_data) /* Treat empty input file as fatal error */ - ERREXIT(cinfo, JERR_INPUT_EMPTY); - WARNMS(cinfo, JWRN_JPEG_EOF); - /* Insert a fake EOI marker */ - src->buffer[0] = (JOCTET) 0xFF; - src->buffer[1] = (JOCTET) JPEG_EOI; - nbytes = 2; - } + if ( nbytes <= 0 ) + { + if ( src->start_of_data ) /* Treat empty input file as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } - src->pub.next_input_byte = src->buffer; - src->pub.bytes_in_buffer = nbytes; - src->start_of_data = FALSE; + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = nbytes; + src->start_of_data = FALSE; - return TRUE; + return( TRUE ); } @@ -307,23 +307,25 @@ static boolean fill_input_buffer (j_decompress_ptr cinfo) static void skip_input_data (j_decompress_ptr cinfo, long num_bytes) { - mem_src_ptr src = (mem_src_ptr) cinfo->src; + mem_src_ptr src = (mem_src_ptr) cinfo->src; - /* Just a dumb implementation for now. Could use fseek() except - * it doesn't work on pipes. Not clear that being smart is worth - * any trouble anyway --- large skips are infrequent. - */ - if (num_bytes > 0) { - while (num_bytes > (long) src->pub.bytes_in_buffer) { - num_bytes -= (long) src->pub.bytes_in_buffer; - (void) fill_input_buffer(cinfo); - /* note we assume that fill_input_buffer will never return FALSE, - * so suspension need not be handled. - */ + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if ( num_bytes > 0 ) + { + while ( num_bytes > (long) src->pub.bytes_in_buffer ) + { + num_bytes -= (long) src->pub.bytes_in_buffer; + (void) fill_input_buffer(cinfo); + /* note we assume that fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; } - src->pub.next_input_byte += (size_t) num_bytes; - src->pub.bytes_in_buffer -= (size_t) num_bytes; - } } @@ -338,7 +340,7 @@ static void skip_input_data (j_decompress_ptr cinfo, long num_bytes) static void term_source (j_decompress_ptr cinfo) { - /* no work necessary here */ + /* no work necessary here */ } @@ -350,47 +352,41 @@ static void term_source (j_decompress_ptr cinfo) void jpeg_mem_src( j_decompress_ptr cinfo, const JOCTET *inbuffer, int inbuffer_size ) { - mem_src_ptr src; + mem_src_ptr src; - /* The source object and input buffer are made permanent so that a series - * of JPEG images can be read from the same file by calling jpeg_mem_src - * only before the first one. (If we discarded the buffer at the end of - * one image, we'd likely lose the start of the next one.) - * This makes it unsafe to use this manager and a different source - * manager serially with the same JPEG object. Caveat programmer. - */ - if (cinfo->src == NULL) - { - /* first time for this JPEG object? */ - cinfo->src = (struct jpeg_source_mgr *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - SIZEOF(mem_source_mgr)); - src = (mem_src_ptr) cinfo->src; - src->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - inbuffer_size * SIZEOF(JOCTET)); - src->inbuffer_size_hwm = inbuffer_size; - } - else - { - src = (mem_src_ptr) cinfo->src; - if ( src->inbuffer_size_hwm < inbuffer_size ) - { - src->buffer = (JOCTET *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - inbuffer_size * SIZEOF(JOCTET)); - src->inbuffer_size_hwm = inbuffer_size; - } - } + /* The source object and input buffer are made permanent so that a series + * of JPEG images can be read from the same file by calling jpeg_mem_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if ( cinfo->src == NULL ) + { + /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(mem_source_mgr)); + src = (mem_src_ptr) cinfo->src; + src->buffer = (JOCTET *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, inbuffer_size * SIZEOF(JOCTET)); + src->inbuffer_size_hwm = inbuffer_size; + } + else + { + src = (mem_src_ptr) cinfo->src; + if ( src->inbuffer_size_hwm < inbuffer_size ) + { + src->buffer = (JOCTET *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, inbuffer_size * SIZEOF(JOCTET)); + src->inbuffer_size_hwm = inbuffer_size; + } + } - src = (mem_src_ptr) cinfo->src; - src->pub.init_source = init_source; - src->pub.fill_input_buffer = fill_input_buffer; - src->pub.skip_input_data = skip_input_data; - src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ - src->pub.term_source = term_source; - src->inbuffer = inbuffer; - src->inbuffer_size = inbuffer_size; - src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ - src->pub.next_input_byte = NULL; /* until buffer loaded */ + src = (mem_src_ptr) cinfo->src; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->pub.term_source = term_source; + src->inbuffer = (JOCTET *)inbuffer; + src->inbuffer_size = inbuffer_size; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ } diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index c24a8a8e6..568223e7b 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -193,21 +193,20 @@ Monitor::Monitor( ) : 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() ), height( (p_orientation==ROTATE_90||p_orientation==ROTATE_270)?p_camera->Width():p_camera->Height() ), + orientation( (Orientation)p_orientation ), label_coord( p_label_coord ), image_buffer_count( p_image_buffer_count ), warmup_count( p_warmup_count ), pre_event_count( p_pre_event_count ), post_event_count( p_post_event_count ), stream_replay_buffer( p_stream_replay_buffer ), - alarm_frame_count( p_alarm_frame_count ), section_length( p_section_length ), frame_skip( p_frame_skip ), capture_delay( p_capture_delay ), alarm_capture_delay( p_alarm_capture_delay ), + alarm_frame_count( p_alarm_frame_count ), fps_report_interval( p_fps_report_interval ), ref_blend_perc( p_ref_blend_perc ), track_motion( p_track_motion ), @@ -215,6 +214,7 @@ Monitor::Monitor( image( width, height, p_camera->Colours() ), ref_image( width, height, p_camera->Colours() ), purpose( p_purpose ), + camera( p_camera ), n_zones( p_n_zones ), zones( p_zones ) { @@ -226,7 +226,7 @@ Monitor::Monitor( // Change \n to actual line feeds char *token_ptr = label_format; const char *token_string = "\n"; - while( token_ptr = strstr( token_ptr, token_string ) ) + while( ( token_ptr = strstr( token_ptr, token_string ) ) ) { if ( *(token_ptr+1) ) { @@ -899,7 +899,7 @@ bool Monitor::Analyse() } struct timeval now; - gettimeofday( &now, &dummy_tz ); + gettimeofday( &now, NULL ); if ( image_count && !(image_count%fps_report_interval) ) { @@ -2127,6 +2127,11 @@ int Monitor::PostCapture() { switch ( orientation ) { + case ROTATE_0 : + { + // No action required + break; + } case ROTATE_90 : case ROTATE_180 : case ROTATE_270 : @@ -2156,7 +2161,7 @@ int Monitor::PostCapture() 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 ); + gettimeofday( image_buffer[index].timestamp, NULL ); if ( config.timestamp_on_capture ) { TimestampImage( &image, image_buffer[index].timestamp ); @@ -2210,7 +2215,6 @@ void Monitor::TimestampImage( Image *ts_image, const struct timeval *ts_time ) c strftime( label_time_text, sizeof(label_time_text), label_format, localtime( &ts_time->tv_sec ) ); char label_text[1024]; - int label_tt_len = strlen( label_time_text ); const char *s_ptr = label_time_text; char *d_ptr = label_text; while ( *s_ptr && ((d_ptr-label_text) < sizeof(label_text)) ) @@ -2252,7 +2256,7 @@ bool Monitor::closeEvent() { if ( function == RECORD || function == MOCORD ) { - gettimeofday( &(event->EndTime()), &dummy_tz ); + gettimeofday( &(event->EndTime()), NULL ); } delete event; event = 0; @@ -2550,7 +2554,7 @@ bool MonitorStream::checkSwapPath( const char *path, bool create_path ) void MonitorStream::processCommand( const CmdMsg *msg ) { - Debug( 2, ( "Got message, type %d, msg %d", msg->msg_type, msg->msg_data[0] )); + Debug( 2, ( "Got message, type %ld, msg %d", msg->msg_type, msg->msg_data[0] )); // Check for incoming command switch( (MsgCommand)msg->msg_data[0] ) { @@ -2869,7 +2873,7 @@ void MonitorStream::sendFrame( Image *image, struct timeval *timestamp ) if ( !frame_count ) base_time = *timestamp; DELTA_TIMEVAL( delta_time, *timestamp, base_time, DT_PREC_3 ); - double pts = vid_stream->EncodeFrame( send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_time.delta ); + /* double pts = */ vid_stream->EncodeFrame( send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_time.delta ); } else #endif // HAVE_LIBAVCODEC @@ -2897,6 +2901,9 @@ void MonitorStream::sendFrame( Image *image, struct timeval *timestamp ) send_image->Zip( img_buffer, &zip_buffer_size ); img_buffer_size = zip_buffer_size; break; + default : + Fatal(( "Unexpected frame type %d", type )); + break; } fprintf( stdout, "Content-Length: %d\r\n\r\n", img_buffer_size ); fwrite( img_buffer, img_buffer_size, 1, stdout ); @@ -2936,7 +2943,6 @@ void MonitorStream::runStream() temp_read_index = temp_image_buffer_count; temp_write_index = temp_image_buffer_count; - char swap_file_name[PATH_MAX]; char swap_path[PATH_MAX] = ""; if ( connkey ) @@ -2978,7 +2984,7 @@ void MonitorStream::runStream() break; } - gettimeofday( &now, &dummy_tz ); + gettimeofday( &now, NULL ); if ( buffer_playback ) { @@ -3198,7 +3204,6 @@ void MonitorStream::runStream() void Monitor::SingleImage( int scale) { - int last_read_index = shared_data->last_write_index; int img_buffer_size = 0; static JOCTET img_buffer[ZM_MAX_IMAGE_SIZE]; Image scaled_image; @@ -3225,7 +3230,6 @@ void Monitor::SingleImage( int scale) void Monitor::SingleImageRaw( int scale) { - int last_read_index = shared_data->last_write_index; Image scaled_image; int index = shared_data->last_write_index%image_buffer_count; Snapshot *snap = &image_buffer[index]; @@ -3249,7 +3253,6 @@ void Monitor::SingleImageRaw( int scale) void Monitor::SingleImageZip( int scale) { - int last_read_index = shared_data->last_write_index; unsigned long img_buffer_size = 0; static Bytef img_buffer[ZM_MAX_IMAGE_SIZE]; Image scaled_image; @@ -3269,7 +3272,7 @@ void Monitor::SingleImageZip( int scale) } snap_image->Zip( img_buffer, &img_buffer_size ); - fprintf( stdout, "Content-Length: %d\r\n", img_buffer_size ); + fprintf( stdout, "Content-Length: %ld\r\n", img_buffer_size ); fprintf( stdout, "Content-Type: image/x-rgbz\r\n\r\n" ); fwrite( img_buffer, img_buffer_size, 1, stdout ); } diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 925dcaf7f..ff7e09b8a 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -22,8 +22,6 @@ #include -static struct timezone dummy_tz; // To avoid declaring pointless one each time we use gettimeofday - #include "zm_coord.h" #include "zm_image.h" #include "zm_zone.h" @@ -118,7 +116,7 @@ protected: class MonitorLink { protected: - int id; + unsigned int id; char name[64]; bool connected; @@ -166,7 +164,7 @@ protected: protected: // These are read from the DB and thereafter remain unchanged - int id; + unsigned int id; char name[64]; Function function; // What the monitor is doing bool enabled; // Whether the monitor is enabled or asleep diff --git a/src/zm_remote_camera.cpp b/src/zm_remote_camera.cpp index e34a2e79d..80df1187c 100644 --- a/src/zm_remote_camera.cpp +++ b/src/zm_remote_camera.cpp @@ -539,6 +539,11 @@ int RemoteCamera::GetResponse() Debug( 3, ( "Returning %d (%d) bytes of captured content", content_length, buffer.Size() )); return( content_length ); } + default : + { + Error(( "Unexpected content parsing state %d", state )); + break; + } } } } @@ -660,7 +665,7 @@ int RemoteCamera::GetResponse() } Debug( 6, ( header_ptr )); - if ( crlf = mempbrk( header_ptr, "\r\n", header_len ) ) + if ( ( crlf = mempbrk( header_ptr, "\r\n", header_len ) ) ) { headers[n_headers++] = header_ptr; @@ -728,7 +733,7 @@ int RemoteCamera::GetResponse() if ( status < 200 || status > 299 ) { - Error(( "Invalid response status %d: %s", status_code, status_mesg )); + Error(( "Invalid response status %s: %s", status_code, status_mesg )); return( -1 ); } Debug( 3, ( "Got status '%d' (%s), http version %s", status, status_mesg, http_version )); @@ -750,7 +755,7 @@ int RemoteCamera::GetResponse() { memset( content_type, 0, sizeof(content_type) ); start_ptr = content_type_header + strspn( content_type_header, " " ); - if ( end_ptr = strchr( start_ptr, ';' ) ) + if ( ( end_ptr = strchr( start_ptr, ';' ) ) ) { strncpy( content_type, start_ptr, end_ptr-start_ptr ); Debug( 3, ( "Got content type '%s'", content_type )); @@ -872,7 +877,7 @@ int RemoteCamera::GetResponse() Debug( 6, ( "%d: %s", subheader_len, subheader_ptr )); - if ( crlf = mempbrk( subheader_ptr, "\r\n", subheader_len ) ) + if ( ( crlf = mempbrk( subheader_ptr, "\r\n", subheader_len ) ) ) { subheaders[n_subheaders++] = subheader_ptr; @@ -909,7 +914,7 @@ int RemoteCamera::GetResponse() if ( all_headers && boundary_header ) { - char *start_ptr, *end_ptr; + char *start_ptr; Debug( 3, ( "Got boundary '%s'", boundary_header )); @@ -1153,7 +1158,6 @@ void RemoteCamera::Base64Encode( const char *in_string, char *out_string ) base64_table[i++] = '/'; } - int in_len = strlen( in_string ); const char *in_ptr = in_string; char *out_ptr = out_string; while( *in_ptr ) diff --git a/src/zm_signal.cpp b/src/zm_signal.cpp index 14c0e2a2f..44239339b 100644 --- a/src/zm_signal.cpp +++ b/src/zm_signal.cpp @@ -86,7 +86,7 @@ RETSIGTYPE zm_die_handler( int signal ) int trace_size = 0; #if HAVE_STRUCT_SIGCONTEXT_EIP - Error(( "Signal address is %p, from %p\n", context.cr2, context.eip )); + Error(( "Signal address is %p, from %p\n", (void *)context.cr2, (void *)context.eip )); trace_size = backtrace( trace, 16 ); // overwrite sigaction with caller's address diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index 6b03f3035..a32eca1e6 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -94,9 +94,6 @@ bool StreamBase::checkCommandQueue() Image *StreamBase::prepareImage( Image *image ) { - int img_buffer_size = 0; - static JOCTET img_buffer[ZM_MAX_IMAGE_SIZE]; - static int last_scale = 0; static int last_zoom = 0; static int last_x = 0; @@ -247,7 +244,7 @@ void StreamBase::sendTextFrame( const char *frame_text ) fprintf( stdout, "Content-type: %s\r\n\r\n", vid_stream->MimeType() ); vid_stream->OpenStream(); } - double pts = vid_stream->EncodeFrame( image.Buffer(), image.Size() ); + /* double pts = */ vid_stream->EncodeFrame( image.Buffer(), image.Size() ); } else #endif // HAVE_LIBAVCODEC diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index 6f777456c..92655132a 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -131,8 +131,6 @@ bool Zone::CheckAlarms( const Image *delta_image ) // Get the difference image Image *diff_image = image = new Image( *delta_image ); int diff_width = diff_image->Width(); - int diff_height = diff_image->Height(); - int diff_stride = diff_width * diff_image->Colours(); unsigned long pixel_diff_count = 0; @@ -346,15 +344,13 @@ bool Zone::CheckAlarms( const Image *delta_image ) { int lo_x = ranges[py].lo_x; int hi_x = ranges[py].hi_x; - int last_lo_x = py>=0?ranges[py-1].lo_x:0; - int last_hi_x = py>=0?ranges[py-1].hi_x:0; pdiff = diff_image->Buffer( lo_x, y ); for ( int x = lo_x; x <= hi_x; x++, pdiff++ ) { if ( *pdiff == WHITE ) { - Debug( 9, ( "Got white pixel at %d,%d (%x)", x, y, pdiff )); + Debug( 9, ( "Got white pixel at %d,%d (%p)", x, y, pdiff )); //last_x = (x>lo_x)?*(pdiff-1):0; //last_y = (y>lo_y&&x>=last_lo_x&&x<=last_hi_x)?*(pdiff-diff_width):0; last_x = x>0?*(pdiff-1):0; @@ -398,7 +394,7 @@ bool Zone::CheckAlarms( const Image *delta_image ) spdiff = diff_image->Buffer( lo_sx, sy ); for ( int sx = lo_sx; sx <= hi_sx; sx++, spdiff++ ) { - Debug( 9, ( "Pixel at %d,%d (%x) is %d", sx, sy, spdiff, *spdiff )); + Debug( 9, ( "Pixel at %d,%d (%p) is %d", sx, sy, spdiff, *spdiff )); if ( *spdiff == bss->tag ) { Debug( 9, ( "Setting pixel" )); @@ -838,7 +834,7 @@ bool Zone::ParseZoneString( const char *zone_string, int &zone_id, int &colour, char *ws = strchr( str, ' ' ); if ( !ws ) { - Debug( 3, ( "No whitespace found in zone string, finishing", zone_string )); + Debug( 3, ( "No whitespace found in zone string '%s', finishing", zone_string )); } zone_id = strtol( str, 0, 10 ); Debug( 3, ( "Got zone %d from zone string", zone_id )); @@ -901,7 +897,7 @@ int Zone::Load( Monitor *monitor, Zone **&zones ) const char *Name = dbrow[col++]; int Type = atoi(dbrow[col++]); const char *Units = dbrow[col++]; - int NumCoords = atoi(dbrow[col++]); + /* int NumCoords = */ atoi(dbrow[col++]); const char *Coords = dbrow[col++]; int AlarmRGB = dbrow[col]?atoi(dbrow[col]):0; col++; int CheckMethod = atoi(dbrow[col++]); diff --git a/src/zma.cpp b/src/zma.cpp index 59a041ca9..3a56c9066 100644 --- a/src/zma.cpp +++ b/src/zma.cpp @@ -109,7 +109,6 @@ int main( int argc, char *argv[] ) sigset_t block_set; sigemptyset( &block_set ); - struct sigaction action, old_action; while( !zm_terminate ) { diff --git a/src/zmc.cpp b/src/zmc.cpp index 358c89735..5d9a67e9c 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -187,7 +187,6 @@ int main( int argc, char *argv[] ) sigset_t block_set; sigemptyset( &block_set ); - struct sigaction action, old_action; sigaddset( &block_set, SIGUSR1 ); sigaddset( &block_set, SIGUSR2 ); @@ -218,7 +217,7 @@ int main( int argc, char *argv[] ) { long min_delay = MAXINT; - gettimeofday( &now, &dummy_tz ); + gettimeofday( &now, NULL ); for ( int j = 0; j < n_monitors; j++ ) { if ( last_capture_times[j].tv_sec ) @@ -256,7 +255,7 @@ int main( int argc, char *argv[] ) if ( next_delays[i] > 0 ) { - gettimeofday( &now, &dummy_tz ); + gettimeofday( &now, NULL ); DELTA_TIMEVAL( delta_time, now, last_capture_times[i], DT_PREC_3 ); long sleep_time = next_delays[i]-delta_time.delta; if ( sleep_time > 0 ) @@ -264,7 +263,7 @@ int main( int argc, char *argv[] ) usleep( sleep_time*(DT_MAXGRAN/DT_PREC_3) ); } } - gettimeofday( &(last_capture_times[i]), &dummy_tz ); + gettimeofday( &(last_capture_times[i]), NULL ); } } sigprocmask( SIG_UNBLOCK, &block_set, 0 ); diff --git a/src/zmf.cpp b/src/zmf.cpp index 67d1f51fc..254404090 100644 --- a/src/zmf.cpp +++ b/src/zmf.cpp @@ -177,7 +177,6 @@ int main( int argc, char *argv[] ) sigset_t block_set; sigemptyset( &block_set ); - struct sigaction action, old_action; int sd = OpenSocket( monitor->Id() ); @@ -223,7 +222,7 @@ int main( int argc, char *argv[] ) } else { - Warning(( "Socket closed at remote end", n_bytes )); + Warning(( "Socket closed at remote end" )); } ReopenSocket( sd, monitor->Id() ); continue; @@ -243,7 +242,7 @@ int main( int argc, char *argv[] ) } else { - Warning(( "Socket closed at remote end", n_bytes )); + Warning(( "Socket closed at remote end" )); } ReopenSocket( sd, monitor->Id() ); continue; @@ -256,7 +255,7 @@ int main( int argc, char *argv[] ) } else { - snprintf( subpath, sizeof(subpath), "%d", frame_header.event_id ); + snprintf( subpath, sizeof(subpath), "%ld", frame_header.event_id ); } static char path[PATH_MAX] = ""; snprintf( path, sizeof(path), frame_header.alarm_frame?anal_path:capt_path, subpath, frame_header.frame_id );