| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 { webrtc::MediaConstraintsInterface::kAutoGainControl, | 71 { webrtc::MediaConstraintsInterface::kAutoGainControl, |
| 72 webrtc::MediaConstraintsInterface::kValueTrue }, | 72 webrtc::MediaConstraintsInterface::kValueTrue }, |
| 73 { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, | 73 { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, |
| 74 webrtc::MediaConstraintsInterface::kValueTrue }, | 74 webrtc::MediaConstraintsInterface::kValueTrue }, |
| 75 { webrtc::MediaConstraintsInterface::kNoiseSuppression, | 75 { webrtc::MediaConstraintsInterface::kNoiseSuppression, |
| 76 webrtc::MediaConstraintsInterface::kValueTrue }, | 76 webrtc::MediaConstraintsInterface::kValueTrue }, |
| 77 { webrtc::MediaConstraintsInterface::kHighpassFilter, | 77 { webrtc::MediaConstraintsInterface::kHighpassFilter, |
| 78 webrtc::MediaConstraintsInterface::kValueTrue }, | 78 webrtc::MediaConstraintsInterface::kValueTrue }, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Map of corresponding media constraints and platform effects. | |
| 82 struct { | |
| 83 const char* constraint; | |
| 84 const media::AudioParameters::PlatformEffectsMask effect; | |
| 85 } const kConstraintEffectMap[] = { | |
| 86 { webrtc::MediaConstraintsInterface::kEchoCancellation, | |
| 87 media::AudioParameters::ECHO_CANCELLER}, | |
| 88 }; | |
| 89 | |
| 90 // Merge |constraints| with |kDefaultAudioConstraints|. For any key which exists | 81 // Merge |constraints| with |kDefaultAudioConstraints|. For any key which exists |
| 91 // in both, the value from |constraints| is maintained, including its | 82 // in both, the value from |constraints| is maintained, including its |
| 92 // mandatory/optional status. New values from |kDefaultAudioConstraints| will | 83 // mandatory/optional status. New values from |kDefaultAudioConstraints| will |
| 93 // be added with mandatory status. | 84 // be added with mandatory status. |
| 94 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { | 85 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
| 95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 86 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
| 96 bool already_set_value; | 87 bool already_set_value; |
| 97 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 88 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
| 98 &already_set_value, NULL)) { | 89 &already_set_value, NULL)) { |
| 99 constraints->AddMandatory(kDefaultAudioConstraints[i].key, | 90 constraints->AddMandatory(kDefaultAudioConstraints[i].key, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 316 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
| 326 | 317 |
| 327 // Check if the source has already been created. This happens when the same | 318 // Check if the source has already been created. This happens when the same |
| 328 // source is used in multiple MediaStreams as a result of calling | 319 // source is used in multiple MediaStreams as a result of calling |
| 329 // getUserMedia. | 320 // getUserMedia. |
| 330 if (source_data->local_audio_source()) | 321 if (source_data->local_audio_source()) |
| 331 continue; | 322 continue; |
| 332 | 323 |
| 333 // TODO(xians): Create a new capturer for difference microphones when we | 324 // TODO(xians): Create a new capturer for difference microphones when we |
| 334 // support multiple microphones. See issue crbug/262117 . | 325 // support multiple microphones. See issue crbug/262117 . |
| 335 StreamDeviceInfo device_info = source_data->device_info(); | 326 const StreamDeviceInfo device_info = source_data->device_info(); |
| 336 RTCMediaConstraints constraints = native_audio_constraints; | |
| 337 | |
| 338 // If any platform effects are available, check them against the | |
| 339 // constraints. Disable effects to match false constraints, but if a | |
| 340 // constraint is true, set the constraint to false to later disable the | |
| 341 // software effect. | |
| 342 int effects = device_info.device.input.effects; | |
| 343 if (effects != media::AudioParameters::NO_EFFECTS) { | |
| 344 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kConstraintEffectMap); ++i) { | |
| 345 bool value; | |
| 346 if (!webrtc::FindConstraint(&constraints, | |
| 347 kConstraintEffectMap[i].constraint, &value, NULL) || !value) { | |
| 348 // If the constraint is false, or does not exist, disable the platform | |
| 349 // effect. | |
| 350 effects &= ~kConstraintEffectMap[i].effect; | |
| 351 DVLOG(1) << "Disabling constraint: " | |
| 352 << kConstraintEffectMap[i].constraint; | |
| 353 } else if (effects & kConstraintEffectMap[i].effect) { | |
| 354 // If the constraint is true, leave the platform effect enabled, and | |
| 355 // set the constraint to false to later disable the software effect. | |
| 356 constraints.AddMandatory(kConstraintEffectMap[i].constraint, | |
| 357 webrtc::MediaConstraintsInterface::kValueFalse, true); | |
| 358 DVLOG(1) << "Disabling platform effect: " | |
| 359 << kConstraintEffectMap[i].constraint; | |
| 360 } | |
| 361 } | |
| 362 device_info.device.input.effects = effects; | |
| 363 } | |
| 364 | |
| 365 scoped_refptr<WebRtcAudioCapturer> capturer( | 327 scoped_refptr<WebRtcAudioCapturer> capturer( |
| 366 MaybeCreateAudioCapturer(render_view_id, device_info)); | 328 MaybeCreateAudioCapturer(render_view_id, device_info)); |
| 367 if (!capturer.get()) { | 329 if (!capturer.get()) { |
| 368 DLOG(WARNING) << "Failed to create the capturer for device " | 330 DLOG(WARNING) << "Failed to create the capturer for device " |
| 369 << device_info.device.id; | 331 << device_info.device.id; |
| 370 sources_created.Run(web_stream, false); | 332 sources_created.Run(web_stream, false); |
| 371 // TODO(xians): Don't we need to check if source_observer is observing | 333 // TODO(xians): Don't we need to check if source_observer is observing |
| 372 // something? If not, then it looks like we have a leak here. | 334 // something? If not, then it looks like we have a leak here. |
| 373 // OTOH, if it _is_ observing something, then the callback might | 335 // OTOH, if it _is_ observing something, then the callback might |
| 374 // be called multiple times which is likely also a bug. | 336 // be called multiple times which is likely also a bug. |
| 375 return; | 337 return; |
| 376 } | 338 } |
| 377 source_data->SetAudioCapturer(capturer); | 339 source_data->SetAudioCapturer(capturer); |
| 378 | 340 |
| 379 // Creates a LocalAudioSource object which holds audio options. | 341 // Creates a LocalAudioSource object which holds audio options. |
| 380 // TODO(xians): The option should apply to the track instead of the source. | 342 // TODO(xians): The option should apply to the track instead of the source. |
| 381 source_data->SetLocalAudioSource( | 343 source_data->SetLocalAudioSource( |
| 382 CreateLocalAudioSource(&constraints).get()); | 344 CreateLocalAudioSource(&native_audio_constraints).get()); |
| 383 source_observer->AddSource(source_data->local_audio_source()); | 345 source_observer->AddSource(source_data->local_audio_source()); |
| 384 } | 346 } |
| 385 | 347 |
| 386 source_observer->StartObservering(); | 348 source_observer->StartObservering(); |
| 387 } | 349 } |
| 388 | 350 |
| 389 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( | 351 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( |
| 390 blink::WebMediaStream* web_stream) { | 352 blink::WebMediaStream* web_stream) { |
| 391 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; | 353 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; |
| 392 if (!EnsurePeerConnectionFactory()) { | 354 if (!EnsurePeerConnectionFactory()) { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 | 903 |
| 942 if (!capturer->Initialize( | 904 if (!capturer->Initialize( |
| 943 render_view_id, | 905 render_view_id, |
| 944 static_cast<media::ChannelLayout>( | 906 static_cast<media::ChannelLayout>( |
| 945 device_info.device.input.channel_layout), | 907 device_info.device.input.channel_layout), |
| 946 device_info.device.input.sample_rate, | 908 device_info.device.input.sample_rate, |
| 947 device_info.device.input.frames_per_buffer, | 909 device_info.device.input.frames_per_buffer, |
| 948 device_info.session_id, | 910 device_info.session_id, |
| 949 device_info.device.id, | 911 device_info.device.id, |
| 950 device_info.device.matched_output.sample_rate, | 912 device_info.device.matched_output.sample_rate, |
| 951 device_info.device.matched_output.frames_per_buffer, | 913 device_info.device.matched_output.frames_per_buffer)) { |
| 952 device_info.device.input.effects)) { | |
| 953 return NULL; | 914 return NULL; |
| 954 } | 915 } |
| 955 | 916 |
| 956 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. | 917 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. |
| 957 if (is_new_capturer) | 918 if (is_new_capturer) |
| 958 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); | 919 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); |
| 959 | 920 |
| 960 return capturer; | 921 return capturer; |
| 961 } | 922 } |
| 962 | 923 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 991 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( | 952 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( |
| 992 const blink::WebMediaStreamTrack& track) { | 953 const blink::WebMediaStreamTrack& track) { |
| 993 if (track.isNull()) | 954 if (track.isNull()) |
| 994 return NULL; | 955 return NULL; |
| 995 MediaStreamTrackExtraData* extra_data = | 956 MediaStreamTrackExtraData* extra_data = |
| 996 static_cast<MediaStreamTrackExtraData*>(track.extraData()); | 957 static_cast<MediaStreamTrackExtraData*>(track.extraData()); |
| 997 return extra_data ? extra_data->track().get() : NULL; | 958 return extra_data ? extra_data->track().get() : NULL; |
| 998 } | 959 } |
| 999 | 960 |
| 1000 } // namespace content | 961 } // namespace content |
| OLD | NEW |