blob: 249b789d0ddc655e3140d00008c087bc2375d635 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
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.org9fb16132013-05-28 08:11:59 +000014#include "webrtc/modules/audio_processing/include/audio_processing.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000015
16#include <list>
17#include <string>
18
pbos@webrtc.org9fb16132013-05-28 08:11:59 +000019#include "webrtc/system_wrappers/interface/scoped_ptr.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000020
21namespace webrtc {
22class AudioBuffer;
23class CriticalSectionWrapper;
andrew@webrtc.org25613ea2013-07-25 18:28:29 +000024class EchoCancellationImplWrapper;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000025class EchoControlMobileImpl;
26class FileWrapper;
27class GainControlImpl;
28class HighPassFilterImpl;
29class LevelEstimatorImpl;
30class NoiseSuppressionImpl;
31class ProcessingComponent;
32class VoiceDetectionImpl;
33
34#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
35namespace audioproc {
36
37class Event;
38
39} // namespace audioproc
40#endif
41
42class AudioProcessingImpl : public AudioProcessing {
43 public:
44 enum {
45 kSampleRate8kHz = 8000,
46 kSampleRate16kHz = 16000,
47 kSampleRate32kHz = 32000
48 };
49
andrew@webrtc.org3fbe6662014-01-25 02:09:06 +000050 explicit AudioProcessingImpl(const Config& config);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000051 virtual ~AudioProcessingImpl();
52
53 CriticalSectionWrapper* crit() const;
54
55 int split_sample_rate_hz() const;
56 bool was_stream_delay_set() const;
57
58 // AudioProcessing methods.
pbos@webrtc.org24add922013-08-02 11:44:11 +000059 virtual int Initialize() OVERRIDE;
pbos@webrtc.org24add922013-08-02 11:44:11 +000060 virtual void SetExtraOptions(const Config& config) OVERRIDE;
aluebs@webrtc.org09b40ec2013-11-19 15:17:51 +000061 virtual int EnableExperimentalNs(bool enable) OVERRIDE;
62 virtual bool experimental_ns_enabled() const OVERRIDE {
63 return false;
64 }
pbos@webrtc.org24add922013-08-02 11:44:11 +000065 virtual int set_sample_rate_hz(int rate) OVERRIDE;
66 virtual int sample_rate_hz() const OVERRIDE;
67 virtual int set_num_channels(int input_channels,
68 int output_channels) OVERRIDE;
69 virtual int num_input_channels() const OVERRIDE;
70 virtual int num_output_channels() const OVERRIDE;
71 virtual int set_num_reverse_channels(int channels) OVERRIDE;
72 virtual int num_reverse_channels() const OVERRIDE;
73 virtual int ProcessStream(AudioFrame* frame) OVERRIDE;
74 virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE;
75 virtual int set_stream_delay_ms(int delay) OVERRIDE;
76 virtual int stream_delay_ms() const OVERRIDE;
77 virtual void set_delay_offset_ms(int offset) OVERRIDE;
78 virtual int delay_offset_ms() const OVERRIDE;
79 virtual int StartDebugRecording(
80 const char filename[kMaxFilenameSize]) OVERRIDE;
henrikg@webrtc.org7b722642013-12-06 16:05:17 +000081 virtual int StartDebugRecording(FILE* handle) OVERRIDE;
pbos@webrtc.org24add922013-08-02 11:44:11 +000082 virtual int StopDebugRecording() OVERRIDE;
83 virtual EchoCancellation* echo_cancellation() const OVERRIDE;
84 virtual EchoControlMobile* echo_control_mobile() const OVERRIDE;
85 virtual GainControl* gain_control() const OVERRIDE;
86 virtual HighPassFilter* high_pass_filter() const OVERRIDE;
87 virtual LevelEstimator* level_estimator() const OVERRIDE;
88 virtual NoiseSuppression* noise_suppression() const OVERRIDE;
89 virtual VoiceDetection* voice_detection() const OVERRIDE;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000090
91 // Module methods.
pbos@webrtc.org24add922013-08-02 11:44:11 +000092 virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000093
andrew@webrtc.orge95dc252014-01-07 17:45:09 +000094 protected:
95 virtual int InitializeLocked();
96
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000097 private:
andrew@webrtc.orge95dc252014-01-07 17:45:09 +000098 int MaybeInitializeLocked(int sample_rate_hz, int num_input_channels,
99 int num_output_channels, int num_reverse_channels);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000100 bool is_data_processed() const;
101 bool interleave_needed(bool is_data_processed) const;
102 bool synthesis_needed(bool is_data_processed) const;
103 bool analysis_needed(bool is_data_processed) const;
104
andrew@webrtc.org25613ea2013-07-25 18:28:29 +0000105 EchoCancellationImplWrapper* echo_cancellation_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000106 EchoControlMobileImpl* echo_control_mobile_;
107 GainControlImpl* gain_control_;
108 HighPassFilterImpl* high_pass_filter_;
109 LevelEstimatorImpl* level_estimator_;
110 NoiseSuppressionImpl* noise_suppression_;
111 VoiceDetectionImpl* voice_detection_;
112
113 std::list<ProcessingComponent*> component_list_;
114 CriticalSectionWrapper* crit_;
115 AudioBuffer* render_audio_;
116 AudioBuffer* capture_audio_;
117#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
118 // TODO(andrew): make this more graceful. Ideally we would split this stuff
119 // out into a separate class with an "enabled" and "disabled" implementation.
120 int WriteMessageToDebugFile();
121 int WriteInitMessage();
122 scoped_ptr<FileWrapper> debug_file_;
andrew@webrtc.orge95dc252014-01-07 17:45:09 +0000123 scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
124 std::string event_str_; // Memory for protobuf serialization.
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000125#endif
126
127 int sample_rate_hz_;
128 int split_sample_rate_hz_;
129 int samples_per_channel_;
130 int stream_delay_ms_;
131 int delay_offset_ms_;
132 bool was_stream_delay_set_;
133
134 int num_reverse_channels_;
135 int num_input_channels_;
136 int num_output_channels_;
137};
138} // namespace webrtc
139
140#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_