base

package
v0.0.0-...-928f415 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AvPacketStreamAudioFormatUnknown AvPacketStreamAudioFormat = 0
	AvPacketStreamAudioFormatRawAac  AvPacketStreamAudioFormat = 1

	AvPacketStreamVideoFormatUnknown AvPacketStreamVideoFormat = 0
	AvPacketStreamVideoFormatAvcc    AvPacketStreamVideoFormat = 1
	AvPacketStreamVideoFormatAnnexb  AvPacketStreamVideoFormat = 2
)
View Source
const (
	// AudioCodecAac StatGroup.AudioCodec
	AudioCodecAac = "AAC"

	// VideoCodecAvc StatGroup.VideoCodec
	VideoCodecAvc  = "H264"
	VideoCodecHevc = "H265"
)
View Source
const (
	PullRetryNumForever = -1
	PullRetryNumNever   = 0

	AutoStopPullAfterNoOutMsNever       = -1
	AutoStopPullAfterNoOutMsImmediately = 0

	RtspModeTcp = 0
	RtspModeUdp = 1
)
View Source
const (
	ErrorCodeSucc = 0
	DespSucc      = "succ"

	ErrorCodeGroupNotFound   = 1001
	DespGroupNotFound        = "group not found"
	ErrorCodeParamMissing    = 1002
	DespParamMissing         = "param missing"
	ErrorCodeSessionNotFound = 1003
	DespSessionNotFound      = "session not found"

	ErrorCodeStartRelayPullFail = 2001
)
View Source
const (
	// RtmpTypeIdAudio 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

	// RtmpUserControlStreamBegin RtmpUserControlXxx...
	//
	// user control message type
	//
	RtmpUserControlStreamBegin  uint8 = 0
	RtmpUserControlRecorded     uint8 = 4
	RtmpUserControlPingRequest  uint8 = 6
	RtmpUserControlPingResponse uint8 = 7

	// RtmpFrameTypeKey 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 RtmpAvcPacketTypeNalu RtmpHevcPacketTypeSeqHeader RtmpHevcPacketTypeNalu
	// 注意,按照标准文档上描述,PacketType还有可能为2:
	// 2: AVC end of sequence (lower level NALU sequence ender is not required or supported)
	//
	// 我自己遇到过在流结尾时,对端发送 27 02 00 00 00的情况(比如我们的使用wontcry.flv的单元测试,最后一个包)
	//
	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

	// RtmpSoundFormatAac 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 // 注意,视频的CodecId是后4位,音频是前4位
	RtmpAacPacketTypeSeqHeader       = 0
	RtmpAacPacketTypeRaw             = 1
)
View Source
const (
	// RtpPacketTypeAvcOrHevc
	//
	// 注意,一般情况下:
	// AVC  96
	// HEVC 98
	// AAC  97
	//
	// 但是我还遇到过:
	// AVC  105
	// HEVC 96
	// AAC  104
	//
	RtpPacketTypeAvcOrHevc = 96
	RtpPacketTypeAac       = 97
	RtpPacketTypeHevc      = 98
)
View Source
const (
	SessionTypeCustomizePub      SessionType = SessionProtocolCustomize<<8 | SessionBaseTypePub
	SessionTypeRtmpServerSession SessionType = SessionProtocolRtmp<<8 | SessionBaseTypePubSub
	SessionTypeRtmpPush          SessionType = SessionProtocolRtmp<<8 | SessionBaseTypePush
	SessionTypeRtmpPull          SessionType = SessionProtocolRtmp<<8 | SessionBaseTypePull
	SessionTypeRtspPub           SessionType = SessionProtocolRtsp<<8 | SessionBaseTypePub
	SessionTypeRtspSub           SessionType = SessionProtocolRtsp<<8 | SessionBaseTypeSub
	SessionTypeRtspPush          SessionType = SessionProtocolRtsp<<8 | SessionBaseTypePush
	SessionTypeRtspPull          SessionType = SessionProtocolRtsp<<8 | SessionBaseTypePull
	SessionTypeFlvSub            SessionType = SessionProtocolFlv<<8 | SessionBaseTypeSub
	SessionTypeFlvPull           SessionType = SessionProtocolFlv<<8 | SessionBaseTypePull
	SessionTypeTsSub             SessionType = SessionProtocolTs<<8 | SessionBaseTypeSub
	SessionTypePsPub             SessionType = SessionProtocolPs<<8 | SessionBaseTypePub

	SessionProtocolCustomize = 1
	SessionProtocolRtmp      = 2
	SessionProtocolRtsp      = 3
	SessionProtocolFlv       = 4
	SessionProtocolTs        = 5
	SessionProtocolPs        = 6

	SessionBaseTypePubSub = 1
	SessionBaseTypePub    = 2
	SessionBaseTypeSub    = 3
	SessionBaseTypePush   = 4
	SessionBaseTypePull   = 5

	SessionProtocolCustomizeStr = "CUSTOMIZE"
	SessionProtocolRtmpStr      = "RTMP"
	SessionProtocolRtspStr      = "RTSP"
	SessionProtocolFlvStr       = "FLV"
	SessionProtocolTsStr        = "TS"
	SessionProtocolPsStr        = "PS"

	SessionBaseTypePubSubStr = "PUBSUB"
	SessionBaseTypePubStr    = "PUB"
	SessionBaseTypeSubStr    = "SUB"
	SessionBaseTypePushStr   = "PUSH"
	SessionBaseTypePullStr   = "PULL"
)
View Source
const (
	UkPreCustomizePubSessionContext = SessionProtocolCustomizeStr + SessionBaseTypePubStr // "CUSTOMIZEPUB"
	UkPreRtmpServerSession          = SessionProtocolRtmpStr + SessionBaseTypePubSubStr   // "RTMPPUBSUB" // 两种可能,pub或者sub
	UkPreRtmpPushSession            = SessionProtocolRtmpStr + SessionBaseTypePushStr     // "RTMPPUSH"
	UkPreRtmpPullSession            = SessionProtocolRtmpStr + SessionBaseTypePullStr     // "RTMPPULL"
	UkPreRtspPubSession             = SessionProtocolRtspStr + SessionBaseTypePubStr      // "RTSPPUB"
	UkPreRtspSubSession             = SessionProtocolRtspStr + SessionBaseTypePubSubStr   // "RTSPSUB"
	UkPreRtspPushSession            = SessionProtocolRtspStr + SessionBaseTypePushStr     // "RTSPPUSH"
	UkPreRtspPullSession            = SessionProtocolRtspStr + SessionBaseTypePullStr     // "RTSPPULL"
	UkPreFlvSubSession              = SessionProtocolFlvStr + SessionBaseTypePubSubStr    // "FLVSUB"
	UkPreFlvPullSession             = SessionProtocolFlvStr + SessionBaseTypePullStr      // "FLVPULL"
	UkPreTsSubSession               = SessionProtocolTsStr + SessionBaseTypePubSubStr     // "TSSUB"
	UkPrePsPubSession               = SessionProtocolPsStr + SessionBaseTypePubStr        // "PSPUB"

	UkPreRtspServerCommandSession = "RTSPSRVCMD" // 这个不暴露给上层

	UkPreGroup              = "GROUP"
	UkPreHlsMuxer           = "HLSMUXER"
	UkPreRtmp2MpegtsRemuxer = "RTMP2MPEGTS"
)
View Source
const (
	DefaultRtmpPort  = 1935
	DefaultHttpPort  = 80
	DefaultHttpsPort = 443
	DefaultRtspPort  = 554
	DefaultRtmpsPort = 443
)
View Source
const ConfVersion = "v0.3.3"

ConfVersion lalserver的配置文件的版本号

View Source
const HttpApiVersion = "v0.3.3"

HttpApiVersion lalserver的HTTP-API功能的版本号

View Source
const HttpNotifyVersion = "v0.1.4"

HttpNotifyVersion lalserver的HTTP-Notify功能的版本号

View Source
const LalVersion = "v0.30.1"

LalVersion 整个lal工程的版本号。注意,该变量由外部脚本修改维护,不要手动在代码中修改

View Source
const (
	NetworkTcp = "tcp"
)
View Source
const WsMagicStr = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

Variables

View Source
var (
	ErrShortBuffer  = errors.New("lal: buffer too short")
	ErrFileNotExist = errors.New("lal: file not exist")
)
View Source
var (
	ErrAddrEmpty               = errors.New("lal.base: http server addr empty")
	ErrMultiRegisterForPattern = errors.New("lal.base: http server multiple registrations for pattern")

	ErrSessionNotStarted = errors.New("lal.base: session has not been started yet")

	ErrInvalidUrl = errors.New("lal.base: invalid url")
)
View Source
var (
	ErrAmfInvalidType = errors.New("lal.rtmp: invalid amf0 type")
	ErrAmfTooShort    = errors.New("lal.rtmp: too short to unmarshal amf0 data")
	ErrAmfNotExist    = errors.New("lal.rtmp: not exist")

	ErrRtmpShortBuffer   = errors.New("lal.rtmp: buffer too short")
	ErrRtmpUnexpectedMsg = errors.New("lal.rtmp: unexpected msg")
)
View Source
var (
	ErrRtsp                 = errors.New("lal.rtsp: fxxk")
	ErrRtspClosedByObserver = errors.New("lal.rtsp: close by observer")
)
View Source
var (
	ErrDupInStream = errors.New("lal.logic: in stream already exist at group")

	ErrSimpleAuthParamNotFound = errors.New("lal.logic: simple auth failed since url param lal_secret not found")
	ErrSimpleAuthFailed        = errors.New("lal.logic: simple auth failed since url param lal_secret invalid")
)
View Source
var (
	LalLibraryName = "lal"
	LalGithubRepo  = "github.com/forkiss/lal"
	LalGithubSite  = "https://github.com/forkiss/lal"
	LalDocSite     = "https://pengrl.com/lal"

	// LalFullInfo e.g. lal v0.12.3 (github.com/forkiss/lal)
	LalFullInfo = LalLibraryName + " " + LalVersion + " (" + LalGithubRepo + ")"

	// LalVersionDot e.g. 0.12.3
	LalVersionDot string

	// LalVersionComma e.g. 0,12,3
	LalVersionComma string
)
View Source
var (
	// LalRtmpHandshakeWaterMark 植入rtmp握手随机字符串中
	// e.g. lal v0.12.3 (github.com/forkiss/lal)
	LalRtmpHandshakeWaterMark string

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

	// LalRtmpPushSessionConnectVersion e.g. lal0.12.3
	LalRtmpPushSessionConnectVersion string

	// LalRtmpBuildMetadataEncoder e.g. lal0.12.3
	LalRtmpBuildMetadataEncoder string

	// LalHttpflvPullSessionUa e.g. lal/0.12.3
	LalHttpflvPullSessionUa string

	// LalHttpflvSubSessionServer e.g. lal0.12.3
	LalHttpflvSubSessionServer string

	// LalHlsM3u8Server e.g. lal0.12.3
	LalHlsM3u8Server string

	// LalHlsTsServer e.g. lal0.12.3
	LalHlsTsServer string

	// LalRtspOptionsResponseServer e.g. lal0.12.3
	LalRtspOptionsResponseServer string

	// LalHttptsSubSessionServer e.g. lal0.12.3
	LalHttptsSubSessionServer string

	// LalHttpApiServer e.g. lal0.12.3
	LalHttpApiServer string

	// LalRtspPullSessionUa e.g. lal/0.12.3
	LalRtspPullSessionUa string

	// LalPackSdp e.g. lal 0.12.3
	LalPackSdp string

	// LalRtspRealm e.g. lal
	LalRtspRealm string
)
View Source
var ErrAvc = errors.New("lal.avc: fxxk")
View Source
var ErrHevc = errors.New("lal.hevc: fxxk")
View Source
var ErrHls = errors.New("lal.hls: fxxk")
View Source
var ErrRtpRtcpShortBuffer = errors.New("lal.rtprtcp: buffer too short")
View Source
var ErrSamplingFrequencyIndex = errors.New("lal.aac: invalid sampling frequency index")
View Source
var ErrSdp = errors.New("lal.sdp: fxxk")

Functions

func GenUkCustomizePubSession

func GenUkCustomizePubSession() string

func GenUkFlvPullSession

func GenUkFlvPullSession() string

func GenUkFlvSubSession

func GenUkFlvSubSession() string

func GenUkGroup

func GenUkGroup() string

func GenUkHlsMuxer

func GenUkHlsMuxer() string

func GenUkPsPubSession

func GenUkPsPubSession() string

func GenUkRtmp2MpegtsRemuxer

func GenUkRtmp2MpegtsRemuxer() string

func GenUkRtmpPullSession

func GenUkRtmpPullSession() string

func GenUkRtmpPushSession

func GenUkRtmpPushSession() string

func GenUkRtmpServerSession

func GenUkRtmpServerSession() string

func GenUkRtspPubSession

func GenUkRtspPubSession() string

func GenUkRtspPullSession

func GenUkRtspPullSession() string

func GenUkRtspPushSession

func GenUkRtspPushSession() string

func GenUkRtspServerCommandSession

func GenUkRtspServerCommandSession() string

func GenUkRtspSubSession

func GenUkRtspSubSession() string

func GenUkTsSubSession

func GenUkTsSubSession() string

func GetWd

func GetWd() string

func LogoutStartInfo

func LogoutStartInfo()

func MakeWsFrameHeader

func MakeWsFrameHeader(wsHeader WsHeader) (buf []byte)

func NewErrAmfInvalidType

func NewErrAmfInvalidType(b byte) error

func NewErrRtmpShortBuffer

func NewErrRtmpShortBuffer(need, actual int, msg string) error

func OsExitAndWaitPressIfWindows

func OsExitAndWaitPressIfWindows(code int)

func ParseHttpRequest

func ParseHttpRequest(req *http.Request) string

ParseHttpRequest

@return 完整url

func ReadableNowTime

func ReadableNowTime() string

ReadableNowTime 当前时间,可读字符串形式

func RunSignalHandler

func RunSignalHandler(cb func())

RunSignalHandler 监听SIGUSR1和SIGUSR2信号并回调

TODO(chef): refactor 函数名应与SIGUSR1挂钩

func UpdateWebSocketHeader

func UpdateWebSocketHeader(secWebSocketKey string) []byte

Types

type ApiCtrlKickSessionReq

type ApiCtrlKickSessionReq struct {
	StreamName string `json:"stream_name"`
	SessionId  string `json:"session_id"`
}

type ApiCtrlStartRelayPull

type ApiCtrlStartRelayPull struct {
	HttpResponseBasic
	Data struct {
		StreamName string `json:"stream_name"`
		SessionId  string `json:"session_id"`
	} `json:"data"`
}

type ApiCtrlStartRelayPullReq

type ApiCtrlStartRelayPullReq struct {
	Url                      string `json:"url"`
	StreamName               string `json:"stream_name"`
	PullTimeoutMs            int    `json:"pull_timeout_ms"`
	PullRetryNum             int    `json:"pull_retry_num"`
	AutoStopPullAfterNoOutMs int    `json:"auto_stop_pull_after_no_out_ms"`
	RtspMode                 int    `json:"rtsp_mode"`
}

type ApiCtrlStartRtpPub

type ApiCtrlStartRtpPub struct {
	HttpResponseBasic
	Data struct {
		StreamName string `json:"stream_name"`
		SessionId  string `json:"session_id"`
		Port       int    `json:"port"`
	}
}

type ApiCtrlStartRtpPubReq

type ApiCtrlStartRtpPubReq struct {
	StreamName string `json:"stream_name"`
	Port       int    `json:"port"`
	TimeoutMs  int    `json:"timeout_ms"`
}

type ApiCtrlStopRelayPull

type ApiCtrlStopRelayPull struct {
	HttpResponseBasic
	Data struct {
		SessionId string `json:"session_id"`
	} `json:"data"`
}

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 {
	PayloadType AvPacketPt
	Timestamp   int64 // 如无特殊说明,此字段是Dts
	Pts         int64
	Payload     []byte
}

AvPacket

不同场景使用时,字段含义可能不同。 使用AvPacket的地方,应注明各字段的含义。

func (*AvPacket) DebugString

func (packet *AvPacket) DebugString() string

func (*AvPacket) IsAudio

func (packet *AvPacket) IsAudio() bool

func (*AvPacket) IsVideo

func (packet *AvPacket) IsVideo() bool

type AvPacketPt

type AvPacketPt int
const (
	AvPacketPtUnknown AvPacketPt = -1
	AvPacketPtAvc     AvPacketPt = 96 // h264
	AvPacketPtHevc    AvPacketPt = 98 // h265
	AvPacketPtAac     AvPacketPt = 97
)

func (AvPacketPt) ReadableString

func (a AvPacketPt) ReadableString() string

type AvPacketStreamAudioFormat

type AvPacketStreamAudioFormat int

type AvPacketStreamOption

type AvPacketStreamOption struct {
	AudioFormat AvPacketStreamAudioFormat
	VideoFormat AvPacketStreamVideoFormat // 视频流的格式,注意,不是指编码格式,而是编码格式确定后,流的格式
}

type AvPacketStreamVideoFormat

type AvPacketStreamVideoFormat int

type BasicHttpSubSession

type BasicHttpSubSession struct {
	BasicHttpSubSessionOption
	// contains filtered or unexported fields
}

func NewBasicHttpSubSession

func NewBasicHttpSubSession(option BasicHttpSubSessionOption) *BasicHttpSubSession

func (*BasicHttpSubSession) AppName

func (session *BasicHttpSubSession) AppName() string

func (*BasicHttpSubSession) Dispose

func (session *BasicHttpSubSession) Dispose() error

func (*BasicHttpSubSession) GetStat

func (session *BasicHttpSubSession) GetStat() StatSession

func (*BasicHttpSubSession) IsAlive

func (session *BasicHttpSubSession) IsAlive() (readAlive, writeAlive bool)

func (*BasicHttpSubSession) RawQuery

func (session *BasicHttpSubSession) RawQuery() string

func (*BasicHttpSubSession) RunLoop

func (session *BasicHttpSubSession) RunLoop() error

func (*BasicHttpSubSession) StreamName

func (session *BasicHttpSubSession) StreamName() string

func (*BasicHttpSubSession) UniqueKey

func (session *BasicHttpSubSession) UniqueKey() string

func (*BasicHttpSubSession) UpdateStat

func (session *BasicHttpSubSession) UpdateStat(intervalSec uint32)

func (*BasicHttpSubSession) Url

func (session *BasicHttpSubSession) Url() string

func (*BasicHttpSubSession) Write

func (session *BasicHttpSubSession) Write(b []byte)

func (*BasicHttpSubSession) WriteHttpResponseHeader

func (session *BasicHttpSubSession) WriteHttpResponseHeader(b []byte)

type BasicHttpSubSessionOption

type BasicHttpSubSessionOption struct {
	Conn          net.Conn
	ConnModOption connection.ModOption
	SessionType   SessionType
	UrlCtx        UrlContext
	IsWebSocket   bool
	WebSocketKey  string
}

type BasicSessionStat

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

BasicSessionStat

包含两部分功能: 1. 维护 StatSession 的一些静态信息 2. 计算带宽

计算带宽有两种方式,一种是通过外部的 connection.Connection 获取最新状态,一种是内部自己管理状态

func NewBasicSessionStat

func NewBasicSessionStat(sessionType SessionType, remoteAddr string) BasicSessionStat

NewBasicSessionStat

@param remoteAddr: 如果当前未知,填入""空字符串

func (*BasicSessionStat) AddReadBytes

func (s *BasicSessionStat) AddReadBytes(n int)

func (*BasicSessionStat) AddWriteBytes

func (s *BasicSessionStat) AddWriteBytes(n int)

func (*BasicSessionStat) BaseType

func (s *BasicSessionStat) BaseType() string

func (*BasicSessionStat) GetStat

func (s *BasicSessionStat) GetStat() StatSession

func (*BasicSessionStat) GetStatWithConn

func (s *BasicSessionStat) GetStatWithConn(conn IStatable) StatSession

func (*BasicSessionStat) IsAlive

func (s *BasicSessionStat) IsAlive() (readAlive, writeAlive bool)

func (*BasicSessionStat) IsAliveWitchConn

func (s *BasicSessionStat) IsAliveWitchConn(conn IStatable) (readAlive, writeAlive bool)

func (*BasicSessionStat) SetBaseType

func (s *BasicSessionStat) SetBaseType(baseType string)

func (*BasicSessionStat) SetRemoteAddr

func (s *BasicSessionStat) SetRemoteAddr(addr string)

func (*BasicSessionStat) UniqueKey

func (s *BasicSessionStat) UniqueKey() string

func (*BasicSessionStat) UpdateStat

func (s *BasicSessionStat) UpdateStat(intervalSec uint32)

func (*BasicSessionStat) UpdateStatWitchConn

func (s *BasicSessionStat) UpdateStatWitchConn(conn IStatable, intervalSec uint32)

type EventCommonInfo

type EventCommonInfo struct {
	ServerId string `json:"server_id"`
}

EventCommonInfo 所有事件共有的字段

type Handler

type Handler func(http.ResponseWriter, *http.Request)

type HlsMakeTsInfo

type HlsMakeTsInfo struct {
	EventCommonInfo

	Event          string  `json:"event"`
	StreamName     string  `json:"stream_name"`
	Cwd            string  `json:"cwd"`
	TsFile         string  `json:"ts_file"`
	LiveM3u8File   string  `json:"live_m3u8_file"`
	RecordM3u8File string  `json:"record_m3u8_file"`
	Id             int     `json:"id"`
	Duration       float64 `json:"duration"`
}

type HttpResponseBasic

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

HttpResponseBasic

TODO(chef): 因为ILalserver会直接使用这个接口,所以重命名为ApiResponseBasic

type HttpServerManager

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

func NewHttpServerManager

func NewHttpServerManager() *HttpServerManager

func (*HttpServerManager) AddListen

func (s *HttpServerManager) AddListen(addrCtx LocalAddrCtx, pattern string, handler Handler) error

AddListen

@param addrCtx IsHttps 是否为https

         注意,如果要为相同的路由同时绑定http和https,那么应该调用该函数两次,分别将该参数设置为true和false
Addr     监听地址,内部会为其建立监听
         http和https不能够使用相同的地址
         注意,多次调用,允许使用相同的地址绑定不同的`pattern`
CertFile
KeyFile
Network  如果为空默认为NetworkTcp="tcp"

@param pattern 必须以`/`开始,并以`/`结束

注意,如果是`/`,则在其他所有pattern都匹配失败后,做为兜底匹配成功
相同的pattern不能绑定不同的`handler`回调函数(显然,我们无法为相同的监听地址,相同的路径绑定多个回调函数)

func (*HttpServerManager) Dispose

func (s *HttpServerManager) Dispose() error

func (*HttpServerManager) RunLoop

func (s *HttpServerManager) RunLoop() error

type IAvPacketStream

type IAvPacketStream interface {
	// WithOption 修改配置项
	//
	WithOption(modOption func(option *AvPacketStreamOption))

	// FeedAudioSpecificConfig 传入音频AAC的初始化数据
	//
	// @param asc:
	//
	// AudioSpecificConfig。含义可参考 aac.AscContext, aac.MakeAscWithAdtsHeader 等内容。
	// 注意,调用 FeedAvPacket 传入AAC音频数据前,需要先调用 FeedAudioSpecificConfig。
	// FeedAudioSpecificConfig 在最开始总共调用一次,后面就可以一直调用 FeedAvPacket
	//
	FeedAudioSpecificConfig(asc []byte)

	// FeedAvPacket
	//
	// @param packet:
	//
	// PayloadType: 类型,支持avc(h264),hevc(h265),aac
	//
	// Timestamp: 时间戳,单位毫秒。注意,是累计递增值,不是单个包的duration时长。
	//
	// Payload: 音视频数据,格式如下
	//
	// 如果是音频AAC,格式是裸数据,不需要adts头。
	// 注意,调用 FeedAvPacket 传入AAC音频数据前,需要先调用 FeedAudioSpecificConfig。
	// FeedAudioSpecificConfig 在最开始总共调用一次,后面就可以一直调用 FeedAvPacket
	//
	// 如果是视频,支持Avcc和Annexb两种格式。
	// Avcc也即[<4字节长度 + nal>...],Annexb也即[<4字节start code 00 00 00 01 + nal>...]。
	// 注意,sps和pps也通过 FeedAvPacket 传入。sps和pps可以单独调用 FeedAvPacket,也可以sps+pps+I帧组合在一起调用一次 FeedAvPacket
	//
	FeedAvPacket(packet AvPacket)
}

type IClientSession

type IClientSession interface {
	IClientSessionLifecycle
	ISession
}

type IClientSessionLifecycle

type IClientSessionLifecycle interface {
	// Dispose 主动关闭session时调用
	//
	// 注意,只有Start(具体session的Start类型函数一般命令为Push和Pull)成功后的session才能调用,否则行为未定义
	//
	// Dispose可在任意协程内调用
	//
	// 注意,目前Dispose允许调用多次,但是未来可能不对该表现做保证
	//
	// Dispose后,调用Write函数将返回错误
	//
	// @return 可以通过返回值判断调用Dispose前,session是否已经被关闭了 TODO(chef) 这个返回值没有太大意义,后面可能会删掉
	//
	Dispose() error

	// WaitChan Start成功后,可使用这个channel来接收session结束的消息
	//
	// 注意,只有Start成功后的session才能调用,否则行为未定义
	//
	// 注意,目前WaitChan只会被通知一次,但是未来可能不对该表现做保证,业务方应该只关注第一次通知
	//
	// TODO(chef): 是否应该严格保证:获取到关闭消息后,后续不应该再有该session的回调上来
	//
	// @return 一般关闭有以下几种情况:
	//         - 对端关闭,此时error为EOF
	//         - 本端底层关闭,比如协议非法等,此时error为具体的错误值
	//         - 本端上层主动调用Dispose关闭,此时error为nil
	//
	WaitChan() <-chan error
}

type IObject

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

type IServerSession

type IServerSession interface {
	IServerSessionLifecycle
	ISession
}

type IServerSessionLifecycle

type IServerSessionLifecycle interface {

	// Dispose 主动关闭session时调用
	//
	// 如果是session通知业务方session已关闭(比如`RunLoop`函数返回错误),则不需要调用`Dispose` TODO(chef): review现状
	//
	Dispose() error
}

type ISession

type ISession interface {
	ISessionUrlContext
	IObject
	ISessionStat
}

type ISessionStat

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

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

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

ISessionStat

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

type ISessionUrlContext

type ISessionUrlContext interface {
	Url() string
	AppName() string
	StreamName() string
	RawQuery() string // 参数,也即 url param
}

ISessionUrlContext 获取和流地址相关的信息

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

type IStatable

type IStatable interface {
	GetStat() connection.Stat // TODO(chef): [refactor] 考虑为 nazanet.UdpConnection 实现这个接口
}

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 LocalAddrCtx

type LocalAddrCtx struct {
	IsHttps  bool
	Addr     string
	CertFile string
	KeyFile  string

	Network string
}

type LogDump

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

func NewLogDump

func NewLogDump(log nazalog.Logger, debugMaxNum int) LogDump

NewLogDump

@param debugMaxNum: 日志最小级别为debug时,使用debug打印日志次数的阈值

func (*LogDump) Outf

func (ld *LogDump) Outf(format string, v ...interface{})

Outf

调用之前需调用 ShouldDump 将 ShouldDump 独立出来的目的是避免不需要打印日志时, Outf 调用前构造实参的开销,比如 ld.Outf("hex=%s", hex.Dump(buf)) 这个hex.Dump调用

func (*LogDump) ShouldDump

func (ld *LogDump) ShouldDump() bool

type MergeWriter

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

MergeWriter 合并多个内存块,达到阈值后一次性将内存块数组返回给上层

注意,输入时的单个内存块,回调时不会出现拆分切割的情况

func NewMergeWriter

func NewMergeWriter(onWritev OnWritev, size int) *MergeWriter

NewMergeWriter

@param onWritev 回调缓存的1~n个内存块 @param size 回调阈值

func (*MergeWriter) Flush

func (w *MergeWriter) Flush()

Flush 强制将内部缓冲的数据全部回调排空

func (*MergeWriter) Write

func (w *MergeWriter) Write(b []byte)

Write

注意,函数调用结束后,`b`内存块会被内部持有

type OnAvPacketFunc

type OnAvPacketFunc func(packet *AvPacket)

type OnWritev

type OnWritev func(bs net.Buffers)

type PubStartInfo

type PubStartInfo struct {
	SessionEventCommonInfo
}

func Session2PubStartInfo

func Session2PubStartInfo(session ISession) PubStartInfo

type PubStopInfo

type PubStopInfo struct {
	SessionEventCommonInfo
}

func Session2PubStopInfo

func Session2PubStopInfo(session ISession) PubStopInfo

type PullStartInfo

type PullStartInfo struct {
	SessionEventCommonInfo
}

func Session2PullStartInfo

func Session2PullStartInfo(session ISession) PullStartInfo

type PullStopInfo

type PullStopInfo struct {
	SessionEventCommonInfo
}

func Session2PullStopInfo

func Session2PullStopInfo(session ISession) PullStopInfo

type RtmpConnectInfo

type RtmpConnectInfo struct {
	EventCommonInfo

	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 // dts, 经过计算得到的流上的绝对时间戳,单位毫秒
}

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) Dts

func (msg RtmpMsg) Dts() uint32

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

func (RtmpMsg) Pts

func (msg RtmpMsg) Pts() uint32

Pts

注意,只有视频才能调用该函数获取pts,音频的dts和pts都直接使用 RtmpMsg.Header.TimestampAbs

func (RtmpMsg) VideoCodecId

func (msg RtmpMsg) VideoCodecId() uint8

type ServerCtx

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

type SessionEventCommonInfo

type SessionEventCommonInfo struct {
	EventCommonInfo

	SessionId  string `json:"session_id"`
	Protocol   string `json:"protocol"`
	BaseType   string `json:"base_type"`
	RemoteAddr string `json:"remote_addr"`

	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"`
}

SessionEventCommonInfo session相关的事件的共有的字段

type SessionType

type SessionType int

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"` // TODO(chef): [opt] 增加数量字段,因为这里不一定全部放入
	StatPull    StatPull  `json:"pull"`
}

type StatPub

type StatPub struct {
	StatSession
}

func Session2StatPub

func Session2StatPub(session ISession) StatPub

type StatPull

type StatPull struct {
	StatSession
}

func Session2StatPull

func Session2StatPull(session ISession) StatPull

type StatSession

type StatSession struct {
	SessionId string `json:"session_id"`
	Protocol  string `json:"protocol"`
	BaseType  string `json:"base_type"`

	StartTime string `json:"start_time"`

	RemoteAddr string `json:"remote_addr"`

	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"`
	// contains filtered or unexported fields
}

type StatSub

type StatSub struct {
	StatSession
}

func Session2StatSub

func Session2StatSub(session ISession) StatSub

type SubStartInfo

type SubStartInfo struct {
	SessionEventCommonInfo
}

func Session2SubStartInfo

func Session2SubStartInfo(session ISession) SubStartInfo

type SubStopInfo

type SubStopInfo struct {
	SessionEventCommonInfo
}

func Session2SubStopInfo

func Session2SubStopInfo(session ISession) SubStopInfo

type UpdateInfo

type UpdateInfo struct {
	EventCommonInfo

	Groups []StatGroup `json:"groups"`
}

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
	// contains filtered or unexported fields
}

func ParseHttpflvUrl

func ParseHttpflvUrl(rawUrl string) (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)

ParseUrl

@param defaultPort: 注意,如果rawUrl中显示指定了端口,则该参数不生效

注意,如果设置为-1,内部依然会对常见协议(http, https, rtmp, rtsp)设置官方默认端口

func (*UrlContext) GetFileType

func (u *UrlContext) GetFileType() string

func (*UrlContext) GetFilenameWithoutType

func (u *UrlContext) GetFilenameWithoutType() string

type UrlPathContext

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

type WsHeader

type WsHeader struct {
	Fin    bool
	Rsv1   bool
	Rsv2   bool
	Rsv3   bool
	Opcode WsOpcode

	PayloadLength uint64

	Masked  bool
	MaskKey uint32
}

type WsOpcode

type WsOpcode = uint8

WsOpcode The WebSocket Protocol https://tools.ietf.org/html/rfc6455

0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-------+-+-------------+-------------------------------+ |F|R|R|R| opcode|M| Payload len | Extended payload length | |I|S|S|S| (4) |A| (7) | (16/64) | |N|V|V|V| |S| | (if payload len==126/127) | | |1|2|3| |K| | | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + | Extended payload length continued, if payload len == 127 | + - - - - - - - - - - - - - - - +-------------------------------+ | |Masking-key, if MASK set to 1 | +-------------------------------+-------------------------------+ | Masking-key (continued) | Payload Data | +-------------------------------- - - - - - - - - - - - - - - - + : Payload Data continued ... : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | Payload Data continued ... | +---------------------------------------------------------------+ opcode: * %x0 denotes a continuation frame * %x1 denotes a text frame * %x2 denotes a binary frame * %x3-7 are reserved for further non-control frames * %x8 denotes a connection close * %x9 denotes a ping * %xA denotes a pong * %xB-F are reserved for further control frames Payload length: 7 bits, 7+16 bits, or 7+64 bits Masking-key: 0 or 4 bytes mark 加密

for i := 0; i < datalen; i {
    m := markingkeys[i%4]
    data[i] = msg[i] ^ m
}
const (
	Wso_Continuous WsOpcode = iota //连续消息片断
	Wso_Text                       //文本消息片断,
	Wso_Binary                     //二进制消息片断,

	// Wso_Rsv3 非控制消息片断保留的操作码,
	Wso_Rsv3
	Wso_Rsv4
	Wso_Rsv5
	Wso_Rsv6
	Wso_Rsv7
	Wso_Close //连接关闭,
	Wso_Ping  //心跳检查的ping,
	Wso_Pong  //心跳检查的pong,

	// Wso_RsvB 为将来的控制消息片断的保留操作码
	Wso_RsvB
	Wso_RsvC
	Wso_RsvD
	Wso_RsvE
	Wso_RsvF
)

Jump to

Keyboard shortcuts

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