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

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

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Adding additional 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
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)
o1ka 2016/12/07 20:56:01 nit: end with "."
Andrew MacPherson 2016/12/08 10:06:12 Done.
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 // Callback get render frame ID for current context (for tests)
o1ka 2016/12/07 20:56:01 nits: empty line before this one, dot in the end
Andrew MacPherson 2016/12/08 10:06:12 Done.
61 using RenderFrameIdCallback = base::Callback<int()>;
62
63 RendererWebAudioDeviceImpl(
64 media::ChannelLayout layout,
65 const blink::WebAudioLatencyHint& latency_hint,
66 blink::WebAudioDevice::RenderCallback* callback,
67 int session_id,
68 const url::Origin& security_origin,
69 const OutputDeviceParamsCallback& device_params_cb,
70 const RenderFrameIdCallback& render_frame_id_cb);
71
47 private: 72 private:
48 const media::AudioParameters params_; 73 media::AudioParameters sink_params_;
74
75 const blink::WebAudioLatencyHint latency_hint_;
49 76
50 // Weak reference to the callback into WebKit code. 77 // Weak reference to the callback into WebKit code.
51 blink::WebAudioDevice::RenderCallback* const client_callback_; 78 blink::WebAudioDevice::RenderCallback* const client_callback_;
52 79
53 // To avoid the need for locking, ensure the control methods of the 80 // To avoid the need for locking, ensure the control methods of the
54 // blink::WebAudioDevice implementation are called on the same thread. 81 // blink::WebAudioDevice implementation are called on the same thread.
55 base::ThreadChecker thread_checker_; 82 base::ThreadChecker thread_checker_;
56 83
57 // When non-NULL, we are started. When NULL, we are stopped. 84 // When non-NULL, we are started. When NULL, we are stopped.
58 scoped_refptr<media::AudioRendererSink> sink_; 85 scoped_refptr<media::AudioRendererSink> sink_;
59 86
60 // ID to allow browser to select the correct input device for unified IO. 87 // ID to allow browser to select the correct input device for unified IO.
61 int session_id_; 88 int session_id_;
62 89
63 // Security origin, used to check permissions for |output_device_|. 90 // Security origin, used to check permissions for |output_device_|.
64 url::Origin security_origin_; 91 url::Origin security_origin_;
65 92
66 // Used to suspend |sink_| usage when silence has been detected for too long. 93 // Used to suspend |sink_| usage when silence has been detected for too long.
67 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_; 94 std::unique_ptr<media::SilentSinkSuspender> webaudio_suspender_;
68 95
96 // Render frame routing ID for the current context.
97 int frame_id_;
98
69 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl); 99 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
70 }; 100 };
71 101
72 } // namespace content 102 } // namespace content
73 103
74 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_ 104 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698