webrtc_rtp_vp8 (webrtc v0.1.0)

View Source

VP8 RTP payload descriptor (RFC 7741 §4.2) without decoding media.

parse/1 reads the payload descriptor; is_keyframe/1 checks the inverse key frame bit of the VP8 payload header (§4.3), present in the first packet of a frame (S = 1, PID = 0). rewrite/2 patches the picture ID and TL0PICIDX in place, keeping the 7 or 15 bit picture ID width of the packet, which is what a forwarding unit needs to keep these fields continuous when it switches between simulcast layers. packetize/3 splits an encoded frame into payloads; frame_size/1 reads the size of a key frame.

Summary

Functions

Width and height of a key frame, from the start of its VP8 data (the payload of its first packet after the descriptor): the 3 byte frame tag, the start code 9d 01 2a, then the 14 bit width and height (RFC 6386 §9.1).

True when the payload starts a key frame: S = 1, partition 0 and the P bit of the VP8 payload header is 0 (RFC 7741 §4.3).

Split an encoded VP8 frame into RTP payloads of at most Mtu bytes, each with a payload descriptor. Options: picture_id (15-bit), tl0picidx, tid and layer_sync (the temporal layer and the Y bit), non_reference. The first payload has S = 1; the caller sets the RTP marker bit on the last one.

Parse the payload descriptor. Returns the descriptor and the VP8 payload that follows it.

Rewrite picture_id and / or tl0picidx in a payload. The new picture ID is truncated to the width used by the packet. Fails when a field to rewrite is not present.

Types

descriptor/0

-type descriptor() ::
          #{non_reference := boolean(),
            start := boolean(),
            partition := 0..7,
            picture_id := undefined | {7 | 15, non_neg_integer()},
            tl0picidx := undefined | 0..255,
            tid := undefined | 0..3,
            layer_sync := undefined | boolean(),
            keyidx := undefined | 0..31,
            size := pos_integer()}.

Functions

frame_size(_)

-spec frame_size(binary()) -> {ok, {pos_integer(), pos_integer()}} | error.

Width and height of a key frame, from the start of its VP8 data (the payload of its first packet after the descriptor): the 3 byte frame tag, the start code 9d 01 2a, then the 14 bit width and height (RFC 6386 §9.1).

is_keyframe(Payload)

-spec is_keyframe(binary()) -> boolean().

True when the payload starts a key frame: S = 1, partition 0 and the P bit of the VP8 payload header is 0 (RFC 7741 §4.3).

packetize(Frame, Mtu, Opts)

-spec packetize(binary(),
                pos_integer(),
                #{picture_id => 0..32767,
                  tl0picidx => 0..255,
                  tid => 0..3,
                  layer_sync => boolean(),
                  non_reference => boolean()}) ->
                   [binary()].

Split an encoded VP8 frame into RTP payloads of at most Mtu bytes, each with a payload descriptor. Options: picture_id (15-bit), tl0picidx, tid and layer_sync (the temporal layer and the Y bit), non_reference. The first payload has S = 1; the caller sets the RTP marker bit on the last one.

parse(_)

-spec parse(binary()) -> {ok, descriptor(), binary()} | {error, truncated}.

Parse the payload descriptor. Returns the descriptor and the VP8 payload that follows it.

rewrite(Payload, Changes)

-spec rewrite(binary(), #{picture_id => non_neg_integer(), tl0picidx => 0..255}) ->
                 {ok, binary()} | {error, truncated | {absent, picture_id | tl0picidx}}.

Rewrite picture_id and / or tl0picidx in a payload. The new picture ID is truncated to the width used by the packet. Fails when a field to rewrite is not present.