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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufferPoolSize = unit.KiBiByte * 256
	DefaultBufferReverse  = 2048
)
View Source
const (
	BaseHeaderSize = 12
	MaxCSRCs       = 15
	MaxExtensions  = math.MaxUint16
)

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包大小不够")
)

Functions

func OutputLayerProvider

func OutputLayerProvider(payloadProvider func() Payload) func() Layer

func OutputPacketProvider

func OutputPacketProvider(payloadProvider func() Payload) func(pool pool.Pool[*OutputPacket]) *OutputPacket

Types

type CSRCs

type CSRCs interface {
	// contains filtered or unexported methods
}

type DefaultExtension

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

func (*DefaultExtension) Append

func (e *DefaultExtension) Append(contents ...uint32)

func (*DefaultExtension) Clear

func (e *DefaultExtension) Clear()

func (*DefaultExtension) Get

func (e *DefaultExtension) Get(i int) uint32

func (*DefaultExtension) Len

func (e *DefaultExtension) Len() int

func (*DefaultExtension) Profile

func (e *DefaultExtension) Profile() uint16

func (*DefaultExtension) Replace

func (e *DefaultExtension) Replace(contents ...uint32)

func (*DefaultExtension) Set

func (e *DefaultExtension) Set(i int, content uint32)

func (*DefaultExtension) SetProfile

func (e *DefaultExtension) SetProfile(profile uint16)

func (*DefaultExtension) Size

func (e *DefaultExtension) Size() int

type DefaultHeader

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

func (*DefaultHeader) CSRCs

func (h *DefaultHeader) CSRCs() CSRCs

func (*DefaultHeader) Clear

func (h *DefaultHeader) Clear()

func (*DefaultHeader) Extension

func (h *DefaultHeader) Extension() Extension

func (*DefaultHeader) HasExtension

func (h *DefaultHeader) HasExtension() bool

func (*DefaultHeader) HasPadding

func (h *DefaultHeader) HasPadding() bool

func (*DefaultHeader) Marker

func (h *DefaultHeader) Marker() bool

func (*DefaultHeader) PayloadType

func (h *DefaultHeader) PayloadType() uint8

func (*DefaultHeader) SSRC

func (h *DefaultHeader) SSRC() uint32

func (*DefaultHeader) SequenceNumber

func (h *DefaultHeader) SequenceNumber() uint16

func (*DefaultHeader) SetMarker

func (h *DefaultHeader) SetMarker(maker bool)

func (*DefaultHeader) SetPayloadType

func (h *DefaultHeader) SetPayloadType(payloadType uint8)

func (*DefaultHeader) SetSSRC

func (h *DefaultHeader) SetSSRC(ssrc uint32)

func (*DefaultHeader) SetSequenceNumber

func (h *DefaultHeader) SetSequenceNumber(seq uint16)

func (*DefaultHeader) SetTimestamp

func (h *DefaultHeader) SetTimestamp(timestamp uint32)

func (*DefaultHeader) Timestamp

func (h *DefaultHeader) Timestamp() uint32

func (*DefaultHeader) Version

func (h *DefaultHeader) Version() uint8

func (*DefaultHeader) WriteTo

func (h *DefaultHeader) WriteTo(w io.Writer) (n int64, err error)

type Extension

type Extension interface {
	Profile() uint16
	SetProfile(profile uint16)
	// contains filtered or unexported methods
}

type Handler

type Handler interface {
	HandlePacket(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)

	OnParseError(stream Stream, err error) (keep bool)

	OnStreamClosed(stream Stream)
}
type Header interface {
	Version() uint8
	HasPadding() bool
	HasExtension() bool
	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)
	CSRCs() CSRCs
	Extension() Extension
	io.WriterTo
	Clear()
}

type IncomingPayload

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

func NewIncomingPayload

func NewIncomingPayload() *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) Range

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

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 InputLayer

type InputLayer struct {
	DefaultHeader
	// contains filtered or unexported fields
}

func NewInputLayer

func NewInputLayer() *InputLayer

func (*InputLayer) Bytes

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

func (*InputLayer) Clear

func (l *InputLayer) Clear()

func (*InputLayer) PaddingLength

func (l *InputLayer) PaddingLength() uint8

func (*InputLayer) Payload

func (l *InputLayer) Payload() Payload

func (*InputLayer) SetPaddingLength

func (l *InputLayer) SetPaddingLength(length uint8)

func (*InputLayer) Size

func (l *InputLayer) Size() int

func (*InputLayer) String

func (l *InputLayer) String() string

func (*InputLayer) Unmarshal

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

func (*InputLayer) UnmarshalChunks

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

func (*InputLayer) WriteTo

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

type InputPacket

type InputPacket struct {
	*InputLayer
	// contains filtered or unexported fields
}

InputPacket 通常用于承载外部接受到的RTP包,可以标记对端地址、接收时间戳等信息,并且使用 InputLayer 作为RTP包的载体

func NewInputPacket

func NewInputPacket(layer *InputLayer, pool pool.Pool[*InputPacket]) *InputPacket

func ProvideInputPacket

func ProvideInputPacket(p pool.Pool[*InputPacket]) *InputPacket

func (*InputPacket) AddRef

func (p *InputPacket) AddRef()

func (*InputPacket) AddRelation

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

func (*InputPacket) Addr

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

func (*InputPacket) Clear

func (p *InputPacket) Clear()

func (*InputPacket) Release

func (p *InputPacket) Release() bool

func (*InputPacket) SetAddr

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

func (*InputPacket) SetTime

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

func (*InputPacket) Time

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

func (*InputPacket) Use

func (p *InputPacket) Use() *InputPacket

type Layer

type Layer interface {
	Header
	Payload() Payload
	PaddingLength() uint8
	SetPaddingLength(length uint8)
	Size() int
	Bytes() []byte
	fmt.Stringer
}

Layer 接口为RTP报文的结构化接口,通过此接口可以获取或修改RTP报文的结构

func ProvideInputLayer

func ProvideInputLayer() Layer

type OutputLayer

type OutputLayer struct {
	DefaultHeader
	// contains filtered or unexported fields
}

func NewOutputLayer

func NewOutputLayer(payload Payload) *OutputLayer

func (*OutputLayer) Bytes

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

func (*OutputLayer) Clear

func (l *OutputLayer) Clear()

func (*OutputLayer) Init

func (l *OutputLayer) Init(payload Payload)

func (*OutputLayer) PaddingLength

func (l *OutputLayer) PaddingLength() uint8

func (*OutputLayer) Payload

func (l *OutputLayer) Payload() Payload

func (*OutputLayer) SetPaddingLength

func (l *OutputLayer) SetPaddingLength(length uint8)

func (*OutputLayer) SetPayload

func (l *OutputLayer) SetPayload(payload Payload)

func (*OutputLayer) Size

func (l *OutputLayer) Size() int

func (*OutputLayer) String

func (l *OutputLayer) String() string

func (*OutputLayer) WriteTo

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

type OutputPacket

type OutputPacket struct {
	OutputLayer
	// contains filtered or unexported fields
}

func NewOutputPacket

func NewOutputPacket(pool pool.Pool[*OutputPacket], payload Payload) *OutputPacket

func (*OutputPacket) AddRef

func (p *OutputPacket) AddRef()

func (*OutputPacket) AddRelation

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

func (*OutputPacket) Clear

func (p *OutputPacket) Clear()

func (*OutputPacket) Release

func (p *OutputPacket) Release() bool

func (*OutputPacket) Use

func (p *OutputPacket) Use() *OutputPacket

type Packet

type Packet interface {
	Layer
	pool.RelationsReference
}

Packet 接口在 Layer 接口的基础上定义了关联引用计数的相关行为

func UsePacket

func UsePacket(packet Packet) Packet

type Padding

type Padding uint8

func (Padding) Len

func (p Padding) Len() uint8

func (Padding) WriteTo

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

type Parser

type Parser struct {
	Layer  *InputLayer
	Length uint16
	// contains filtered or unexported fields
}

func (*Parser) Parse

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

func (*Parser) Reset

func (p *Parser) Reset()

type Payload

type Payload interface {
	Size() int
	Bytes() []byte
	io.WriterTo
	Clear()
}

func ProvideIncomingPayload

func ProvideIncomingPayload() Payload

type Server

type Server interface {
	lifecycle.Lifecycle

	log.LoggerProvider

	Addr() net.Addr
}

type SliceCSRCs

type SliceCSRCs []uint32

func (*SliceCSRCs) Append

func (cs *SliceCSRCs) Append(csrcs ...uint32)

func (*SliceCSRCs) Clear

func (cs *SliceCSRCs) Clear()

func (*SliceCSRCs) Get

func (cs *SliceCSRCs) Get(i int) uint32

func (*SliceCSRCs) Len

func (cs *SliceCSRCs) Len() int

func (*SliceCSRCs) Replace

func (cs *SliceCSRCs) Replace(csrcs ...uint32)

func (*SliceCSRCs) Set

func (cs *SliceCSRCs) Set(i int, csrc uint32)

func (*SliceCSRCs) Size

func (cs *SliceCSRCs) Size() int

type Stream

type Stream interface {
	Handler() Handler

	SetHandler(handler Handler) Stream

	SSRC() int64

	SetSSRC(ssrc int64) Stream

	LocalAddr() net.Addr

	RemoteAddr() net.Addr

	SetRemoteAddr(addr net.Addr) Stream

	Timeout() time.Duration

	SetTimeout(timeout time.Duration) Stream

	GetOnTimeout() func(Stream)

	SetOnTimeout(onTimeout func(Stream)) Stream

	OnLossPacket() func(stream Stream, loss int)

	SetOnLossPacket(onLossPacket func(stream Stream, loss int)) Stream

	CloseConn() bool

	SetCloseConn(enable bool) Stream

	Send(layer rtp.Layer) error

	Close()

	log.LoggerProvider
}

Jump to

Keyboard shortcuts

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