Fixed path problem when streaming.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@814 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2004-02-05 21:58:44 +00:00
parent d4cdf761ff
commit 9fc320fbf7
5 changed files with 34 additions and 10 deletions

View File

@ -27,6 +27,7 @@
#define ZM_DB_PASSA "<from zmconfig>" // Privileged DB user password
#define ZM_DB_USERB "<from zmconfig>" // Unprivileged DB user name, need just select privilege.
#define ZM_DB_PASSB "<from zmconfig>" // Unprivileged DB user password
#define ZM_PATH_WEB "<from zmconfig>" // Path to web files
#define ZM_MAX_IMAGE_WIDTH 2048 // The largest image we imagine ever handling
#define ZM_MAX_IMAGE_HEIGHT 1536 // The largest image we imagine ever handling

View File

@ -319,11 +319,12 @@ void Event::AddFrame( struct timeval timestamp, const Image *image, unsigned int
}
}
void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FILE *fd )
void Event::StreamEvent( int event_id, int rate, int scale, FILE *fd )
{
static char sql[BUFSIZ];
static char eventpath[PATH_MAX];
sprintf( sql, "select Id, EventId, Delta from Frames where EventId = %d order by Id", event_id );
sprintf( sql, "select M.Id, M.Name from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = %d", event_id );
if ( mysql_query( &dbconn, sql ) )
{
Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
@ -336,6 +337,31 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI
Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
MYSQL_ROW dbrow = mysql_fetch_row( result );
if ( mysql_errno( &dbconn ) )
{
Error(( "Can't fetch row: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
sprintf( eventpath, "%s/%s/%s/%d", ZM_PATH_WEB, (const char *)config.Item( ZM_DIR_EVENTS ), dbrow[1], event_id );
mysql_free_result( result );
sprintf( sql, "select FrameId, EventId, Delta from Frames where EventId = %d order by FrameId", event_id );
if ( mysql_query( &dbconn, sql ) )
{
Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
result = mysql_store_result( &dbconn );
if ( !result )
{
Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
setbuf( fd, 0 );
@ -364,7 +390,7 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI
struct DeltaTimeval delta_time;
gettimeofday( &now, &dummy_tz );
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
for( int i = 0; dbrow = mysql_fetch_row( result ); i++ )
{
if ( rate )
{
@ -390,7 +416,7 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI
gettimeofday( &last_now, &dummy_tz );
}
static char filepath[PATH_MAX];
sprintf( filepath, "%s/%03d-capture.jpg", path, dbrow[0] );
sprintf( filepath, "%s/%03d-capture.jpg", eventpath, atoi(dbrow[0]) );
fprintf( fd, "Content-type: image/jpg\n\n" );
if ( scale == 1 )

View File

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

View File

@ -29,7 +29,6 @@ int main(void )
unsigned int rate = 1;
unsigned int scale = 1;
int event = 0;
const char *path = ".";
unsigned int ttl = 0;
//setbuf( fd, 0 );
@ -66,8 +65,6 @@ int main(void )
id = atoi( value );
else if ( !strcmp( name, "event" ) )
event = strtoull( value, (char **)NULL, 10 );
else if ( !strcmp( name, "path" ) )
path = value;
else if ( !strcmp( name, "ttl" ) )
ttl = atoi(value);
}
@ -90,7 +87,7 @@ int main(void )
}
else
{
Event::StreamEvent( path, event, rate, scale, stdout );
Event::StreamEvent( event, rate, scale, stdout );
}
return( 0 );
}

View File

@ -233,7 +233,7 @@ if ( $mode == "still" && $paged && !empty($page) )
<?php
if ( $mode == "stream" )
{
$stream_src = ZM_PATH_ZMS."?path=".ZM_PATH_WEB."&event=$eid&rate=$rate&scale=$scale";
$stream_src = ZM_PATH_ZMS."?event=$eid&rate=$rate&scale=$scale";
if ( canStreamNative() )
{
?>