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 typedef media::AudioParameters::PlatformEffects PlatformEffects; | |
tommi (sloooow) - chröme
2013/12/11 12:14:36
Is it a good idea to create a new type for this?
ajm
2013/12/12 01:51:27
Removed.
| |
100 | |
101 // |key| is the constraint for which |constraints| should be updated, and | |
102 // |effect| is the state of the corresponding platform effect. | |
tommi (sloooow) - chröme
2013/12/11 12:14:36
This function is still confusing to me since both
ajm
2013/12/11 17:46:49
That works, and I agree is much cleaner.
ajm
2013/12/12 01:51:27
Ugh, on further reflection, it doesn't work. First
| |
103 // |constraints| and |effect| are both input and output parameters. | |
104 // | |
105 // See the function below for a full description of the purpose. | |
106 void ReconcileConstraintAndPlatformEffect(const char* key, | |
107 RTCMediaConstraints* constraints, | |
108 bool* effect) { | |
109 bool value; | |
110 if (!webrtc::FindConstraint(constraints, key, &value, NULL) || | |
tommi (sloooow) - chröme
2013/12/11 12:14:36
nit: this fits on one line:
if (!webrtc::FindCon
ajm
2013/12/12 01:51:27
Removed.
| |
111 value == false) { | |
112 // If the constraint does not exist, or is set to false, disable the | |
113 // corresponding platform effect. | |
114 *effect = false; | |
115 DVLOG(1) << "Disabling platform effect: " << key; | |
116 } else if (*effect) { | |
117 // If the constraint is set to true, and the corresponding platform effect | |
118 // is available, disable the constraint. | |
119 constraints->AddMandatory(key, | |
120 webrtc::MediaConstraintsInterface::kValueFalse, true); | |
121 DVLOG(1) << "Disabling constraint: " << key; | |
122 } | |
123 } | |
124 | |
125 // Updates |constraints| and |effects| to be consistent with each other. At | |
126 // input, |constraints| must be the media constraints requested for the gUM | |
127 // stream. At output |constraints| will be updated to reflect what should be | |
128 // applied to the source (e.g. PeerConnection). At input, |effects| must be the | |
129 // available platform (i.e. built-in, typically hardware) audio effects which | |
130 // should be used in preference to software effects. At output, |effects| will | |
131 // be updated to reflect what should be applied to the platform capturer. | |
132 // | |
133 // In particular this means: | |
134 // - Any true constraint with an available corresponding platform effect at | |
135 // input will be set to false at output. | |
136 // - Any false constraint at input will cause the corresponding platform effect | |
137 // to be disabled at output. | |
138 void ReconcileConstraintsAndPlatformEffects(RTCMediaConstraints* constraints, | |
139 PlatformEffects* effects) { | |
140 // This currently only deals with AEC, but is prepared for expansion to other | |
141 // platform effects. | |
142 ReconcileConstraintAndPlatformEffect( | |
143 webrtc::MediaConstraintsInterface::kEchoCancellation, | |
144 constraints, | |
145 &effects->echo_canceller); | |
146 } | |
147 | |
99 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { | 148 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { |
100 public: | 149 public: |
101 P2PPortAllocatorFactory( | 150 P2PPortAllocatorFactory( |
102 P2PSocketDispatcher* socket_dispatcher, | 151 P2PSocketDispatcher* socket_dispatcher, |
103 talk_base::NetworkManager* network_manager, | 152 talk_base::NetworkManager* network_manager, |
104 talk_base::PacketSocketFactory* socket_factory, | 153 talk_base::PacketSocketFactory* socket_factory, |
105 blink::WebFrame* web_frame) | 154 blink::WebFrame* web_frame) |
106 : socket_dispatcher_(socket_dispatcher), | 155 : socket_dispatcher_(socket_dispatcher), |
107 network_manager_(network_manager), | 156 network_manager_(network_manager), |
108 socket_factory_(socket_factory), | 157 socket_factory_(socket_factory), |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 365 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
317 | 366 |
318 // Check if the source has already been created. This happens when the same | 367 // 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 | 368 // source is used in multiple MediaStreams as a result of calling |
320 // getUserMedia. | 369 // getUserMedia. |
321 if (source_data->local_audio_source()) | 370 if (source_data->local_audio_source()) |
322 continue; | 371 continue; |
323 | 372 |
324 // TODO(xians): Create a new capturer for difference microphones when we | 373 // TODO(xians): Create a new capturer for difference microphones when we |
325 // support multiple microphones. See issue crbug/262117 . | 374 // support multiple microphones. See issue crbug/262117 . |
326 const StreamDeviceInfo device_info = source_data->device_info(); | 375 StreamDeviceInfo device_info = source_data->device_info(); |
376 | |
377 RTCMediaConstraints platform_constraints = native_audio_constraints; | |
378 // This has the potential to update both the constraints and the platform | |
379 // effects, such that we prefer platform to software effects but disable | |
380 // platform effects when requested by constraints. | |
381 // | |
382 // See the function documentation for a full description. | |
383 ReconcileConstraintsAndPlatformEffects(&platform_constraints, | |
384 &device_info.device.input.effects); | |
327 scoped_refptr<WebRtcAudioCapturer> capturer( | 385 scoped_refptr<WebRtcAudioCapturer> capturer( |
328 MaybeCreateAudioCapturer(render_view_id, device_info)); | 386 MaybeCreateAudioCapturer(render_view_id, device_info)); |
329 if (!capturer.get()) { | 387 if (!capturer.get()) { |
330 DLOG(WARNING) << "Failed to create the capturer for device " | 388 DLOG(WARNING) << "Failed to create the capturer for device " |
331 << device_info.device.id; | 389 << device_info.device.id; |
332 sources_created.Run(web_stream, false); | 390 sources_created.Run(web_stream, false); |
333 // TODO(xians): Don't we need to check if source_observer is observing | 391 // 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. | 392 // something? If not, then it looks like we have a leak here. |
335 // OTOH, if it _is_ observing something, then the callback might | 393 // OTOH, if it _is_ observing something, then the callback might |
336 // be called multiple times which is likely also a bug. | 394 // be called multiple times which is likely also a bug. |
337 return; | 395 return; |
338 } | 396 } |
339 source_data->SetAudioCapturer(capturer); | 397 source_data->SetAudioCapturer(capturer); |
340 | 398 |
341 // Creates a LocalAudioSource object which holds audio options. | 399 // Creates a LocalAudioSource object which holds audio options. |
342 // TODO(xians): The option should apply to the track instead of the source. | 400 // TODO(xians): The option should apply to the track instead of the source. |
343 source_data->SetLocalAudioSource( | 401 source_data->SetLocalAudioSource( |
344 CreateLocalAudioSource(&native_audio_constraints).get()); | 402 CreateLocalAudioSource(&platform_constraints).get()); |
345 source_observer->AddSource(source_data->local_audio_source()); | 403 source_observer->AddSource(source_data->local_audio_source()); |
346 } | 404 } |
347 | 405 |
348 source_observer->StartObservering(); | 406 source_observer->StartObservering(); |
349 } | 407 } |
350 | 408 |
351 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( | 409 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( |
352 blink::WebMediaStream* web_stream) { | 410 blink::WebMediaStream* web_stream) { |
353 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; | 411 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; |
354 if (!EnsurePeerConnectionFactory()) { | 412 if (!EnsurePeerConnectionFactory()) { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 | 961 |
904 if (!capturer->Initialize( | 962 if (!capturer->Initialize( |
905 render_view_id, | 963 render_view_id, |
906 static_cast<media::ChannelLayout>( | 964 static_cast<media::ChannelLayout>( |
907 device_info.device.input.channel_layout), | 965 device_info.device.input.channel_layout), |
908 device_info.device.input.sample_rate, | 966 device_info.device.input.sample_rate, |
909 device_info.device.input.frames_per_buffer, | 967 device_info.device.input.frames_per_buffer, |
910 device_info.session_id, | 968 device_info.session_id, |
911 device_info.device.id, | 969 device_info.device.id, |
912 device_info.device.matched_output.sample_rate, | 970 device_info.device.matched_output.sample_rate, |
913 device_info.device.matched_output.frames_per_buffer)) { | 971 device_info.device.matched_output.frames_per_buffer, |
972 device_info.device.input.effects)) { | |
914 return NULL; | 973 return NULL; |
915 } | 974 } |
916 | 975 |
917 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. | 976 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. |
918 if (is_new_capturer) | 977 if (is_new_capturer) |
919 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); | 978 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); |
920 | 979 |
921 return capturer; | 980 return capturer; |
922 } | 981 } |
923 | 982 |
(...skipping 28 matching lines...) Expand all Loading... | |
952 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( | 1011 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( |
953 const blink::WebMediaStreamTrack& track) { | 1012 const blink::WebMediaStreamTrack& track) { |
954 if (track.isNull()) | 1013 if (track.isNull()) |
955 return NULL; | 1014 return NULL; |
956 MediaStreamTrackExtraData* extra_data = | 1015 MediaStreamTrackExtraData* extra_data = |
957 static_cast<MediaStreamTrackExtraData*>(track.extraData()); | 1016 static_cast<MediaStreamTrackExtraData*>(track.extraData()); |
958 return extra_data ? extra_data->track().get() : NULL; | 1017 return extra_data ? extra_data->track().get() : NULL; |
959 } | 1018 } |
960 | 1019 |
961 } // namespace content | 1020 } // namespace content |
OLD | NEW |