rtp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: ISC Imports: 6 Imported by: 3

Documentation

Overview

Package rtp implements the Real-Time Transport Protocol as specified in RFC 3550.

Index

Constants

View Source
const (
	VersionDraft   uint8 = 1 << 6
	VersionRFC3550       = 1 << 7
)
View Source
const (
	ClockMP2T     = 90000 // 90KHz
	ClockPCMAudio = 44100 // 44.1KHz
	ClockText     = 1000  // 1KHz
)

Variables

View Source
var ErrNoPayload = errors.New("no payload")

Functions

func Marshal

func Marshal(p *Packet) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, p *Packet) error

Types

type Extension

type Extension struct {
	Profile [2]byte
	Data    []byte
}
type Header struct {
	// Version specifies the version of RTP used in the Packet.
	// In practice, the only version in use is VersionRFC3550.
	Version uint8

	// Marker indicates the marker bit is set. The payload type
	// determines how this value is interpreted.
	Marker bool

	// Type specifies the format of the payload transported in the Packet.
	// In general, each type has its own IETF RFC specifying how the payload is encoded.
	// For example, PayloadMP2T is detailed in RFC 2250.
	Type PayloadType

	// Sequence is a monotonically incremented number used by
	// receivers to manage packet loss. The first packet's Sequence
	// should be randomly assigned, then incremented by one for each
	// RTP packet transmitted.
	Sequence uint16

	// Timestamp is the instant sampled of the first byte of the packet.
	// The first packet in a session should have a randomly assigned
	// timestamp. Subsequent timestamps are calculated according to a
	// monotonically incrementing clock. The clock frequency, and how the
	// timestamp should be interpreted, is dictated by the payload type. For
	// instance, the Timestamp field of RTP packets with MPEG payloads
	// represents the number of ticks of a 90KHz clock. Timestamps of GSM
	// audio RTP packets represent ticks of a 8KHz clock.
	Timestamp uint32

	// SyncSource identifies the synchronisation source of the RTP
	// session. It should be randomly assigned at the start of a
	// session and remain unchanged throughout to prevent
	// collisions with other sessions.
	SyncSource uint32

	// ContribSource lists a maximum of 15 contribution sources
	// used to generate the payload. For example, a RTP session for
	// audio transport may list each SyncSource in ContribSource.
	ContribSource []uint32

	// Extension is an optional field which may be used by certain
	// payloads to transmit extra information. The RTP specification
	// discourages the use of Extension. Instead it recommendeds to
	// store extra information in leading bytes of the payload.
	Extension *Extension
	// contains filtered or unexported fields
}

Header represents the "Fixed Header" specified in RFC 3550 section 5.1.

type Packet

type Packet struct {
	// Header is the RTP fixed header present at the beginning of
	// every packet.
	Header Header
	// Payload contains the raw bytes, excluding the header,
	// transported in a packet.
	Payload []byte
}

Packet represents a single RTP data packet.

type PayloadType

type PayloadType uint8
const (
	PayloadL16Stereo PayloadType = 10
	PayloadL16Mono   PayloadType = 11
	PayloadMP2T      PayloadType = 33
)

func DynamicPayloadType

func DynamicPayloadType() PayloadType

DynamicPayloadType returns a randomly generated PayloadType from the range of allowed values for payloads with non-static PayloadType values. For example, transporting text and JPEG XS with RTP requires the use of a dynamic payload type.

func (PayloadType) String

func (t PayloadType) String() string

type Session

type Session struct {
	// Clock is the rate of the... in hertz.
	// If zero, automatic detection attempted...
	Clock int
	// contains filtered or unexported fields
}

Session represents a RTP session... When a Session is established with Dial(), ... TODO(otl): what does session automatically handle? what do we not need to set in each packets header?

func Dial

func Dial(network, addr string) (*Session, error)

func (*Session) Transmit

func (s *Session) Transmit(packet *Packet) error

Transmit sends the packet to the destination address in s.

TODO(otl): some fields in packet's header are set by Transmit. Which ones? Otherwise people are going to get surprised!

Jump to

Keyboard shortcuts

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