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 <memory> |
| 9 |
8 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
9 #include "base/files/file.h" | 11 #include "base/files/file.h" |
10 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/optional.h" | 15 #include "base/optional.h" |
14 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
15 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
18 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
19 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
20 #include "content/renderer/media/aec_dump_message_filter.h" | 22 #include "content/renderer/media/aec_dump_message_filter.h" |
21 #include "content/renderer/media/audio_repetition_detector.h" | 23 #include "content/renderer/media/audio_repetition_detector.h" |
| 24 #include "content/renderer/media/media_stream_audio_processor_options.h" |
22 #include "content/renderer/media/webrtc_audio_device_impl.h" | 25 #include "content/renderer/media/webrtc_audio_device_impl.h" |
23 #include "media/base/audio_converter.h" | 26 #include "media/base/audio_converter.h" |
24 #include "third_party/webrtc/api/mediastreaminterface.h" | 27 #include "third_party/webrtc/api/mediastreaminterface.h" |
25 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" | 28 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
26 | 29 |
27 // The audio repetition detector is by default only used on non-official | 30 // The audio repetition detector is by default only used on non-official |
28 // ChromeOS builds for debugging purposes. http://crbug.com/658719. | 31 // ChromeOS builds for debugging purposes. http://crbug.com/658719. |
29 #if !defined(ENABLE_AUDIO_REPETITION_DETECTOR) | 32 #if !defined(ENABLE_AUDIO_REPETITION_DETECTOR) |
30 #if defined(OS_CHROMEOS) && !defined(OFFICIAL_BUILD) | 33 #if defined(OS_CHROMEOS) && !defined(OFFICIAL_BUILD) |
31 #define ENABLE_AUDIO_REPETITION_DETECTOR 1 | 34 #define ENABLE_AUDIO_REPETITION_DETECTOR 1 |
32 #else | 35 #else |
33 #define ENABLE_AUDIO_REPETITION_DETECTOR 0 | 36 #define ENABLE_AUDIO_REPETITION_DETECTOR 0 |
34 #endif | 37 #endif |
35 #endif | 38 #endif |
36 | 39 |
37 namespace blink { | |
38 class WebMediaConstraints; | |
39 } | |
40 | |
41 namespace media { | 40 namespace media { |
42 class AudioBus; | 41 class AudioBus; |
43 class AudioParameters; | 42 class AudioParameters; |
44 } // namespace media | 43 } // namespace media |
45 | 44 |
46 namespace webrtc { | 45 namespace webrtc { |
47 class TypingDetection; | 46 class TypingDetection; |
48 } | 47 } |
49 | 48 |
50 namespace content { | 49 namespace content { |
(...skipping 12 matching lines...) Expand all Loading... |
63 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource::Sink), | 62 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource::Sink), |
64 NON_EXPORTED_BASE(public AudioProcessorInterface), | 63 NON_EXPORTED_BASE(public AudioProcessorInterface), |
65 NON_EXPORTED_BASE(public AecDumpMessageFilter::AecDumpDelegate) { | 64 NON_EXPORTED_BASE(public AecDumpMessageFilter::AecDumpDelegate) { |
66 public: | 65 public: |
67 // |playout_data_source| is used to register this class as a sink to the | 66 // |playout_data_source| is used to register this class as a sink to the |
68 // WebRtc playout data for processing AEC. If clients do not enable AEC, | 67 // WebRtc playout data for processing AEC. If clients do not enable AEC, |
69 // |playout_data_source| won't be used. | 68 // |playout_data_source| won't be used. |
70 // | 69 // |
71 // Threading note: The constructor assumes it is being run on the main render | 70 // Threading note: The constructor assumes it is being run on the main render |
72 // thread. | 71 // thread. |
73 MediaStreamAudioProcessor( | 72 MediaStreamAudioProcessor(const AudioProcessingProperties& properties, |
74 const blink::WebMediaConstraints& constraints, | 73 WebRtcPlayoutDataSource* playout_data_source); |
75 const MediaStreamDevice::AudioDeviceParameters& input_params, | |
76 WebRtcPlayoutDataSource* playout_data_source); | |
77 | 74 |
78 // Called when the format of the capture data has changed. | 75 // Called when the format of the capture data has changed. |
79 // Called on the main render thread. The caller is responsible for stopping | 76 // Called on the main render thread. The caller is responsible for stopping |
80 // the capture thread before calling this method. | 77 // the capture thread before calling this method. |
81 // After this method, the capture thread will be changed to a new capture | 78 // After this method, the capture thread will be changed to a new capture |
82 // thread. | 79 // thread. |
83 void OnCaptureFormatChanged(const media::AudioParameters& source_params); | 80 void OnCaptureFormatChanged(const media::AudioParameters& source_params); |
84 | 81 |
85 // Pushes capture data in |audio_source| to the internal FIFO. Each call to | 82 // Pushes capture data in |audio_source| to the internal FIFO. Each call to |
86 // this method should be followed by calls to ProcessAndConsumeData() while | 83 // this method should be followed by calls to ProcessAndConsumeData() while |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bool has_audio_processing() const { return audio_processing_ != NULL; } | 116 bool has_audio_processing() const { return audio_processing_ != NULL; } |
120 | 117 |
121 // AecDumpMessageFilter::AecDumpDelegate implementation. | 118 // AecDumpMessageFilter::AecDumpDelegate implementation. |
122 // Called on the main render thread. | 119 // Called on the main render thread. |
123 void OnAecDumpFile(const IPC::PlatformFileForTransit& file_handle) override; | 120 void OnAecDumpFile(const IPC::PlatformFileForTransit& file_handle) override; |
124 void OnDisableAecDump() override; | 121 void OnDisableAecDump() override; |
125 void OnAec3Enable(bool enable) override; | 122 void OnAec3Enable(bool enable) override; |
126 void OnIpcClosing() override; | 123 void OnIpcClosing() override; |
127 | 124 |
128 // Returns true if MediaStreamAudioProcessor would modify the audio signal, | 125 // Returns true if MediaStreamAudioProcessor would modify the audio signal, |
129 // based on the |constraints| and |effects_flags| parsed from a user media | 126 // based on |properties|. If the audio signal would not be modified, there is |
130 // request. If the audio signal would not be modified, there is no need to | 127 // no need to instantiate a MediaStreamAudioProcessor and feed audio through |
131 // instantiate a MediaStreamAudioProcessor and feed audio through it. Doing so | 128 // it. Doing so would waste a non-trivial amount of memory and CPU resources. |
132 // would waste a non-trivial amount of memory and CPU resources. | 129 static bool WouldModifyAudio(const AudioProcessingProperties& properties); |
133 // | |
134 // See media::AudioParameters::PlatformEffectsMask for interpretation of | |
135 // |effects_flags|. | |
136 static bool WouldModifyAudio(const blink::WebMediaConstraints& constraints, | |
137 int effects_flags); | |
138 | 130 |
139 protected: | 131 protected: |
140 ~MediaStreamAudioProcessor() override; | 132 ~MediaStreamAudioProcessor() override; |
141 | 133 |
142 private: | 134 private: |
143 friend class MediaStreamAudioProcessorTest; | 135 friend class MediaStreamAudioProcessorTest; |
144 | 136 |
145 FRIEND_TEST_ALL_PREFIXES(MediaStreamAudioProcessorTest, | 137 FRIEND_TEST_ALL_PREFIXES(MediaStreamAudioProcessorTest, |
146 GetAecDumpMessageFilter); | 138 GetAecDumpMessageFilter); |
147 | 139 |
148 // WebRtcPlayoutDataSource::Sink implementation. | 140 // WebRtcPlayoutDataSource::Sink implementation. |
149 void OnPlayoutData(media::AudioBus* audio_bus, | 141 void OnPlayoutData(media::AudioBus* audio_bus, |
150 int sample_rate, | 142 int sample_rate, |
151 int audio_delay_milliseconds) override; | 143 int audio_delay_milliseconds) override; |
152 void OnPlayoutDataSourceChanged() override; | 144 void OnPlayoutDataSourceChanged() override; |
153 void OnRenderThreadChanged() override; | 145 void OnRenderThreadChanged() override; |
154 | 146 |
155 // webrtc::AudioProcessorInterface implementation. | 147 // webrtc::AudioProcessorInterface implementation. |
156 // This method is called on the libjingle thread. | 148 // This method is called on the libjingle thread. |
157 void GetStats(AudioProcessorStats* stats) override; | 149 void GetStats(AudioProcessorStats* stats) override; |
158 | 150 |
159 // Helper to initialize the WebRtc AudioProcessing. | 151 // Helper to initialize the WebRtc AudioProcessing. |
160 void InitializeAudioProcessingModule( | 152 void InitializeAudioProcessingModule( |
161 const blink::WebMediaConstraints& constraints, | 153 const AudioProcessingProperties& properties); |
162 const MediaStreamDevice::AudioDeviceParameters& input_params); | |
163 | 154 |
164 // Helper to initialize the capture converter. | 155 // Helper to initialize the capture converter. |
165 void InitializeCaptureFifo(const media::AudioParameters& input_format); | 156 void InitializeCaptureFifo(const media::AudioParameters& input_format); |
166 | 157 |
167 // Helper to initialize the render converter. | 158 // Helper to initialize the render converter. |
168 void InitializeRenderFifoIfNeeded(int sample_rate, | 159 void InitializeRenderFifoIfNeeded(int sample_rate, |
169 int number_of_channels, | 160 int number_of_channels, |
170 int frames_per_buffer); | 161 int frames_per_buffer); |
171 | 162 |
172 // Called by ProcessAndConsumeData(). | 163 // Called by ProcessAndConsumeData(). |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // Object for logging UMA stats for echo information when the AEC is enabled. | 237 // Object for logging UMA stats for echo information when the AEC is enabled. |
247 // Accessed on the main render thread. | 238 // Accessed on the main render thread. |
248 std::unique_ptr<EchoInformation> echo_information_; | 239 std::unique_ptr<EchoInformation> echo_information_; |
249 | 240 |
250 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioProcessor); | 241 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioProcessor); |
251 }; | 242 }; |
252 | 243 |
253 } // namespace content | 244 } // namespace content |
254 | 245 |
255 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 246 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
OLD | NEW |