Adds janus_enable_audio, a switch to try to enable audio in live stream viewing.

This commit is contained in:
Jonathan Bennett 2022-01-19 00:14:52 -06:00
parent d00aaa11e9
commit fb832e7d1b
10 changed files with 80 additions and 3 deletions

View File

@ -456,6 +456,7 @@ CREATE TABLE `Monitors` (
`Enabled` tinyint(3) unsigned NOT NULL default '1',
`DecodingEnabled` tinyint(3) unsigned NOT NULL default '1',
`JanusEnabled` BOOLEAN NOT NULL default false,
`JanusAudioEnabled` BOOLEAN NOT NULL default false,
`LinkedMonitors` varchar(255),
`Triggers` set('X10') NOT NULL default '',
`EventStartCommand` VARCHAR(255) NOT NULL DEFAULT '',

18
db/zm_update-1.37.9.sql Normal file
View File

@ -0,0 +1,18 @@
--
-- Update Monitors table to have JanusEnabled
--
SELECT 'Checking for JanusAudioEnabled in Monitors';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Monitors'
AND table_schema = DATABASE()
AND column_name = 'JanusAudioEnabled'
) > 0,
"SELECT 'Column JanusAudioEnabled already exists in Monitors'",
"ALTER TABLE `Monitors` ADD COLUMN `JanusAudioEnabled` BOOLEAN NOT NULL default false AFTER `JanusEnabled`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

View File

@ -77,7 +77,7 @@ struct Namespace namespaces[] =
// This is the official SQL (and ordering of the fields) to load a Monitor.
// It will be used whereever a Monitor dbrow is needed. WHERE conditions can be appended
std::string load_monitor_sql =
"SELECT `Id`, `Name`, `ServerId`, `StorageId`, `Type`, `Function`+0, `Enabled`, `DecodingEnabled`, `JanusEnabled`,"
"SELECT `Id`, `Name`, `ServerId`, `StorageId`, `Type`, `Function`+0, `Enabled`, `DecodingEnabled`, `JanusEnabled`, `JanusAudioEnabled`,"
"`LinkedMonitors`, `EventStartCommand`, `EventEndCommand`, `AnalysisFPSLimit`, `AnalysisUpdateDelay`, `MaxFPS`, `AlarmMaxFPS`,"
"`Device`, `Channel`, `Format`, `V4LMultiBuffer`, `V4LCapturesPerFrame`, " // V4L Settings
"`Protocol`, `Method`, `Options`, `User`, `Pass`, `Host`, `Port`, `Path`, `SecondPath`, `Width`, `Height`, `Colours`, `Palette`, `Orientation`+0, `Deinterlacing`, "
@ -307,6 +307,7 @@ Monitor::Monitor()
enabled(false),
decoding_enabled(false),
janus_enabled(false),
janus_audio_enabled(false),
//protocol
//method
//options
@ -447,7 +448,7 @@ Monitor::Monitor()
/*
std::string load_monitor_sql =
"SELECT Id, Name, ServerId, StorageId, Type, Function+0, Enabled, DecodingEnabled, JanusEnabled, LinkedMonitors, `EventStartCommand`, `EventEndCommand`, "
"SELECT Id, Name, ServerId, StorageId, Type, Function+0, Enabled, DecodingEnabled, JanusEnabled, JanusAudioEnabled, LinkedMonitors, `EventStartCommand`, `EventEndCommand`, "
"AnalysisFPSLimit, AnalysisUpdateDelay, MaxFPS, AlarmMaxFPS,"
"Device, Channel, Format, V4LMultiBuffer, V4LCapturesPerFrame, " // V4L Settings
"Protocol, Method, Options, User, Pass, Host, Port, Path, SecondPath, Width, Height, Colours, Palette, Orientation+0, Deinterlacing, RTSPDescribe, "
@ -501,6 +502,7 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
decoding_enabled = dbrow[col] ? atoi(dbrow[col]) : false; col++;
// See below after save_jpegs for a recalculation of decoding_enabled
janus_enabled = dbrow[col] ? atoi(dbrow[col]) : false; col++;
janus_audio_enabled = dbrow[col] ? atoi(dbrow[col]) : false; col++;
ReloadLinkedMonitors(dbrow[col]); col++;
event_start_command = dbrow[col] ? dbrow[col] : ""; col++;
@ -1121,7 +1123,7 @@ bool Monitor::connect() {
#if HAVE_LIBCURL //janus setup. Depends on libcurl.
if (janus_enabled && (path.find("rtsp://") != std::string::npos)) {
if (add_to_janus() != 0) {
if (add_to_janus() != 0) {
if (add_to_janus() != 0) { //The initial attempt may fail. This is a temporary workaround.
Warning("Failed to add monitor stream to Janus!");
}
}
@ -3453,6 +3455,7 @@ int Monitor::add_to_janus() {
postData += rtsp_password;
postData += "\", \"id\" : ";
postData += std::to_string(id);
if (janus_audio_enabled) postData += ", \"audio\" : true";
postData += ", \"video\" : true}}";
curl_easy_setopt(curl, CURLOPT_URL,endpoint.c_str());

View File

@ -269,6 +269,7 @@ protected:
bool enabled; // Whether the monitor is enabled or asleep
bool decoding_enabled; // Whether the monitor will decode h264/h265 packets
bool janus_enabled; // Whether we set the h264/h265 stream up on janus
bool janus_audio_enabled; // Whether we tell Janus to try to include audio.
std::string protocol;
std::string method;
@ -511,6 +512,18 @@ public:
inline bool DecodingEnabled() const {
return decoding_enabled;
}
bool JanusEnabled() {
return janus_enabled;
}
bool JanusAudioEnabled() {
return janus_audio_enabled;
}
bool OnvifEnabled() {
return onvif_event_listener;
}
bool OnvifHealthy() {
return ONVIF_Healthy;
}
inline const char *EventPrefix() const { return event_prefix.c_str(); }
inline bool Ready() const {
if ( image_count >= ready_count ) {

View File

@ -79,6 +79,16 @@ if ( !canEdit('Monitors') ) return;
}
?>
</div>
<div class="form-group" id="FunctionJanusAudioEnabled">
<label for="newJanusAudioEnabled"><?php echo translate('Janus Audio Enabled') ?></label>
<input type="checkbox" name="newJanusAudioEnabled" id="newJanusAudioEnabled" value="1"/>
<?php
if ( isset($OLANG['FUNCTION_JANUS_AUDIO_ENABLED']) ) {
echo '<div class="form-text">'.$OLANG['FUNCTION_JANUS_AUDIO_ENABLED']['Help'].'</div>';
}
?>
</div>
</div>
<div class="modal-footer">

View File

@ -56,6 +56,7 @@ class Monitor extends ZM_Object {
'Enabled' => array('type'=>'boolean','default'=>1),
'DecodingEnabled' => array('type'=>'boolean','default'=>1),
'JanusEnabled' => array('type'=>'boolean','default'=>0),
'JanusAudioEnabled' => array('type'=>'boolean','default'=>0),
'LinkedMonitors' => array('type'=>'set', 'default'=>null),
'Triggers' => array('type'=>'set','default'=>''),
'EventStartCommand' => '',

View File

@ -90,6 +90,7 @@ if ($action == 'save') {
'Enabled' => 0,
'DecodingEnabled' => 0,
'JanusEnabled' => 0,
'JanusAudioEnabled' => 0,
'Exif' => 0,
'RTSPDescribe' => 0,
'V4LMultiBuffer' => '',

View File

@ -1179,6 +1179,11 @@ $OLANG = array(
Attempt to use Janus streaming server for h264/h265 live view. Experimental, but allows
for significantly better performance.'
),
'FUNCTION_JANUS_AUDIO_ENABLED' => array(
'Help' => '
Attempt to enable audio in the Janus stream. Has no effect for cameras without audio support,
but can prevent a stream playing if your camera sends an audio format unsupported by the browser.'
),
'ImageBufferCount' => array(
'Help' => '
Number of raw images available in /dev/shm. Currently should be set in the 3-5 range. Used for live viewing.'

View File

@ -260,6 +260,21 @@ function initPage() {
window.location.assign('?view=console');
});
//manage the Janus audio check
if (document.getElementsByName("newMonitor[JanusEnabled]")[0].checked) {
document.getElementById("FunctionJanusAudioEnabled").hidden = false;
} else {
document.getElementById("FunctionJanusAudioEnabled").hidden = true;
}
document.getElementsByName("newMonitor[JanusEnabled]")[0].addEventListener('change', function() {
if (this.checked) {
document.getElementById("FunctionJanusAudioEnabled").hidden = false;
} else {
document.getElementById("FunctionJanusAudioEnabled").hidden = true;
}
});
if ( ZM_OPT_USE_GEOLOCATION ) {
if ( window.L ) {
var form = document.getElementById('contentForm');

View File

@ -584,6 +584,16 @@ if (count($available_monitor_ids)) {
if ( isset($OLANG['FUNCTION_JANUS_ENABLED']) ) {
echo '<div class="form-text">'.$OLANG['FUNCTION_JANUS_ENABLED']['Help'].'</div>';
}
?>
</td>
</tr>
<tr id="FunctionJanusAudioEnabled">
<td class="text-right pr-3"><?php echo translate('Janus Live Stream Audio') ?></td>
<td><input type="checkbox" name="newMonitor[JanusAudioEnabled]" value="1"<?php echo $monitor->JanusAudioEnabled() ? ' checked="checked"' : '' ?>/>
<?php
if ( isset($OLANG['FUNCTION_JANUS_AUDIO_ENABLED']) ) {
echo '<div class="form-text">'.$OLANG['FUNCTION_JANUS_AUDIO_ENABLED']['Help'].'</div>';
}
?>
</td>
</tr>