rtprtcp

package
v0.0.0-...-3f607ea Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RtcpPacketTypeSr  = 200 // 0xc8 Sender Report
	RtcpPacketTypeRr  = 201 // 0xc9 Receiver Report
	RtcpPacketTypeApp = 204

	RtcpHeaderLength = 4

	RtcpVersion = 2
)
View Source
const (
	NaluTypeAvcSingleMax = 23
	NaluTypeAvcStapa     = 24 // one packet, multiple nals
	NaluTypeAvcFua       = 28
)
View Source
const (
	RtpFixedHeaderLength = 12

	DefaultRtpVersion = 2
)
View Source
const (
	PositionTypeSingle    uint8 = 1
	PositionTypeFuaStart  uint8 = 2
	PositionTypeFuaMiddle uint8 = 3
	PositionTypeFuaEnd    uint8 = 4
	PositionTypeStapa     uint8 = 5
)
View Source
const MaxRtpRtcpPacketSize = 1500
View Source
const (
	NaluTypeHevcFua = 49
)

Variables

View Source
var ErrRtcp = errors.New("lal.rtcp: fxxk")
View Source
var ErrRtp = errors.New("lal.rtp: fxxk")

Functions

func CompareSeq

func CompareSeq(a, b uint16) int

比较序号的值,内部处理序号翻转问题,见单元测试中的例子 @return 0 a和b相等

 1 a大于b
-1 a小于b

func MswLsw2Ntp

func MswLsw2Ntp(msw, lsw uint64) uint64

msw是ntp的高32位,lsw是ntp的低32位

func MswLsw2UnixNano

func MswLsw2UnixNano(msw, lsw uint64) uint64

将ntp时间戳(高32位低32位分开的形式)转换为Unix时间戳

func Ntp2UnixNano

func Ntp2UnixNano(v uint64) uint64

将ntp时间戳转换为Unix时间戳,Unix时间戳单位是纳秒

func SubSeq

func SubSeq(a, b uint16) int

a减b的值,内部处理序号翻转问题,如果a小于b,则返回负值,见单元测试中的例子

Types

type IRtpPackerPayload

type IRtpPackerPayload interface {
	// @param maxSize: rtp payload包体部分(不含包头)的最大大小
	//
	Pack(in []byte, maxSize int) (out [][]byte)
}

type IRtpUnpackContainer

type IRtpUnpackContainer interface {
	Feed(pkt RtpPacket)
}

type IRtpUnpacker

type IRtpUnpacker interface {
	IRtpUnpackContainer
}

func DefaultRtpUnpackerFactory

func DefaultRtpUnpackerFactory(payloadType base.AvPacketPt, clockRate int, maxSize int, onAvPacket OnAvPacket) IRtpUnpacker

目前支持AVC,HEVC和AAC MPEG4-GENERIC/44100/2,业务方也可以自己实现IRtpUnpackerProtocol,甚至是IRtpUnpackContainer

type IRtpUnpackerProtocol

type IRtpUnpackerProtocol interface {
	// 计算rtp包处于帧中的位置
	CalcPositionIfNeeded(pkt *RtpPacket)

	// 尝试合成一个完整帧
	//
	// 从当前队列的第一个包开始合成
	// 如果一个rtp包对应一个完整帧,则合成一帧
	// 如果一个rtp包对应多个完整帧,则合成多帧
	// 如果多个rtp包对应一个完整帧,则尝试合成一帧
	//
	// @return unpackedFlag 本次调用是否成功合成
	// @return unpackedSeq  如果成功合成,合成使用的最后一个seq号;如果失败,则为0
	TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
}

type ModRtpPackerOption

type ModRtpPackerOption func(option *RtpPackerOption)

type ModRtpPackerPayloadAvcOption

type ModRtpPackerPayloadAvcOption func(option *RtpPackerPayloadAvcOption)

type OnAvPacket

type OnAvPacket func(pkt base.AvPacket)

@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 Rr

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

func (*Rr) Pack

func (r *Rr) Pack() []byte

type RrProducer

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

func NewRrProducer

func NewRrProducer(clockRate int) *RrProducer

func (*RrProducer) FeedRtpPacket

func (r *RrProducer) FeedRtpPacket(seq uint16)

每次收到rtp包,都将seq序号传入这个函数

func (*RrProducer) Produce

func (r *RrProducer) Produce(lsr uint32) []byte

收到sr包时,产生rr包

@param lsr: 从sr包中获取,见func SR.GetMiddleNtp @return: rr包的二进制数据

type RtcpHeader

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

func ParseRtcpHeader(b []byte) RtcpHeader

func (*RtcpHeader) PackTo

func (r *RtcpHeader) PackTo(out []byte)

@param out 传出参数,注意,调用方保证长度>=4

type RtpHeader

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

func MakeDefaultRtpHeader

func MakeDefaultRtpHeader() RtpHeader

func ParseRtpHeader

func ParseRtpHeader(b []byte) (h RtpHeader, err error)

func (*RtpHeader) PackTo

func (h *RtpHeader) PackTo(out []byte)

type RtpPacker

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

func NewRtpPacker

func NewRtpPacker(payloadPacker IRtpPackerPayload, clockRate int, ssrc uint32, modOptions ...ModRtpPackerOption) *RtpPacker

func (*RtpPacker) Pack

func (r *RtpPacker) Pack(pkt base.AvPacket) (out []RtpPacket)

@param pkt: pkt.Timestamp 绝对时间戳,单位毫秒

pkt.PayloadType rtp包头中的packet type

type RtpPackerOption

type RtpPackerOption struct {
	MaxPayloadSize int
	FirstSeq       uint16 // 初始seq,如果不设置,则随机产生
}

type RtpPackerPayloadAvc

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

func NewRtpPackerPayloadAvc

func NewRtpPackerPayloadAvc(modOptions ...ModRtpPackerPayloadAvcOption) *RtpPackerPayloadAvc

func (*RtpPackerPayloadAvc) Pack

func (r *RtpPackerPayloadAvc) Pack(in []byte, maxSize int) (out [][]byte)

@param in: AVCC格式

@return out: 内存块为独立新申请;函数返回后,内部不再持有该内存块

func (*RtpPackerPayloadAvc) PackNal

func (r *RtpPackerPayloadAvc) PackNal(nal []byte, maxSize int) (out [][]byte)

type RtpPackerPayloadAvcOption

type RtpPackerPayloadAvcOption struct {
	Typ RtpPackerPayloadAvcType
}

type RtpPackerPayloadAvcType

type RtpPackerPayloadAvcType int
const (
	RtpPackerPayloadAvcTypeNalu RtpPackerPayloadAvcType = iota + 1
	RtpPackerPayloadAvcTypeAvcc
	RtpPackerPayloadAvcTypeAnnexb
)

type RtpPacket

type RtpPacket struct {
	Header RtpHeader
	Raw    []byte // 包含header内存
	// contains filtered or unexported fields
}

func MakeRtpPacket

func MakeRtpPacket(h RtpHeader, payload []byte) (pkt RtpPacket)

func ParseRtpPacket

func ParseRtpPacket(b []byte) (pkt RtpPacket, err error)

函数调用结束后,不持有参数<b>的内存块

type RtpPacketList

type RtpPacketList struct {
	Head RtpPacketListItem // 哨兵,自身不存放rtp包,第一个rtp包存在在head.next中
	Size int               // 实际元素个数
}

type RtpPacketListItem

type RtpPacketListItem struct {
	Packet RtpPacket
	Next   *RtpPacketListItem
}

type RtpUnpackContainer

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

func NewRtpUnpackContainer

func NewRtpUnpackContainer(maxSize int, unpackerProtocol IRtpUnpackerProtocol) *RtpUnpackContainer

func (*RtpUnpackContainer) Feed

func (r *RtpUnpackContainer) Feed(pkt RtpPacket)

输入收到的rtp包

type RtpUnpackerAac

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

func NewRtpUnpackerAac

func NewRtpUnpackerAac(payloadType base.AvPacketPt, clockRate int, onAvPacket OnAvPacket) *RtpUnpackerAac

func (*RtpUnpackerAac) CalcPositionIfNeeded

func (unpacker *RtpUnpackerAac) CalcPositionIfNeeded(pkt *RtpPacket)

func (*RtpUnpackerAac) TryUnpackOne

func (unpacker *RtpUnpackerAac) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)

type RtpUnpackerAvcHevc

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

func NewRtpUnpackerAvcHevc

func NewRtpUnpackerAvcHevc(payloadType base.AvPacketPt, clockRate int, onAvPacket OnAvPacket) *RtpUnpackerAvcHevc

func (*RtpUnpackerAvcHevc) CalcPositionIfNeeded

func (unpacker *RtpUnpackerAvcHevc) CalcPositionIfNeeded(pkt *RtpPacket)

func (*RtpUnpackerAvcHevc) TryUnpackOne

func (unpacker *RtpUnpackerAvcHevc) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)

type Sr

type Sr struct {
	SenderSsrc uint32
	Msw        uint32 // NTP timestamp, most significant word
	Lsw        uint32 // NTP timestamp, least significant word
	Timestamp  uint32
	PktCnt     uint32
	OctetCnt   uint32
}

func ParseSr

func ParseSr(b []byte) Sr

rfc3550 6.4.1

@param b rtcp包,包含包头

func (*Sr) GetMiddleNtp

func (s *Sr) GetMiddleNtp() uint32

Jump to

Keyboard shortcuts

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