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_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 int audio_delay_milliseconds, | 192 int audio_delay_milliseconds, |
193 base::TimeDelta* current_time) = 0; | 193 base::TimeDelta* current_time) = 0; |
194 | 194 |
195 // Callback to notify the client that the renderer is going away. | 195 // Callback to notify the client that the renderer is going away. |
196 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0; | 196 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0; |
197 | 197 |
198 protected: | 198 protected: |
199 virtual ~WebRtcAudioRendererSource() {} | 199 virtual ~WebRtcAudioRendererSource() {} |
200 }; | 200 }; |
201 | 201 |
202 class PeerConnectionAudioSink { | |
203 public: | |
204 // Callback to deliver the captured interleaved data. | |
205 // |channels| contains a vector of WebRtc VoE channels. | |
206 // |audio_data| is the pointer to the audio data. | |
207 // |sample_rate| is the sample frequency of audio data. | |
208 // |number_of_channels| is the number of channels reflecting the order of | |
209 // surround sound channels. | |
210 // |audio_delay_milliseconds| is recording delay value. | |
211 // |current_volume| is current microphone volume, in range of |0, 255]. | |
212 // |need_audio_processing| indicates if the audio needs WebRtc AEC/NS/AGC | |
213 // audio processing. | |
214 // The return value is the new microphone volume, in the range of |0, 255]. | |
215 // When the volume does not need to be updated, it returns 0. | |
216 virtual int OnData(const int16* audio_data, | |
217 int sample_rate, | |
218 int number_of_channels, | |
219 int number_of_frames, | |
220 const std::vector<int>& channels, | |
221 int audio_delay_milliseconds, | |
222 int current_volume, | |
223 bool need_audio_processing, | |
224 bool key_pressed) = 0; | |
225 | |
226 // Set the format for the capture audio parameters. | |
227 // This is called when the capture format has changed, and it must be called | |
228 // on the same thread as calling CaptureData(). | |
229 virtual void OnSetFormat(const media::AudioParameters& params) = 0; | |
230 | |
231 protected: | |
232 virtual ~PeerConnectionAudioSink() {} | |
233 }; | |
234 | |
235 // TODO(xians): Merge this interface with WebRtcAudioRendererSource. | 202 // TODO(xians): Merge this interface with WebRtcAudioRendererSource. |
236 // The reason why we could not do it today is that WebRtcAudioRendererSource | 203 // The reason why we could not do it today is that WebRtcAudioRendererSource |
237 // gets the data by pulling, while the data is pushed into | 204 // gets the data by pulling, while the data is pushed into |
238 // WebRtcPlayoutDataSource::Sink. | 205 // WebRtcPlayoutDataSource::Sink. |
239 class WebRtcPlayoutDataSource { | 206 class WebRtcPlayoutDataSource { |
240 public: | 207 public: |
241 class Sink { | 208 class Sink { |
242 public: | 209 public: |
243 // Callback to get the playout data. | 210 // Callback to get the playout data. |
244 // Called on the render audio thread. | 211 // Called on the render audio thread. |
(...skipping 16 matching lines...) Expand all Loading... |
261 virtual void RemovePlayoutSink(Sink* sink) = 0; | 228 virtual void RemovePlayoutSink(Sink* sink) = 0; |
262 | 229 |
263 protected: | 230 protected: |
264 virtual ~WebRtcPlayoutDataSource() {} | 231 virtual ~WebRtcPlayoutDataSource() {} |
265 }; | 232 }; |
266 | 233 |
267 // Note that this class inherits from webrtc::AudioDeviceModule but due to | 234 // Note that this class inherits from webrtc::AudioDeviceModule but due to |
268 // the high number of non-implemented methods, we move the cruft over to the | 235 // the high number of non-implemented methods, we move the cruft over to the |
269 // WebRtcAudioDeviceNotImpl. | 236 // WebRtcAudioDeviceNotImpl. |
270 class CONTENT_EXPORT WebRtcAudioDeviceImpl | 237 class CONTENT_EXPORT WebRtcAudioDeviceImpl |
271 : NON_EXPORTED_BASE(public PeerConnectionAudioSink), | 238 : NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl), |
272 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl), | |
273 NON_EXPORTED_BASE(public WebRtcAudioRendererSource), | 239 NON_EXPORTED_BASE(public WebRtcAudioRendererSource), |
274 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) { | 240 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) { |
275 public: | 241 public: |
276 // The maximum volume value WebRtc uses. | 242 // The maximum volume value WebRtc uses. |
277 static const int kMaxVolumeLevel = 255; | 243 static const int kMaxVolumeLevel = 255; |
278 | 244 |
279 // Instances of this object are created on the main render thread. | 245 // Instances of this object are created on the main render thread. |
280 WebRtcAudioDeviceImpl(); | 246 WebRtcAudioDeviceImpl(); |
281 | 247 |
282 // webrtc::RefCountedModule implementation. | 248 // webrtc::RefCountedModule implementation. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 320 } |
355 | 321 |
356 private: | 322 private: |
357 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; | 323 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; |
358 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; | 324 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; |
359 class RenderBuffer; | 325 class RenderBuffer; |
360 | 326 |
361 // Make destructor private to ensure that we can only be deleted by Release(). | 327 // Make destructor private to ensure that we can only be deleted by Release(). |
362 ~WebRtcAudioDeviceImpl() override; | 328 ~WebRtcAudioDeviceImpl() override; |
363 | 329 |
364 // PeerConnectionAudioSink implementation. | |
365 | |
366 // Called on the AudioInputDevice worker thread. | |
367 int OnData(const int16* audio_data, | |
368 int sample_rate, | |
369 int number_of_channels, | |
370 int number_of_frames, | |
371 const std::vector<int>& channels, | |
372 int audio_delay_milliseconds, | |
373 int current_volume, | |
374 bool need_audio_processing, | |
375 bool key_pressed) override; | |
376 | |
377 // Called on the AudioInputDevice worker thread. | |
378 void OnSetFormat(const media::AudioParameters& params) override; | |
379 | |
380 // WebRtcAudioRendererSource implementation. | 330 // WebRtcAudioRendererSource implementation. |
381 | 331 |
382 // Called on the AudioOutputDevice worker thread. | 332 // Called on the AudioOutputDevice worker thread. |
383 void RenderData(media::AudioBus* audio_bus, | 333 void RenderData(media::AudioBus* audio_bus, |
384 int sample_rate, | 334 int sample_rate, |
385 int audio_delay_milliseconds, | 335 int audio_delay_milliseconds, |
386 base::TimeDelta* current_time) override; | 336 base::TimeDelta* current_time) override; |
387 | 337 |
388 // Called on the main render thread. | 338 // Called on the main render thread. |
389 void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) override; | 339 void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) override; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 bool recording_; | 383 bool recording_; |
434 | 384 |
435 // Stores latest microphone volume received in a CaptureData() callback. | 385 // Stores latest microphone volume received in a CaptureData() callback. |
436 // Range is [0, 255]. | 386 // Range is [0, 255]. |
437 uint32_t microphone_volume_; | 387 uint32_t microphone_volume_; |
438 | 388 |
439 // Buffer used for temporary storage during render callback. | 389 // Buffer used for temporary storage during render callback. |
440 // It is only accessed by the audio render thread. | 390 // It is only accessed by the audio render thread. |
441 std::vector<int16> render_buffer_; | 391 std::vector<int16> render_buffer_; |
442 | 392 |
443 // Flag to tell if audio processing is enabled in MediaStreamAudioProcessor. | |
444 const bool is_audio_track_processing_enabled_; | |
445 | |
446 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); | 393 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); |
447 }; | 394 }; |
448 | 395 |
449 } // namespace content | 396 } // namespace content |
450 | 397 |
451 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 398 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
OLD | NEW |