| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/renderer/media/aec_dump_message_filter.h" |
| 19 #include "content/renderer/media/webrtc_audio_capturer.h" | 20 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 20 #include "content/renderer/media/webrtc_audio_device_not_impl.h" | 21 #include "content/renderer/media/webrtc_audio_device_not_impl.h" |
| 21 #include "ipc/ipc_platform_file.h" | 22 #include "ipc/ipc_platform_file.h" |
| 22 #include "media/base/audio_capturer_source.h" | 23 #include "media/base/audio_capturer_source.h" |
| 23 #include "media/base/audio_renderer_sink.h" | 24 #include "media/base/audio_renderer_sink.h" |
| 24 | 25 |
| 25 // A WebRtcAudioDeviceImpl instance implements the abstract interface | 26 // A WebRtcAudioDeviceImpl instance implements the abstract interface |
| 26 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: | 27 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: |
| 27 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). | 28 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). |
| 28 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the | 29 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 virtual ~WebRtcPlayoutDataSource() {} | 265 virtual ~WebRtcPlayoutDataSource() {} |
| 265 }; | 266 }; |
| 266 | 267 |
| 267 // Note that this class inherits from webrtc::AudioDeviceModule but due to | 268 // 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 | 269 // the high number of non-implemented methods, we move the cruft over to the |
| 269 // WebRtcAudioDeviceNotImpl. | 270 // WebRtcAudioDeviceNotImpl. |
| 270 class CONTENT_EXPORT WebRtcAudioDeviceImpl | 271 class CONTENT_EXPORT WebRtcAudioDeviceImpl |
| 271 : NON_EXPORTED_BASE(public PeerConnectionAudioSink), | 272 : NON_EXPORTED_BASE(public PeerConnectionAudioSink), |
| 272 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl), | 273 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl), |
| 273 NON_EXPORTED_BASE(public WebRtcAudioRendererSource), | 274 NON_EXPORTED_BASE(public WebRtcAudioRendererSource), |
| 274 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) { | 275 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource), |
| 276 NON_EXPORTED_BASE(public AecDumpMessageFilter::AecDumpObserver) { |
| 275 public: | 277 public: |
| 276 // The maximum volume value WebRtc uses. | 278 // The maximum volume value WebRtc uses. |
| 277 static const int kMaxVolumeLevel = 255; | 279 static const int kMaxVolumeLevel = 255; |
| 278 | 280 |
| 279 // Instances of this object are created on the main render thread. | 281 // Instances of this object are created on the main render thread. |
| 280 WebRtcAudioDeviceImpl(); | 282 WebRtcAudioDeviceImpl(); |
| 281 | 283 |
| 282 // webrtc::RefCountedModule implementation. | 284 // webrtc::RefCountedModule implementation. |
| 283 // The creator must call AddRef() after construction and use Release() | 285 // The creator must call AddRef() after construction and use Release() |
| 284 // to release the reference and delete this object. | 286 // to release the reference and delete this object. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 320 |
| 319 virtual int32_t MaxMicrophoneVolume(uint32_t* max_volume) const OVERRIDE; | 321 virtual int32_t MaxMicrophoneVolume(uint32_t* max_volume) const OVERRIDE; |
| 320 virtual int32_t MinMicrophoneVolume(uint32_t* min_volume) const OVERRIDE; | 322 virtual int32_t MinMicrophoneVolume(uint32_t* min_volume) const OVERRIDE; |
| 321 virtual int32_t StereoPlayoutIsAvailable(bool* available) const OVERRIDE; | 323 virtual int32_t StereoPlayoutIsAvailable(bool* available) const OVERRIDE; |
| 322 virtual int32_t StereoRecordingIsAvailable(bool* available) const OVERRIDE; | 324 virtual int32_t StereoRecordingIsAvailable(bool* available) const OVERRIDE; |
| 323 virtual int32_t PlayoutDelay(uint16_t* delay_ms) const OVERRIDE; | 325 virtual int32_t PlayoutDelay(uint16_t* delay_ms) const OVERRIDE; |
| 324 virtual int32_t RecordingDelay(uint16_t* delay_ms) const OVERRIDE; | 326 virtual int32_t RecordingDelay(uint16_t* delay_ms) const OVERRIDE; |
| 325 virtual int32_t RecordingSampleRate(uint32_t* sample_rate) const OVERRIDE; | 327 virtual int32_t RecordingSampleRate(uint32_t* sample_rate) const OVERRIDE; |
| 326 virtual int32_t PlayoutSampleRate(uint32_t* sample_rate) const OVERRIDE; | 328 virtual int32_t PlayoutSampleRate(uint32_t* sample_rate) const OVERRIDE; |
| 327 | 329 |
| 330 // AecDumpMessageFilter::AecDumpObserver implementation. |
| 331 virtual void OnAecDumpFile( |
| 332 int id, |
| 333 const IPC::PlatformFileForTransit& file_handle) OVERRIDE; |
| 334 virtual void OnDisableAecDump() OVERRIDE; |
| 335 virtual void OnIpcClosed() OVERRIDE; |
| 336 |
| 328 // Sets the |renderer_|, returns false if |renderer_| already exists. | 337 // Sets the |renderer_|, returns false if |renderer_| already exists. |
| 329 // Called on the main renderer thread. | 338 // Called on the main renderer thread. |
| 330 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); | 339 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); |
| 331 | 340 |
| 332 // Adds/Removes the capturer to the ADM. | 341 // Adds/Removes the capturer to the ADM. |
| 333 // TODO(xians): Remove these two methods once the ADM does not need to pass | 342 // TODO(xians): Remove these two methods once the ADM does not need to pass |
| 334 // hardware information up to WebRtc. | 343 // hardware information up to WebRtc. |
| 335 void AddAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); | 344 void AddAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); |
| 336 void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); | 345 void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); |
| 337 | 346 |
| 338 // Gets the default capturer, which is the last capturer in |capturers_|. | 347 // Gets the default capturer, which is the last capturer in |capturers_|. |
| 339 // The method can be called by both Libjingle thread and main render thread. | 348 // The method can be called by both Libjingle thread and main render thread. |
| 340 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const; | 349 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const; |
| 341 | 350 |
| 342 // Gets paired device information of the capture device for the audio | 351 // Gets paired device information of the capture device for the audio |
| 343 // renderer. This is used to pass on a session id, sample rate and buffer | 352 // renderer. This is used to pass on a session id, sample rate and buffer |
| 344 // size to a webrtc audio renderer (either local or remote), so that audio | 353 // size to a webrtc audio renderer (either local or remote), so that audio |
| 345 // will be rendered to a matching output device. | 354 // will be rendered to a matching output device. |
| 346 // Returns true if the capture device has a paired output device, otherwise | 355 // Returns true if the capture device has a paired output device, otherwise |
| 347 // false. Note that if there are more than one open capture device the | 356 // false. Note that if there are more than one open capture device the |
| 348 // function will not be able to pick an appropriate device and return false. | 357 // function will not be able to pick an appropriate device and return false. |
| 349 bool GetAuthorizedDeviceInfoForAudioRenderer( | 358 bool GetAuthorizedDeviceInfoForAudioRenderer( |
| 350 int* session_id, int* output_sample_rate, int* output_buffer_size); | 359 int* session_id, int* output_sample_rate, int* output_buffer_size); |
| 351 | 360 |
| 352 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { | 361 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { |
| 353 return renderer_; | 362 return renderer_; |
| 354 } | 363 } |
| 355 | 364 |
| 356 // Enables the Aec dump. If the default capturer exists, it will call | |
| 357 // StartAecDump() on the capturer and pass the ownership of the file to | |
| 358 // WebRtc. Otherwise it will hold the file until a capturer is added. | |
| 359 void EnableAecDump(base::File aec_dump_file); | |
| 360 | |
| 361 // Disables the Aec dump. When this method is called, the ongoing Aec dump | |
| 362 // on WebRtc will be stopped. | |
| 363 void DisableAecDump(); | |
| 364 | |
| 365 private: | 365 private: |
| 366 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; | 366 typedef std::map<int, scoped_refptr<WebRtcAudioCapturer> > CapturerMap; |
| 367 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; | 367 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; |
| 368 class RenderBuffer; | 368 class RenderBuffer; |
| 369 | 369 |
| 370 // Make destructor private to ensure that we can only be deleted by Release(). | 370 // Make destructor private to ensure that we can only be deleted by Release(). |
| 371 virtual ~WebRtcAudioDeviceImpl(); | 371 virtual ~WebRtcAudioDeviceImpl(); |
| 372 | 372 |
| 373 // PeerConnectionAudioSink implementation. | 373 // PeerConnectionAudioSink implementation. |
| 374 | 374 |
| 375 // Called on the AudioInputDevice worker thread. | 375 // Called on the AudioInputDevice worker thread. |
| 376 virtual int OnData(const int16* audio_data, | 376 virtual int OnData(const int16* audio_data, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 394 int audio_delay_milliseconds, | 394 int audio_delay_milliseconds, |
| 395 base::TimeDelta* current_time) OVERRIDE; | 395 base::TimeDelta* current_time) OVERRIDE; |
| 396 | 396 |
| 397 // Called on the main render thread. | 397 // Called on the main render thread. |
| 398 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE; | 398 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE; |
| 399 | 399 |
| 400 // WebRtcPlayoutDataSource implementation. | 400 // WebRtcPlayoutDataSource implementation. |
| 401 virtual void AddPlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE; | 401 virtual void AddPlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE; |
| 402 virtual void RemovePlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE; | 402 virtual void RemovePlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE; |
| 403 | 403 |
| 404 // Helper to start the Aec dump if the default capturer exists. | 404 // Registers capturer with ID |id| as an AEC dump consumer with the browser. |
| 405 void MaybeStartAecDump(); | 405 void RegisterAecDumpForId(int id); |
| 406 |
| 407 // Disables the AEC dump on all capturers. |
| 408 void DisableAecDump(); |
| 406 | 409 |
| 407 // Used to DCHECK that we are called on the correct thread. | 410 // Used to DCHECK that we are called on the correct thread. |
| 408 base::ThreadChecker thread_checker_; | 411 base::ThreadChecker thread_checker_; |
| 409 | 412 |
| 410 int ref_count_; | 413 int ref_count_; |
| 411 | 414 |
| 412 // List of captures which provides access to the native audio input layer | 415 // Map of captures which provides access to the native audio input layer |
| 413 // in the browser process. | 416 // in the browser process. |
| 414 CapturerList capturers_; | 417 CapturerMap capturers_; |
| 415 | 418 |
| 416 // Provides access to the audio renderer in the browser process. | 419 // Provides access to the audio renderer in the browser process. |
| 417 scoped_refptr<WebRtcAudioRenderer> renderer_; | 420 scoped_refptr<WebRtcAudioRenderer> renderer_; |
| 418 | 421 |
| 419 // A list of raw pointer of WebRtcPlayoutDataSource::Sink objects which want | 422 // A list of raw pointer of WebRtcPlayoutDataSource::Sink objects which want |
| 420 // to get the playout data, the sink need to call RemovePlayoutSink() | 423 // to get the playout data, the sink need to call RemovePlayoutSink() |
| 421 // before it goes away. | 424 // before it goes away. |
| 422 PlayoutDataSinkList playout_sinks_; | 425 PlayoutDataSinkList playout_sinks_; |
| 423 | 426 |
| 424 // Weak reference to the audio callback. | 427 // Weak reference to the audio callback. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 445 bool recording_; | 448 bool recording_; |
| 446 | 449 |
| 447 // Stores latest microphone volume received in a CaptureData() callback. | 450 // Stores latest microphone volume received in a CaptureData() callback. |
| 448 // Range is [0, 255]. | 451 // Range is [0, 255]. |
| 449 uint32_t microphone_volume_; | 452 uint32_t microphone_volume_; |
| 450 | 453 |
| 451 // Buffer used for temporary storage during render callback. | 454 // Buffer used for temporary storage during render callback. |
| 452 // It is only accessed by the audio render thread. | 455 // It is only accessed by the audio render thread. |
| 453 std::vector<int16> render_buffer_; | 456 std::vector<int16> render_buffer_; |
| 454 | 457 |
| 455 // Used for start the Aec dump on the default capturer. | 458 // Communication with browser for AEC dump. |
| 456 base::File aec_dump_file_; | 459 // This is only used if audio track processing is enabled. |
| 460 // TODO(xians): Remove the above comment line when option to disable audio |
| 461 // track processing is removed. |
| 462 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_; |
| 457 | 463 |
| 458 // Flag to tell if audio processing is enabled in MediaStreamAudioProcessor. | 464 // Flag to tell if audio processing is enabled in MediaStreamAudioProcessor. |
| 459 const bool is_audio_track_processing_enabled_; | 465 const bool is_audio_track_processing_enabled_; |
| 460 | 466 |
| 461 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); | 467 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); |
| 462 }; | 468 }; |
| 463 | 469 |
| 464 } // namespace content | 470 } // namespace content |
| 465 | 471 |
| 466 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 472 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
| OLD | NEW |