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 #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 Loading... | |
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 |
51 int FrameIdFromCurrentContext() { | 50 int FrameIdFromCurrentContext() { |
52 // Assumption: This method is being invoked within a V8 call stack. CHECKs | 51 // Assumption: This method is being invoked within a V8 call stack. CHECKs |
53 // will fail in the call to frameForCurrentContext() otherwise. | 52 // will fail in the call to frameForCurrentContext() otherwise. |
54 // | 53 // |
55 // Therefore, we can perform look-ups to determine which RenderView is | 54 // Therefore, we can perform look-ups to determine which RenderView is |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 break; | 120 break; |
122 case media::AudioLatency::LATENCY_RTC: | 121 case media::AudioLatency::LATENCY_RTC: |
123 output_buffer_size = media::AudioLatency::GetRtcBufferSize( | 122 output_buffer_size = media::AudioLatency::GetRtcBufferSize( |
124 hardware_params.sample_rate(), hardware_params.frames_per_buffer()); | 123 hardware_params.sample_rate(), hardware_params.frames_per_buffer()); |
125 break; | 124 break; |
126 case media::AudioLatency::LATENCY_PLAYBACK: | 125 case media::AudioLatency::LATENCY_PLAYBACK: |
127 output_buffer_size = media::AudioLatency::GetHighLatencyBufferSize( | 126 output_buffer_size = media::AudioLatency::GetHighLatencyBufferSize( |
128 hardware_params.sample_rate(), 0); | 127 hardware_params.sample_rate(), 0); |
129 break; | 128 break; |
130 case media::AudioLatency::LATENCY_EXACT_MS: | 129 case media::AudioLatency::LATENCY_EXACT_MS: |
131 // TODO(olka): add support when WebAudio requires it. | 130 output_buffer_size = |
131 latency_hint.seconds() * hardware_params.sample_rate(), | |
132 output_buffer_size = | |
133 std::max(std::min(output_buffer_size, | |
134 media::AudioLatency::GetHighLatencyBufferSize( | |
135 hardware_params.sample_rate(), 0)), | |
136 hardware_params.frames_per_buffer()); | |
o1ka
2017/03/14 15:55:43
Looks like we need something like media::AudioLate
Andrew MacPherson
2017/03/15 15:08:17
Done, I've added this now taking a parameter for t
| |
137 break; | |
132 default: | 138 default: |
133 NOTREACHED(); | 139 NOTREACHED(); |
134 } | 140 } |
135 | 141 |
136 DCHECK_NE(output_buffer_size, 0); | 142 DCHECK_NE(output_buffer_size, 0); |
137 | 143 |
138 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, | 144 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, |
139 hardware_params.sample_rate(), 16, output_buffer_size); | 145 hardware_params.sample_rate(), 16, output_buffer_size); |
140 // Always set channels, this should be a no-op in all but the discrete case; | 146 // 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. | 147 // this call will fail if channels doesn't match the layout in other cases. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 const scoped_refptr<base::SingleThreadTaskRunner>& | 236 const scoped_refptr<base::SingleThreadTaskRunner>& |
231 RendererWebAudioDeviceImpl::GetMediaTaskRunner() { | 237 RendererWebAudioDeviceImpl::GetMediaTaskRunner() { |
232 if (!media_task_runner_) { | 238 if (!media_task_runner_) { |
233 media_task_runner_ = | 239 media_task_runner_ = |
234 RenderThreadImpl::current()->GetMediaThreadTaskRunner(); | 240 RenderThreadImpl::current()->GetMediaThreadTaskRunner(); |
235 } | 241 } |
236 return media_task_runner_; | 242 return media_task_runner_; |
237 } | 243 } |
238 | 244 |
239 } // namespace content | 245 } // namespace content |
OLD | NEW |