Skip to content

Commit

Permalink
Merge pull request #445 from tphakala/fix-no-rtsp-panic
Browse files Browse the repository at this point in the history
refactor: Improve RTSP stream configuration and settings handling
  • Loading branch information
tphakala authored Feb 10, 2025
2 parents e111f20 + 0228b1f commit 8c02e82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 19 additions & 2 deletions internal/httpcontroller/handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (h *Handlers) SaveSettings(c echo.Context) error {
h.controlChan <- "rebuild_range_filter"
}

// Check if RTSP settings have changed
if rtspSettingsChanged(&oldSettings, settings) {
// Check if RTSP settings were included in the form and have changed
if hasRTSPSettings(formParams) && rtspSettingsChanged(&oldSettings, settings) {
h.SSE.SendNotification(Notification{
Message: "Reconfiguring RTSP sources...",
Type: "info",
Expand Down Expand Up @@ -650,3 +650,20 @@ func rtspSettingsChanged(oldSettings, currentSettings *conf.Settings) bool {

return false
}

// hasRTSPSettings checks if any RTSP-related settings were included in the form data
func hasRTSPSettings(formParams map[string][]string) bool {
rtspPrefixes := []string{
"realtime.rtsp.urls",
"realtime.rtsp.transport",
}

for key := range formParams {
for _, prefix := range rtspPrefixes {
if strings.HasPrefix(strings.ToLower(key), prefix) {
return true
}
}
}
return false
}
15 changes: 9 additions & 6 deletions internal/myaudio/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ func SetAudioDevice(deviceName string) (string, error) {

// ReconfigureRTSPStreams handles dynamic reconfiguration of RTSP streams
func ReconfigureRTSPStreams(settings *conf.Settings, wg *sync.WaitGroup, quitChan, restartChan chan struct{}, audioLevelChan chan AudioLevelData) {
// If there are no RTSP URLs configured and FFmpeg monitor is running, stop it
if len(settings.Realtime.RTSP.URLs) == 0 {
if ffmpegMonitor != nil {
ffmpegMonitor.Stop()
ffmpegMonitor = nil
}
return
}

// Initialize FFmpeg monitor if not already running
if ffmpegMonitor == nil {
ffmpegMonitor = NewFFmpegMonitor()
Expand Down Expand Up @@ -249,12 +258,6 @@ func ReconfigureRTSPStreams(settings *conf.Settings, wg *sync.WaitGroup, quitCha
activeStreams.Store(url, true)
go CaptureAudioRTSP(url, settings.Realtime.RTSP.Transport, wg, quitChan, restartChan, audioLevelChan)
}

// If no more RTSP streams are configured, stop the FFmpeg monitor
if len(settings.Realtime.RTSP.URLs) == 0 && ffmpegMonitor != nil {
ffmpegMonitor.Stop()
ffmpegMonitor = nil
}
}

func CaptureAudio(settings *conf.Settings, wg *sync.WaitGroup, quitChan, restartChan chan struct{}, audioLevelChan chan AudioLevelData) {
Expand Down

0 comments on commit 8c02e82

Please sign in to comment.