base

package
v0.19.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 10 Imported by: 0

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

	// 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 (
	UKPRTMPServerSession        = "RTMPPUBSUB"
	UKPRTMPPushSession          = "RTMPPUSH"
	UKPRTMPPullSession          = "RTMPPULL"
	UKPRTSPServerCommandSession = "RTSPSRVCMD"
	UKPRTSPPubSession           = "RTSPPUB"
	UKPRTSPSubSession           = "RTSPSUB"
	UKPRTSPPushSession          = "RTSPPUSH"
	UKPRTSPPullSession          = "RTSPPULL"
	UKPFLVSubSession            = "FLVSUB"
	UKPTSSubSession             = "TSSUB"
	UKPFLVPullSession           = "FLVPULL"

	UKPGroup    = "GROUP"
	UKPHLSMuxer = "HLSMUXER"
	UKPStreamer = "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.19.1"

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

Variables

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

	// e.g. lal v0.12.3 (github.com/cfeeling/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 ErrURL = errors.New("lal.url: fxxk")

Functions

func GenUniqueKey

func GenUniqueKey(prefix string) string

func OSExitAndWaitPressIfWindows

func OSExitAndWaitPressIfWindows(code int)

Types

type APICtrlKickOutSession

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

type APICtrlStartPullReq

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

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

type APIStatGroup

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

type APIStatLALInfo

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

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

type HTTPResponseBasic

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

type ISession

type ISession interface {
	RemoteAddr() string
}

type ISessionStat

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

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

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

type ISessionURLContext

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

type LALInfo

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

type PubStartInfo struct {
	SessionEventCommonInfo
}

type PubStopInfo

type PubStopInfo struct {
	SessionEventCommonInfo
}

type RTMPConnectInfo

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

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

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

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

type StatPub struct {
	StatSession
}

func StatSession2Pub

func StatSession2Pub(ss StatSession) (ret StatPub)

type StatPull

type StatPull struct {
	StatSession
}

func StatSession2Pull

func StatSession2Pull(ss StatSession) (ret StatPull)

type StatSession

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

type StatSub struct {
	StatSession
}

func StatSession2Sub

func StatSession2Sub(ss StatSession) (ret StatSub)

type SubStartInfo

type SubStartInfo struct {
	SessionEventCommonInfo
}

type SubStopInfo

type SubStopInfo struct {
	SessionEventCommonInfo
}

type URLContext

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

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

func ParseHTTPTSURL

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

func ParseRTMPURL

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

func ParseRTSPURL

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

func ParseURL

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

type URLPathContext

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

type UpdateInfo

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