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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file.h" | 16 #include "base/files/file.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 22 #include "content/renderer/media/webrtc_audio_capturer.h" |
22 #include "content/renderer/media/webrtc_audio_device_not_impl.h" | 23 #include "content/renderer/media/webrtc_audio_device_not_impl.h" |
23 #include "ipc/ipc_platform_file.h" | 24 #include "ipc/ipc_platform_file.h" |
| 25 #include "media/base/audio_capturer_source.h" |
| 26 #include "media/base/audio_renderer_sink.h" |
24 | 27 |
25 // A WebRtcAudioDeviceImpl instance implements the abstract interface | 28 // A WebRtcAudioDeviceImpl instance implements the abstract interface |
26 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: | 29 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: |
27 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). | 30 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). |
28 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the | 31 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the |
29 // session id that tells which device to use. The user can then call | 32 // session id that tells which device to use. The user can then call |
30 // WebRtcAudioDeviceImpl::StartPlayout() and | 33 // WebRtcAudioDeviceImpl::StartPlayout() and |
31 // WebRtcAudioDeviceImpl::StartRecording() from the render process to initiate | 34 // WebRtcAudioDeviceImpl::StartRecording() from the render process to initiate |
32 // and start audio rendering and capturing in the browser process. IPC is | 35 // and start audio rendering and capturing in the browser process. IPC is |
33 // utilized to set up the media streams. | 36 // utilized to set up the media streams. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // order to avoid potential deadlocks. | 175 // order to avoid potential deadlocks. |
173 // - The webrtc::AudioDeviceModule is reference counted. | 176 // - The webrtc::AudioDeviceModule is reference counted. |
174 // - AGC is only supported in combination with the WASAPI-based audio layer | 177 // - AGC is only supported in combination with the WASAPI-based audio layer |
175 // on Windows, i.e., it is not supported on Windows XP. | 178 // on Windows, i.e., it is not supported on Windows XP. |
176 // - All volume levels required for the AGC scheme are transfered in a | 179 // - All volume levels required for the AGC scheme are transfered in a |
177 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints | 180 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints |
178 // (WebRTC client a media layer). This approach ensures that we can avoid | 181 // (WebRTC client a media layer). This approach ensures that we can avoid |
179 // transferring maximum levels between the renderer and the browser. | 182 // transferring maximum levels between the renderer and the browser. |
180 // | 183 // |
181 | 184 |
182 namespace media { | |
183 class AudioBus; | |
184 } | |
185 | |
186 namespace content { | 185 namespace content { |
187 | 186 |
188 class ProcessedLocalAudioSource; | 187 class WebRtcAudioCapturer; |
189 class WebRtcAudioRenderer; | 188 class WebRtcAudioRenderer; |
190 | 189 |
191 // TODO(xians): Move the following two interfaces to webrtc so that | 190 // TODO(xians): Move the following two interfaces to webrtc so that |
192 // libjingle can own references to the renderer and capturer. | 191 // libjingle can own references to the renderer and capturer. |
193 class WebRtcAudioRendererSource { | 192 class WebRtcAudioRendererSource { |
194 public: | 193 public: |
195 // Callback to get the rendered data. | 194 // Callback to get the rendered data. |
196 virtual void RenderData(media::AudioBus* audio_bus, | 195 virtual void RenderData(media::AudioBus* audio_bus, |
197 int sample_rate, | 196 int sample_rate, |
198 int audio_delay_milliseconds, | 197 int audio_delay_milliseconds, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 304 |
306 public: | 305 public: |
307 // Sets the |renderer_|, returns false if |renderer_| already exists. | 306 // Sets the |renderer_|, returns false if |renderer_| already exists. |
308 // Called on the main renderer thread. | 307 // Called on the main renderer thread. |
309 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); | 308 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); |
310 | 309 |
311 // Adds/Removes the |capturer| to the ADM. Does NOT take ownership. | 310 // Adds/Removes the |capturer| to the ADM. Does NOT take ownership. |
312 // Capturers must remain valid until RemoveAudioCapturer() is called. | 311 // Capturers must remain valid until RemoveAudioCapturer() is called. |
313 // TODO(xians): Remove these two methods once the ADM does not need to pass | 312 // TODO(xians): Remove these two methods once the ADM does not need to pass |
314 // hardware information up to WebRtc. | 313 // hardware information up to WebRtc. |
315 void AddAudioCapturer(ProcessedLocalAudioSource* capturer); | 314 void AddAudioCapturer(WebRtcAudioCapturer* capturer); |
316 void RemoveAudioCapturer(ProcessedLocalAudioSource* capturer); | 315 void RemoveAudioCapturer(WebRtcAudioCapturer* capturer); |
317 | 316 |
318 // Gets paired device information of the capture device for the audio | 317 // Gets paired device information of the capture device for the audio |
319 // renderer. This is used to pass on a session id, sample rate and buffer | 318 // renderer. This is used to pass on a session id, sample rate and buffer |
320 // size to a webrtc audio renderer (either local or remote), so that audio | 319 // size to a webrtc audio renderer (either local or remote), so that audio |
321 // will be rendered to a matching output device. | 320 // will be rendered to a matching output device. |
322 // Returns true if the capture device has a paired output device, otherwise | 321 // Returns true if the capture device has a paired output device, otherwise |
323 // false. Note that if there are more than one open capture device the | 322 // false. Note that if there are more than one open capture device the |
324 // function will not be able to pick an appropriate device and return false. | 323 // function will not be able to pick an appropriate device and return false. |
325 bool GetAuthorizedDeviceInfoForAudioRenderer( | 324 bool GetAuthorizedDeviceInfoForAudioRenderer( |
326 int* session_id, int* output_sample_rate, int* output_buffer_size); | 325 int* session_id, int* output_sample_rate, int* output_buffer_size); |
327 | 326 |
328 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { | 327 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { |
329 return renderer_; | 328 return renderer_; |
330 } | 329 } |
331 | 330 |
332 private: | 331 private: |
333 typedef std::list<ProcessedLocalAudioSource*> CapturerList; | 332 typedef std::list<WebRtcAudioCapturer*> CapturerList; |
334 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; | 333 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; |
335 class RenderBuffer; | 334 class RenderBuffer; |
336 | 335 |
337 // Make destructor private to ensure that we can only be deleted by Release(). | 336 // Make destructor private to ensure that we can only be deleted by Release(). |
338 ~WebRtcAudioDeviceImpl() override; | 337 ~WebRtcAudioDeviceImpl() override; |
339 | 338 |
340 // WebRtcAudioRendererSource implementation. | 339 // WebRtcAudioRendererSource implementation. |
341 | 340 |
342 // Called on the AudioOutputDevice worker thread. | 341 // Called on the AudioOutputDevice worker thread. |
343 void RenderData(media::AudioBus* audio_bus, | 342 void RenderData(media::AudioBus* audio_bus, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // Buffer used for temporary storage during render callback. | 398 // Buffer used for temporary storage during render callback. |
400 // It is only accessed by the audio render thread. | 399 // It is only accessed by the audio render thread. |
401 std::vector<int16_t> render_buffer_; | 400 std::vector<int16_t> render_buffer_; |
402 | 401 |
403 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); | 402 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); |
404 }; | 403 }; |
405 | 404 |
406 } // namespace content | 405 } // namespace content |
407 | 406 |
408 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 407 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
OLD | NEW |