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 } | 30 } |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
33 class RTCMediaConstraints; | 34 class RTCMediaConstraints; |
34 | 35 |
35 // This class owns an object of webrtc::AudioProcessing which contains signal | 36 // This class owns an object of webrtc::AudioProcessing which contains signal |
36 // processing components like AGC, AEC and NS. It enables the components based | 37 // processing components like AGC, AEC and NS. It enables the components based |
37 // on the getUserMedia constraints, processes the data and outputs it in a unit | 38 // on the getUserMedia constraints, processes the data and outputs it in a unit |
38 // of 10 ms data chunk. | 39 // of 10 ms data chunk. |
39 class CONTENT_EXPORT MediaStreamAudioProcessor : | 40 class CONTENT_EXPORT MediaStreamAudioProcessor : |
40 public base::RefCountedThreadSafe<MediaStreamAudioProcessor> { | 41 public base::RefCountedThreadSafe<MediaStreamAudioProcessor>, |
42 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource::Sink) { | |
41 public: | 43 public: |
44 // |audio_device| is used to register this class as observer to the WebRtc | |
45 // render data for processing AEC. If clients do not enable AEC, | |
46 // |audio_device| won't be used. | |
42 MediaStreamAudioProcessor(const media::AudioParameters& source_params, | 47 MediaStreamAudioProcessor(const media::AudioParameters& source_params, |
43 const blink::WebMediaConstraints& constraints, | 48 const blink::WebMediaConstraints& constraints, |
44 int effects); | 49 int effects, |
50 WebRtcPlayoutDataSource* playout_data_source); | |
45 | 51 |
46 // Pushes capture data in |audio_source| to the internal FIFO. | 52 // Pushes capture data in |audio_source| to the internal FIFO. |
47 // Called on the capture audio thread. | 53 // Called on the capture audio thread. |
48 void PushCaptureData(media::AudioBus* audio_source); | 54 void PushCaptureData(media::AudioBus* audio_source); |
49 | 55 |
50 // Push the render audio to webrtc::AudioProcessing for analysis. This is | |
51 // needed iff echo processing is enabled. | |
52 // |render_audio| is the pointer to the render audio data, its format | |
53 // is specified by |sample_rate|, |number_of_channels| and |number_of_frames|. | |
54 // Called on the render audio thread. | |
55 void PushRenderData(const int16* render_audio, | |
56 int sample_rate, | |
57 int number_of_channels, | |
58 int number_of_frames, | |
59 base::TimeDelta render_delay); | |
60 | |
61 // Processes a block of 10 ms data from the internal FIFO and outputs it via | 56 // Processes a block of 10 ms data from the internal FIFO and outputs it via |
62 // |out|. |out| is the address of the pointer that will be pointed to | 57 // |out|. |out| is the address of the pointer that will be pointed to |
63 // the post-processed data if the method is returning a true. The lifetime | 58 // the post-processed data if the method is returning a true. The lifetime |
64 // of the data represeted by |out| is guaranteed to outlive the method call. | 59 // of the data represeted by |out| is guaranteed to outlive the method call. |
65 // That also says *|out| won't change until this method is called again. | 60 // That also says *|out| won't change until this method is called again. |
66 // |new_volume| receives the new microphone volume from the AGC. | 61 // |new_volume| receives the new microphone volume from the AGC. |
67 // The new microphoen volume range is [0, 255], and the value will be 0 if | 62 // The new microphoen volume range is [0, 255], and the value will be 0 if |
68 // the microphone volume should not be adjusted. | 63 // the microphone volume should not be adjusted. |
69 // Returns true if the internal FIFO has at least 10 ms data for processing, | 64 // Returns true if the internal FIFO has at least 10 ms data for processing, |
70 // otherwise false. | 65 // otherwise false. |
(...skipping 18 matching lines...) Expand all Loading... | |
89 | 84 |
90 protected: | 85 protected: |
91 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; | 86 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; |
92 virtual ~MediaStreamAudioProcessor(); | 87 virtual ~MediaStreamAudioProcessor(); |
93 | 88 |
94 private: | 89 private: |
95 friend class MediaStreamAudioProcessorTest; | 90 friend class MediaStreamAudioProcessorTest; |
96 | 91 |
97 class MediaStreamAudioConverter; | 92 class MediaStreamAudioConverter; |
98 | 93 |
94 // WebRtcPlayoutDataSource::Sink implementation. | |
95 virtual void OnPlayoutData(media::AudioBus* audio_bus, | |
96 int sample_rate, | |
97 int audio_delay_milliseconds) OVERRIDE; | |
98 | |
99 // Helper to initialize the WebRtc AudioProcessing. | 99 // Helper to initialize the WebRtc AudioProcessing. |
100 void InitializeAudioProcessingModule( | 100 void InitializeAudioProcessingModule( |
101 const blink::WebMediaConstraints& constraints, int effects); | 101 const blink::WebMediaConstraints& constraints, int effects); |
102 | 102 |
103 // Helper to initialize the capture converter. | 103 // Helper to initialize the capture converter. |
104 void InitializeCaptureConverter(const media::AudioParameters& source_params); | 104 void InitializeCaptureConverter(const media::AudioParameters& source_params); |
105 | 105 |
106 // Helper to initialize the render converter. | 106 // Helper to initialize the render converter. |
107 void InitializeRenderConverterIfNeeded(int sample_rate, | 107 void InitializeRenderConverterIfNeeded(int sample_rate, |
108 int number_of_channels, | 108 int number_of_channels, |
(...skipping 27 matching lines...) Expand all Loading... | |
136 // Converter used for the down-mixing and resampling of the render data when | 136 // Converter used for the down-mixing and resampling of the render data when |
137 // the AEC is enabled. | 137 // the AEC is enabled. |
138 scoped_ptr<MediaStreamAudioConverter> render_converter_; | 138 scoped_ptr<MediaStreamAudioConverter> render_converter_; |
139 | 139 |
140 // AudioFrame used to hold the output of |render_converter_|. | 140 // AudioFrame used to hold the output of |render_converter_|. |
141 webrtc::AudioFrame render_frame_; | 141 webrtc::AudioFrame render_frame_; |
142 | 142 |
143 // Data bus to help converting interleaved data to an AudioBus. | 143 // Data bus to help converting interleaved data to an AudioBus. |
144 scoped_ptr<media::AudioBus> render_data_bus_; | 144 scoped_ptr<media::AudioBus> render_data_bus_; |
145 | 145 |
146 // Used to DCHECK that some methods are called on the main render thread. | 146 // Raw pointer to the WebRtcPlayoutDataSource, which is valid for the |
147 base::ThreadChecker main_thread_checker_; | 147 // lifetime of RenderThread. |
tommi (sloooow) - chröme
2014/02/06 16:47:01
why are we removing this?
no longer working on chromium
2014/02/06 17:20:14
Please see the comment in the cc file.
| |
148 WebRtcPlayoutDataSource* const playout_data_source_; | |
148 | 149 |
149 // Used to DCHECK that some methods are called on the capture audio thread. | 150 // Used to DCHECK that some methods are called on the capture audio thread. |
150 base::ThreadChecker capture_thread_checker_; | 151 base::ThreadChecker capture_thread_checker_; |
151 | 152 |
152 // Used to DCHECK that PushRenderData() is called on the render audio thread. | 153 // Used to DCHECK that PushRenderData() is called on the render audio thread. |
153 base::ThreadChecker render_thread_checker_; | 154 base::ThreadChecker render_thread_checker_; |
154 | 155 |
155 // Flag to enable the stereo channels mirroring. | 156 // Flag to enable the stereo channels mirroring. |
156 bool audio_mirroring_; | 157 bool audio_mirroring_; |
157 }; | 158 }; |
158 | 159 |
159 } // namespace content | 160 } // namespace content |
160 | 161 |
161 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 162 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
OLD | NEW |