From 17859a3c99c8828b8de1f9e8835591f57637fbb9 Mon Sep 17 00:00:00 2001 From: peng Date: Mon, 14 Sep 2020 16:23:47 +0800 Subject: [PATCH] audio_quality_enhancement --- src/sdk/base/mediastream-factory.js | 21 ++++++++++++++++++++- src/sdk/base/sdputils.js | 24 ++++++++++++++++++++++++ src/sdk/conference/channel.js | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/sdk/base/mediastream-factory.js b/src/sdk/base/mediastream-factory.js index a579041f..0099ec47 100644 --- a/src/sdk/base/mediastream-factory.js +++ b/src/sdk/base/mediastream-factory.js @@ -177,7 +177,26 @@ export class MediaStreamFactory { } } else { if (constraints.audio.source === MediaFormatModule.AudioSourceInfo.SCREENCAST) { - mediaConstraints.audio = true; + mediaConstraints.audio = {}; + if (constraints.audio.echoCancellation === false) { + mediaConstraints.audio.echoCancellation = constraints.audio.echoCancellation; + } + if (constraints.audio.autoGainControl === false) { + mediaConstraints.audio.autoGainControl = constraints.audio.autoGainControl; + } + if (constraints.audio.noiseSuppression === false) { + mediaConstraints.audio.noiseSuppression = constraints.audio.noiseSuppression; + } + if (constraints.audio.channelCount) { + mediaConstraints.audio.channelCount = constraints.audio.channelCount; + } + if (constraints.audio.sampleRate) { + mediaConstraints.audio.sampleRate = constraints.audio.sampleRate; + } + if (!constraints.audio.echoCancellation && !constraints.audio.autoGainControl && !constraints.audio.noiseSuppression && !constraints.audio.channelCount && !constraints.audio.sampleRate) { + mediaConstraints.audio = true; + } + } else { mediaConstraints.audio = constraints.audio; } diff --git a/src/sdk/base/sdputils.js b/src/sdk/base/sdputils.js index ef1a9251..34ad1410 100644 --- a/src/sdk/base/sdputils.js +++ b/src/sdk/base/sdputils.js @@ -685,6 +685,30 @@ export function addLegacySimulcast(sdp, type, numStreams) { return sdp; } +export function setOpusParam(sdp, audioOptions) { + let maxAverageBitrateKB; + if(audioOptions.__proto__ === Array.prototype){ + if(audioOptions[0].maxAverageBitrate !== undefined){ + maxAverageBitrateKB = audioOptions[0].maxAverageBitrate*1000; + sdp = setCodecParam( + sdp, 'opus/48000', 'maxaveragebitrate', maxAverageBitrateKB); + } + if(audioOptions[0].stereo && audioOptions[0].stereo === true){ + sdp = maybeSetOpusOptions(sdp, { + opusStereo: 'true' + }); + } + } + else{ + if(audioOptions.stereo && audioOptions.stereo === true){ + sdp = maybeSetOpusOptions(sdp, { + opusStereo: 'true' + }); + } + } + return sdp; + } + export function setMaxBitrate(sdp, encodingParametersList) { for (const encodingParameters of encodingParametersList) { if (encodingParameters.maxBitrate) { diff --git a/src/sdk/conference/channel.js b/src/sdk/conference/channel.js index cd41f1a1..056f29c7 100644 --- a/src/sdk/conference/channel.js +++ b/src/sdk/conference/channel.js @@ -732,10 +732,12 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { return sdp; } sdp = this._setMaxBitrate(sdp, options); + sdp = SdpUtils.setOpusParam(sdp, options.audio); return sdp; } _setRtpReceiverOptions(sdp, options) { + sdp = SdpUtils.setOpusParam(sdp, options.audio); // Add legacy simulcast in SDP for safari. if (this._isRtpEncodingParameters(options.video) && Utils.isSafari()) { if (options.video.length > 1) {