Documentation ¶
Index ¶
- Constants
- Variables
- func GenUkCustomizePubSession() string
- func GenUkFlvPullSession() string
- func GenUkFlvSubSession() string
- func GenUkGroup() string
- func GenUkHlsMuxer() string
- func GenUkRtmp2MpegtsRemuxer() string
- func GenUkRtmpPullSession() string
- func GenUkRtmpPushSession() string
- func GenUkRtmpServerSession() string
- func GenUkRtspPubSession() string
- func GenUkRtspPullSession() string
- func GenUkRtspPushSession() string
- func GenUkRtspServerCommandSession() string
- func GenUkRtspSubSession() string
- func GenUkTsSubSession() string
- func IsUseClosedConnectionError(err error) bool
- func LogoutStartInfo()
- func MakeWsFrameHeader(wsHeader WsHeader) (buf []byte)
- func NewErrAmfInvalidType(b byte) error
- func NewErrRtmpShortBuffer(need, actual int, msg string) error
- func OsExitAndWaitPressIfWindows(code int)
- func ParseHttpRequest(req *http.Request) string
- func ReadableNowTime() string
- func RunSignalHandler(cb func())
- func UpdateWebSocketHeader(secWebSocketKey string) []byte
- type ApiCtrlKickOutSession
- type ApiCtrlStartPullReq
- type ApiStatAllGroup
- type ApiStatGroup
- type ApiStatLalInfo
- type AvPacket
- type AvPacketPt
- type AvPacketStreamAudioFormat
- type AvPacketStreamOption
- type AvPacketStreamVideoFormat
- type Handler
- type HttpResponseBasic
- type HttpServerManager
- type HttpSubSession
- func (session *HttpSubSession) AppName() string
- func (session *HttpSubSession) Dispose() error
- func (session *HttpSubSession) GetStat() StatSession
- func (session *HttpSubSession) IsAlive() (readAlive, writeAlive bool)
- func (session *HttpSubSession) RawQuery() string
- func (session *HttpSubSession) RunLoop() error
- func (session *HttpSubSession) StreamName() string
- func (session *HttpSubSession) UniqueKey() string
- func (session *HttpSubSession) UpdateStat(intervalSec uint32)
- func (session *HttpSubSession) Url() string
- func (session *HttpSubSession) Write(b []byte)
- func (session *HttpSubSession) WriteHttpResponseHeader(b []byte)
- type HttpSubSessionOption
- type IAvPacketStream
- type IClientSession
- type IClientSessionLifecycle
- type IObject
- type IServerSession
- type IServerSessionLifecycle
- type ISessionStat
- type ISessionUrlContext
- type LalInfo
- type LocalAddrCtx
- type LogDump
- type MergeWriter
- type OnWritev
- type PubStartInfo
- type PubStopInfo
- type RtmpConnectInfo
- type RtmpHeader
- type RtmpMsg
- func (msg RtmpMsg) Clone() (ret RtmpMsg)
- func (msg RtmpMsg) Dts() uint32
- func (msg RtmpMsg) IsAacSeqHeader() bool
- func (msg RtmpMsg) IsAvcKeyNalu() bool
- func (msg RtmpMsg) IsAvcKeySeqHeader() bool
- func (msg RtmpMsg) IsHevcKeyNalu() bool
- func (msg RtmpMsg) IsHevcKeySeqHeader() bool
- func (msg RtmpMsg) IsVideoKeyNalu() bool
- func (msg RtmpMsg) IsVideoKeySeqHeader() bool
- func (msg RtmpMsg) Pts() uint32
- type ServerCtx
- type SessionEventCommonInfo
- type StatGroup
- type StatPub
- type StatPull
- type StatSession
- type StatSub
- type SubStartInfo
- type SubStopInfo
- type UpdateInfo
- type UrlContext
- type UrlPathContext
- type WsHeader
- type WsOpcode
Constants ¶
const ( AvPacketStreamAudioFormatUnknown AvPacketStreamAudioFormat = 0 AvPacketStreamAudioFormatRawAac AvPacketStreamAudioFormat = 1 AvPacketStreamVideoFormatUnknown AvPacketStreamVideoFormat = 0 AvPacketStreamVideoFormatAvcc AvPacketStreamVideoFormat = 1 AvPacketStreamVideoFormatAnnexb AvPacketStreamVideoFormat = 2 )
const ( ErrorCodeSucc = 0 DespSucc = "succ" ErrorCodeGroupNotFound = 1001 DespGroupNotFound = "group not found" ErrorCodeParamMissing = 1002 DespParamMissing = "param missing" ErrorCodeSessionNotFound = 1003 DespSessionNotFound = "session not found" )
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 )
const ( // RtpPacketTypeAvcOrHevc 注意,一般情况下,AVC使用96,AAC使用97,HEVC使用98 // 但是我还遇到过: // HEVC使用96 // AVC使用105 RtpPacketTypeAvcOrHevc = 96 RtpPacketTypeAac = 97 RtpPacketTypeHevc = 98 )
const ( // AudioCodecAac StatGroup.AudioCodec AudioCodecAac = "AAC" // VideoCodecAvc StatGroup.VideoCodec VideoCodecAvc = "H264" VideoCodecHevc = "H265" // ProtocolRtmp StatSession.Protocol ProtocolRtmp = "RTMP" ProtocolRtsp = "RTSP" ProtocolHttpflv = "HTTP-FLV" ProtocolHttpts = "HTTP-TS" )
const ( UkPreCustomizePubSessionContext = "CUSTOMIZEPUB" 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" UkPreRtmp2MpegtsRemuxer = "RTMP2MPEGTS" )
const ( DefaultRtmpPort = 1935 DefaultHttpPort = 80 DefaultHttpsPort = 443 DefaultRtspPort = 554 )
const HttpApiVersion = "v0.1.4"
const HttpNotifyVersion = "v0.1.0"
const LalVersion = "v0.28.0"
LalVersion 版本,该变量由外部脚本修改维护
const (
NetworkTcp = "tcp"
)
const WsMagicStr = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
Variables ¶
var ( ErrShortBuffer = errors.New("lal: buffer too short") ErrFileNotExist = errors.New("lal: file not exist") )
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") )
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") )
var ( ErrRtsp = errors.New("lal.rtsp: fxxk") ErrRtspClosedByObserver = errors.New("lal.rtsp: close by observer") )
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") )
var ( LalLibraryName = "lal" LalGithubRepo = "github.com/q191201771/lal" LalGithubSite = "https://github.com/q191201771/lal" LalDocSite = "https://pengrl.com/lal" // LalFullInfo e.g. lal v0.12.3 (github.com/q191201771/lal) LalFullInfo = LalLibraryName + " " + LalVersion + " (" + LalGithubRepo + ")" // LalVersionDot e.g. 0.12.3 LalVersionDot string // LalVersionComma e.g. 0,12,3 LalVersionComma string )
var ( // LalRtmpHandshakeWaterMark 植入rtmp握手随机字符串中 // e.g. lal v0.12.3 (github.com/q191201771/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 )
var DefaultApsOption = AvPacketStreamOption{ AudioFormat: AvPacketStreamAudioFormatRawAac, VideoFormat: AvPacketStreamVideoFormatAvcc, }
var ErrAvc = errors.New("lal.avc: fxxk")
var ErrHevc = errors.New("lal.hevc: fxxk")
var ErrHls = errors.New("lal.hls: fxxk")
var ErrRtpRtcpShortBuffer = errors.New("lal.rtprtcp: buffer too short")
var ErrSamplingFrequencyIndex = errors.New("lal.aac: invalid sampling frequency index")
var ErrSdp = errors.New("lal.sdp: fxxk")
var Log = nazalog.GetGlobalLogger()
Functions ¶
func GenUkCustomizePubSession ¶ added in v0.29.0
func GenUkCustomizePubSession() string
func GenUkFlvPullSession ¶ added in v0.23.0
func GenUkFlvPullSession() string
func GenUkFlvSubSession ¶ added in v0.23.0
func GenUkFlvSubSession() string
func GenUkGroup ¶ added in v0.23.0
func GenUkGroup() string
func GenUkHlsMuxer ¶ added in v0.23.0
func GenUkHlsMuxer() string
func GenUkRtmp2MpegtsRemuxer ¶ added in v0.28.0
func GenUkRtmp2MpegtsRemuxer() string
func GenUkRtmpPullSession ¶ added in v0.23.0
func GenUkRtmpPullSession() string
func GenUkRtmpPushSession ¶ added in v0.23.0
func GenUkRtmpPushSession() string
func GenUkRtmpServerSession ¶ added in v0.23.0
func GenUkRtmpServerSession() string
func GenUkRtspPubSession ¶ added in v0.23.0
func GenUkRtspPubSession() string
func GenUkRtspPullSession ¶ added in v0.23.0
func GenUkRtspPullSession() string
func GenUkRtspPushSession ¶ added in v0.23.0
func GenUkRtspPushSession() string
func GenUkRtspServerCommandSession ¶ added in v0.23.0
func GenUkRtspServerCommandSession() string
func GenUkRtspSubSession ¶ added in v0.23.0
func GenUkRtspSubSession() string
func GenUkTsSubSession ¶ added in v0.23.0
func GenUkTsSubSession() string
func IsUseClosedConnectionError ¶ added in v0.25.0
IsUseClosedConnectionError 当connection处于这些情况时,就不需要再Close了 TODO(chef): 临时放这 TODO(chef): 目前暂时没有使用,因为connection支持多次调用Close
func LogoutStartInfo ¶ added in v0.28.0
func LogoutStartInfo()
func MakeWsFrameHeader ¶ added in v0.23.0
func NewErrAmfInvalidType ¶ added in v0.27.0
func NewErrRtmpShortBuffer ¶ added in v0.27.0
func OsExitAndWaitPressIfWindows ¶ added in v0.23.0
func OsExitAndWaitPressIfWindows(code int)
func RunSignalHandler ¶ added in v0.26.0
func RunSignalHandler(cb func())
RunSignalHandler 监听SIGUSR1和SIGUSR2信号并回调
TODO(chef): refactor 函数名应与SIGUSR1挂钩
func UpdateWebSocketHeader ¶ added in v0.22.0
Types ¶
type ApiCtrlKickOutSession ¶ added in v0.23.0
type ApiCtrlStartPullReq ¶ added in v0.23.0
type ApiStatAllGroup ¶ added in v0.23.0
type ApiStatAllGroup struct { HttpResponseBasic Data struct { Groups []StatGroup `json:"groups"` } `json:"data"` }
type ApiStatGroup ¶ added in v0.23.0
type ApiStatGroup struct { HttpResponseBasic Data *StatGroup `json:"data"` }
type ApiStatLalInfo ¶ added in v0.23.0
type ApiStatLalInfo struct { HttpResponseBasic Data LalInfo `json:"data"` }
type AvPacket ¶ added in v0.23.0
type AvPacket struct { PayloadType AvPacketPt Timestamp int64 Payload []byte }
AvPacket
不同场景使用时,字段含义可能不同。 使用AvPacket的地方,应注明各字段的含义。
func (*AvPacket) DebugString ¶ added in v0.29.0
type AvPacketPt ¶ added in v0.23.0
type AvPacketPt int
const ( AvPacketPtUnknown AvPacketPt = -1 AvPacketPtAvc AvPacketPt = 96 // h264 AvPacketPtHevc AvPacketPt = 98 // h265 AvPacketPtAac AvPacketPt = 97 )
func (AvPacketPt) ReadableString ¶ added in v0.23.0
func (a AvPacketPt) ReadableString() string
type AvPacketStreamAudioFormat ¶ added in v0.29.0
type AvPacketStreamAudioFormat int
type AvPacketStreamOption ¶ added in v0.29.0
type AvPacketStreamOption struct { AudioFormat AvPacketStreamAudioFormat VideoFormat AvPacketStreamVideoFormat // 视频流的格式,注意,不是指编码格式,而是编码格式确定后,流的格式 }
type AvPacketStreamVideoFormat ¶ added in v0.29.0
type AvPacketStreamVideoFormat int
type HttpResponseBasic ¶ added in v0.23.0
type HttpServerManager ¶ added in v0.23.0
type HttpServerManager struct {
// contains filtered or unexported fields
}
func NewHttpServerManager ¶ added in v0.23.0
func NewHttpServerManager() *HttpServerManager
func (*HttpServerManager) AddListen ¶ added in v0.23.0
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 ¶ added in v0.23.0
func (s *HttpServerManager) Dispose() error
func (*HttpServerManager) RunLoop ¶ added in v0.23.0
func (s *HttpServerManager) RunLoop() error
type HttpSubSession ¶ added in v0.23.0
type HttpSubSession struct { HttpSubSessionOption // contains filtered or unexported fields }
func NewHttpSubSession ¶ added in v0.23.0
func NewHttpSubSession(option HttpSubSessionOption) *HttpSubSession
func (*HttpSubSession) AppName ¶ added in v0.23.0
func (session *HttpSubSession) AppName() string
func (*HttpSubSession) Dispose ¶ added in v0.23.0
func (session *HttpSubSession) Dispose() error
func (*HttpSubSession) GetStat ¶ added in v0.23.0
func (session *HttpSubSession) GetStat() StatSession
func (*HttpSubSession) IsAlive ¶ added in v0.23.0
func (session *HttpSubSession) IsAlive() (readAlive, writeAlive bool)
func (*HttpSubSession) RawQuery ¶ added in v0.23.0
func (session *HttpSubSession) RawQuery() string
func (*HttpSubSession) RunLoop ¶ added in v0.23.0
func (session *HttpSubSession) RunLoop() error
func (*HttpSubSession) StreamName ¶ added in v0.23.0
func (session *HttpSubSession) StreamName() string
func (*HttpSubSession) UniqueKey ¶ added in v0.23.0
func (session *HttpSubSession) UniqueKey() string
func (*HttpSubSession) UpdateStat ¶ added in v0.23.0
func (session *HttpSubSession) UpdateStat(intervalSec uint32)
func (*HttpSubSession) Url ¶ added in v0.23.0
func (session *HttpSubSession) Url() string
func (*HttpSubSession) Write ¶ added in v0.23.0
func (session *HttpSubSession) Write(b []byte)
func (*HttpSubSession) WriteHttpResponseHeader ¶ added in v0.23.0
func (session *HttpSubSession) WriteHttpResponseHeader(b []byte)
type HttpSubSessionOption ¶ added in v0.23.0
type HttpSubSessionOption struct { Conn net.Conn ConnModOption connection.ModOption Uk string // unique key Protocol string UrlCtx UrlContext IsWebSocket bool WebSocketKey string }
type IAvPacketStream ¶ added in v0.29.0
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 ¶ added in v0.20.0
type IClientSession interface { IClientSessionLifecycle ISessionUrlContext IObject ISessionStat }
type IClientSessionLifecycle ¶ added in v0.20.0
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 ¶ added in v0.20.0
type IObject interface { // UniqueKey // // 对象的全局唯一标识 // UniqueKey() string }
type IServerSession ¶ added in v0.20.0
type IServerSession interface { IServerSessionLifecycle ISessionUrlContext IObject ISessionStat }
type IServerSessionLifecycle ¶ added in v0.20.0
type IServerSessionLifecycle interface { // Dispose 主动关闭session时调用 // // 如果是session通知业务方session已关闭(比如`RunLoop`函数返回错误),则不需要调用`Dispose` TODO(chef): review现状 // Dispose() error }
type ISessionStat ¶ added in v0.18.0
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 ¶ added in v0.23.0
type ISessionUrlContext interface { Url() string AppName() string StreamName() string RawQuery() string }
ISessionUrlContext 获取和流地址相关的信息
调用约束:对于Client类型的Session,调用Start函数并返回成功后才能调用,否则行为未定义
type LocalAddrCtx ¶ added in v0.23.0
type LogDump ¶ added in v0.28.0
type LogDump struct {
// contains filtered or unexported fields
}
func (*LogDump) Outf ¶ added in v0.28.0
Outf
调用之前需调用 ShouldDump 将 ShouldDump 独立出来的目的是避免不需要打印日志时, Outf 调用前构造实参的开销,比如 ld.Outf("hex=%s", hex.Dump(buf)) 这个hex.Dump调用
func (*LogDump) ShouldDump ¶ added in v0.28.0
type MergeWriter ¶ added in v0.26.0
type MergeWriter struct {
// contains filtered or unexported fields
}
MergeWriter 合并多个内存块,达到阈值后一次性将内存块数组返回给上层
注意,输入时的单个内存块,回调时不会出现拆分切割的情况
func NewMergeWriter ¶ added in v0.26.0
func NewMergeWriter(onWritev OnWritev, size int) *MergeWriter
NewMergeWriter
@param onWritev 回调缓存的1~n个内存块 @param size 回调阈值
func (*MergeWriter) Write ¶ added in v0.26.0
func (w *MergeWriter) Write(b []byte)
Write
注意,函数调用结束后,`b`内存块会被内部持有
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.23.0
type RtmpHeader ¶ added in v0.23.0
type RtmpMsg ¶ added in v0.23.0
type RtmpMsg struct { Header RtmpHeader Payload []byte // Payload不包含Header内容。如果需要将RtmpMsg序列化成RTMP chunk,可调用rtmp.ChunkDivider相关的函数 }
func (RtmpMsg) IsAacSeqHeader ¶ added in v0.23.0
func (RtmpMsg) IsAvcKeyNalu ¶ added in v0.23.0
func (RtmpMsg) IsAvcKeySeqHeader ¶ added in v0.23.0
func (RtmpMsg) IsHevcKeyNalu ¶ added in v0.23.0
func (RtmpMsg) IsHevcKeySeqHeader ¶ added in v0.23.0
func (RtmpMsg) IsVideoKeyNalu ¶ added in v0.23.0
func (RtmpMsg) IsVideoKeySeqHeader ¶ added in v0.23.0
type ServerCtx ¶ added in v0.23.0
type ServerCtx struct {
// contains filtered or unexported fields
}
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"` // TODO(chef): [opt] 增加数量字段,因为这里不一定全部放入 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 UpdateInfo ¶ added in v0.17.0
type UrlContext ¶ added in v0.23.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 // contains filtered or unexported fields }
func ParseHttpflvUrl ¶ added in v0.23.0
func ParseHttpflvUrl(rawUrl string) (ctx UrlContext, err error)
func ParseRtmpUrl ¶ added in v0.23.0
func ParseRtmpUrl(rawUrl string) (ctx UrlContext, err error)
func ParseRtspUrl ¶ added in v0.23.0
func ParseRtspUrl(rawUrl string) (ctx UrlContext, err error)
func ParseUrl ¶ added in v0.23.0
func ParseUrl(rawUrl string, defaultPort int) (ctx UrlContext, err error)
ParseUrl
@param defaultPort: 注意,如果rawUrl中显示指定了端口,则该参数不生效
注意,如果设置为-1,内部依然会对常见协议(http, https, rtmp, rtsp)设置官方默认端口
func (*UrlContext) GetFileType ¶ added in v0.27.0
func (u *UrlContext) GetFileType() string
func (*UrlContext) GetFilenameWithoutType ¶ added in v0.27.0
func (u *UrlContext) GetFilenameWithoutType() string
type UrlPathContext ¶ added in v0.23.0
type WsOpcode ¶ added in v0.22.0
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 }