blob: 2f6385f026ec391c50f889dd4bcfd57098a2d60a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +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
11#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_
13
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000014#include "webrtc/modules/audio_processing/include/audio_processing.h"
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000015
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include <list>
ajm@google.com808e0e02011-08-03 21:08:51 +000017#include <string>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000019#include "webrtc/system_wrappers/interface/scoped_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022class AudioBuffer;
ajm@google.com808e0e02011-08-03 21:08:51 +000023class CriticalSectionWrapper;
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000024class EchoCancellationImpl;
niklase@google.com470e71d2011-07-07 08:21:25 +000025class EchoControlMobileImpl;
ajm@google.com808e0e02011-08-03 21:08:51 +000026class FileWrapper;
niklase@google.com470e71d2011-07-07 08:21:25 +000027class GainControlImpl;
28class HighPassFilterImpl;
29class LevelEstimatorImpl;
30class NoiseSuppressionImpl;
31class ProcessingComponent;
32class VoiceDetectionImpl;
33
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000034#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
35namespace audioproc {
36
37class Event;
38
39} // namespace audioproc
40#endif
41
niklase@google.com470e71d2011-07-07 08:21:25 +000042class AudioProcessingImpl : public AudioProcessing {
43 public:
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000044 explicit AudioProcessingImpl(const Config& config);
niklase@google.com470e71d2011-07-07 08:21:25 +000045 virtual ~AudioProcessingImpl();
46
niklase@google.com470e71d2011-07-07 08:21:25 +000047 // AudioProcessing methods.
pbos@webrtc.org91620802013-08-02 11:44:11 +000048 virtual int Initialize() OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000049 virtual void SetExtraOptions(const Config& config) OVERRIDE;
aluebs@webrtc.org0b72f582013-11-19 15:17:51 +000050 virtual int EnableExperimentalNs(bool enable) OVERRIDE;
51 virtual bool experimental_ns_enabled() const OVERRIDE {
52 return false;
53 }
pbos@webrtc.org91620802013-08-02 11:44:11 +000054 virtual int set_sample_rate_hz(int rate) OVERRIDE;
55 virtual int sample_rate_hz() const OVERRIDE;
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000056 virtual int split_sample_rate_hz() const OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000057 virtual int set_num_channels(int input_channels,
58 int output_channels) OVERRIDE;
59 virtual int num_input_channels() const OVERRIDE;
60 virtual int num_output_channels() const OVERRIDE;
61 virtual int set_num_reverse_channels(int channels) OVERRIDE;
62 virtual int num_reverse_channels() const OVERRIDE;
andrew@webrtc.org17342e52014-02-12 22:28:31 +000063 virtual void set_output_will_be_muted(bool muted) OVERRIDE;
64 virtual bool output_will_be_muted() const OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000065 virtual int ProcessStream(AudioFrame* frame) OVERRIDE;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000066 virtual int ProcessStream(float* const* data,
67 int samples_per_channel,
68 int sample_rate_hz,
69 ChannelLayout input_layout,
70 ChannelLayout output_layout) OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000071 virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000072 virtual int AnalyzeReverseStream(const float* const* data,
73 int samples_per_channel,
74 int sample_rate_hz,
75 ChannelLayout layout) OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000076 virtual int set_stream_delay_ms(int delay) OVERRIDE;
77 virtual int stream_delay_ms() const OVERRIDE;
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000078 virtual bool was_stream_delay_set() const OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000079 virtual void set_delay_offset_ms(int offset) OVERRIDE;
80 virtual int delay_offset_ms() const OVERRIDE;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +000081 virtual void set_stream_key_pressed(bool key_pressed) OVERRIDE;
82 virtual bool stream_key_pressed() const OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000083 virtual int StartDebugRecording(
84 const char filename[kMaxFilenameSize]) OVERRIDE;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000085 virtual int StartDebugRecording(FILE* handle) OVERRIDE;
pbos@webrtc.org91620802013-08-02 11:44:11 +000086 virtual int StopDebugRecording() OVERRIDE;
87 virtual EchoCancellation* echo_cancellation() const OVERRIDE;
88 virtual EchoControlMobile* echo_control_mobile() const OVERRIDE;
89 virtual GainControl* gain_control() const OVERRIDE;
90 virtual HighPassFilter* high_pass_filter() const OVERRIDE;
91 virtual LevelEstimator* level_estimator() const OVERRIDE;
92 virtual NoiseSuppression* noise_suppression() const OVERRIDE;
93 virtual VoiceDetection* voice_detection() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000095 protected:
96 virtual int InitializeLocked();
97
niklase@google.com470e71d2011-07-07 08:21:25 +000098 private:
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000099 int MaybeInitializeLocked(int sample_rate_hz, int num_input_channels,
100 int num_output_channels, int num_reverse_channels);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000101 int ProcessStreamLocked();
102 int AnalyzeReverseStreamLocked();
103
andrew@webrtc.org369166a2012-04-24 18:38:03 +0000104 bool is_data_processed() const;
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000105 bool output_copy_needed(bool is_data_processed) const;
andrew@webrtc.org369166a2012-04-24 18:38:03 +0000106 bool synthesis_needed(bool is_data_processed) const;
107 bool analysis_needed(bool is_data_processed) const;
ajm@google.com808e0e02011-08-03 21:08:51 +0000108
andrew@webrtc.org56e4a052014-02-27 22:23:17 +0000109 EchoCancellationImpl* echo_cancellation_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 EchoControlMobileImpl* echo_control_mobile_;
111 GainControlImpl* gain_control_;
112 HighPassFilterImpl* high_pass_filter_;
113 LevelEstimatorImpl* level_estimator_;
114 NoiseSuppressionImpl* noise_suppression_;
115 VoiceDetectionImpl* voice_detection_;
116
117 std::list<ProcessingComponent*> component_list_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 CriticalSectionWrapper* crit_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 AudioBuffer* render_audio_;
120 AudioBuffer* capture_audio_;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000121#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
122 // TODO(andrew): make this more graceful. Ideally we would split this stuff
123 // out into a separate class with an "enabled" and "disabled" implementation.
124 int WriteMessageToDebugFile();
125 int WriteInitMessage();
126 scoped_ptr<FileWrapper> debug_file_;
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000127 scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
128 std::string event_str_; // Memory for protobuf serialization.
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000129#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
131 int sample_rate_hz_;
132 int split_sample_rate_hz_;
133 int samples_per_channel_;
134 int stream_delay_ms_;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000135 int delay_offset_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136 bool was_stream_delay_set_;
137
ajm@google.com808e0e02011-08-03 21:08:51 +0000138 int num_reverse_channels_;
139 int num_input_channels_;
140 int num_output_channels_;
andrew@webrtc.org17342e52014-02-12 22:28:31 +0000141 bool output_will_be_muted_;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000142
143 bool key_pressed_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144};
145} // namespace webrtc
146
147#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_