OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
7 | 7 |
8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/renderer/media/webrtc_audio_device_impl.h" |
13 #include "media/base/audio_converter.h" | 14 #include "media/base/audio_converter.h" |
14 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" | 15 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
15 #include "third_party/webrtc/modules/interface/module_common_types.h" | 16 #include "third_party/webrtc/modules/interface/module_common_types.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 class WebMediaConstraints; | 19 class WebMediaConstraints; |
19 } | 20 } |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 class AudioBus; | 23 class AudioBus; |
23 class AudioFifo; | 24 class AudioFifo; |
24 class AudioParameters; | 25 class AudioParameters; |
25 } // namespace media | 26 } // namespace media |
26 | 27 |
27 namespace webrtc { | 28 namespace webrtc { |
28 class AudioFrame; | 29 class AudioFrame; |
29 class TypingDetection; | 30 class TypingDetection; |
30 } | 31 } |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 | 34 |
34 class RTCMediaConstraints; | 35 class RTCMediaConstraints; |
35 | 36 |
36 // This class owns an object of webrtc::AudioProcessing which contains signal | 37 // This class owns an object of webrtc::AudioProcessing which contains signal |
37 // processing components like AGC, AEC and NS. It enables the components based | 38 // processing components like AGC, AEC and NS. It enables the components based |
38 // on the getUserMedia constraints, processes the data and outputs it in a unit | 39 // on the getUserMedia constraints, processes the data and outputs it in a unit |
39 // of 10 ms data chunk. | 40 // of 10 ms data chunk. |
40 class CONTENT_EXPORT MediaStreamAudioProcessor : | 41 class CONTENT_EXPORT MediaStreamAudioProcessor : |
41 public base::RefCountedThreadSafe<MediaStreamAudioProcessor> { | 42 public base::RefCountedThreadSafe<MediaStreamAudioProcessor>, |
| 43 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource::Sink) { |
42 public: | 44 public: |
| 45 // |playout_data_source| is used to register this class as a sink to the |
| 46 // WebRtc playout data for processing AEC. If clients do not enable AEC, |
| 47 // |playout_data_source| won't be used. |
43 MediaStreamAudioProcessor(const media::AudioParameters& source_params, | 48 MediaStreamAudioProcessor(const media::AudioParameters& source_params, |
44 const blink::WebMediaConstraints& constraints, | 49 const blink::WebMediaConstraints& constraints, |
45 int effects); | 50 int effects, |
| 51 WebRtcPlayoutDataSource* playout_data_source); |
46 | 52 |
47 // Pushes capture data in |audio_source| to the internal FIFO. | 53 // Pushes capture data in |audio_source| to the internal FIFO. |
48 // Called on the capture audio thread. | 54 // Called on the capture audio thread. |
49 void PushCaptureData(media::AudioBus* audio_source); | 55 void PushCaptureData(media::AudioBus* audio_source); |
50 | 56 |
51 // Push the render audio to webrtc::AudioProcessing for analysis. This is | |
52 // needed iff echo processing is enabled. | |
53 // |render_audio| is the pointer to the render audio data, its format | |
54 // is specified by |sample_rate|, |number_of_channels| and |number_of_frames|. | |
55 // Called on the render audio thread. | |
56 void PushRenderData(const int16* render_audio, | |
57 int sample_rate, | |
58 int number_of_channels, | |
59 int number_of_frames, | |
60 base::TimeDelta render_delay); | |
61 | |
62 // Processes a block of 10 ms data from the internal FIFO and outputs it via | 57 // Processes a block of 10 ms data from the internal FIFO and outputs it via |
63 // |out|. |out| is the address of the pointer that will be pointed to | 58 // |out|. |out| is the address of the pointer that will be pointed to |
64 // the post-processed data if the method is returning a true. The lifetime | 59 // the post-processed data if the method is returning a true. The lifetime |
65 // of the data represeted by |out| is guaranteed to outlive the method call. | 60 // of the data represeted by |out| is guaranteed to outlive the method call. |
66 // That also says *|out| won't change until this method is called again. | 61 // That also says *|out| won't change until this method is called again. |
67 // |new_volume| receives the new microphone volume from the AGC. | 62 // |new_volume| receives the new microphone volume from the AGC. |
68 // The new microphoen volume range is [0, 255], and the value will be 0 if | 63 // The new microphoen volume range is [0, 255], and the value will be 0 if |
69 // the microphone volume should not be adjusted. | 64 // the microphone volume should not be adjusted. |
70 // Returns true if the internal FIFO has at least 10 ms data for processing, | 65 // Returns true if the internal FIFO has at least 10 ms data for processing, |
71 // otherwise false. | 66 // otherwise false. |
(...skipping 18 matching lines...) Expand all Loading... |
90 | 85 |
91 protected: | 86 protected: |
92 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; | 87 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; |
93 virtual ~MediaStreamAudioProcessor(); | 88 virtual ~MediaStreamAudioProcessor(); |
94 | 89 |
95 private: | 90 private: |
96 friend class MediaStreamAudioProcessorTest; | 91 friend class MediaStreamAudioProcessorTest; |
97 | 92 |
98 class MediaStreamAudioConverter; | 93 class MediaStreamAudioConverter; |
99 | 94 |
| 95 // WebRtcPlayoutDataSource::Sink implementation. |
| 96 virtual void OnPlayoutData(media::AudioBus* audio_bus, |
| 97 int sample_rate, |
| 98 int audio_delay_milliseconds) OVERRIDE; |
| 99 |
100 // Helper to initialize the WebRtc AudioProcessing. | 100 // Helper to initialize the WebRtc AudioProcessing. |
101 void InitializeAudioProcessingModule( | 101 void InitializeAudioProcessingModule( |
102 const blink::WebMediaConstraints& constraints, int effects); | 102 const blink::WebMediaConstraints& constraints, int effects); |
103 | 103 |
104 // Helper to initialize the capture converter. | 104 // Helper to initialize the capture converter. |
105 void InitializeCaptureConverter(const media::AudioParameters& source_params); | 105 void InitializeCaptureConverter(const media::AudioParameters& source_params); |
106 | 106 |
107 // Helper to initialize the render converter. | 107 // Helper to initialize the render converter. |
108 void InitializeRenderConverterIfNeeded(int sample_rate, | 108 void InitializeRenderConverterIfNeeded(int sample_rate, |
109 int number_of_channels, | 109 int number_of_channels, |
(...skipping 27 matching lines...) Expand all Loading... |
137 // Converter used for the down-mixing and resampling of the render data when | 137 // Converter used for the down-mixing and resampling of the render data when |
138 // the AEC is enabled. | 138 // the AEC is enabled. |
139 scoped_ptr<MediaStreamAudioConverter> render_converter_; | 139 scoped_ptr<MediaStreamAudioConverter> render_converter_; |
140 | 140 |
141 // AudioFrame used to hold the output of |render_converter_|. | 141 // AudioFrame used to hold the output of |render_converter_|. |
142 webrtc::AudioFrame render_frame_; | 142 webrtc::AudioFrame render_frame_; |
143 | 143 |
144 // Data bus to help converting interleaved data to an AudioBus. | 144 // Data bus to help converting interleaved data to an AudioBus. |
145 scoped_ptr<media::AudioBus> render_data_bus_; | 145 scoped_ptr<media::AudioBus> render_data_bus_; |
146 | 146 |
147 // Used to DCHECK that some methods are called on the main render thread. | 147 // Raw pointer to the WebRtcPlayoutDataSource, which is valid for the |
| 148 // lifetime of RenderThread. |
| 149 WebRtcPlayoutDataSource* const playout_data_source_; |
| 150 |
| 151 // Used to DCHECK that the destructor is called on the main render thread. |
148 base::ThreadChecker main_thread_checker_; | 152 base::ThreadChecker main_thread_checker_; |
149 | 153 |
150 // Used to DCHECK that some methods are called on the capture audio thread. | 154 // Used to DCHECK that some methods are called on the capture audio thread. |
151 base::ThreadChecker capture_thread_checker_; | 155 base::ThreadChecker capture_thread_checker_; |
152 | 156 |
153 // Used to DCHECK that PushRenderData() is called on the render audio thread. | 157 // Used to DCHECK that PushRenderData() is called on the render audio thread. |
154 base::ThreadChecker render_thread_checker_; | 158 base::ThreadChecker render_thread_checker_; |
155 | 159 |
156 // Flag to enable the stereo channels mirroring. | 160 // Flag to enable the stereo channels mirroring. |
157 bool audio_mirroring_; | 161 bool audio_mirroring_; |
158 | 162 |
159 // Used by the typing detection. | 163 // Used by the typing detection. |
160 scoped_ptr<webrtc::TypingDetection> typing_detector_; | 164 scoped_ptr<webrtc::TypingDetection> typing_detector_; |
161 | 165 |
162 // Result from the typing detection. | 166 // Result from the typing detection. |
163 bool typing_detected_; | 167 bool typing_detected_; |
164 }; | 168 }; |
165 | 169 |
166 } // namespace content | 170 } // namespace content |
167 | 171 |
168 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 172 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
OLD | NEW |