Revamped the streaming line endings slightly.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@446 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-04-04 10:00:57 +00:00
parent 6265c24162
commit 64907c388c
2 changed files with 16 additions and 12 deletions

View File

@ -127,9 +127,10 @@ void Event::StreamEvent( const char *path, int event_id, unsigned long refresh,
exit( mysql_errno( &dbconn ) ); exit( mysql_errno( &dbconn ) );
} }
fprintf( fd, "Server: ZoneMinder Stream Server\n" ); setbuf( fd, 0 );
fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\n\n" ); fprintf( fd, "Server: ZoneMinder Stream Server\r\n" );
fprintf( fd, "--ZoneMinderFrame\n" ); fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n\r\n" );
fprintf( fd, "--ZoneMinderFrame\r\n" );
int n_frames = mysql_num_rows( result ); int n_frames = mysql_num_rows( result );
Info(( "Got %d frames\n", n_frames )); Info(( "Got %d frames\n", n_frames ));
@ -142,13 +143,12 @@ void Event::StreamEvent( const char *path, int event_id, unsigned long refresh,
sprintf( filepath, "%s/%s", path, dbrow[2] ); sprintf( filepath, "%s/%s", path, dbrow[2] );
if ( fdj = fopen( filepath, "r" ) ) if ( fdj = fopen( filepath, "r" ) )
{ {
fprintf( fd, "Content-type: image/jpg\n\n" ); fprintf( fd, "Content-type: image/jpg\r\n\r\n" );
while ( n_bytes = fread( buffer, 1, sizeof(buffer), fdj ) ) while ( n_bytes = fread( buffer, 1, sizeof(buffer), fdj ) )
{ {
fwrite( buffer, 1, n_bytes, fd ); fwrite( buffer, 1, n_bytes, fd );
} }
fprintf( fd, "\n--ZoneMinderFrame\n" ); fprintf( fd, "\r\n--ZoneMinderFrame\r\n" );
fflush( fd );
fclose( fdj ); fclose( fdj );
} }
else else

View File

@ -669,9 +669,10 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd,
{ {
time_t start_time, now; time_t start_time, now;
fprintf( fd, "Server: ZoneMinder Stream Server\n" ); setbuf( fd, 0 );
fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\n\n" ); fprintf( fd, "Server: ZoneMinder Stream Server\r\n" );
fprintf( fd, "--ZoneMinderFrame\n" ); fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n\r\n" );
fprintf( fd, "--ZoneMinderFrame\r\n" );
int last_read_index = image_buffer_count; int last_read_index = image_buffer_count;
JOCTET img_buffer[camera->ImageSize()]; JOCTET img_buffer[camera->ImageSize()];
int img_buffer_size = 0; int img_buffer_size = 0;
@ -679,6 +680,10 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd,
time( &start_time ); time( &start_time );
while ( true ) while ( true )
{ {
if ( feof( fd ) || ferror( fd ) )
{
break;
}
if ( last_read_index != shared_images->last_write_index ) if ( last_read_index != shared_images->last_write_index )
{ {
// Send the next frame // Send the next frame
@ -689,10 +694,9 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd,
Image *image = snap->image; Image *image = snap->image;
image->EncodeJpeg( img_buffer, &img_buffer_size ); image->EncodeJpeg( img_buffer, &img_buffer_size );
fprintf( fd, "Content-type: image/jpg\n\n" ); fprintf( fd, "Content-type: image/jpg\r\n\r\n" );
fwrite( img_buffer, 1, img_buffer_size, fd ); fwrite( img_buffer, 1, img_buffer_size, fd );
fprintf( fd, "\n--ZoneMinderFrame\n" ); fprintf( fd, "\r\n--ZoneMinderFrame\r\n" );
fflush( fd );
} }
usleep( refresh*1000 ); usleep( refresh*1000 );
for ( int i = 0; shared_images->state == IDLE && i < loop_count; i++ ) for ( int i = 0; shared_images->state == IDLE && i < loop_count; i++ )