blob: d5a8b0b445155e655e42b3702f1f37523f7a2f0e [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
kwiberg88788ad2016-02-19 07:04:49 -080016#include <memory>
terelius85fa7d52016-03-24 01:51:52 -070017#include <vector>
kwiberg88788ad2016-02-19 07:04:49 -080018
Yves Gerey988cc082018-10-23 12:03:01 +020019#include "api/array_view.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000022
niklase@google.com470e71d2011-07-07 08:21:25 +000023class AudioBuffer;
24
sazabe490b22018-10-03 17:03:13 +020025// The acoustic echo control for mobile (AECM) component is a low complexity
26// robust option intended for use on mobile devices.
Sam Zackrisson8c147b62018-09-28 12:40:47 +020027class EchoControlMobileImpl {
niklase@google.com470e71d2011-07-07 08:21:25 +000028 public:
Sam Zackrissonc22f5512018-11-05 16:10:00 +010029 EchoControlMobileImpl();
peahdf3efa82015-11-28 12:35:15 -080030
Sam Zackrisson8c147b62018-09-28 12:40:47 +020031 ~EchoControlMobileImpl();
32
33 int Enable(bool enable);
34 bool is_enabled() const;
35
36 // Recommended settings for particular audio routes. In general, the louder
37 // the echo is expected to be, the higher this value should be set. The
38 // preferred setting may vary from device to device.
39 enum RoutingMode {
40 kQuietEarpieceOrHeadset,
41 kEarpiece,
42 kLoudEarpiece,
43 kSpeakerphone,
44 kLoudSpeakerphone
45 };
46
47 // Sets echo control appropriate for the audio routing |mode| on the device.
48 // It can and should be updated during a call if the audio routing changes.
49 int set_routing_mode(RoutingMode mode);
50 RoutingMode routing_mode() const;
51
52 // Comfort noise replaces suppressed background noise to maintain a
53 // consistent signal level.
54 int enable_comfort_noise(bool enable);
55 bool is_comfort_noise_enabled() const;
56
peaha0624602016-10-25 04:45:24 -070057 void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
peah253534d2016-03-15 04:32:28 -070058 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
peah253534d2016-03-15 04:32:28 -070060 void Initialize(int sample_rate_hz,
61 size_t num_reverse_channels,
62 size_t num_output_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
peaha0624602016-10-25 04:45:24 -070064 static void PackRenderAudioBuffer(const AudioBuffer* audio,
65 size_t num_output_channels,
66 size_t num_channels,
67 std::vector<int16_t>* packed_buffer);
68
69 static size_t NumCancellersRequired(size_t num_output_channels,
70 size_t num_reverse_channels);
peahfa6228e2015-11-16 16:27:42 -080071
niklase@google.com470e71d2011-07-07 08:21:25 +000072 private:
peahbb9edbd2016-03-10 12:54:25 -080073 class Canceller;
peah253534d2016-03-15 04:32:28 -070074 struct StreamProperties;
peahbb9edbd2016-03-10 12:54:25 -080075
peahbb9edbd2016-03-10 12:54:25 -080076 int Configure();
peahfa6228e2015-11-16 16:27:42 -080077
peahbb9edbd2016-03-10 12:54:25 -080078 bool enabled_ = false;
79
Sam Zackrissonc22f5512018-11-05 16:10:00 +010080 RoutingMode routing_mode_;
81 bool comfort_noise_enabled_;
peahdf3efa82015-11-28 12:35:15 -080082
peahbb9edbd2016-03-10 12:54:25 -080083 std::vector<std::unique_ptr<Canceller>> cancellers_;
peah253534d2016-03-15 04:32:28 -070084 std::unique_ptr<StreamProperties> stream_properties_;
niklase@google.com470e71d2011-07-07 08:21:25 +000085};
86} // namespace webrtc
87
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_