logic

package
v0.19.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ConfVersion = "v0.1.2"

Variables

View Source
var ErrLogic = errors.New("lal.logic: fxxk")

Functions

func Dispose

func Dispose()

func Entry

func Entry(confFile string)

func RunServer

func RunServer(c *Config)

Types

type Config

type Config struct {
	ConfVersion     string          `json:"conf_version"`
	RTMPConfig      RTMPConfig      `json:"rtmp"`
	HTTPFLVConfig   HTTPFLVConfig   `json:"httpflv"`
	HLSConfig       HLSConfig       `json:"hls"`
	HTTPTSConfig    HTTPTSConfig    `json:"httpts"`
	RTSPConfig      RTSPConfig      `json:"rtsp"`
	RecordConfig    RecordConfig    `json:"record"`
	RelayPushConfig RelayPushConfig `json:"relay_push"`
	RelayPullConfig RelayPullConfig `json:"relay_pull"`

	HTTPAPIConfig    HTTPAPIConfig    `json:"http_api"`
	ServerID         string           `json:"server_id"`
	HTTPNotifyConfig HTTPNotifyConfig `json:"http_notify"`
	PProfConfig      PProfConfig      `json:"pprof"`
	LogConfig        nazalog.Option   `json:"log"`
}

func LoadConfAndInitLog added in v0.19.12

func LoadConfAndInitLog(confFile string) *Config

type GOP

type GOP struct {
	// contains filtered or unexported fields
}

func (*GOP) Clear

func (g *GOP) Clear()

func (*GOP) Feed

func (g *GOP) Feed(msg base.RTMPMsg, b []byte)

type GOPCache

type GOPCache struct {
	Metadata       []byte
	VideoSeqHeader []byte
	AACSeqHeader   []byte
	// contains filtered or unexported fields
}

func NewGOPCache

func NewGOPCache(t string, uniqueKey string, gopNum int) *GOPCache

func (*GOPCache) Clear

func (gc *GOPCache) Clear()

func (*GOPCache) Feed

func (gc *GOPCache) Feed(msg base.RTMPMsg, lg LazyGet)

func (*GOPCache) GetGOPCount

func (gc *GOPCache) GetGOPCount() int

func (*GOPCache) GetGOPDataAt

func (gc *GOPCache) GetGOPDataAt(pos int) [][]byte

type Group

type Group struct {
	UniqueKey string // const after init
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(appName string, streamName string, pullEnable bool, pullURL string) *Group

func (*Group) AddHTTPFLVSubSession

func (group *Group) AddHTTPFLVSubSession(session *httpflv.SubSession)

func (*Group) AddHTTPTSSubSession

func (group *Group) AddHTTPTSSubSession(session *httpts.SubSession)

TODO chef:

这里应该也要考虑触发hls muxer开启
也即HTTPTS sub需要使用hls muxer,hls muxer开启和关闭都要考虑HTTPTS sub

func (*Group) AddRTMPPubSession

func (group *Group) AddRTMPPubSession(session *rtmp.ServerSession) bool

func (*Group) AddRTMPPullSession

func (group *Group) AddRTMPPullSession(session *rtmp.PullSession) bool

func (*Group) AddRTMPPushSession

func (group *Group) AddRTMPPushSession(url string, session *rtmp.PushSession)

func (*Group) AddRTMPSubSession

func (group *Group) AddRTMPSubSession(session *rtmp.ServerSession)

func (*Group) AddRTSPPubSession

func (group *Group) AddRTSPPubSession(session *rtsp.PubSession) bool

TODO chef: rtsp package中,增加回调返回值判断,如果是false,将连接关掉

func (*Group) BroadcastRTMP added in v0.19.12

func (group *Group) BroadcastRTMP(msg base.RTMPMsg)

func (*Group) DelHTTPFLVSubSession

func (group *Group) DelHTTPFLVSubSession(session *httpflv.SubSession)

func (*Group) DelHTTPTSSubSession

func (group *Group) DelHTTPTSSubSession(session *httpts.SubSession)

func (*Group) DelRTMPPubSession

func (group *Group) DelRTMPPubSession(session *rtmp.ServerSession)

func (*Group) DelRTMPPullSession

func (group *Group) DelRTMPPullSession(session *rtmp.PullSession)

func (*Group) DelRTMPPushSession

func (group *Group) DelRTMPPushSession(url string, session *rtmp.PushSession)

func (*Group) DelRTMPSubSession

func (group *Group) DelRTMPSubSession(session *rtmp.ServerSession)

func (*Group) DelRTSPPubSession

func (group *Group) DelRTSPPubSession(session *rtsp.PubSession)

func (*Group) DelRTSPSubSession

func (group *Group) DelRTSPSubSession(session *rtsp.SubSession)

func (*Group) Dispose

func (group *Group) Dispose()

主动释放所有资源。保证所有资源的生命周期逻辑上都在我们的控制中。降低出bug的几率,降低心智负担。 注意,Dispose后,不应再使用这个对象。 值得一提,如果是从其他协程回调回来的消息,在使用Group中的资源前,要判断资源是否存在以及可用。

TODO chef:

后续弄个协程来替换掉目前锁的方式,来做消息同步。这样有个好处,就是不用写很多的资源有效判断。统一写一个就好了。
目前Dispose在IsTotalEmpty时调用,暂时没有这个问题。

func (*Group) GetStat

func (group *Group) GetStat() base.StatGroup

func (*Group) HandleNewRTSPSubSessionDescribe

func (group *Group) HandleNewRTSPSubSessionDescribe(session *rtsp.SubSession) (ok bool, sdp []byte)

func (*Group) HandleNewRTSPSubSessionPlay

func (group *Group) HandleNewRTSPSubSessionPlay(session *rtsp.SubSession) bool

func (*Group) HasInSession

func (group *Group) HasInSession() bool

func (*Group) HasOutSession

func (group *Group) HasOutSession() bool

func (*Group) IsHLSMuxerAlive

func (group *Group) IsHLSMuxerAlive() bool

func (*Group) IsTotalEmpty

func (group *Group) IsTotalEmpty() bool

func (*Group) KickOutSession

func (group *Group) KickOutSession(sessionID string) bool

func (*Group) OnAVConfig

func (group *Group) OnAVConfig(asc, vps, sps, pps []byte)

rtsp.PubSession

func (*Group) OnAVPacket

func (group *Group) OnAVPacket(pkt base.AVPacket)

rtsp.PubSession

func (*Group) OnRTPPacket

func (group *Group) OnRTPPacket(pkt rtprtcp.RTPPacket)

rtsp.PubSession

func (*Group) OnReadRTMPAVMsg

func (group *Group) OnReadRTMPAVMsg(msg base.RTMPMsg)

rtmp.PubSession or rtmp.PullSession

func (*Group) OnTSPackets

func (group *Group) OnTSPackets(rawFrame []byte, boundary bool)

hls.Muxer

func (*Group) RunLoop

func (group *Group) RunLoop()

func (*Group) StartPull

func (group *Group) StartPull(url string)

func (*Group) StringifyDebugStats

func (group *Group) StringifyDebugStats() string

func (*Group) Tick

func (group *Group) Tick()

TODO chef: 传入时间 目前每秒触发一次

type HLSConfig

type HLSConfig struct {
	SubListenAddr       string `json:"sub_listen_addr"`
	UseMemoryAsDiskFlag bool   `json:"use_memory_as_disk_flag"`
	hls.MuxerConfig
	EventObserverConfig  hls.MuxerEventObserver `json:"-"`
	HttpReadFileFallback hls.ReadFileFallback   `json:"-"`
}

type HTTPAPIConfig

type HTTPAPIConfig struct {
	Enable bool   `json:"enable"`
	Addr   string `json:"addr"`
}

type HTTPAPIServer

type HTTPAPIServer struct {
	// contains filtered or unexported fields
}

func NewHTTPAPIServer

func NewHTTPAPIServer(addr string, observer HTTPAPIServerObserver) *HTTPAPIServer

func (*HTTPAPIServer) Listen

func (h *HTTPAPIServer) Listen() (err error)

func (*HTTPAPIServer) Runloop

func (h *HTTPAPIServer) Runloop() error

type HTTPAPIServerObserver

type HTTPAPIServerObserver interface {
	OnStatAllGroup() []base.StatGroup
	OnStatGroup(streamName string) *base.StatGroup
	OnCtrlStartPull(info base.APICtrlStartPullReq)
	OnCtrlKickOutSession(info base.APICtrlKickOutSession) base.HTTPResponseBasic
}

type HTTPFLVConfig

type HTTPFLVConfig struct {
	httpflv.ServerConfig
	GOPNum int `json:"gop_num"`
}

type HTTPNotify

type HTTPNotify struct {
	// contains filtered or unexported fields
}

func (*HTTPNotify) OnPubStart

func (h *HTTPNotify) OnPubStart(info base.PubStartInfo)

func (*HTTPNotify) OnPubStop

func (h *HTTPNotify) OnPubStop(info base.PubStopInfo)

func (*HTTPNotify) OnRTMPConnect

func (h *HTTPNotify) OnRTMPConnect(info base.RTMPConnectInfo)

func (*HTTPNotify) OnServerStart

func (h *HTTPNotify) OnServerStart()

注意,这里的函数命名以On开头并不是因为是回调函数,而是notify给业务方的接口叫做on_server_start

func (*HTTPNotify) OnSubStart

func (h *HTTPNotify) OnSubStart(info base.SubStartInfo)

func (*HTTPNotify) OnSubStop

func (h *HTTPNotify) OnSubStop(info base.SubStopInfo)

func (*HTTPNotify) OnUpdate

func (h *HTTPNotify) OnUpdate(info base.UpdateInfo)

func (*HTTPNotify) RunLoop

func (h *HTTPNotify) RunLoop()

type HTTPNotifyConfig

type HTTPNotifyConfig struct {
	Enable            bool   `json:"enable"`
	UpdateIntervalSec int    `json:"update_interval_sec"`
	OnServerStart     string `json:"on_server_start"`
	OnUpdate          string `json:"on_update"`
	OnPubStart        string `json:"on_pub_start"`
	OnPubStop         string `json:"on_pub_stop"`
	OnSubStart        string `json:"on_sub_start"`
	OnSubStop         string `json:"on_sub_stop"`
	OnRTMPConnect     string `json:"on_rtmp_connect"`
}

type HTTPTSConfig

type HTTPTSConfig struct {
	Enable        bool   `json:"enable"`
	SubListenAddr string `json:"sub_listen_addr"`
}

type LazyChunkDivider

type LazyChunkDivider struct {
	// contains filtered or unexported fields
}

考虑以下两种场景: - 只有上行,没有下行,没有必要做rtmp chunk切片的操作 - 有多个下行,只需要做一次rtmp chunk切片 所以这一步做了懒处理

func (*LazyChunkDivider) Get

func (lcd *LazyChunkDivider) Get() []byte

func (*LazyChunkDivider) Init

func (lcd *LazyChunkDivider) Init(message []byte, header *base.RTMPHeader)

type LazyGet

type LazyGet func() []byte

type LazyRTMPMsg2FLVTag

type LazyRTMPMsg2FLVTag struct {
	// contains filtered or unexported fields
}

懒转换

func (*LazyRTMPMsg2FLVTag) Get

func (l *LazyRTMPMsg2FLVTag) Get() []byte

func (*LazyRTMPMsg2FLVTag) Init

func (l *LazyRTMPMsg2FLVTag) Init(msg base.RTMPMsg)

type PProfConfig

type PProfConfig struct {
	Enable bool   `json:"enable"`
	Addr   string `json:"addr"`
}

type PostTask

type PostTask struct {
	// contains filtered or unexported fields
}

type RTMPConfig

type RTMPConfig struct {
	Enable bool   `json:"enable"`
	Addr   string `json:"addr"`
	GOPNum int    `json:"gop_num"`
}

type RTSPConfig

type RTSPConfig struct {
	Enable bool   `json:"enable"`
	Addr   string `json:"addr"`
}

type RecordConfig added in v0.19.12

type RecordConfig struct {
	EnableFLV     bool   `json:"enable_flv"`
	FLVOutPath    string `json:"flv_out_path"`
	EnableMPEGTS  bool   `json:"enable_mpegts"`
	MPEGTSOutPath string `json:"mpegts_out_path"`
}

type RelayPullConfig

type RelayPullConfig struct {
	Enable bool   `json:"enable"`
	Addr   string `json:"addr"`
}

type RelayPushConfig

type RelayPushConfig struct {
	Enable   bool     `json:"enable"`
	AddrList []string `json:"addr_list"`
}

type ServerManager

type ServerManager struct {
	// contains filtered or unexported fields
}

func NewServerManager

func NewServerManager() *ServerManager

func (*ServerManager) Dispose

func (sm *ServerManager) Dispose()

func (*ServerManager) GetGroup

func (sm *ServerManager) GetGroup(appName string, streamName string) *Group

func (*ServerManager) OnCtrlKickOutSession

func (sm *ServerManager) OnCtrlKickOutSession(info base.APICtrlKickOutSession) base.HTTPResponseBasic

HTTPAPIServerObserver

func (*ServerManager) OnCtrlStartPull

func (sm *ServerManager) OnCtrlStartPull(info base.APICtrlStartPullReq)

HTTPAPIServerObserver

func (*ServerManager) OnDelHTTPFLVSubSession

func (sm *ServerManager) OnDelHTTPFLVSubSession(session *httpflv.SubSession)

ServerObserver of httpflv.Server

func (*ServerManager) OnDelHTTPTSSubSession

func (sm *ServerManager) OnDelHTTPTSSubSession(session *httpts.SubSession)

ServerObserver of httpts.Server

func (*ServerManager) OnDelRTMPPubSession

func (sm *ServerManager) OnDelRTMPPubSession(session *rtmp.ServerSession)

ServerObserver of rtmp.Server

func (*ServerManager) OnDelRTMPSubSession

func (sm *ServerManager) OnDelRTMPSubSession(session *rtmp.ServerSession)

ServerObserver of rtmp.Server

func (*ServerManager) OnDelRTSPPubSession

func (sm *ServerManager) OnDelRTSPPubSession(session *rtsp.PubSession)

ServerObserver of rtsp.Server

func (*ServerManager) OnDelRTSPSession

func (sm *ServerManager) OnDelRTSPSession(session *rtsp.ServerCommandSession)

ServerObserver of rtsp.Server

func (*ServerManager) OnDelRTSPSubSession

func (sm *ServerManager) OnDelRTSPSubSession(session *rtsp.SubSession)

ServerObserver of rtsp.Server

func (*ServerManager) OnNewHTTPFLVSubSession

func (sm *ServerManager) OnNewHTTPFLVSubSession(session *httpflv.SubSession) bool

ServerObserver of httpflv.Server

func (*ServerManager) OnNewHTTPTSSubSession

func (sm *ServerManager) OnNewHTTPTSSubSession(session *httpts.SubSession) bool

ServerObserver of httpts.Server

func (*ServerManager) OnNewRTMPPubSession

func (sm *ServerManager) OnNewRTMPPubSession(session *rtmp.ServerSession) bool

ServerObserver of rtmp.Server

func (*ServerManager) OnNewRTMPSubSession

func (sm *ServerManager) OnNewRTMPSubSession(session *rtmp.ServerSession) bool

ServerObserver of rtmp.Server

func (*ServerManager) OnNewRTSPPubSession

func (sm *ServerManager) OnNewRTSPPubSession(session *rtsp.PubSession) bool

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRTSPSessionConnect

func (sm *ServerManager) OnNewRTSPSessionConnect(session *rtsp.ServerCommandSession)

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRTSPSubSessionDescribe

func (sm *ServerManager) OnNewRTSPSubSessionDescribe(session *rtsp.SubSession) (ok bool, sdp []byte)

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRTSPSubSessionPlay

func (sm *ServerManager) OnNewRTSPSubSessionPlay(session *rtsp.SubSession) bool

ServerObserver of rtsp.Server

func (*ServerManager) OnRTMPConnect

func (sm *ServerManager) OnRTMPConnect(session *rtmp.ServerSession, opa rtmp.ObjectPairArray)

ServerObserver of rtmp.Server

func (*ServerManager) OnStatAllGroup

func (sm *ServerManager) OnStatAllGroup() (sgs []base.StatGroup)

HTTPAPIServerObserver

func (*ServerManager) OnStatGroup

func (sm *ServerManager) OnStatGroup(streamName string) *base.StatGroup

HTTPAPIServerObserver

func (*ServerManager) RunLoop

func (sm *ServerManager) RunLoop() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL