Documentation ¶
Overview ¶
Package rtprtcp *
- @Author: W.w.
- @File: i_rtp_packer
- @Date: 2023-07-23 13:59
- @Description:
Package rtprtcp *
- @Author: W.w.
- @File: i_rtp_payload_protocol
- @Date: 2023-07-22 23:16
- @Description:
Package rtprtcp *
- @Author: slad_shang
- @Date: 2020/9/17 17:07
- @Desc:
Package rtprtcp *
- @Author: W.w.
- @File: rtp_unpack_video_container
- @Date: 2023-07-23 19:58
- @Description:
Package rtprtcp *
- @Author: W.w.
- @File: rtprtcp
- @Date: 2023-06-08 10:57
- @Description:
Index ¶
- Constants
- func CompareSeq(a, b uint16) int
- func IsAvcBoundary(pkt RTPPacket) bool
- func IsHevcBoundary(pkt RTPPacket) bool
- func SubSeq(a, b uint16) int
- func SubSeqOne(a uint16) uint16
- type Extension
- type Header
- func (self *Header) DelExtension(id uint8) error
- func (self *Header) GetExtension(id uint8) []byte
- func (self *Header) Marshal() []byte
- func (h *Header) MarshalSize() int
- func (self *Header) SetCSRC(CSRC uint32)
- func (self *Header) SetExtension(id uint8, payload []byte) error
- func (self *Header) Unmarshal(rawPacket []byte) (int, int)
- type IRtpPacker
- type IRtpPayloadProtocol
- type IRtpUnpacker
- type ModRtpPackerOption
- type OnAvPacket
- type RTPPacket
- type Rr
- type RrProducer
- type RtcpHeader
- type RtpPacker
- type RtpPackerOption
- type RtpPacketList
- func (l *RtpPacketList) DropOneFrame()
- 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 RtpPayloadProtocolAac
- type RtpPayloadProtocolH264H265
- func (protocol *RtpPayloadProtocolH264H265) CalcPositionIfNeeded(pkt *RTPPacket)
- func (protocol *RtpPayloadProtocolH264H265) SplitPayload(payload []byte, maxMtu uint32) (out [][]byte)
- func (protocol *RtpPayloadProtocolH264H265) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
- type RtpPayloadProtocolRaw
- type RtpPayloadProtocolVP8
- type RtpUnpackContainer
- type RtpUnpackVideoContainer
- type Sr
Constants ¶
const ( RtcpPacketTypeSr = 200 // 0xc8 Sender Report RtcpPacketTypeRr = 201 // 0xc9 Receiver Report RtcpPacketTypeApp = 204 RtcpHeaderLength = 4 RtcpVersion = 2 )
const ( PositionTypeUnknown uint8 = 0 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使用 PositionTypeVp8Start uint8 = 7 PositionTypeVp8Continuation uint8 = 8 )
视频解码时用到
const ( NaluTypeAvcSingleMax = 23 NaluTypeAvcStapa = 24 // one packet, multiple nals NaluTypeAvcFua = 28 NaluTypeHevcAp = 48 NaluTypeHevcFua = 49 )
const (
BaseHeaderLength = 12
)
const MaxRtpRtcpPacketSize = 1500
Variables ¶
This section is empty.
Functions ¶
func IsAvcBoundary ¶
func IsHevcBoundary ¶
Types ¶
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension RTP Header extension
type Header ¶
type Header struct { Version uint8 // V Padding bool // P Marker bool // M PayloadType uint8 // PT SequenceNumber uint16 Timestamp uint32 SSRC uint32 CSRC []uint32 // 长度为CC Extension bool // X ExtensionProfile uint16 Extensions []Extension }
func (*Header) DelExtension ¶
DelExtension Removes an RTP Header extension
func (*Header) GetExtension ¶
GetExtension returns an RTP header extension
func (*Header) MarshalSize ¶
func (*Header) SetExtension ¶
SetExtension sets an RTP header extension
type IRtpPacker ¶
func DefaultRtpPackerFactory ¶
func DefaultRtpPackerFactory(mediaType media.AvMediaType, clockRate int, payloadType uint8, modOptions ...ModRtpPackerOption) IRtpPacker
type IRtpPayloadProtocol ¶
type IRtpPayloadProtocol interface { // CalcPositionIfNeeded 计算rtp包处于帧中的位置 CalcPositionIfNeeded(pkt *RTPPacket) // TryUnpackOne 尝试合成一个完整帧 // // 从当前队列的第一个包开始合成 // 如果一个rtp包对应一个完整帧,则合成一帧 // 如果一个rtp包对应多个完整帧,则合成多帧 // 如果多个rtp包对应一个完整帧,则尝试合成一帧 // // @return unpackedFlag 本次调用是否成功合成 // @return unpackedSeq 如果成功合成,合成使用的最后一个seq号;如果失败,则为0 TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16) // SplitPayload /****************************************************** * @Description: 视频数据超过 maxMtu 分包数据 * @param payload 数据 * @param timestamp 时戳 * @param marker ******************************************************/ SplitPayload(payload []byte, maxMtu uint32) (out [][]byte) }
type IRtpUnpacker ¶
type IRtpUnpacker interface {
Feed(pkt RTPPacket)
}
func DefaultRtpUnpackerFactory ¶
func DefaultRtpUnpackerFactory(mediaType media.AvMediaType, clockRate int, maxSize int, onAvPacket OnAvPacket) IRtpUnpacker
DefaultRtpUnpackerFactory 目前支持AVC,HEVC和AAC MPEG4-GENERIC,业务方也可以自己实现IRtpPayloadProtocol,
type ModRtpPackerOption ¶
type ModRtpPackerOption func(option *RtpPackerOption)
type OnAvPacket ¶
type RTPPacket ¶
type RTPPacket struct { Header Raw []byte Payload []byte PaddingData []byte // contains filtered or unexported fields }
RTPPacket *****************************************************
- @Description: Packet represents an RTP Packet *****************************************************
func (*RTPPacket) SetPadding ¶
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)
FeedRtpPacket 每次收到rtp包,都将seq序号传入这个函数
func (*RrProducer) Produce ¶
func (r *RrProducer) Produce(lsr uint32) []byte
Produce *****************************************************
- @Description: 收到sr包时,产生rr包
- @receiver r
- @param lsr 从sr包中获取,见func SR.GetMiddleNtp
- @return []byte 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)
PackTo *****************************************************
- @Description:
- @receiver r
- @param out 传出参数,注意,调用方保证长度>=4 *****************************************************
type RtpPacker ¶
type RtpPacker struct {
// contains filtered or unexported fields
}
func NewRtpPacker ¶
func NewRtpPacker(payloadProtocol IRtpPayloadProtocol, clockRate int, payloadType uint8, modOptions ...ModRtpPackerOption) *RtpPacker
type RtpPackerOption ¶
type RtpPacketList ¶
type RtpPacketList struct { Head RtpPacketListItem // 哨兵,自身不存放rtp包,第一个rtp包存在在head.next中 Size int // 实际元素个数 // contains filtered or unexported fields }
RtpPacketList rtp packet的有序链表,前面的seq小于后面的seq
为什么不用红黑树等查找性能更高的有序kv结构? 第一,容器有最大值,这个数量级用啥容器都差不多, 第二,插入时,99.99%的seq号是当前最大号附近的,遍历找就可以了, 注意,这个链表并不是一个定长容器,当数据有序时,容器内缓存的数据是一个帧的数据。
func (*RtpPacketList) DropOneFrame ¶
func (l *RtpPacketList) DropOneFrame()
func (*RtpPacketList) InitMaxSize ¶
func (l *RtpPacketList) InitMaxSize(maxSize int)
InitMaxSize 设置容器最大容量
func (*RtpPacketList) IsFirstSequential ¶
func (l *RtpPacketList) IsFirstSequential() bool
IsFirstSequential 第一个包是否是需要的(与之前已处理的是连续的)
func (*RtpPacketList) PeekFirst ¶
func (l *RtpPacketList) PeekFirst() RTPPacket
PeekFirst 查看第一个包。注意,调用方保证容器不为空时调用
func (*RtpPacketList) PopFirst ¶
func (l *RtpPacketList) PopFirst() RTPPacket
PopFirst 弹出第一个包。注意,调用方保证容器不为空时调用
func (*RtpPacketList) Reset ¶
func (l *RtpPacketList) Reset()
func (*RtpPacketList) SetDoneSeq ¶
func (l *RtpPacketList) SetDoneSeq(seq uint16)
SetDoneSeq 设置已处理的包序号,比如已经成功合成了,或者主动丢弃到该位置结束丢弃了
type RtpPacketListItem ¶
type RtpPacketListItem struct { Packet RTPPacket Next *RtpPacketListItem }
type RtpPayloadProtocolAac ¶
type RtpPayloadProtocolAac struct {
// contains filtered or unexported fields
}
func NewRtpPayloadProtocolAac ¶
func NewRtpPayloadProtocolAac(mediaType media.AvMediaType, clockRate int, onAvPacket OnAvPacket) *RtpPayloadProtocolAac
func (*RtpPayloadProtocolAac) CalcPositionIfNeeded ¶
func (protocol *RtpPayloadProtocolAac) CalcPositionIfNeeded(pkt *RTPPacket)
func (*RtpPayloadProtocolAac) SplitPayload ¶
func (protocol *RtpPayloadProtocolAac) SplitPayload(payload []byte, maxMtu uint32) (out [][]byte)
func (*RtpPayloadProtocolAac) TryUnpackOne ¶
func (protocol *RtpPayloadProtocolAac) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpPayloadProtocolH264H265 ¶
type RtpPayloadProtocolH264H265 struct {
// contains filtered or unexported fields
}
func NewRtpPayloadProtocolH264H265 ¶
func NewRtpPayloadProtocolH264H265(mediaType media.AvMediaType, clockRate int, onAvPacket OnAvPacket) *RtpPayloadProtocolH264H265
func (*RtpPayloadProtocolH264H265) CalcPositionIfNeeded ¶
func (protocol *RtpPayloadProtocolH264H265) CalcPositionIfNeeded(pkt *RTPPacket)
func (*RtpPayloadProtocolH264H265) SplitPayload ¶
func (protocol *RtpPayloadProtocolH264H265) SplitPayload(payload []byte, maxMtu uint32) (out [][]byte)
func (*RtpPayloadProtocolH264H265) TryUnpackOne ¶
func (protocol *RtpPayloadProtocolH264H265) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpPayloadProtocolRaw ¶
type RtpPayloadProtocolRaw struct {
// contains filtered or unexported fields
}
func NewRtpPayloadProtocolRaw ¶
func NewRtpPayloadProtocolRaw(mediaType media.AvMediaType, clockRate int, onAvPacket OnAvPacket) *RtpPayloadProtocolRaw
func (*RtpPayloadProtocolRaw) CalcPositionIfNeeded ¶
func (protocol *RtpPayloadProtocolRaw) CalcPositionIfNeeded(pkt *RTPPacket)
func (*RtpPayloadProtocolRaw) SplitPayload ¶
func (protocol *RtpPayloadProtocolRaw) SplitPayload(payload []byte, maxMtu uint32) (out [][]byte)
func (*RtpPayloadProtocolRaw) TryUnpackOne ¶
func (protocol *RtpPayloadProtocolRaw) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpPayloadProtocolVP8 ¶
type RtpPayloadProtocolVP8 struct {
// contains filtered or unexported fields
}
func NewRtpPayloadProtocolVP8 ¶
func NewRtpPayloadProtocolVP8(mediaType media.AvMediaType, clockRate int, onAvPacket OnAvPacket) *RtpPayloadProtocolVP8
func (*RtpPayloadProtocolVP8) CalcPositionIfNeeded ¶
func (protocol *RtpPayloadProtocolVP8) CalcPositionIfNeeded(pkt *RTPPacket)
func (*RtpPayloadProtocolVP8) SplitPayload ¶
func (protocol *RtpPayloadProtocolVP8) SplitPayload(payload []byte, maxMtu uint32) (out [][]byte)
func (*RtpPayloadProtocolVP8) TryUnpackOne ¶
func (protocol *RtpPayloadProtocolVP8) TryUnpackOne(list *RtpPacketList) (unpackedFlag bool, unpackedSeq uint16)
type RtpUnpackContainer ¶
type RtpUnpackContainer struct {
// contains filtered or unexported fields
}
func NewRtpUnpackContainer ¶
func NewRtpUnpackContainer(maxSize int, payloadProtocol IRtpPayloadProtocol) *RtpUnpackContainer
type RtpUnpackVideoContainer ¶
type RtpUnpackVideoContainer struct {
RtpUnpackContainer
}
func NewRtpUnpackVideoContainer ¶
func NewRtpUnpackVideoContainer(payloadProtocol IRtpPayloadProtocol) *RtpUnpackVideoContainer
func (*RtpUnpackVideoContainer) Feed ¶
func (r *RtpUnpackVideoContainer) Feed(pkt RTPPacket)
Feed 输入收到的rtp包
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 ¶
ParseSr *****************************************************
- @Description: rfc3550 6.4.1
- @param b rtcp包,包含包头
- @return Sr *****************************************************
func (*Sr) GetMiddleNtp ¶
Source Files ¶
- i_rtp_packer.go
- i_rtp_payload_protocol.go
- i_rtp_unpacker.go
- rtcp.go
- rtcp_pack.go
- rtcp_rr_producer.go
- rtp_packer.go
- rtp_packet.go
- rtp_packet_list.go
- rtp_payload_protocol_264_265.go
- rtp_payload_protocol_aac.go
- rtp_payload_protocol_raw.go
- rtp_payload_protocol_vp8.go
- rtp_unpack_container.go
- rtp_unpack_video_container.go
- rtprtcp.go