Browse Source

Merge pull request #224 from KylinMountain/bugfix/initconfig

FIX utils.Conf() would not read easy-darwin.ini configuration
pull/282/head
Babosa 1 year ago committed by GitHub
parent
commit
f9545f46d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      routers/stats.go
  2. 4
      routers/sys.go
  3. 16
      rtsp/rtsp-server.go

4
routers/stats.go

@ -49,7 +49,7 @@ func (h *APIHandler) Pushers(c *gin.Context) {
} }
hostname := utils.GetRequestHostname(c.Request) hostname := utils.GetRequestHostname(c.Request)
pushers := make([]interface{}, 0) pushers := make([]interface{}, 0)
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
port := pusher.Server().TCPPort port := pusher.Server().TCPPort
rtsp := fmt.Sprintf("rtsp://%s:%d%s", hostname, port, pusher.Path()) rtsp := fmt.Sprintf("rtsp://%s:%d%s", hostname, port, pusher.Path())
if port == 554 { if port == 554 {
@ -102,7 +102,7 @@ func (h *APIHandler) Players(c *gin.Context) {
return return
} }
players := make([]*rtsp.Player, 0) players := make([]*rtsp.Player, 0)
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
for _, player := range pusher.GetPlayers() { for _, player := range pusher.GetPlayers() {
players = append(players, player) players = append(players, player)
} }

4
routers/sys.go

@ -50,9 +50,9 @@ func init() {
now := utils.DateTime(time.Now()) now := utils.DateTime(time.Now())
memData = append(memData, PercentData{Time: now, Used: mem.UsedPercent / 100}) memData = append(memData, PercentData{Time: now, Used: mem.UsedPercent / 100})
cpuData = append(cpuData, PercentData{Time: now, Used: cpu[0] / 100}) cpuData = append(cpuData, PercentData{Time: now, Used: cpu[0] / 100})
pusherData = append(pusherData, CountData{Time: now, Total: uint(rtsp.Instance.GetPusherSize())}) pusherData = append(pusherData, CountData{Time: now, Total: uint(rtsp.GetServer().GetPusherSize())})
playerCnt := 0 playerCnt := 0
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
playerCnt += len(pusher.GetPlayers()) playerCnt += len(pusher.GetPlayers())
} }
playerData = append(playerData, CountData{Time: now, Total: uint(playerCnt)}) playerData = append(playerData, CountData{Time: now, Total: uint(playerCnt)})

16
rtsp/rtsp-server.go

@ -27,17 +27,23 @@ type Server struct {
removePusherCh chan *Pusher removePusherCh chan *Pusher
} }
var Instance *Server = &Server{ var (
instance *Server
once sync.Once
)
func GetServer() *Server {
once.Do(func() {
instance = &Server{
SessionLogger: SessionLogger{log.New(os.Stdout, "[RTSPServer]", log.LstdFlags|log.Lshortfile)}, SessionLogger: SessionLogger{log.New(os.Stdout, "[RTSPServer]", log.LstdFlags|log.Lshortfile)},
Stoped: true, Stoped: true,
TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554), TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554),
pushers: make(map[string]*Pusher), pushers: make(map[string]*Pusher),
addPusherCh: make(chan *Pusher), addPusherCh: make(chan *Pusher),
removePusherCh: make(chan *Pusher), removePusherCh: make(chan *Pusher),
} }
})
func GetServer() *Server { return instance
return Instance
} }
func (server *Server) Start() (err error) { func (server *Server) Start() (err error) {

Loading…
Cancel
Save