Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable hls setting ignored, allow keyless rtmp, cleaner logs. #152

Merged
merged 12 commits into from
Jan 19, 2021
8 changes: 8 additions & 0 deletions configure/liveconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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"`
Expand All @@ -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",
Expand All @@ -70,6 +76,8 @@ var defaultConf = ServerCfg{
Appname: "live",
Live: true,
Hls: true,
Flv: true,
Api: true,
StaticPush: nil,
}},
}
Expand Down
4 changes: 4 additions & 0 deletions livego.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,3 +21,5 @@ server:
- appname: live
live: true
hls: true
api: true
flv: true
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion protocol/hls/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}()
Expand Down
2 changes: 1 addition & 1 deletion protocol/httpflv/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 14 additions & 3 deletions protocol/rtmp/rtmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down