From 64907c388ce0c5f0910d489f324085058ffeda70 Mon Sep 17 00:00:00 2001 From: stan Date: Fri, 4 Apr 2003 10:00:57 +0000 Subject: [PATCH] Revamped the streaming line endings slightly. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@446 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zm_event.cpp | 12 ++++++------ src/zm_monitor.cpp | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 1415f61d8..86fb0dcff 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -127,9 +127,10 @@ void Event::StreamEvent( const char *path, int event_id, unsigned long refresh, exit( mysql_errno( &dbconn ) ); } - fprintf( fd, "Server: ZoneMinder Stream Server\n" ); - fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\n\n" ); - fprintf( fd, "--ZoneMinderFrame\n" ); + setbuf( fd, 0 ); + fprintf( fd, "Server: ZoneMinder Stream Server\r\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 ); 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] ); 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 ) ) { fwrite( buffer, 1, n_bytes, fd ); } - fprintf( fd, "\n--ZoneMinderFrame\n" ); - fflush( fd ); + fprintf( fd, "\r\n--ZoneMinderFrame\r\n" ); fclose( fdj ); } else diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index a722c3a5b..846f57368 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -669,9 +669,10 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd, { time_t start_time, now; - fprintf( fd, "Server: ZoneMinder Stream Server\n" ); - fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\n\n" ); - fprintf( fd, "--ZoneMinderFrame\n" ); + setbuf( fd, 0 ); + fprintf( fd, "Server: ZoneMinder Stream Server\r\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; JOCTET img_buffer[camera->ImageSize()]; int img_buffer_size = 0; @@ -679,6 +680,10 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd, time( &start_time ); while ( true ) { + if ( feof( fd ) || ferror( fd ) ) + { + break; + } if ( last_read_index != shared_images->last_write_index ) { // Send the next frame @@ -689,10 +694,9 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd, Image *image = snap->image; 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 ); - fprintf( fd, "\n--ZoneMinderFrame\n" ); - fflush( fd ); + fprintf( fd, "\r\n--ZoneMinderFrame\r\n" ); } usleep( refresh*1000 ); for ( int i = 0; shared_images->state == IDLE && i < loop_count; i++ )