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/renderer_blink_platform_impl.h" | 5 #include "content/renderer/renderer_blink_platform_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 #include "media/blink/webcontentdecryptionmodule_impl.h" | 79 #include "media/blink/webcontentdecryptionmodule_impl.h" |
80 #include "media/filters/stream_parser_factory.h" | 80 #include "media/filters/stream_parser_factory.h" |
81 #include "mojo/common/common_type_converters.h" | 81 #include "mojo/common/common_type_converters.h" |
82 #include "mojo/public/cpp/bindings/associated_group.h" | 82 #include "mojo/public/cpp/bindings/associated_group.h" |
83 #include "services/service_manager/public/cpp/interface_provider.h" | 83 #include "services/service_manager/public/cpp/interface_provider.h" |
84 #include "storage/common/database/database_identifier.h" | 84 #include "storage/common/database/database_identifier.h" |
85 #include "storage/common/quota/quota_types.h" | 85 #include "storage/common/quota/quota_types.h" |
86 #include "third_party/WebKit/public/platform/BlameContext.h" | 86 #include "third_party/WebKit/public/platform/BlameContext.h" |
87 #include "third_party/WebKit/public/platform/FilePathConversion.h" | 87 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
88 #include "third_party/WebKit/public/platform/URLConversion.h" | 88 #include "third_party/WebKit/public/platform/URLConversion.h" |
89 #include "third_party/WebKit/public/platform/WebAudioLatencyHint.h" | |
89 #include "third_party/WebKit/public/platform/WebBlobRegistry.h" | 90 #include "third_party/WebKit/public/platform/WebBlobRegistry.h" |
90 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" | 91 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" |
91 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 92 #include "third_party/WebKit/public/platform/WebFileInfo.h" |
92 #include "third_party/WebKit/public/platform/WebGamepads.h" | 93 #include "third_party/WebKit/public/platform/WebGamepads.h" |
93 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h" | 94 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h" |
94 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" | 95 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" |
95 #include "third_party/WebKit/public/platform/WebPluginListBuilder.h" | 96 #include "third_party/WebKit/public/platform/WebPluginListBuilder.h" |
96 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 97 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
97 #include "third_party/WebKit/public/platform/WebURL.h" | 98 #include "third_party/WebKit/public/platform/WebURL.h" |
98 #include "third_party/WebKit/public/platform/WebVector.h" | 99 #include "third_party/WebKit/public/platform/WebVector.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 #define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior | 135 #define WebScrollbarBehaviorImpl blink::WebScrollbarBehavior |
135 #endif | 136 #endif |
136 | 137 |
137 #if defined(ENABLE_WEBRTC) | 138 #if defined(ENABLE_WEBRTC) |
138 #include "content/renderer/media/rtc_certificate_generator.h" | 139 #include "content/renderer/media/rtc_certificate_generator.h" |
139 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 140 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
140 #endif | 141 #endif |
141 | 142 |
142 using blink::Platform; | 143 using blink::Platform; |
143 using blink::WebAudioDevice; | 144 using blink::WebAudioDevice; |
145 using blink::WebAudioLatencyHint; | |
144 using blink::WebBlobRegistry; | 146 using blink::WebBlobRegistry; |
145 using blink::WebCanvasCaptureHandler; | 147 using blink::WebCanvasCaptureHandler; |
146 using blink::WebDatabaseObserver; | 148 using blink::WebDatabaseObserver; |
147 using blink::WebFileInfo; | 149 using blink::WebFileInfo; |
148 using blink::WebFileSystem; | 150 using blink::WebFileSystem; |
149 using blink::WebGamepad; | 151 using blink::WebGamepad; |
150 using blink::WebGamepads; | 152 using blink::WebGamepads; |
151 using blink::WebIDBFactory; | 153 using blink::WebIDBFactory; |
152 using blink::WebImageCaptureFrameGrabber; | 154 using blink::WebImageCaptureFrameGrabber; |
153 using blink::WebMIDIAccessor; | 155 using blink::WebMIDIAccessor; |
(...skipping 25 matching lines...) Expand all Loading... | |
179 media::AudioParameters GetAudioHardwareParams() { | 181 media::AudioParameters GetAudioHardwareParams() { |
180 blink::WebLocalFrame* const web_frame = | 182 blink::WebLocalFrame* const web_frame = |
181 blink::WebLocalFrame::frameForCurrentContext(); | 183 blink::WebLocalFrame::frameForCurrentContext(); |
182 RenderFrame* const render_frame = RenderFrame::FromWebFrame(web_frame); | 184 RenderFrame* const render_frame = RenderFrame::FromWebFrame(web_frame); |
183 return AudioDeviceFactory::GetOutputDeviceInfo(render_frame->GetRoutingID(), | 185 return AudioDeviceFactory::GetOutputDeviceInfo(render_frame->GetRoutingID(), |
184 0, std::string(), | 186 0, std::string(), |
185 web_frame->getSecurityOrigin()) | 187 web_frame->getSecurityOrigin()) |
186 .output_params(); | 188 .output_params(); |
187 } | 189 } |
188 | 190 |
191 AudioDeviceFactory::SourceType GetLatencyHintSourceType( | |
192 WebAudioLatencyHint::Category latency_category) { | |
193 switch (latency_category) { | |
194 case WebAudioLatencyHint::CategoryInteractive: | |
195 return AudioDeviceFactory::kSourceWebAudioInteractive; | |
196 case WebAudioLatencyHint::CategoryBalanced: | |
197 return AudioDeviceFactory::kSourceWebAudioBalanced; | |
198 case WebAudioLatencyHint::CategoryPlayback: | |
199 return AudioDeviceFactory::kSourceWebAudioPlayback; | |
200 } | |
201 NOTREACHED(); | |
202 return AudioDeviceFactory::kSourceWebAudioInteractive; | |
203 } | |
204 | |
205 // 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
| |
206 // hardware parameters for audio output. | |
207 media::AudioParameters GetLatencyParams( | |
208 const media::AudioParameters& input_params, | |
209 const media::AudioParameters& hardware_params, | |
210 media::AudioLatency::LatencyType latency) { | |
211 int output_sample_rate = input_params.sample_rate(); | |
o1ka
2016/11/15 22:44:27
(explanation of how this mixer code differs from w
| |
212 bool valid_not_fake_hardware_params = | |
213 hardware_params.format() != media::AudioParameters::AUDIO_FAKE && | |
214 hardware_params.IsValid(); | |
215 int preferred_high_latency_output_buffer_size = 0; | |
216 | |
217 #if !defined(OS_CHROMEOS) | |
218 // On ChromeOS as well as when a fake device is used, we can rely on the | |
219 // playback device to handle resampling, so don't waste cycles on it here. | |
220 // On other systems if hardware parameters are valid and the device is not | |
221 // fake, resample to hardware sample rate. Otherwise, pass the input one and | |
222 // let the browser side handle automatic fallback. | |
o1ka
2016/11/15 22:44:27
(explanation of how this mixer code differs from w
| |
223 if (valid_not_fake_hardware_params) { | |
224 output_sample_rate = hardware_params.sample_rate(); | |
225 preferred_high_latency_output_buffer_size = | |
226 hardware_params.frames_per_buffer(); | |
227 } | |
228 #endif | |
229 | |
230 int output_buffer_size = 0; | |
231 | |
232 // Adjust output buffer size according to the latency requirement. | |
233 switch (latency) { | |
234 case media::AudioLatency::LATENCY_INTERACTIVE: | |
235 output_buffer_size = media::AudioLatency::GetInteractiveBufferSize( | |
236 hardware_params.frames_per_buffer()); | |
237 break; | |
238 case media::AudioLatency::LATENCY_RTC: | |
239 output_buffer_size = media::AudioLatency::GetRtcBufferSize( | |
240 output_sample_rate, valid_not_fake_hardware_params | |
241 ? hardware_params.frames_per_buffer() | |
242 : 0); | |
243 break; | |
244 case media::AudioLatency::LATENCY_PLAYBACK: | |
245 output_buffer_size = media::AudioLatency::GetHighLatencyBufferSize( | |
246 output_sample_rate, preferred_high_latency_output_buffer_size); | |
247 break; | |
248 case media::AudioLatency::LATENCY_EXACT_MS: | |
249 // TODO(olka): add support when WebAudio requires it. | |
250 default: | |
251 NOTREACHED(); | |
252 } | |
253 | |
254 DCHECK_NE(output_buffer_size, 0); | |
255 | |
256 // Force to 16-bit output for now since we know that works everywhere; | |
257 // ChromeOS does not support other bit depths. | |
258 media::AudioParameters params(input_params.format(), | |
259 input_params.channel_layout(), | |
260 output_sample_rate, 16, output_buffer_size); | |
261 | |
262 // Specify the latency info to be passed to the browser side. | |
263 params.set_latency_tag(latency); | |
264 return params; | |
265 } | |
266 | |
189 } // namespace | 267 } // namespace |
190 | 268 |
191 //------------------------------------------------------------------------------ | 269 //------------------------------------------------------------------------------ |
192 | 270 |
193 class RendererBlinkPlatformImpl::FileUtilities : public WebFileUtilitiesImpl { | 271 class RendererBlinkPlatformImpl::FileUtilities : public WebFileUtilitiesImpl { |
194 public: | 272 public: |
195 explicit FileUtilities(ThreadSafeSender* sender) | 273 explicit FileUtilities(ThreadSafeSender* sender) |
196 : thread_safe_sender_(sender) {} | 274 : thread_safe_sender_(sender) {} |
197 bool getFileInfo(const WebString& path, WebFileInfo& result) override; | 275 bool getFileInfo(const WebString& path, WebFileInfo& result) override; |
198 | 276 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 | 722 |
645 unsigned RendererBlinkPlatformImpl::audioHardwareOutputChannels() { | 723 unsigned RendererBlinkPlatformImpl::audioHardwareOutputChannels() { |
646 return GetAudioHardwareParams().channels(); | 724 return GetAudioHardwareParams().channels(); |
647 } | 725 } |
648 | 726 |
649 WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() { | 727 WebDatabaseObserver* RendererBlinkPlatformImpl::databaseObserver() { |
650 return web_database_observer_impl_.get(); | 728 return web_database_observer_impl_.get(); |
651 } | 729 } |
652 | 730 |
653 WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice( | 731 WebAudioDevice* RendererBlinkPlatformImpl::createAudioDevice( |
654 size_t buffer_size, | |
655 unsigned input_channels, | 732 unsigned input_channels, |
656 unsigned channels, | 733 unsigned channels, |
657 double sample_rate, | 734 const blink::WebAudioLatencyHint& latency_hint, |
658 WebAudioDevice::RenderCallback* callback, | 735 WebAudioDevice::RenderCallback* callback, |
659 const blink::WebString& input_device_id, | 736 const blink::WebString& input_device_id, |
660 const blink::WebSecurityOrigin& security_origin) { | 737 const blink::WebSecurityOrigin& security_origin) { |
661 // Use a mock for testing. | |
662 blink::WebAudioDevice* mock_device = | |
663 GetContentClient()->renderer()->OverrideCreateAudioDevice(sample_rate); | |
664 if (mock_device) | |
665 return mock_device; | |
666 | |
667 // The |channels| does not exactly identify the channel layout of the | 738 // The |channels| does not exactly identify the channel layout of the |
668 // device. The switch statement below assigns a best guess to the channel | 739 // device. The switch statement below assigns a best guess to the channel |
669 // layout based on number of channels. | 740 // layout based on number of channels. |
670 media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED; | 741 media::ChannelLayout layout = media::CHANNEL_LAYOUT_UNSUPPORTED; |
671 switch (channels) { | 742 switch (channels) { |
672 case 1: | 743 case 1: |
673 layout = media::CHANNEL_LAYOUT_MONO; | 744 layout = media::CHANNEL_LAYOUT_MONO; |
674 break; | 745 break; |
675 case 2: | 746 case 2: |
676 layout = media::CHANNEL_LAYOUT_STEREO; | 747 layout = media::CHANNEL_LAYOUT_STEREO; |
(...skipping 25 matching lines...) Expand all Loading... | |
702 int session_id = 0; | 773 int session_id = 0; |
703 if (input_device_id.isNull() || | 774 if (input_device_id.isNull() || |
704 !base::StringToInt(base::UTF16ToUTF8( | 775 !base::StringToInt(base::UTF16ToUTF8( |
705 base::StringPiece16(input_device_id)), &session_id)) { | 776 base::StringPiece16(input_device_id)), &session_id)) { |
706 if (input_channels > 0) | 777 if (input_channels > 0) |
707 DLOG(WARNING) << "createAudioDevice(): request for audio input ignored"; | 778 DLOG(WARNING) << "createAudioDevice(): request for audio input ignored"; |
708 | 779 |
709 input_channels = 0; | 780 input_channels = 0; |
710 } | 781 } |
711 | 782 |
783 media::AudioParameters input_params( | |
784 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, layout, | |
785 static_cast<int>(GetAudioHardwareParams().sample_rate()), 16, | |
786 GetAudioHardwareParams().frames_per_buffer()); | |
787 | |
788 AudioDeviceFactory::SourceType source_type( | |
789 GetLatencyHintSourceType(latency_hint.category())); | |
790 media::AudioParameters params( | |
791 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!
| |
792 AudioDeviceFactory::GetSourceLatencyType(source_type))); | |
793 | |
712 // For CHANNEL_LAYOUT_DISCRETE, pass the explicit channel count along with | 794 // For CHANNEL_LAYOUT_DISCRETE, pass the explicit channel count along with |
713 // the channel layout when creating an |AudioParameters| object. | 795 // the channel layout when creating an |AudioParameters| object. |
714 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
715 layout, static_cast<int>(sample_rate), 16, | |
716 buffer_size); | |
717 params.set_channels_for_discrete(channels); | 796 params.set_channels_for_discrete(channels); |
718 | 797 |
798 // Use a mock for testing. | |
799 blink::WebAudioDevice* mock_device = | |
800 GetContentClient()->renderer()->OverrideCreateAudioDevice( | |
801 params.sample_rate(), params.frames_per_buffer()); | |
802 if (mock_device) | |
803 return mock_device; | |
804 | |
719 return new RendererWebAudioDeviceImpl( | 805 return new RendererWebAudioDeviceImpl( |
720 params, callback, session_id, static_cast<url::Origin>(security_origin)); | 806 params, source_type, callback, session_id, |
807 static_cast<url::Origin>(security_origin)); | |
721 } | 808 } |
722 | 809 |
723 bool RendererBlinkPlatformImpl::loadAudioResource( | 810 bool RendererBlinkPlatformImpl::loadAudioResource( |
724 blink::WebAudioBus* destination_bus, | 811 blink::WebAudioBus* destination_bus, |
725 const char* audio_file_data, | 812 const char* audio_file_data, |
726 size_t data_size) { | 813 size_t data_size) { |
727 return DecodeAudioFileData( | 814 return DecodeAudioFileData( |
728 destination_bus, audio_file_data, data_size); | 815 destination_bus, audio_file_data, data_size); |
729 } | 816 } |
730 | 817 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 return &trial_token_validator_; | 1377 return &trial_token_validator_; |
1291 } | 1378 } |
1292 | 1379 |
1293 void RendererBlinkPlatformImpl::workerContextCreated( | 1380 void RendererBlinkPlatformImpl::workerContextCreated( |
1294 const v8::Local<v8::Context>& worker) { | 1381 const v8::Local<v8::Context>& worker) { |
1295 GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( | 1382 GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( |
1296 worker); | 1383 worker); |
1297 } | 1384 } |
1298 | 1385 |
1299 } // namespace content | 1386 } // namespace content |
OLD | NEW |