| 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_RENDERER_WEBAUDIODEVICE_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "content/renderer/media/audio_device_factory.h" |
| 13 #include "media/base/audio_parameters.h" | 14 #include "media/base/audio_parameters.h" |
| 14 #include "media/base/audio_renderer_sink.h" | 15 #include "media/base/audio_renderer_sink.h" |
| 15 #include "third_party/WebKit/public/platform/WebAudioDevice.h" | 16 #include "third_party/WebKit/public/platform/WebAudioDevice.h" |
| 16 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
| 17 #include "url/origin.h" | 18 #include "url/origin.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 class SilentSinkSuspender; | 21 class SilentSinkSuspender; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 class RendererWebAudioDeviceImpl | 25 class RendererWebAudioDeviceImpl |
| 25 : public blink::WebAudioDevice, | 26 : public blink::WebAudioDevice, |
| 26 public media::AudioRendererSink::RenderCallback { | 27 public media::AudioRendererSink::RenderCallback { |
| 27 public: | 28 public: |
| 28 RendererWebAudioDeviceImpl(const media::AudioParameters& params, | 29 RendererWebAudioDeviceImpl(const media::AudioParameters& params, |
| 30 const AudioDeviceFactory::SourceType source_type, |
| 29 blink::WebAudioDevice::RenderCallback* callback, | 31 blink::WebAudioDevice::RenderCallback* callback, |
| 30 int session_id, | 32 int session_id, |
| 31 const url::Origin& security_origin); | 33 const url::Origin& security_origin); |
| 32 ~RendererWebAudioDeviceImpl() override; | 34 ~RendererWebAudioDeviceImpl() override; |
| 33 | 35 |
| 34 // blink::WebAudioDevice implementation. | 36 // blink::WebAudioDevice implementation. |
| 35 void start() override; | 37 void start() override; |
| 36 void stop() override; | 38 void stop() override; |
| 37 double sampleRate() override; | 39 double sampleRate() override; |
| 40 int framesPerBuffer() override; |
| 38 | 41 |
| 39 // AudioRendererSink::RenderCallback implementation. | 42 // AudioRendererSink::RenderCallback implementation. |
| 40 int Render(media::AudioBus* dest, | 43 int Render(media::AudioBus* dest, |
| 41 uint32_t frames_delayed, | 44 uint32_t frames_delayed, |
| 42 uint32_t frames_skipped) override; | 45 uint32_t frames_skipped) override; |
| 43 | 46 |
| 44 void OnRenderError() override; | 47 void OnRenderError() override; |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 const media::AudioParameters params_; | 50 const media::AudioParameters sink_params_; |
| 51 |
| 52 const AudioDeviceFactory::SourceType source_type_; |
| 48 | 53 |
| 49 // Weak reference to the callback into WebKit code. | 54 // Weak reference to the callback into WebKit code. |
| 50 blink::WebAudioDevice::RenderCallback* const client_callback_; | 55 blink::WebAudioDevice::RenderCallback* const client_callback_; |
| 51 | 56 |
| 52 // To avoid the need for locking, ensure the control methods of the | 57 // To avoid the need for locking, ensure the control methods of the |
| 53 // blink::WebAudioDevice implementation are called on the same thread. | 58 // blink::WebAudioDevice implementation are called on the same thread. |
| 54 base::ThreadChecker thread_checker_; | 59 base::ThreadChecker thread_checker_; |
| 55 | 60 |
| 56 // When non-NULL, we are started. When NULL, we are stopped. | 61 // When non-NULL, we are started. When NULL, we are stopped. |
| 57 scoped_refptr<media::AudioRendererSink> sink_; | 62 scoped_refptr<media::AudioRendererSink> sink_; |
| 58 | 63 |
| 59 // ID to allow browser to select the correct input device for unified IO. | 64 // ID to allow browser to select the correct input device for unified IO. |
| 60 int session_id_; | 65 int session_id_; |
| 61 | 66 |
| 62 // Security origin, used to check permissions for |output_device_|. | 67 // Security origin, used to check permissions for |output_device_|. |
| 63 url::Origin security_origin_; | 68 url::Origin security_origin_; |
| 64 | 69 |
| 65 // Used to suspend |sink_| usage when silence has been detected for too long. | 70 // Used to suspend |sink_| usage when silence has been detected for too long. |
| 66 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; | 71 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; |
| 67 | 72 |
| 68 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); | 73 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 } // namespace content | 76 } // namespace content |
| 72 | 77 |
| 73 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ | 78 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ |
| OLD | NEW |