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/common/content_export.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" |
| 17 #include "third_party/WebKit/public/platform/WebAudioLatencyHint.h" |
16 #include "third_party/WebKit/public/platform/WebVector.h" | 18 #include "third_party/WebKit/public/platform/WebVector.h" |
17 #include "url/origin.h" | 19 #include "url/origin.h" |
18 | 20 |
19 namespace media { | 21 namespace media { |
20 class SilentSinkSuspender; | 22 class SilentSinkSuspender; |
21 } | 23 } |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 class RendererWebAudioDeviceImpl | 26 class CONTENT_EXPORT RendererWebAudioDeviceImpl |
25 : public blink::WebAudioDevice, | 27 : public blink::WebAudioDevice, |
26 public media::AudioRendererSink::RenderCallback { | 28 public media::AudioRendererSink::RenderCallback { |
27 public: | 29 public: |
28 RendererWebAudioDeviceImpl(const media::AudioParameters& params, | |
29 blink::WebAudioDevice::RenderCallback* callback, | |
30 int session_id, | |
31 const url::Origin& security_origin); | |
32 ~RendererWebAudioDeviceImpl() override; | 30 ~RendererWebAudioDeviceImpl() override; |
33 | 31 |
| 32 static RendererWebAudioDeviceImpl* Create( |
| 33 media::ChannelLayout layout, |
| 34 const blink::WebAudioLatencyHint& latency_hint, |
| 35 blink::WebAudioDevice::RenderCallback* callback, |
| 36 int session_id, |
| 37 const url::Origin& security_origin); |
| 38 |
34 // blink::WebAudioDevice implementation. | 39 // blink::WebAudioDevice implementation. |
35 void start() override; | 40 void start() override; |
36 void stop() override; | 41 void stop() override; |
37 double sampleRate() override; | 42 double sampleRate() override; |
| 43 int framesPerBuffer() override; |
38 | 44 |
39 // AudioRendererSink::RenderCallback implementation. | 45 // AudioRendererSink::RenderCallback implementation. |
40 int Render(base::TimeDelta delay, | 46 int Render(base::TimeDelta delay, |
41 base::TimeTicks delay_timestamp, | 47 base::TimeTicks delay_timestamp, |
42 int prior_frames_skipped, | 48 int prior_frames_skipped, |
43 media::AudioBus* dest) override; | 49 media::AudioBus* dest) override; |
44 | 50 |
45 void OnRenderError() override; | 51 void OnRenderError() override; |
46 | 52 |
| 53 protected: |
| 54 // Callback to get output device params (for tests). |
| 55 using OutputDeviceParamsCallback = base::Callback<media::AudioParameters( |
| 56 int frame_id, |
| 57 int session_id, |
| 58 const std::string& device_id, |
| 59 const url::Origin& security_origin)>; |
| 60 |
| 61 // Callback get render frame ID for current context (for tests). |
| 62 using RenderFrameIdCallback = base::Callback<int()>; |
| 63 |
| 64 RendererWebAudioDeviceImpl( |
| 65 media::ChannelLayout layout, |
| 66 const blink::WebAudioLatencyHint& latency_hint, |
| 67 blink::WebAudioDevice::RenderCallback* callback, |
| 68 int session_id, |
| 69 const url::Origin& security_origin, |
| 70 const OutputDeviceParamsCallback& device_params_cb, |
| 71 const RenderFrameIdCallback& render_frame_id_cb); |
| 72 |
47 private: | 73 private: |
48 const media::AudioParameters params_; | 74 media::AudioParameters sink_params_; |
| 75 |
| 76 const blink::WebAudioLatencyHint latency_hint_; |
49 | 77 |
50 // Weak reference to the callback into WebKit code. | 78 // Weak reference to the callback into WebKit code. |
51 blink::WebAudioDevice::RenderCallback* const client_callback_; | 79 blink::WebAudioDevice::RenderCallback* const client_callback_; |
52 | 80 |
53 // To avoid the need for locking, ensure the control methods of the | 81 // To avoid the need for locking, ensure the control methods of the |
54 // blink::WebAudioDevice implementation are called on the same thread. | 82 // blink::WebAudioDevice implementation are called on the same thread. |
55 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
56 | 84 |
57 // When non-NULL, we are started. When NULL, we are stopped. | 85 // When non-NULL, we are started. When NULL, we are stopped. |
58 scoped_refptr<media::AudioRendererSink> sink_; | 86 scoped_refptr<media::AudioRendererSink> sink_; |
59 | 87 |
60 // ID to allow browser to select the correct input device for unified IO. | 88 // ID to allow browser to select the correct input device for unified IO. |
61 int session_id_; | 89 int session_id_; |
62 | 90 |
63 // Security origin, used to check permissions for |output_device_|. | 91 // Security origin, used to check permissions for |output_device_|. |
64 url::Origin security_origin_; | 92 url::Origin security_origin_; |
65 | 93 |
66 // Used to suspend |sink_| usage when silence has been detected for too long. | 94 // Used to suspend |sink_| usage when silence has been detected for too long. |
67 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; | 95 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; |
68 | 96 |
| 97 // Render frame routing ID for the current context. |
| 98 int frame_id_; |
| 99 |
69 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); | 100 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); |
70 }; | 101 }; |
71 | 102 |
72 } // namespace content | 103 } // namespace content |
73 | 104 |
74 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ | 105 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ |
OLD | NEW |