Skip to content

Commit

Permalink
Merge pull request #97 from GNURub/keep_hls_m3u8_after_stream_finish
Browse files Browse the repository at this point in the history
Keep hls after finish stream
  • Loading branch information
gwuhaolin authored Apr 28, 2020
2 parents dbf26a7 + 40052bb commit 8c30a7a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
46 changes: 24 additions & 22 deletions configure/liveconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,34 @@ type JWT struct {
Algorithm string `mapstructure:"algorithm"`
}
type ServerCfg struct {
Level string `mapstructure:"level"`
ConfigFile string `mapstructure:"config_file"`
FLVDir string `mapstructure:"flv_dir"`
RTMPAddr string `mapstructure:"rtmp_addr"`
HTTPFLVAddr string `mapstructure:"httpflv_addr"`
HLSAddr string `mapstructure:"hls_addr"`
APIAddr string `mapstructure:"api_addr"`
RedisAddr string `mapstructure:"redis_addr"`
RedisPwd string `mapstructure:"redis_pwd"`
ReadTimeout int `mapstructure:"read_timeout"`
WriteTimeout int `mapstructure:"write_timeout"`
GopNum int `mapstructure:"gop_num"`
JWT JWT `mapstructure:"jwt"`
Server []Application `mapstructure:"server"`
Level string `mapstructure:"level"`
ConfigFile string `mapstructure:"config_file"`
FLVDir string `mapstructure:"flv_dir"`
RTMPAddr string `mapstructure:"rtmp_addr"`
HTTPFLVAddr string `mapstructure:"httpflv_addr"`
HLSAddr string `mapstructure:"hls_addr"`
HLSKeepAfterEnd bool `mapstructure:"hls_keep_after_end"`
APIAddr string `mapstructure:"api_addr"`
RedisAddr string `mapstructure:"redis_addr"`
RedisPwd string `mapstructure:"redis_pwd"`
ReadTimeout int `mapstructure:"read_timeout"`
WriteTimeout int `mapstructure:"write_timeout"`
GopNum int `mapstructure:"gop_num"`
JWT JWT `mapstructure:"jwt"`
Server Applications `mapstructure:"server"`
}

// default config
var defaultConf = ServerCfg{
ConfigFile: "livego.yaml",
RTMPAddr: ":1935",
HTTPFLVAddr: ":7001",
HLSAddr: ":7002",
APIAddr: ":8090",
WriteTimeout: 10,
ReadTimeout: 10,
GopNum: 1,
ConfigFile: "livego.yaml",
RTMPAddr: ":1935",
HTTPFLVAddr: ":7001",
HLSAddr: ":7002",
HLSKeepAfterEnd: false,
APIAddr: ":8090",
WriteTimeout: 10,
ReadTimeout: 10,
GopNum: 1,
Server: Applications{{
Appname: "live",
Live: true,
Expand Down
1 change: 0 additions & 1 deletion livego.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# # API Options
# api_addr: ":8090"

server:
- appname: live
live: true
Expand Down
3 changes: 2 additions & 1 deletion protocol/hls/hls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hls

import (
"fmt"
"livego/configure"
"net"
"net/http"
"path"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (server *Server) checkStop() {
<-time.After(5 * time.Second)
for item := range server.conns.IterBuffered() {
v := item.Val.(*Source)
if !v.Alive() {
if !v.Alive() && !configure.Config.GetBool("hls_keep_after_end") {
log.Debug("check stop and remove: ", v.Info())
server.conns.Remove(item.Key)
}
Expand Down
3 changes: 2 additions & 1 deletion protocol/hls/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hls
import (
"bytes"
"fmt"
"livego/configure"
"time"

"livego/av"
Expand Down Expand Up @@ -180,7 +181,7 @@ func (source *Source) cleanup() {

func (source *Source) Close(err error) {
log.Debug("hls source closed: ", source.info)
if !source.closed {
if !source.closed && !configure.Config.GetBool("hls_keep_after_end") {
source.cleanup()
}
source.closed = true
Expand Down

0 comments on commit 8c30a7a

Please sign in to comment.