mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
TEST: Upgrade pion to v3.2.9. (#3567)
------ Co-authored-by: chundonglinlin <chundonglinlin@163.com>
This commit is contained in:
parent
104cf14d68
commit
df854339ea
1383 changed files with 118469 additions and 41421 deletions
196
trunk/3rdparty/srs-bench/vendor/github.com/pion/rtp/packet.go
generated
vendored
196
trunk/3rdparty/srs-bench/vendor/github.com/pion/rtp/packet.go
generated
vendored
|
@ -13,13 +13,11 @@ type Extension struct {
|
|||
}
|
||||
|
||||
// Header represents an RTP packet header
|
||||
// NOTE: PayloadOffset is populated by Marshal/Unmarshal and should not be modified
|
||||
type Header struct {
|
||||
Version uint8
|
||||
Padding bool
|
||||
Extension bool
|
||||
Marker bool
|
||||
PayloadOffset int
|
||||
PayloadType uint8
|
||||
SequenceNumber uint16
|
||||
Timestamp uint32
|
||||
|
@ -30,11 +28,10 @@ type Header struct {
|
|||
}
|
||||
|
||||
// Packet represents an RTP Packet
|
||||
// NOTE: Raw is populated by Marshal/Unmarshal and should not be modified
|
||||
type Packet struct {
|
||||
Header
|
||||
Raw []byte
|
||||
Payload []byte
|
||||
Payload []byte
|
||||
PaddingSize byte
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -77,10 +74,11 @@ func (p Packet) String() string {
|
|||
return out
|
||||
}
|
||||
|
||||
// Unmarshal parses the passed byte slice and stores the result in the Header this method is called upon
|
||||
func (h *Header) Unmarshal(rawPacket []byte) error { //nolint:gocognit
|
||||
if len(rawPacket) < headerLength {
|
||||
return fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficient, len(rawPacket), headerLength)
|
||||
// Unmarshal parses the passed byte slice and stores the result in the Header.
|
||||
// It returns the number of bytes read n and any error.
|
||||
func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit
|
||||
if len(buf) < headerLength {
|
||||
return 0, fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficient, len(buf), headerLength)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -98,31 +96,32 @@ func (h *Header) Unmarshal(rawPacket []byte) error { //nolint:gocognit
|
|||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
h.Version = rawPacket[0] >> versionShift & versionMask
|
||||
h.Padding = (rawPacket[0] >> paddingShift & paddingMask) > 0
|
||||
h.Extension = (rawPacket[0] >> extensionShift & extensionMask) > 0
|
||||
nCSRC := int(rawPacket[0] & ccMask)
|
||||
h.Version = buf[0] >> versionShift & versionMask
|
||||
h.Padding = (buf[0] >> paddingShift & paddingMask) > 0
|
||||
h.Extension = (buf[0] >> extensionShift & extensionMask) > 0
|
||||
nCSRC := int(buf[0] & ccMask)
|
||||
if cap(h.CSRC) < nCSRC || h.CSRC == nil {
|
||||
h.CSRC = make([]uint32, nCSRC)
|
||||
} else {
|
||||
h.CSRC = h.CSRC[:nCSRC]
|
||||
}
|
||||
|
||||
currOffset := csrcOffset + (nCSRC * csrcLength)
|
||||
if len(rawPacket) < currOffset {
|
||||
return fmt.Errorf("size %d < %d: %w", len(rawPacket), currOffset, errHeaderSizeInsufficient)
|
||||
n = csrcOffset + (nCSRC * csrcLength)
|
||||
if len(buf) < n {
|
||||
return n, fmt.Errorf("size %d < %d: %w", len(buf), n,
|
||||
errHeaderSizeInsufficient)
|
||||
}
|
||||
|
||||
h.Marker = (rawPacket[1] >> markerShift & markerMask) > 0
|
||||
h.PayloadType = rawPacket[1] & ptMask
|
||||
h.Marker = (buf[1] >> markerShift & markerMask) > 0
|
||||
h.PayloadType = buf[1] & ptMask
|
||||
|
||||
h.SequenceNumber = binary.BigEndian.Uint16(rawPacket[seqNumOffset : seqNumOffset+seqNumLength])
|
||||
h.Timestamp = binary.BigEndian.Uint32(rawPacket[timestampOffset : timestampOffset+timestampLength])
|
||||
h.SSRC = binary.BigEndian.Uint32(rawPacket[ssrcOffset : ssrcOffset+ssrcLength])
|
||||
h.SequenceNumber = binary.BigEndian.Uint16(buf[seqNumOffset : seqNumOffset+seqNumLength])
|
||||
h.Timestamp = binary.BigEndian.Uint32(buf[timestampOffset : timestampOffset+timestampLength])
|
||||
h.SSRC = binary.BigEndian.Uint32(buf[ssrcOffset : ssrcOffset+ssrcLength])
|
||||
|
||||
for i := range h.CSRC {
|
||||
offset := csrcOffset + (i * csrcLength)
|
||||
h.CSRC[i] = binary.BigEndian.Uint32(rawPacket[offset:])
|
||||
h.CSRC[i] = binary.BigEndian.Uint32(buf[offset:])
|
||||
}
|
||||
|
||||
if h.Extensions != nil {
|
||||
|
@ -130,21 +129,21 @@ func (h *Header) Unmarshal(rawPacket []byte) error { //nolint:gocognit
|
|||
}
|
||||
|
||||
if h.Extension {
|
||||
if expected := currOffset + 4; len(rawPacket) < expected {
|
||||
return fmt.Errorf("size %d < %d: %w",
|
||||
len(rawPacket), expected,
|
||||
if expected := n + 4; len(buf) < expected {
|
||||
return n, fmt.Errorf("size %d < %d: %w",
|
||||
len(buf), expected,
|
||||
errHeaderSizeInsufficientForExtension,
|
||||
)
|
||||
}
|
||||
|
||||
h.ExtensionProfile = binary.BigEndian.Uint16(rawPacket[currOffset:])
|
||||
currOffset += 2
|
||||
extensionLength := int(binary.BigEndian.Uint16(rawPacket[currOffset:])) * 4
|
||||
currOffset += 2
|
||||
h.ExtensionProfile = binary.BigEndian.Uint16(buf[n:])
|
||||
n += 2
|
||||
extensionLength := int(binary.BigEndian.Uint16(buf[n:])) * 4
|
||||
n += 2
|
||||
|
||||
if expected := currOffset + extensionLength; len(rawPacket) < expected {
|
||||
return fmt.Errorf("size %d < %d: %w",
|
||||
len(rawPacket), expected,
|
||||
if expected := n + extensionLength; len(buf) < expected {
|
||||
return n, fmt.Errorf("size %d < %d: %w",
|
||||
len(buf), expected,
|
||||
errHeaderSizeInsufficientForExtension,
|
||||
)
|
||||
}
|
||||
|
@ -152,87 +151,91 @@ func (h *Header) Unmarshal(rawPacket []byte) error { //nolint:gocognit
|
|||
switch h.ExtensionProfile {
|
||||
// RFC 8285 RTP One Byte Header Extension
|
||||
case extensionProfileOneByte:
|
||||
end := currOffset + extensionLength
|
||||
for currOffset < end {
|
||||
if rawPacket[currOffset] == 0x00 { // padding
|
||||
currOffset++
|
||||
end := n + extensionLength
|
||||
for n < end {
|
||||
if buf[n] == 0x00 { // padding
|
||||
n++
|
||||
continue
|
||||
}
|
||||
|
||||
extid := rawPacket[currOffset] >> 4
|
||||
len := int(rawPacket[currOffset]&^0xF0 + 1)
|
||||
currOffset++
|
||||
extid := buf[n] >> 4
|
||||
len := int(buf[n]&^0xF0 + 1)
|
||||
n++
|
||||
|
||||
if extid == extensionIDReserved {
|
||||
break
|
||||
}
|
||||
|
||||
extension := Extension{id: extid, payload: rawPacket[currOffset : currOffset+len]}
|
||||
extension := Extension{id: extid, payload: buf[n : n+len]}
|
||||
h.Extensions = append(h.Extensions, extension)
|
||||
currOffset += len
|
||||
n += len
|
||||
}
|
||||
|
||||
// RFC 8285 RTP Two Byte Header Extension
|
||||
case extensionProfileTwoByte:
|
||||
end := currOffset + extensionLength
|
||||
for currOffset < end {
|
||||
if rawPacket[currOffset] == 0x00 { // padding
|
||||
currOffset++
|
||||
end := n + extensionLength
|
||||
for n < end {
|
||||
if buf[n] == 0x00 { // padding
|
||||
n++
|
||||
continue
|
||||
}
|
||||
|
||||
extid := rawPacket[currOffset]
|
||||
currOffset++
|
||||
extid := buf[n]
|
||||
n++
|
||||
|
||||
len := int(rawPacket[currOffset])
|
||||
currOffset++
|
||||
len := int(buf[n])
|
||||
n++
|
||||
|
||||
extension := Extension{id: extid, payload: rawPacket[currOffset : currOffset+len]}
|
||||
extension := Extension{id: extid, payload: buf[n : n+len]}
|
||||
h.Extensions = append(h.Extensions, extension)
|
||||
currOffset += len
|
||||
n += len
|
||||
}
|
||||
|
||||
default: // RFC3550 Extension
|
||||
if len(rawPacket) < currOffset+extensionLength {
|
||||
return fmt.Errorf("%w: %d < %d", errHeaderSizeInsufficientForExtension, len(rawPacket), currOffset+extensionLength)
|
||||
if len(buf) < n+extensionLength {
|
||||
return n, fmt.Errorf("%w: %d < %d",
|
||||
errHeaderSizeInsufficientForExtension, len(buf), n+extensionLength)
|
||||
}
|
||||
|
||||
extension := Extension{id: 0, payload: rawPacket[currOffset : currOffset+extensionLength]}
|
||||
extension := Extension{id: 0, payload: buf[n : n+extensionLength]}
|
||||
h.Extensions = append(h.Extensions, extension)
|
||||
currOffset += len(h.Extensions[0].payload)
|
||||
n += len(h.Extensions[0].payload)
|
||||
}
|
||||
}
|
||||
|
||||
h.PayloadOffset = currOffset
|
||||
|
||||
return nil
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Unmarshal parses the passed byte slice and stores the result in the Packet this method is called upon
|
||||
func (p *Packet) Unmarshal(rawPacket []byte) error {
|
||||
if err := p.Header.Unmarshal(rawPacket); err != nil {
|
||||
// Unmarshal parses the passed byte slice and stores the result in the Packet.
|
||||
func (p *Packet) Unmarshal(buf []byte) error {
|
||||
n, err := p.Header.Unmarshal(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.Payload = rawPacket[p.PayloadOffset:]
|
||||
p.Raw = rawPacket
|
||||
end := len(buf)
|
||||
if p.Header.Padding {
|
||||
p.PaddingSize = buf[end-1]
|
||||
end -= int(p.PaddingSize)
|
||||
}
|
||||
if end < n {
|
||||
return errTooSmall
|
||||
}
|
||||
p.Payload = buf[n:end]
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal serializes the header into bytes.
|
||||
func (h *Header) Marshal() (buf []byte, err error) {
|
||||
func (h Header) Marshal() (buf []byte, err error) {
|
||||
buf = make([]byte, h.MarshalSize())
|
||||
|
||||
n, err := h.MarshalTo(buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf[:n], nil
|
||||
}
|
||||
|
||||
// MarshalTo serializes the header and writes to the buffer.
|
||||
func (h *Header) MarshalTo(buf []byte) (n int, err error) {
|
||||
func (h Header) MarshalTo(buf []byte) (n int, err error) {
|
||||
/*
|
||||
* 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
|
||||
|
@ -253,7 +256,8 @@ func (h *Header) MarshalTo(buf []byte) (n int, err error) {
|
|||
return 0, io.ErrShortBuffer
|
||||
}
|
||||
|
||||
// The first byte contains the version, padding bit, extension bit, and csrc size
|
||||
// The first byte contains the version, padding bit, extension bit,
|
||||
// and csrc size.
|
||||
buf[0] = (h.Version << versionShift) | uint8(len(h.CSRC))
|
||||
if h.Padding {
|
||||
buf[0] |= 1 << paddingShift
|
||||
|
@ -324,13 +328,11 @@ func (h *Header) MarshalTo(buf []byte) (n int, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
h.PayloadOffset = n
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// MarshalSize returns the size of the header once marshaled.
|
||||
func (h *Header) MarshalSize() int {
|
||||
func (h Header) MarshalSize() int {
|
||||
// NOTE: Be careful to match the MarshalTo() method.
|
||||
size := 12 + (len(h.CSRC) * csrcLength)
|
||||
|
||||
|
@ -455,7 +457,7 @@ func (h *Header) DelExtension(id uint8) error {
|
|||
}
|
||||
|
||||
// Marshal serializes the packet into bytes.
|
||||
func (p *Packet) Marshal() (buf []byte, err error) {
|
||||
func (p Packet) Marshal() (buf []byte, err error) {
|
||||
buf = make([]byte, p.MarshalSize())
|
||||
|
||||
n, err := p.MarshalTo(buf)
|
||||
|
@ -467,24 +469,60 @@ func (p *Packet) Marshal() (buf []byte, err error) {
|
|||
}
|
||||
|
||||
// MarshalTo serializes the packet and writes to the buffer.
|
||||
func (p *Packet) MarshalTo(buf []byte) (n int, err error) {
|
||||
func (p Packet) MarshalTo(buf []byte) (n int, err error) {
|
||||
p.Header.Padding = p.PaddingSize != 0
|
||||
n, err = p.Header.MarshalTo(buf)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Make sure the buffer is large enough to hold the packet.
|
||||
if n+len(p.Payload) > len(buf) {
|
||||
if n+len(p.Payload)+int(p.PaddingSize) > len(buf) {
|
||||
return 0, io.ErrShortBuffer
|
||||
}
|
||||
|
||||
m := copy(buf[n:], p.Payload)
|
||||
p.Raw = buf[:n+m]
|
||||
if p.Header.Padding {
|
||||
buf[n+m+int(p.PaddingSize-1)] = p.PaddingSize
|
||||
}
|
||||
|
||||
return n + m, nil
|
||||
return n + m + int(p.PaddingSize), nil
|
||||
}
|
||||
|
||||
// MarshalSize returns the size of the packet once marshaled.
|
||||
func (p *Packet) MarshalSize() int {
|
||||
return p.Header.MarshalSize() + len(p.Payload)
|
||||
func (p Packet) MarshalSize() int {
|
||||
return p.Header.MarshalSize() + len(p.Payload) + int(p.PaddingSize)
|
||||
}
|
||||
|
||||
// Clone returns a deep copy of p.
|
||||
func (p Packet) Clone() *Packet {
|
||||
clone := &Packet{}
|
||||
clone.Header = p.Header.Clone()
|
||||
if p.Payload != nil {
|
||||
clone.Payload = make([]byte, len(p.Payload))
|
||||
copy(clone.Payload, p.Payload)
|
||||
}
|
||||
clone.PaddingSize = p.PaddingSize
|
||||
return clone
|
||||
}
|
||||
|
||||
// Clone returns a deep copy h.
|
||||
func (h Header) Clone() Header {
|
||||
clone := h
|
||||
if h.CSRC != nil {
|
||||
clone.CSRC = make([]uint32, len(h.CSRC))
|
||||
copy(clone.CSRC, h.CSRC)
|
||||
}
|
||||
if h.Extensions != nil {
|
||||
ext := make([]Extension, len(h.Extensions))
|
||||
for i, e := range h.Extensions {
|
||||
ext[i] = e
|
||||
if e.payload != nil {
|
||||
ext[i].payload = make([]byte, len(e.payload))
|
||||
copy(ext[i].payload, e.payload)
|
||||
}
|
||||
}
|
||||
clone.Extensions = ext
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue