niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 14 | #include <memory> |
terelius | 85fa7d5 | 2016-03-24 01:51:52 -0700 | [diff] [blame] | 15 | #include <vector> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 24 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | class AudioBuffer; |
| 26 | |
Sam Zackrisson | 8c147b6 | 2018-09-28 12:40:47 +0200 | [diff] [blame^] | 27 | class EchoControlMobileImpl { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | public: |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 29 | EchoControlMobileImpl(rtc::CriticalSection* crit_render, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 30 | rtc::CriticalSection* crit_capture); |
| 31 | |
Sam Zackrisson | 8c147b6 | 2018-09-28 12:40:47 +0200 | [diff] [blame^] | 32 | ~EchoControlMobileImpl(); |
| 33 | |
| 34 | int Enable(bool enable); |
| 35 | bool is_enabled() const; |
| 36 | |
| 37 | // Recommended settings for particular audio routes. In general, the louder |
| 38 | // the echo is expected to be, the higher this value should be set. The |
| 39 | // preferred setting may vary from device to device. |
| 40 | enum RoutingMode { |
| 41 | kQuietEarpieceOrHeadset, |
| 42 | kEarpiece, |
| 43 | kLoudEarpiece, |
| 44 | kSpeakerphone, |
| 45 | kLoudSpeakerphone |
| 46 | }; |
| 47 | |
| 48 | // Sets echo control appropriate for the audio routing |mode| on the device. |
| 49 | // It can and should be updated during a call if the audio routing changes. |
| 50 | int set_routing_mode(RoutingMode mode); |
| 51 | RoutingMode routing_mode() const; |
| 52 | |
| 53 | // Comfort noise replaces suppressed background noise to maintain a |
| 54 | // consistent signal level. |
| 55 | int enable_comfort_noise(bool enable); |
| 56 | bool is_comfort_noise_enabled() const; |
| 57 | |
| 58 | // A typical use case is to initialize the component with an echo path from a |
| 59 | // previous call. The echo path is retrieved using |GetEchoPath()|, typically |
| 60 | // at the end of a call. The data can then be stored for later use as an |
| 61 | // initializer before the next call, using |SetEchoPath()|. |
| 62 | // |
| 63 | // Controlling the echo path this way requires the data |size_bytes| to match |
| 64 | // the internal echo path size. This size can be acquired using |
| 65 | // |echo_path_size_bytes()|. |SetEchoPath()| causes an entire reset, worth |
| 66 | // noting if it is to be called during an ongoing call. |
| 67 | // |
| 68 | // It is possible that version incompatibilities may result in a stored echo |
| 69 | // path of the incorrect size. In this case, the stored path should be |
| 70 | // discarded. |
| 71 | int SetEchoPath(const void* echo_path, size_t size_bytes); |
| 72 | int GetEchoPath(void* echo_path, size_t size_bytes) const; |
| 73 | |
| 74 | // The returned path size is guaranteed not to change for the lifetime of |
| 75 | // the application. |
| 76 | static size_t echo_path_size_bytes(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 78 | void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio); |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 79 | int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 81 | void Initialize(int sample_rate_hz, |
| 82 | size_t num_reverse_channels, |
| 83 | size_t num_output_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 85 | static void PackRenderAudioBuffer(const AudioBuffer* audio, |
| 86 | size_t num_output_channels, |
| 87 | size_t num_channels, |
| 88 | std::vector<int16_t>* packed_buffer); |
| 89 | |
| 90 | static size_t NumCancellersRequired(size_t num_output_channels, |
| 91 | size_t num_reverse_channels); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 92 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | private: |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 94 | class Canceller; |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 95 | struct StreamProperties; |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 96 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 97 | int Configure(); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 98 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 99 | rtc::CriticalSection* const crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 100 | rtc::CriticalSection* const crit_capture_; |
| 101 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 102 | bool enabled_ = false; |
| 103 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 104 | RoutingMode routing_mode_ RTC_GUARDED_BY(crit_capture_); |
| 105 | bool comfort_noise_enabled_ RTC_GUARDED_BY(crit_capture_); |
| 106 | unsigned char* external_echo_path_ RTC_GUARDED_BY(crit_render_) |
| 107 | RTC_GUARDED_BY(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 108 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 109 | std::vector<std::unique_ptr<Canceller>> cancellers_; |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 110 | std::unique_ptr<StreamProperties> stream_properties_; |
| 111 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 112 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoControlMobileImpl); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | }; |
| 114 | } // namespace webrtc |
| 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 116 | #endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |