webrtc_codecs (webrtc_codecs v0.1.0)

View Source

Codec plugins for erlang_webrtc, and the plugin that picks one of them from the negotiated codec.

Set it on a transceiver, or for every transceiver a remote offer creates:

webrtc:add_transceiver(Pc, audio, #{frames => true, codec_plugin => {webrtc_codecs, #{}}}),
webrtc:new_peer_connection(#{frames => true, codec_plugins => #{audio => {webrtc_codecs, #{}}}}).

Opts go unchanged to the module of the negotiated codec; see each module for the options it reads. available/0 lists the codecs this build can decode and encode.

Raw media, what decode/2 gives and encode/2 takes, is described by picture/0 and audio/0. Timestamps are in the RTP clock of the negotiated codec in both directions.

Summary

Types

Raw audio: signed 16 bit little endian samples, interleaved by channel.

Raw media without a picture or samples: changes the encoder and sends nothing.

What a decoder gives in place of a picture or samples for a frame it could not decode. The frame is dropped; for video, ask the sender for a key frame with webrtc:request_keyframe/2.

A raw picture: I420 planes without padding, so y is width * height bytes and u and v are a quarter of that each. When the width or the height is odd, the chroma planes round it up: ((width + 1) div 2) * ((height + 1) div 2) bytes. timestamp is in 90 kHz units.

Functions

The codecs this build can decode or encode.

The plugin module for a codec name as SDP gives it (<<"PCMU">>, <<"VP8">>), whatever its case.

Types

audio()

-type audio() ::
          #{format := s16le,
            sample_rate := pos_integer(),
            channels := pos_integer(),
            samples := binary(),
            timestamp => non_neg_integer(),
            bitrate => pos_integer()}.

Raw audio: signed 16 bit little endian samples, interleaved by channel.

To an encoder, samples holds 10 or 20 ms, timestamp is optional (the encoder counts samples from the last one it was given, or from 0) and bitrate sets the target in bits per second.

codec_info()

-type codec_info() ::
          #{name := binary(),
            kind := audio | video,
            decode := boolean(),
            encode := boolean(),
            implementation := binary(),
            module := module()}.

control()

-type control() :: #{bitrate => pos_integer(), keyframe => boolean()}.

Raw media without a picture or samples: changes the encoder and sends nothing.

dropped()

-type dropped() :: #{dropped := term(), timestamp := non_neg_integer()}.

What a decoder gives in place of a picture or samples for a frame it could not decode. The frame is dropped; for video, ask the sender for a key frame with webrtc:request_keyframe/2.

picture()

-type picture() ::
          #{format := i420,
            width := pos_integer(),
            height := pos_integer(),
            y := binary(),
            u := binary(),
            v := binary(),
            timestamp := non_neg_integer(),
            keyframe => boolean(),
            bitrate => pos_integer()}.

A raw picture: I420 planes without padding, so y is width * height bytes and u and v are a quarter of that each. When the width or the height is odd, the chroma planes round it up: ((width + 1) div 2) * ((height + 1) div 2) bytes. timestamp is in 90 kHz units.

To an encoder, keyframe => true asks for a key frame (set it after {keyframe_request, Mid}) and bitrate sets the target in bits per second (set it after {bandwidth_estimate, Bps}).

Functions

available()

-spec available() -> [codec_info()].

The codecs this build can decode or encode.

module(Name)

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

The plugin module for a codec name as SDP gives it (<<"PCMU">>, <<"VP8">>), whatever its case.