drachtio / drachtio-fsmrf

Drachtio freeswitch-based media resource function -- http://davehorton.github.io/drachtio-fsmrf
MIT License
47 stars 26 forks source link

Adding method to modify MRF SDP before its sent back to client #65

Open lylepratt opened 1 year ago

lylepratt commented 1 year ago

I needed to add some SDP fields to improve WebRTC video quality on Chrome and Safari. This required that I intercept the SDP coming back from FreeSwitch before its passed back to the WebRTC client.

In my case I'm adding these fields on all a=fmtp lines:

x-google-max-bitrate=6000;x-google-min-bitrate=2000;x-google-start-bitrate=2000

I enabled this functionality by adding an optional function that can be passed to mediaserver.connectCaller called modifyMrfSdpResponse.

Here is an example of it being used:

        var {endpoint, dialog} = await thisMediaServer.connectCaller(this.req, this.res, {modifyMrfSdpResponse: function(sdp) {
          var remoteArr = sdp.split('\r\n');
          remoteArr.forEach((str, i) => {
            if (/^a=fmtp:\d*/.test(str)) {
              remoteArr[i] = str + ';x-google-max-bitrate=6000;x-google-min-bitrate=2000;x-google-start-bitrate=4000';
            } else if (/^a=mid:(1|video)/.test(str)) {
              remoteArr[i] += '\r\nb=AS:6000';
            }
          });
          var newRemote = remoteArr.join('\r\n');
          return newRemote;
        }})  

With this implemented I have improved the quality of my video calls by many times. These SDP parameters are respected by both Chrome and Safar.