diff --git a/internal/core/api.go b/internal/core/api.go index cf9831ca780..2345f459f5c 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -180,7 +180,7 @@ type apiRTMPServer interface { } type apiHLSServer interface { - onAPIHLSMuxersList(req hlsServerMuxersListReq) hlsServerMuxersListRes + onAPIHLSMuxersList(req hlsServerAPIMuxersListReq) hlsServerAPIMuxersListRes } type apiParent interface { @@ -530,7 +530,7 @@ func (a *api) onRTMPConnsKick(ctx *gin.Context) { } func (a *api) onHLSMuxersList(ctx *gin.Context) { - res := a.hlsServer.onAPIHLSMuxersList(hlsServerMuxersListReq{}) + res := a.hlsServer.onAPIHLSMuxersList(hlsServerAPIMuxersListReq{}) if res.Err != nil { ctx.AbortWithStatus(http.StatusInternalServerError) return diff --git a/internal/core/hls_muxer.go b/internal/core/hls_muxer.go index 84cbba3483e..5604d95e15b 100644 --- a/internal/core/hls_muxer.go +++ b/internal/core/hls_muxer.go @@ -141,8 +141,8 @@ type hlsMuxer struct { requests []hlsMuxerRequest // in - request chan hlsMuxerRequest - hlsServerMuxersList chan hlsServerMuxersListSubReq + request chan hlsMuxerRequest + hlsServerAPIMuxersList chan hlsServerAPIMuxersListSubReq } func newHLSMuxer( @@ -174,8 +174,8 @@ func newHLSMuxer( v := time.Now().Unix() return &v }(), - request: make(chan hlsMuxerRequest), - hlsServerMuxersList: make(chan hlsServerMuxersListSubReq), + request: make(chan hlsMuxerRequest), + hlsServerAPIMuxersList: make(chan hlsServerAPIMuxersListSubReq), } m.log(logger.Info, "opened") @@ -226,8 +226,8 @@ func (m *hlsMuxer) run() { m.requests = append(m.requests, req) } - case req := <-m.hlsServerMuxersList: - req.Data.Items[m.name] = hlsServerMuxersListItem{ + case req := <-m.hlsServerAPIMuxersList: + req.Data.Items[m.name] = hlsServerAPIMuxersListItem{ LastRequest: time.Unix(atomic.LoadInt64(m.lastRequestTime), 0).String(), } close(req.Res) @@ -512,10 +512,10 @@ func (m *hlsMuxer) onReaderAPIDescribe() interface{} { } // onAPIHLSMuxersList is called by api. -func (m *hlsMuxer) onAPIHLSMuxersList(req hlsServerMuxersListSubReq) { +func (m *hlsMuxer) onAPIHLSMuxersList(req hlsServerAPIMuxersListSubReq) { req.Res = make(chan struct{}) select { - case m.hlsServerMuxersList <- req: + case m.hlsServerAPIMuxersList <- req: <-req.Res case <-m.ctx.Done(): diff --git a/internal/core/hls_server.go b/internal/core/hls_server.go index 0e2fa92ae6c..8c3fa7fab1f 100644 --- a/internal/core/hls_server.go +++ b/internal/core/hls_server.go @@ -17,26 +17,26 @@ import ( "github.com/aler9/rtsp-simple-server/internal/logger" ) -type hlsServerMuxersListItem struct { +type hlsServerAPIMuxersListItem struct { LastRequest string `json:"lastRequest"` } -type hlsServerMuxersListData struct { - Items map[string]hlsServerMuxersListItem `json:"items"` +type hlsServerAPIMuxersListData struct { + Items map[string]hlsServerAPIMuxersListItem `json:"items"` } -type hlsServerMuxersListRes struct { - Data *hlsServerMuxersListData +type hlsServerAPIMuxersListRes struct { + Data *hlsServerAPIMuxersListData Muxers map[string]*hlsMuxer Err error } -type hlsServerMuxersListReq struct { - Res chan hlsServerMuxersListRes +type hlsServerAPIMuxersListReq struct { + Res chan hlsServerAPIMuxersListRes } -type hlsServerMuxersListSubReq struct { - Data *hlsServerMuxersListData +type hlsServerAPIMuxersListSubReq struct { + Data *hlsServerAPIMuxersListData Res chan struct{} } @@ -64,7 +64,7 @@ type hlsServer struct { pathSourceReady chan *path request chan hlsMuxerRequest muxerClose chan *hlsMuxer - apiMuxersList chan hlsServerMuxersListReq + apiMuxersList chan hlsServerAPIMuxersListReq } func newHLSServer( @@ -102,7 +102,7 @@ func newHLSServer( pathSourceReady: make(chan *path), request: make(chan hlsMuxerRequest), muxerClose: make(chan *hlsMuxer), - apiMuxersList: make(chan hlsServerMuxersListReq), + apiMuxersList: make(chan hlsServerAPIMuxersListReq), } s.log(logger.Info, "listener opened on "+address) @@ -164,7 +164,7 @@ outer: muxers[name] = m } - req.Res <- hlsServerMuxersListRes{ + req.Res <- hlsServerAPIMuxersListRes{ Muxers: muxers, } @@ -298,23 +298,23 @@ func (s *hlsServer) onPathSourceReady(pa *path) { } // onAPIHLSMuxersList is called by api. -func (s *hlsServer) onAPIHLSMuxersList(req hlsServerMuxersListReq) hlsServerMuxersListRes { - req.Res = make(chan hlsServerMuxersListRes) +func (s *hlsServer) onAPIHLSMuxersList(req hlsServerAPIMuxersListReq) hlsServerAPIMuxersListRes { + req.Res = make(chan hlsServerAPIMuxersListRes) select { case s.apiMuxersList <- req: res := <-req.Res - res.Data = &hlsServerMuxersListData{ - Items: make(map[string]hlsServerMuxersListItem), + res.Data = &hlsServerAPIMuxersListData{ + Items: make(map[string]hlsServerAPIMuxersListItem), } for _, pa := range res.Muxers { - pa.onAPIHLSMuxersList(hlsServerMuxersListSubReq{Data: res.Data}) + pa.onAPIHLSMuxersList(hlsServerAPIMuxersListSubReq{Data: res.Data}) } return res case <-s.ctx.Done(): - return hlsServerMuxersListRes{Err: fmt.Errorf("terminated")} + return hlsServerAPIMuxersListRes{Err: fmt.Errorf("terminated")} } } diff --git a/internal/core/metrics.go b/internal/core/metrics.go index 1b71689c650..88cf54b63b6 100644 --- a/internal/core/metrics.go +++ b/internal/core/metrics.go @@ -30,7 +30,7 @@ type metricsRTMPServer interface { } type metricsHLSServer interface { - onAPIHLSMuxersList(req hlsServerMuxersListReq) hlsServerMuxersListRes + onAPIHLSMuxersList(req hlsServerAPIMuxersListReq) hlsServerAPIMuxersListRes } type metricsParent interface { @@ -181,7 +181,7 @@ func (m *metrics) onMetrics(ctx *gin.Context) { } if !interfaceIsEmpty(m.hlsServer) { - res := m.hlsServer.onAPIHLSMuxersList(hlsServerMuxersListReq{}) + res := m.hlsServer.onAPIHLSMuxersList(hlsServerAPIMuxersListReq{}) if res.Err == nil { for name := range res.Data.Items { out += metric("hls_muxers{name=\""+name+"\"}", 1)