Commit c0f61670 authored by Gustaf Ullberg's avatar Gustaf Ullberg Committed by Commit Bot

Use StreamConfig APIs of AudioProcessing

This change switches to the StreamConfig versions of ProcessStream
and AnalyzeReverseStream. This is part of the preparations for
multichannel audio processing. It also means that Chromium no longer
uses deprecated WebRTC APIs for audio processing.

Bug: chromium:1016708
Change-Id: I105a1a434d081879f31efa8703f994e4111c0f5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875261Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Gustaf Ullberg <gustaf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708975}
parent 97a0231d
......@@ -18,6 +18,8 @@ component("webrtc") {
sources = [
"audio_delay_stats_reporter.cc",
"audio_delay_stats_reporter.h",
"helpers.cc",
"helpers.h",
"webrtc_switches.cc",
"webrtc_switches.h",
]
......@@ -26,6 +28,7 @@ component("webrtc") {
deps = [
"//base",
"//media:shared_memory_support",
"//third_party/webrtc/modules/audio_processing",
"//third_party/webrtc/modules/audio_processing:api",
"//third_party/webrtc/modules/audio_processing:audio_processing_statistics",
......
......@@ -18,6 +18,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "media/webrtc/helpers.h"
#include "media/webrtc/webrtc_switches.h"
#include "third_party/webrtc/api/audio/echo_canceller3_factory.h"
#include "third_party/webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h"
......@@ -29,25 +30,6 @@ namespace {
constexpr int kBuffersPerSecond = 100; // 10 ms per buffer.
webrtc::AudioProcessing::ChannelLayout MediaLayoutToWebRtcLayout(
ChannelLayout media_layout) {
switch (media_layout) {
case CHANNEL_LAYOUT_MONO:
return webrtc::AudioProcessing::kMono;
case CHANNEL_LAYOUT_STEREO:
case CHANNEL_LAYOUT_DISCRETE:
// TODO(https://crbug.com/868026): currently mapping all discrete channel
// layouts to two channels assuming that any required channel remix takes
// place in the native audio layer.
return webrtc::AudioProcessing::kStereo;
case CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC:
return webrtc::AudioProcessing::kStereoAndKeyboard;
default:
NOTREACHED() << "Layout not supported: " << media_layout;
return webrtc::AudioProcessing::kMono;
}
}
} // namespace
AudioProcessor::ProcessingResult::ProcessingResult(
......@@ -131,8 +113,7 @@ void AudioProcessor::AnalyzePlayout(const AudioBus& audio,
}
const int apm_error = audio_processing_->AnalyzeReverseStream(
channel_ptrs, parameters.frames_per_buffer(), parameters.sample_rate(),
webrtc_layout);
channel_ptrs, CreateStreamConfig(parameters));
DCHECK_EQ(apm_error, webrtc::AudioProcessing::kNoError);
}
......@@ -205,7 +186,6 @@ void AudioProcessor::InitializeAPM() {
// AEC setup part 1.
// Echo cancellation is configured both before and after AudioProcessing
// construction, but before Initialize.
if (settings_.echo_cancellation == EchoCancellationType::kAec3) {
......@@ -333,13 +313,9 @@ void AudioProcessor::FeedDataToAPM(const AudioBus& source) {
input_ptrs[i] = source.channel(i);
}
const auto layout =
MediaLayoutToWebRtcLayout(audio_parameters_.channel_layout());
const int sample_rate = audio_parameters_.sample_rate();
int err = audio_processing_->ProcessStream(
input_ptrs.data(), audio_parameters_.frames_per_buffer(), sample_rate,
layout, sample_rate, layout, output_ptrs_.data());
const webrtc::StreamConfig config = CreateStreamConfig(audio_parameters_);
int err = audio_processing_->ProcessStream(input_ptrs.data(), config, config,
output_ptrs_.data());
DCHECK_EQ(err, 0) << "ProcessStream() error: " << err;
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/webrtc/helpers.h"
namespace media {
webrtc::StreamConfig CreateStreamConfig(const AudioParameters& parameters) {
const int rate = parameters.sample_rate();
const int channels = std::min(parameters.channels(), 2);
const bool has_keyboard = parameters.channel_layout() ==
media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC;
return webrtc::StreamConfig(rate, channels, has_keyboard);
}
} // namespace media
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_WEBRTC_HELPERS_H_
#define MEDIA_WEBRTC_HELPERS_H_
#include "base/component_export.h"
#include "media/base/audio_parameters.h"
#include "third_party/webrtc/modules/audio_processing/include/audio_processing.h"
namespace media {
COMPONENT_EXPORT(MEDIA_WEBRTC)
webrtc::StreamConfig CreateStreamConfig(const AudioParameters& parameters);
} // namespace media
#endif // MEDIA_WEBRTC_WEBRTC_HELPERS_H_
......@@ -37,6 +37,7 @@ include_rules = [
"+media/mojo/mojom",
"+media/webrtc/audio_delay_stats_reporter.h",
"+media/webrtc/audio_processor_controls.h",
"+media/webrtc/helpers.h",
"+media/webrtc/webrtc_switches.h",
"+mojo/public/cpp/bindings/binding.h",
"-third_party/blink/renderer/modules",
......
......@@ -23,6 +23,7 @@
#include "media/base/audio_fifo.h"
#include "media/base/audio_parameters.h"
#include "media/base/channel_layout.h"
#include "media/webrtc/helpers.h"
#include "media/webrtc/webrtc_switches.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/web/modules/webrtc/webrtc_audio_device_impl.h"
......@@ -34,6 +35,7 @@
#include "third_party/webrtc/api/audio/echo_canceller3_config.h"
#include "third_party/webrtc/api/audio/echo_canceller3_config_json.h"
#include "third_party/webrtc/api/audio/echo_canceller3_factory.h"
#include "third_party/webrtc/modules/audio_processing/include/audio_processing.h"
#include "third_party/webrtc/modules/audio_processing/include/audio_processing_statistics.h"
#include "third_party/webrtc/modules/audio_processing/typing_detection.h"
#include "third_party/webrtc_overrides/task_queue_factory.h"
......@@ -61,33 +63,6 @@ using webrtc::AudioProcessing;
constexpr int kAudioProcessingNumberOfChannels = 1;
constexpr int kBuffersPerSecond = 100; // 10 ms per buffer.
AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) {
switch (media_layout) {
case media::CHANNEL_LAYOUT_MONO:
return AudioProcessing::kMono;
case media::CHANNEL_LAYOUT_STEREO:
return AudioProcessing::kStereo;
case media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC:
return AudioProcessing::kStereoAndKeyboard;
default:
NOTREACHED() << "Layout not supported: " << media_layout;
return AudioProcessing::kMono;
}
}
// This is only used for playout data where only max two channels is supported.
AudioProcessing::ChannelLayout ChannelsToLayout(int num_channels) {
switch (num_channels) {
case 1:
return AudioProcessing::kMono;
case 2:
return AudioProcessing::kStereo;
default:
NOTREACHED() << "Channels not supported: " << num_channels;
return AudioProcessing::kMono;
}
}
} // namespace
// Wraps AudioBus to provide access to the array of channel pointers, since this
......@@ -467,8 +442,7 @@ void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus,
// TODO(ajm): Should AnalyzeReverseStream() account for the
// |audio_delay_milliseconds|?
const int apm_error = audio_processing_->AnalyzeReverseStream(
channel_ptrs.data(), audio_bus->frames(), sample_rate,
ChannelsToLayout(channels));
channel_ptrs.data(), webrtc::StreamConfig(sample_rate, channels));
if (apm_error != webrtc::AudioProcessing::kNoError &&
apm_playout_error_code_log_count_ < 10) {
LOG(ERROR) << "MSAP::OnPlayoutData: AnalyzeReverseStream error="
......@@ -725,10 +699,8 @@ int MediaStreamAudioProcessor::ProcessData(const float* const* process_ptrs,
ap->set_stream_analog_level(volume);
ap->set_stream_key_pressed(key_pressed);
int err = ap->ProcessStream(
process_ptrs, process_frames, input_format_.sample_rate(),
MapLayout(input_format_.channel_layout()), output_format_.sample_rate(),
MapLayout(output_format_.channel_layout()), output_ptrs);
int err = ap->ProcessStream(process_ptrs, CreateStreamConfig(input_format_),
CreateStreamConfig(output_format_), output_ptrs);
DCHECK_EQ(err, 0) << "ProcessStream() error: " << err;
if (typing_detector_) {
......
......@@ -727,6 +727,7 @@ _CONFIG = [
'webrtc::EchoCanceller3Factory',
'webrtc::ExperimentalAgc',
'webrtc::MediaStreamTrackInterface',
'webrtc::StreamConfig',
'webrtc::TypingDetection',
'webrtc::VideoTrackInterface',
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment