Skip to content

Commit

Permalink
webrtc: add advanced audio settings
Browse files Browse the repository at this point in the history
autoGainControl, echoCancellation, and noiseSuppression are audio
processing options that are usually enabled by default on WebRTC input
tracks.

This commit adds the possibility to enable/disable them, as they can be
undesirable in some cases (audiophile use cases). For example, one might
want to stream electronic dance music, which is basically noise, so it
should not be suppressed in that specific case.

Note that these are not exact settings, they are set as "ideal" in order
not to break anything on devices where those constraints are not
implemented.

Signed-off-by: László Várady <laszlo.varady@protonmail.com>
  • Loading branch information
MrAnno committed Jun 5, 2022
1 parent e35ede0 commit 28f353d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/webrtc/mediaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ import { logger } from "../logger";
import { MatrixClient } from "../client";
import { CallState } from "./call";

export interface AudioSettings {
autoGainControl: boolean;
echoCancellation: boolean;
noiseSuppression: boolean;
}

export class MediaHandler {
private audioInput: string;
private audioSettings?: AudioSettings;
private videoInput: string;
private localUserMediaStream?: MediaStream;
public userMediaStreams: MediaStream[] = [];
Expand All @@ -44,6 +51,17 @@ export class MediaHandler {
await this.updateLocalUsermediaStreams();
}

/**
* Set audio settings for MatrixCalls
* @param {AudioSettings} opts audio options to set
*/
public async setAudioSettings(opts: AudioSettings): Promise<void> {
logger.info("LOG settings audio settings to", opts);

this.audioSettings = Object.assign({}, opts) as AudioSettings;
await this.updateLocalUsermediaStreams();
}

/**
* Set a video input device to use for MatrixCalls
* @param {string} deviceId the identifier for the device
Expand Down Expand Up @@ -253,6 +271,9 @@ export class MediaHandler {
audio: audio
? {
deviceId: this.audioInput ? { ideal: this.audioInput } : undefined,
autoGainControl: this.audioSettings ? { ideal: this.audioSettings.autoGainControl } : undefined,
echoCancellation: this.audioSettings ? { ideal: this.audioSettings.echoCancellation } : undefined,
noiseSuppression: this.audioSettings ? { ideal: this.audioSettings.noiseSuppression } : undefined,
}
: false,
video: video
Expand Down

0 comments on commit 28f353d

Please sign in to comment.