Browse Source

Merge pull request #152 from EssGeeEich/master

Disable hls setting ignored, allow keyless rtmp, cleaner logs.
pull/154/head 0.0.15
Matthew 4 years ago committed by GitHub
parent
commit
12948dfb67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      configure/liveconfig.go
  2. 4
      livego.yaml
  3. 21
      main.go
  4. 2
      protocol/hls/source.go
  5. 2
      protocol/httpflv/writer.go
  6. 17
      protocol/rtmp/rtmp.go

8
configure/liveconfig.go

@ -28,6 +28,8 @@ type Application struct { @@ -28,6 +28,8 @@ type Application struct {
Appname string `mapstructure:"appname"`
Live bool `mapstructure:"live"`
Hls bool `mapstructure:"hls"`
Flv bool `mapstructure:"flv"`
Api bool `mapstructure:"api"`
StaticPush []string `mapstructure:"static_push"`
}
@ -40,7 +42,9 @@ type JWT struct { @@ -40,7 +42,9 @@ type JWT struct {
type ServerCfg struct {
Level string `mapstructure:"level"`
ConfigFile string `mapstructure:"config_file"`
FLVArchive bool `mapstructure:"flv_archive"`
FLVDir string `mapstructure:"flv_dir"`
RTMPNoAuth bool `mapstructure:"rtmp_noauth"`
RTMPAddr string `mapstructure:"rtmp_addr"`
HTTPFLVAddr string `mapstructure:"httpflv_addr"`
HLSAddr string `mapstructure:"hls_addr"`
@ -58,6 +62,8 @@ type ServerCfg struct { @@ -58,6 +62,8 @@ type ServerCfg struct {
// default config
var defaultConf = ServerCfg{
ConfigFile: "livego.yaml",
FLVArchive: false,
RTMPNoAuth: false,
RTMPAddr: ":1935",
HTTPFLVAddr: ":7001",
HLSAddr: ":7002",
@ -70,6 +76,8 @@ var defaultConf = ServerCfg{ @@ -70,6 +76,8 @@ var defaultConf = ServerCfg{
Appname: "live",
Live: true,
Hls: true,
Flv: true,
Api: true,
StaticPush: nil,
}},
}

4
livego.yaml

@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
# level: info
# # FLV Options
# flv_archive: false
# flv_dir: "./tmp"
# httpflv_addr: ":7001"
# # RTMP Options
# rtmp_noauth: false
# rtmp_addr: ":1935"
# read_timeout: 10
# write_timeout: 10
@ -19,3 +21,5 @@ server: @@ -19,3 +21,5 @@ server:
- appname: live
live: true
hls: true
api: true
flv: true

21
main.go

@ -134,10 +134,21 @@ func main() { @@ -134,10 +134,21 @@ func main() {
version: %s
`, VERSION)
stream := rtmp.NewRtmpStream()
hlsServer := startHls()
startHTTPFlv(stream)
startAPI(stream)
apps := configure.Applications{}
configure.Config.UnmarshalKey("server", &apps)
for _, app := range apps {
stream := rtmp.NewRtmpStream()
var hlsServer *hls.Server
if app.Hls {
hlsServer = startHls()
}
if app.Flv {
startHTTPFlv(stream)
}
if app.Api {
startAPI(stream)
}
startRtmp(stream, hlsServer)
startRtmp(stream, hlsServer)
}
}

2
protocol/hls/source.go

@ -58,7 +58,7 @@ func NewSource(info av.Info) *Source { @@ -58,7 +58,7 @@ func NewSource(info av.Info) *Source {
go func() {
err := s.SendPacket()
if err != nil {
log.Warning("send packet error: ", err)
log.Debug("send packet error: ", err)
s.closed = true
}
}()

2
protocol/httpflv/writer.go

@ -54,7 +54,7 @@ func NewFLVWriter(app, title, url string, ctx http.ResponseWriter) *FLVWriter { @@ -54,7 +54,7 @@ func NewFLVWriter(app, title, url string, ctx http.ResponseWriter) *FLVWriter {
go func() {
err := ret.SendPacket()
if err != nil {
log.Error("SendPacket error: ", err)
log.Debug("SendPacket error: ", err)
ret.closed = true
}

17
protocol/rtmp/rtmp.go

@ -122,6 +122,16 @@ func (s *Server) handleConn(conn *core.Conn) error { @@ -122,6 +122,16 @@ func (s *Server) handleConn(conn *core.Conn) error {
log.Debugf("handleConn: IsPublisher=%v", connServer.IsPublisher())
if connServer.IsPublisher() {
if configure.Config.GetBool("rtmp_noauth") {
key, err := configure.RoomKeys.GetKey(name)
if err != nil {
err := fmt.Errorf("Cannot create key err=%s", err.Error())
conn.Close()
log.Error("GetKey err: ", err)
return err
}
name = key
}
channel, err := configure.RoomKeys.GetChannel(name)
if err != nil {
err := fmt.Errorf("invalid key err=%s", err.Error())
@ -143,9 +153,10 @@ func (s *Server) handleConn(conn *core.Conn) error { @@ -143,9 +153,10 @@ func (s *Server) handleConn(conn *core.Conn) error {
writer := s.getter.GetWriter(reader.Info())
s.handler.HandleWriter(writer)
}
//FIXME: should flv should be configurable, not always on -gs
flvWriter := new(flv.FlvDvr)
s.handler.HandleWriter(flvWriter.GetWriter(reader.Info()))
if configure.Config.GetBool("flv_archive") {
flvWriter := new(flv.FlvDvr)
s.handler.HandleWriter(flvWriter.GetWriter(reader.Info()))
}
} else {
writer := NewVirWriter(connServer)
log.Debugf("new player: %+v", writer.Info())

Loading…
Cancel
Save