blob: e4437975ddb759a9fd5c8ad0a57bda504334b72d [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
Sam Zackrisson8c147b62018-09-28 12:40:47 +020033 // Recommended settings for particular audio routes. In general, the louder
34 // the echo is expected to be, the higher this value should be set. The
35 // preferred setting may vary from device to device.
36 enum RoutingMode {
37 kQuietEarpieceOrHeadset,
38 kEarpiece,
39 kLoudEarpiece,
40 kSpeakerphone,
41 kLoudSpeakerphone
42 };
43
44 // Sets echo control appropriate for the audio routing |mode| on the device.
45 // It can and should be updated during a call if the audio routing changes.
46 int set_routing_mode(RoutingMode mode);
47 RoutingMode routing_mode() const;
48
49 // Comfort noise replaces suppressed background noise to maintain a
50 // consistent signal level.
51 int enable_comfort_noise(bool enable);
52 bool is_comfort_noise_enabled() const;
53
peaha0624602016-10-25 04:45:24 -070054 void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
peah253534d2016-03-15 04:32:28 -070055 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
peah253534d2016-03-15 04:32:28 -070057 void Initialize(int sample_rate_hz,
58 size_t num_reverse_channels,
59 size_t num_output_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
peaha0624602016-10-25 04:45:24 -070061 static void PackRenderAudioBuffer(const AudioBuffer* audio,
62 size_t num_output_channels,
63 size_t num_channels,
64 std::vector<int16_t>* packed_buffer);
65
66 static size_t NumCancellersRequired(size_t num_output_channels,
67 size_t num_reverse_channels);
peahfa6228e2015-11-16 16:27:42 -080068
niklase@google.com470e71d2011-07-07 08:21:25 +000069 private:
peahbb9edbd2016-03-10 12:54:25 -080070 class Canceller;
peah253534d2016-03-15 04:32:28 -070071 struct StreamProperties;
peahbb9edbd2016-03-10 12:54:25 -080072
peahbb9edbd2016-03-10 12:54:25 -080073 int Configure();
peahfa6228e2015-11-16 16:27:42 -080074
Sam Zackrissonc22f5512018-11-05 16:10:00 +010075 RoutingMode routing_mode_;
76 bool comfort_noise_enabled_;
peahdf3efa82015-11-28 12:35:15 -080077
peahbb9edbd2016-03-10 12:54:25 -080078 std::vector<std::unique_ptr<Canceller>> cancellers_;
peah253534d2016-03-15 04:32:28 -070079 std::unique_ptr<StreamProperties> stream_properties_;
niklase@google.com470e71d2011-07-07 08:21:25 +000080};
81} // namespace webrtc
82
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020083#endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_