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/media_stream_dependency_factory.h" | 5 #include "content/renderer/media/media_stream_dependency_factory.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 &already_set_value, NULL)) { | 89 &already_set_value, NULL)) { |
90 constraints->AddMandatory(kDefaultAudioConstraints[i].key, | 90 constraints->AddMandatory(kDefaultAudioConstraints[i].key, |
91 kDefaultAudioConstraints[i].value, false); | 91 kDefaultAudioConstraints[i].value, false); |
92 } else { | 92 } else { |
93 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key | 93 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
94 << " already set to " << already_set_value; | 94 << " already set to " << already_set_value; |
95 } | 95 } |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 void TransferConstraintToPlatformEffect(RTCMediaConstraints* constraints, | |
tommi (sloooow) - chröme
2013/12/06 12:11:34
Please document all the arguments. |platform_effe
ajm
2013/12/10 06:37:16
I tried returning the output effect and using just
| |
100 const char* key, | |
101 bool* platform_effect) { | |
102 bool value; | |
103 if (!webrtc::FindConstraint(constraints, key, &value, NULL) || | |
104 value == false) { | |
105 // If the constraint does not exist, or is set to false, disable the | |
106 // corresponding platform effect. | |
107 *platform_effect = false; | |
108 DVLOG(1) << "Disabling platform effect: " << key; | |
109 } else { | |
110 if (*platform_effect) { | |
tommi (sloooow) - chröme
2013/12/06 12:11:34
nit: you can save one scope:
} else if (*platform_
ajm
2013/12/10 06:37:16
Done.
| |
111 // If the constraint is set to true, and the corresponding platform effect | |
112 // is available, disable the constraint. | |
113 constraints->AddMandatory(key, | |
114 webrtc::MediaConstraintsInterface::kValueFalse, true); | |
115 DVLOG(1) << "Disabling constraint: " << key; | |
116 } | |
117 } | |
118 } | |
119 | |
120 // Any true constraint with an available corresponding platform effect will be | |
121 // set to false. Any false constraint will cause the corresponding platform | |
122 // effect to be disabled. | |
123 // | |
124 // This currently only deals with AEC, but is prepared for expansion to other | |
125 // platform effects. | |
126 void TransferConstraintsToPlatformEffects(RTCMediaConstraints* constraints, | |
127 MediaStreamDevice::AudioDeviceParameters* params) { | |
tommi (sloooow) - chröme
2013/12/06 12:11:34
please document that both parameters are in+out an
ajm
2013/12/10 06:37:16
Done. Hopefully you think it's sufficiently clear
| |
128 TransferConstraintToPlatformEffect(constraints, | |
129 webrtc::MediaConstraintsInterface::kEchoCancellation, | |
130 ¶ms->use_platform_aec); | |
131 } | |
132 | |
99 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { | 133 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { |
100 public: | 134 public: |
101 P2PPortAllocatorFactory( | 135 P2PPortAllocatorFactory( |
102 P2PSocketDispatcher* socket_dispatcher, | 136 P2PSocketDispatcher* socket_dispatcher, |
103 talk_base::NetworkManager* network_manager, | 137 talk_base::NetworkManager* network_manager, |
104 talk_base::PacketSocketFactory* socket_factory, | 138 talk_base::PacketSocketFactory* socket_factory, |
105 blink::WebFrame* web_frame) | 139 blink::WebFrame* web_frame) |
106 : socket_dispatcher_(socket_dispatcher), | 140 : socket_dispatcher_(socket_dispatcher), |
107 network_manager_(network_manager), | 141 network_manager_(network_manager), |
108 socket_factory_(socket_factory), | 142 socket_factory_(socket_factory), |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 350 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
317 | 351 |
318 // Check if the source has already been created. This happens when the same | 352 // Check if the source has already been created. This happens when the same |
319 // source is used in multiple MediaStreams as a result of calling | 353 // source is used in multiple MediaStreams as a result of calling |
320 // getUserMedia. | 354 // getUserMedia. |
321 if (source_data->local_audio_source()) | 355 if (source_data->local_audio_source()) |
322 continue; | 356 continue; |
323 | 357 |
324 // TODO(xians): Create a new capturer for difference microphones when we | 358 // TODO(xians): Create a new capturer for difference microphones when we |
325 // support multiple microphones. See issue crbug/262117 . | 359 // support multiple microphones. See issue crbug/262117 . |
326 const StreamDeviceInfo device_info = source_data->device_info(); | 360 StreamDeviceInfo device_info = source_data->device_info(); |
361 | |
362 RTCMediaConstraints platform_constraints = native_audio_constraints; | |
363 // This causes constraint settings to be transferred to their corresponding | |
364 // platform effects. For example, if a platform AEC is available, and the | |
365 // AEC constraint is set to true, we should leave the platform AEC | |
366 // enabled, and disable the software AEC by setting the constraint to false. | |
367 // Contrariwise, if the AEC constraint is set to false, we should disable | |
368 // the platform AEC even if available. | |
tommi (sloooow) - chröme
2013/12/06 12:11:34
This comment is good but I think it would be good
henrika (OOO until Aug 14)
2013/12/06 12:52:21
is it correct to assume that everything should wor
ajm
2013/12/10 06:37:16
If an AudioManager claims that a platform AEC exis
| |
369 TransferConstraintsToPlatformEffects(&platform_constraints, | |
370 &device_info.device.input); | |
327 scoped_refptr<WebRtcAudioCapturer> capturer( | 371 scoped_refptr<WebRtcAudioCapturer> capturer( |
328 MaybeCreateAudioCapturer(render_view_id, device_info)); | 372 MaybeCreateAudioCapturer(render_view_id, device_info)); |
329 if (!capturer.get()) { | 373 if (!capturer.get()) { |
330 DLOG(WARNING) << "Failed to create the capturer for device " | 374 DLOG(WARNING) << "Failed to create the capturer for device " |
331 << device_info.device.id; | 375 << device_info.device.id; |
332 sources_created.Run(web_stream, false); | 376 sources_created.Run(web_stream, false); |
333 // TODO(xians): Don't we need to check if source_observer is observing | 377 // TODO(xians): Don't we need to check if source_observer is observing |
334 // something? If not, then it looks like we have a leak here. | 378 // something? If not, then it looks like we have a leak here. |
335 // OTOH, if it _is_ observing something, then the callback might | 379 // OTOH, if it _is_ observing something, then the callback might |
336 // be called multiple times which is likely also a bug. | 380 // be called multiple times which is likely also a bug. |
337 return; | 381 return; |
338 } | 382 } |
339 source_data->SetAudioCapturer(capturer); | 383 source_data->SetAudioCapturer(capturer); |
340 | 384 |
341 // Creates a LocalAudioSource object which holds audio options. | 385 // Creates a LocalAudioSource object which holds audio options. |
342 // TODO(xians): The option should apply to the track instead of the source. | 386 // TODO(xians): The option should apply to the track instead of the source. |
343 source_data->SetLocalAudioSource( | 387 source_data->SetLocalAudioSource( |
344 CreateLocalAudioSource(&native_audio_constraints).get()); | 388 CreateLocalAudioSource(&platform_constraints).get()); |
345 source_observer->AddSource(source_data->local_audio_source()); | 389 source_observer->AddSource(source_data->local_audio_source()); |
346 } | 390 } |
347 | 391 |
348 source_observer->StartObservering(); | 392 source_observer->StartObservering(); |
349 } | 393 } |
350 | 394 |
351 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( | 395 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( |
352 blink::WebMediaStream* web_stream) { | 396 blink::WebMediaStream* web_stream) { |
353 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; | 397 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; |
354 if (!EnsurePeerConnectionFactory()) { | 398 if (!EnsurePeerConnectionFactory()) { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 | 947 |
904 if (!capturer->Initialize( | 948 if (!capturer->Initialize( |
905 render_view_id, | 949 render_view_id, |
906 static_cast<media::ChannelLayout>( | 950 static_cast<media::ChannelLayout>( |
907 device_info.device.input.channel_layout), | 951 device_info.device.input.channel_layout), |
908 device_info.device.input.sample_rate, | 952 device_info.device.input.sample_rate, |
909 device_info.device.input.frames_per_buffer, | 953 device_info.device.input.frames_per_buffer, |
910 device_info.session_id, | 954 device_info.session_id, |
911 device_info.device.id, | 955 device_info.device.id, |
912 device_info.device.matched_output.sample_rate, | 956 device_info.device.matched_output.sample_rate, |
913 device_info.device.matched_output.frames_per_buffer)) { | 957 device_info.device.matched_output.frames_per_buffer, |
958 device_info.device.input.use_platform_aec)) { | |
914 return NULL; | 959 return NULL; |
915 } | 960 } |
916 | 961 |
917 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. | 962 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. |
918 if (is_new_capturer) | 963 if (is_new_capturer) |
919 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); | 964 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); |
920 | 965 |
921 return capturer; | 966 return capturer; |
922 } | 967 } |
923 | 968 |
(...skipping 28 matching lines...) Expand all Loading... | |
952 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( | 997 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( |
953 const blink::WebMediaStreamTrack& track) { | 998 const blink::WebMediaStreamTrack& track) { |
954 if (track.isNull()) | 999 if (track.isNull()) |
955 return NULL; | 1000 return NULL; |
956 MediaStreamTrackExtraData* extra_data = | 1001 MediaStreamTrackExtraData* extra_data = |
957 static_cast<MediaStreamTrackExtraData*>(track.extraData()); | 1002 static_cast<MediaStreamTrackExtraData*>(track.extraData()); |
958 return extra_data ? extra_data->track().get() : NULL; | 1003 return extra_data ? extra_data->track().get() : NULL; |
959 } | 1004 } |
960 | 1005 |
961 } // namespace content | 1006 } // namespace content |
OLD | NEW |