Browse Source

Merge pull request #97 from GNURub/keep_hls_m3u8_after_stream_finish

Keep hls after finish stream
pull/98/head 0.0.11
浩麟 5 years ago committed by GitHub
parent
commit
8c30a7a93f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      configure/liveconfig.go
  2. 1
      livego.yaml
  3. 3
      protocol/hls/hls.go
  4. 3
      protocol/hls/source.go

46
configure/liveconfig.go

@ -38,32 +38,34 @@ type JWT struct { @@ -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,

1
livego.yaml

@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
# # API Options
# api_addr: ":8090"
server:
- appname: live
live: true

3
protocol/hls/hls.go

@ -2,6 +2,7 @@ package hls @@ -2,6 +2,7 @@ package hls
import (
"fmt"
"livego/configure"
"net"
"net/http"
"path"
@ -82,7 +83,7 @@ func (server *Server) checkStop() { @@ -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)
}

3
protocol/hls/source.go

@ -3,6 +3,7 @@ package hls @@ -3,6 +3,7 @@ package hls
import (
"bytes"
"fmt"
"livego/configure"
"time"
"livego/av"
@ -180,7 +181,7 @@ func (source *Source) cleanup() { @@ -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

Loading…
Cancel
Save