native webrtc (objc) で audio track に echo cancel, auto gain control などのオプションを設定する

音声を送る場合は

let audioTrack = factory.audioTrackWithID("...")

のような感じで作るがオプション (RTCMediaConstraints) を現状 RTCPeerConnectionFactory からだと渡せないのでやはり自前で書く必要がある

- (RTCAudioTrack*)audioTrackWithID:(NSString*)audioId constraints:(RTCMediaConstraints*)constraints {
    
    rtc::scoped_refptr<webrtc::AudioSourceInterface> source = self.nativeFactory->CreateAudioSource(constraints.constraints);
    rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
    self.nativeFactory->CreateAudioTrack([audioId UTF8String], source);
    return [[RTCAudioTrack alloc] initWithMediaTrack:track];
}

このようなメソッドを用意し

        let audioConstraints = RTCMediaConstraints(mandatoryConstraints: [
            RTCPair(key: "googAutoGainControl", value: "false"),
            RTCPair(key: "googAutoGainControl2", value: "false"),
            RTCPair(key: "googEchoCancellation", value: "false"),
            RTCPair(key: "googEchoCancellation2", value: "false"),
            RTCPair(key: "googNoiseSuppression", value: "false"),
            RTCPair(key: "googNoiseSuppression2", value: "false"),
            RTCPair(key: "googHighpassFilter", value: "false"),
            ], optionalConstraints: [])
        
        let audioTrack = factory.audioTrackWithID("...", constraints: audioConstraints)

上のように audio track を作ると echo cancel, auto gain control などを無効・有効に出来る。 人間の会話を送る場合は特にこれらを無効にする必用はないが、音楽などを送る場合は適してないので無効にすると良い。

ここで指定出来るオプションはここに書いてある。

video のほうは track と source が分かれて method がちゃんと生えてるのでこのようなことをする必用はない。