1/*
2 *  Copyright (c) 2011 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
14#include "audio_processing.h"
15
16#include <list>
17#include <string>
18
19#include "scoped_ptr.h"
20
21namespace webrtc {
22class AudioBuffer;
23class CriticalSectionWrapper;
24class EchoCancellationImpl;
25class 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
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;
72  virtual int StartDebugRecording(const char filename[kMaxFilenameSize]);
73  virtual int StopDebugRecording();
74  virtual EchoCancellation* echo_cancellation() const;
75  virtual EchoControlMobile* echo_control_mobile() const;
76  virtual GainControl* gain_control() const;
77  virtual HighPassFilter* high_pass_filter() const;
78  virtual LevelEstimator* level_estimator() const;
79  virtual NoiseSuppression* noise_suppression() const;
80  virtual VoiceDetection* voice_detection() const;
81
82  // Module methods.
83  virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
84
85 private:
86  bool stream_data_changed() const;
87  bool synthesis_needed(bool stream_data_changed) const;
88  bool analysis_needed(bool stream_data_changed) const;
89
90  int id_;
91
92  EchoCancellationImpl* echo_cancellation_;
93  EchoControlMobileImpl* echo_control_mobile_;
94  GainControlImpl* gain_control_;
95  HighPassFilterImpl* high_pass_filter_;
96  LevelEstimatorImpl* level_estimator_;
97  NoiseSuppressionImpl* noise_suppression_;
98  VoiceDetectionImpl* voice_detection_;
99
100  std::list<ProcessingComponent*> component_list_;
101  CriticalSectionWrapper* crit_;
102  AudioBuffer* render_audio_;
103  AudioBuffer* capture_audio_;
104#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
105  // TODO(andrew): make this more graceful. Ideally we would split this stuff
106  // out into a separate class with an "enabled" and "disabled" implementation.
107  int WriteMessageToDebugFile();
108  int WriteInitMessage();
109  scoped_ptr<FileWrapper> debug_file_;
110  scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
111  std::string event_str_; // Memory for protobuf serialization.
112#endif
113
114  int sample_rate_hz_;
115  int split_sample_rate_hz_;
116  int samples_per_channel_;
117  int stream_delay_ms_;
118  bool was_stream_delay_set_;
119
120  int num_reverse_channels_;
121  int num_input_channels_;
122  int num_output_channels_;
123};
124}  // namespace webrtc
125
126#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_
127