Chromium Code Reviews| Index: content/renderer/renderer_blink_platform_impl.cc |
| diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc |
| index 339af699cf3917c0519e1e23228f5ab38b7ae9fb..6e6a2dda42b6cd50f977b78760d951977930aa7e 100644 |
| --- a/content/renderer/renderer_blink_platform_impl.cc |
| +++ b/content/renderer/renderer_blink_platform_impl.cc |
| @@ -86,6 +86,7 @@ |
| #include "third_party/WebKit/public/platform/BlameContext.h" |
| #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| #include "third_party/WebKit/public/platform/URLConversion.h" |
| +#include "third_party/WebKit/public/platform/WebAudioLatencyHint.h" |
| #include "third_party/WebKit/public/platform/WebBlobRegistry.h" |
| #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" |
| #include "third_party/WebKit/public/platform/WebFileInfo.h" |
| @@ -141,6 +142,7 @@ |
| using blink::Platform; |
| using blink::WebAudioDevice; |
| +using blink::WebAudioLatencyHint; |
| using blink::WebBlobRegistry; |
| using blink::WebCanvasCaptureHandler; |
| using blink::WebDatabaseObserver; |
| @@ -186,6 +188,82 @@ media::AudioParameters GetAudioHardwareParams() { |
| .output_params(); |
| } |
| +AudioDeviceFactory::SourceType GetLatencyHintSourceType( |
| + WebAudioLatencyHint::Category latency_category) { |
| + switch (latency_category) { |
| + case WebAudioLatencyHint::CategoryInteractive: |
| + return AudioDeviceFactory::kSourceWebAudioInteractive; |
| + case WebAudioLatencyHint::CategoryBalanced: |
| + return AudioDeviceFactory::kSourceWebAudioBalanced; |
| + case WebAudioLatencyHint::CategoryPlayback: |
| + return AudioDeviceFactory::kSourceWebAudioPlayback; |
| + } |
| + NOTREACHED(); |
| + return AudioDeviceFactory::kSourceWebAudioInteractive; |
| +} |
| + |
| +// Calculate mixer output parameters based on mixer input parameters and |
|
o1ka
2016/11/15 22:44:27
I don't think we need it here.
And WebAudioDevice
Andrew MacPherson
2016/11/16 10:58:29
Sounds good, I will remove this function entirely
|
| +// hardware parameters for audio output. |
| +media::AudioParameters GetLatencyParams( |
| + const media::AudioParameters& input_params, |
| + const media::AudioParameters& hardware_params, |
| + media::AudioLatency::LatencyType latency) { |
| + int output_sample_rate = input_params.sample_rate(); |
|
o1ka
2016/11/15 22:44:27
(explanation of how this mixer code differs from w
|
| + bool valid_not_fake_hardware_params = |
| + hardware_params.format() != media::AudioParameters::AUDIO_FAKE && |
| + hardware_params.IsValid(); |
| + int preferred_high_latency_output_buffer_size = 0; |
| + |
| +#if !defined(OS_CHROMEOS) |
| + // On ChromeOS as well as when a fake device is used, we can rely on the |
| + // playback device to handle resampling, so don't waste cycles on it here. |
| + // On other systems if hardware parameters are valid and the device is not |
| + // fake, resample to hardware sample rate. Otherwise, pass the input one and |
| + // let the browser side handle automatic fallback. |
|
o1ka
2016/11/15 22:44:27
(explanation of how this mixer code differs from w
|
| + if (valid_not_fake_hardware_params) { |
| + output_sample_rate = hardware_params.sample_rate(); |
| + preferred_high_latency_output_buffer_size = |
| + hardware_params.frames_per_buffer(); |
| + } |
| +#endif |
| + |
| + int output_buffer_size = 0; |
| + |
| + // Adjust output buffer size according to the latency requirement. |
| + switch (latency) { |
| + case media::AudioLatency::LATENCY_INTERACTIVE: |
| + output_buffer_size = media::AudioLatency::GetInteractiveBufferSize( |
| + hardware_params.frames_per_buffer()); |
| + break; |
| + case media::AudioLatency::LATENCY_RTC: |
| + output_buffer_size = media::AudioLatency::GetRtcBufferSize( |
| + output_sample_rate, valid_not_fake_hardware_params |
| + ? hardware_params.frames_per_buffer() |
| + : 0); |
| + break; |
| + case media::AudioLatency::LATENCY_PLAYBACK: |
| + output_buffer_size = media::AudioLatency::GetHighLatencyBufferSize( |
| + output_sample_rate, preferred_high_latency_output_buffer_size); |
| + break; |
| + case media::AudioLatency::LATENCY_EXACT_MS: |
| + // TODO(olka): add support when WebAudio requires it. |
| + default: |
| + NOTREACHED(); |
| + } |
| + |
| + DCHECK_NE(output_buffer_size, 0); |
| + |
| + // Force to 16-bit output for now since we know that works everywhere; |
| + // ChromeOS does not support other bit depths. |
| + media::AudioParameters params(input_params.format(), |
| + input_params.channel_layout(), |
| + output_sample_rate, 16, output_buffer_size); |
| + |
| + // Specify the latency info to be passed to the browser side. |
| + params.set_latency_tag(latency); |
| + return params; |
| +} |
| + |
| } // namespace |
| //------------------------------------------------------------------------------ |
| @@ -651,19 +729,12 @@ WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() { |
| } |
| WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice( |
| - size_t buffer_size, |
| unsigned input_channels, |
| unsigned channels, |
| - double sample_rate, |
| + const blink::WebAudioLatencyHint& latency_hint, |
| WebAudioDevice::RenderCallback* callback, |
| const blink::WebString& input_device_id, |
| const blink::WebSecurityOrigin& security_origin) { |
| - // Use a mock for testing. |
| - blink::WebAudioDevice* mock_device = |
| - GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate); |
| - if (mock_device) |
| - return mock_device; |
| - |
| // The |channels| does not exactly identify the channel layout of the |
| // device. The switch statement below assigns a best guess to the channel |
| // layout based on number of channels. |
| @@ -709,15 +780,31 @@ WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice( |
| input_channels = 0; |
| } |
| + media::AudioParameters input_params( |
| + media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, |
| + static_cast<int>(GetAudioHardwareParams().sample_rate()), 16, |
| + GetAudioHardwareParams().frames_per_buffer()); |
| + |
| + AudioDeviceFactory::SourceType source_type( |
| + GetLatencyHintSourceType(latency_hint.category())); |
| + media::AudioParameters params( |
| + GetLatencyParams(input_params, GetAudioHardwareParams(), |
|
o1ka
2016/11/15 22:44:27
I think we just do not need to pass parameters to
Andrew MacPherson
2016/11/16 10:58:29
Will fix in the next commit, thanks!
|
| + AudioDeviceFactory::GetSourceLatencyType(source_type))); |
| + |
| // For CHANNEL_LAYOUT_DISCRETE, pass the explicit channel count along with |
| // the channel layout when creating an |AudioParameters| object. |
| - media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| - layout, static_cast<int>(sample_rate), 16, |
| - buffer_size); |
| params.set_channels_for_discrete(channels); |
| + // Use a mock for testing. |
| + blink::WebAudioDevice* mock_device = |
| + GetContentClient()->renderer()->OverrideCreateAudioDevice( |
| + params.sample_rate(), params.frames_per_buffer()); |
| + if (mock_device) |
| + return mock_device; |
| + |
| return new RendererWebAudioDeviceImpl( |
| - params, callback, session_id, static_cast<url::Origin>(security_origin)); |
| + params, source_type, callback, session_id, |
| + static_cast<url::Origin>(security_origin)); |
| } |
| bool RendererBlinkPlatformImpl::loadAudioResource( |