Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC - Receive video from another peer using an offer from an audio-only stream

Tags:

html

webrtc

Is is possible to receive both video and audio from another peer if the peer who called createOffer() only allowed audio when requested via getUserMedia()?

Explanation by scenario:

  1. Alice connects to a signalling server, and when getUserMedia() is called, chooses to share both video and audio.
  2. Bob connects to the signalling server, and when getUserMedia() is called, only shares audio.
  3. As Bob is the last to party, Bob creates the peer connection offer via RTCPeerConnection.createOffer(). He shares his localDescription which contains SDP data that does not mention video.
  4. The resultant connection is audio-only as the SDP data only contained audio-related information.

Can an offer be created that asks to receive video data without sharing it?

like image 289
Arite Avatar asked Apr 20 '15 00:04

Arite


1 Answers

So the key was in the creation of the offer.

Referring to the Specification

The WebRTC 1.0 specification says:

4.2.5 Offer/Answer Options

These dictionaries describe the options that can be used to control the offer/answer creation process.

dictionary RTCOfferOptions {
    long    offerToReceiveVideo;
    long    offerToReceiveAudio;
    boolean voiceActivityDetection = true;
    boolean iceRestart = false;
};

In the case of video:

offerToReceiveVideo of type long

In some cases, an RTCPeerConnection may wish to receive video but not send any video. The RTCPeerConnection needs to know if it should signal to the remote side whether it wishes to receive video or not. This option allows an application to indicate its preferences for the number of video streams to receive when creating an offer.

Solution

RTCPeerConnection.createOffer() can take MediaConstraints as an optional third parameter.

The example I found was from the WebRTC for Beginners article:

Creating Offer SDP

peerConnection.createOffer(function (sessionDescription) {
    peerConnection.setLocalDescription(sessionDescription);

    // POST-Offer-SDP-For-Other-Peer(sessionDescription.sdp, sessionDescription.type);

}, function(error) {
    alert(error);
}, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });

These MediaContraints can also be used with createAnswer().

like image 100
Arite Avatar answered Sep 19 '22 11:09

Arite