Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: content/renderer/media/renderer_webaudiodevice_impl.h

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Update RendererWebAudioDeviceImpl unit tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 media::AudioLatency::LatencyType latencyType();
39
34 // blink::WebAudioDevice implementation. 40 // blink::WebAudioDevice implementation.
35 void start() override; 41 void start() override;
36 void stop() override; 42 void stop() override;
37 double sampleRate() override; 43 double sampleRate() override;
44 int framesPerBuffer() override;
38 45
39 // AudioRendererSink::RenderCallback implementation. 46 // AudioRendererSink::RenderCallback implementation.
40 int Render(base::TimeDelta delay, 47 int Render(base::TimeDelta delay,
41 base::TimeTicks delay_timestamp, 48 base::TimeTicks delay_timestamp,
42 int prior_frames_skipped, 49 int prior_frames_skipped,
43 media::AudioBus* dest) override; 50 media::AudioBus* dest) override;
44 51
45 void OnRenderError() override; 52 void OnRenderError() override;
46 53
54 protected:
55 // Callback to get output device params (for tests).
56 using OutputDeviceParamsCallback = base::Callback<media::AudioParameters(
57 int frame_id,
58 int session_id,
59 const std::string& device_id,
60 const url::Origin& security_origin)>;
61
62 // Callback get render frame ID for current context (for tests).
63 using RenderFrameIdCallback = base::Callback<int()>;
64
65 RendererWebAudioDeviceImpl(
66 media::ChannelLayout layout,
67 const blink::WebAudioLatencyHint& latency_hint,
68 blink::WebAudioDevice::RenderCallback* callback,
69 int session_id,
70 const url::Origin& security_origin,
71 const OutputDeviceParamsCallback& device_params_cb,
72 const RenderFrameIdCallback& render_frame_id_cb);
73
47 private: 74 private:
48 const media::AudioParameters params_; 75 media::AudioParameters sink_params_;
76
77 const blink::WebAudioLatencyHint latency_hint_;
49 78
50 // Weak reference to the callback into WebKit code. 79 // Weak reference to the callback into WebKit code.
51 blink::WebAudioDevice::RenderCallback* const client_callback_; 80 blink::WebAudioDevice::RenderCallback* const client_callback_;
52 81
53 // To avoid the need for locking, ensure the control methods of the 82 // To avoid the need for locking, ensure the control methods of the
54 // blink::WebAudioDevice implementation are called on the same thread. 83 // blink::WebAudioDevice implementation are called on the same thread.
55 base::ThreadChecker thread_checker_; 84 base::ThreadChecker thread_checker_;
56 85
57 // When non-NULL, we are started. When NULL, we are stopped. 86 // When non-NULL, we are started. When NULL, we are stopped.
58 scoped_refptr<media::AudioRendererSink> sink_; 87 scoped_refptr<media::AudioRendererSink> sink_;
59 88
60 // ID to allow browser to select the correct input device for unified IO. 89 // ID to allow browser to select the correct input device for unified IO.
61 int session_id_; 90 int session_id_;
62 91
63 // Security origin, used to check permissions for |output_device_|. 92 // Security origin, used to check permissions for |output_device_|.
64 url::Origin security_origin_; 93 url::Origin security_origin_;
65 94
66 // Used to suspend |sink_| usage when silence has been detected for too long. 95 // Used to suspend |sink_| usage when silence has been detected for too long.
67 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; 96 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_;
68 97
98 // Render frame routing ID for the current context.
99 int frame_id_;
100
69 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); 101 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
70 }; 102 };
71 103
72 } // namespace content 104 } // namespace content
73 105
74 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 106 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698