Skip to content

Commit

Permalink
Opt: init hls
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Nov 3, 2023
1 parent 5b7c93d commit 58de2ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func Server(cmd *cobra.Command, args []string) {
channels := rwmap.RWMap[string, *server.Channel]{}
s := server.NewRtmpServer(func(ReqAppName, ReqChannelName string, IsPublisher bool) (*server.Channel, error) {
c, _ := channels.LoadOrStore(ReqAppName, server.NewChannel())
c.InitHlsPlayer()
return c, nil
return c, c.InitHlsPlayer()
})
go s.Serve(tcp)
if flags.Dev {
Expand Down
5 changes: 2 additions & 3 deletions server/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,21 @@ func (c *Channel) GetPlayers() ([]av.WriteCloser, error) {
return players, nil
}

func (c *Channel) InitHlsPlayer() error {
func (c *Channel) InitHlsPlayer(conf ...hls.SourceConf) error {
c.wg.Add(1)
defer c.wg.Done()
if c.Closed() {
return ErrClosed
}
c.hlsOnce.Do(func() {
p := hls.NewSource()
p := hls.NewSource(conf...)
c.hlsWriter.Store(p)
go func() {
for {
if c.Closed() {
return
}
if err := c.AddPlayer(p); err != nil {
p.Close()
continue
}
p.SendPacket()
Expand Down

0 comments on commit 58de2ae

Please sign in to comment.