Bug 73 - Made video devices use paths rather than numbers

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1519 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2005-10-17 10:58:25 +00:00
parent 8a66238a2b
commit 74e4bd5737
11 changed files with 76 additions and 101 deletions

View File

@ -4,6 +4,9 @@
alter table Monitors add column WebColour varchar(32) not null default 'red';
update Monitors set WebColour = concat( '#', hex(14*rand()),hex(15*rand()),hex(14*rand()),hex(15*rand()),hex(14*rand()),hex(15*rand()) );
alter table Monitors add column Sequence smallint unsigned;
alter table Monitors modify column Device tinytext;
update Monitors set Device = concat( "/dev/video", Device );
update Monitors set Device = NULL where Type = "Remote";
alter table Events add column Height smallint(5) unsigned not null default '0' after EndTime;
alter table Events add column Width smallint(5) unsigned not null default '0' after EndTime;
--

View File

@ -43,7 +43,7 @@ short *LocalCamera::g_v_table;
short *LocalCamera::g_u_table;
short *LocalCamera::b_u_table;
LocalCamera::LocalCamera( int p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture ) : Camera( LOCAL, p_width, p_height, p_palette, p_brightness, p_contrast, p_hue, p_colour, p_capture ), device( p_device ), channel( p_channel ), format( p_format )
LocalCamera::LocalCamera( const char *p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture ) : Camera( LOCAL, p_width, p_height, p_palette, p_brightness, p_contrast, p_hue, p_colour, p_capture ), device( p_device ), channel( p_channel ), format( p_format )
{
if ( !camera_count++ && capture )
{
@ -61,12 +61,9 @@ LocalCamera::~LocalCamera()
void LocalCamera::Initialise()
{
char device_path[64];
snprintf( device_path, sizeof(device_path), "/dev/video%d", device );
if ( (m_videohandle=open(device_path, O_RDWR)) < 0 )
if ( (m_videohandle=open(device, O_RDWR)) < 0 )
{
Error(( "Failed to open video device %s: %s", device_path, strerror(errno) ));
Error(( "Failed to open video device %s: %s", device, strerror(errno) ));
exit(-1);
}
@ -266,19 +263,16 @@ void LocalCamera::Terminate()
close(m_videohandle);
}
bool LocalCamera::GetCurrentSettings( int device, char *output, bool verbose )
bool LocalCamera::GetCurrentSettings( const char *device, char *output, bool verbose )
{
char device_path[64];
output[0] = 0;
snprintf( device_path, sizeof(device_path), "/dev/video%d", device );
if ( verbose )
sprintf( output, output+strlen(output), "Checking Video Device: %s\n", device_path );
if ( (m_videohandle=open(device_path, O_RDWR)) <=0 )
sprintf( output, output+strlen(output), "Checking Video Device: %s\n", device );
if ( (m_videohandle=open(device, O_RDWR)) <=0 )
{
Error(( "Failed to open video device %s: %s", device_path, strerror(errno) ));
Error(( "Failed to open video device %s: %s", device, strerror(errno) ));
if ( verbose )
sprintf( output+strlen(output), "Error, failed to open video device: %s\n", strerror(errno) );
sprintf( output+strlen(output), "Error, failed to open video device %s: %s\n", device, strerror(errno) );
else
sprintf( output+strlen(output), "error%d\n", errno );
return( false );
@ -289,7 +283,7 @@ bool LocalCamera::GetCurrentSettings( int device, char *output, bool verbose )
{
Error(( "Failed to get video capabilities: %s", strerror(errno) ));
if ( verbose )
sprintf( output, "Error, failed to get video capabilities: %s\n", strerror(errno) );
sprintf( output, "Error, failed to get video capabilities %s: %s\n", device, strerror(errno) );
else
sprintf( output, "error%d\n", errno );
return( false );

View File

@ -33,13 +33,13 @@
class LocalCamera : public Camera
{
protected:
int device;
const char *device;
int channel;
int format;
protected:
static int m_cap_frame;
static int m_cap_frame_active;
static int m_cap_frame_active;
static int m_sync_frame;
static video_mbuf m_vmb;
static video_mmap *m_vmm;
@ -54,13 +54,13 @@ protected:
static short *b_u_table;
public:
LocalCamera( int p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture=true );
LocalCamera( const char *p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture=true );
~LocalCamera();
void Initialise();
void Terminate();
unsigned int Device() const { return( device ); }
const char *Device() const { return( device ); }
unsigned int Channel() const { return( channel ); }
unsigned int Format() const { return( format ); }
@ -72,7 +72,7 @@ public:
int PreCapture();
int PostCapture( Image &image );
static bool GetCurrentSettings( int device, char *output, bool verbose );
static bool GetCurrentSettings( const char *device, char *output, bool verbose );
};
#endif // ZM_LOCAL_CAMERA_H

View File

@ -31,7 +31,7 @@ Monitor::Monitor(
int p_id,
char *p_name,
int p_function,
int p_device,
const char *p_device,
int p_channel,
int p_format,
int p_width,
@ -1001,16 +1001,16 @@ void Monitor::ReloadZones()
DumpZoneImage();
}
int Monitor::Load( int device, Monitor **&monitors, Purpose purpose )
int Monitor::Load( const char *device, Monitor **&monitors, Purpose purpose )
{
static char sql[BUFSIZ];
if ( device == -1 )
if ( !device[0] )
{
strncpy( sql, "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local'", sizeof(sql) );
}
else
{
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local' and Device = %d", device );
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Local' and Device = '%s'", device );
}
if ( mysql_query( &dbconn, sql ) )
{
@ -1034,7 +1034,7 @@ int Monitor::Load( int device, Monitor **&monitors, Purpose purpose )
atoi(dbrow[0]), // Id
dbrow[1], // Name
atoi(dbrow[2]), // Function
atoi(dbrow[3]), // Device
dbrow[3], // Device
atoi(dbrow[4]), // Channel
atoi(dbrow[5]), // Format
atoi(dbrow[6]), // Width
@ -1180,7 +1180,7 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose )
atoi(dbrow[0]), // Id
dbrow[1], // Name
atoi(dbrow[3]), // Function
atoi(dbrow[4]), // Device
dbrow[4], // Device
atoi(dbrow[5]), // Channel
atoi(dbrow[6]), // Format
atoi(dbrow[10]), // Width
@ -1464,7 +1464,7 @@ bool Monitor::DumpSettings( char *output, bool verbose )
sprintf( output+strlen(output), "Type : %s\n", camera->IsLocal()?"Local":"Remote" );
if ( camera->IsLocal() )
{
sprintf( output+strlen(output), "Device : %d\n", ((LocalCamera *)camera)->Device() );
sprintf( output+strlen(output), "Device : %s\n", ((LocalCamera *)camera)->Device() );
sprintf( output+strlen(output), "Channel : %d\n", ((LocalCamera *)camera)->Channel() );
sprintf( output+strlen(output), "Format : %d\n", ((LocalCamera *)camera)->Format() );
}

View File

@ -158,7 +158,7 @@ protected:
Camera *camera;
public:
Monitor( int p_id, char *p_name, int p_function, int p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_orientation, int p_brightness, int p_contrast, int p_hue, int p_colour, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_alarm_frame_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, bool p_track_motion, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
Monitor( int p_id, char *p_name, int p_function, const char *p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_orientation, int p_brightness, int p_contrast, int p_hue, int p_colour, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_alarm_frame_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, bool p_track_motion, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
Monitor( int p_id, char *p_name, int p_function, const char *p_host, const char *p_port, const char *p_path, int p_width, int p_height, int p_palette, int p_orientation, int p_brightness, int p_contrast, int p_hue, int p_colour, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_alarm_frame_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, bool p_track_motion, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
~Monitor();
@ -341,7 +341,7 @@ public:
unsigned int Compare( const Image &comp_image );
void ReloadZones();
static int Load( int device, Monitor **&monitors, Purpose purpose=QUERY );
static int Load( const char *device, Monitor **&monitors, Purpose purpose=QUERY );
static int Load( const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose=QUERY );
static Monitor *Load( int id, bool load_zones=false, Purpose purpose=QUERY );
void StreamImages( int scale=100, int maxfps=10, time_t ttl=0 );

View File

@ -35,10 +35,10 @@ void zmc_term_handler( int /* signal */ )
void Usage()
{
fprintf( stderr, "zmc -d <device_id> or -m <monitor_id>\n" );
fprintf( stderr, "zmc -d <device_path> or -H <host> -P <port> -p <path> or -m <monitor_id>\n" );
fprintf( stderr, "Options:\n" );
fprintf( stderr, " -d, --device <device_id> : For local cameras, device to access 0=>/dev/video0 etc\n" );
fprintf( stderr, " -d, --device <device_path> : For local cameras, device to access. E.g /dev/video0 etc\n" );
fprintf( stderr, " -H <host> -P <port> -p <path> : For remote cameras\n" );
fprintf( stderr, " -m, --monitor <monitor_id> : For sources associated with a single monitor\n" );
fprintf( stderr, " -h, --help : This screen\n" );
@ -47,7 +47,7 @@ void Usage()
int main( int argc, char *argv[] )
{
int device = -1;
const char *device = "";
const char *host = "";
const char *port = "";
const char *path = "";
@ -76,7 +76,7 @@ int main( int argc, char *argv[] )
switch (c)
{
case 'd':
device = atoi(optarg);
device = optarg;
break;
case 'H':
host = optarg;
@ -109,8 +109,8 @@ int main( int argc, char *argv[] )
Usage();
}
if (( device >= 0 && host[0] )
|| ( device >= 0 && monitor_id > 0 )
if (( device[0] && host[0] )
|| ( device[0] && monitor_id > 0 )
|| ( monitor_id > 0 && host[0] ))
{
fprintf( stderr, "Only one of device or host/port/path or monitor id allowed\n" );
@ -118,7 +118,7 @@ int main( int argc, char *argv[] )
exit( 0 );
}
if ( device < 0 && !host[0] && monitor_id <= 0 )
if ( !device[0] && !host[0] && monitor_id <= 0 )
{
fprintf( stderr, "One of device or host/port/path or monitor id must be specified\n" );
Usage();
@ -126,9 +126,10 @@ int main( int argc, char *argv[] )
}
char dbg_id_string[16];
if ( device >= 0 )
if ( device[0] )
{
snprintf( dbg_id_string, sizeof(dbg_id_string), "d%d", device );
const char *slash_ptr = strrchr( device, '/' );
snprintf( dbg_id_string, sizeof(dbg_id_string), "d%s", slash_ptr?slash_ptr+1:device );
}
else if ( host[0] )
{
@ -145,7 +146,7 @@ int main( int argc, char *argv[] )
Monitor **monitors = 0;
int n_monitors = 0;
if ( device >= 0 )
if ( device[0] )
{
n_monitors = Monitor::Load( device, monitors, Monitor::CAPTURE );
}
@ -184,7 +185,7 @@ int main( int argc, char *argv[] )
sigaddset( &block_set, SIGUSR1 );
sigaddset( &block_set, SIGUSR2 );
if ( device >= 0 && n_monitors == 1 )
if ( device[0] && n_monitors == 1 )
{
monitors[0]->PreCapture();
}

View File

@ -78,71 +78,47 @@ bool fixDevice( const char *device_path )
return( true );
}
bool fixVideoDevice( int device )
{
char device_path[64];
snprintf( device_path, sizeof(device_path), "/dev/video%d", device );
return( fixDevice( device_path ) );
}
int main( int argc, char *argv[] )
{
zmDbgInit( "zmfix", "", -1 );
zmLoadConfig();
if ( argc > 1 && !strcmp( argv[1], "-a" ) )
// Only do registered devices
static char sql[BUFSIZ];
snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Type = 'Local'" );
if ( mysql_query( &dbconn, sql ) )
{
// Do all devices we can find
for ( int device = 0; device < 256; device++ )
{
if ( !fixVideoDevice( device ) )
{
break;
}
}
Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
else
MYSQL_RES *result = mysql_store_result( &dbconn );
if ( !result )
{
// Only do registered devices
static char sql[BUFSIZ];
//snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Function != 'None' and Type = 'Local'" );
snprintf( sql, sizeof(sql), "select distinct Device from Monitors where Type = 'Local'" );
if ( mysql_query( &dbconn, sql ) )
{
Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
MYSQL_RES *result = mysql_store_result( &dbconn );
if ( !result )
{
Error(( "Can't use query result: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
{
const char *device = dbrow[0];
fixDevice( device );
}
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
{
int device = atoi(dbrow[0]);
fixVideoDevice( device );
}
if ( mysql_errno( &dbconn ) )
{
Error(( "Can't fetch row: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
// Yadda yadda
mysql_free_result( result );
if ( mysql_errno( &dbconn ) )
if ( config.opt_x10 )
{
if ( config.x10_device )
{
Error(( "Can't fetch row: %s", mysql_error( &dbconn ) ));
exit( mysql_errno( &dbconn ) );
}
// Yadda yadda
mysql_free_result( result );
if ( config.opt_x10 )
{
if ( config.x10_device )
{
fixDevice( config.x10_device );
}
fixDevice( config.x10_device );
}
}
return( 0 );

View File

@ -27,13 +27,13 @@
void Usage( int status=-1 )
{
fprintf( stderr, "zmu <-d device_no> [-v] [function] [-U<username> -P<password>]\n" );
fprintf( stderr, "zmu <-d device_path> [-v] [function] [-U<username> -P<password>]\n" );
fprintf( stderr, "zmu <-m monitor_id> [-v] [function] [-U<username> -P<password>]\n" );
fprintf( stderr, "General options:\n" );
fprintf( stderr, " -h, --help : This screen\n" );
fprintf( stderr, " -v, --verbose : Produce more verbose output\n" );
fprintf( stderr, "Options for use with devices:\n" );
fprintf( stderr, " -d, --device <device_no> : Get the current video device settings for /dev/video<device_no>\n" );
fprintf( stderr, " -d, --device <device_path> : Get the current video device settings for <device_path>\n" );
fprintf( stderr, " -q, --query : Query the current settings for the device\n" );
fprintf( stderr, "Options for use with monitors:\n" );
fprintf( stderr, " -m, --monitor <monitor_id> : Specify which monitor to address, default 1 if absent\n" );
@ -157,7 +157,7 @@ int main( int argc, char *argv[] )
{0, 0, 0, 0}
};
int dev_id = -1;
const char *device = "";
int mon_id = 0;
bool verbose = false;
Function function = BOGUS;
@ -184,7 +184,7 @@ int main( int argc, char *argv[] )
switch (c)
{
case 'd':
dev_id = atoi(optarg);
device = optarg;
break;
case 'm':
mon_id = atoi(optarg);
@ -303,7 +303,7 @@ int main( int argc, char *argv[] )
Usage();
}
if ( dev_id >= 0 && !(function&QUERY) )
if ( device[0] && !(function&QUERY) )
{
fprintf( stderr, "Error, -d option cannot be used with this option\n" );
Usage();
@ -344,12 +344,12 @@ int main( int argc, char *argv[] )
ValidateAccess( user, mon_id, function );
}
if ( dev_id >= 0 )
if ( device[0] )
{
if ( function & QUERY )
{
char vid_string[BUFSIZ] = "";
bool ok = LocalCamera::GetCurrentSettings( dev_id, vid_string, verbose );
bool ok = LocalCamera::GetCurrentSettings( device, vid_string, verbose );
printf( "%s", vid_string );
exit( ok?0:-1 );
}

View File

@ -333,7 +333,7 @@ foreach( $monitors as $monitor )
<td align="left" class="text"><?= makeLink( "javascript: newWindow( '$PHP_SELF?view=watch&mid=".$monitor['Id']."', 'zmWatch".$monitor['Id']."', ".($monitor['Width']+$jws['watch']['w']).", ".($monitor['Height']+$jws['watch']['h'])." );", $monitor['Name'], ($monitor['Function'] != 'None') && canView( 'Stream' ) ) ?></td>
<td align="left" class="text"><?= makeLink( "javascript: newWindow( '$PHP_SELF?view=function&mid=".$monitor['Id']."', 'zmFunction', ".$jws['function']['w'].", ".$jws['function']['h']." );", "<span class=\"$fclass\">".$monitor['Function']."</span>", canEdit( 'Monitors' ) ) ?></td>
<?php if ( $monitor['Type'] == "Local" ) { ?>
<td align="left" class="text"><?= makeLink( "javascript: newWindow( '$PHP_SELF?view=monitor&mid=".$monitor['Id']."', 'zmMonitor', ".$jws['monitor']['w'].", ".$jws['monitor']['h']." );", "<span class=\"$dclass\">/dev/video".$monitor['Device']." (".$monitor['Channel'].")</span>", canEdit( 'Monitors' ) ) ?></td>
<td align="left" class="text"><?= makeLink( "javascript: newWindow( '$PHP_SELF?view=monitor&mid=".$monitor['Id']."', 'zmMonitor', ".$jws['monitor']['w'].", ".$jws['monitor']['h']." );", "<span class=\"$dclass\">".$monitor['Device']." (".$monitor['Channel'].")</span>", canEdit( 'Monitors' ) ) ?></td>
<?php } else { ?>
<td align="left" class="text"><?= makeLink( "javascript: newWindow( '$PHP_SELF?view=monitor&mid=".$monitor['Id']."', 'zmMonitor', ".$jws['monitor']['w'].", ".$jws['monitor']['h']." );", "<span class=\"$dclass\">".preg_replace( '/^.*@/', '', $monitor['Host'] )."</span>", canEdit( 'Monitors' ) ) ?></td>
<?php } ?>

View File

@ -409,7 +409,7 @@ switch ( $tab )
if ( $new_monitor['Type'] == "Local" )
{
?>
<tr><td align="left" class="text"><?= $zmSlangDeviceNumber ?></td><td align="left" class="text"><input type="text" name="new_monitor[Device]" value="<?= $new_monitor['Device'] ?>" size="4" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangDevicePath ?></td><td align="left" class="text"><input type="text" name="new_monitor[Device]" value="<?= $new_monitor['Device'] ?>" size="24" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangDeviceChannel ?></td><td align="left" class="text"><input type="text" name="new_monitor[Channel]" value="<?= $new_monitor['Channel'] ?>" size="4" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangDeviceFormat ?></td><td align="left" class="text"><input type="text" name="new_monitor[Format]" value="<?= $new_monitor['Format'] ?>" size="4" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangCapturePalette ?></td><td align="left" class="text"><select name="new_monitor[Palette]" class="form"><?php foreach ( $local_palettes as $name => $value ) { ?><option value="<?= $value ?>"<?php if ( $value == $new_monitor['Palette'] ) { ?> selected<?php } ?>><?= $name ?></option><?php } ?></select></td></tr>

View File

@ -200,6 +200,7 @@ $zmSlangDeleteAndPrev = 'Delete &amp; Prev';
$zmSlangDelete = 'Delete';
$zmSlangDeleteSavedFilter = 'Delete saved filter';
$zmSlangDescription = 'Description';
$zmSlangDevicePath = 'Device Path';
$zmSlangDeviceChannel = 'Device Channel';
$zmSlangDeviceFormat = 'Device Format (0=PAL,1=NTSC etc)';
$zmSlangDeviceNumber = 'Device Number (/dev/video?)';