If no device specified, look in /dev/ for video devices and specify them to zmu. Fix use of undefined host var

pull/3468/head
Isaac Connor 2022-04-18 15:56:14 -04:00
parent 01ab1c2535
commit 53805079b6
1 changed files with 86 additions and 74 deletions

View File

@ -27,22 +27,33 @@ if (!canEdit('Monitors')) {
function probeV4L() { function probeV4L() {
$cameras = array(); $cameras = array();
$monitors = array();
foreach ( dbFetchAll("SELECT Id, Name, Device, Channel FROM Monitors WHERE Type = 'Local' ORDER BY Device, Channel" ) as $monitor )
$monitors[$monitor['Device'].':'.$monitor['Channel']] = $monitor;
$devices = array();
$devices_to_probe = array();
$preferredStandards = array('PAL', 'NTSC');
$preferredFormats = array('BGR3', 'RGB3', 'YUYV', 'UYVY', 'JPEG', 'MJPG', '422P', 'YU12', 'GREY');
if ( !empty($_REQUEST['device']) ) {
$devices_to_probe[] = $_REQUEST['device'];
} else {
$it = new FilesystemIterator('/dev/');
foreach ($it as $fileinfo) {
if (preg_match('/^video\d+$/', $fileinfo->getFilename())) {
$devices_to_probe[] = '/dev/'.$fileinfo->getFilename();
}
}
}
foreach ($devices_to_probe as $d) {
$command = getZmuCommand(' --query --device'); $command = getZmuCommand(' --query --device');
if ( !empty($_REQUEST['device']) ) $command .= '='.escapeshellarg($d);
$command .= '='.escapeshellarg($_REQUEST['device']);
$result = exec(escapeshellcmd($command), $output, $status); $result = exec(escapeshellcmd($command), $output, $status);
if ($status) { if ($status) {
ZM\Warning("Errors while probe local cameras using $command, status is '$status' " . implode("\n", $output)); ZM\Warning("Errors while probe local cameras using $command, status is '$status' " . implode("\n", $output));
} }
$monitors = array();
foreach ( dbFetchAll("SELECT Id, Name, Device, Channel FROM Monitors WHERE Type = 'Local' ORDER BY Device, Channel" ) as $monitor )
$monitors[$monitor['Device'].':'.$monitor['Channel']] = $monitor;
$devices = array();
$preferredStandards = array('PAL', 'NTSC');
$preferredFormats = array('BGR3', 'RGB3', 'YUYV', 'UYVY', 'JPEG', 'MJPG', '422P', 'YU12', 'GREY');
foreach ( $output as $line ) { foreach ( $output as $line ) {
if ( !preg_match('/^d:([^|]+).*S:([^|]*).*F:([^|]+).*I:(\d+)\|(.+)$/', $line, $deviceMatches) ) { if ( !preg_match('/^d:([^|]+).*S:([^|]*).*F:([^|]+).*I:(\d+)\|(.+)$/', $line, $deviceMatches) ) {
ZM\Error("Can't parse command output '$line'"); ZM\Error("Can't parse command output '$line'");
@ -112,6 +123,7 @@ function probeV4L() {
$device['inputs'] = $inputs; $device['inputs'] = $inputs;
$devices[] = $device; $devices[] = $device;
} # end foreach output line } # end foreach output line
} # end foreach device in /dev
return $cameras; return $cameras;
} # end function probeV4L } # end function probeV4L
@ -347,7 +359,7 @@ function probeNetwork() {
$macBase = $macBases[$macRoot]; $macBase = $macBases[$macRoot];
$camera = call_user_func($macBase['probeFunc'], $ip); $camera = call_user_func($macBase['probeFunc'], $ip);
$sourceDesc = base64_encode(json_encode($camera['monitor'])); $sourceDesc = base64_encode(json_encode($camera['monitor']));
$sourceString = $camera['model'].' @ '.$host; $sourceString = $camera['model'].' @ '.$ip;
if ( isset($monitors[$ip]) ) { if ( isset($monitors[$ip]) ) {
$monitor = $monitors[$ip]; $monitor = $monitors[$ip];
$sourceString .= ' ('.$monitor['Name'].')'; $sourceString .= ' ('.$monitor['Name'].')';
@ -370,7 +382,7 @@ function probeNetwork() {
$macBase = $macBases[$macRoot]; $macBase = $macBases[$macRoot];
$camera = call_user_func($macBase['probeFunc'], $ip); $camera = call_user_func($macBase['probeFunc'], $ip);
$sourceDesc = base64_encode(json_encode($camera['monitor'])); $sourceDesc = base64_encode(json_encode($camera['monitor']));
$sourceString = $camera['model'].' @ '.$host; $sourceString = $camera['model'].' @ '.$ip;
if (isset($monitors[$ip])) { if (isset($monitors[$ip])) {
$monitor = $monitors[$ip]; $monitor = $monitors[$ip];
$sourceString .= ' ('.$monitor['Name'].')'; $sourceString .= ' ('.$monitor['Name'].')';