WebRTC extension

The architecture of the WebRTC extension is composed by:

  • Overlay P2P: a peer-to-peer network
  • PSng: who receive an RTP stream and send it to the P2STR plugin
  • P2STR plugin: convert the RTP stream in SRTP and send it to the browser
  • Browser: show the stream in a video tag using the WebRTC api

In the following figure you can see the full architecture of the project.

Few notes on Janus and its streaming plugin

P2STR

WebRTC ("Web Real-Time Communication") is a suite of communications protocols and application programming interfaces that enables real-time communication over peer-to-peer connections.
WebRTC supports applications such as video conferencing, file transfer, chat, or desktop sharing without the need of back-ends.

Peer-to-streaming (P2STR) is a Janus plugin converting an RTP stream to a WebRTC stream (comprising of all the involved protocols, such as: SRTP, DLEP, DTLS...).
It exposes a ReST inteface which integrates with the Janus core one in order to drive the building and managing of these RTP/WebRTC bridges dynamically through HTTP calls.
It is worth noticing, the RTP stream in input must be encoded following the WebRTC standards, namely VP8 and Vorbis and the output RTP stream will be served with the same characteristics.

P2STR comprises of two, tigthly connected modules:
  • a C, server side, Janus extension (p2str.c);
  • a Javascript, client side library (p2str.js).

Janus managing interface

In order to orchestrate WebRTC resources, Janus architecture requires first to bind to valid Janus sessions and plugin handles.
Since PeerStreamer-ng requires the constant monitoring and operation on Janus plugins it maintains a managing session through which it can send the actual commands.

At its very beginning, PeerStreamer-ng calls:
  • create: to create Janus session;
  • attach: to create a plugin handle for the session.

RTP2WebRTC

This aspect refers to the video consumer part of PeerStreamer-ng.
In this target scenario, a client picks a streaming channel name and clicks to visualize it.

p2str.js implements the following interface:
  • createJanus();
  • startStream(streamID);

The first one instantiates a WebRTC peer capable of interacting with the running Janus instance of PeerStreamer-ng.
The startStream function is responsible of requesting Janus for a particular streaming instance and visualize the video in the HTML related component.

P2STR Janus extension implements the following interface:
  • {\"request\": \"create\", \"type\": \"rtp\"}: to create a streaming mountpoint for a given input RTP stream;
  • {\"request\": \"destroy\", \"id\": <streamID>}: to destroy a given streaming mountpoint;
  • {\"request\": \"watch\", \"id\": <streamID>}: to join an RTP stream through a valid WebRTC connection;
  • {\"request\": \"start\", \"id\": <streamID>}: to start streaming an incoming RTP stream through a valid WebRTC connection;
  • {\"request\": \"stop\", \"id\": <streamID>}: to stop streaming an incoming RTP stream through a valid WebRTC connection;

The managing of the mountpoint is left to the core of PeerStreamer-ng which is responsible of setting up and down the RTP streamings.
The latter three P2STR calls are instead demanded to the web client interface which, through the browser API and Janus Javascript library, can create valid WebRTC connections.

  1. the web client request a stream by calling _POST /channels/<stream_id> with payload ipaddr=<sourceip>&port=<sourceport> _
  2. PeerStreamer-ng
    1. instantiates a P2P streamer for the P2P source <sourceip>,<sourceport>;
    2. st the output of that streamer toward a convenient set of RTP ports <port_audio>,<port_video>;
    3. calls the P2STR request http://localhost:8088/janus/&lt;mgmt_session&gt;/&lt;mgmt_handle> --data "{\"transaction\": \"random\", \"janus\": \"message\", \"body\": {\"request\": \"create\", \"type\": \"rtp\",\"audio\": true, \"audioport\": <port_audio>, \"audiopt\": 111, \"audiortpmap\": \"opus/48000/2\",\"video\": true, \"videoport\": <port_video>, \"videopt\": 100, \"videortpmap\": \"VP8/90000\"}}
      and it collects the JSON answer containing the streamID;
    4. returns the newly created channel description inclusive of the streamID to the web client.
  3. the web client can finally call startStream(streamID) which
    1. calls the 'watch' method of P2STR Janus extension;
    2. create a video component and redirect the incoming media to it.

WebRTC2RTP

This aspect refers to the video distributor part of PeerStreamer-ng.
In this target scenario, a client wants to stream its webcam stream through PeerStreamer-ng

p2str.js implements the following interface:
  • createJanus();
  • startSource(streamID);

The first one instantiates a WebRTC peer capable of interacting with the running Janus instance of PeerStreamer-ng.
The startSource function is responsible of sending Janus content for a particular streamID (identifying a unique position).

P2STR Janus extension implements the following interface:
  • {\"request\": \"create\", \"type\": \"webrtc2rtp\"}: to create a valid bridge instance between WebRTC and RTP ports (it returns the streamID);
  • {\"request\": \"destroy\", \"id\": <streamID>}: to destroy the bridge.

Both calls are intended to be called by PeerStreamer-ng, which is also the one managing the RTP ports to be open.

  1. the web client requests to stream by calling POST /mysources/<channel_name>
  2. PeerStreamer-ng
    1. instantiates a P2P streamer source listening to the selected RTP ports;
    2. calls the P2STR request to create a webrtc2rtp bridge;
    3. returns the newly created channel description inclusive of the streamID to the web client.
  3. the web client can finally call startSource(streamID) which
    1. captures the webcam video;
    2. send the video to the Janus WebRTC instance.

P2STR.png (30.9 KB) Orgest Shehaj, 11/16/2017 04:14 PM