blob: 1a3c6ea64100df1c84adf7c29379286d5cd08dd8 [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
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000014#include "audio_processing.h"
15
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
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000019#include "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;
niklase@google.com470e71d2011-07-07 08:21:25 +000024class EchoCancellationImpl;
25class 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:
44 enum {
45 kSampleRate8kHz = 8000,
46 kSampleRate16kHz = 16000,
47 kSampleRate32kHz = 32000
48 };
49
50 explicit AudioProcessingImpl(int id);
51 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.
59 virtual int Initialize();
60 virtual int InitializeLocked();
61 virtual int set_sample_rate_hz(int rate);
62 virtual int sample_rate_hz() const;
63 virtual int set_num_channels(int input_channels, int output_channels);
64 virtual int num_input_channels() const;
65 virtual int num_output_channels() const;
66 virtual int set_num_reverse_channels(int channels);
67 virtual int num_reverse_channels() const;
68 virtual int ProcessStream(AudioFrame* frame);
69 virtual int AnalyzeReverseStream(AudioFrame* frame);
70 virtual int set_stream_delay_ms(int delay);
71 virtual int stream_delay_ms() const;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +000072 virtual void set_delay_offset_ms(int offset);
73 virtual int delay_offset_ms() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000074 virtual int StartDebugRecording(const char filename[kMaxFilenameSize]);
75 virtual int StopDebugRecording();
76 virtual EchoCancellation* echo_cancellation() const;
77 virtual EchoControlMobile* echo_control_mobile() const;
78 virtual GainControl* gain_control() const;
79 virtual HighPassFilter* high_pass_filter() const;
80 virtual LevelEstimator* level_estimator() const;
81 virtual NoiseSuppression* noise_suppression() const;
82 virtual VoiceDetection* voice_detection() const;
83
84 // Module methods.
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000085 virtual int32_t ChangeUniqueId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000086
87 private:
andrew@webrtc.org369166a2012-04-24 18:38:03 +000088 bool is_data_processed() const;
89 bool interleave_needed(bool is_data_processed) const;
90 bool synthesis_needed(bool is_data_processed) const;
91 bool analysis_needed(bool is_data_processed) const;
ajm@google.com808e0e02011-08-03 21:08:51 +000092
niklase@google.com470e71d2011-07-07 08:21:25 +000093 int id_;
94
95 EchoCancellationImpl* echo_cancellation_;
96 EchoControlMobileImpl* echo_control_mobile_;
97 GainControlImpl* gain_control_;
98 HighPassFilterImpl* high_pass_filter_;
99 LevelEstimatorImpl* level_estimator_;
100 NoiseSuppressionImpl* noise_suppression_;
101 VoiceDetectionImpl* voice_detection_;
102
103 std::list<ProcessingComponent*> component_list_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104 CriticalSectionWrapper* crit_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 AudioBuffer* render_audio_;
106 AudioBuffer* capture_audio_;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000107#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
108 // TODO(andrew): make this more graceful. Ideally we would split this stuff
109 // out into a separate class with an "enabled" and "disabled" implementation.
110 int WriteMessageToDebugFile();
111 int WriteInitMessage();
112 scoped_ptr<FileWrapper> debug_file_;
113 scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
114 std::string event_str_; // Memory for protobuf serialization.
115#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
117 int sample_rate_hz_;
118 int split_sample_rate_hz_;
119 int samples_per_channel_;
120 int stream_delay_ms_;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000121 int delay_offset_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122 bool was_stream_delay_set_;
123
ajm@google.com808e0e02011-08-03 21:08:51 +0000124 int num_reverse_channels_;
125 int num_input_channels_;
126 int num_output_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127};
128} // namespace webrtc
129
130#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_