File: audio_processing_impl.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (227 lines) | stat: -rw-r--r-- 8,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_

#include "webrtc/modules/audio_processing/include/audio_processing.h"

#include <list>
#include <string>

#include "webrtc/base/thread_annotations.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"

namespace webrtc {

class AgcManagerDirect;
class AudioBuffer;
class Beamformer;
class CriticalSectionWrapper;
class EchoCancellationImpl;
class EchoControlMobileImpl;
class FileWrapper;
class GainControlImpl;
class GainControlForNewAgc;
class HighPassFilterImpl;
class LevelEstimatorImpl;
class NoiseSuppressionImpl;
class ProcessingComponent;
class TransientSuppressor;
class VoiceDetectionImpl;

#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
namespace audioproc {

class Event;

}  // namespace audioproc
#endif

class AudioRate {
 public:
  explicit AudioRate(int sample_rate_hz)
      : rate_(sample_rate_hz),
        samples_per_channel_(AudioProcessing::kChunkSizeMs * rate_ / 1000) {}
  virtual ~AudioRate() {}

  void set(int rate) {
    rate_ = rate;
    samples_per_channel_ = AudioProcessing::kChunkSizeMs * rate_ / 1000;
  }

  int rate() const { return rate_; }
  int samples_per_channel() const { return samples_per_channel_; }

 private:
  int rate_;
  int samples_per_channel_;
};

class AudioFormat : public AudioRate {
 public:
  AudioFormat(int sample_rate_hz, int num_channels)
      : AudioRate(sample_rate_hz),
        num_channels_(num_channels) {}
  virtual ~AudioFormat() {}

  void set(int rate, int num_channels) {
    AudioRate::set(rate);
    num_channels_ = num_channels;
  }

  int num_channels() const { return num_channels_; }

 private:
  int num_channels_;
};

class AudioProcessingImpl : public AudioProcessing {
 public:
  explicit AudioProcessingImpl(const Config& config);
  virtual ~AudioProcessingImpl();

  // AudioProcessing methods.
  virtual int Initialize() OVERRIDE;
  virtual int Initialize(int input_sample_rate_hz,
                         int output_sample_rate_hz,
                         int reverse_sample_rate_hz,
                         ChannelLayout input_layout,
                         ChannelLayout output_layout,
                         ChannelLayout reverse_layout) OVERRIDE;
  virtual void SetExtraOptions(const Config& config) OVERRIDE;
  virtual int set_sample_rate_hz(int rate) OVERRIDE;
  virtual int input_sample_rate_hz() const OVERRIDE;
  virtual int sample_rate_hz() const OVERRIDE;
  virtual int proc_sample_rate_hz() const OVERRIDE;
  virtual int proc_split_sample_rate_hz() const OVERRIDE;
  virtual int num_input_channels() const OVERRIDE;
  virtual int num_output_channels() const OVERRIDE;
  virtual int num_reverse_channels() const OVERRIDE;
  virtual void set_output_will_be_muted(bool muted) OVERRIDE;
  virtual bool output_will_be_muted() const OVERRIDE;
  virtual int ProcessStream(AudioFrame* frame) OVERRIDE;
  virtual int ProcessStream(const float* const* src,
                            int samples_per_channel,
                            int input_sample_rate_hz,
                            ChannelLayout input_layout,
                            int output_sample_rate_hz,
                            ChannelLayout output_layout,
                            float* const* dest) OVERRIDE;
  virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE;
  virtual int AnalyzeReverseStream(const float* const* data,
                                   int samples_per_channel,
                                   int sample_rate_hz,
                                   ChannelLayout layout) OVERRIDE;
  virtual int set_stream_delay_ms(int delay) OVERRIDE;
  virtual int stream_delay_ms() const OVERRIDE;
  virtual bool was_stream_delay_set() const OVERRIDE;
  virtual void set_delay_offset_ms(int offset) OVERRIDE;
  virtual int delay_offset_ms() const OVERRIDE;
  virtual void set_stream_key_pressed(bool key_pressed) OVERRIDE;
  virtual bool stream_key_pressed() const OVERRIDE;
  virtual int StartDebugRecording(
      const char filename[kMaxFilenameSize]) OVERRIDE;
  virtual int StartDebugRecording(FILE* handle) OVERRIDE;
  virtual int StartDebugRecordingForPlatformFile(
      rtc::PlatformFile handle) OVERRIDE;
  virtual int StopDebugRecording() OVERRIDE;
  virtual EchoCancellation* echo_cancellation() const OVERRIDE;
  virtual EchoControlMobile* echo_control_mobile() const OVERRIDE;
  virtual GainControl* gain_control() const OVERRIDE;
  virtual HighPassFilter* high_pass_filter() const OVERRIDE;
  virtual LevelEstimator* level_estimator() const OVERRIDE;
  virtual NoiseSuppression* noise_suppression() const OVERRIDE;
  virtual VoiceDetection* voice_detection() const OVERRIDE;

 protected:
  // Overridden in a mock.
  virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);

 private:
  int InitializeLocked(int input_sample_rate_hz,
                       int output_sample_rate_hz,
                       int reverse_sample_rate_hz,
                       int num_input_channels,
                       int num_output_channels,
                       int num_reverse_channels)
      EXCLUSIVE_LOCKS_REQUIRED(crit_);
  int MaybeInitializeLocked(int input_sample_rate_hz,
                            int output_sample_rate_hz,
                            int reverse_sample_rate_hz,
                            int num_input_channels,
                            int num_output_channels,
                            int num_reverse_channels)
      EXCLUSIVE_LOCKS_REQUIRED(crit_);
  int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
  int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);

  bool is_data_processed() const;
  bool output_copy_needed(bool is_data_processed) const;
  bool synthesis_needed(bool is_data_processed) const;
  bool analysis_needed(bool is_data_processed) const;
  int InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_);
  int InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_);
  void InitializeBeamformer() EXCLUSIVE_LOCKS_REQUIRED(crit_);

  EchoCancellationImpl* echo_cancellation_;
  EchoControlMobileImpl* echo_control_mobile_;
  GainControlImpl* gain_control_;
  HighPassFilterImpl* high_pass_filter_;
  LevelEstimatorImpl* level_estimator_;
  NoiseSuppressionImpl* noise_suppression_;
  VoiceDetectionImpl* voice_detection_;
  scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc_;

  std::list<ProcessingComponent*> component_list_;
  CriticalSectionWrapper* crit_;
  scoped_ptr<AudioBuffer> render_audio_;
  scoped_ptr<AudioBuffer> capture_audio_;
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
  // TODO(andrew): make this more graceful. Ideally we would split this stuff
  // out into a separate class with an "enabled" and "disabled" implementation.
  int WriteMessageToDebugFile();
  int WriteInitMessage();
  scoped_ptr<FileWrapper> debug_file_;
  scoped_ptr<audioproc::Event> event_msg_;  // Protobuf message.
  std::string event_str_;  // Memory for protobuf serialization.
#endif

  AudioFormat fwd_in_format_;
  // This one is an AudioRate, because the forward processing number of channels
  // is mutable and is tracked by the capture_audio_.
  AudioRate fwd_proc_format_;
  AudioFormat fwd_out_format_;
  AudioFormat rev_in_format_;
  AudioFormat rev_proc_format_;
  int split_rate_;

  int stream_delay_ms_;
  int delay_offset_ms_;
  bool was_stream_delay_set_;

  bool output_will_be_muted_;

  bool key_pressed_;

  // Only set through the constructor's Config parameter.
  const bool use_new_agc_;
  scoped_ptr<AgcManagerDirect> agc_manager_ GUARDED_BY(crit_);

  bool transient_suppressor_enabled_;
  scoped_ptr<TransientSuppressor> transient_suppressor_;
  const bool beamformer_enabled_;
  scoped_ptr<Beamformer> beamformer_;
  const std::vector<Point> array_geometry_;
};

}  // namespace webrtc

#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_