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 <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "content/renderer/media/webrtc_audio_capturer.h" | |
22 #include "content/renderer/media/webrtc_audio_device_not_impl.h" | 21 #include "content/renderer/media/webrtc_audio_device_not_impl.h" |
23 #include "ipc/ipc_platform_file.h" | 22 #include "ipc/ipc_platform_file.h" |
24 #include "media/base/audio_capturer_source.h" | 23 #include "media/base/audio_capturer_source.h" |
25 #include "media/base/audio_renderer_sink.h" | 24 #include "media/base/audio_renderer_sink.h" |
26 | 25 |
27 // A WebRtcAudioDeviceImpl instance implements the abstract interface | 26 // A WebRtcAudioDeviceImpl instance implements the abstract interface |
28 // 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:: |
29 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). | 28 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). |
30 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the | 29 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the |
31 // 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 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // - 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 |
177 // on Windows, i.e., it is not supported on Windows XP. | 176 // on Windows, i.e., it is not supported on Windows XP. |
178 // - 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 |
179 // 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 |
180 // (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 |
181 // transferring maximum levels between the renderer and the browser. | 180 // transferring maximum levels between the renderer and the browser. |
182 // | 181 // |
183 | 182 |
184 namespace content { | 183 namespace content { |
185 | 184 |
186 class WebRtcAudioCapturer; | 185 class ProcessedLocalAudioSource; |
187 class WebRtcAudioRenderer; | 186 class WebRtcAudioRenderer; |
188 | 187 |
189 // TODO(xians): Move the following two interfaces to webrtc so that | 188 // TODO(xians): Move the following two interfaces to webrtc so that |
190 // libjingle can own references to the renderer and capturer. | 189 // libjingle can own references to the renderer and capturer. |
191 class WebRtcAudioRendererSource { | 190 class WebRtcAudioRendererSource { |
192 public: | 191 public: |
193 // Callback to get the rendered data. | 192 // Callback to get the rendered data. |
194 virtual void RenderData(media::AudioBus* audio_bus, | 193 virtual void RenderData(media::AudioBus* audio_bus, |
195 int sample_rate, | 194 int sample_rate, |
196 int audio_delay_milliseconds, | 195 int audio_delay_milliseconds, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 int32_t PlayoutDelay(uint16_t* delay_ms) const override; | 298 int32_t PlayoutDelay(uint16_t* delay_ms) const override; |
300 int32_t RecordingDelay(uint16_t* delay_ms) const override; | 299 int32_t RecordingDelay(uint16_t* delay_ms) const override; |
301 int32_t RecordingSampleRate(uint32_t* sample_rate) const override; | 300 int32_t RecordingSampleRate(uint32_t* sample_rate) const override; |
302 int32_t PlayoutSampleRate(uint32_t* sample_rate) const override; | 301 int32_t PlayoutSampleRate(uint32_t* sample_rate) const override; |
303 | 302 |
304 public: | 303 public: |
305 // Sets the |renderer_|, returns false if |renderer_| already exists. | 304 // Sets the |renderer_|, returns false if |renderer_| already exists. |
306 // Called on the main renderer thread. | 305 // Called on the main renderer thread. |
307 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); | 306 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); |
308 | 307 |
309 // Adds/Removes the capturer to the ADM. | 308 // Adds/Removes the |capturer| to the ADM. Does NOT take ownership. |
310 // TODO(xians): Remove these two methods once the ADM does not need to pass | 309 // TODO(xians): Remove these two methods once the ADM does not need to pass |
311 // hardware information up to WebRtc. | 310 // hardware information up to WebRtc. |
312 void AddAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); | 311 void AddAudioCapturer(ProcessedLocalAudioSource* capturer); |
313 void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); | 312 void RemoveAudioCapturer(ProcessedLocalAudioSource* capturer); |
314 | |
315 // Gets the default capturer, which is the last capturer in |capturers_|. | |
316 // The method can be called by both Libjingle thread and main render thread. | |
317 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const; | |
318 | 313 |
319 // Gets paired device information of the capture device for the audio | 314 // Gets paired device information of the capture device for the audio |
320 // renderer. This is used to pass on a session id, sample rate and buffer | 315 // renderer. This is used to pass on a session id, sample rate and buffer |
321 // size to a webrtc audio renderer (either local or remote), so that audio | 316 // size to a webrtc audio renderer (either local or remote), so that audio |
322 // will be rendered to a matching output device. | 317 // will be rendered to a matching output device. |
323 // Returns true if the capture device has a paired output device, otherwise | 318 // Returns true if the capture device has a paired output device, otherwise |
324 // false. Note that if there are more than one open capture device the | 319 // false. Note that if there are more than one open capture device the |
325 // function will not be able to pick an appropriate device and return false. | 320 // function will not be able to pick an appropriate device and return false. |
326 bool GetAuthorizedDeviceInfoForAudioRenderer( | 321 bool GetAuthorizedDeviceInfoForAudioRenderer( |
327 int* session_id, int* output_sample_rate, int* output_buffer_size); | 322 int* session_id, int* output_sample_rate, int* output_buffer_size); |
328 | 323 |
329 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { | 324 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { |
330 return renderer_; | 325 return renderer_; |
331 } | 326 } |
332 | 327 |
333 private: | 328 private: |
334 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; | 329 typedef std::list<ProcessedLocalAudioSource*> CapturerList; |
335 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; | 330 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; |
336 class RenderBuffer; | 331 class RenderBuffer; |
337 | 332 |
338 // Make destructor private to ensure that we can only be deleted by Release(). | 333 // Make destructor private to ensure that we can only be deleted by Release(). |
339 ~WebRtcAudioDeviceImpl() override; | 334 ~WebRtcAudioDeviceImpl() override; |
340 | 335 |
341 // WebRtcAudioRendererSource implementation. | 336 // WebRtcAudioRendererSource implementation. |
342 | 337 |
343 // Called on the AudioOutputDevice worker thread. | 338 // Called on the AudioOutputDevice worker thread. |
344 void RenderData(media::AudioBus* audio_bus, | 339 void RenderData(media::AudioBus* audio_bus, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // Buffer used for temporary storage during render callback. | 400 // Buffer used for temporary storage during render callback. |
406 // It is only accessed by the audio render thread. | 401 // It is only accessed by the audio render thread. |
407 std::vector<int16_t> render_buffer_; | 402 std::vector<int16_t> render_buffer_; |
408 | 403 |
409 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); | 404 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); |
410 }; | 405 }; |
411 | 406 |
412 } // namespace content | 407 } // namespace content |
413 | 408 |
414 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ | 409 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ |
OLD | NEW |