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 | |
81 // Merge |constraints| with |kDefaultAudioConstraints|. For any key which exists | 90 // Merge |constraints| with |kDefaultAudioConstraints|. For any key which exists |
82 // in both, the value from |constraints| is maintained, including its | 91 // in both, the value from |constraints| is maintained, including its |
83 // mandatory/optional status. New values from |kDefaultAudioConstraints| will | 92 // mandatory/optional status. New values from |kDefaultAudioConstraints| will |
84 // be added with mandatory status. | 93 // be added with mandatory status. |
85 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { | 94 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
86 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
87 bool already_set_value; | 96 bool already_set_value; |
88 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 97 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
89 &already_set_value, NULL)) { | 98 &already_set_value, NULL)) { |
90 constraints->AddMandatory(kDefaultAudioConstraints[i].key, | 99 constraints->AddMandatory(kDefaultAudioConstraints[i].key, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 325 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
317 | 326 |
318 // Check if the source has already been created. This happens when the same | 327 // 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 | 328 // source is used in multiple MediaStreams as a result of calling |
320 // getUserMedia. | 329 // getUserMedia. |
321 if (source_data->local_audio_source()) | 330 if (source_data->local_audio_source()) |
322 continue; | 331 continue; |
323 | 332 |
324 // TODO(xians): Create a new capturer for difference microphones when we | 333 // TODO(xians): Create a new capturer for difference microphones when we |
325 // support multiple microphones. See issue crbug/262117 . | 334 // support multiple microphones. See issue crbug/262117 . |
326 const StreamDeviceInfo device_info = source_data->device_info(); | 335 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 | |
327 scoped_refptr<WebRtcAudioCapturer> capturer( | 365 scoped_refptr<WebRtcAudioCapturer> capturer( |
328 MaybeCreateAudioCapturer(render_view_id, device_info)); | 366 MaybeCreateAudioCapturer(render_view_id, device_info)); |
329 if (!capturer.get()) { | 367 if (!capturer.get()) { |
330 DLOG(WARNING) << "Failed to create the capturer for device " | 368 DLOG(WARNING) << "Failed to create the capturer for device " |
331 << device_info.device.id; | 369 << device_info.device.id; |
332 sources_created.Run(web_stream, false); | 370 sources_created.Run(web_stream, false); |
333 // TODO(xians): Don't we need to check if source_observer is observing | 371 // 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. | 372 // something? If not, then it looks like we have a leak here. |
335 // OTOH, if it _is_ observing something, then the callback might | 373 // OTOH, if it _is_ observing something, then the callback might |
336 // be called multiple times which is likely also a bug. | 374 // be called multiple times which is likely also a bug. |
337 return; | 375 return; |
338 } | 376 } |
339 source_data->SetAudioCapturer(capturer); | 377 source_data->SetAudioCapturer(capturer); |
340 | 378 |
341 // Creates a LocalAudioSource object which holds audio options. | 379 // Creates a LocalAudioSource object which holds audio options. |
342 // TODO(xians): The option should apply to the track instead of the source. | 380 // TODO(xians): The option should apply to the track instead of the source. |
343 source_data->SetLocalAudioSource( | 381 source_data->SetLocalAudioSource( |
344 CreateLocalAudioSource(&native_audio_constraints).get()); | 382 CreateLocalAudioSource(&constraints).get()); |
no longer working on chromium
2013/12/30 14:55:56
you modify the constraints and save the change in
ajm
2014/01/08 01:35:02
We only need to update the constraints for paths w
| |
345 source_observer->AddSource(source_data->local_audio_source()); | 383 source_observer->AddSource(source_data->local_audio_source()); |
346 } | 384 } |
347 | 385 |
348 source_observer->StartObservering(); | 386 source_observer->StartObservering(); |
349 } | 387 } |
350 | 388 |
351 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( | 389 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( |
352 blink::WebMediaStream* web_stream) { | 390 blink::WebMediaStream* web_stream) { |
353 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; | 391 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; |
354 if (!EnsurePeerConnectionFactory()) { | 392 if (!EnsurePeerConnectionFactory()) { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 RTCMediaConstraints* constraints) { | 735 RTCMediaConstraints* constraints) { |
698 DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()"; | 736 DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()"; |
699 DCHECK(GetWebRtcAudioDevice()); | 737 DCHECK(GetWebRtcAudioDevice()); |
700 | 738 |
701 scoped_refptr<WebAudioCapturerSource> | 739 scoped_refptr<WebAudioCapturerSource> |
702 webaudio_capturer_source(new WebAudioCapturerSource()); | 740 webaudio_capturer_source(new WebAudioCapturerSource()); |
703 MediaStreamSourceExtraData* source_data = new MediaStreamSourceExtraData(); | 741 MediaStreamSourceExtraData* source_data = new MediaStreamSourceExtraData(); |
704 | 742 |
705 // Create a LocalAudioSource object which holds audio options. | 743 // Create a LocalAudioSource object which holds audio options. |
706 // SetLocalAudioSource() affects core audio parts in third_party/Libjingle. | 744 // SetLocalAudioSource() affects core audio parts in third_party/Libjingle. |
707 source_data->SetLocalAudioSource(CreateLocalAudioSource(constraints).get()); | 745 source_data->SetLocalAudioSource(CreateLocalAudioSource(constraints).get()); |
no longer working on chromium
2013/12/30 14:55:56
shouldn't you do the same thing for the case when
ajm
2014/01/08 01:35:02
Agreed, I believe we should update the constraints
tommi (sloooow) - chröme
2014/01/09 15:33:16
Yes. Ideally the constraints should be consistent
| |
708 source->setExtraData(source_data); | 746 source->setExtraData(source_data); |
709 | 747 |
710 // Replace the default source with WebAudio as source instead. | 748 // Replace the default source with WebAudio as source instead. |
711 source->addAudioConsumer(webaudio_capturer_source.get()); | 749 source->addAudioConsumer(webaudio_capturer_source.get()); |
712 | 750 |
713 return webaudio_capturer_source; | 751 return webaudio_capturer_source; |
714 } | 752 } |
715 | 753 |
716 scoped_refptr<webrtc::VideoTrackInterface> | 754 scoped_refptr<webrtc::VideoTrackInterface> |
717 MediaStreamDependencyFactory::CreateLocalVideoTrack( | 755 MediaStreamDependencyFactory::CreateLocalVideoTrack( |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 | 941 |
904 if (!capturer->Initialize( | 942 if (!capturer->Initialize( |
905 render_view_id, | 943 render_view_id, |
906 static_cast<media::ChannelLayout>( | 944 static_cast<media::ChannelLayout>( |
907 device_info.device.input.channel_layout), | 945 device_info.device.input.channel_layout), |
908 device_info.device.input.sample_rate, | 946 device_info.device.input.sample_rate, |
909 device_info.device.input.frames_per_buffer, | 947 device_info.device.input.frames_per_buffer, |
910 device_info.session_id, | 948 device_info.session_id, |
911 device_info.device.id, | 949 device_info.device.id, |
912 device_info.device.matched_output.sample_rate, | 950 device_info.device.matched_output.sample_rate, |
913 device_info.device.matched_output.frames_per_buffer)) { | 951 device_info.device.matched_output.frames_per_buffer, |
952 device_info.device.input.effects)) { | |
914 return NULL; | 953 return NULL; |
915 } | 954 } |
916 | 955 |
917 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. | 956 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. |
918 if (is_new_capturer) | 957 if (is_new_capturer) |
919 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); | 958 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); |
920 | 959 |
921 return capturer; | 960 return capturer; |
922 } | 961 } |
923 | 962 |
(...skipping 28 matching lines...) Expand all Loading... | |
952 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( | 991 MediaStreamDependencyFactory::GetNativeMediaStreamTrack( |
953 const blink::WebMediaStreamTrack& track) { | 992 const blink::WebMediaStreamTrack& track) { |
954 if (track.isNull()) | 993 if (track.isNull()) |
955 return NULL; | 994 return NULL; |
956 MediaStreamTrackExtraData* extra_data = | 995 MediaStreamTrackExtraData* extra_data = |
957 static_cast<MediaStreamTrackExtraData*>(track.extraData()); | 996 static_cast<MediaStreamTrackExtraData*>(track.extraData()); |
958 return extra_data ? extra_data->track().get() : NULL; | 997 return extra_data ? extra_data->track().get() : NULL; |
959 } | 998 } |
960 | 999 |
961 } // namespace content | 1000 } // namespace content |
OLD | NEW |