hls: fix toggling hlsAlwaysRemux after server is started (#4503)
Some checks are pending
code_lint / golangci_lint (push) Waiting to run
code_lint / mod_tidy (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run

When hlsAlwaysRemux was switched from false to true, through API or hot
reloading, muxers of existing paths were not created. This fixes the
issue.
This commit is contained in:
Alessandro Ros 2025-05-09 22:50:11 +02:00 committed by GitHub
parent 84ed7a5f3b
commit defee1eed9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 380 additions and 182 deletions

View file

@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"sort"
"sync"
"time"
@ -22,6 +23,10 @@ import (
// ErrConnNotFound is returned when a connection is not found.
var ErrConnNotFound = errors.New("connection not found")
func interfaceIsEmpty(i interface{}) bool {
return reflect.ValueOf(i).Kind() != reflect.Ptr || reflect.ValueOf(i).IsNil()
}
func srtMaxPayloadSize(u int) int {
return ((u - 16) / 188) * 188 // 16 = SRT header, 188 = MPEG-TS packet
}
@ -54,6 +59,10 @@ type serverAPIConnsKickReq struct {
res chan serverAPIConnsKickRes
}
type serverMetrics interface {
SetSRTServer(defs.APISRTServer)
}
type serverPathManager interface {
AddPublisher(req defs.PathAddPublisherReq) (defs.Path, error)
AddReader(req defs.PathAddReaderReq) (defs.Path, *stream.Stream, error)
@ -74,6 +83,7 @@ type Server struct {
RunOnConnectRestart bool
RunOnDisconnect string
ExternalCmdPool *externalcmd.Pool
Metrics serverMetrics
PathManager serverPathManager
Parent serverParent
@ -126,6 +136,10 @@ func (s *Server) Initialize() error {
s.wg.Add(1)
go s.run()
if !interfaceIsEmpty(s.Metrics) {
s.Metrics.SetSRTServer(s)
}
return nil
}
@ -137,6 +151,11 @@ func (s *Server) Log(level logger.Level, format string, args ...interface{}) {
// Close closes the server.
func (s *Server) Close() {
s.Log(logger.Info, "listener is closing")
if !interfaceIsEmpty(s.Metrics) {
s.Metrics.SetSRTServer(nil)
}
s.ctxCancel()
s.wg.Wait()
}