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