Skip to content

Commit

Permalink
rename struct
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Nov 6, 2021
1 parent 08fa61e commit 21a149c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions internal/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ type apiRTMPServer interface {
}

type apiHLSServer interface {
onAPIHLSMuxersList(req hlsServerMuxersListReq) hlsServerMuxersListRes
onAPIHLSMuxersList(req hlsServerAPIMuxersListReq) hlsServerAPIMuxersListRes
}

type apiParent interface {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions internal/core/hls_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ type hlsMuxer struct {
requests []hlsMuxerRequest

// in
request chan hlsMuxerRequest
hlsServerMuxersList chan hlsServerMuxersListSubReq
request chan hlsMuxerRequest
hlsServerAPIMuxersList chan hlsServerAPIMuxersListSubReq
}

func newHLSMuxer(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
36 changes: 18 additions & 18 deletions internal/core/hls_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down Expand Up @@ -64,7 +64,7 @@ type hlsServer struct {
pathSourceReady chan *path
request chan hlsMuxerRequest
muxerClose chan *hlsMuxer
apiMuxersList chan hlsServerMuxersListReq
apiMuxersList chan hlsServerAPIMuxersListReq
}

func newHLSServer(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -164,7 +164,7 @@ outer:
muxers[name] = m
}

req.Res <- hlsServerMuxersListRes{
req.Res <- hlsServerAPIMuxersListRes{
Muxers: muxers,
}

Expand Down Expand Up @@ -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")}
}
}
4 changes: 2 additions & 2 deletions internal/core/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type metricsRTMPServer interface {
}

type metricsHLSServer interface {
onAPIHLSMuxersList(req hlsServerMuxersListReq) hlsServerMuxersListRes
onAPIHLSMuxersList(req hlsServerAPIMuxersListReq) hlsServerAPIMuxersListRes
}

type metricsParent interface {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 21a149c

Please sign in to comment.