From 9b84daad22f7dbc0fcc986c1f80164a2edfaa4b2 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 17 Jul 2023 00:33:47 +0200 Subject: [PATCH] temp --- go.mod | 2 ++ go.sum | 4 +++ internal/core/core.go | 1 - internal/core/srt_server.go | 49 +++++++++++++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 459f08c95a56..ef22210abf4d 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/bluenviron/gohlslib v0.2.7 github.com/bluenviron/gortsplib/v3 v3.8.1 github.com/bluenviron/mediacommon v0.5.1 + github.com/datarhei/gosrt v0.5.2 github.com/fsnotify/fsnotify v1.6.0 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 @@ -33,6 +34,7 @@ require ( require ( github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 // indirect github.com/asticode/go-astikit v0.30.0 // indirect + github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 8cc729d038f2..1d984327ca0f 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= github.com/asticode/go-astits v1.11.0 h1:GTHUXht0ZXAJXsVbsLIcyfHr1Bchi4QQwMARw2ZWAng= github.com/asticode/go-astits v1.11.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI= +github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c h1:8XZeJrs4+ZYhJeJ2aZxADI2tGADS15AzIF8MQ8XAhT4= +github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c/go.mod h1:x1vxHcL/9AVzuk5HOloOEPrtJY0MaalYr78afXZ+pWI= github.com/bluenviron/gohlslib v0.2.7 h1:wV4ky3PbozwWORWd9pURktMnPIT7j/mBK3ivVljgVkk= github.com/bluenviron/gohlslib v0.2.7/go.mod h1:x5XU60uvx91bQkRI8lrKNEltUtudR0WzaONBOhH+nzQ= github.com/bluenviron/gortsplib/v3 v3.8.1 h1:E+B8UWFJpqRWbaVnhQwQiAjEOeJjnueFhZQxSxY9Gps= @@ -25,6 +27,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j github.com/cloudfoundry/bytefmt v0.0.0-20211005130812-5bb3c17173e5 h1:xB7KkA98BcUdzVcwyZxb5R0FGIHxNPHgZOzkjPEY5gM= github.com/cloudfoundry/bytefmt v0.0.0-20211005130812-5bb3c17173e5/go.mod h1:v4VVB6oBMz/c9fRY6vZrwr5xKRWOH5NPDjQZlPk0Gbs= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/datarhei/gosrt v0.5.2 h1:eagqZwEIiGPNJW0rLep3gwceObyaZ17+iKRc+l4VEpc= +github.com/datarhei/gosrt v0.5.2/go.mod h1:0308GQhAu5hxe2KYdbss901aKceSSKXnwCr8Vs++eiw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/core/core.go b/internal/core/core.go index eee98b104241..7d005f8f5929 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -619,7 +619,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closeHLSManager || closeWebRTCManager - if newConf == nil && p.confWatcher != nil { p.confWatcher.Close() p.confWatcher = nil diff --git a/internal/core/srt_server.go b/internal/core/srt_server.go index 586853d1e520..18131236124f 100644 --- a/internal/core/srt_server.go +++ b/internal/core/srt_server.go @@ -1,10 +1,55 @@ package core +import ( + "context" + "sync" + + "github.com/datarhei/gosrt" +) + type srtServer struct { + ctx context.Context + ctxCancel func() + wg sync.WaitGroup + ln srt.Listener } -func newSRTServer() (*srtServer, error) { - s := &srtServer{} +func newSRTServer( + address string, +) (*srtServer, error) { + ln, err := srt.Listen("srt", address, srt.Config{ + }) + if err != nil { + return nil, err + } + + s := &srtServer{ + ln: ln, + } + + s.wg.Add(1) + go s.run() return s, nil } + +func (s *srtServer) close() { + s.ctxCancel() + s.wg.Wait() +} + +func (s *srtServer) run() { + defer s.wg.Done() + +outer: + for { + select { + case <-s.ctx.Done(): + break outer + } + } + + s.ctxCancel() + + s.ln.Close() +}