2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-30 20:51:15 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/audio_processing_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-08-03 21:08:51 +00:00
|
|
|
#include <assert.h>
|
2015-07-23 11:41:39 -07:00
|
|
|
#include <algorithm>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-06-29 14:57:29 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2014-10-10 08:36:56 +00:00
|
|
|
#include "webrtc/base/platform_file.h"
|
2015-12-17 06:42:29 -08:00
|
|
|
#include "webrtc/base/trace_event.h"
|
2015-08-14 10:35:55 -07:00
|
|
|
#include "webrtc/common_audio/audio_converter.h"
|
2015-03-25 16:37:27 -07:00
|
|
|
#include "webrtc/common_audio/channel_buffer.h"
|
2015-08-14 10:35:55 -07:00
|
|
|
#include "webrtc/common_audio/include/audio_util.h"
|
2014-01-07 17:45:09 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
2015-06-29 14:57:29 +02:00
|
|
|
#include "webrtc/modules/audio_processing/aec/aec_core.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
#include "webrtc/modules/audio_processing/agc/agc_manager_direct.h"
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
2015-03-13 00:13:32 +00:00
|
|
|
#include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h"
|
2014-04-22 21:00:04 +00:00
|
|
|
#include "webrtc/modules/audio_processing/common.h"
|
2014-02-27 22:23:17 +00:00
|
|
|
#include "webrtc/modules/audio_processing/echo_cancellation_impl.h"
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
|
2016-02-13 16:40:47 -08:00
|
|
|
#include "webrtc/modules/audio_processing/gain_control_for_experimental_agc.h"
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/gain_control_impl.h"
|
|
|
|
|
#include "webrtc/modules/audio_processing/high_pass_filter_impl.h"
|
2015-08-14 10:35:55 -07:00
|
|
|
#include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h"
|
2016-06-29 15:26:12 -07:00
|
|
|
#include "webrtc/modules/audio_processing/level_controller/level_controller.h"
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/level_estimator_impl.h"
|
|
|
|
|
#include "webrtc/modules/audio_processing/noise_suppression_impl.h"
|
2014-12-19 19:57:34 +00:00
|
|
|
#include "webrtc/modules/audio_processing/transient/transient_suppressor.h"
|
2013-03-01 16:36:19 +00:00
|
|
|
#include "webrtc/modules/audio_processing/voice_detection_impl.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/file_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/logging.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/metrics.h"
|
2011-12-03 00:03:31 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
|
|
|
|
// Files generated at build-time by the protobuf compiler.
|
2012-03-16 21:36:00 +00:00
|
|
|
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
|
2012-10-22 21:21:52 +00:00
|
|
|
#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
|
2011-08-03 23:34:31 +00:00
|
|
|
#else
|
2016-02-09 08:13:06 -08:00
|
|
|
#include "webrtc/modules/audio_processing/debug.pb.h"
|
2011-08-03 23:34:31 +00:00
|
|
|
#endif
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
#define RETURN_ON_ERR(expr) \
|
|
|
|
|
do { \
|
|
|
|
|
int err = (expr); \
|
|
|
|
|
if (err != kNoError) { \
|
|
|
|
|
return err; \
|
|
|
|
|
} \
|
2014-01-07 17:45:09 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
2016-03-16 18:26:35 -07:00
|
|
|
|
|
|
|
|
const int AudioProcessing::kNativeSampleRatesHz[] = {
|
|
|
|
|
AudioProcessing::kSampleRate8kHz,
|
|
|
|
|
AudioProcessing::kSampleRate16kHz,
|
|
|
|
|
#ifdef WEBRTC_ARCH_ARM_FAMILY
|
|
|
|
|
AudioProcessing::kSampleRate32kHz};
|
|
|
|
|
#else
|
|
|
|
|
AudioProcessing::kSampleRate32kHz,
|
|
|
|
|
AudioProcessing::kSampleRate48kHz};
|
|
|
|
|
#endif // WEBRTC_ARCH_ARM_FAMILY
|
|
|
|
|
const size_t AudioProcessing::kNumNativeSampleRates =
|
|
|
|
|
arraysize(AudioProcessing::kNativeSampleRatesHz);
|
|
|
|
|
const int AudioProcessing::kMaxNativeSampleRateHz = AudioProcessing::
|
|
|
|
|
kNativeSampleRatesHz[AudioProcessing::kNumNativeSampleRates - 1];
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) {
|
|
|
|
|
switch (layout) {
|
|
|
|
|
case AudioProcessing::kMono:
|
|
|
|
|
case AudioProcessing::kStereo:
|
|
|
|
|
return false;
|
|
|
|
|
case AudioProcessing::kMonoAndKeyboard:
|
|
|
|
|
case AudioProcessing::kStereoAndKeyboard:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-16 18:26:35 -07:00
|
|
|
|
|
|
|
|
bool is_multi_band(int sample_rate_hz) {
|
|
|
|
|
return sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
|
|
|
|
|
sample_rate_hz == AudioProcessing::kSampleRate48kHz;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-09 16:06:52 -07:00
|
|
|
int ClosestHigherNativeRate(int min_proc_rate) {
|
2016-03-16 18:26:35 -07:00
|
|
|
for (int rate : AudioProcessing::kNativeSampleRatesHz) {
|
|
|
|
|
if (rate >= min_proc_rate) {
|
|
|
|
|
return rate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return AudioProcessing::kMaxNativeSampleRateHz;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
} // namespace
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
// Throughout webrtc, it's assumed that success is represented by zero.
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2015-12-08 13:22:33 -08:00
|
|
|
struct AudioProcessingImpl::ApmPublicSubmodules {
|
2016-03-10 21:09:04 -08:00
|
|
|
ApmPublicSubmodules() {}
|
2015-12-08 13:22:33 -08:00
|
|
|
// Accessed externally of APM without any lock acquired.
|
2016-03-05 03:01:14 -08:00
|
|
|
std::unique_ptr<EchoCancellationImpl> echo_cancellation;
|
2016-03-10 12:54:25 -08:00
|
|
|
std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
|
2016-03-10 21:09:04 -08:00
|
|
|
std::unique_ptr<GainControlImpl> gain_control;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<HighPassFilterImpl> high_pass_filter;
|
|
|
|
|
std::unique_ptr<LevelEstimatorImpl> level_estimator;
|
|
|
|
|
std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
|
|
|
|
|
std::unique_ptr<VoiceDetectionImpl> voice_detection;
|
|
|
|
|
std::unique_ptr<GainControlForExperimentalAgc>
|
2016-02-13 16:40:47 -08:00
|
|
|
gain_control_for_experimental_agc;
|
2015-12-08 13:22:33 -08:00
|
|
|
|
|
|
|
|
// Accessed internally from both render and capture.
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<TransientSuppressor> transient_suppressor;
|
|
|
|
|
std::unique_ptr<IntelligibilityEnhancer> intelligibility_enhancer;
|
2015-12-08 13:22:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AudioProcessingImpl::ApmPrivateSubmodules {
|
2016-06-28 10:38:33 -07:00
|
|
|
explicit ApmPrivateSubmodules(Beamformer<float>* beamformer)
|
2015-12-08 13:22:33 -08:00
|
|
|
: beamformer(beamformer) {}
|
|
|
|
|
// Accessed internally from capture or during initialization
|
2016-06-28 10:38:33 -07:00
|
|
|
std::unique_ptr<Beamformer<float>> beamformer;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<AgcManagerDirect> agc_manager;
|
2016-06-29 15:26:12 -07:00
|
|
|
std::unique_ptr<LevelController> level_controller;
|
2015-12-08 13:22:33 -08:00
|
|
|
};
|
|
|
|
|
|
2014-01-25 02:09:06 +00:00
|
|
|
AudioProcessing* AudioProcessing::Create() {
|
|
|
|
|
Config config;
|
2015-01-15 18:07:21 +00:00
|
|
|
return Create(config, nullptr);
|
2014-01-25 02:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessing* AudioProcessing::Create(const Config& config) {
|
2015-01-15 18:07:21 +00:00
|
|
|
return Create(config, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessing* AudioProcessing::Create(const Config& config,
|
2016-06-28 10:38:33 -07:00
|
|
|
Beamformer<float>* beamformer) {
|
2015-01-15 18:07:21 +00:00
|
|
|
AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (apm->Initialize() != kNoError) {
|
|
|
|
|
delete apm;
|
2015-11-28 12:35:15 -08:00
|
|
|
apm = nullptr;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return apm;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 02:09:06 +00:00
|
|
|
AudioProcessingImpl::AudioProcessingImpl(const Config& config)
|
2015-01-15 18:07:21 +00:00
|
|
|
: AudioProcessingImpl(config, nullptr) {}
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::AudioProcessingImpl(const Config& config,
|
2016-06-28 10:38:33 -07:00
|
|
|
Beamformer<float>* beamformer)
|
2015-11-28 12:35:15 -08:00
|
|
|
: public_submodules_(new ApmPublicSubmodules()),
|
|
|
|
|
private_submodules_(new ApmPrivateSubmodules(beamformer)),
|
|
|
|
|
constants_(config.Get<ExperimentalAgc>().startup_min_volume,
|
2014-12-15 09:41:24 +00:00
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2016-05-16 15:32:38 -07:00
|
|
|
false),
|
2014-12-15 09:41:24 +00:00
|
|
|
#else
|
2016-05-16 15:32:38 -07:00
|
|
|
config.Get<ExperimentalAgc>().enabled),
|
2014-12-15 09:41:24 +00:00
|
|
|
#endif
|
2015-06-24 18:14:14 -07:00
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2016-01-11 18:04:30 -08:00
|
|
|
capture_(false,
|
2015-06-24 18:14:14 -07:00
|
|
|
#else
|
2016-01-11 18:04:30 -08:00
|
|
|
capture_(config.Get<ExperimentalNs>().enabled,
|
2015-06-24 18:14:14 -07:00
|
|
|
#endif
|
2016-01-11 18:04:30 -08:00
|
|
|
config.Get<Beamforming>().array_geometry,
|
2016-01-11 20:32:29 -08:00
|
|
|
config.Get<Beamforming>().target_direction),
|
2016-05-16 15:32:38 -07:00
|
|
|
capture_nonlocked_(config.Get<Beamforming>().enabled,
|
2016-06-29 15:26:12 -07:00
|
|
|
config.Get<Intelligibility>().enabled,
|
|
|
|
|
config.Get<LevelControl>().enabled) {
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
|
2016-03-05 03:01:14 -08:00
|
|
|
public_submodules_->echo_cancellation.reset(
|
2016-03-15 09:34:24 -07:00
|
|
|
new EchoCancellationImpl(&crit_render_, &crit_capture_));
|
2016-03-10 12:54:25 -08:00
|
|
|
public_submodules_->echo_control_mobile.reset(
|
2016-03-15 04:32:28 -07:00
|
|
|
new EchoControlMobileImpl(&crit_render_, &crit_capture_));
|
2016-03-10 21:09:04 -08:00
|
|
|
public_submodules_->gain_control.reset(
|
2016-03-15 02:28:08 -07:00
|
|
|
new GainControlImpl(&crit_capture_, &crit_capture_));
|
2015-12-08 11:07:32 -08:00
|
|
|
public_submodules_->high_pass_filter.reset(
|
|
|
|
|
new HighPassFilterImpl(&crit_capture_));
|
2015-12-15 11:39:38 -08:00
|
|
|
public_submodules_->level_estimator.reset(
|
|
|
|
|
new LevelEstimatorImpl(&crit_capture_));
|
2015-12-08 13:22:33 -08:00
|
|
|
public_submodules_->noise_suppression.reset(
|
|
|
|
|
new NoiseSuppressionImpl(&crit_capture_));
|
2015-12-16 03:31:12 -08:00
|
|
|
public_submodules_->voice_detection.reset(
|
|
|
|
|
new VoiceDetectionImpl(&crit_capture_));
|
2016-02-13 16:40:47 -08:00
|
|
|
public_submodules_->gain_control_for_experimental_agc.reset(
|
2016-03-10 21:09:04 -08:00
|
|
|
new GainControlForExperimentalAgc(
|
|
|
|
|
public_submodules_->gain_control.get(), &crit_capture_));
|
2016-06-29 15:26:12 -07:00
|
|
|
|
|
|
|
|
private_submodules_->level_controller.reset(new LevelController());
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2014-01-25 02:09:06 +00:00
|
|
|
SetExtraOptions(config);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::~AudioProcessingImpl() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Depends on gain_control_ and
|
2016-02-13 16:40:47 -08:00
|
|
|
// public_submodules_->gain_control_for_experimental_agc.
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager.reset();
|
|
|
|
|
// Depends on gain_control_.
|
2016-02-13 16:40:47 -08:00
|
|
|
public_submodules_->gain_control_for_experimental_agc.reset();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
debug_dump_.debug_file->CloseFile();
|
2015-11-28 12:35:15 -08:00
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::Initialize() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner during initialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2011-07-07 08:21:25 +00:00
|
|
|
return InitializeLocked();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::Initialize(int input_sample_rate_hz,
|
|
|
|
|
int output_sample_rate_hz,
|
2014-03-10 22:26:12 +00:00
|
|
|
int reverse_sample_rate_hz,
|
2014-04-22 21:00:04 +00:00
|
|
|
ChannelLayout input_layout,
|
|
|
|
|
ChannelLayout output_layout,
|
|
|
|
|
ChannelLayout reverse_layout) {
|
2015-07-23 11:41:39 -07:00
|
|
|
const ProcessingConfig processing_config = {
|
2015-08-14 10:35:55 -07:00
|
|
|
{{input_sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(input_layout),
|
2015-07-23 11:41:39 -07:00
|
|
|
LayoutHasKeyboard(input_layout)},
|
2015-08-14 10:35:55 -07:00
|
|
|
{output_sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(output_layout),
|
2015-07-23 11:41:39 -07:00
|
|
|
LayoutHasKeyboard(output_layout)},
|
2015-08-14 10:35:55 -07:00
|
|
|
{reverse_sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(reverse_layout),
|
|
|
|
|
LayoutHasKeyboard(reverse_layout)},
|
|
|
|
|
{reverse_sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(reverse_layout),
|
2015-07-23 11:41:39 -07:00
|
|
|
LayoutHasKeyboard(reverse_layout)}}};
|
|
|
|
|
|
|
|
|
|
return Initialize(processing_config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner during initialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-07-23 11:41:39 -07:00
|
|
|
return InitializeLocked(processing_config);
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::MaybeInitializeRender(
|
2015-11-27 02:47:28 -08:00
|
|
|
const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
return MaybeInitialize(processing_config);
|
2015-11-27 02:47:28 -08:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::MaybeInitializeCapture(
|
2015-11-27 02:47:28 -08:00
|
|
|
const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
return MaybeInitialize(processing_config);
|
2015-11-27 02:47:28 -08:00
|
|
|
}
|
|
|
|
|
|
2015-11-17 02:16:45 -08:00
|
|
|
// Calls InitializeLocked() if any of the audio parameters have changed from
|
2015-11-28 12:35:15 -08:00
|
|
|
// their current values (needs to be called while holding the crit_render_lock).
|
|
|
|
|
int AudioProcessingImpl::MaybeInitialize(
|
2015-11-17 02:16:45 -08:00
|
|
|
const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Called from both threads. Thread check is therefore not possible.
|
|
|
|
|
if (processing_config == formats_.api_format) {
|
2015-11-17 02:16:45 -08:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-11-17 02:16:45 -08:00
|
|
|
return InitializeLocked(processing_config);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int AudioProcessingImpl::InitializeLocked() {
|
2015-07-23 11:41:39 -07:00
|
|
|
const int fwd_audio_buffer_channels =
|
2016-01-11 20:32:29 -08:00
|
|
|
capture_nonlocked_.beamformer_enabled
|
2015-11-28 12:35:15 -08:00
|
|
|
? formats_.api_format.input_stream().num_channels()
|
|
|
|
|
: formats_.api_format.output_stream().num_channels();
|
2015-08-14 10:35:55 -07:00
|
|
|
const int rev_audio_buffer_out_num_frames =
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_output_stream().num_frames() == 0
|
|
|
|
|
? formats_.rev_proc_format.num_frames()
|
|
|
|
|
: formats_.api_format.reverse_output_stream().num_frames();
|
|
|
|
|
if (formats_.api_format.reverse_input_stream().num_channels() > 0) {
|
|
|
|
|
render_.render_audio.reset(new AudioBuffer(
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_frames(),
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_channels(),
|
|
|
|
|
formats_.rev_proc_format.num_frames(),
|
|
|
|
|
formats_.rev_proc_format.num_channels(),
|
2015-08-14 10:35:55 -07:00
|
|
|
rev_audio_buffer_out_num_frames));
|
|
|
|
|
if (rev_conversion_needed()) {
|
2016-02-24 05:22:32 -08:00
|
|
|
render_.render_converter = AudioConverter::Create(
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_channels(),
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_frames(),
|
|
|
|
|
formats_.api_format.reverse_output_stream().num_channels(),
|
2016-02-24 05:22:32 -08:00
|
|
|
formats_.api_format.reverse_output_stream().num_frames());
|
2015-08-14 10:35:55 -07:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_converter.reset(nullptr);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio.reset(nullptr);
|
|
|
|
|
render_.render_converter.reset(nullptr);
|
2015-07-23 11:41:39 -07:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio.reset(
|
|
|
|
|
new AudioBuffer(formats_.api_format.input_stream().num_frames(),
|
|
|
|
|
formats_.api_format.input_stream().num_channels(),
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.num_frames(),
|
|
|
|
|
fwd_audio_buffer_channels,
|
|
|
|
|
formats_.api_format.output_stream().num_frames()));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
InitializeGainController();
|
2016-03-05 03:01:14 -08:00
|
|
|
InitializeEchoCanceller();
|
2016-03-10 12:54:25 -08:00
|
|
|
InitializeEchoControlMobile();
|
2015-04-15 11:42:40 +02:00
|
|
|
InitializeExperimentalAgc();
|
|
|
|
|
InitializeTransient();
|
2014-12-19 19:57:34 +00:00
|
|
|
InitializeBeamformer();
|
2015-08-14 10:35:55 -07:00
|
|
|
InitializeIntelligibility();
|
2015-12-08 11:07:32 -08:00
|
|
|
InitializeHighPassFilter();
|
2015-12-08 13:22:33 -08:00
|
|
|
InitializeNoiseSuppression();
|
2015-12-15 11:39:38 -08:00
|
|
|
InitializeLevelEstimator();
|
2015-12-16 03:31:12 -08:00
|
|
|
InitializeVoiceDetection();
|
2016-06-29 15:26:12 -07:00
|
|
|
InitializeLevelController();
|
2015-12-08 11:07:32 -08:00
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2011-08-03 21:08:51 +00:00
|
|
|
int err = WriteInitMessage();
|
|
|
|
|
if (err != kNoError) {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif
|
2011-08-03 21:08:51 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
|
|
|
|
|
for (const auto& stream : config.streams) {
|
|
|
|
|
if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) {
|
|
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
Revert of Allow more than 2 input channels in AudioProcessing. (patchset #13 id:240001 of https://codereview.webrtc.org/1226093007/)
Reason for revert:
Breaks Chromium FYI content_browsertest on all platforms. The testcase that fails is WebRtcAecDumpBrowserTest.CallWithAecDump.
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Linux/builds/19388
Sample output:
[ RUN ] WebRtcAecDumpBrowserTest.CallWithAecDump
Xlib: extension "RANDR" missing on display ":9".
[4:14:0722/211548:1282124453:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: ISAC/48000/1 (105)
[4:14:0722/211548:1282124593:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMU/8000/2 (110)
[4:14:0722/211548:1282124700:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMA/8000/2 (118)
[4:14:0722/211548:1282124815:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: G722/8000/2 (119)
[19745:19745:0722/211548:1282133667:INFO:CONSOLE(64)] "Looking at video in element remote-view-1", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
[19745:19745:0722/211548:1282136892:INFO:CONSOLE(64)] "Looking at video in element remote-view-2", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
../../content/test/webrtc_content_browsertest_base.cc:62: Failure
Value of: ExecuteScriptAndExtractString( shell()->web_contents(), javascript, &result)
Actual: false
Expected: true
Failed to execute javascript call({video: true, audio: true});.
From javascript: (nothing)
When executing 'call({video: true, audio: true});'
../../content/test/webrtc_content_browsertest_base.cc:75: Failure
Failed
../../content/browser/media/webrtc_aecdump_browsertest.cc:26: Failure
Expected: (base::kNullProcessId) != (*id), actual: 0 vs 0
../../content/browser/media/webrtc_aecdump_browsertest.cc:95: Failure
Value of: GetRenderProcessHostId(&render_process_id)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:99: Failure
Value of: base::PathExists(dump_file)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:101: Failure
Value of: base::GetFileSize(dump_file, &file_size)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:102: Failure
Expected: (file_size) > (0), actual: 0 vs 0
[ FAILED ] WebRtcAecDumpBrowserTest.CallWithAecDump, where TypeParam = and GetParam() = (361 ms)
Original issue's description:
> Allow more than 2 input channels in AudioProcessing.
>
> The number of output channels is constrained to be equal to either 1 or the
> number of input channels.
>
> R=aluebs@webrtc.org, andrew@webrtc.org, pbos@webrtc.org
>
> Committed: https://chromium.googlesource.com/external/webrtc/+/c204754b7a0cc801c70e8ce6c689f57f6ce00b3b
TBR=andrew@webrtc.org,aluebs@webrtc.org,ajm@chromium.org,pbos@chromium.org,pbos@webrtc.org,mgraczyk@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.webrtc.org/1253573005
Cr-Commit-Position: refs/heads/master@{#9621}
2015-07-23 04:30:06 -07:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t num_in_channels = config.input_stream().num_channels();
|
|
|
|
|
const size_t num_out_channels = config.output_stream().num_channels();
|
2015-07-23 11:41:39 -07:00
|
|
|
|
|
|
|
|
// Need at least one input channel.
|
|
|
|
|
// Need either one output channel or as many outputs as there are inputs.
|
|
|
|
|
if (num_in_channels == 0 ||
|
|
|
|
|
!(num_out_channels == 1 || num_out_channels == num_in_channels)) {
|
2014-03-10 22:26:12 +00:00
|
|
|
return kBadNumberChannelsError;
|
|
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2016-01-11 20:32:29 -08:00
|
|
|
if (capture_nonlocked_.beamformer_enabled &&
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
num_in_channels != capture_.array_geometry.size()) {
|
2015-01-15 18:07:21 +00:00
|
|
|
return kBadNumberChannelsError;
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format = config;
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2016-04-09 16:06:52 -07:00
|
|
|
capture_nonlocked_.fwd_proc_format = StreamConfig(ClosestHigherNativeRate(
|
|
|
|
|
std::min(formats_.api_format.input_stream().sample_rate_hz(),
|
|
|
|
|
formats_.api_format.output_stream().sample_rate_hz())));
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2016-04-20 15:27:58 -07:00
|
|
|
int rev_proc_rate = ClosestHigherNativeRate(std::min(
|
|
|
|
|
formats_.api_format.reverse_input_stream().sample_rate_hz(),
|
|
|
|
|
formats_.api_format.reverse_output_stream().sample_rate_hz()));
|
|
|
|
|
// TODO(aluebs): Remove this restriction once we figure out why the 3-band
|
|
|
|
|
// splitting filter degrades the AEC performance.
|
|
|
|
|
if (rev_proc_rate > kSampleRate32kHz) {
|
|
|
|
|
rev_proc_rate = is_rev_processed() ? kSampleRate32kHz : kSampleRate16kHz;
|
|
|
|
|
}
|
|
|
|
|
// If the forward sample rate is 8 kHz, the reverse stream is also processed
|
|
|
|
|
// at this rate.
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate8kHz) {
|
2014-04-22 21:00:04 +00:00
|
|
|
rev_proc_rate = kSampleRate8kHz;
|
|
|
|
|
} else {
|
2016-04-20 15:27:58 -07:00
|
|
|
rev_proc_rate = std::max(rev_proc_rate, static_cast<int>(kSampleRate16kHz));
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
// Always downmix the reverse stream to mono for analysis. This has been
|
|
|
|
|
// demonstrated to work well for AEC in most practical scenarios.
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.rev_proc_format = StreamConfig(rev_proc_rate, 1);
|
2014-03-10 22:26:12 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate32kHz ||
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) {
|
|
|
|
|
capture_nonlocked_.split_rate = kSampleRate16kHz;
|
2014-03-10 22:26:12 +00:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_nonlocked_.split_rate =
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.sample_rate_hz();
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return InitializeLocked();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-25 18:28:29 +00:00
|
|
|
void AudioProcessingImpl::SetExtraOptions(const Config& config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner when setting the extra options.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2016-03-05 03:01:14 -08:00
|
|
|
public_submodules_->echo_cancellation->SetExtraOptions(config);
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled !=
|
|
|
|
|
config.Get<ExperimentalNs>().enabled) {
|
|
|
|
|
capture_.transient_suppressor_enabled =
|
|
|
|
|
config.Get<ExperimentalNs>().enabled;
|
2014-12-15 09:41:24 +00:00
|
|
|
InitializeTransient();
|
|
|
|
|
}
|
2016-01-11 18:04:30 -08:00
|
|
|
|
2016-06-29 15:26:12 -07:00
|
|
|
if (capture_nonlocked_.level_controller_enabled !=
|
|
|
|
|
config.Get<LevelControl>().enabled) {
|
|
|
|
|
capture_nonlocked_.level_controller_enabled =
|
|
|
|
|
config.Get<LevelControl>().enabled;
|
|
|
|
|
LOG(LS_INFO) << "Level controller activated: "
|
|
|
|
|
<< config.Get<LevelControl>().enabled;
|
|
|
|
|
|
|
|
|
|
InitializeLevelController();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-16 15:32:38 -07:00
|
|
|
if(capture_nonlocked_.intelligibility_enabled !=
|
|
|
|
|
config.Get<Intelligibility>().enabled) {
|
|
|
|
|
capture_nonlocked_.intelligibility_enabled =
|
|
|
|
|
config.Get<Intelligibility>().enabled;
|
|
|
|
|
InitializeIntelligibility();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 18:04:30 -08:00
|
|
|
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
|
2016-01-11 20:32:29 -08:00
|
|
|
if (capture_nonlocked_.beamformer_enabled !=
|
|
|
|
|
config.Get<Beamforming>().enabled) {
|
|
|
|
|
capture_nonlocked_.beamformer_enabled = config.Get<Beamforming>().enabled;
|
2016-01-11 18:04:30 -08:00
|
|
|
if (config.Get<Beamforming>().array_geometry.size() > 1) {
|
|
|
|
|
capture_.array_geometry = config.Get<Beamforming>().array_geometry;
|
|
|
|
|
}
|
|
|
|
|
capture_.target_direction = config.Get<Beamforming>().target_direction;
|
|
|
|
|
InitializeBeamformer();
|
|
|
|
|
}
|
|
|
|
|
#endif // WEBRTC_ANDROID_PLATFORM_BUILD
|
2013-07-25 18:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::proc_sample_rate_hz() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.fwd_proc_format.sample_rate_hz();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::proc_split_sample_rate_hz() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.split_rate;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_reverse_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return formats_.rev_proc_format.num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_input_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return formats_.api_format.input_stream().num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_proc_channels() const {
|
2016-01-11 20:32:29 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.beamformer_enabled ? 1 : num_output_channels();
|
|
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_output_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return formats_.api_format.output_stream().num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-12 22:28:31 +00:00
|
|
|
void AudioProcessingImpl::set_output_will_be_muted(bool muted) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.output_will_be_muted = muted;
|
|
|
|
|
if (private_submodules_->agc_manager.get()) {
|
|
|
|
|
private_submodules_->agc_manager->SetCaptureMuted(
|
|
|
|
|
capture_.output_will_be_muted);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2014-02-12 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::ProcessStream(const float* const* src,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t samples_per_channel,
|
2014-04-22 21:00:04 +00:00
|
|
|
int input_sample_rate_hz,
|
2014-03-04 20:58:13 +00:00
|
|
|
ChannelLayout input_layout,
|
2014-04-22 21:00:04 +00:00
|
|
|
int output_sample_rate_hz,
|
|
|
|
|
ChannelLayout output_layout,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout");
|
2015-11-28 12:35:15 -08:00
|
|
|
StreamConfig input_stream;
|
|
|
|
|
StreamConfig output_stream;
|
|
|
|
|
{
|
|
|
|
|
// Access the formats_.api_format.input_stream beneath the capture lock.
|
|
|
|
|
// The lock must be released as it is later required in the call
|
|
|
|
|
// to ProcessStream(,,,);
|
|
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
input_stream = formats_.api_format.input_stream();
|
|
|
|
|
output_stream = formats_.api_format.output_stream();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
input_stream.set_sample_rate_hz(input_sample_rate_hz);
|
|
|
|
|
input_stream.set_num_channels(ChannelsFromLayout(input_layout));
|
|
|
|
|
input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout));
|
|
|
|
|
output_stream.set_sample_rate_hz(output_sample_rate_hz);
|
|
|
|
|
output_stream.set_num_channels(ChannelsFromLayout(output_layout));
|
|
|
|
|
output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout));
|
|
|
|
|
|
|
|
|
|
if (samples_per_channel != input_stream.num_frames()) {
|
|
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
|
|
|
|
return ProcessStream(src, input_stream, output_stream, dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessStream(const float* const* src,
|
|
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig");
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config;
|
|
|
|
|
{
|
|
|
|
|
// Acquire the capture lock in order to safely call the function
|
|
|
|
|
// that retrieves the render side data. This function accesses apm
|
|
|
|
|
// getters that need the capture lock held when being called.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
public_submodules_->echo_cancellation->ReadQueuedRenderData();
|
|
|
|
|
public_submodules_->echo_control_mobile->ReadQueuedRenderData();
|
|
|
|
|
public_submodules_->gain_control->ReadQueuedRenderData();
|
|
|
|
|
|
|
|
|
|
if (!src || !dest) {
|
|
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
processing_config = formats_.api_format;
|
|
|
|
|
}
|
2015-11-16 16:27:42 -08:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
processing_config.input_stream() = input_config;
|
|
|
|
|
processing_config.output_stream() = output_config;
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Do conditional reinitialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
RETURN_ON_ERR(MaybeInitializeCapture(processing_config));
|
|
|
|
|
}
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-07-23 11:41:39 -07:00
|
|
|
assert(processing_config.input_stream().num_frames() ==
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.input_stream().num_frames());
|
2014-03-04 20:58:13 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-10-03 00:39:14 +02:00
|
|
|
RETURN_ON_ERR(WriteConfigMessage(false));
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
|
|
|
|
|
audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
|
2014-08-28 10:43:09 +00:00
|
|
|
const size_t channel_size =
|
2015-11-28 12:35:15 -08:00
|
|
|
sizeof(float) * formats_.api_format.input_stream().num_frames();
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
for (size_t i = 0; i < formats_.api_format.input_stream().num_channels();
|
|
|
|
|
++i)
|
2014-04-22 21:00:04 +00:00
|
|
|
msg->add_input_channel(src[i], channel_size);
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream());
|
2014-03-04 20:58:13 +00:00
|
|
|
RETURN_ON_ERR(ProcessStreamLocked());
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest);
|
2014-03-04 20:58:13 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
|
2014-08-28 10:43:09 +00:00
|
|
|
const size_t channel_size =
|
2015-11-28 12:35:15 -08:00
|
|
|
sizeof(float) * formats_.api_format.output_stream().num_frames();
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
for (size_t i = 0; i < formats_.api_format.output_stream().num_channels();
|
|
|
|
|
++i)
|
2014-04-22 21:00:04 +00:00
|
|
|
msg->add_output_channel(dest[i], channel_size);
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.capture));
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Acquire the capture lock in order to safely call the function
|
|
|
|
|
// that retrieves the render side data. This function accesses apm
|
|
|
|
|
// getters that need the capture lock held when being called.
|
|
|
|
|
// The lock needs to be released as
|
|
|
|
|
// public_submodules_->echo_control_mobile->is_enabled() aquires this lock
|
|
|
|
|
// as well.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
public_submodules_->echo_cancellation->ReadQueuedRenderData();
|
|
|
|
|
public_submodules_->echo_control_mobile->ReadQueuedRenderData();
|
|
|
|
|
public_submodules_->gain_control->ReadQueuedRenderData();
|
|
|
|
|
}
|
2015-11-16 16:27:42 -08:00
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
if (!frame) {
|
2014-01-07 17:45:09 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
// Must be a native rate.
|
|
|
|
|
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
2014-11-17 23:01:23 +00:00
|
|
|
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
2014-04-22 21:00:04 +00:00
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
2015-11-17 02:16:45 -08:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config;
|
|
|
|
|
{
|
|
|
|
|
// Aquire lock for the access of api_format.
|
|
|
|
|
// The lock is released immediately due to the conditional
|
|
|
|
|
// reinitialization.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
// TODO(ajm): The input and output rates and channels are currently
|
|
|
|
|
// constrained to be identical in the int16 interface.
|
|
|
|
|
processing_config = formats_.api_format;
|
|
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
|
|
|
|
processing_config.input_stream().set_num_channels(frame->num_channels_);
|
|
|
|
|
processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
|
|
|
|
processing_config.output_stream().set_num_channels(frame->num_channels_);
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Do conditional reinitialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
RETURN_ON_ERR(MaybeInitializeCapture(processing_config));
|
|
|
|
|
}
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-11-17 02:16:45 -08:00
|
|
|
if (frame->samples_per_channel_ !=
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.input_stream().num_frames()) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
|
|
|
|
|
audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
|
2015-07-23 11:41:39 -07:00
|
|
|
const size_t data_size =
|
|
|
|
|
sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
|
2012-05-02 23:56:37 +00:00
|
|
|
msg->set_input_data(frame->data_, data_size);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio->DeinterleaveFrom(frame);
|
2014-03-04 20:58:13 +00:00
|
|
|
RETURN_ON_ERR(ProcessStreamLocked());
|
2016-03-16 18:26:35 -07:00
|
|
|
capture_.capture_audio->InterleaveTo(frame, output_copy_needed());
|
2014-03-04 20:58:13 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
|
2015-07-23 11:41:39 -07:00
|
|
|
const size_t data_size =
|
|
|
|
|
sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
|
2014-03-04 20:58:13 +00:00
|
|
|
msg->set_output_data(frame->data_, data_size);
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.capture));
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessStreamLocked() {
|
2016-03-15 09:34:24 -07:00
|
|
|
// Ensure that not both the AEC and AECM are active at the same time.
|
|
|
|
|
// TODO(peah): Simplify once the public API Enable functions for these
|
|
|
|
|
// are moved to APM.
|
|
|
|
|
RTC_DCHECK(!(public_submodules_->echo_cancellation->is_enabled() &&
|
|
|
|
|
public_submodules_->echo_control_mobile->is_enabled()));
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
|
|
|
|
|
msg->set_delay(capture_nonlocked_.stream_delay_ms);
|
|
|
|
|
msg->set_drift(
|
|
|
|
|
public_submodules_->echo_cancellation->stream_drift_samples());
|
2015-02-06 19:44:21 +00:00
|
|
|
msg->set_level(gain_control()->stream_analog_level());
|
2015-11-28 12:35:15 -08:00
|
|
|
msg->set_keypress(capture_.key_pressed);
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-06-29 14:57:29 +02:00
|
|
|
MaybeUpdateHistograms();
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
AudioBuffer* ca = capture_.capture_audio.get(); // For brevity.
|
2015-08-14 10:35:55 -07:00
|
|
|
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc &&
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->gain_control->is_enabled()) {
|
|
|
|
|
private_submodules_->agc_manager->AnalyzePreProcess(
|
|
|
|
|
ca->channels()[0], ca->num_channels(),
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.num_frames());
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
if (fwd_analysis_needed()) {
|
2014-11-14 22:18:10 +00:00
|
|
|
ca->SplitIntoFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-11 20:32:29 -08:00
|
|
|
if (capture_nonlocked_.beamformer_enabled) {
|
2016-06-28 10:38:33 -07:00
|
|
|
private_submodules_->beamformer->ProcessChunk(*ca->split_data_f(),
|
|
|
|
|
ca->split_data_f());
|
2014-12-19 19:57:34 +00:00
|
|
|
ca->set_num_channels(1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-08 11:07:32 -08:00
|
|
|
public_submodules_->high_pass_filter->ProcessCaptureAudio(ca);
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(public_submodules_->gain_control->AnalyzeCaptureAudio(ca));
|
2015-12-08 13:22:33 -08:00
|
|
|
public_submodules_->noise_suppression->AnalyzeCaptureAudio(ca);
|
2016-03-15 09:34:24 -07:00
|
|
|
|
|
|
|
|
// Ensure that the stream delay was set before the call to the
|
|
|
|
|
// AEC ProcessCaptureAudio function.
|
|
|
|
|
if (public_submodules_->echo_cancellation->is_enabled() &&
|
|
|
|
|
!was_stream_delay_set()) {
|
|
|
|
|
return AudioProcessing::kStreamParameterNotSetError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessCaptureAudio(
|
|
|
|
|
ca, stream_delay_ms()));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (public_submodules_->echo_control_mobile->is_enabled() &&
|
|
|
|
|
public_submodules_->noise_suppression->is_enabled()) {
|
2014-04-24 18:28:56 +00:00
|
|
|
ca->CopyLowPassToReference();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2015-12-08 13:22:33 -08:00
|
|
|
public_submodules_->noise_suppression->ProcessCaptureAudio(ca);
|
2016-05-16 15:32:38 -07:00
|
|
|
if (capture_nonlocked_.intelligibility_enabled) {
|
2016-02-10 12:03:00 -08:00
|
|
|
RTC_DCHECK(public_submodules_->noise_suppression->is_enabled());
|
2016-05-16 15:32:38 -07:00
|
|
|
int gain_db = public_submodules_->gain_control->is_enabled() ?
|
|
|
|
|
public_submodules_->gain_control->compression_gain_db() :
|
|
|
|
|
0;
|
2016-02-10 12:03:00 -08:00
|
|
|
public_submodules_->intelligibility_enhancer->SetCaptureNoiseEstimate(
|
2016-05-16 15:32:38 -07:00
|
|
|
public_submodules_->noise_suppression->NoiseEstimate(), gain_db);
|
2016-02-10 12:03:00 -08:00
|
|
|
}
|
2016-03-15 04:32:28 -07:00
|
|
|
|
|
|
|
|
// Ensure that the stream delay was set before the call to the
|
|
|
|
|
// AECM ProcessCaptureAudio function.
|
|
|
|
|
if (public_submodules_->echo_control_mobile->is_enabled() &&
|
|
|
|
|
!was_stream_delay_set()) {
|
|
|
|
|
return AudioProcessing::kStreamParameterNotSetError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessCaptureAudio(
|
|
|
|
|
ca, stream_delay_ms()));
|
|
|
|
|
|
2015-12-16 03:31:12 -08:00
|
|
|
public_submodules_->voice_detection->ProcessCaptureAudio(ca);
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc &&
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->gain_control->is_enabled() &&
|
2016-01-11 20:32:29 -08:00
|
|
|
(!capture_nonlocked_.beamformer_enabled ||
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->beamformer->is_target_present())) {
|
|
|
|
|
private_submodules_->agc_manager->Process(
|
|
|
|
|
ca->split_bands_const(0)[kBand0To8kHz], ca->num_frames_per_band(),
|
|
|
|
|
capture_nonlocked_.split_rate);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2016-03-15 02:28:08 -07:00
|
|
|
RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(
|
|
|
|
|
ca, echo_cancellation()->stream_has_echo()));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
if (fwd_synthesis_needed()) {
|
2014-11-14 22:18:10 +00:00
|
|
|
ca->MergeFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-15 09:41:24 +00:00
|
|
|
// TODO(aluebs): Investigate if the transient suppression placement should be
|
|
|
|
|
// before or after the AGC.
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled) {
|
2014-12-15 09:41:24 +00:00
|
|
|
float voice_probability =
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager.get()
|
|
|
|
|
? private_submodules_->agc_manager->voice_probability()
|
|
|
|
|
: 1.f;
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->transient_suppressor->Suppress(
|
2015-07-23 11:41:39 -07:00
|
|
|
ca->channels_f()[0], ca->num_frames(), ca->num_channels(),
|
|
|
|
|
ca->split_bands_const_f(0)[kBand0To8kHz], ca->num_frames_per_band(),
|
|
|
|
|
ca->keyboard_data(), ca->num_keyboard_frames(), voice_probability,
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.key_pressed);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-29 15:26:12 -07:00
|
|
|
if (capture_nonlocked_.level_controller_enabled) {
|
|
|
|
|
private_submodules_->level_controller->Process(ca);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
// The level estimator operates on the recombined data.
|
2015-12-15 11:39:38 -08:00
|
|
|
public_submodules_->level_estimator->ProcessStream(ca);
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.was_stream_delay_set = false;
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t samples_per_channel,
|
2015-08-14 10:35:55 -07:00
|
|
|
int rev_sample_rate_hz,
|
2014-03-04 20:58:13 +00:00
|
|
|
ChannelLayout layout) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
2015-07-23 11:41:39 -07:00
|
|
|
const StreamConfig reverse_config = {
|
2015-08-14 10:35:55 -07:00
|
|
|
rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout),
|
2015-07-23 11:41:39 -07:00
|
|
|
};
|
|
|
|
|
if (samples_per_channel != reverse_config.num_frames()) {
|
|
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessReverseStream(
|
|
|
|
|
const float* const* src,
|
|
|
|
|
const StreamConfig& reverse_input_config,
|
|
|
|
|
const StreamConfig& reverse_output_config,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
|
|
|
|
RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config,
|
|
|
|
|
reverse_output_config));
|
2015-08-14 10:35:55 -07:00
|
|
|
if (is_rev_processed()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(),
|
|
|
|
|
dest);
|
2015-11-27 02:47:28 -08:00
|
|
|
} else if (render_check_rev_conversion_needed()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_converter->Convert(src, reverse_input_config.num_samples(),
|
|
|
|
|
dest,
|
|
|
|
|
reverse_output_config.num_samples());
|
2015-08-14 10:35:55 -07:00
|
|
|
} else {
|
|
|
|
|
CopyAudioIfNeeded(src, reverse_input_config.num_frames(),
|
|
|
|
|
reverse_input_config.num_channels(), dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return kNoError;
|
2015-07-23 11:41:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::AnalyzeReverseStreamLocked(
|
2015-08-14 10:35:55 -07:00
|
|
|
const float* const* src,
|
|
|
|
|
const StreamConfig& reverse_input_config,
|
|
|
|
|
const StreamConfig& reverse_output_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (src == nullptr) {
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2011-11-15 16:57:56 +00:00
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
if (reverse_input_config.num_channels() == 0) {
|
2015-07-23 11:41:39 -07:00
|
|
|
return kBadNumberChannelsError;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config = formats_.api_format;
|
2015-08-14 10:35:55 -07:00
|
|
|
processing_config.reverse_input_stream() = reverse_input_config;
|
|
|
|
|
processing_config.reverse_output_stream() = reverse_output_config;
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(MaybeInitializeRender(processing_config));
|
2015-08-14 10:35:55 -07:00
|
|
|
assert(reverse_input_config.num_frames() ==
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_frames());
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM);
|
|
|
|
|
audioproc::ReverseStream* msg =
|
|
|
|
|
debug_dump_.render.event_msg->mutable_reverse_stream();
|
2014-08-28 10:43:09 +00:00
|
|
|
const size_t channel_size =
|
2015-11-28 12:35:15 -08:00
|
|
|
sizeof(float) * formats_.api_format.reverse_input_stream().num_frames();
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
for (size_t i = 0;
|
2015-11-28 12:35:15 -08:00
|
|
|
i < formats_.api_format.reverse_input_stream().num_channels(); ++i)
|
2015-08-14 10:35:55 -07:00
|
|
|
msg->add_channel(src[i], channel_size);
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.render));
|
2011-08-03 21:08:51 +00:00
|
|
|
}
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif
|
2011-08-03 21:08:51 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio->CopyFrom(src,
|
|
|
|
|
formats_.api_format.reverse_input_stream());
|
2015-08-14 10:35:55 -07:00
|
|
|
return ProcessReverseStreamLocked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
|
|
|
|
if (frame == nullptr) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
// Must be a native rate.
|
|
|
|
|
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
2014-11-17 23:01:23 +00:00
|
|
|
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
2014-04-22 21:00:04 +00:00
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
2014-03-10 22:26:12 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
if (frame->num_channels_ <= 0) {
|
|
|
|
|
return kBadNumberChannelsError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config = formats_.api_format;
|
2015-08-14 10:35:55 -07:00
|
|
|
processing_config.reverse_input_stream().set_sample_rate_hz(
|
|
|
|
|
frame->sample_rate_hz_);
|
|
|
|
|
processing_config.reverse_input_stream().set_num_channels(
|
|
|
|
|
frame->num_channels_);
|
|
|
|
|
processing_config.reverse_output_stream().set_sample_rate_hz(
|
|
|
|
|
frame->sample_rate_hz_);
|
|
|
|
|
processing_config.reverse_output_stream().set_num_channels(
|
|
|
|
|
frame->num_channels_);
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(MaybeInitializeRender(processing_config));
|
2015-07-23 11:41:39 -07:00
|
|
|
if (frame->samples_per_channel_ !=
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_frames()) {
|
2014-03-04 20:58:13 +00:00
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (debug_dump_.debug_file->is_open()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.render.event_msg->set_type(audioproc::Event::REVERSE_STREAM);
|
|
|
|
|
audioproc::ReverseStream* msg =
|
|
|
|
|
debug_dump_.render.event_msg->mutable_reverse_stream();
|
2015-07-23 11:41:39 -07:00
|
|
|
const size_t data_size =
|
|
|
|
|
sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
|
2012-05-02 23:56:37 +00:00
|
|
|
msg->set_data(frame->data_, data_size);
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.render));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio->DeinterleaveFrom(frame);
|
2016-03-17 20:39:53 -07:00
|
|
|
RETURN_ON_ERR(ProcessReverseStreamLocked());
|
|
|
|
|
if (is_rev_processed()) {
|
|
|
|
|
render_.render_audio->InterleaveTo(frame, true);
|
|
|
|
|
}
|
|
|
|
|
return kNoError;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
int AudioProcessingImpl::ProcessReverseStreamLocked() {
|
2015-11-28 12:35:15 -08:00
|
|
|
AudioBuffer* ra = render_.render_audio.get(); // For brevity.
|
2016-03-16 18:26:35 -07:00
|
|
|
if (rev_analysis_needed()) {
|
2014-11-14 22:18:10 +00:00
|
|
|
ra->SplitIntoFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-16 15:32:38 -07:00
|
|
|
if (capture_nonlocked_.intelligibility_enabled) {
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->intelligibility_enhancer->ProcessRenderAudio(
|
|
|
|
|
ra->split_channels_f(kBand0To8kHz), capture_nonlocked_.split_rate,
|
|
|
|
|
ra->num_channels());
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(public_submodules_->echo_cancellation->ProcessRenderAudio(ra));
|
|
|
|
|
RETURN_ON_ERR(
|
|
|
|
|
public_submodules_->echo_control_mobile->ProcessRenderAudio(ra));
|
2016-02-13 16:40:47 -08:00
|
|
|
if (!constants_.use_experimental_agc) {
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(public_submodules_->gain_control->ProcessRenderAudio(ra));
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
if (rev_synthesis_needed()) {
|
2015-08-14 10:35:55 -07:00
|
|
|
ra->MergeFrequencyBands();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::set_stream_delay_ms(int delay) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
2012-05-29 21:14:06 +00:00
|
|
|
Error retval = kNoError;
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.was_stream_delay_set = true;
|
|
|
|
|
delay += capture_.delay_offset_ms;
|
2012-03-06 19:03:39 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
if (delay < 0) {
|
2012-05-29 21:14:06 +00:00
|
|
|
delay = 0;
|
|
|
|
|
retval = kBadStreamParameterWarning;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(ajm): the max is rather arbitrarily chosen; investigate.
|
|
|
|
|
if (delay > 500) {
|
2012-05-29 21:14:06 +00:00
|
|
|
delay = 500;
|
|
|
|
|
retval = kBadStreamParameterWarning;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_nonlocked_.stream_delay_ms = delay;
|
2012-05-29 21:14:06 +00:00
|
|
|
return retval;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::stream_delay_ms() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.stream_delay_ms;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::was_stream_delay_set() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_.was_stream_delay_set;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.key_pressed = key_pressed;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-06 19:03:39 +00:00
|
|
|
void AudioProcessingImpl::set_delay_offset_ms(int offset) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.delay_offset_ms = offset;
|
2012-03-06 19:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::delay_offset_ms() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
return capture_.delay_offset_ms;
|
2012-03-06 19:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int AudioProcessingImpl::StartDebugRecording(
|
2016-01-15 03:06:36 -08:00
|
|
|
const char filename[AudioProcessing::kMaxFilenameSize],
|
|
|
|
|
int64_t max_log_size_bytes) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-05-20 11:11:07 +02:00
|
|
|
static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (filename == nullptr) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2016-01-15 03:06:36 -08:00
|
|
|
debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes;
|
2011-07-07 08:21:25 +00:00
|
|
|
// Stop any ongoing recording.
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
debug_dump_.debug_file->CloseFile();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (!debug_dump_.debug_file->OpenFile(filename, false)) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kFileError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:39:14 +02:00
|
|
|
RETURN_ON_ERR(WriteConfigMessage(true));
|
|
|
|
|
RETURN_ON_ERR(WriteInitMessage());
|
2013-12-06 16:05:17 +00:00
|
|
|
return kNoError;
|
|
|
|
|
#else
|
|
|
|
|
return kUnsupportedFunctionError;
|
|
|
|
|
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 03:06:36 -08:00
|
|
|
int AudioProcessingImpl::StartDebugRecording(FILE* handle,
|
|
|
|
|
int64_t max_log_size_bytes) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2013-12-06 16:05:17 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (handle == nullptr) {
|
2013-12-06 16:05:17 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2016-01-15 03:06:36 -08:00
|
|
|
debug_dump_.num_bytes_left_for_log_ = max_log_size_bytes;
|
|
|
|
|
|
2013-12-06 16:05:17 +00:00
|
|
|
// Stop any ongoing recording.
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
debug_dump_.debug_file->CloseFile();
|
2013-12-06 16:05:17 +00:00
|
|
|
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
if (!debug_dump_.debug_file->OpenFromFileHandle(handle)) {
|
2013-12-06 16:05:17 +00:00
|
|
|
return kFileError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:39:14 +02:00
|
|
|
RETURN_ON_ERR(WriteConfigMessage(true));
|
|
|
|
|
RETURN_ON_ERR(WriteInitMessage());
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNoError;
|
2011-12-03 00:03:31 +00:00
|
|
|
#else
|
|
|
|
|
return kUnsupportedFunctionError;
|
|
|
|
|
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-10 08:36:56 +00:00
|
|
|
int AudioProcessingImpl::StartDebugRecordingForPlatformFile(
|
|
|
|
|
rtc::PlatformFile handle) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2014-10-10 08:36:56 +00:00
|
|
|
FILE* stream = rtc::FdopenPlatformFileForWriting(handle);
|
2016-01-15 03:06:36 -08:00
|
|
|
return StartDebugRecording(stream, -1);
|
2014-10-10 08:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int AudioProcessingImpl::StopDebugRecording() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2011-12-03 00:03:31 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2011-07-07 08:21:25 +00:00
|
|
|
// We just return if recording hasn't started.
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
debug_dump_.debug_file->CloseFile();
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNoError;
|
2011-12-03 00:03:31 +00:00
|
|
|
#else
|
|
|
|
|
return kUnsupportedFunctionError;
|
|
|
|
|
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EchoCancellation* AudioProcessingImpl::echo_cancellation() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2016-03-05 03:01:14 -08:00
|
|
|
return public_submodules_->echo_cancellation.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2016-03-10 12:54:25 -08:00
|
|
|
return public_submodules_->echo_control_mobile.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GainControl* AudioProcessingImpl::gain_control() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc) {
|
|
|
|
|
return public_submodules_->gain_control_for_experimental_agc.get();
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2016-03-10 21:09:04 -08:00
|
|
|
return public_submodules_->gain_control.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HighPassFilter* AudioProcessingImpl::high_pass_filter() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2015-12-08 11:07:32 -08:00
|
|
|
return public_submodules_->high_pass_filter.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LevelEstimator* AudioProcessingImpl::level_estimator() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2015-12-15 11:39:38 -08:00
|
|
|
return public_submodules_->level_estimator.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NoiseSuppression* AudioProcessingImpl::noise_suppression() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2015-12-08 13:22:33 -08:00
|
|
|
return public_submodules_->noise_suppression.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoiceDetection* AudioProcessingImpl::voice_detection() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Adding a lock here has no effect as it allows any access to the submodule
|
|
|
|
|
// from the returned pointer.
|
2015-12-16 03:31:12 -08:00
|
|
|
return public_submodules_->voice_detection.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-31 18:04:40 -07:00
|
|
|
bool AudioProcessingImpl::is_fwd_processed() const {
|
2016-02-22 02:00:09 -08:00
|
|
|
// The beamformer, noise suppressor and highpass filter
|
|
|
|
|
// modify the data.
|
|
|
|
|
if (capture_nonlocked_.beamformer_enabled ||
|
|
|
|
|
public_submodules_->high_pass_filter->is_enabled() ||
|
2016-03-05 03:01:14 -08:00
|
|
|
public_submodules_->noise_suppression->is_enabled() ||
|
2016-03-10 12:54:25 -08:00
|
|
|
public_submodules_->echo_cancellation->is_enabled() ||
|
2016-03-10 21:09:04 -08:00
|
|
|
public_submodules_->echo_control_mobile->is_enabled() ||
|
|
|
|
|
public_submodules_->gain_control->is_enabled()) {
|
2014-12-19 19:57:34 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 02:00:09 -08:00
|
|
|
// The capture data is otherwise unchanged.
|
|
|
|
|
return false;
|
2011-12-03 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
bool AudioProcessingImpl::output_copy_needed() const {
|
2012-04-24 18:38:03 +00:00
|
|
|
// Check if we've upmixed or downmixed the audio.
|
2015-11-28 12:35:15 -08:00
|
|
|
return ((formats_.api_format.output_stream().num_channels() !=
|
|
|
|
|
formats_.api_format.input_stream().num_channels()) ||
|
2016-06-29 15:26:12 -07:00
|
|
|
is_fwd_processed() || capture_.transient_suppressor_enabled ||
|
|
|
|
|
capture_nonlocked_.level_controller_enabled);
|
2011-12-03 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
bool AudioProcessingImpl::fwd_synthesis_needed() const {
|
2016-03-31 18:04:40 -07:00
|
|
|
return (is_fwd_processed() &&
|
2016-03-16 18:26:35 -07:00
|
|
|
is_multi_band(capture_nonlocked_.fwd_proc_format.sample_rate_hz()));
|
2012-04-24 18:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
bool AudioProcessingImpl::fwd_analysis_needed() const {
|
2016-03-31 18:04:40 -07:00
|
|
|
if (!is_fwd_processed() &&
|
2015-11-28 12:35:15 -08:00
|
|
|
!public_submodules_->voice_detection->is_enabled() &&
|
|
|
|
|
!capture_.transient_suppressor_enabled) {
|
|
|
|
|
// Only public_submodules_->level_estimator is enabled.
|
2011-12-03 00:03:31 +00:00
|
|
|
return false;
|
2016-03-16 18:26:35 -07:00
|
|
|
} else if (is_multi_band(
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.sample_rate_hz())) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Something besides public_submodules_->level_estimator is enabled, and we
|
|
|
|
|
// have super-wb.
|
2011-12-03 00:03:31 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
bool AudioProcessingImpl::is_rev_processed() const {
|
2016-05-16 15:32:38 -07:00
|
|
|
return capture_nonlocked_.intelligibility_enabled;
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 18:26:35 -07:00
|
|
|
bool AudioProcessingImpl::rev_synthesis_needed() const {
|
|
|
|
|
return (is_rev_processed() &&
|
2016-04-20 15:27:58 -07:00
|
|
|
is_multi_band(formats_.rev_proc_format.sample_rate_hz()));
|
2016-03-16 18:26:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::rev_analysis_needed() const {
|
2016-04-20 15:27:58 -07:00
|
|
|
return is_multi_band(formats_.rev_proc_format.sample_rate_hz()) &&
|
2016-03-31 18:04:40 -07:00
|
|
|
(is_rev_processed() ||
|
2016-04-06 09:30:58 -07:00
|
|
|
public_submodules_->echo_cancellation
|
|
|
|
|
->is_enabled_render_side_query() ||
|
|
|
|
|
public_submodules_->echo_control_mobile
|
|
|
|
|
->is_enabled_render_side_query() ||
|
|
|
|
|
public_submodules_->gain_control->is_enabled_render_side_query());
|
2016-03-16 18:26:35 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 02:47:28 -08:00
|
|
|
bool AudioProcessingImpl::render_check_rev_conversion_needed() const {
|
|
|
|
|
return rev_conversion_needed();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
bool AudioProcessingImpl::rev_conversion_needed() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
return (formats_.api_format.reverse_input_stream() !=
|
|
|
|
|
formats_.api_format.reverse_output_stream());
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:42:40 +02:00
|
|
|
void AudioProcessingImpl::InitializeExperimentalAgc() {
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc) {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (!private_submodules_->agc_manager.get()) {
|
|
|
|
|
private_submodules_->agc_manager.reset(new AgcManagerDirect(
|
2016-03-10 21:09:04 -08:00
|
|
|
public_submodules_->gain_control.get(),
|
2016-02-13 16:40:47 -08:00
|
|
|
public_submodules_->gain_control_for_experimental_agc.get(),
|
2015-11-28 12:35:15 -08:00
|
|
|
constants_.agc_startup_min_volume));
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager->Initialize();
|
|
|
|
|
private_submodules_->agc_manager->SetCaptureMuted(
|
|
|
|
|
capture_.output_will_be_muted);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:42:40 +02:00
|
|
|
void AudioProcessingImpl::InitializeTransient() {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled) {
|
|
|
|
|
if (!public_submodules_->transient_suppressor.get()) {
|
|
|
|
|
public_submodules_->transient_suppressor.reset(new TransientSuppressor());
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->transient_suppressor->Initialize(
|
|
|
|
|
capture_nonlocked_.fwd_proc_format.sample_rate_hz(),
|
|
|
|
|
capture_nonlocked_.split_rate,
|
2016-01-11 20:32:29 -08:00
|
|
|
num_proc_channels());
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 19:57:34 +00:00
|
|
|
void AudioProcessingImpl::InitializeBeamformer() {
|
2016-01-11 20:32:29 -08:00
|
|
|
if (capture_nonlocked_.beamformer_enabled) {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (!private_submodules_->beamformer) {
|
|
|
|
|
private_submodules_->beamformer.reset(new NonlinearBeamformer(
|
2016-06-28 10:38:33 -07:00
|
|
|
capture_.array_geometry, capture_.target_direction));
|
2015-01-15 18:07:21 +00:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->beamformer->Initialize(kChunkSizeMs,
|
|
|
|
|
capture_nonlocked_.split_rate);
|
2014-12-19 19:57:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
void AudioProcessingImpl::InitializeIntelligibility() {
|
2016-05-16 15:32:38 -07:00
|
|
|
if (capture_nonlocked_.intelligibility_enabled) {
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->intelligibility_enhancer.reset(
|
2016-02-22 15:57:38 -08:00
|
|
|
new IntelligibilityEnhancer(capture_nonlocked_.split_rate,
|
2016-03-09 16:24:34 +01:00
|
|
|
render_.render_audio->num_channels(),
|
|
|
|
|
NoiseSuppressionImpl::num_noise_bins()));
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-08 11:07:32 -08:00
|
|
|
void AudioProcessingImpl::InitializeHighPassFilter() {
|
2016-01-11 20:32:29 -08:00
|
|
|
public_submodules_->high_pass_filter->Initialize(num_proc_channels(),
|
2015-12-08 11:07:32 -08:00
|
|
|
proc_sample_rate_hz());
|
2015-12-08 13:22:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::InitializeNoiseSuppression() {
|
2016-01-11 20:32:29 -08:00
|
|
|
public_submodules_->noise_suppression->Initialize(num_proc_channels(),
|
2015-12-08 13:22:33 -08:00
|
|
|
proc_sample_rate_hz());
|
2015-12-08 11:07:32 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-05 03:01:14 -08:00
|
|
|
void AudioProcessingImpl::InitializeEchoCanceller() {
|
2016-03-15 09:34:24 -07:00
|
|
|
public_submodules_->echo_cancellation->Initialize(
|
|
|
|
|
proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(),
|
|
|
|
|
num_proc_channels());
|
2016-03-05 03:01:14 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
void AudioProcessingImpl::InitializeGainController() {
|
2016-03-15 02:28:08 -07:00
|
|
|
public_submodules_->gain_control->Initialize(num_proc_channels(),
|
|
|
|
|
proc_sample_rate_hz());
|
2016-03-10 21:09:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-10 12:54:25 -08:00
|
|
|
void AudioProcessingImpl::InitializeEchoControlMobile() {
|
2016-03-15 04:32:28 -07:00
|
|
|
public_submodules_->echo_control_mobile->Initialize(
|
2016-03-15 14:04:58 -07:00
|
|
|
proc_split_sample_rate_hz(),
|
|
|
|
|
num_reverse_channels(),
|
|
|
|
|
num_output_channels());
|
2016-03-10 12:54:25 -08:00
|
|
|
}
|
|
|
|
|
|
2015-12-15 11:39:38 -08:00
|
|
|
void AudioProcessingImpl::InitializeLevelEstimator() {
|
|
|
|
|
public_submodules_->level_estimator->Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-29 15:26:12 -07:00
|
|
|
void AudioProcessingImpl::InitializeLevelController() {
|
|
|
|
|
private_submodules_->level_controller->Initialize(proc_sample_rate_hz());
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 03:31:12 -08:00
|
|
|
void AudioProcessingImpl::InitializeVoiceDetection() {
|
|
|
|
|
public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:57:29 +02:00
|
|
|
void AudioProcessingImpl::MaybeUpdateHistograms() {
|
2015-07-05 10:46:01 +02:00
|
|
|
static const int kMinDiffDelayMs = 60;
|
2015-06-29 14:57:29 +02:00
|
|
|
|
|
|
|
|
if (echo_cancellation()->is_enabled()) {
|
2015-07-07 11:50:05 +02:00
|
|
|
// Activate delay_jumps_ counters if we know echo_cancellation is runnning.
|
|
|
|
|
// If a stream has echo we know that the echo_cancellation is in process.
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.stream_delay_jumps == -1 &&
|
|
|
|
|
echo_cancellation()->stream_has_echo()) {
|
|
|
|
|
capture_.stream_delay_jumps = 0;
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.aec_system_delay_jumps == -1 &&
|
2015-07-07 11:50:05 +02:00
|
|
|
echo_cancellation()->stream_has_echo()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.aec_system_delay_jumps = 0;
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:57:29 +02:00
|
|
|
// Detect a jump in platform reported system delay and log the difference.
|
2015-11-28 12:35:15 -08:00
|
|
|
const int diff_stream_delay_ms =
|
|
|
|
|
capture_nonlocked_.stream_delay_ms - capture_.last_stream_delay_ms;
|
|
|
|
|
if (diff_stream_delay_ms > kMinDiffDelayMs &&
|
|
|
|
|
capture_.last_stream_delay_ms != 0) {
|
2016-03-07 01:52:59 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS("WebRTC.Audio.PlatformReportedStreamDelayJump",
|
|
|
|
|
diff_stream_delay_ms, kMinDiffDelayMs, 1000, 100);
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.stream_delay_jumps == -1) {
|
|
|
|
|
capture_.stream_delay_jumps = 0; // Activate counter if needed.
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.stream_delay_jumps++;
|
2015-06-29 14:57:29 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.last_stream_delay_ms = capture_nonlocked_.stream_delay_ms;
|
2015-06-29 14:57:29 +02:00
|
|
|
|
|
|
|
|
// Detect a jump in AEC system delay and log the difference.
|
2016-03-04 11:50:54 -08:00
|
|
|
const int samples_per_ms =
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CheckedDivExact(capture_nonlocked_.split_rate, 1000);
|
2016-03-04 11:50:54 -08:00
|
|
|
RTC_DCHECK_LT(0, samples_per_ms);
|
2015-06-29 14:57:29 +02:00
|
|
|
const int aec_system_delay_ms =
|
2016-03-04 11:50:54 -08:00
|
|
|
public_submodules_->echo_cancellation->GetSystemDelayInSamples() /
|
|
|
|
|
samples_per_ms;
|
2015-07-23 11:41:39 -07:00
|
|
|
const int diff_aec_system_delay_ms =
|
2015-11-28 12:35:15 -08:00
|
|
|
aec_system_delay_ms - capture_.last_aec_system_delay_ms;
|
2015-06-29 14:57:29 +02:00
|
|
|
if (diff_aec_system_delay_ms > kMinDiffDelayMs &&
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.last_aec_system_delay_ms != 0) {
|
2016-03-07 01:52:59 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AecSystemDelayJump",
|
|
|
|
|
diff_aec_system_delay_ms, kMinDiffDelayMs, 1000,
|
|
|
|
|
100);
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.aec_system_delay_jumps == -1) {
|
|
|
|
|
capture_.aec_system_delay_jumps = 0; // Activate counter if needed.
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.aec_system_delay_jumps++;
|
2015-06-29 14:57:29 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.last_aec_system_delay_ms = aec_system_delay_ms;
|
2015-06-29 14:57:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 11:50:05 +02:00
|
|
|
void AudioProcessingImpl::UpdateHistogramsOnCallEnd() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
|
|
|
|
|
if (capture_.stream_delay_jumps > -1) {
|
2016-03-07 01:52:59 -08:00
|
|
|
RTC_HISTOGRAM_ENUMERATION(
|
2015-07-07 11:50:05 +02:00
|
|
|
"WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps",
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.stream_delay_jumps, 51);
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.stream_delay_jumps = -1;
|
|
|
|
|
capture_.last_stream_delay_ms = 0;
|
2015-07-07 11:50:05 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.aec_system_delay_jumps > -1) {
|
2016-03-07 01:52:59 -08:00
|
|
|
RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps",
|
|
|
|
|
capture_.aec_system_delay_jumps, 51);
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.aec_system_delay_jumps = -1;
|
|
|
|
|
capture_.last_aec_system_delay_ms = 0;
|
2015-07-07 11:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-03 00:03:31 +00:00
|
|
|
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::WriteMessageToDebugFile(
|
|
|
|
|
FileWrapper* debug_file,
|
2016-01-15 03:06:36 -08:00
|
|
|
int64_t* filesize_limit_bytes,
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CriticalSection* crit_debug,
|
|
|
|
|
ApmDebugDumpThreadState* debug_state) {
|
|
|
|
|
int32_t size = debug_state->event_msg->ByteSize();
|
2011-08-03 21:08:51 +00:00
|
|
|
if (size <= 0) {
|
|
|
|
|
return kUnspecifiedError;
|
|
|
|
|
}
|
2013-10-22 10:27:23 +00:00
|
|
|
#if defined(WEBRTC_ARCH_BIG_ENDIAN)
|
2015-07-23 11:41:39 -07:00
|
|
|
// TODO(ajm): Use little-endian "on the wire". For the moment, we can be
|
|
|
|
|
// pretty safe in assuming little-endian.
|
2011-08-03 21:08:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (!debug_state->event_msg->SerializeToString(&debug_state->event_str)) {
|
2011-08-03 21:08:51 +00:00
|
|
|
return kUnspecifiedError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Ensure atomic writes of the message.
|
2016-01-15 03:06:36 -08:00
|
|
|
rtc::CritScope cs_debug(crit_debug);
|
|
|
|
|
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
RTC_DCHECK(debug_file->is_open());
|
2016-01-15 03:06:36 -08:00
|
|
|
// Update the byte counter.
|
|
|
|
|
if (*filesize_limit_bytes >= 0) {
|
|
|
|
|
*filesize_limit_bytes -=
|
|
|
|
|
(sizeof(int32_t) + debug_state->event_str.length());
|
|
|
|
|
if (*filesize_limit_bytes < 0) {
|
|
|
|
|
// Not enough bytes are left to write this message, so stop logging.
|
|
|
|
|
debug_file->CloseFile();
|
|
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
// Write message preceded by its size.
|
|
|
|
|
if (!debug_file->Write(&size, sizeof(int32_t))) {
|
|
|
|
|
return kFileError;
|
|
|
|
|
}
|
|
|
|
|
if (!debug_file->Write(debug_state->event_str.data(),
|
|
|
|
|
debug_state->event_str.length())) {
|
|
|
|
|
return kFileError;
|
|
|
|
|
}
|
2011-08-03 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_state->event_msg->Clear();
|
2011-08-03 21:08:51 +00:00
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
2011-08-03 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::WriteInitMessage() {
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.capture.event_msg->set_type(audioproc::Event::INIT);
|
|
|
|
|
audioproc::Init* msg = debug_dump_.capture.event_msg->mutable_init();
|
|
|
|
|
msg->set_sample_rate(formats_.api_format.input_stream().sample_rate_hz());
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
msg->set_num_input_channels(static_cast<google::protobuf::int32>(
|
|
|
|
|
formats_.api_format.input_stream().num_channels()));
|
|
|
|
|
msg->set_num_output_channels(static_cast<google::protobuf::int32>(
|
|
|
|
|
formats_.api_format.output_stream().num_channels()));
|
|
|
|
|
msg->set_num_reverse_channels(static_cast<google::protobuf::int32>(
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_channels()));
|
2015-08-14 10:35:55 -07:00
|
|
|
msg->set_reverse_sample_rate(
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().sample_rate_hz());
|
2015-11-17 02:16:45 -08:00
|
|
|
msg->set_output_sample_rate(
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.output_stream().sample_rate_hz());
|
2016-04-11 07:05:53 -07:00
|
|
|
msg->set_reverse_output_sample_rate(
|
|
|
|
|
formats_.api_format.reverse_output_stream().sample_rate_hz());
|
|
|
|
|
msg->set_num_reverse_output_channels(
|
|
|
|
|
formats_.api_format.reverse_output_stream().num_channels());
|
2011-08-03 21:08:51 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.capture));
|
2015-10-03 00:39:14 +02:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::WriteConfigMessage(bool forced) {
|
|
|
|
|
audioproc::Config config;
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_aec_enabled(public_submodules_->echo_cancellation->is_enabled());
|
2015-10-03 00:39:14 +02:00
|
|
|
config.set_aec_delay_agnostic_enabled(
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->echo_cancellation->is_delay_agnostic_enabled());
|
2015-10-03 00:39:14 +02:00
|
|
|
config.set_aec_drift_compensation_enabled(
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->echo_cancellation->is_drift_compensation_enabled());
|
2015-10-03 00:39:14 +02:00
|
|
|
config.set_aec_extended_filter_enabled(
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->echo_cancellation->is_extended_filter_enabled());
|
|
|
|
|
config.set_aec_suppression_level(static_cast<int>(
|
|
|
|
|
public_submodules_->echo_cancellation->suppression_level()));
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_aecm_enabled(
|
|
|
|
|
public_submodules_->echo_control_mobile->is_enabled());
|
2015-10-03 00:39:14 +02:00
|
|
|
config.set_aecm_comfort_noise_enabled(
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->echo_control_mobile->is_comfort_noise_enabled());
|
|
|
|
|
config.set_aecm_routing_mode(static_cast<int>(
|
|
|
|
|
public_submodules_->echo_control_mobile->routing_mode()));
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_agc_enabled(public_submodules_->gain_control->is_enabled());
|
|
|
|
|
config.set_agc_mode(
|
|
|
|
|
static_cast<int>(public_submodules_->gain_control->mode()));
|
|
|
|
|
config.set_agc_limiter_enabled(
|
|
|
|
|
public_submodules_->gain_control->is_limiter_enabled());
|
2016-02-13 16:40:47 -08:00
|
|
|
config.set_noise_robust_agc_enabled(constants_.use_experimental_agc);
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_hpf_enabled(public_submodules_->high_pass_filter->is_enabled());
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_ns_enabled(public_submodules_->noise_suppression->is_enabled());
|
|
|
|
|
config.set_ns_level(
|
|
|
|
|
static_cast<int>(public_submodules_->noise_suppression->level()));
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
config.set_transient_suppression_enabled(
|
|
|
|
|
capture_.transient_suppressor_enabled);
|
2016-05-16 15:32:38 -07:00
|
|
|
config.set_intelligibility_enhancer_enabled(
|
|
|
|
|
capture_nonlocked_.intelligibility_enabled);
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2016-04-15 01:19:44 -07:00
|
|
|
std::string experiments_description =
|
|
|
|
|
public_submodules_->echo_cancellation->GetExperimentsDescription();
|
|
|
|
|
// TODO(peah): Add semicolon-separated concatenations of experiment
|
|
|
|
|
// descriptions for other submodules.
|
2016-06-29 15:26:12 -07:00
|
|
|
if (capture_nonlocked_.level_controller_enabled) {
|
|
|
|
|
experiments_description += "LevelController;";
|
|
|
|
|
}
|
2016-04-15 01:19:44 -07:00
|
|
|
config.set_experiments_description(experiments_description);
|
|
|
|
|
|
2015-10-03 00:39:14 +02:00
|
|
|
std::string serialized_config = config.SerializeAsString();
|
2015-11-28 12:35:15 -08:00
|
|
|
if (!forced &&
|
|
|
|
|
debug_dump_.capture.last_serialized_config == serialized_config) {
|
2015-10-03 00:39:14 +02:00
|
|
|
return kNoError;
|
2011-08-03 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.capture.last_serialized_config = serialized_config;
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG);
|
|
|
|
|
debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
|
2015-10-03 00:39:14 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
|
2016-01-15 03:06:36 -08:00
|
|
|
&debug_dump_.num_bytes_left_for_log_,
|
2015-11-28 12:35:15 -08:00
|
|
|
&crit_debug_, &debug_dump_.capture));
|
2011-08-03 21:08:51 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
2011-12-03 00:03:31 +00:00
|
|
|
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|