rtp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufferPoolSize  = unit.KiBiByte * 256
	DefaultBufferReverse   = 2048
	DefaultWriteBufferSize = 2048
)
View Source
const RtpHeaderMinSize = 12

Variables

View Source
var (
	InvalidVersionError       = errors.New("RTP版本号必须为2")
	CSRCLengthOutOfRange      = errors.New("RTP CSRC长度超过限制(0, 15)")
	ExtensionLengthOutOfRange = errors.New("RTP扩展头部长度超过限制(0, 65535)")
	PayloadLengthOutOfRange   = errors.New("RTP负载长度超过限制(0, 65535)")
	ZeroPaddingLengthError    = errors.New("RTP填充长度不能为0")
	PacketSizeNotEnoughError  = errors.New("RTP包大小不够")
)
View Source
var InvalidTCPHeaderIDError = errors.New("invalid tcp header id")

Functions

func DefaultLayerProvider

func DefaultLayerProvider(payloadProvider func() Payload) func() Layer

func DefaultPacketProvider

func DefaultPacketProvider(payloadProvider func() Payload) func(pool pool.Pool[*DefaultPacket]) *DefaultPacket

Types

type Buffer

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

func (*Buffer) AddRef

func (b *Buffer) AddRef()

func (*Buffer) Alloc

func (b *Buffer) Alloc(size uint) *Data

func (*Buffer) Get

func (b *Buffer) Get() []byte

func (*Buffer) Release

func (b *Buffer) Release()

func (*Buffer) Use

func (b *Buffer) Use() *Buffer

type BufferPool

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

func NewBufferPool

func NewBufferPool(size uint) BufferPool

func (BufferPool) Get

func (p BufferPool) Get() *Buffer

type Data

type Data struct {
	Data []byte
	// contains filtered or unexported fields
}

func (*Data) AddRef

func (d *Data) AddRef()

func (*Data) Release

func (d *Data) Release()

func (*Data) Use

func (d *Data) Use() *Data

type DefaultLayer

type DefaultLayer struct {
	Header
	// contains filtered or unexported fields
}

func NewDefaultLayer

func NewDefaultLayer(payload Payload) *DefaultLayer

func (*DefaultLayer) Bytes

func (l *DefaultLayer) Bytes() []byte

func (*DefaultLayer) Init

func (l *DefaultLayer) Init(payload Payload)

func (*DefaultLayer) Payload

func (l *DefaultLayer) Payload() Payload

func (*DefaultLayer) Read

func (l *DefaultLayer) Read(p []byte) (n int, err error)

func (*DefaultLayer) SetPayload

func (l *DefaultLayer) SetPayload(payload Payload)

func (*DefaultLayer) Size

func (l *DefaultLayer) Size() int

func (*DefaultLayer) String

func (l *DefaultLayer) String() string

func (*DefaultLayer) WriteTo

func (l *DefaultLayer) WriteTo(w io.Writer) (n int64, err error)

type DefaultPacket

type DefaultPacket struct {
	DefaultLayer
	// contains filtered or unexported fields
}

func NewDefaultPacket

func NewDefaultPacket(pool pool.Pool[*DefaultPacket], payload Payload) *DefaultPacket

func (*DefaultPacket) AddRef

func (p *DefaultPacket) AddRef()

func (*DefaultPacket) AddRelation

func (p *DefaultPacket) AddRelation(relation pool.Reference)

func (*DefaultPacket) Clear

func (p *DefaultPacket) Clear()

func (*DefaultPacket) Release

func (p *DefaultPacket) Release() bool

func (*DefaultPacket) Use

func (p *DefaultPacket) Use() *DefaultPacket
type Header struct {
	// contains filtered or unexported fields
}

func (*Header) AddCSRC

func (l *Header) AddCSRC(csrc uint32)

func (*Header) AddCSRCList

func (l *Header) AddCSRCList(csrcList ...uint32)

func (*Header) AddExtensionContent

func (l *Header) AddExtensionContent(content uint32)

func (*Header) AddExtensionContents

func (l *Header) AddExtensionContents(contents ...uint32)

func (*Header) CSRCCount

func (l *Header) CSRCCount() uint8

func (*Header) CSRCList

func (l *Header) CSRCList() []uint32

func (*Header) Clear

func (l *Header) Clear()

func (*Header) DumpHeader

func (l *Header) DumpHeader(header *Header)

func (*Header) ExtensionContents

func (l *Header) ExtensionContents() []uint32

func (*Header) ExtensionLength

func (l *Header) ExtensionLength() uint16

func (*Header) ExtensionProfile

func (l *Header) ExtensionProfile() uint16

func (*Header) HasExtension

func (l *Header) HasExtension() bool

func (*Header) HasPadding

func (l *Header) HasPadding() bool

func (*Header) Marker

func (l *Header) Marker() bool

func (*Header) PaddingLength

func (l *Header) PaddingLength() uint8

func (*Header) PayloadType

func (l *Header) PayloadType() uint8

func (*Header) SSRC

func (l *Header) SSRC() uint32

func (*Header) SequenceNumber

func (l *Header) SequenceNumber() uint16

func (*Header) SetCSRCList

func (l *Header) SetCSRCList(csrcList []uint32)

func (*Header) SetExtensionContents

func (l *Header) SetExtensionContents(contents []uint32)

func (*Header) SetExtensionProfile

func (l *Header) SetExtensionProfile(profile uint16)

func (*Header) SetMarker

func (l *Header) SetMarker(maker bool)

func (*Header) SetPaddingLength

func (l *Header) SetPaddingLength(length uint8)

func (*Header) SetPayloadType

func (l *Header) SetPayloadType(payloadType uint8)

func (*Header) SetSSRC

func (l *Header) SetSSRC(ssrc uint32)

func (*Header) SetSequenceNumber

func (l *Header) SetSequenceNumber(seq uint16)

func (*Header) SetTimestamp

func (l *Header) SetTimestamp(timestamp uint32)

func (*Header) Timestamp

func (l *Header) Timestamp() uint32

func (*Header) Version

func (l *Header) Version() uint8

type IncomingLayer

type IncomingLayer struct {
	Header
	// contains filtered or unexported fields
}

func BuildIncomingLayer

func BuildIncomingLayer(cfg *IncomingLayerConfig) *IncomingLayer

func NewIncomingLayer

func NewIncomingLayer() *IncomingLayer

func (*IncomingLayer) Bytes

func (l *IncomingLayer) Bytes() []byte

func (*IncomingLayer) Payload

func (l *IncomingLayer) Payload() Payload

func (*IncomingLayer) Read

func (l *IncomingLayer) Read(p []byte) (n int, err error)

func (*IncomingLayer) Size

func (l *IncomingLayer) Size() int

func (*IncomingLayer) String

func (l *IncomingLayer) String() string

func (*IncomingLayer) Unmarshal

func (l *IncomingLayer) Unmarshal(data []byte) error

func (*IncomingLayer) UnmarshalChunks

func (l *IncomingLayer) UnmarshalChunks(cs [][]byte) error

func (*IncomingLayer) WriteTo

func (l *IncomingLayer) WriteTo(w io.Writer) (n int64, err error)

type IncomingLayerConfig

type IncomingLayerConfig struct {
	Marker            bool
	PayloadType       uint8
	SequenceNumber    uint16
	Timestamp         uint32
	SSRC              uint32
	CSRCList          []uint32
	ExtensionProfile  uint16
	ExtensionContents []uint32
	PaddingLength     uint8
	PayloadContent    []byte
	PayloadContents   [][]byte
}

type IncomingPacket

type IncomingPacket struct {
	*IncomingLayer
	// contains filtered or unexported fields
}

func NewIncomingPacket

func NewIncomingPacket(layer *IncomingLayer, pool pool.Pool[*IncomingPacket]) *IncomingPacket

func ProvideIncomingPacket

func ProvideIncomingPacket(p pool.Pool[*IncomingPacket]) *IncomingPacket

func (*IncomingPacket) AddRef

func (p *IncomingPacket) AddRef()

func (*IncomingPacket) AddRelation

func (p *IncomingPacket) AddRelation(relation pool.Reference)

func (*IncomingPacket) Addr

func (p *IncomingPacket) Addr() net.Addr

func (*IncomingPacket) Clear

func (p *IncomingPacket) Clear()

func (*IncomingPacket) Release

func (p *IncomingPacket) Release() bool

func (*IncomingPacket) SetAddr

func (p *IncomingPacket) SetAddr(addr net.Addr)

func (*IncomingPacket) SetTime

func (p *IncomingPacket) SetTime(t time.Time)

func (*IncomingPacket) Time

func (p *IncomingPacket) Time() time.Time

func (*IncomingPacket) Use

func (p *IncomingPacket) Use() *IncomingPacket

type IncomingPayload

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

func NewIncomingPayload

func NewIncomingPayload() *IncomingPayload

func (*IncomingPayload) AddContent

func (p *IncomingPayload) AddContent(content []byte) *IncomingPayload

func (*IncomingPayload) AddContents

func (p *IncomingPayload) AddContents(contents ...[]byte) *IncomingPayload

func (*IncomingPayload) Bytes

func (p *IncomingPayload) Bytes() []byte

func (*IncomingPayload) Clear

func (p *IncomingPayload) Clear()

func (*IncomingPayload) Content

func (p *IncomingPayload) Content() []byte

func (*IncomingPayload) Extends

func (p *IncomingPayload) Extends() [][]byte

func (*IncomingPayload) Range

func (p *IncomingPayload) Range(f func(chunk []byte) bool) bool

func (*IncomingPayload) Read

func (p *IncomingPayload) Read(buf []byte) (n int, err error)

func (*IncomingPayload) SetContent

func (p *IncomingPayload) SetContent(content []byte) *IncomingPayload

func (*IncomingPayload) SetContents

func (p *IncomingPayload) SetContents(contents [][]byte) *IncomingPayload

func (*IncomingPayload) Size

func (p *IncomingPayload) Size() int

func (*IncomingPayload) WriteTo

func (p *IncomingPayload) WriteTo(w io.Writer) (n int64, err error)

type Layer

type Layer interface {
	Version() uint8

	HasPadding() bool

	HasExtension() bool

	CSRCCount() uint8

	Marker() bool

	SetMarker(maker bool)

	PayloadType() uint8

	SetPayloadType(payloadType uint8)

	SequenceNumber() uint16

	SetSequenceNumber(seq uint16)

	Timestamp() uint32

	SetTimestamp(timestamp uint32)

	SSRC() uint32

	SetSSRC(ssrc uint32)

	CSRCList() []uint32

	SetCSRCList(csrcList []uint32)

	AddCSRC(csrc uint32)

	AddCSRCList(csrcList ...uint32)

	ExtensionProfile() uint16

	SetExtensionProfile(profile uint16)

	ExtensionLength() uint16

	ExtensionContents() []uint32

	SetExtensionContents(contents []uint32)

	AddExtensionContent(content uint32)

	AddExtensionContents(contents ...uint32)

	PaddingLength() uint8

	SetPaddingLength(length uint8)

	DumpHeader(header *Header)

	Payload() Payload

	Size() int

	Bytes() []byte

	io.Reader

	io.WriterTo

	fmt.Stringer
}

func ProvideIncomingLayer

func ProvideIncomingLayer() Layer

type Packet

type Packet interface {
	Layer

	AddRelation(relation pool.Reference)

	Clear()

	pool.Reference
}

func UsePacket

func UsePacket(packet Packet) Packet

type Parser

type Parser struct {
	//ID     byte
	Layer  *IncomingLayer
	Length uint16
	// contains filtered or unexported fields
}

func (*Parser) Parse

func (p *Parser) Parse(buf []byte) (ok bool, remain []byte, err error)

type Payload

type Payload interface {
	Size() int

	Bytes() []byte

	io.Reader

	io.WriterTo

	Clear()
}

func ProvideIncomingPayload

func ProvideIncomingPayload() Payload

type Reader

type Reader struct {
	Reader io.Reader
}

func (*Reader) Read

func (r *Reader) Read() (layer *IncomingLayer, err error)

type Writer

type Writer struct {
	Writer io.Writer
}

func (*Writer) Write

func (w *Writer) Write(layer *IncomingLayer) error

Jump to

Keyboard shortcuts

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