rtsp_base

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package rtsp_base *

  • @Author: W.w.
  • @File: base
  • @Date: 2023-08-09 18:52
  • @Description:

Index

Constants

View Source
const (
	WAIT_ANSWER_LONG_TIME = time.Second * 40
	MAX_TALK_LONG_TIME    = time.Hour * 24
)
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
	SessionTypeHlsSub            SessionType = SessionProtocolHls<<8 | SessionBaseTypeSub
	SessionTypeWebrtcSub         SessionType = SessionProtocolWebrtc<<8 | SessionBaseTypeSub
	SessionTypeWebrtcPub         SessionType = SessionProtocolWebrtc<<8 | SessionBaseTypePub
	SessionTypeWebrtc            SessionType = SessionProtocolWebrtc<<8 | SessionBaseTypePubSub
	SessionTypeSip               SessionType = SessionProtocolSip<<8 | SessionBaseTypePubSub
	SessionTypeSipPush           SessionType = SessionProtocolSip<<8 | SessionBaseTypePush

	SessionProtocolCustomize = 1
	SessionProtocolRtmp      = 2
	SessionProtocolRtsp      = 3
	SessionProtocolFlv       = 4
	SessionProtocolTs        = 5
	SessionProtocolPs        = 6
	SessionProtocolHls       = 7
	SessionProtocolWebrtc    = 8
	SessionProtocolSip       = 9

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

	SessionProtocolCustomizeStr = "customize"
	SessionProtocolRtmpStr      = "rtmp"
	SessionProtocolRtspStr      = "rtsp"
	SessionProtocolFlvStr       = "flv"
	SessionProtocolTsStr        = "ts"
	SessionProtocolPsStr        = "ps"
	SessionProtocolHlsStr       = "hls"
	SessionProtocolWebrtcStr    = "webrtc"
	SessionProtocolSipStr       = "sip"

	SessionBaseTypePubSubStr = "pub_sub"
	SessionBaseTypePubStr    = "pub"
	SessionBaseTypeSubStr    = "sub"
	SessionBaseTypePushStr   = "push"
	SessionBaseTypePullStr   = "pull"
)
View Source
const (
	// AudioCodecAac StatGroup.AudioCodec
	AudioCodecAac   = "AAC"
	AudioCodecG711U = "PCMU"
	AudioCodecG711A = "PCMA"

	// VideoCodecAvc StatGroup.VideoCodec
	VideoCodecAvc  = "H264"
	VideoCodecHevc = "H265"
)
View Source
const (
	UkPreCustomizePubSessionContext = SessionProtocolCustomizeStr + "-" + SessionBaseTypePubStr
	UkPreRtmpServerSession          = SessionProtocolRtmpStr + "-" + SessionBaseTypePubSubStr
	UkPreRtmpPushSession            = SessionProtocolRtmpStr + "-" + SessionBaseTypePushStr
	UkPreRtmpPullSession            = SessionProtocolRtmpStr + "-" + SessionBaseTypePullStr
	UkPreRtspPubSession             = SessionProtocolRtspStr + "-" + SessionBaseTypePubStr
	UkPreRtspSubSession             = SessionProtocolRtspStr + "-" + SessionBaseTypePubSubStr
	UkPreRtspPushSession            = SessionProtocolRtspStr + "-" + SessionBaseTypePushStr
	UkPreRtspPullSession            = SessionProtocolRtspStr + "-" + SessionBaseTypePullStr
	UkPreFlvSubSession              = SessionProtocolFlvStr + "-" + SessionBaseTypePubSubStr
	UkPreFlvPullSession             = SessionProtocolFlvStr + "-" + SessionBaseTypePullStr
	UkPreTsSubSession               = SessionProtocolTsStr + "-" + SessionBaseTypePubSubStr
	UkPrePsPubSession               = SessionProtocolPsStr + "-" + SessionBaseTypePubStr
	UkPreHlsSubSession              = SessionProtocolHlsStr + "-" + SessionBaseTypeSubStr
	UkPreWebrtcSubSession           = SessionProtocolWebrtcStr + "-" + SessionBaseTypeSubStr
	UkPreWebrtcPubSession           = SessionProtocolWebrtcStr + "-" + SessionBaseTypePubStr
	UkPreWebrtcSession              = SessionProtocolWebrtcStr + "-" + SessionBaseTypePubSubStr
	UkPreSipSession                 = SessionProtocolSipStr + "-" + SessionBaseTypePubSubStr
	UkPreSipPushSession             = SessionProtocolSipStr + "-" + SessionBaseTypePushStr

	UkPreRtspServerCommandSession = "rtsp-session" // 这个不暴露给上层

	UkPreGroup              = "group"
	UkPreHlsMuxer           = "hls-muxer"
	UkPreRtmp2MpegtsRemuxer = "rtmp-2-mpegts"
)

Variables

View Source
var (
	ErrShortBuffer       = errors.New("buffer too short")
	ErrSessionNotStarted = errors.New("session has not been started yet")
)
View Source
var (
	ErrRtsp                     = errors.New("rtsp: error")
	ErrRtspClosedByObserver     = errors.New("rtsp: close by observer")
	ErrRtspNotFound             = errors.New("rtsp: 404 not found")
	ErrRtspNotAcceptable        = errors.New("rtsp: 406 Not Acceptable")
	ErrRtspBadRequest           = errors.New("rtsp: 400 Bad Request")
	ErrRtspUnsupportedTransport = errors.New("rtsp: unsupported Transport")
	ErrRtspSendResponseFailed   = errors.New("rtsp: send response failed")
)
View Source
var (
	ErrAmfInvalidType = errors.New("rtmp: invalid amf0 type")
	ErrAmfTooShort    = errors.New("rtmp: too short to unmarshal amf0 data")
	ErrAmfNotExist    = errors.New("rtmp: not exist")

	ErrRtmpShortBuffer   = errors.New("rtmp: buffer too short")
	ErrRtmpUnexpectedMsg = errors.New("rtmp: unexpected msg")
)
View Source
var (
	ErrDupInStream      = errors.New("in stream already exist at group")
	ErrDisposedInStream = errors.New("in stream already disposed")
)
View Source
var ErrAvc = errors.New("avc: error")
View Source
var ErrHevc = errors.New("hevc: error")
View Source
var (
	ErrInvalidUrl = errors.New("base: invalid url")
)
View Source
var ErrSamplingFrequencyIndex = errors.New("aac: invalid sampling frequency index")
View Source
var ErrSdp = errors.New("sdp: error")
View Source
var GAvailUdpConnPool = netUdp.NewAvailUdpConnPool("", 47000, 49000)
View Source
var GRtspAvailUdpConnPool = netUdp.NewAvailUdpConnPool("", 44500, 45000)

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 GenUkHlsSubSession

func GenUkHlsSubSession() 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 GenUkRtspServerSession

func GenUkRtspServerSession() string

func GenUkRtspSubSession

func GenUkRtspSubSession() string

func GenUkSipPushSession

func GenUkSipPushSession() string

func GenUkSipSession

func GenUkSipSession() string

func GenUkTsSubSession

func GenUkTsSubSession() string

func GenUkWebrtcPubSession

func GenUkWebrtcPubSession() string

func GenUkWebrtcSession

func GenUkWebrtcSession() string

func GenUkWebrtcSubSession

func GenUkWebrtcSubSession() string

func NewErrAmfInvalidType

func NewErrAmfInvalidType(b byte) error

func NewErrRtmpShortBuffer

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

Types

type BasicSessionStat

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

BasicSessionStat *****************************************************

  • @Description: 包含两部分功能: 1. 维护 StatSession 的一些静态信息 2. 计算带宽
  • 计算带宽有两种方式,一种是通过外部的 netUtils.Connection 获取最新状态,一种是内部自己管理状态 *****************************************************

func NewBasicSessionStat

func NewBasicSessionStat(sessionType SessionType, remoteAddr string) BasicSessionStat

NewBasicSessionStat *****************************************************

  • @Description:
  • @param sessionType
  • @param remoteAddr 如果当前未知,填入""空字符串
  • @return BasicSessionStat *****************************************************

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 IAVObserver

type IAVObserver interface {
	OnAudioPacket(pkt media.AvPacket)
	OnVideoPacket(pkt media.AvPacket)
}

type IBaseSession

type IBaseSession interface {
	UniqueKey() string
}

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 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
	IBaseSession
	ISessionStat
}

type ISessionStat

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

	// GetStat
	//
	// 获取session状态
	//
	// @return 注意,结构体中的`BitrateKbits`的值由最近一次`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() netUtils.Stat
}

type SessionType

type SessionType int

type StatGroup

type StatGroup struct {
	StreamName  string    `json:"stream_name"`
	AppName     string    `json:"app_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
}

type StatPull

type StatPull struct {
	StatSession
}

type StatSession

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

	StartTime string `json:"start_time"`

	ReadBytesSum      uint64 `json:"read_bytes_sum"`
	WroteBytesSum     uint64 `json:"wrote_bytes_sum"`
	BitrateKbits      int    `json:"bitrate_kbits"`
	ReadBitrateKbits  int    `json:"read_bitrate_kbits"`
	WriteBitrateKbits int    `json:"write_bitrate_kbits"`
	// contains filtered or unexported fields
}

type StatSub

type StatSub struct {
	StatSession
}

Jump to

Keyboard shortcuts

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