OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "content/renderer/media/audio_input_device.h" | 18 #include "media/audio/audio_input_device.h" |
19 #include "media/base/audio_renderer_sink.h" | 19 #include "media/base/audio_renderer_sink.h" |
20 #include "third_party/webrtc/modules/audio_device/main/interface/audio_device.h" | 20 #include "third_party/webrtc/modules/audio_device/main/interface/audio_device.h" |
21 | 21 |
22 // A WebRtcAudioDeviceImpl instance implements the abstract interface | 22 // A WebRtcAudioDeviceImpl instance implements the abstract interface |
23 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: | 23 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: |
24 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). | 24 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). |
25 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the | 25 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the |
26 // session id that tells which device to use. The user can either get the | 26 // session id that tells which device to use. The user can either get the |
27 // session id from the MediaStream or use a value of 1 (AudioInputDeviceManager | 27 // session id from the MediaStream or use a value of 1 (AudioInputDeviceManager |
28 // ::kFakeOpenSessionId), the later will open the default device without going | 28 // ::kFakeOpenSessionId), the later will open the default device without going |
(...skipping 27 matching lines...) Expand all Loading... |
56 // VoiceEngine::Delete(voe); | 56 // VoiceEngine::Delete(voe); |
57 // } | 57 // } |
58 // | 58 // |
59 // webrtc::VoiceEngine::Init() calls these ADM methods (in this order): | 59 // webrtc::VoiceEngine::Init() calls these ADM methods (in this order): |
60 // | 60 // |
61 // RegisterAudioCallback(this) | 61 // RegisterAudioCallback(this) |
62 // webrtc::VoiceEngine is an webrtc::AudioTransport implementation and | 62 // webrtc::VoiceEngine is an webrtc::AudioTransport implementation and |
63 // implements the RecordedDataIsAvailable() and NeedMorePlayData() callbacks. | 63 // implements the RecordedDataIsAvailable() and NeedMorePlayData() callbacks. |
64 // | 64 // |
65 // Init() | 65 // Init() |
66 // Creates and initializes the AudioDevice and AudioInputDevice objects. | 66 // Creates and initializes the AudioOutputDevice and AudioInputDevice |
| 67 // objects. |
67 // | 68 // |
68 // SetAGC(true) | 69 // SetAGC(true) |
69 // Enables the adaptive analog mode of the AGC which ensures that a | 70 // Enables the adaptive analog mode of the AGC which ensures that a |
70 // suitable microphone volume level will be set. This scheme will affect | 71 // suitable microphone volume level will be set. This scheme will affect |
71 // the actual microphone control slider. | 72 // the actual microphone control slider. |
72 // | 73 // |
73 // Media example: | 74 // Media example: |
74 // | 75 // |
75 // When the underlying audio layer wants data samples to be played out, the | 76 // When the underlying audio layer wants data samples to be played out, the |
76 // AudioDevice::RenderCallback() will be called, which in turn uses the | 77 // AudioOutputDevice::RenderCallback() will be called, which in turn uses the |
77 // registered webrtc::AudioTransport callback and gets the data to be played | 78 // registered webrtc::AudioTransport callback and gets the data to be played |
78 // out from the webrtc::VoiceEngine. | 79 // out from the webrtc::VoiceEngine. |
79 // | 80 // |
80 // The picture below illustrates the media flow on the capture side where the | 81 // The picture below illustrates the media flow on the capture side where the |
81 // AudioInputDevice client acts as link between the renderer and browser | 82 // AudioInputDevice client acts as link between the renderer and browser |
82 // process: | 83 // process: |
83 // | 84 // |
84 // .------------------. .----------------------. | 85 // .------------------. .----------------------. |
85 // (Native audio) => | AudioInputStream |-> OnData ->| AudioInputController |-. | 86 // (Native audio) => | AudioInputStream |-> OnData ->| AudioInputController |-. |
86 // .------------------. .----------------------. | | 87 // .------------------. .----------------------. | |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // - The webrtc::AudioDeviceModule is reference counted. | 197 // - The webrtc::AudioDeviceModule is reference counted. |
197 // - AGC is only supported in combination with the WASAPI-based audio layer | 198 // - AGC is only supported in combination with the WASAPI-based audio layer |
198 // on Windows, i.e., it is not supported on Windows XP. | 199 // on Windows, i.e., it is not supported on Windows XP. |
199 // - All volume levels required for the AGC scheme are transfered in a | 200 // - All volume levels required for the AGC scheme are transfered in a |
200 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints | 201 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints |
201 // (WebRTC client a media layer). This approach ensures that we can avoid | 202 // (WebRTC client a media layer). This approach ensures that we can avoid |
202 // transferring maximum levels between the renderer and the browser. | 203 // transferring maximum levels between the renderer and the browser. |
203 // | 204 // |
204 class CONTENT_EXPORT WebRtcAudioDeviceImpl | 205 class CONTENT_EXPORT WebRtcAudioDeviceImpl |
205 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), | 206 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), |
206 public media::AudioRendererSink::RenderCallback, | 207 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), |
207 public AudioInputDevice::CaptureCallback, | 208 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback), |
208 public AudioInputDevice::CaptureEventHandler { | 209 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler) { |
209 public: | 210 public: |
210 // Methods called on main render thread. | 211 // Methods called on main render thread. |
211 WebRtcAudioDeviceImpl(); | 212 WebRtcAudioDeviceImpl(); |
212 | 213 |
213 // webrtc::RefCountedModule implementation. | 214 // webrtc::RefCountedModule implementation. |
214 // The creator must call AddRef() after construction and use Release() | 215 // The creator must call AddRef() after construction and use Release() |
215 // to release the reference and delete this object. | 216 // to release the reference and delete this object. |
216 virtual int32_t AddRef() OVERRIDE; | 217 virtual int32_t AddRef() OVERRIDE; |
217 virtual int32_t Release() OVERRIDE; | 218 virtual int32_t Release() OVERRIDE; |
218 | 219 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // be executed on that thread. | 397 // be executed on that thread. |
397 void InitOnRenderThread(int32_t* error, base::WaitableEvent* event); | 398 void InitOnRenderThread(int32_t* error, base::WaitableEvent* event); |
398 | 399 |
399 int ref_count_; | 400 int ref_count_; |
400 | 401 |
401 // Gives access to the message loop of the render thread on which this | 402 // Gives access to the message loop of the render thread on which this |
402 // object is created. | 403 // object is created. |
403 scoped_refptr<base::MessageLoopProxy> render_loop_; | 404 scoped_refptr<base::MessageLoopProxy> render_loop_; |
404 | 405 |
405 // Provides access to the native audio input layer in the browser process. | 406 // Provides access to the native audio input layer in the browser process. |
406 scoped_refptr<AudioInputDevice> audio_input_device_; | 407 scoped_refptr<media::AudioInputDevice> audio_input_device_; |
407 | 408 |
408 // Provides access to the native audio output layer in the browser process. | 409 // Provides access to the native audio output layer in the browser process. |
409 scoped_refptr<media::AudioRendererSink> audio_output_device_; | 410 scoped_refptr<media::AudioRendererSink> audio_output_device_; |
410 | 411 |
411 // Weak reference to the audio callback. | 412 // Weak reference to the audio callback. |
412 // The webrtc client defines |audio_transport_callback_| by calling | 413 // The webrtc client defines |audio_transport_callback_| by calling |
413 // RegisterAudioCallback(). | 414 // RegisterAudioCallback(). |
414 webrtc::AudioTransport* audio_transport_callback_; | 415 webrtc::AudioTransport* audio_transport_callback_; |
415 | 416 |
416 // Cached values of utilized audio parameters. Platform dependent. | 417 // Cached values of utilized audio parameters. Platform dependent. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 bool agc_is_enabled_; | 450 bool agc_is_enabled_; |
450 | 451 |
451 // Used for histograms of total recording and playout times. | 452 // Used for histograms of total recording and playout times. |
452 base::Time start_capture_time_; | 453 base::Time start_capture_time_; |
453 base::Time start_render_time_; | 454 base::Time start_render_time_; |
454 | 455 |
455 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); | 456 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); |
456 }; | 457 }; |
457 | 458 |
458 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 459 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
OLD | NEW |