logic

package
v0.24.28 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const ConfVersion = "v0.2.2"

Variables

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

Functions

func Dispose

func Dispose()

func Init added in v0.24.1

func Init(confFile string)

func RunLoop added in v0.24.1

func RunLoop()

func SetConfig added in v0.24.3

func SetConfig(c *Config)

Types

type CommonHttpAddrConfig added in v0.24.1

type CommonHttpAddrConfig struct {
	HttpListenAddr  string `json:"http_listen_addr"`
	HttpsListenAddr string `json:"https_listen_addr"`
	HttpsCertFile   string `json:"https_cert_file"`
	HttpsKeyFile    string `json:"https_key_file"`
}

type CommonHttpServerConfig added in v0.24.1

type CommonHttpServerConfig struct {
	CommonHttpAddrConfig

	Enable      bool   `json:"enable"`
	EnableHttps bool   `json:"enable_https"`
	UrlPattern  string `json:"url_pattern"`
}

type Config

type Config struct {
	ConfVersion       string            `json:"conf_version"`
	RtmpConfig        RtmpConfig        `json:"rtmp"`
	DefaultHttpConfig DefaultHttpConfig `json:"default_http"`
	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 GetConfig added in v0.24.1

func GetConfig() *Config

TODO(chef) 临时供innertest使用,后面应该重构

func LoadConfAndInitLog added in v0.19.12

func LoadConfAndInitLog(confFile string) *Config

type DefaultHttpConfig added in v0.24.1

type DefaultHttpConfig struct {
	CommonHttpAddrConfig
}

type Gop added in v0.24.1

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

func (*Gop) Clear added in v0.24.1

func (g *Gop) Clear()

func (*Gop) Feed added in v0.24.1

func (g *Gop) Feed(msg base.RtmpMsg, b []byte)

type GopCache added in v0.24.1

type GopCache struct {
	Metadata       []byte
	VideoSeqHeader []byte
	AacSeqHeader   []byte
	// contains filtered or unexported fields
}

提供两个功能:

  1. 缓存Metadata, VideoSeqHeader, AacSeqHeader
  2. 缓存音视频GOP数据

以下,只讨论GopCache的第2点功能

音频和视频都会缓存

GopCache也可能不缓存GOP数据,见NewGopCache函数的gopNum参数说明

以下,我们只讨论gopNum > 0(也即gopSize > 1)的情况

GopCache为空时,只有输入了关键帧,才能开启GOP缓存,非关键帧以及音频数据不会被缓存 因此,单音频的流是ok的,相当于不缓存任何数据

GopCache不为空时,输入关键帧触发生成新的GOP元素,其他情况则往最后一个GOP元素一直追加

first用于读取第一个GOP(可能不完整),last的前一个用于写入当前GOP

最近不完整的GOP也会被缓存,见NewGopCache函数的gopNum参数说明

----- gopNum = 1 gopSize = 2

first     |   first       |       first   | 在后面两个状态间转换,就不画了
  |       |     |         |        |      |
  0   1   |     0   1	  |    0   1      |
  *   *   |     *   *	  |    *   *      |
  |       |         |	  |    |          |
last      |        last   |   last        |
          |               |               |
(empty)   |   (full)      |   (full)      |

GetGopCount: 0 | 1 | 1 | -----

func NewGopCache added in v0.24.1

func NewGopCache(t string, uniqueKey string, gopNum int) *GopCache

@param gopNum: gop缓存大小

如果为0,则不缓存音频数据,也即GOP缓存功能不生效
如果>0,则缓存<gopNum>个完整GOP,另外还可能有半个最近不完整的GOP

func (*GopCache) Clear added in v0.24.1

func (gc *GopCache) Clear()

func (*GopCache) Feed added in v0.24.1

func (gc *GopCache) Feed(msg base.RtmpMsg, lg LazyGet)

func (*GopCache) GetGopCount added in v0.24.1

func (gc *GopCache) GetGopCount() int

获取GOP数量,注意,最后一个可能是不完整的

func (*GopCache) GetGopDataAt added in v0.24.1

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) *Group

func (*Group) AddHttpflvSubSession added in v0.24.1

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

func (*Group) AddHttptsSubSession added in v0.24.1

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

TODO chef:

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

func (*Group) AddRtmpPubSession added in v0.24.1

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

func (*Group) AddRtmpPullSession added in v0.24.1

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

func (*Group) AddRtmpPushSession added in v0.24.1

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

func (*Group) AddRtmpSubSession added in v0.24.1

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

func (*Group) AddRtspPubSession added in v0.24.1

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

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

func (*Group) DelHttpflvSubSession added in v0.24.1

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

func (*Group) DelHttptsSubSession added in v0.24.1

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

func (*Group) DelRtmpPubSession added in v0.24.1

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

func (*Group) DelRtmpPullSession added in v0.24.1

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

func (*Group) DelRtmpPushSession added in v0.24.1

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

func (*Group) DelRtmpSubSession added in v0.24.1

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

func (*Group) DelRtspPubSession added in v0.24.1

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

func (*Group) DelRtspSubSession added in v0.24.1

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

func (*Group) Dispose

func (group *Group) Dispose()

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

func (*Group) GetStat

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

func (*Group) HandleNewRtspSubSessionDescribe added in v0.24.1

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

func (*Group) HandleNewRtspSubSessionPlay added in v0.24.1

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 added in v0.24.1

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) OnAvPacket added in v0.24.1

func (group *Group) OnAvPacket(pkt base.AvPacket)

rtsp.PubSession

func (*Group) OnPatPmt added in v0.24.1

func (group *Group) OnPatPmt(b []byte)

hls.Muxer

func (*Group) OnReadRtmpAvMsg added in v0.24.1

func (group *Group) OnReadRtmpAvMsg(msg base.RtmpMsg)

rtmp.PubSession or rtmp.PullSession

func (*Group) OnRtpPacket added in v0.24.1

func (group *Group) OnRtpPacket(pkt rtprtcp.RtpPacket)

rtsp.PubSession

func (*Group) OnSdp added in v0.24.1

func (group *Group) OnSdp(sdpCtx sdp.LogicContext)

rtsp.PubSession

func (*Group) OnTsPackets added in v0.24.1

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)

外部命令主动触发pull拉流

当前调用时机: 1. 比如http api

func (*Group) StringifyDebugStats

func (group *Group) StringifyDebugStats() string

func (*Group) Tick

func (group *Group) Tick()

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

type HlsConfig added in v0.24.1

type HlsConfig struct {
	CommonHttpServerConfig

	UseMemoryAsDiskFlag  bool                   `json:"use_memory_as_disk_flag"`
	HttpReadFileFallback hls.ReadFileFallback   `json:"-"`
	EventObserverConfig  hls.MuxerEventObserver `json:"-"`
	hls.MuxerConfig
}

type HttpApiConfig added in v0.24.1

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

type HttpApiServer added in v0.24.1

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

func NewHttpApiServer added in v0.24.1

func NewHttpApiServer(addr string, observer HttpApiServerObserver) *HttpApiServer

func (*HttpApiServer) Listen added in v0.24.1

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

func (*HttpApiServer) Runloop added in v0.24.1

func (h *HttpApiServer) Runloop() error

type HttpApiServerObserver added in v0.24.1

type HttpApiServerObserver interface {
	OnStatAllGroup() []base.StatGroup
	OnStatGroup(streamName string) *base.StatGroup
	OnCtrlStartPull(info base.ApiCtrlStartPullReq)
	OnCtrlKickOutSession(info base.ApiCtrlKickOutSession) base.HttpResponseBasic
}

type HttpNotify added in v0.24.1

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

func (*HttpNotify) OnPubStart added in v0.24.1

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

func (*HttpNotify) OnPubStop added in v0.24.1

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

func (*HttpNotify) OnRtmpConnect added in v0.24.1

func (h *HttpNotify) OnRtmpConnect(info base.RtmpConnectInfo)

func (*HttpNotify) OnServerStart added in v0.24.1

func (h *HttpNotify) OnServerStart()

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

func (*HttpNotify) OnSubStart added in v0.24.1

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

func (*HttpNotify) OnSubStop added in v0.24.1

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

func (*HttpNotify) OnUpdate added in v0.24.1

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

func (*HttpNotify) RunLoop added in v0.24.1

func (h *HttpNotify) RunLoop()

type HttpNotifyConfig added in v0.24.1

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 HttpServerHandler added in v0.24.1

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

func NewHttpServerHandler added in v0.24.1

func NewHttpServerHandler(observer HttpServerHandlerObserver) *HttpServerHandler

func (*HttpServerHandler) ServeSubSession added in v0.24.1

func (h *HttpServerHandler) ServeSubSession(writer http.ResponseWriter, req *http.Request)

type HttpServerHandlerObserver added in v0.24.1

type HttpServerHandlerObserver interface {
	// 通知上层有新的拉流者
	// 返回值: true则允许拉流,false则关闭连接
	OnNewHttpflvSubSession(session *httpflv.SubSession) bool

	OnDelHttpflvSubSession(session *httpflv.SubSession)

	OnNewHttptsSubSession(session *httpts.SubSession) bool
	OnDelHttptsSubSession(session *httpts.SubSession)
}

type HttpflvConfig added in v0.24.1

type HttpflvConfig struct {
	CommonHttpServerConfig

	GopNum int `json:"gop_num"`
}

type HttptsConfig added in v0.24.1

type HttptsConfig struct {
	CommonHttpServerConfig
}

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 added in v0.24.1

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

懒转换

func (*LazyRtmpMsg2FlvTag) Get added in v0.24.1

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

func (*LazyRtmpMsg2FlvTag) Init added in v0.24.1

func (l *LazyRtmpMsg2FlvTag) Init(msg base.RtmpMsg)

type PostTask

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

type PprofConfig added in v0.24.1

type PprofConfig 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 RtmpConfig added in v0.24.1

type RtmpConfig struct {
	Enable         bool   `json:"enable"`
	Addr           string `json:"addr"`
	GopNum         int    `json:"gop_num"`
	MergeWriteSize int    `json:"merge_write_size"`
}

type RtspConfig added in v0.24.1

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

type ServerManager

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

func NewServerManager

func NewServerManager() *ServerManager

func NewStandaloneServerManager added in v0.24.2

func NewStandaloneServerManager(config *Config) *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 added in v0.24.1

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

ServerObserver of httpflv.Server

func (*ServerManager) OnDelHttptsSubSession added in v0.24.1

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

ServerObserver of httpts.Server

func (*ServerManager) OnDelRtmpPubSession added in v0.24.1

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

ServerObserver of rtmp.Server

func (*ServerManager) OnDelRtmpSubSession added in v0.24.1

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

ServerObserver of rtmp.Server

func (*ServerManager) OnDelRtspPubSession added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnDelRtspSession added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnDelRtspSubSession added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnNewHttpflvSubSession added in v0.24.1

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

ServerObserver of httpflv.Server

func (*ServerManager) OnNewHttptsSubSession added in v0.24.1

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

ServerObserver of httpts.Server

func (*ServerManager) OnNewRtmpPubSession added in v0.24.1

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

ServerObserver of rtmp.Server

func (*ServerManager) OnNewRtmpSubSession added in v0.24.1

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

ServerObserver of rtmp.Server

func (*ServerManager) OnNewRtspPubSession added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRtspSessionConnect added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRtspSubSessionDescribe added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnNewRtspSubSessionPlay added in v0.24.1

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

ServerObserver of rtsp.Server

func (*ServerManager) OnRtmpConnect added in v0.24.1

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