blob: a03ab4d48667897f11b55f8c313e3cc845266029 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
12#define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwiberg88788ad2016-02-19 07:04:49 -080014#include <memory>
terelius85fa7d52016-03-24 01:51:52 -070015#include <vector>
kwiberg88788ad2016-02-19 07:04:49 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_processing/include/audio_processing.h"
18#include "modules/audio_processing/render_queue_item_verifier.h"
19#include "rtc_base/constructormagic.h"
20#include "rtc_base/criticalsection.h"
21#include "rtc_base/swap_queue.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000024
niklase@google.com470e71d2011-07-07 08:21:25 +000025class AudioBuffer;
26
peahbb9edbd2016-03-10 12:54:25 -080027class EchoControlMobileImpl : public EchoControlMobile {
niklase@google.com470e71d2011-07-07 08:21:25 +000028 public:
peah253534d2016-03-15 04:32:28 -070029 EchoControlMobileImpl(rtc::CriticalSection* crit_render,
peahdf3efa82015-11-28 12:35:15 -080030 rtc::CriticalSection* crit_capture);
31
kwiberg83ffe452016-08-29 14:46:07 -070032 ~EchoControlMobileImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
peaha0624602016-10-25 04:45:24 -070034 void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
peah253534d2016-03-15 04:32:28 -070035 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
37 // EchoControlMobile implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 bool is_enabled() const override;
Minyue13b96ba2015-10-03 00:39:14 +020039 RoutingMode routing_mode() const override;
40 bool is_comfort_noise_enabled() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
peah253534d2016-03-15 04:32:28 -070042 void Initialize(int sample_rate_hz,
43 size_t num_reverse_channels,
44 size_t num_output_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000045
peaha0624602016-10-25 04:45:24 -070046 static void PackRenderAudioBuffer(const AudioBuffer* audio,
47 size_t num_output_channels,
48 size_t num_channels,
49 std::vector<int16_t>* packed_buffer);
50
51 static size_t NumCancellersRequired(size_t num_output_channels,
52 size_t num_reverse_channels);
peahfa6228e2015-11-16 16:27:42 -080053
niklase@google.com470e71d2011-07-07 08:21:25 +000054 private:
peahbb9edbd2016-03-10 12:54:25 -080055 class Canceller;
peah253534d2016-03-15 04:32:28 -070056 struct StreamProperties;
peahbb9edbd2016-03-10 12:54:25 -080057
niklase@google.com470e71d2011-07-07 08:21:25 +000058 // EchoControlMobile implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 int Enable(bool enable) override;
60 int set_routing_mode(RoutingMode mode) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000061 int enable_comfort_noise(bool enable) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 int SetEchoPath(const void* echo_path, size_t size_bytes) override;
63 int GetEchoPath(void* echo_path, size_t size_bytes) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
peahbb9edbd2016-03-10 12:54:25 -080065 int Configure();
peahfa6228e2015-11-16 16:27:42 -080066
danilchap56359be2017-09-07 07:53:45 -070067 rtc::CriticalSection* const crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -080068 rtc::CriticalSection* const crit_capture_;
69
peahbb9edbd2016-03-10 12:54:25 -080070 bool enabled_ = false;
71
danilchap56359be2017-09-07 07:53:45 -070072 RoutingMode routing_mode_ RTC_GUARDED_BY(crit_capture_);
73 bool comfort_noise_enabled_ RTC_GUARDED_BY(crit_capture_);
74 unsigned char* external_echo_path_ RTC_GUARDED_BY(crit_render_)
75 RTC_GUARDED_BY(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -080076
peahbb9edbd2016-03-10 12:54:25 -080077 std::vector<std::unique_ptr<Canceller>> cancellers_;
peah253534d2016-03-15 04:32:28 -070078 std::unique_ptr<StreamProperties> stream_properties_;
79
peahbb9edbd2016-03-10 12:54:25 -080080 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoControlMobileImpl);
niklase@google.com470e71d2011-07-07 08:21:25 +000081};
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_