Documentation ¶
Index ¶
- Constants
- Variables
- func CompareSeq(a, b uint16) int
- func IsAvcBoundary(pkt RtpPacket) bool
- func IsAvcHevcBoundary(pkt RtpPacket, pt base.AvPacketPt) bool
- func IsHevcBoundary(pkt RtpPacket) bool
- func MswLsw2Ntp(msw, lsw uint64) uint64
- func MswLsw2UnixNano(msw, lsw uint64) uint64
- func Ntp2UnixNano(v uint64) uint64
- func SubSeq(a, b uint16) int
- type IRtpPackerPayload
- type IRtpUnpackContainer
- type IRtpUnpacker
- type IRtpUnpackerProtocol
- type ModRtpPackerOption
- type ModRtpPackerPayloadAvcHevcOption
- type OnAvPacket
- type Rr
- type RrProducer
- type RtcpHeader
- type RtpHeader
- type RtpPacker
- type RtpPackerOption
- type RtpPackerPayloadAac
- type RtpPackerPayloadAvcHevc
- func NewRtpPackerPayloadAvc(modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
- func NewRtpPackerPayloadAvcHevc(payloadType base.AvPacketPt, modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
- func NewRtpPackerPayloadHevc(modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
- type RtpPackerPayloadAvcHevcOption
- type RtpPackerPayloadAvcHevcType
- type RtpPackerPayloadPcm
- type RtpPacket
- type RtpPacketList
- func (l *RtpPacketList) DebugString() string
- func (l *RtpPacketList) Full() bool
- func (l *RtpPacketList) InitMaxSize(maxSize int)
- func (l *RtpPacketList) Insert(pkt RtpPacket)
- func (l *RtpPacketList) IsFirstSequential() bool
- func (l *RtpPacketList) IsStale(seq uint16) bool
- func (l *RtpPacketList) PeekFirst() RtpPacket
- func (l *RtpPacketList) PopFirst() RtpPacket
- func (l *RtpPacketList) Reset()
- func (l *RtpPacketList) SetDoneSeq(seq uint16)
- type RtpPacketListItem
- type RtpUnpackContainer
- type RtpUnpackerAac
- type RtpUnpackerAvcHevc
- type RtpUnpackerRaw
- type Sr
Constants ¶
const ( RtcpPacketTypeSr = 200 // 0xc8 Sender Report RtcpPacketTypeRr = 201 // 0xc9 Receiver Report RtcpPacketTypeApp = 204 RtcpHeaderLength = 4 RtcpVersion = 2 )
const ( NaluTypeAvcSingleMax = 23 NaluTypeAvcStapa = 24 // one packet, multiple nals NaluTypeAvcFua = 28 NaluTypeHevcAp = 48 NaluTypeHevcFua = 49 )
const ( RtpPackerPayloadAvcHevcTypeNalu RtpPackerPayloadAvcHevcType = 1 RtpPackerPayloadAvcHevcTypeAvcc = 2 RtpPackerPayloadAvcHevcTypeAnnexb = 3 )
const ( RtpFixedHeaderLength = 12 DefaultRtpVersion = 2 )
const ( PositionTypeSingle uint8 = 1 PositionTypeFuaStart uint8 = 2 PositionTypeFuaMiddle uint8 = 3 PositionTypeFuaEnd uint8 = 4 PositionTypeStapa uint8 = 5 // 1个rtp包包含多个帧,目前供h264的stapa使用 PositionTypeAp uint8 = 6 // 1个rtp包包含多个帧,目前供h265的ap使用 )
const MaxRtpRtcpPacketSize = 1500
Variables ¶
var Log = nazalog.GetGlobalLogger()
Functions ¶
func IsAvcBoundary ¶ added in v0.24.0
func IsAvcHevcBoundary ¶ added in v0.24.0
func IsAvcHevcBoundary(pkt RtpPacket, pt base.AvPacketPt) bool
IsAvcHevcBoundary
@param pt: 取值范围为AvPacketPtAvc或AvPacketPtHevc,否则直接返回false
func IsHevcBoundary ¶ added in v0.24.0
func MswLsw2Ntp ¶ added in v0.23.0
MswLsw2Ntp msw是ntp的高32位,lsw是ntp的低32位
func MswLsw2UnixNano ¶ added in v0.23.0
MswLsw2UnixNano 将ntp时间戳(高32位低32位分开的形式)转换为Unix时间戳
func Ntp2UnixNano ¶ added in v0.23.0
Ntp2UnixNano 将ntp时间戳转换为Unix时间戳,Unix时间戳单位是纳秒
Types ¶
type IRtpPackerPayload ¶ added in v0.24.0
type IRtpUnpackContainer ¶ added in v0.23.0
type IRtpUnpackContainer interface {
Feed(pkt RtpPacket)
}
type IRtpUnpacker ¶ added in v0.23.0
type IRtpUnpacker interface { IRtpUnpackContainer }
func DefaultRtpUnpackerFactory ¶ added in v0.23.0
func DefaultRtpUnpackerFactory(payloadType base.AvPacketPt, clockRate int, maxSize int, onAvPacket OnAvPacket) IRtpUnpacker
DefaultRtpUnpackerFactory 目前支持AVC,HEVC和AAC MPEG4-GENERIC,业务方也可以自己实现IRtpUnpackerProtocol,甚至是IRtpUnpackContainer
type IRtpUnpackerProtocol ¶ added in v0.23.0
type IRtpUnpackerProtocol interface { // CalcPositionIfNeeded 计算rtp包处于帧中的位置 CalcPositionIfNeeded(pkt *RtpPacket) // TryUnpackOne 尝试合成一个完整帧 // // 从当前队列的第一个包开始合成 // 如果一个rtp包对应一个完整帧,则合成一帧 // 如果一个rtp包对应多个完整帧,则合成多帧 // 如果多个rtp包对应一个完整帧,则尝试合成一帧 // // @return unpackedFlag 本次调用是否成功合成 // @return unpackedSeq 如果成功合成,合成使用的最后一个seq号;如果失败,则为0 TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16) }
type ModRtpPackerOption ¶ added in v0.24.0
type ModRtpPackerOption func(option *RtpPackerOption)
type ModRtpPackerPayloadAvcHevcOption ¶ added in v0.24.0
type ModRtpPackerPayloadAvcHevcOption func(option *RtpPackerPayloadAvcHevcOption)
type OnAvPacket ¶ added in v0.23.0
OnAvPacket
@param pkt:
pkt.Timestamp: RTP包头中的时间戳(pts)经过clockrate换算后的时间戳,单位毫秒。 注意,不支持带B帧的视频流,pts和dts永远相同。 pkt.PayloadType: base.AvPacketPTXXX。 pkt.Payload: AAC: 返回的是raw frame,一个AvPacket只包含一帧。 引用的是接收到的RTP包中的内存块。 AVC或HEVC: AVCC格式,每个NAL前包含4字节NAL的长度。 新申请的内存块,回调结束后,内部不再使用该内存块。 注意,这一层只做RTP包的合并,假如sps和pps是两个RTP single包,则合并结果为两个AvPacket, 假如sps和pps是一个stapA包,则合并结果为一个AvPacket。
type RrProducer ¶ added in v0.23.0
type RrProducer struct {
// contains filtered or unexported fields
}
func NewRrProducer ¶ added in v0.23.0
func NewRrProducer(clockRate int) *RrProducer
func (*RrProducer) FeedRtpPacket ¶ added in v0.23.0
func (r *RrProducer) FeedRtpPacket(seq uint16)
FeedRtpPacket 每次收到rtp包,都将seq序号传入这个函数
func (*RrProducer) Produce ¶ added in v0.23.0
func (r *RrProducer) Produce(lsr uint32) []byte
Produce 收到sr包时,产生rr包
@param lsr: 从sr包中获取,见func SR.GetMiddleNtp @return: rr包的二进制数据
type RtcpHeader ¶ added in v0.23.0
type RtcpHeader struct { Version uint8 // 2b Padding uint8 // 1b CountOrFormat uint8 // 5b PacketType uint8 // 8b Length uint16 // 16b, whole packet byte length = (Length+1) * 4 }
func ParseRtcpHeader ¶ added in v0.23.0
func ParseRtcpHeader(b []byte) RtcpHeader
func (*RtcpHeader) PackTo ¶ added in v0.23.0
func (r *RtcpHeader) PackTo(out []byte)
PackTo @param out 传出参数,注意,调用方保证长度>=4
type RtpHeader ¶ added in v0.23.0
type RtpHeader struct { Version uint8 // 2b * Padding uint8 // 1b Extension uint8 // 1 CsrcCount uint8 // 4b Mark uint8 // 1b * PacketType uint8 // 7b Seq uint16 // 16b ** Timestamp uint32 // 32b **** samples Ssrc uint32 // 32b **** Synchronization source Csrc []uint32 ExtensionProfile uint16 // Extensions 包含了整个extension,引用的是包体的内存 // // TODO(chef): [opt] 后续考虑解析extension中的单独个item存储至结构体中 202211 Extensions []byte // contains filtered or unexported fields }
func MakeDefaultRtpHeader ¶ added in v0.24.0
func MakeDefaultRtpHeader() RtpHeader
func ParseRtpHeader ¶ added in v0.23.0
type RtpPacker ¶ added in v0.24.0
type RtpPacker struct {
// contains filtered or unexported fields
}
func NewRtpPacker ¶ added in v0.24.0
func NewRtpPacker(payloadPacker IRtpPackerPayload, clockRate int, ssrc uint32, modOptions ...ModRtpPackerOption) *RtpPacker
type RtpPackerOption ¶ added in v0.24.0
type RtpPackerPayloadAac ¶ added in v0.24.0
type RtpPackerPayloadAac struct { }
func NewRtpPackerPayloadAac ¶ added in v0.24.0
func NewRtpPackerPayloadAac() *RtpPackerPayloadAac
type RtpPackerPayloadAvcHevc ¶ added in v0.24.0
type RtpPackerPayloadAvcHevc struct {
// contains filtered or unexported fields
}
func NewRtpPackerPayloadAvc ¶ added in v0.24.0
func NewRtpPackerPayloadAvc(modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
func NewRtpPackerPayloadAvcHevc ¶ added in v0.24.0
func NewRtpPackerPayloadAvcHevc(payloadType base.AvPacketPt, modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
func NewRtpPackerPayloadHevc ¶ added in v0.24.0
func NewRtpPackerPayloadHevc(modOptions ...ModRtpPackerPayloadAvcHevcOption) *RtpPackerPayloadAvcHevc
type RtpPackerPayloadAvcHevcOption ¶ added in v0.24.0
type RtpPackerPayloadAvcHevcOption struct {
Typ RtpPackerPayloadAvcHevcType
}
type RtpPackerPayloadAvcHevcType ¶ added in v0.24.0
type RtpPackerPayloadAvcHevcType int
type RtpPackerPayloadPcm ¶ added in v0.34.3
type RtpPackerPayloadPcm struct { }
func NewRtpPackerPayloadPcm ¶ added in v0.34.3
func NewRtpPackerPayloadPcm() *RtpPackerPayloadPcm
type RtpPacket ¶ added in v0.23.0
type RtpPacket struct { Header RtpHeader Raw []byte // 包含header内存 // contains filtered or unexported fields }
func MakeRtpPacket ¶ added in v0.24.0
func ParseRtpPacket ¶ added in v0.23.0
ParseRtpPacket 函数调用结束后,不持有参数<b>的内存块
type RtpPacketList ¶ added in v0.23.0
type RtpPacketList struct { // TODO(chef): [refactor] 隐藏这两个变量的访问权限 202207 Head RtpPacketListItem // 哨兵,自身不存放rtp包,第一个rtp包存在在head.next中 Size int // 实际元素个数 // contains filtered or unexported fields }
RtpPacketList rtp packet的有序链表,前面的seq小于后面的seq
为什么不用红黑树等查找性能更高的有序kv结构? 第一,容器有最大值,这个数量级用啥容器都差不多, 第二,插入时,99.99%的seq号是当前最大号附近的,遍历找就可以了, 注意,这个链表并不是一个定长容器,当数据有序时,容器内缓存的数据是一个帧的数据。
func (*RtpPacketList) DebugString ¶ added in v0.31.0
func (l *RtpPacketList) DebugString() string
func (*RtpPacketList) InitMaxSize ¶ added in v0.31.0
func (l *RtpPacketList) InitMaxSize(maxSize int)
InitMaxSize 设置容器最大容量
func (*RtpPacketList) Insert ¶ added in v0.31.0
func (l *RtpPacketList) Insert(pkt RtpPacket)
Insert 插入有序链表,并去重
func (*RtpPacketList) IsFirstSequential ¶ added in v0.31.0
func (l *RtpPacketList) IsFirstSequential() bool
IsFirstSequential 第一个包是否是需要的(与之前已处理的是连续的)
func (*RtpPacketList) IsStale ¶ added in v0.31.0
func (l *RtpPacketList) IsStale(seq uint16) bool
IsStale 是否过期
func (*RtpPacketList) PeekFirst ¶ added in v0.31.0
func (l *RtpPacketList) PeekFirst() RtpPacket
PeekFirst 查看第一个包。注意,调用方保证容器不为空时调用
func (*RtpPacketList) PopFirst ¶ added in v0.31.0
func (l *RtpPacketList) PopFirst() RtpPacket
PopFirst 弹出第一个包。注意,调用方保证容器不为空时调用
func (*RtpPacketList) Reset ¶ added in v0.31.0
func (l *RtpPacketList) Reset()
func (*RtpPacketList) SetDoneSeq ¶ added in v0.31.0
func (l *RtpPacketList) SetDoneSeq(seq uint16)
SetDoneSeq 设置已处理的包序号,比如已经成功合成了,或者主动丢弃到该位置结束丢弃了
type RtpPacketListItem ¶ added in v0.23.0
type RtpPacketListItem struct { Packet RtpPacket Next *RtpPacketListItem }
type RtpUnpackContainer ¶ added in v0.23.0
type RtpUnpackContainer struct {
// contains filtered or unexported fields
}
func NewRtpUnpackContainer ¶ added in v0.23.0
func NewRtpUnpackContainer(maxSize int, unpackerProtocol IRtpUnpackerProtocol) *RtpUnpackContainer
func (*RtpUnpackContainer) Feed ¶ added in v0.23.0
func (r *RtpUnpackContainer) Feed(pkt RtpPacket)
Feed 输入收到的rtp包
type RtpUnpackerAac ¶ added in v0.23.0
type RtpUnpackerAac struct {
// contains filtered or unexported fields
}
func NewRtpUnpackerAac ¶ added in v0.23.0
func NewRtpUnpackerAac(payloadType base.AvPacketPt, clockRate int, onAvPacket OnAvPacket) *RtpUnpackerAac
func (*RtpUnpackerAac) CalcPositionIfNeeded ¶ added in v0.23.0
func (unpacker *RtpUnpackerAac) CalcPositionIfNeeded(pkt *RtpPacket)
func (*RtpUnpackerAac) TryUnpackOne ¶ added in v0.23.0
func (unpacker *RtpUnpackerAac) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpUnpackerAvcHevc ¶ added in v0.23.0
type RtpUnpackerAvcHevc struct {
// contains filtered or unexported fields
}
func NewRtpUnpackerAvcHevc ¶ added in v0.23.0
func NewRtpUnpackerAvcHevc(payloadType base.AvPacketPt, clockRate int, onAvPacket OnAvPacket) *RtpUnpackerAvcHevc
func (*RtpUnpackerAvcHevc) CalcPositionIfNeeded ¶ added in v0.23.0
func (unpacker *RtpUnpackerAvcHevc) CalcPositionIfNeeded(pkt *RtpPacket)
func (*RtpUnpackerAvcHevc) TryUnpackOne ¶ added in v0.23.0
func (unpacker *RtpUnpackerAvcHevc) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpUnpackerRaw ¶ added in v0.34.3
type RtpUnpackerRaw struct {
// contains filtered or unexported fields
}
func NewRtpUnpackerRaw ¶ added in v0.34.3
func NewRtpUnpackerRaw(payloadType base.AvPacketPt, clockRate int, onAvPacket OnAvPacket) *RtpUnpackerRaw
func (*RtpUnpackerRaw) CalcPositionIfNeeded ¶ added in v0.34.3
func (unpacker *RtpUnpackerRaw) CalcPositionIfNeeded(pkt *RtpPacket)
func (*RtpUnpackerRaw) TryUnpackOne ¶ added in v0.34.3
func (unpacker *RtpUnpackerRaw) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
Source Files ¶
- ntp.go
- rtcp.go
- rtcp_pack.go
- rtcp_rr_producer.go
- rtp.go
- rtp_packer.go
- rtp_packer_payload.go
- rtp_packer_payload_aac.go
- rtp_packer_payload_avc_hevc.go
- rtp_packer_payload_pcm.go
- rtp_packet.go
- rtp_packet_list.go
- rtp_unpack_container.go
- rtp_unpacker.go
- rtp_unpacker_aac.go
- rtp_unpacker_avc_hevc.go
- rtp_unpacker_raw.go
- rtprtcp.go
- var.go