diff --git a/src/zm.cpp b/src/zm.cpp index 2e6b7fee3..16dd91835 100644 --- a/src/zm.cpp +++ b/src/zm.cpp @@ -2405,8 +2405,10 @@ Monitor *Monitor::Load( int id, bool load_zones ) return( monitor ); } -void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd ) +void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd, unsigned int ttl ) { + time_t start_time, now; + fprintf( fd, "Server: ZoneMinder Stream Server\r\n" ); fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n" ); fprintf( fd, "\r\n" ); @@ -2415,6 +2417,7 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd JOCTET img_buffer[camera->ImageSize()]; int img_buffer_size = 0; int loop_count = (idle/refresh)-1; + time( &start_time ); while ( true ) { if ( last_read_index != shared_images->last_write_index ) @@ -2437,6 +2440,14 @@ void Monitor::StreamImages( unsigned long idle, unsigned long refresh, FILE *fd { usleep( refresh*1000 ); } + if ( ttl ) + { + time( &now ); + if ( (now - start_time) > ttl ) + { + break; + } + } } } diff --git a/src/zm.h b/src/zm.h index 227971769..78c68fd66 100644 --- a/src/zm.h +++ b/src/zm.h @@ -738,5 +738,5 @@ public: void ReloadZones(); static int Load( int device, Monitor **&monitors, bool capture=true ); static Monitor *Load( int id, bool load_zones=false ); - void StreamImages( unsigned long idle=5000, unsigned long refresh=50, FILE *fd=stdout ); + void StreamImages( unsigned long idle=5000, unsigned long refresh=50, FILE *fd=stdout, unsigned int ttl=0 ); }; diff --git a/src/zms.cpp b/src/zms.cpp index 3bd7e7872..cb1a52568 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -26,6 +26,7 @@ int main( int argc, const char *argv[] ) unsigned long refresh = 50; int event = 0; char *path = "."; + unsigned int ttl = 0; const char *query = getenv( "QUERY_STRING" ); if ( query ) @@ -55,6 +56,8 @@ int main( int argc, const char *argv[] ) event = atoi( value ); else if ( !strcmp( name, "path" ) ) path = value; + else if ( !strcmp( name, "path" ) ) + ttl = atoi(value); } } @@ -83,7 +86,9 @@ int main( int argc, const char *argv[] ) Monitor *monitor = Monitor::Load( id ); if ( monitor ) - monitor->StreamImages( idle, refresh, stdout ); + { + monitor->StreamImages( idle, refresh, stdout, ttl ); + } } else {