Setting up WebRTC SDP

2,642 views
Skip to first unread message

Paul Poupet

unread,
Nov 26, 2015, 6:05:31 AM11/26/15
to discuss-webrtc

Hi everybody,

I have been trying to transmit some high quality audio stream through WebRTC. Opus, the main advertised codec seems perfect since it can support up to 510kbit/s, way more than needed. The problem is, setting up the Webrtc SDP is way less obvious than it seems. Thanks to Muaz Khan great work, I have been able to force it to 128kbit/s. Basically the code looks like that: 

 function setBandwidth(sdp) {
 var sdpLines = sdp.split('\r\n');


// Find opus payload.
var opusIndex = findLine(sdpLines, 'a=rtpmap', 'opus/48000');
var opusPayload;
if (opusIndex) {
    opusPayload = '109';
}
sdpLines[opusIndex]='a=rtpmap:'+opusPayload+' opus/48000/2';


   var mediaIndex = findLine(sdpLines, 'm=audio');
sdpLines[mediaIndex]=(sdpLines[mediaIndex].slice(0,(sdpLines[mediaIndex].indexOf("RTP/SAVPF")+10))).concat(opusPayload); 
 var abIndex = findLine(sdpLines, 'a=mid:');
  sdpLines[abIndex]='a=mid:audio\r\nb=AS:300000';

// Find the payload in fmtp line.
  var fmtpLineIndex = findLine(sdpLines, 'a=fmtp:' + opusPayload.toString());

if (fmtpLineIndex == null) {
    sdpLines[opusIndex] = sdpLines[opusIndex].concat('\r\n'+'a=fmtp:' + opusPayload.toString()+ ' minptime=10; useinbandfec=1; maxaveragebitrate='+128*1024+'; stereo=1; sprop-stereo=1 ; cbr=1');
     sdp = sdpLines.join('\r\n');

    return sdp;
}

// Append stereo=1 to fmtp line.
// added maxaveragebitrate here; about 50 kbits/s
// added stereo=1 here for stereo audio
// x-google-min-bitrate=50; x-google-max-bitrate=50
sdpLines[fmtpLineIndex] = sdpLines[fmtpLineIndex].concat('; maxaveragebitrate='+128*1024+'; stereo=1; sprop-stereo=1 ; cbr=1');


sdp = sdpLines.join('\r\n');
return sdp;
}

So now everything is set, both firefox and chrome display the right value for sender and receiver, the communication opens, the music is played!

adding answer-sdp v=0
o=mozilla...THIS_IS_SDPARTA-42.0 502631676322875352 0 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256.....
a=ice-options:trickle
a=msid-semantic:WMS *
m=audio 9 RTP/SAVPF 109 
c=IN IP4 0.0.0.0
a=recvonly
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=ice-pwd:c56d106030599efe08cfa2a4f9b3ad5a
a=ice-ufrag:93982a76
a=mid:audio
b=AS:300000
a=rtcp-mux
a=rtpmap:109 opus/48000/2
a=fmtp:109 minptime=10; useinbandfec=1; maxaveragebitrate=131072; stereo=1; sprop-stereo=1 ; cbr=1
a=setup:active
a=ssrc:1948755120 cname:{208483df-13c9-e347-ba4a-c71604df3ad9}

But the quality is terrible. Chrome shows about 30kbit/s on chrome://webrtc-internals/ and the sound is heavily distorted with variable volume... 


Thanks a lot,


Paul

Christoffer Jansson

unread,
Nov 27, 2015, 3:59:30 AM11/27/15
to discuss-webrtc
Hi,

Do you get the same result if you do Firefox to Firefox and Chrome to Chrome?

Seems like firefox does not support B=AS yet, https://bugzilla.mozilla.org/show_bug.cgi?id=976521.

/Chris

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/acdf4d0d-2107-4e85-ace7-0f7d6b84cf8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christoffer Jansson

unread,
Nov 27, 2015, 4:31:49 AM11/27/15
to discuss-webrtc
Hi,

Talked about this with a colleague and maxaveragebitrate is only what it can receive, if not set, it's at the maximum 510. The problem is that there is no way to change the send bit-rate, B=AS only sets the max bandwidth for the channel, it does not tell the encoder what bit-rate to use. I might be wrong but AFAIK currently you can only tell the encoder what bit-rate you want in the Native API's.

And also regarding my last comment, if Firefox does not support B=AS (which seems to be the case), it does not make sense to try Firefox to Firefox (other than to confirm it does not support B=AS) ;)

/Chris
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.

Minyue Li

unread,
Nov 27, 2015, 9:41:57 AM11/27/15
to discuss-webrtc
I think maxaveragebitrate does change the rate.

You may try


In there, you can modify the SDP. Add 
"; maxaveragebitrate=131072; stereo=1; sprop-stereo=1 ; cbr=1"

Then I get a 1xx kbps stream.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages