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

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

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: Update TODO with userid and crbug. Created 3 years, 8 months 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 #include "content/renderer/media/renderer_webaudiodevice_impl.h" 5 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 23 matching lines...) Expand all
34 AudioDeviceFactory::SourceType GetLatencyHintSourceType( 34 AudioDeviceFactory::SourceType GetLatencyHintSourceType(
35 WebAudioLatencyHint::AudioContextLatencyCategory latency_category) { 35 WebAudioLatencyHint::AudioContextLatencyCategory latency_category) {
36 switch (latency_category) { 36 switch (latency_category) {
37 case WebAudioLatencyHint::kCategoryInteractive: 37 case WebAudioLatencyHint::kCategoryInteractive:
38 return AudioDeviceFactory::kSourceWebAudioInteractive; 38 return AudioDeviceFactory::kSourceWebAudioInteractive;
39 case WebAudioLatencyHint::kCategoryBalanced: 39 case WebAudioLatencyHint::kCategoryBalanced:
40 return AudioDeviceFactory::kSourceWebAudioBalanced; 40 return AudioDeviceFactory::kSourceWebAudioBalanced;
41 case WebAudioLatencyHint::kCategoryPlayback: 41 case WebAudioLatencyHint::kCategoryPlayback:
42 return AudioDeviceFactory::kSourceWebAudioPlayback; 42 return AudioDeviceFactory::kSourceWebAudioPlayback;
43 case WebAudioLatencyHint::kCategoryExact: 43 case WebAudioLatencyHint::kCategoryExact:
44 // TODO implement CategoryExact 44 return AudioDeviceFactory::kSourceWebAudioExact;
45 return AudioDeviceFactory::kSourceWebAudioInteractive;
46 } 45 }
47 NOTREACHED(); 46 NOTREACHED();
48 return AudioDeviceFactory::kSourceWebAudioInteractive; 47 return AudioDeviceFactory::kSourceWebAudioInteractive;
49 } 48 }
50 49
50 int GetOutputBufferSize(const blink::WebAudioLatencyHint& latency_hint,
51 const media::AudioLatency::LatencyType latency,
o1ka 2017/04/06 16:02:30 const not needed?
Andrew MacPherson 2017/04/07 06:59:03 Done.
52 const media::AudioParameters& hardware_params) {
53 // Adjust output buffer size according to the latency requirement.
54 switch (latency) {
55 case media::AudioLatency::LATENCY_INTERACTIVE:
56 return media::AudioLatency::GetInteractiveBufferSize(
57 hardware_params.frames_per_buffer());
58 break;
59 case media::AudioLatency::LATENCY_RTC:
60 return media::AudioLatency::GetRtcBufferSize(
61 hardware_params.sample_rate(), hardware_params.frames_per_buffer());
62 break;
63 case media::AudioLatency::LATENCY_PLAYBACK:
64 return media::AudioLatency::GetHighLatencyBufferSize(
65 hardware_params.sample_rate(), 0);
66 break;
67 case media::AudioLatency::LATENCY_EXACT_MS:
68 // TODO(andrew.macpherson@soundtrap.com): http://crbug.com/708917
69 return std::min(4096,
70 media::AudioLatency::GetExactBufferSize(
71 base::TimeDelta::FromSecondsD(latency_hint.seconds()),
72 hardware_params.sample_rate(),
73 hardware_params.frames_per_buffer()));
74 break;
75 default:
76 NOTREACHED();
77 }
78 return 0;
79 }
80
51 int FrameIdFromCurrentContext() { 81 int FrameIdFromCurrentContext() {
52 // Assumption: This method is being invoked within a V8 call stack. CHECKs 82 // Assumption: This method is being invoked within a V8 call stack. CHECKs
53 // will fail in the call to frameForCurrentContext() otherwise. 83 // will fail in the call to frameForCurrentContext() otherwise.
54 // 84 //
55 // Therefore, we can perform look-ups to determine which RenderView is 85 // Therefore, we can perform look-ups to determine which RenderView is
56 // starting the audio device. The reason for all this is because the creator 86 // starting the audio device. The reason for all this is because the creator
57 // of the WebAudio objects might not be the actual source of the audio (e.g., 87 // of the WebAudio objects might not be the actual source of the audio (e.g.,
58 // an extension creates a object that is passed and used within a page). 88 // an extension creates a object that is passed and used within a page).
59 blink::WebLocalFrame* const web_frame = 89 blink::WebLocalFrame* const web_frame =
60 blink::WebLocalFrame::frameForCurrentContext(); 90 blink::WebLocalFrame::frameForCurrentContext();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const OutputDeviceParamsCallback& device_params_cb, 127 const OutputDeviceParamsCallback& device_params_cb,
98 const RenderFrameIdCallback& render_frame_id_cb) 128 const RenderFrameIdCallback& render_frame_id_cb)
99 : latency_hint_(latency_hint), 129 : latency_hint_(latency_hint),
100 client_callback_(callback), 130 client_callback_(callback),
101 session_id_(session_id), 131 session_id_(session_id),
102 security_origin_(security_origin), 132 security_origin_(security_origin),
103 frame_id_(render_frame_id_cb.Run()) { 133 frame_id_(render_frame_id_cb.Run()) {
104 DCHECK(client_callback_); 134 DCHECK(client_callback_);
105 DCHECK_NE(frame_id_, MSG_ROUTING_NONE); 135 DCHECK_NE(frame_id_, MSG_ROUTING_NONE);
106 136
107 media::AudioParameters hardware_params(device_params_cb.Run( 137 media::AudioParameters hardware_params(device_params_cb.Run(
o1ka 2017/04/06 16:02:30 const?
Andrew MacPherson 2017/04/07 06:59:03 Done.
108 frame_id_, session_id_, std::string(), security_origin_)); 138 frame_id_, session_id_, std::string(), security_origin_));
109 139
110 int output_buffer_size = 0;
111
112 media::AudioLatency::LatencyType latency = 140 media::AudioLatency::LatencyType latency =
o1ka 2017/04/06 16:02:30 const?
Andrew MacPherson 2017/04/07 06:59:03 Done.
113 AudioDeviceFactory::GetSourceLatencyType( 141 AudioDeviceFactory::GetSourceLatencyType(
114 GetLatencyHintSourceType(latency_hint_.category())); 142 GetLatencyHintSourceType(latency_hint.category()));
115 143 int output_buffer_size =
o1ka 2017/04/06 16:02:30 const?
Andrew MacPherson 2017/04/07 06:59:03 Done.
116 // Adjust output buffer size according to the latency requirement. 144 GetOutputBufferSize(latency_hint_, latency, hardware_params);
117 switch (latency) {
118 case media::AudioLatency::LATENCY_INTERACTIVE:
119 output_buffer_size = media::AudioLatency::GetInteractiveBufferSize(
120 hardware_params.frames_per_buffer());
121 break;
122 case media::AudioLatency::LATENCY_RTC:
123 output_buffer_size = media::AudioLatency::GetRtcBufferSize(
124 hardware_params.sample_rate(), hardware_params.frames_per_buffer());
125 break;
126 case media::AudioLatency::LATENCY_PLAYBACK:
127 output_buffer_size = media::AudioLatency::GetHighLatencyBufferSize(
128 hardware_params.sample_rate(), 0);
129 break;
130 case media::AudioLatency::LATENCY_EXACT_MS:
131 // TODO(olka): add support when WebAudio requires it.
132 default:
133 NOTREACHED();
134 }
135
136 DCHECK_NE(output_buffer_size, 0); 145 DCHECK_NE(output_buffer_size, 0);
o1ka 2017/04/06 16:02:30 I think usually it's DCHECK_NE(0, output_buffer_si
Andrew MacPherson 2017/04/07 06:59:03 Done.
137 146
138 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, 147 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout,
139 hardware_params.sample_rate(), 16, output_buffer_size); 148 hardware_params.sample_rate(), 16, output_buffer_size);
140 // Always set channels, this should be a no-op in all but the discrete case; 149 // Always set channels, this should be a no-op in all but the discrete case;
141 // this call will fail if channels doesn't match the layout in other cases. 150 // this call will fail if channels doesn't match the layout in other cases.
142 sink_params_.set_channels_for_discrete(channels); 151 sink_params_.set_channels_for_discrete(channels);
143 152
144 // Specify the latency info to be passed to the browser side. 153 // Specify the latency info to be passed to the browser side.
145 sink_params_.set_latency_tag(latency); 154 sink_params_.set_latency_tag(latency);
146 } 155 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 const scoped_refptr<base::SingleThreadTaskRunner>& 239 const scoped_refptr<base::SingleThreadTaskRunner>&
231 RendererWebAudioDeviceImpl::GetMediaTaskRunner() { 240 RendererWebAudioDeviceImpl::GetMediaTaskRunner() {
232 if (!media_task_runner_) { 241 if (!media_task_runner_) {
233 media_task_runner_ = 242 media_task_runner_ =
234 RenderThreadImpl::current()->GetMediaThreadTaskRunner(); 243 RenderThreadImpl::current()->GetMediaThreadTaskRunner();
235 } 244 }
236 return media_task_runner_; 245 return media_task_runner_;
237 } 246 }
238 247
239 } // namespace content 248 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698