2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-30 09:39:08 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-01-30 09:39:08 +00:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
#include <memory>
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
2015-11-28 12:35:15 -08:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2016-03-24 01:51:52 -07:00
|
|
|
#include "webrtc/base/swap_queue.h"
|
2015-11-28 12:35:15 -08:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2013-05-28 08:11:59 +00:00
|
|
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
2016-03-10 23:05:28 -08:00
|
|
|
#include "webrtc/modules/audio_processing/render_queue_item_verifier.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2014-02-27 22:23:17 +00:00
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
class ApmDataDumper;
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioBuffer;
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
class GainControlImpl : public GainControl {
|
2011-07-07 08:21:25 +00:00
|
|
|
public:
|
2016-03-15 02:28:08 -07:00
|
|
|
GainControlImpl(rtc::CriticalSection* crit_render,
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CriticalSection* crit_capture);
|
2016-03-10 21:09:04 -08:00
|
|
|
~GainControlImpl() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
|
2011-07-07 08:21:25 +00:00
|
|
|
int AnalyzeCaptureAudio(AudioBuffer* audio);
|
2016-03-15 02:28:08 -07:00
|
|
|
int ProcessCaptureAudio(AudioBuffer* audio, bool stream_has_echo);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-15 02:28:08 -07:00
|
|
|
void Initialize(size_t num_proc_channels, int sample_rate_hz);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
static void PackRenderAudioBuffer(AudioBuffer* audio,
|
|
|
|
|
std::vector<int16_t>* packed_buffer);
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// GainControl implementation.
|
2015-03-04 12:58:35 +00:00
|
|
|
bool is_enabled() const override;
|
|
|
|
|
int stream_analog_level() override;
|
2015-10-03 00:39:14 +02:00
|
|
|
bool is_limiter_enabled() const override;
|
|
|
|
|
Mode mode() const override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-04-28 14:58:32 -07:00
|
|
|
int compression_gain_db() const override;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2016-03-10 21:09:04 -08:00
|
|
|
class GainController;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// GainControl implementation.
|
2015-03-04 12:58:35 +00:00
|
|
|
int Enable(bool enable) override;
|
|
|
|
|
int set_stream_analog_level(int level) override;
|
|
|
|
|
int set_mode(Mode mode) override;
|
|
|
|
|
int set_target_level_dbfs(int level) override;
|
|
|
|
|
int target_level_dbfs() const override;
|
|
|
|
|
int set_compression_gain_db(int gain) override;
|
|
|
|
|
int enable_limiter(bool enable) override;
|
|
|
|
|
int set_analog_level_limits(int minimum, int maximum) override;
|
|
|
|
|
int analog_level_minimum() const override;
|
|
|
|
|
int analog_level_maximum() const override;
|
|
|
|
|
bool stream_is_saturated() const override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
int Configure();
|
2015-11-16 23:52:25 -08:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_);
|
|
|
|
|
rtc::CriticalSection* const crit_capture_;
|
|
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
bool enabled_ = false;
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
Mode mode_ GUARDED_BY(crit_capture_);
|
|
|
|
|
int minimum_capture_level_ GUARDED_BY(crit_capture_);
|
|
|
|
|
int maximum_capture_level_ GUARDED_BY(crit_capture_);
|
|
|
|
|
bool limiter_enabled_ GUARDED_BY(crit_capture_);
|
|
|
|
|
int target_level_dbfs_ GUARDED_BY(crit_capture_);
|
|
|
|
|
int compression_gain_db_ GUARDED_BY(crit_capture_);
|
|
|
|
|
int analog_capture_level_ GUARDED_BY(crit_capture_);
|
|
|
|
|
bool was_analog_level_set_ GUARDED_BY(crit_capture_);
|
|
|
|
|
bool stream_is_saturated_ GUARDED_BY(crit_capture_);
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
std::vector<std::unique_ptr<GainController>> gain_controllers_;
|
|
|
|
|
|
2016-03-15 02:28:08 -07:00
|
|
|
rtc::Optional<size_t> num_proc_channels_ GUARDED_BY(crit_capture_);
|
|
|
|
|
rtc::Optional<int> sample_rate_hz_ GUARDED_BY(crit_capture_);
|
|
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
static int instance_counter_;
|
2016-03-10 21:09:04 -08:00
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlImpl);
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2012-01-30 09:39:08 +00:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|