Merge pull request #675 from ZoneMinder/small_performance_improvement

small performance improvement when streaming.
This commit is contained in:
Isaac Connor 2015-01-29 16:27:34 -05:00
commit 7e685bb04a
1 changed files with 30 additions and 29 deletions

View File

@ -3940,39 +3940,39 @@ void MonitorStream::runStream()
temp_read_index = temp_image_buffer_count; temp_read_index = temp_image_buffer_count;
temp_write_index = temp_image_buffer_count; temp_write_index = temp_image_buffer_count;
char swap_path[PATH_MAX] = ""; char *swap_path = 0;
bool buffered_playback = false; bool buffered_playback = false;
int swap_path_length = strlen(config.path_swap)+1; // +1 for NULL terminator
if ( connkey && playback_buffer > 0 ) if ( connkey && playback_buffer > 0 ) {
{
Debug( 2, "Checking swap image location" ); if ( swap_path_length + 15 > PATH_MAX ) {
Debug( 3, "Checking swap image path" ); // 15 is for /zmswap-whatever, assuming max 6 digits for monitor id
strncpy( swap_path, config.path_swap, sizeof(swap_path) ); Error( "Swap Path is too long. %d > %d ", swap_path_length+15, PATH_MAX );
if ( checkSwapPath( swap_path, false ) ) } else {
{ swap_path = (char *)malloc( swap_path_length+15 );
snprintf( &(swap_path[strlen(swap_path)]), sizeof(swap_path)-strlen(swap_path), "/zmswap-m%d", monitor->Id() ); Debug( 3, "Checking swap image path %s", config.path_swap );
if ( checkSwapPath( swap_path, true ) ) strncpy( swap_path, config.path_swap, swap_path_length );
{ if ( checkSwapPath( swap_path, false ) ) {
snprintf( &(swap_path[strlen(swap_path)]), sizeof(swap_path)-strlen(swap_path), "/zmswap-q%06d", connkey ); snprintf( &(swap_path[swap_path_length]), sizeof(swap_path)-swap_path_length, "/zmswap-m%d", monitor->Id() );
if ( checkSwapPath( swap_path, true ) ) if ( checkSwapPath( swap_path, true ) ) {
{ snprintf( &(swap_path[swap_path_length]), sizeof(swap_path)-swap_path_length, "/zmswap-q%06d", connkey );
if ( checkSwapPath( swap_path, true ) ) {
buffered_playback = true; buffered_playback = true;
} }
} }
} }
if ( !buffered_playback ) if ( !buffered_playback ) {
{
Error( "Unable to validate swap image path, disabling buffered playback" ); Error( "Unable to validate swap image path, disabling buffered playback" );
} } else {
else
{
Debug( 2, "Assigning temporary buffer" ); Debug( 2, "Assigning temporary buffer" );
temp_image_buffer = new SwapImage[temp_image_buffer_count]; temp_image_buffer = new SwapImage[temp_image_buffer_count];
memset( temp_image_buffer, 0, sizeof(*temp_image_buffer)*temp_image_buffer_count ); memset( temp_image_buffer, 0, sizeof(*temp_image_buffer)*temp_image_buffer_count );
Debug( 2, "Assigned temporary buffer" ); Debug( 2, "Assigned temporary buffer" );
} }
} }
}
float max_secs_since_last_sent_frame = 10.0; //should be > keep alive amount (5 secs) float max_secs_since_last_sent_frame = 10.0; //should be > keep alive amount (5 secs)
while ( !zm_terminate ) while ( !zm_terminate )
@ -4209,6 +4209,7 @@ void MonitorStream::runStream()
} }
} }
} }
if ( swap_path ) free( swap_path );
closeComms(); closeComms();
} }