Documentation
¶
Overview ¶
Package rtpav moves goav media over RTP. In: a PacketReader seam over any transport (Pion types are used directly), jitter buffering, per-codec depacketizers (Opus, VP8, VP9, H264, AV1), and RTCP feedback builders; rtpav.Receive adapts a reader into a goav source provider for goav.From(...). Out: the matching packetizers, and rtpav.Send, a media destination over a PacketWriter (DialUDP) with sender reports, NACK retransmission, and keyframe and bitrate feedback.
Index ¶
- Variables
- func Send(writer PacketWriter, options ...SendOption) pipeline.Sink
- type AV1Depacketizer
- func (d *AV1Depacketizer) Codec() av.CodecID
- func (d *AV1Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
- func (d *AV1Depacketizer) HandleEvent(ctx context.Context, event *av.Event) error
- func (d *AV1Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, ...) error
- type BufferLimits
- type DepacketizeResult
- type Depacketizer
- type Feedback
- type FeedbackResult
- type FeedbackWriter
- type H264Depacketizer
- func (d *H264Depacketizer) Codec() av.CodecID
- func (d *H264Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
- func (d *H264Depacketizer) HandleEvent(ctx context.Context, event *av.Event) error
- func (d *H264Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, ...) error
- type Header
- type Input
- type JitterBuffer
- type JitterConfig
- type JitterResult
- type JitterRing
- func (b *JitterRing) FlushInto(ctx context.Context, out *JitterResult) error
- func (b *JitterRing) PopInto(ctx context.Context, pkt *rtp.Packet) (bool, error)
- func (b *JitterRing) PushInto(ctx context.Context, pkt *rtp.Packet, out *JitterResult) error
- func (b *JitterRing) Reset()
- func (b *JitterRing) Stats() JitterStats
- type JitterStats
- type OpusDepacketizer
- func (d *OpusDepacketizer) Codec() av.CodecID
- func (d *OpusDepacketizer) FlushInto(context.Context, *DepacketizeResult) error
- func (d *OpusDepacketizer) HandleEvent(ctx context.Context, event *av.Event) error
- func (d *OpusDepacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, ...) error
- type Packet
- type PacketReader
- type PacketWriter
- type PacketizeResult
- type Packetizer
- type PayloadCodec
- type PayloadMap
- type ReadRTPFunc
- type ReceiveOption
- func WithBufferLimits(limits BufferLimits) ReceiveOption
- func WithCodec(spec codec.Spec) ReceiveOption
- func WithDecodeBounds(bounds codec.DecodeBounds) ReceiveOption
- func WithDepacketizers(depacketizers ...Depacketizer) ReceiveOption
- func WithFeedback(feedback FeedbackWriter) ReceiveOption
- func WithJitter(jitter JitterBuffer) ReceiveOption
- func WithMaxTimestampGap(gap av.Duration) ReceiveOption
- func WithName(name string) ReceiveOption
- type SendOption
- type SequenceDetector
- type SequenceState
- type Source
- type SourceConfig
- type StaticPayloadMap
- type StaticReader
- type VP8Depacketizer
- func (d *VP8Depacketizer) Codec() av.CodecID
- func (d *VP8Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
- func (d *VP8Depacketizer) HandleEvent(ctx context.Context, event *av.Event) error
- func (d *VP8Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, ...) error
- type VP9Depacketizer
- func (d *VP9Depacketizer) Codec() av.CodecID
- func (d *VP9Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
- func (d *VP9Depacketizer) HandleEvent(ctx context.Context, event *av.Event) error
- func (d *VP9Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, ...) error
- type VideoDepacketizerOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOrderedConfigurationRequired refuses a configuration change on an // explicitly static legacy reader; event channels cannot prove ordering. ErrOrderedConfigurationRequired = errors.New("rtpav: ordered configuration read required") // ErrInvalidConfiguration reports a missing map or an unannounced change. ErrInvalidConfiguration = errors.New("rtpav: invalid ordered configuration") // ErrEpochRegression reports a stream's read map moving backwards. ErrEpochRegression = errors.New("rtpav: configuration epoch regressed") // ErrAmbiguousStream reports packet configuration without enough stream // identity to choose among equal codecs on different tracks. ErrAmbiguousStream = errors.New("rtpav: ambiguous RTP stream") // ErrJitterStreamConflict refuses interleaved streams through one jitter // window. Configure a separate receive Source and jitter buffer per track. ErrJitterStreamConflict = errors.New("rtpav: jitter buffer requires one stream") // ErrInvalidJitterCapacity reports a jitter ring sized <= 0. ErrInvalidJitterCapacity = errors.New("rtpav: invalid jitter capacity") // ErrClosed reports a read on a closed source or reader. ErrClosed = errors.New("rtpav: closed") // ErrNilReceiver reports a nil PacketReader handed to Receive. ErrNilReceiver = errors.New("rtpav: nil receiver") // ErrInvalidPayload reports an RTP payload the depacketizer cannot parse. ErrInvalidPayload = errors.New("rtpav: invalid payload") // ErrPayloadNotFound reports a payload type the PayloadMap cannot resolve. ErrPayloadNotFound = errors.New("rtpav: payload not found") // ErrDepacketizerNotFound reports a codec with no registered depacketizer. ErrDepacketizerNotFound = errors.New("rtpav: depacketizer not found") // ErrFrameTooLarge reports a reassembled frame exceeding the configured // maximum video frame size, or an Opus packet too large for the MTU. ErrFrameTooLarge = errors.New("rtpav: frame too large") // ErrResultFull reports a result slice at capacity. ErrResultFull = errors.New("rtpav: result capacity full") // ErrPacketizerNotFound reports a codec with no built-in packetizer. ErrPacketizerNotFound = errors.New("rtpav: packetizer not found") // ErrNoTimestamp reports a packet to send with neither a PTS nor a DTS. ErrNoTimestamp = errors.New("rtpav: packet has no timestamp") // ErrNilWriter reports a nil PacketWriter handed to Send. ErrNilWriter = errors.New("rtpav: nil writer") // ErrUnknownStream reports a packet for a stream Send was not opened with. ErrUnknownStream = errors.New("rtpav: unknown stream") )
RTP sentinels, matched with errors.Is.
Functions ¶
func Send ¶
func Send(writer PacketWriter, options ...SendOption) pipeline.Sink
Send is the RTP output: a media destination for goav.Sink (or a provider.DestinationScheme) that packetizes the packets routed to it and writes them through writer, one SSRC per stream. It declares the codecs it accepts, so the planner encodes frames to one of them, and that it is live, so the planner paces what it is fed in real time; learns its streams, with their extradata, before the first packet; sends RTCP sender reports; answers NACK from a bounded history as it arrives; and turns PLI and FIR into a keyframe control and REMB into a bitrate control on the encoder that feeds the stream, between 64 kb/s and the bitrate the recipe configured (2.5 Mb/s when it set none). Closing it sends BYE and closes writer.
Types ¶
type AV1Depacketizer ¶
type AV1Depacketizer struct {
// contains filtered or unexported fields
}
AV1Depacketizer converts AV1 RTP aggregation payloads into bounded packets.
func NewAV1Depacketizer ¶
func NewAV1Depacketizer(stream av.Stream, options ...VideoDepacketizerOption) *AV1Depacketizer
NewAV1Depacketizer assembles AV1 RTP payloads into AV1 low-overhead bitstream packets.
func (*AV1Depacketizer) Codec ¶
func (d *AV1Depacketizer) Codec() av.CodecID
Codec reports the codec this depacketizer reassembles.
func (*AV1Depacketizer) FlushInto ¶
func (d *AV1Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
FlushInto discards any partial temporal unit at end of stream.
func (*AV1Depacketizer) HandleEvent ¶
HandleEvent resets reassembly state on discontinuities.
func (*AV1Depacketizer) PushInto ¶
func (d *AV1Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, out *DepacketizeResult) error
PushInto consumes one RTP packet of AV1 aggregation elements, appending a completed temporal-unit packet to out when the packet finishes one.
type BufferLimits ¶
BufferLimits bounds the reusable scratch capacity of a receive Source: ready packets per jitter push, events, feedback packets, and depacketized packets. Zero fields keep the Source defaults.
type DepacketizeResult ¶
DepacketizeResult is the caller-owned output buffer depacketizers fill: reassembled codec packets, events (loss, discontinuity), and RTCP feedback to send.
func (*DepacketizeResult) Reset ¶
func (r *DepacketizeResult) Reset()
Reset clears the result for reuse, keeping allocated capacity.
type Depacketizer ¶
type Depacketizer interface {
Codec() av.CodecID
PushInto(context.Context, *rtp.Packet, PayloadCodec, *DepacketizeResult) error
FlushInto(context.Context, *DepacketizeResult) error
HandleEvent(context.Context, *av.Event) error
}
Depacketizer reassembles one codec's RTP payloads into av.Packets: PushInto consumes RTP in order (possibly emitting zero or more packets), FlushInto drains a partial tail, HandleEvent reacts to in-band events.
type FeedbackResult ¶
type FeedbackResult struct {
Packets []rtcp.Packet
NACKPairs []rtcp.NackPair
FIREntries []rtcp.FIREntry
// contains filtered or unexported fields
}
FeedbackResult is a caller-owned, allocation-free builder for outgoing RTCP feedback: AddNACK/AddPLI/AddFIR append into preallocated capacity and Packets is what a FeedbackWriter sends.
func (*FeedbackResult) AddFIR ¶
func (r *FeedbackResult) AddFIR(senderSSRC uint32, mediaSSRC uint32, sequenceNumber uint8) error
AddFIR appends one full-intra request with the given FIR sequence number.
func (*FeedbackResult) AddNACK ¶
func (r *FeedbackResult) AddNACK(senderSSRC uint32, mediaSSRC uint32, missing []uint16) error
AddNACK appends one transport-layer NACK covering the missing sequence numbers (compressed into NACK pairs).
func (*FeedbackResult) AddPLI ¶
func (r *FeedbackResult) AddPLI(senderSSRC uint32, mediaSSRC uint32) error
AddPLI appends one picture-loss indication asking the sender for a new keyframe.
func (*FeedbackResult) Reset ¶
func (r *FeedbackResult) Reset()
Reset clears the result for reuse, keeping allocated capacity.
type FeedbackWriter ¶
FeedbackWriter sends RTCP feedback (NACK, PLI, FIR) back toward the sender; receivers that cannot send feedback simply do not implement it.
type H264Depacketizer ¶
type H264Depacketizer struct {
// contains filtered or unexported fields
}
H264Depacketizer converts H264 RTP payloads into Annex B access-unit packets.
func NewH264Depacketizer ¶
func NewH264Depacketizer(stream av.Stream, options ...VideoDepacketizerOption) *H264Depacketizer
NewH264Depacketizer assembles H264 RTP packets into bounded Annex B payloads.
func (*H264Depacketizer) Codec ¶
func (d *H264Depacketizer) Codec() av.CodecID
Codec reports the codec this depacketizer reassembles.
func (*H264Depacketizer) FlushInto ¶
func (d *H264Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
FlushInto discards any partial access unit at end of stream.
func (*H264Depacketizer) HandleEvent ¶
HandleEvent resets reassembly state on discontinuities.
func (*H264Depacketizer) PushInto ¶
func (d *H264Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, out *DepacketizeResult) error
PushInto consumes one RTP packet (single NALU, STAP-A, or FU-A), appending a completed Annex B access unit to out when the packet finishes one.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input is the RTP receive provider: it owns a PacketReader plus receive intent (jitter buffer, feedback writer, codec, buffer limits, decode bounds, timestamp-gap policy) and opens it as a running pipeline source.
Example ¶
ExampleInput opens an RTP receive provider as a goav recipe input: the provider seam carries the transport, goav carries the recipe.
package main
import (
"context"
"fmt"
"io"
"github.com/pion/rtp"
"github.com/thesyncim/goav"
"github.com/thesyncim/goav/av"
"github.com/thesyncim/goav/bundle"
"github.com/thesyncim/goav/codec"
"github.com/thesyncim/goav/rtpav"
)
// staticRTPReader is a minimal rtpav.PacketReader: one declared Opus stream
// and an immediately ended packet feed.
type staticRTPReader struct{}
func (staticRTPReader) Streams(context.Context) ([]av.Stream, error) {
return []av.Stream{{ID: "audio", Type: av.MediaAudio, Codec: av.CodecParameters{ID: av.CodecOpus, Type: av.MediaAudio}}}, nil
}
func (staticRTPReader) PayloadMap() rtpav.PayloadMap { return nil }
func (staticRTPReader) ReadRTP(context.Context) (*rtp.Packet, *av.Event, rtpav.PayloadMap, error) {
return nil, nil, nil, io.EOF
}
func (staticRTPReader) Events() <-chan av.Event { return nil }
func (staticRTPReader) Close() error { return nil }
// ExampleInput opens an RTP receive provider as a goav recipe input: the
// provider seam carries the transport, goav carries the recipe.
func main() {
mic := goav.From(rtpav.Receive(staticRTPReader{}, rtpav.WithName("mic"), rtpav.WithCodec(codec.Opus())))
report, err := bundle.Explain(context.Background(), mic.Audio().To(goav.Write("mic.webm", io.Discard)))
if err != nil {
fmt.Println(err)
return
}
in := report.Inputs[0]
fmt.Printf("input=%s codec=%s realtime=%t\n", in.Name, in.Codec, in.Realtime)
}
Output: input=mic codec=opus realtime=true
func Receive ¶
func Receive(receiver PacketReader, options ...ReceiveOption) *Input
Receive builds an RTP receive Input around a packet reader. Without WithCodec or WithDepacketizers, each stream the reader reports gets its codec's built-in depacketizer. Equal-codec tracks require StreamID in each read's payload map so their assemblies stay separate.
func (*Input) DecodeBounds ¶
func (in *Input) DecodeBounds(id av.StreamID) codec.DecodeBounds
DecodeBounds returns the configured decode bounds when the stream belongs to this input, and a zero value otherwise. Streams are the ones resolved by the most recent OpenSource call.
func (*Input) OpenSource ¶
OpenSource resolves the receiver streams and depacketizers and opens the running pipeline source.
func (*Input) SourceShape ¶
SourceShape declares the packet-domain realtime shape of this input, plus any media facts asserted by the codec intent.
type JitterBuffer ¶
type JitterBuffer interface {
PushInto(context.Context, *rtp.Packet, *JitterResult) error
PopInto(context.Context, *rtp.Packet) (bool, error)
FlushInto(context.Context, *JitterResult) error
Reset()
Stats() JitterStats
}
JitterBuffer reorders out-of-order RTP: PushInto admits a packet and releases whatever became in-order, PopInto drains one ready packet, FlushInto drains everything at a boundary. Reset discards buffered packets and clears sequence/SSRC state for a new stream incarnation. Source drains the old window before resetting at removal, replacement, or discontinuity. Decorators must preserve Reset along with the packet operations.
type JitterConfig ¶
type JitterConfig struct {
Capacity int
}
JitterConfig sizes a JitterRing: Capacity is the reorder window in packets.
type JitterResult ¶
type JitterResult struct {
Ready []*rtp.Packet
Events []av.Event
Feedback []rtcp.Packet
State SequenceState
}
JitterResult is the caller-owned output buffer jitter operations fill: packets released in order, events, RTCP feedback to send, and the observed sequence state.
func (*JitterResult) Reset ¶
func (r *JitterResult) Reset()
Reset clears the result for reuse, keeping allocated capacity.
type JitterRing ¶
type JitterRing struct {
// contains filtered or unexported fields
}
JitterRing is a fixed-capacity, allocation-free JitterBuffer: packets slot by their distance from the next expected sequence number and release in order, with loss and reordering surfaced as events and stats. Positioning is relative to expected, never raw sequence modulo capacity, so any capacity orders correctly across the uint16 wrap.
func NewJitterRing ¶
func NewJitterRing(config JitterConfig) (*JitterRing, error)
NewJitterRing builds a ring with the configured reorder window.
func (*JitterRing) FlushInto ¶
func (b *JitterRing) FlushInto(ctx context.Context, out *JitterResult) error
FlushInto drains every buffered packet in sequence order at end of stream.
func (*JitterRing) PopInto ¶
PopInto drains one ready in-order packet into pkt, reporting whether one was available.
func (*JitterRing) PushInto ¶
func (b *JitterRing) PushInto(ctx context.Context, pkt *rtp.Packet, out *JitterResult) error
PushInto admits one packet and appends whatever became in-order to out, recording loss, lateness, and SSRC resets along the way.
func (*JitterRing) Reset ¶
func (b *JitterRing) Reset()
Reset clears the ring for reuse with a new stream.
func (*JitterRing) Stats ¶
func (b *JitterRing) Stats() JitterStats
Stats reports the ring's current counters.
type JitterStats ¶
type JitterStats struct {
SSRC uint32
Buffered int
Expected uint16
Lost uint64
Late uint64
Reordered uint64
EstimatedDelay time.Duration
}
JitterStats is a point-in-time view of a jitter buffer: occupancy, loss, lateness, reordering, and estimated delay.
type OpusDepacketizer ¶
type OpusDepacketizer struct {
// contains filtered or unexported fields
}
OpusDepacketizer turns Opus RTP payloads into av.Packets — one packet per RTP payload, stamped with the stream's clock-rate timing.
func NewOpusDepacketizer ¶
func NewOpusDepacketizer(stream av.Stream) *OpusDepacketizer
NewOpusDepacketizer builds a depacketizer for the given stream, defaulting the clock rate to 48000 when undeclared.
func (*OpusDepacketizer) Codec ¶
func (d *OpusDepacketizer) Codec() av.CodecID
Codec reports the codec this depacketizer reassembles.
func (*OpusDepacketizer) FlushInto ¶
func (d *OpusDepacketizer) FlushInto(context.Context, *DepacketizeResult) error
FlushInto is a no-op: Opus payloads never span RTP packets.
func (*OpusDepacketizer) HandleEvent ¶
HandleEvent observes in-band events; Opus depacketizing keeps no state to reset.
func (*OpusDepacketizer) PushInto ¶
func (d *OpusDepacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, out *DepacketizeResult) error
PushInto converts one RTP packet into one Opus av.Packet appended to out.
type PacketReader ¶
type PacketReader interface {
Streams(context.Context) ([]av.Stream, error)
PayloadMap() PayloadMap
ReadRTP(context.Context) (*rtp.Packet, *av.Event, PayloadMap, error)
Events() <-chan av.Event
Close() error
}
PacketReader is the transport seam Receive adapts. ReadRTP atomically returns a packet, an optional preceding event, and that record's immutable payload map. Event-only records are legal. Configuration events travel through this operation; Events is a best-effort observer stream, never the data contract. A map whose entries carry StreamID belongs to that one stream, with its own monotonic epoch. Untagged maps can cover several distinct codecs and use a session-wide epoch; any configuration event announces its next generation. A changed epoch requires a configuration event. StreamRemoved ends a tagged stream's incarnation; StreamAdded can start it again at a new initial epoch. A packet already in flight retains its old map. Reads are sequential. Packet and event memory may be reused only after the next ReadRTP; maps stay immutable. Legacy readers with a fixed configuration can use Static.
func DecorateReader ¶
func DecorateReader(reader PacketReader, wrap func(ReadRTPFunc) ReadRTPFunc) PacketReader
DecorateReader intercepts the authoritative atomic read for logging, metrics, or tracing, while preserving the reader's other operations and optional RTCP. The decorator must preserve packet/event/map ordering and propagate errors.
func Static ¶
func Static(reader StaticReader, payloads PayloadMap) PacketReader
Static adapts a fixed-configuration legacy reader with an owned, frozen map. Dynamic configuration events fail explicitly. It cannot reconstruct atomic configuration from a legacy reader; dynamic transports must migrate ReadRTP.
type PacketWriter ¶
type PacketWriter interface {
FeedbackWriter
WriteRTP(context.Context, *rtp.Packet) error
ReadRTCP(context.Context) ([]rtcp.Packet, error)
Close() error
}
PacketWriter is the transport seam Send writes through: RTP out, RTCP both ways. ReadRTCP blocks until feedback arrives and fails once the writer closes. WriteRTP is called from the data path and, to retransmit, from the feedback loop, so it must be safe for concurrent use. DialUDP returns one over UDP; webrtcav adapts Pion tracks.
type PacketizeResult ¶
PacketizeResult is the caller-owned output buffer packetizers fill: one access unit's RTP packets in send order, their payloads held in one arena the result reuses. Payloads stay valid until Reset; a result reused across access units allocates only while it grows to the largest one.
func (*PacketizeResult) Reset ¶
func (r *PacketizeResult) Reset()
Reset clears the result for reuse, keeping allocated capacity.
type Packetizer ¶
type Packetizer interface {
Codec() av.CodecID
PacketizeInto(context.Context, *av.Packet, PayloadCodec, *PacketizeResult) error
}
Packetizer splits one codec's av.Packets into RTP packets, the inverse of a Depacketizer: PacketizeInto appends one access unit's packets to out, with the payload type, timestamp (the packet's PTS on the payload clock), marker, and payload set. The sender owns SSRC and sequence numbers.
func NewPacketizer ¶
func NewPacketizer(stream av.Stream, options ...SendOption) (Packetizer, error)
NewPacketizer builds the packetizer of the stream's codec: Opus, VP8, VP9, H264 (single NAL, STAP-A, FU-A, with SPS/PPS before every IDR), or AV1 (OBU aggregation). The stream's extradata seeds the parameter sets an IDR or AV1 keyframe is sent with; in-band ones replace them. WithMTU bounds the packets. A codec with no built-in packetizer returns ErrPacketizerNotFound.
type PayloadCodec ¶
type PayloadCodec struct {
PayloadType uint8
// StreamID disambiguates equal codecs and payload types on different
// tracks. An atomic read's map describes the track that produced it.
StreamID av.StreamID
Parameters av.CodecParameters
MIMEType string
ClockRate uint32
Channels uint16
FMTP string
Attributes av.Metadata
}
PayloadCodec maps one RTP payload type to its negotiated codec: the codec parameters plus the SDP facts (MIME, clock rate, channels, fmtp) the receiver learned out of band.
type PayloadMap ¶
type PayloadMap interface {
Epoch() av.Epoch
Lookup(payloadType uint8) (PayloadCodec, bool)
Codecs() []PayloadCodec
}
PayloadMap resolves RTP payload types to codecs. Epoch increments when the mapping renegotiates, so consumers detect codec changes without comparing whole maps.
type ReadRTPFunc ¶
ReadRTPFunc is the single atomic read operation, including event-only records.
type ReceiveOption ¶
type ReceiveOption func(*Input)
ReceiveOption configures an Input under construction.
func WithBufferLimits ¶
func WithBufferLimits(limits BufferLimits) ReceiveOption
WithBufferLimits bounds the source scratch buffers.
func WithCodec ¶
func WithCodec(spec codec.Spec) ReceiveOption
WithCodec declares the codec carried by this input; a matching default depacketizer (Opus, VP8, VP9, H264, AV1) is derived at open.
func WithDecodeBounds ¶
func WithDecodeBounds(bounds codec.DecodeBounds) ReceiveOption
WithDecodeBounds seeds codec.DecodeConfig.Bounds for decoders fed by this input.
func WithDepacketizers ¶
func WithDepacketizers(depacketizers ...Depacketizer) ReceiveOption
WithDepacketizers registers explicit depacketizers; nil entries are skipped.
func WithFeedback ¶
func WithFeedback(feedback FeedbackWriter) ReceiveOption
WithFeedback routes RTCP feedback to an explicit writer instead of the receiver itself.
func WithJitter ¶
func WithJitter(jitter JitterBuffer) ReceiveOption
WithJitter orders packets through a jitter buffer before depacketizing.
func WithMaxTimestampGap ¶
func WithMaxTimestampGap(gap av.Duration) ReceiveOption
WithMaxTimestampGap emits a discontinuity when a positive packet timestamp delta exceeds this threshold. Backward timestamps always emit one.
func WithName ¶
func WithName(name string) ReceiveOption
WithName names the source node and selects the stream the codec intent applies to.
type SendOption ¶
type SendOption func(*sendConfig)
SendOption configures the RTP send side: NewPacketizer reads WithMTU, and Send reads them all.
func WithHistory ¶
func WithHistory(packets int) SendOption
WithHistory keeps the last packets of each stream for NACK retransmission (default 512); 0 keeps none, for a transport that retransmits itself.
func WithMTU ¶
func WithMTU(size int) SendOption
WithMTU caps every RTP packet at size bytes, its 12-byte header included (default 1200). Sizes below 28 are raised to 28.
func WithPayloads ¶
func WithPayloads(payloads PayloadMap) SendOption
WithPayloads sets the payload type and clock rate each codec is sent with, looked up by codec, and limits what Send accepts to those codecs; the default sends Opus as 111, VP8 as 96, VP9 as 98, H264 as 102, and AV1 as 45.
func WithReportInterval ¶
func WithReportInterval(interval time.Duration) SendOption
WithReportInterval sets the RTCP sender-report cadence (default 1s); 0 sends none, for a transport that reports itself.
type SequenceDetector ¶
type SequenceDetector struct {
// contains filtered or unexported fields
}
SequenceDetector tracks RTP sequence numbers across wraparound, reporting loss, reordering, and SSRC changes per pushed packet.
func (*SequenceDetector) Push ¶
func (d *SequenceDetector) Push(pkt *rtp.Packet, missing []uint16) SequenceState
Push advances the detector with one packet, filling missing (capacity permitting) and returning the observed sequence state.
func (*SequenceDetector) Reset ¶
func (d *SequenceDetector) Reset()
Reset clears the detector for a new stream.
type SequenceState ¶
type SequenceState struct {
SSRC uint32
Cycles uint32
Expected uint16
Missing []uint16
MissingTruncated bool
LossBefore bool
Discontinuous bool
}
SequenceState reports what RTP sequence tracking observed around the current packet: missing sequence numbers, loss before this packet, and discontinuity.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source adapts a PacketReader into a pipeline.Source: RTP is read, optionally reordered, depacketized into av.Packets, stamped with media timestamps, and emitted with loss/discontinuity events; RTCP feedback flows back through the FeedbackWriter.
func NewSource ¶
func NewSource(config SourceConfig) (*Source, error)
NewSource builds an RTP source; the receiver is required and unset bounds take small defaults.
func (*Source) DescribeNode ¶
DescribeNode reports the source's spec entry for Describe.
func (*Source) DroppedMessages ¶
DroppedMessages counts incomplete built-in access units discarded at a configuration, removal, or discontinuity boundary.
type SourceConfig ¶
type SourceConfig struct {
Name string
Detail string
Receiver PacketReader
Feedback FeedbackWriter
Jitter JitterBuffer
Depacketizers []Depacketizer
Streams []av.Stream
// MaxTimestampGap emits a discontinuity when a positive packet timestamp
// delta exceeds this threshold. Backward timestamps always emit one.
MaxTimestampGap av.Duration
MaxReady int
MaxEvents int
MaxFeedback int
MaxPackets int
}
SourceConfig assembles an RTP Source: the transport reader, optional feedback writer and jitter buffer, the depacketizers per codec, and the per-read output bounds.
type StaticPayloadMap ¶
type StaticPayloadMap struct {
// contains filtered or unexported fields
}
StaticPayloadMap is a fixed PayloadMap over a known codec list — the right shape when the payload mapping was negotiated once, out of band.
func NewStaticPayloadMap ¶
func NewStaticPayloadMap(epoch av.Epoch, codecs []PayloadCodec) StaticPayloadMap
NewStaticPayloadMap builds a fixed map at the given epoch.
func (StaticPayloadMap) Codecs ¶
func (m StaticPayloadMap) Codecs() []PayloadCodec
Codecs lists every mapped payload codec.
func (StaticPayloadMap) Epoch ¶
func (m StaticPayloadMap) Epoch() av.Epoch
Epoch reports the mapping generation it was built with.
func (StaticPayloadMap) Lookup ¶
func (m StaticPayloadMap) Lookup(payloadType uint8) (PayloadCodec, bool)
Lookup resolves one payload type to its codec. Reference fields are borrowed immutable values; use Codecs for an independently owned copy.
type StaticReader ¶
type StaticReader interface {
Streams(context.Context) ([]av.Stream, error)
PayloadMap() PayloadMap
ReadRTP(context.Context) (*rtp.Packet, error)
Events() <-chan av.Event
Close() error
}
StaticReader is the legacy transport interface, supported only when its configuration is fixed for its entire lifetime.
type VP8Depacketizer ¶
type VP8Depacketizer struct {
// contains filtered or unexported fields
}
VP8Depacketizer reassembles VP8 RTP payloads into whole-frame av.Packets, detecting keyframes and dropping fragments interrupted by loss.
func NewVP8Depacketizer ¶
func NewVP8Depacketizer(stream av.Stream, options ...VideoDepacketizerOption) *VP8Depacketizer
NewVP8Depacketizer builds a VP8 depacketizer for the given stream.
func (*VP8Depacketizer) Codec ¶
func (d *VP8Depacketizer) Codec() av.CodecID
Codec reports the codec this depacketizer reassembles.
func (*VP8Depacketizer) FlushInto ¶
func (d *VP8Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
FlushInto discards any partial frame at end of stream.
func (*VP8Depacketizer) HandleEvent ¶
HandleEvent resets reassembly state on discontinuities.
func (*VP8Depacketizer) PushInto ¶
func (d *VP8Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, out *DepacketizeResult) error
PushInto consumes one RTP packet, appending a completed VP8 frame to out when the packet finishes one.
type VP9Depacketizer ¶
type VP9Depacketizer struct {
// contains filtered or unexported fields
}
VP9Depacketizer reassembles VP9 RTP payloads into whole-frame av.Packets, detecting keyframes and dropping fragments interrupted by loss.
func NewVP9Depacketizer ¶
func NewVP9Depacketizer(stream av.Stream, options ...VideoDepacketizerOption) *VP9Depacketizer
NewVP9Depacketizer builds a VP9 depacketizer for the given stream.
func (*VP9Depacketizer) Codec ¶
func (d *VP9Depacketizer) Codec() av.CodecID
Codec reports the codec this depacketizer reassembles.
func (*VP9Depacketizer) FlushInto ¶
func (d *VP9Depacketizer) FlushInto(context.Context, *DepacketizeResult) error
FlushInto discards any partial frame at end of stream.
func (*VP9Depacketizer) HandleEvent ¶
HandleEvent resets reassembly state on discontinuities.
func (*VP9Depacketizer) PushInto ¶
func (d *VP9Depacketizer) PushInto(ctx context.Context, pkt *rtp.Packet, payload PayloadCodec, out *DepacketizeResult) error
PushInto consumes one RTP packet, appending a completed VP9 frame to out when the packet finishes one.
type VideoDepacketizerOption ¶
type VideoDepacketizerOption func(*videoDepacketizerConfig)
VideoDepacketizerOption configures a video depacketizer constructor.
func WithMaxVideoFrameSize ¶
func WithMaxVideoFrameSize(size int) VideoDepacketizerOption
WithMaxVideoFrameSize caps the bytes one reassembled video frame may reach; larger frames are refused with ErrFrameTooLarge.