Merge pull request #79 from knnniggett/frameserver
Added frameserver patch from Zoneminder Wiki Changes the socket reader in zmf from a single read, to a loop read. Incomplete reads would be reported even though the image writer wrote the whole image to the socket. The problem was when the read went to read the image frame from the socket, all the data had not yet been written to the socket by the writer, so the reader thought there was a problem. The loop reads from the socket until a full image frame is read, or there is an error. Originally at http://www.zoneminder.com/wiki/index.php/1.24.2_Patches
This commit is contained in:
commit
de9b1af1a1
37
src/zmf.cpp
37
src/zmf.cpp
|
@ -233,17 +233,40 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
Debug( 1, "Read frame header, expecting %ld 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];
|
||||||
n_bytes = read( sd, image_data, frame_header.image_length );
|
|
||||||
if ( n_bytes != (ssize_t)frame_header.image_length )
|
// Read for pipe and loop until bytes expected have been read or an error occures
|
||||||
|
int bytes_read = 0;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
|
n_bytes = read( sd, image_data+bytes_read, frame_header.image_length-bytes_read );
|
||||||
|
if (n_bytes < 0) break; // break on error
|
||||||
|
if (n_bytes < frame_header.image_length)
|
||||||
|
{
|
||||||
|
// print some informational messages
|
||||||
|
if (bytes_read == 0)
|
||||||
|
{
|
||||||
|
// Warning("Image read : Short read %d bytes of %d expected bytes",n_bytes,frame_header.image_length);
|
||||||
|
}
|
||||||
|
else if (bytes_read+n_bytes == frame_header.image_length)
|
||||||
|
{
|
||||||
|
// Warning("Image read : Read rest of short read: %d bytes read total of %d bytes",n_bytes,frame_header.image_length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Warning("Image read : continuing, read %d bytes (%d so far)", n_bytes, bytes_read+n_bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bytes_read+= n_bytes;
|
||||||
|
} while (n_bytes>0 && (bytes_read < (ssize_t)frame_header.image_length) );
|
||||||
|
|
||||||
|
// Print errors if there was a problem
|
||||||
|
if ( n_bytes < 1 )
|
||||||
|
{
|
||||||
|
Error( "Only read %d bytes of %d\n", bytes_read, frame_header.image_length);
|
||||||
if ( n_bytes < 0 )
|
if ( n_bytes < 0 )
|
||||||
{
|
{
|
||||||
Error( "Can't read frame image data: %s", strerror(errno) );
|
Error( "Can't read frame image data: %s", strerror(errno) );
|
||||||
}
|
}
|
||||||
else if ( n_bytes > 0 )
|
|
||||||
{
|
|
||||||
Error( "Incomplete read of frame image data, %d bytes only", n_bytes );
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Warning( "Socket closed at remote end" );
|
Warning( "Socket closed at remote end" );
|
||||||
|
@ -251,6 +274,7 @@ int main( int argc, char *argv[] )
|
||||||
ReopenSocket( sd, monitor->Id() );
|
ReopenSocket( sd, monitor->Id() );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char subpath[PATH_MAX] = "";
|
static char subpath[PATH_MAX] = "";
|
||||||
if ( config.use_deep_storage )
|
if ( config.use_deep_storage )
|
||||||
{
|
{
|
||||||
|
@ -261,6 +285,7 @@ int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
snprintf( subpath, sizeof(subpath), "%ld", frame_header.event_id );
|
snprintf( subpath, sizeof(subpath), "%ld", frame_header.event_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
static char path[PATH_MAX] = "";
|
static char path[PATH_MAX] = "";
|
||||||
snprintf( path, sizeof(path), frame_header.alarm_frame?anal_path:capt_path, subpath, frame_header.frame_id );
|
snprintf( path, sizeof(path), frame_header.alarm_frame?anal_path:capt_path, subpath, frame_header.frame_id );
|
||||||
Debug( 1, "Got image, writing to %s", path );
|
Debug( 1, "Got image, writing to %s", path );
|
||||||
|
|
Loading…
Reference in New Issue