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

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

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: Fix audiocontextoptions LayoutTest. 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,
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(
DaleCurtis 2017/03/28 17:34:07 I wonder if we should just replace this with GetEx
Andrew MacPherson 2017/03/29 08:34:09 Sounds good!
65 hardware_params.sample_rate(), 0);
66 break;
67 case media::AudioLatency::LATENCY_EXACT_MS:
68 return media::AudioLatency::GetExactBufferSize(latency_hint.seconds(),
69 hardware_params);
70 break;
71 default:
72 NOTREACHED();
73 }
74 return 0;
75 }
76
51 int FrameIdFromCurrentContext() { 77 int FrameIdFromCurrentContext() {
52 // Assumption: This method is being invoked within a V8 call stack. CHECKs 78 // Assumption: This method is being invoked within a V8 call stack. CHECKs
53 // will fail in the call to frameForCurrentContext() otherwise. 79 // will fail in the call to frameForCurrentContext() otherwise.
54 // 80 //
55 // Therefore, we can perform look-ups to determine which RenderView is 81 // 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 82 // 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., 83 // 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). 84 // an extension creates a object that is passed and used within a page).
59 blink::WebLocalFrame* const web_frame = 85 blink::WebLocalFrame* const web_frame =
60 blink::WebLocalFrame::frameForCurrentContext(); 86 blink::WebLocalFrame::frameForCurrentContext();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 client_callback_(callback), 126 client_callback_(callback),
101 session_id_(session_id), 127 session_id_(session_id),
102 security_origin_(security_origin), 128 security_origin_(security_origin),
103 frame_id_(render_frame_id_cb.Run()) { 129 frame_id_(render_frame_id_cb.Run()) {
104 DCHECK(client_callback_); 130 DCHECK(client_callback_);
105 DCHECK_NE(frame_id_, MSG_ROUTING_NONE); 131 DCHECK_NE(frame_id_, MSG_ROUTING_NONE);
106 132
107 media::AudioParameters hardware_params(device_params_cb.Run( 133 media::AudioParameters hardware_params(device_params_cb.Run(
108 frame_id_, session_id_, std::string(), security_origin_)); 134 frame_id_, session_id_, std::string(), security_origin_));
109 135
110 int output_buffer_size = 0;
111
112 media::AudioLatency::LatencyType latency = 136 media::AudioLatency::LatencyType latency =
113 AudioDeviceFactory::GetSourceLatencyType( 137 AudioDeviceFactory::GetSourceLatencyType(
114 GetLatencyHintSourceType(latency_hint_.category())); 138 GetLatencyHintSourceType(latency_hint.category()));
115 139 int output_buffer_size =
116 // Adjust output buffer size according to the latency requirement. 140 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); 141 DCHECK_NE(output_buffer_size, 0);
137 142
138 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, 143 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout,
139 hardware_params.sample_rate(), 16, output_buffer_size); 144 hardware_params.sample_rate(), 16, output_buffer_size);
140 // Always set channels, this should be a no-op in all but the discrete case; 145 // 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. 146 // this call will fail if channels doesn't match the layout in other cases.
142 sink_params_.set_channels_for_discrete(channels); 147 sink_params_.set_channels_for_discrete(channels);
143 148
144 // Specify the latency info to be passed to the browser side. 149 // Specify the latency info to be passed to the browser side.
145 sink_params_.set_latency_tag(latency); 150 sink_params_.set_latency_tag(latency);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 const scoped_refptr<base::SingleThreadTaskRunner>& 235 const scoped_refptr<base::SingleThreadTaskRunner>&
231 RendererWebAudioDeviceImpl::GetMediaTaskRunner() { 236 RendererWebAudioDeviceImpl::GetMediaTaskRunner() {
232 if (!media_task_runner_) { 237 if (!media_task_runner_) {
233 media_task_runner_ = 238 media_task_runner_ =
234 RenderThreadImpl::current()->GetMediaThreadTaskRunner(); 239 RenderThreadImpl::current()->GetMediaThreadTaskRunner();
235 } 240 }
236 return media_task_runner_; 241 return media_task_runner_;
237 } 242 }
238 243
239 } // namespace content 244 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698