mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 20:26:05 -05:00
- Add configurable Go2RTC RTSP backchannel handling on the C++ side
- Add a helper to add or update Go2RTC URL parameters without overwriting existing options or appending duplicate parameters. - Allow enabling or disabling RTSP backchannel handling for cameras, including both primary and secondary stream paths.
This commit is contained in:
1 parent
022fff8355
commit
0de8f784a8
3 files changed
+52
-1
No files matched your search
+4
-1
@@ -109,7 +109,7 @@ std::string load_monitor_sql =
|
||||
", `MQTT_Enabled`, `MQTT_Subscriptions`"
|
||||
#endif
|
||||
", `StartupDelay`"
|
||||
", `AudioDetection`, `AudioThreshold`, `AudioAlarmScore`, `DeviceClass`"
|
||||
", `AudioDetection`, `AudioThreshold`, `AudioAlarmScore`, `DeviceClass`, `Go2RTCDisableBackChannel`"
|
||||
" FROM `Monitors`";
|
||||
|
||||
// Indexed by Monitor::CameraType, which starts at 1, so entry 0 covers the
|
||||
@@ -188,6 +188,7 @@ Monitor::Monitor() :
|
||||
RTSP2Web_enabled(false),
|
||||
RTSP2Web_type(WEBRTC),
|
||||
Go2RTC_enabled(false),
|
||||
Go2RTC_disable_backchannel(true),
|
||||
janus_enabled(false),
|
||||
janus_audio_enabled(false),
|
||||
janus_profile_override(""),
|
||||
@@ -740,6 +741,8 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
|
||||
col++;
|
||||
device_class = dbrow[col] ? dbrow[col] : "Camera";
|
||||
col++;
|
||||
Go2RTC_disable_backchannel = dbrow[col] && atoi(dbrow[col]);
|
||||
col++;
|
||||
|
||||
// How many frames we need to have before we start analysing.
|
||||
// Must account for alarm_frame_count because openEvent walks back
|
||||
|
||||
@@ -580,6 +580,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
|
||||
int RTSP2Web_type; // Whether we set the h264/h265 stream up on RTSP2Web
|
||||
StreamChannelOption stream_channel; // Which stream source to use: Restream, CameraDirectPrimary, or CameraDirectSecondary
|
||||
bool Go2RTC_enabled; // Whether we set the h264/h265 stream up on Go2RTC
|
||||
bool Go2RTC_disable_backchannel;
|
||||
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 janus_profile_override; // The Profile-ID to force the stream to use.
|
||||
|
||||
@@ -105,6 +105,53 @@ Monitor::Go2RTCManager::Go2RTCManager(Monitor *parent_)
|
||||
if (!rtsp_second_path.empty() && rtsp_second_path.find('#') == std::string::npos)
|
||||
rtsp_second_path += "#backchannel=0";
|
||||
}
|
||||
|
||||
// Helper to add or update a Go2RTC URL option while preserving other options.
|
||||
// For cameras, disable RTSP backchannel by default to prevent issues with
|
||||
// Dahua cameras, such as events not being recorded and ONVIF not working
|
||||
// when viewing the camera on the Watch page using go2rtc.
|
||||
// Unlike simply appending "#backchannel=0", this helper updates an existing
|
||||
// backchannel option without adding a duplicate, and preserves other Go2RTC
|
||||
// options such as "#media=" or "#video=" in the URL.
|
||||
// The Go2RTC_disable_backchannel setting controls this behavior:
|
||||
// when enabled, set backchannel=0, adding the option if it does not exist;
|
||||
// when disabled, set an existing backchannel option to 1, but do not add
|
||||
// the option if it is absent from the RTSP path.
|
||||
auto set_rtsp_param = [](std::string& path,
|
||||
const std::string& name,
|
||||
const std::string& value) {
|
||||
const std::string param = "#" + name + "=";
|
||||
size_t pos = path.find(param);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
size_t value_start = pos + param.size();
|
||||
size_t value_end = path.find('#', value_start);
|
||||
path.replace(value_start,
|
||||
value_end == std::string::npos ? std::string::npos : value_end - value_start,
|
||||
value);
|
||||
} else {
|
||||
path += param + value;
|
||||
}
|
||||
};
|
||||
|
||||
if (parent->device_class == "Camera") {
|
||||
if (Go2RTC_disable_backchannel) {
|
||||
// Disable backchannel for both RTSP stream paths.
|
||||
set_rtsp_param(rtsp_path, "backchannel", "0");
|
||||
|
||||
if (!rtsp_second_path.empty())
|
||||
set_rtsp_param(rtsp_second_path, "backchannel", "0");
|
||||
} else {
|
||||
// Re-enable backchannel only if explicitly configured in the RTSP path.
|
||||
// Do not add the option when absent, as backchannel is enabled by default.
|
||||
if (rtsp_path.find("#backchannel=") != std::string::npos)
|
||||
set_rtsp_param(rtsp_path, "backchannel", "1");
|
||||
|
||||
if (!rtsp_second_path.empty() &&
|
||||
rtsp_second_path.find("#backchannel=") != std::string::npos)
|
||||
set_rtsp_param(rtsp_second_path, "backchannel", "1");
|
||||
}
|
||||
}
|
||||
} // end if !user.empty
|
||||
|
||||
Debug(1, "Go2RTC: Primary RTSP path: %s", rtsp_path.c_str());
|
||||
|
||||
Reference in new issue
Block a user