Interop peer protocol

View Source

Every peer adapter (Pion, aiortc, browsers through a driver) is a process that speaks newline-delimited JSON on stdin and stdout. The Erlang test controller (test/interop/webrtc_interop_peer.erl) starts the adapter, sends commands and waits for events. This protocol exists only for tests; the library never depends on it.

Diagnostics go to stderr, which the controller saves next to the test logs.

Commands (controller to peer)

cmdfieldseffect
initmedia: list of "audio"/"video", channels: list of channel specs, ice_lite: bool, simulcast: boolCreate the peer connection. Channel specs are {label, ordered, max_retransmits, max_packet_life_time, negotiated, id, protocol}; they are created when the peer makes the offer. With simulcast, browsers send their video as three layers with rids q, h and f (scaled down by 4, 2 and 1), and Pion negotiates the MID, rid and repaired-rid header extensions to receive layers.
create_offerice_restart: boolCreate an offer, set it as local description, emit local_description.
remote_descriptiontype, sdpApply. When type is offer the peer answers and emits local_description.
remote_candidatecandidate, midAdd a trickled candidate. An empty candidate means end of candidates.
sendlabel, data, binary (data is base64 when binary)Send on a data channel.
create_channelchannel specOpen a new data channel after connection.
close_channellabelClose a data channel.
send_rtcpkind: sli or rrrPion: send RTCP about the video stream the Erlang side sends: SLI with First 1, Number 2, PictureID 3, or an RTCP-SR-REQ (RFC 6051).
statsEmit stats.
closeClose the peer connection and exit.

Events (peer to controller)

eventfields
readyimplementation, version
local_descriptiontype, sdp
local_candidatecandidate, mid (empty candidate: gathering complete)
ice_state, connection_state, signaling_statestate
channel_openlabel, id, protocol, ordered
channel_closelabel
messagelabel, data, binary
trackmid, kind, ssrc, codec, rid (Pion; empty without simulcast)
rtpmid, count, bytes (sent every 50 packets and on the first one), rid (Pion, per layer)
rtcpkind, type (sli, sr), ssrc, entries (Pion: SLI received about its tracks, SR about the tracks it receives, with t its arrival in Unix ms)
statsstats
errormessage

Behavior

  • Every data channel message received is sent back on the same channel prefixed with echo: (binary messages are echoed unchanged with a 4 byte echo prefix).
  • Every RTP packet received on a track is written back unchanged (payload, marker, timestamp) on the peer's local track of the same kind. The Erlang side checks the packets it gets back.