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