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