base

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 10 Imported by: 20

Documentation

Index

Constants

View Source
const (
	ErrorCodeSucc            = 0
	DespSucc                 = "succ"
	ErrorCodeGroupNotFound   = 1001
	DespGroupNotFound        = "group not found"
	ErrorCodeParamMissing    = 1002
	DespParamMissing         = "param missing"
	ErrorCodeSessionNotFound = 1003
	DespSessionNotFound      = "session not found"
)
View Source
const (
	// spec-rtmp_specification_1.0.pdf
	// 7.1. Types of Messages
	RTMPTypeIDAudio              uint8 = 8
	RTMPTypeIDVideo              uint8 = 9
	RTMPTypeIDMetadata           uint8 = 18 // RTMPTypeIDDataMessageAMF0
	RTMPTypeIDSetChunkSize       uint8 = 1
	RTMPTypeIDAck                uint8 = 3
	RTMPTypeIDUserControl        uint8 = 4
	RTMPTypeIDWinAckSize         uint8 = 5
	RTMPTypeIDBandwidth          uint8 = 6
	RTMPTypeIDCommandMessageAMF3 uint8 = 17
	RTMPTypeIDCommandMessageAMF0 uint8 = 20
	RTMPTypeIDAggregateMessage   uint8 = 22

	// user control message type
	RTMPUserControlStreamBegin uint8 = 0
	RTMPUserControlRecorded    uint8 = 4

	// spec-video_file_format_spec_v10.pdf
	// Video tags
	//   VIDEODATA
	//     FrameType UB[4]
	//     CodecID   UB[4]
	//   AVCVIDEOPACKET
	//     AVCPacketType   UI8
	//     CompositionTime SI24
	//     Data            UI8[n]
	RTMPFrameTypeKey   uint8 = 1
	RTMPFrameTypeInter uint8 = 2

	RTMPCodecIDAVC  uint8 = 7
	RTMPCodecIDHEVC uint8 = 12

	RTMPAVCPacketTypeSeqHeader  uint8 = 0
	RTMPAVCPacketTypeNALU       uint8 = 1
	RTMPHEVCPacketTypeSeqHeader       = RTMPAVCPacketTypeSeqHeader
	RTMPHEVCPacketTypeNALU            = RTMPAVCPacketTypeNALU

	RTMPAVCKeyFrame    = RTMPFrameTypeKey<<4 | RTMPCodecIDAVC
	RTMPHEVCKeyFrame   = RTMPFrameTypeKey<<4 | RTMPCodecIDHEVC
	RTMPAVCInterFrame  = RTMPFrameTypeInter<<4 | RTMPCodecIDAVC
	RTMPHEVCInterFrame = RTMPFrameTypeInter<<4 | RTMPCodecIDHEVC

	// spec-video_file_format_spec_v10.pdf
	// Audio tags
	//   AUDIODATA
	//     SoundFormat UB[4]
	//     SoundRate   UB[2]
	//     SoundSize   UB[1]
	//     SoundType   UB[1]
	//   AACAUDIODATA
	//     AACPacketType UI8
	//     Data          UI8[n]
	RTMPSoundFormatAAC         uint8 = 10
	RTMPAACPacketTypeSeqHeader       = 0
	RTMPAACPacketTypeRaw             = 1
)
View Source
const (
	// 注意,一般情况下,AVC使用96,AAC使用97,HEVC使用98
	// 但是我还遇到过:
	// HEVC使用96
	// AVC使用105
	RTPPacketTypeAVCOrHEVC = 96
	RTPPacketTypeAAC       = 97
	RTPPacketTypeHEVC      = 98
)
View Source
const (
	// StatGroup.AudioCodec
	AudioCodecAAC = "AAC"

	// StatGroup.VideoCodec
	VideoCodecAVC  = "H264"
	VideoCodecHEVC = "H265"

	// StatSession.Protocol
	ProtocolRTMP    = "RTMP"
	ProtocolRTSP    = "RTSP"
	ProtocolHTTPFLV = "HTTP-FLV"
	ProtocolHTTPTS  = "HTTP-TS"
)
View Source
const (
	UKPreRTMPServerSession        = "RTMPPUBSUB"
	UKPreRTMPPushSession          = "RTMPPUSH"
	UKPreRTMPPullSession          = "RTMPPULL"
	UKPreRTSPServerCommandSession = "RTSPSRVCMD"
	UKPreRTSPPubSession           = "RTSPPUB"
	UKPreRTSPSubSession           = "RTSPSUB"
	UKPreRTSPPushSession          = "RTSPPUSH"
	UKPreRTSPPullSession          = "RTSPPULL"
	UKPreFLVSubSession            = "FLVSUB"
	UKPreTSSubSession             = "TSSUB"
	UKPreFLVPullSession           = "FLVPULL"

	UKPreGroup    = "GROUP"
	UKPreHLSMuxer = "HLSMUXER"
	UKPreStreamer = "STREAMER"
)
View Source
const (
	DefaultRTMPPort  = 1935
	DefaultHTTPPort  = 80
	DefaultHTTPSPort = 443
	DefaultRTSPPort  = 554
)
View Source
const HTTPAPIVersion = "v0.1.4"
View Source
const HTTPNotifyVersion = "v0.1.0"
View Source
const LALVersion = "v0.21.0"

版本,该变量由外部脚本修改维护

Variables

View Source
var (
	LALLibraryName = "lal"
	LALGithubRepo  = "github.com/q191201771/lal"
	LALGithubSite  = "https://github.com/q191201771/lal"
	LALDocSite     = "https://pengrl.com/lal"

	// e.g. lal v0.12.3 (github.com/q191201771/lal)
	LALFullInfo = LALLibraryName + " " + LALVersion + " (" + LALGithubRepo + ")"

	// e.g. 0.12.3
	LALVersionDot string

	// e.g. 0,12,3
	LALVersionComma string
)
View Source
var (

	// 植入rtmp server中的connect result信令中
	// 注意,有两个object,第一个object中的fmsVer我们保持通用公认的值,在第二个object中植入
	// e.g. 0,12,3
	LALRTMPConnectResultVersion string

	// e.g. lal0.12.3
	LALRTMPPushSessionConnectVersion string

	// e.g. lal0.12.3
	LALRTMPBuildMetadataEncoder string

	// e.g. lal/0.12.3
	LALHTTPFLVPullSessionUA string

	// e.g. lal0.12.3
	LALHTTPFLVSubSessionServer string

	// e.g. lal0.12.3
	LALHLSM3U8Server string

	// e.g. lal0.12.3
	LALHLSTSServer string

	// e.g. lal0.12.3
	LALRTSPOptionsResponseServer string

	// e.g. lal0.12.3
	LALHTTPTSSubSessionServer string

	// e.g. lal0.12.3
	LALHTTPAPIServer string

	// e.g. lal/0.12.3
	LALRTSPPullSessionUA string
)
View Source
var (
	ErrSessionNotStarted = errors.New("lal.base: session has not been started yet")
)
View Source
var ErrURL = errors.New("lal.url: fxxk")

Functions

func GenUKFLVPullSession added in v0.20.0

func GenUKFLVPullSession() string

func GenUKFLVSubSession added in v0.20.0

func GenUKFLVSubSession() string

func GenUKGroup added in v0.20.0

func GenUKGroup() string

func GenUKHLSMuxer added in v0.20.0

func GenUKHLSMuxer() string

func GenUKRTMPPullSession added in v0.20.0

func GenUKRTMPPullSession() string

func GenUKRTMPPushSession added in v0.20.0

func GenUKRTMPPushSession() string

func GenUKRTMPServerSession added in v0.20.0

func GenUKRTMPServerSession() string

func GenUKRTSPPubSession added in v0.20.0

func GenUKRTSPPubSession() string

func GenUKRTSPPullSession added in v0.20.0

func GenUKRTSPPullSession() string

func GenUKRTSPPushSession added in v0.20.0

func GenUKRTSPPushSession() string

func GenUKRTSPServerCommandSession added in v0.20.0

func GenUKRTSPServerCommandSession() string

func GenUKRTSPSubSession added in v0.20.0

func GenUKRTSPSubSession() string

func GenUKStreamer added in v0.20.0

func GenUKStreamer() string

func GenUKTSSubSession added in v0.20.0

func GenUKTSSubSession() string

func OSExitAndWaitPressIfWindows added in v0.19.0

func OSExitAndWaitPressIfWindows(code int)

Types

type APICtrlKickOutSession added in v0.17.0

type APICtrlKickOutSession struct {
	StreamName string `json:"stream_name"`
	SessionID  string `json:"session_id"`
}

type APICtrlStartPullReq added in v0.17.0

type APICtrlStartPullReq struct {
	Protocol   string `json:"protocol"`
	Addr       string `json:"addr"`
	AppName    string `json:"app_name"`
	StreamName string `json:"stream_name"`
	URLParam   string `json:"url_param"`
}

type APIStatAllGroup added in v0.17.0

type APIStatAllGroup struct {
	HTTPResponseBasic
	Data struct {
		Groups []StatGroup `json:"groups"`
	} `json:"data"`
}

type APIStatGroup added in v0.17.0

type APIStatGroup struct {
	HTTPResponseBasic
	Data *StatGroup `json:"data"`
}

type APIStatLALInfo added in v0.17.0

type APIStatLALInfo struct {
	HTTPResponseBasic
	Data LALInfo `json:"data"`
}

type AVPacket

type AVPacket struct {
	Timestamp   uint32
	PayloadType AVPacketPT
	Payload     []byte
}

目前供package rtsp使用。以后可能被多个package使用。 不排除不同package使用时,字段含义也不同的情况出现。 使用AVPacket的地方,应注明各字段的含义。

type AVPacketPT added in v0.16.0

type AVPacketPT int
const (
	AVPacketPTUnknown AVPacketPT = -1
	AVPacketPTAVC     AVPacketPT = RTPPacketTypeAVCOrHEVC
	AVPacketPTHEVC    AVPacketPT = RTPPacketTypeHEVC
	AVPacketPTAAC     AVPacketPT = RTPPacketTypeAAC
)

type HTTPResponseBasic added in v0.17.0

type HTTPResponseBasic struct {
	ErrorCode int    `json:"error_code"`
	Desp      string `json:"desp"`
}

type IClientSession added in v0.20.0

type IClientSessionLifecycle added in v0.20.0

type IClientSessionLifecycle interface {
	// 关闭session
	// 业务方想主动关闭session时调用
	// 注意,Start成功后的session,必须显示调用Dispose释放资源(即使是被动接收到了WaitChan信号)
	Dispose() error

	// Start成功后,可使用这个channel来接收session结束的信号
	WaitChan() <-chan error
}

调用约束:对于Client类型的Session,调用Start函数并返回成功后才能调用,否则行为未定义

type IObject added in v0.20.0

type IObject interface {
	// 对象的全局唯一标识
	UniqueKey() string
}

type IServerSession added in v0.20.0

type IServerSessionLifecycle added in v0.20.0

type IServerSessionLifecycle interface {
	// 开启session的事件循环,阻塞直到session结束
	RunLoop() error

	// 主动关闭session时调用
	Dispose() error
}

type ISessionStat added in v0.18.0

type ISessionStat interface {
	// 周期性调用该函数,用于计算bitrate
	//
	// @param intervalSec 距离上次调用的时间间隔,单位毫秒
	UpdateStat(intervalSec uint32)

	// 获取session状态
	//
	// @return 注意,结构体中的`Bitrate`的值由最近一次`func UpdateStat`调用计算决定,其他值为当前最新值
	GetStat() StatSession

	// 周期性调用该函数,判断是否有读取、写入数据
	// 注意,判断的依据是,距离上次调用该函数的时间间隔内,是否有读取、写入数据
	// 注意,不活跃,并一定是链路或网络有问题,也可能是业务层没有写入数据
	//
	// @return readAlive  读取是否获取
	// @return writeAlive 写入是否活跃
	IsAlive() (readAlive, writeAlive bool)
}

调用约束:对于Client类型的Session,调用Start函数并返回成功后才能调用,否则行为未定义

type ISessionURLContext added in v0.18.0

type ISessionURLContext interface {
	URL() string
	AppName() string
	StreamName() string
	RawQuery() string
}

获取和流地址相关的信息

调用约束:对于Client类型的Session,调用Start函数并返回成功后才能调用,否则行为未定义

type LALInfo added in v0.17.0

type LALInfo struct {
	ServerID      string `json:"server_id"`
	BinInfo       string `json:"bin_info"`
	LalVersion    string `json:"lal_version"`
	APIVersion    string `json:"api_version"`
	NotifyVersion string `json:"notify_version"`
	StartTime     string `json:"start_time"`
}

type PubStartInfo added in v0.17.0

type PubStartInfo struct {
	SessionEventCommonInfo
}

type PubStopInfo added in v0.17.0

type PubStopInfo struct {
	SessionEventCommonInfo
}

type RTMPConnectInfo added in v0.17.0

type RTMPConnectInfo struct {
	ServerID   string `json:"server_id"`
	SessionID  string `json:"session_id"`
	RemoteAddr string `json:"remote_addr"`
	App        string `json:"app"`
	FlashVer   string `json:"flashVer"`
	TCURL      string `json:"tcUrl"`
}

type RTMPHeader

type RTMPHeader struct {
	CSID         int
	MsgLen       uint32 // 不包含header的大小
	MsgTypeID    uint8  // 8 audio 9 video 18 metadata
	MsgStreamID  int
	TimestampAbs uint32 // 经过计算得到的流上的绝对时间戳
}

type RTMPMsg

type RTMPMsg struct {
	Header  RTMPHeader
	Payload []byte // Payload不包含Header内容。如果需要将RTMPMsg序列化成RTMP chunk,可调用rtmp.ChunkDivider相关的函数
}

func (RTMPMsg) Clone added in v0.19.0

func (msg RTMPMsg) Clone() (ret RTMPMsg)

func (RTMPMsg) IsAACSeqHeader

func (msg RTMPMsg) IsAACSeqHeader() bool

func (RTMPMsg) IsAVCKeyNALU

func (msg RTMPMsg) IsAVCKeyNALU() bool

func (RTMPMsg) IsAVCKeySeqHeader

func (msg RTMPMsg) IsAVCKeySeqHeader() bool

func (RTMPMsg) IsHEVCKeyNALU

func (msg RTMPMsg) IsHEVCKeyNALU() bool

func (RTMPMsg) IsHEVCKeySeqHeader

func (msg RTMPMsg) IsHEVCKeySeqHeader() bool

func (RTMPMsg) IsVideoKeyNALU

func (msg RTMPMsg) IsVideoKeyNALU() bool

func (RTMPMsg) IsVideoKeySeqHeader

func (msg RTMPMsg) IsVideoKeySeqHeader() bool

type SessionEventCommonInfo added in v0.17.0

type SessionEventCommonInfo struct {
	Protocol      string `json:"protocol"`
	SessionID     string `json:"session_id"`
	RemoteAddr    string `json:"remote_addr"`
	ServerID      string `json:"server_id"`
	URL           string `json:"url"`
	AppName       string `json:"app_name"`
	StreamName    string `json:"stream_name"`
	URLParam      string `json:"url_param"`
	HasInSession  bool   `json:"has_in_session"`
	HasOutSession bool   `json:"has_out_session"`
}

type StatGroup added in v0.16.0

type StatGroup struct {
	StreamName  string    `json:"stream_name"`
	AudioCodec  string    `json:"audio_codec"`
	VideoCodec  string    `json:"video_codec"`
	VideoWidth  int       `json:"video_width"`
	VideoHeight int       `json:"video_height"`
	StatPub     StatPub   `json:"pub"`
	StatSubs    []StatSub `json:"subs"`
	StatPull    StatPull  `json:"pull"`
}

type StatPub added in v0.16.0

type StatPub struct {
	StatSession
}

func StatSession2Pub added in v0.16.0

func StatSession2Pub(ss StatSession) (ret StatPub)

type StatPull added in v0.17.0

type StatPull struct {
	StatSession
}

func StatSession2Pull added in v0.17.0

func StatSession2Pull(ss StatSession) (ret StatPull)

type StatSession added in v0.16.0

type StatSession struct {
	Protocol   string `json:"protocol"`
	SessionID  string `json:"session_id"`
	RemoteAddr string `json:"remote_addr"`
	StartTime  string `json:"start_time"`

	ReadBytesSum  uint64 `json:"read_bytes_sum"`
	WroteBytesSum uint64 `json:"wrote_bytes_sum"`
	Bitrate       int    `json:"bitrate"`
	ReadBitrate   int    `json:"read_bitrate"`
	WriteBitrate  int    `json:"write_bitrate"`
}

type StatSub added in v0.16.0

type StatSub struct {
	StatSession
}

func StatSession2Sub added in v0.16.0

func StatSession2Sub(ss StatSession) (ret StatSub)

type SubStartInfo added in v0.17.0

type SubStartInfo struct {
	SessionEventCommonInfo
}

type SubStopInfo added in v0.17.0

type SubStopInfo struct {
	SessionEventCommonInfo
}

type URLContext added in v0.18.0

type URLContext struct {
	URL string

	Scheme       string
	Username     string
	Password     string
	StdHost      string // host or host:port
	HostWithPort string
	Host         string
	Port         int

	//URLPathContext
	PathWithRawQuery    string
	Path                string
	PathWithoutLastItem string // 注意,没有前面的'/',也没有后面的'/'
	LastItemOfPath      string // 注意,没有前面的'/'
	RawQuery            string

	RawURLWithoutUserInfo string
}

TODO chef: 考虑把rawURL也放入其中

func ParseHTTPFLVURL added in v0.18.0

func ParseHTTPFLVURL(rawURL string, isHTTPS bool) (ctx URLContext, err error)

func ParseHTTPTSURL added in v0.20.0

func ParseHTTPTSURL(rawURL string, isHTTPS bool) (ctx URLContext, err error)

func ParseRTMPURL added in v0.18.0

func ParseRTMPURL(rawURL string) (ctx URLContext, err error)

func ParseRTSPURL added in v0.18.0

func ParseRTSPURL(rawURL string) (ctx URLContext, err error)

func ParseURL added in v0.18.0

func ParseURL(rawURL string, defaultPort int) (ctx URLContext, err error)

type URLPathContext added in v0.18.0

type URLPathContext struct {
	PathWithRawQuery    string
	Path                string
	PathWithoutLastItem string // 注意,没有前面的'/',也没有后面的'/'
	LastItemOfPath      string // 注意,没有前面的'/'
	RawQuery            string
}

type UpdateInfo added in v0.17.0

type UpdateInfo struct {
	ServerID string      `json:"server_id"`
	Groups   []StatGroup `json:"groups"`
}

Jump to

Keyboard shortcuts

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