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
浩麟 6 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 {
Algorithm string `mapstructure:"algorithm"` Algorithm string `mapstructure:"algorithm"`
} }
type ServerCfg struct { type ServerCfg struct {
Level string `mapstructure:"level"` Level string `mapstructure:"level"`
ConfigFile string `mapstructure:"config_file"` ConfigFile string `mapstructure:"config_file"`
FLVDir string `mapstructure:"flv_dir"` FLVDir string `mapstructure:"flv_dir"`
RTMPAddr string `mapstructure:"rtmp_addr"` RTMPAddr string `mapstructure:"rtmp_addr"`
HTTPFLVAddr string `mapstructure:"httpflv_addr"` HTTPFLVAddr string `mapstructure:"httpflv_addr"`
HLSAddr string `mapstructure:"hls_addr"` HLSAddr string `mapstructure:"hls_addr"`
APIAddr string `mapstructure:"api_addr"` HLSKeepAfterEnd bool `mapstructure:"hls_keep_after_end"`
RedisAddr string `mapstructure:"redis_addr"` APIAddr string `mapstructure:"api_addr"`
RedisPwd string `mapstructure:"redis_pwd"` RedisAddr string `mapstructure:"redis_addr"`
ReadTimeout int `mapstructure:"read_timeout"` RedisPwd string `mapstructure:"redis_pwd"`
WriteTimeout int `mapstructure:"write_timeout"` ReadTimeout int `mapstructure:"read_timeout"`
GopNum int `mapstructure:"gop_num"` WriteTimeout int `mapstructure:"write_timeout"`
JWT JWT `mapstructure:"jwt"` GopNum int `mapstructure:"gop_num"`
Server []Application `mapstructure:"server"` JWT JWT `mapstructure:"jwt"`
Server Applications `mapstructure:"server"`
} }
// default config // default config
var defaultConf = ServerCfg{ var defaultConf = ServerCfg{
ConfigFile: "livego.yaml", ConfigFile: "livego.yaml",
RTMPAddr: ":1935", RTMPAddr: ":1935",
HTTPFLVAddr: ":7001", HTTPFLVAddr: ":7001",
HLSAddr: ":7002", HLSAddr: ":7002",
APIAddr: ":8090", HLSKeepAfterEnd: false,
WriteTimeout: 10, APIAddr: ":8090",
ReadTimeout: 10, WriteTimeout: 10,
GopNum: 1, ReadTimeout: 10,
GopNum: 1,
Server: Applications{{ Server: Applications{{
Appname: "live", Appname: "live",
Live: true, Live: true,

1
livego.yaml

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

3
protocol/hls/hls.go

@ -2,6 +2,7 @@ package hls
import ( import (
"fmt" "fmt"
"livego/configure"
"net" "net"
"net/http" "net/http"
"path" "path"
@ -82,7 +83,7 @@ func (server *Server) checkStop() {
<-time.After(5 * time.Second) <-time.After(5 * time.Second)
for item := range server.conns.IterBuffered() { for item := range server.conns.IterBuffered() {
v := item.Val.(*Source) 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()) log.Debug("check stop and remove: ", v.Info())
server.conns.Remove(item.Key) server.conns.Remove(item.Key)
} }

3
protocol/hls/source.go

@ -3,6 +3,7 @@ package hls
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"livego/configure"
"time" "time"
"livego/av" "livego/av"
@ -180,7 +181,7 @@ func (source *Source) cleanup() {
func (source *Source) Close(err error) { func (source *Source) Close(err error) {
log.Debug("hls source closed: ", source.info) log.Debug("hls source closed: ", source.info)
if !source.closed { if !source.closed && !configure.Config.GetBool("hls_keep_after_end") {
source.cleanup() source.cleanup()
} }
source.closed = true source.closed = true

Loading…
Cancel
Save