webrtc_rtp_vp9 (webrtc v0.1.0)

View Source

VP9 RTP payload format (RFC 9628): payload descriptor, key frame detection, frame size and packetization.

A payload starts a key frame of the base layer when the frame does not use inter-picture prediction (P = 0), it is the first packet of the frame (B = 1) and, when layer indices are present, the spatial layer is 0.

parse/1 reads the descriptor (§4.2): picture ID, layer indices, the reference indices of flexible mode and the scalability structure. parse_payload/1 also returns the VP9 data after it. frame_size/1 reads the size of a key frame from its uncompressed header. packetize/3 splits one layer frame into payloads.

Summary

Functions

Width and height of a key frame from its uncompressed header (VP9 bitstream specification §6.2): frame marker, profile, frame type, the sync code 49 83 42, the color config, then the frame size.

Split one layer frame into RTP payloads of at most Mtu bytes, each with a descriptor. Options: picture_id (15 bit), inter_predicted (default true), tid, sid, tl0picidx (layer indices in non-flexible mode), flexible with refs (P_DIFF list), switching_up, inter_layer, not_reference, and layer_sizes, a scalability structure with the size of each spatial layer, sent in the first payload. B is set on the first payload and E on the last; the caller sets the RTP marker bit on the last payload of the picture.

Parse the descriptor.

Parse the descriptor; also return the VP9 data that follows it.

Types

descriptor/0

-type descriptor() ::
          #{inter_predicted := boolean(),
            flexible := boolean(),
            start := boolean(),
            'end' := boolean(),
            picture_id := undefined | {7 | 15, non_neg_integer()},
            tid := undefined | 0..7,
            sid := undefined | 0..7,
            tl0picidx := undefined | 0..255,
            switching_up := undefined | boolean(),
            inter_layer := undefined | boolean(),
            refs := [1..127],
            layer_sizes := undefined | [{0..65535, 0..65535}],
            not_reference := boolean()}.

Functions

frame_size(_)

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

Width and height of a key frame from its uncompressed header (VP9 bitstream specification §6.2): frame marker, profile, frame type, the sync code 49 83 42, the color config, then the frame size.

is_keyframe(Payload)

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

packetize(Frame, Mtu, Opts)

-spec packetize(binary(), pos_integer(), map()) -> [binary()].

Split one layer frame into RTP payloads of at most Mtu bytes, each with a descriptor. Options: picture_id (15 bit), inter_predicted (default true), tid, sid, tl0picidx (layer indices in non-flexible mode), flexible with refs (P_DIFF list), switching_up, inter_layer, not_reference, and layer_sizes, a scalability structure with the size of each spatial layer, sent in the first payload. B is set on the first payload and E on the last; the caller sets the RTP marker bit on the last payload of the picture.

parse(Payload)

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

Parse the descriptor.

parse_payload(_)

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

Parse the descriptor; also return the VP9 data that follows it.