From d0679bd7e28ed43c656ed26014fb967f6df156e2 Mon Sep 17 00:00:00 2001 From: henrika Date: Tue, 9 Jul 2019 15:37:45 +0200 Subject: [PATCH] Enables usage of ChannelMixer in WebRTC's output mixer. Ensures that newly added ChannelMixer is utilized when number of channels is larger than two in the output mixer. Decided to land with henrik.lundin as TBR since he has reviewed all other changes in WebRTC related to channel mixing for multi-channel cases. All this CL does is to ensure that the new channel mixing scheme can be used in Chrome. The old scheme is still used for mono and stereo combinations. TBR: henrik.lundin Bug: webrtc:10783 Change-Id: I11c02f1b4ef60e847095efbcd5e5f5faf27a5cdd Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140290 Commit-Queue: Henrik Andreassson Reviewed-by: Henrik Andreassson Cr-Commit-Position: refs/heads/master@{#28517} --- audio/channel_send.cc | 2 +- modules/audio_mixer/DEPS | 1 + .../audio_mixer/audio_frame_manipulator.cc | 35 +++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/audio/channel_send.cc b/audio/channel_send.cc index 8bb54d6f2d..e7cee58f14 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -1118,7 +1118,7 @@ void ChannelSend::ProcessAndEncodeAudio( void ChannelSend::ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input) { RTC_DCHECK_GT(audio_input->samples_per_channel_, 0); - RTC_DCHECK_LE(audio_input->num_channels_, 2); + RTC_DCHECK_LE(audio_input->num_channels_, 8); // Measure time between when the audio frame is added to the task queue and // when the task is actually executed. Goal is to keep track of unwanted diff --git a/modules/audio_mixer/DEPS b/modules/audio_mixer/DEPS index dcee4a37d3..46f29bccf8 100644 --- a/modules/audio_mixer/DEPS +++ b/modules/audio_mixer/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+audio/utility/audio_frame_operations.h", + "+audio/utility/channel_mixer.h", "+call", "+common_audio", "+modules/audio_coding", diff --git a/modules/audio_mixer/audio_frame_manipulator.cc b/modules/audio_mixer/audio_frame_manipulator.cc index 78c11b19c4..3100271cfb 100644 --- a/modules/audio_mixer/audio_frame_manipulator.cc +++ b/modules/audio_mixer/audio_frame_manipulator.cc @@ -11,6 +11,7 @@ #include "modules/audio_mixer/audio_frame_manipulator.h" #include "audio/utility/audio_frame_operations.h" +#include "audio/utility/channel_mixer.h" #include "rtc_base/checks.h" namespace webrtc { @@ -56,16 +57,36 @@ void Ramp(float start_gain, float target_gain, AudioFrame* audio_frame) { void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) { RTC_DCHECK_GE(target_number_of_channels, 1); - if (frame->num_channels_ == target_number_of_channels) { + // TODO(bugs.webrtc.org/10783): take channel layout into account as well. + if (frame->num_channels() == target_number_of_channels) { return; } - if (frame->num_channels_ > target_number_of_channels) { - AudioFrameOperations::DownmixChannels(target_number_of_channels, frame); - } else if (frame->num_channels_ < target_number_of_channels) { - AudioFrameOperations::UpmixChannels(target_number_of_channels, frame); + + // Use legacy components for the most simple cases (mono <-> stereo) to ensure + // that native WebRTC clients are not affected when support for multi-channel + // audio is added to Chrome. + // TODO(bugs.webrtc.org/10783): utilize channel mixer for mono/stereo as well. + if (target_number_of_channels < 3 && frame->num_channels() < 3) { + if (frame->num_channels() > target_number_of_channels) { + AudioFrameOperations::DownmixChannels(target_number_of_channels, frame); + } else { + AudioFrameOperations::UpmixChannels(target_number_of_channels, frame); + } + } else { + // Use generic channel mixer when the number of channels for input our + // output is larger than two. E.g. stereo -> 5.1 channel up-mixing. + // TODO(bugs.webrtc.org/10783): ensure that actual channel layouts are used + // instead of guessing based on number of channels. + const ChannelLayout output_layout( + GuessChannelLayout(target_number_of_channels)); + ChannelMixer mixer(GuessChannelLayout(frame->num_channels()), + output_layout); + mixer.Transform(frame); + RTC_DCHECK_EQ(frame->channel_layout(), output_layout); } - RTC_DCHECK_EQ(frame->num_channels_, target_number_of_channels) - << "Wrong number of channels, " << frame->num_channels_ << " vs " + RTC_DCHECK_EQ(frame->num_channels(), target_number_of_channels) + << "Wrong number of channels, " << frame->num_channels() << " vs " << target_number_of_channels; } + } // namespace webrtc