5 comments on “How to limit WebRTC bandwidth by modifying the SDP

  1. Got this from Nils (Firefox team): The blog post should mention that b=AS only works with Chrome. For Firefox you need to look for b=TIAS to accomplish the same.

    • Hey @Victor,

      Are you sure about that point?

      I currently seems to “work” for me on Firefox 51 & 52 ;
      At least it doesn’t trigger any error when setting the updated RTCSessionDescription as remote description.
      Maybe it doesn’t have any effect on bandwidth, though? How to mesure it?

      And I am wondering, as “b=AS” is following the RFC 3556, what would be the point for Firefox not to follow it?

  2. Hey,

    Thanks for this tip,
    If you’re interested, here is an ES6 rewrite of the same method 🙂
    Feel free to use it if you wish.

    setMediaBitrate(sdp, mediaType, bitrate) {
    let sdpLines = sdp.split(‘\n’),
    mediaLineIndex = -1,
    mediaLine = ‘m=’ + mediaType,
    bitrateLineIndex = -1,
    bitrateLine = ‘b=AS:’ + bitrate,
    mediaLineIndex = sdpLines.findIndex(line => line.startsWith(mediaLine));

    // If we find a line matching “m={mediaType}”
    if (mediaLineIndex && mediaLineIndex < sdpLines.length) {
    // Skip the media line
    bitrateLineIndex = mediaLineIndex + 1;

    // Skip both i=* and c=* lines (bandwidths limiters have to come afterwards)
    while (sdpLines[bitrateLineIndex].startsWith('i=') || sdpLines[bitrateLineIndex].startsWith('c=')) {

    if (sdpLines[bitrateLineIndex].startsWith('b=')) {
    // If the next line is a b=* line, replace it with our new bandwidth
    sdpLines[bitrateLineIndex] = bitrateLine;
    } else {
    // Otherwise insert a new bitrate line.
    sdpLines.splice(bitrateLineIndex, 0, bitrateLine);

    // Then return the updated sdp content as a string
    return sdpLines.join('\n');

  3. With this we limit download bandwidth or upload bandwidth or both? If answer is both. Is there a way to control each one of them individually?

Leave a Reply

Your email address will not be published. Required fields are marked *