webrtc_rtp_opus (webrtc v0.1.0)
View SourceOpus RTP payload format (RFC 7587).
There is nothing to packetize: each RTP payload is exactly one Opus packet (RFC 6716 §3), which may itself hold one or more frames, and Opus packets are never fragmented (RFC 7587 §4.2). The RTP clock rate is always 48000 Hz whatever the audio bandwidth (§4.1), and the timestamp advances by the packet duration in 48 kHz samples.
toc/1 and duration/1 read the table-of-contents byte and the frame count of RFC 6716 §3.1 and §3.2 to compute the duration of a packet without decoding it, which is what a sender needs to advance the RTP timestamp.
Summary
Functions
Duration of an Opus packet in 48 kHz samples. Code 3 packets carry the frame count (1..48) in the second byte (§3.2.5); a packet longer than 120 ms is invalid (§3.4 [R5]).
One Opus packet per RTP payload.
Parse the TOC byte (RFC 6716 §3.1).
Types
-type toc() :: #{config := 0..31, mode := silk | hybrid | celt, stereo := boolean(), code := 0..3, frame_samples := pos_integer()}.
Functions
-spec clock_rate() -> 48000.
-spec duration(binary()) -> {ok, pos_integer()} | {error, empty | truncated | too_long | bad_frame_count}.
Duration of an Opus packet in 48 kHz samples. Code 3 packets carry the frame count (1..48) in the second byte (§3.2.5); a packet longer than 120 ms is invalid (§3.4 [R5]).
One Opus packet per RTP payload.
Parse the TOC byte (RFC 6716 §3.1).