Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 client_callback_(callback), | 99 client_callback_(callback), |
| 101 session_id_(session_id), | 100 session_id_(session_id), |
| 102 security_origin_(security_origin), | 101 security_origin_(security_origin), |
| 103 frame_id_(render_frame_id_cb.Run()) { | 102 frame_id_(render_frame_id_cb.Run()) { |
| 104 DCHECK(client_callback_); | 103 DCHECK(client_callback_); |
| 105 DCHECK_NE(frame_id_, MSG_ROUTING_NONE); | 104 DCHECK_NE(frame_id_, MSG_ROUTING_NONE); |
| 106 | 105 |
| 107 media::AudioParameters hardware_params(device_params_cb.Run( | 106 media::AudioParameters hardware_params(device_params_cb.Run( |
| 108 frame_id_, session_id_, std::string(), security_origin_)); | 107 frame_id_, session_id_, std::string(), security_origin_)); |
| 109 | 108 |
| 110 int output_buffer_size = 0; | 109 int output_buffer_size = 0; |
|
o1ka
2017/03/16 10:51:23
Would be nice to wrap |output_buffer_size| calcula
Andrew MacPherson
2017/03/16 17:02:09
Done, I had to pass the latency_hint as well since
| |
| 111 | 110 |
| 112 media::AudioLatency::LatencyType latency = | 111 media::AudioLatency::LatencyType latency = |
| 113 AudioDeviceFactory::GetSourceLatencyType( | 112 AudioDeviceFactory::GetSourceLatencyType( |
| 114 GetLatencyHintSourceType(latency_hint_.category())); | 113 GetLatencyHintSourceType(latency_hint_.category())); |
| 115 | 114 |
| 116 // Adjust output buffer size according to the latency requirement. | 115 // Adjust output buffer size according to the latency requirement. |
| 117 switch (latency) { | 116 switch (latency) { |
| 118 case media::AudioLatency::LATENCY_INTERACTIVE: | 117 case media::AudioLatency::LATENCY_INTERACTIVE: |
| 119 output_buffer_size = media::AudioLatency::GetInteractiveBufferSize( | 118 output_buffer_size = media::AudioLatency::GetInteractiveBufferSize( |
| 120 hardware_params.frames_per_buffer()); | 119 hardware_params.frames_per_buffer()); |
| 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 = output_buffer_size = |
|
o1ka
2017/03/16 10:51:23
extra "output_buffer_size ="?
Andrew MacPherson
2017/03/16 17:02:09
Oops, fixed!
| |
| 131 media::AudioLatency::GetExactBufferSize( | |
| 132 latency_hint.seconds() * hardware_params.sample_rate(), | |
| 133 media::AudioLatency::GetHighLatencyBufferSize( | |
| 134 hardware_params.sample_rate(), 0), | |
| 135 hardware_params.frames_per_buffer()); | |
|
o1ka
2017/03/16 10:51:24
Can it be GetExactBufferSize(duration, hardware_pa
Andrew MacPherson
2017/03/16 17:02:09
Done.
| |
| 136 break; | |
| 132 default: | 137 default: |
| 133 NOTREACHED(); | 138 NOTREACHED(); |
| 134 } | 139 } |
| 135 | 140 |
| 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); |
|
o1ka
2017/03/16 10:51:24
We need top-to-bottom browser tests to see if a pl
Andrew MacPherson
2017/03/16 17:02:09
Do you mean like a renderer_webaudiodevice_impl_br
o1ka
2017/03/17 11:17:22
Let's see what dalecurtis@ thinks about testing it
| |
| 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); |
| 146 } | 151 } |
| 147 | 152 |
| 148 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 153 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
| 149 DCHECK(!sink_); | 154 DCHECK(!sink_); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |