Added realtime option to event streaming.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@540 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-05-27 08:59:11 +00:00
parent 384881798f
commit 57158a3eac
2 changed files with 7 additions and 10 deletions

View File

@ -267,7 +267,7 @@ void Event::AddFrame( struct timeval timestamp, const Image *image, const Image
void Event::StreamEvent( const char *path, int event_id, unsigned long refresh, FILE *fd ) void Event::StreamEvent( const char *path, int event_id, unsigned long refresh, FILE *fd )
{ {
static char sql[256]; static char sql[256];
sprintf( sql, "select Id, EventId, ImagePath, Delta*10000 from Frames where EventId = %d order by Id", event_id ); sprintf( sql, "select Id, EventId, ImagePath, Delta from Frames where EventId = %d order by Id", event_id );
if ( mysql_query( &dbconn, sql ) ) if ( mysql_query( &dbconn, sql ) )
{ {
Error(( "Can't run query: %s", mysql_error( &dbconn ) )); Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
@ -294,19 +294,16 @@ void Event::StreamEvent( const char *path, int event_id, unsigned long refresh,
FILE *fdj = NULL; FILE *fdj = NULL;
int n_bytes = 0; int n_bytes = 0;
static unsigned char buffer[400000]; static unsigned char buffer[400000];
int last_delta = 0; double last_delta = 0;
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
{ {
if ( !refresh ) if ( refresh < 0 )
{ {
if ( !i ) if ( i )
{ {
last_delta = atoi(dbrow[3]); usleep( (int)((1000000*(atof(dbrow[3])-last_delta))/abs(refresh)) );
}
else
{
usleep( atoi(dbrow[3])-last_delta );
} }
last_delta = atof(dbrow[3]);
} }
char filepath[PATH_MAX]; char filepath[PATH_MAX];
sprintf( filepath, "%s/%s", path, dbrow[2] ); sprintf( filepath, "%s/%s", path, dbrow[2] );

View File

@ -79,7 +79,7 @@ public:
void AddFrames( int n_frames, struct timeval **timestamps, const Image **images ); void AddFrames( int n_frames, struct timeval **timestamps, const Image **images );
void AddFrame( struct timeval timestamp, const Image *image, const Image *alarm_frame=NULL, unsigned int score=0 ); void AddFrame( struct timeval timestamp, const Image *image, const Image *alarm_frame=NULL, unsigned int score=0 );
static void StreamEvent( const char *path, int event_id, unsigned long refresh=100, FILE *fd=stdout ); static void StreamEvent( const char *path, int event_id, unsigned long refresh=-1, FILE *fd=stdout );
}; };
#endif // ZM_EVENT_H #endif // ZM_EVENT_H