Merge pull request #222 from thewind296/master

[opt] 1) HTTP-API和Notify中StatGroup增加AppName字段 2) 向外暴露IAuthentication,用于定制化鉴权 3) 向外暴露ModConfigGroupCreator,支持为特定的Group独立配置
pull/228/head
yoko 3 years ago committed by GitHub
commit bf0853145d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,7 @@ type LalInfo struct {
type StatGroup struct {
StreamName string `json:"stream_name"`
AppName string `json:"app_name"`
AudioCodec string `json:"audio_codec"`
VideoCodec string `json:"video_codec"`
VideoWidth int `json:"video_width"`

@ -0,0 +1,11 @@
package logic
import (
"github.com/q191201771/lal/pkg/base"
)
type IAuthentication interface {
OnPubStart(info base.PubStartInfo) error
OnSubStart(info base.SubStartInfo) error
OnHls(streamName, urlParam string) error
}

@ -136,6 +136,7 @@ func NewGroup(appName string, streamName string, config *Config, observer IGroup
observer: observer,
stat: base.StatGroup{
StreamName: streamName,
AppName: appName,
},
exitChan: make(chan struct{}, 1),
rtmpSubSessionSet: make(map[*rtmp.ServerSession]struct{}),

@ -14,6 +14,8 @@ type IGroupCreator interface {
CreateGroup(appName, streamName string) *Group
}
type ModConfigGroupCreator func(appName, streamName string, baseConfig *Config)
// IGroupManager
//
// 封装管理Group的容器

@ -93,6 +93,16 @@ type Option struct {
// 注意如果业务方实现了自己的事件监听则lal server内部不再走http notify的逻辑也即二选一
//
NotifyHandler INotifyHandler
// ModConfigGroupCreator
// This func help us modify the group configuration base on appName or streamName
// so that group can have it own configuration (configuration can be in other source like db)
// It will help us reduce resource usage if we just want some specific group record flv or hls...
ModConfigGroupCreator ModConfigGroupCreator
// Authentication
// This interface make authenticate customizable so that we can implement any authenticate strategy like jwt...
Authentication IAuthentication
}
var defaultOption = Option{

@ -54,7 +54,6 @@ type ServerManager struct {
mutex sync.Mutex
groupManager IGroupManager
simpleAuthCtx *SimpleAuthCtx
}
func NewServerManager(modOption ...ModOption) *ServerManager {
@ -136,7 +135,9 @@ Doc: %s
sm.pprofServer = &http.Server{Addr: sm.config.PprofConfig.Addr, Handler: nil}
}
sm.simpleAuthCtx = NewSimpleAuthCtx(sm.config.SimpleAuthConfig)
if sm.option.Authentication == nil {
sm.option.Authentication = NewSimpleAuthCtx(sm.config.SimpleAuthConfig)
}
return sm
}
@ -375,7 +376,7 @@ func (sm *ServerManager) OnNewRtmpPubSession(session *rtmp.ServerSession) error
info := base.Session2PubStartInfo(session)
// 先做simple auth鉴权
if err := sm.simpleAuthCtx.OnPubStart(info); err != nil {
if err := sm.option.Authentication.OnPubStart(info); err != nil {
return err
}
@ -414,7 +415,7 @@ func (sm *ServerManager) OnNewRtmpSubSession(session *rtmp.ServerSession) error
info := base.Session2SubStartInfo(session)
if err := sm.simpleAuthCtx.OnSubStart(info); err != nil {
if err := sm.option.Authentication.OnSubStart(info); err != nil {
return err
}
@ -453,7 +454,7 @@ func (sm *ServerManager) OnNewHttpflvSubSession(session *httpflv.SubSession) err
info := base.Session2SubStartInfo(session)
if err := sm.simpleAuthCtx.OnSubStart(info); err != nil {
if err := sm.option.Authentication.OnSubStart(info); err != nil {
return err
}
@ -490,7 +491,7 @@ func (sm *ServerManager) OnNewHttptsSubSession(session *httpts.SubSession) error
info := base.Session2SubStartInfo(session)
if err := sm.simpleAuthCtx.OnSubStart(info); err != nil {
if err := sm.option.Authentication.OnSubStart(info); err != nil {
return err
}
@ -538,7 +539,7 @@ func (sm *ServerManager) OnNewRtspPubSession(session *rtsp.PubSession) error {
info := base.Session2PubStartInfo(session)
if err := sm.simpleAuthCtx.OnPubStart(info); err != nil {
if err := sm.option.Authentication.OnPubStart(info); err != nil {
return err
}
@ -576,7 +577,7 @@ func (sm *ServerManager) OnNewRtspSubSessionDescribe(session *rtsp.SubSession) (
info := base.Session2SubStartInfo(session)
if err := sm.simpleAuthCtx.OnSubStart(info); err != nil {
if err := sm.option.Authentication.OnSubStart(info); err != nil {
return false, nil
}
@ -621,7 +622,15 @@ func (sm *ServerManager) OnDelRtspSubSession(session *rtsp.SubSession) {
// ----- implement IGroupCreator interface -----------------------------------------------------------------------------
func (sm *ServerManager) CreateGroup(appName string, streamName string) *Group {
return NewGroup(appName, streamName, sm.config, sm)
var config *Config
if sm.option.ModConfigGroupCreator != nil {
cloneConfig := *sm.config
sm.option.ModConfigGroupCreator(appName, streamName, &cloneConfig)
config = &cloneConfig
} else {
config = sm.config
}
return NewGroup(appName, streamName, config, sm)
}
// ----- implement IGroupObserver interface -----------------------------------------------------------------------------
@ -703,7 +712,7 @@ func (sm *ServerManager) serveHls(writer http.ResponseWriter, req *http.Request)
if urlCtx.GetFileType() == "m3u8" {
// TODO(chef): [refactor] 需要整理,这里使用 hls.PathStrategy 不太好 202207
streamName := hls.PathStrategy.GetRequestInfo(urlCtx, sm.config.HlsConfig.OutPath).StreamName
if err = sm.simpleAuthCtx.OnHls(streamName, urlCtx.RawQuery); err != nil {
if err = sm.option.Authentication.OnHls(streamName, urlCtx.RawQuery); err != nil {
Log.Errorf("simple auth failed. err=%+v", err)
return
}

Loading…
Cancel
Save