From 74e4bd5737e2e9c3210d78388bbf457aec9719a5 Mon Sep 17 00:00:00 2001 From: stan Date: Mon, 17 Oct 2005 10:58:25 +0000 Subject: [PATCH] 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 --- db/zmalter-1.21.3.sql | 3 ++ src/zm_local_camera.cpp | 24 ++++------- src/zm_local_camera.h | 10 ++--- src/zm_monitor.cpp | 14 +++---- src/zm_monitor.h | 4 +- src/zmc.cpp | 23 ++++++----- src/zmfix.cpp | 80 +++++++++++++----------------------- src/zmu.cpp | 14 +++---- web/zm_html_view_console.php | 2 +- web/zm_html_view_monitor.php | 2 +- web/zm_lang_en_gb.php | 1 + 11 files changed, 76 insertions(+), 101 deletions(-) diff --git a/db/zmalter-1.21.3.sql b/db/zmalter-1.21.3.sql index 0963a2d8b..f5b69bfa9 100644 --- a/db/zmalter-1.21.3.sql +++ b/db/zmalter-1.21.3.sql @@ -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; -- diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 9bc551077..4dedecd83 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -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 ); diff --git a/src/zm_local_camera.h b/src/zm_local_camera.h index 6faf70deb..6a5ae9891 100644 --- a/src/zm_local_camera.h +++ b/src/zm_local_camera.h @@ -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 diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 398a4b6bd..79d2d18bf 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -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() ); } diff --git a/src/zm_monitor.h b/src/zm_monitor.h index e8535317b..d3516bc0d 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -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 ); diff --git a/src/zmc.cpp b/src/zmc.cpp index 8a3269d2a..bbb2fee09 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -35,10 +35,10 @@ void zmc_term_handler( int /* signal */ ) void Usage() { - fprintf( stderr, "zmc -d or -m \n" ); + fprintf( stderr, "zmc -d or -H -P -p or -m \n" ); fprintf( stderr, "Options:\n" ); - fprintf( stderr, " -d, --device : For local cameras, device to access 0=>/dev/video0 etc\n" ); + fprintf( stderr, " -d, --device : For local cameras, device to access. E.g /dev/video0 etc\n" ); fprintf( stderr, " -H -P -p : For remote cameras\n" ); fprintf( stderr, " -m, --monitor : 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(); } diff --git a/src/zmfix.cpp b/src/zmfix.cpp index ed5704fd2..ff34ec721 100644 --- a/src/zmfix.cpp +++ b/src/zmfix.cpp @@ -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 ); diff --git a/src/zmu.cpp b/src/zmu.cpp index 9d5421e46..fe5028753 100644 --- a/src/zmu.cpp +++ b/src/zmu.cpp @@ -27,13 +27,13 @@ void Usage( int status=-1 ) { - fprintf( stderr, "zmu <-d device_no> [-v] [function] [-U -P]\n" ); + fprintf( stderr, "zmu <-d device_path> [-v] [function] [-U -P]\n" ); fprintf( stderr, "zmu <-m monitor_id> [-v] [function] [-U -P]\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 : Get the current video device settings for /dev/video\n" ); + fprintf( stderr, " -d, --device : Get the current video device settings for \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 : 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 ); } diff --git a/web/zm_html_view_console.php b/web/zm_html_view_console.php index aac412b22..1a0a1d1dc 100644 --- a/web/zm_html_view_console.php +++ b/web/zm_html_view_console.php @@ -333,7 +333,7 @@ foreach( $monitors as $monitor ) ".$monitor['Function']."", canEdit( 'Monitors' ) ) ?> -/dev/video".$monitor['Device']." (".$monitor['Channel'].")", canEdit( 'Monitors' ) ) ?> +".$monitor['Device']." (".$monitor['Channel'].")", canEdit( 'Monitors' ) ) ?> ".preg_replace( '/^.*@/', '', $monitor['Host'] )."", canEdit( 'Monitors' ) ) ?> diff --git a/web/zm_html_view_monitor.php b/web/zm_html_view_monitor.php index eb7c50533..ad377a158 100644 --- a/web/zm_html_view_monitor.php +++ b/web/zm_html_view_monitor.php @@ -409,7 +409,7 @@ switch ( $tab ) if ( $new_monitor['Type'] == "Local" ) { ?> - + diff --git a/web/zm_lang_en_gb.php b/web/zm_lang_en_gb.php index 6d0c86045..83cf4653b 100644 --- a/web/zm_lang_en_gb.php +++ b/web/zm_lang_en_gb.php @@ -200,6 +200,7 @@ $zmSlangDeleteAndPrev = 'Delete & 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?)';