Added ttl to streaming.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@401 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-03-21 10:53:55 +00:00
parent 7f3e3e8e38
commit c722d9046d
3 changed files with 19 additions and 3 deletions

View File

@ -2405,8 +2405,10 @@ Monitor *Monitor::Load( int id, bool load_zones )
return( monitor ); 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, "Server: ZoneMinder Stream Server\r\n" );
fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n" ); fprintf( fd, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n" );
fprintf( fd, "\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()]; JOCTET img_buffer[camera->ImageSize()];
int img_buffer_size = 0; int img_buffer_size = 0;
int loop_count = (idle/refresh)-1; int loop_count = (idle/refresh)-1;
time( &start_time );
while ( true ) while ( true )
{ {
if ( last_read_index != shared_images->last_write_index ) 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 ); usleep( refresh*1000 );
} }
if ( ttl )
{
time( &now );
if ( (now - start_time) > ttl )
{
break;
}
}
} }
} }

View File

@ -738,5 +738,5 @@ public:
void ReloadZones(); void ReloadZones();
static int Load( int device, Monitor **&monitors, bool capture=true ); static int Load( int device, Monitor **&monitors, bool capture=true );
static Monitor *Load( int id, bool load_zones=false ); 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 );
}; };

View File

@ -26,6 +26,7 @@ int main( int argc, const char *argv[] )
unsigned long refresh = 50; unsigned long refresh = 50;
int event = 0; int event = 0;
char *path = "."; char *path = ".";
unsigned int ttl = 0;
const char *query = getenv( "QUERY_STRING" ); const char *query = getenv( "QUERY_STRING" );
if ( query ) if ( query )
@ -55,6 +56,8 @@ int main( int argc, const char *argv[] )
event = atoi( value ); event = atoi( value );
else if ( !strcmp( name, "path" ) ) else if ( !strcmp( name, "path" ) )
path = value; 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 ); Monitor *monitor = Monitor::Load( id );
if ( monitor ) if ( monitor )
monitor->StreamImages( idle, refresh, stdout ); {
monitor->StreamImages( idle, refresh, stdout, ttl );
}
} }
else else
{ {