| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 constraints.AddMandatory(kConstraintEffectMap[i].constraint, | 360 constraints.AddMandatory(kConstraintEffectMap[i].constraint, |
| 361 webrtc::MediaConstraintsInterface::kValueFalse, true); | 361 webrtc::MediaConstraintsInterface::kValueFalse, true); |
| 362 DVLOG(1) << "Disabling platform effect: " | 362 DVLOG(1) << "Disabling platform effect: " |
| 363 << kConstraintEffectMap[i].constraint; | 363 << kConstraintEffectMap[i].constraint; |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 device_info.device.input.effects = effects; | 366 device_info.device.input.effects = effects; |
| 367 } | 367 } |
| 368 | 368 |
| 369 scoped_refptr<WebRtcAudioCapturer> capturer( | 369 scoped_refptr<WebRtcAudioCapturer> capturer( |
| 370 MaybeCreateAudioCapturer(render_view_id, device_info)); | 370 CreateAudioCapturer(render_view_id, device_info)); |
| 371 if (!capturer.get()) { | 371 if (!capturer.get()) { |
| 372 DLOG(WARNING) << "Failed to create the capturer for device " | 372 DLOG(WARNING) << "Failed to create the capturer for device " |
| 373 << device_info.device.id; | 373 << device_info.device.id; |
| 374 sources_created.Run(web_stream, false); | 374 sources_created.Run(web_stream, false); |
| 375 // TODO(xians): Don't we need to check if source_observer is observing | 375 // TODO(xians): Don't we need to check if source_observer is observing |
| 376 // something? If not, then it looks like we have a leak here. | 376 // something? If not, then it looks like we have a leak here. |
| 377 // OTOH, if it _is_ observing something, then the callback might | 377 // OTOH, if it _is_ observing something, then the callback might |
| 378 // be called multiple times which is likely also a bug. | 378 // be called multiple times which is likely also a bug. |
| 379 return; | 379 return; |
| 380 } | 380 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 source_data = | 455 source_data = |
| 456 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 456 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
| 457 } else { | 457 } else { |
| 458 // TODO(perkj): Implement support for sources from | 458 // TODO(perkj): Implement support for sources from |
| 459 // remote MediaStreams. | 459 // remote MediaStreams. |
| 460 NOTIMPLEMENTED(); | 460 NOTIMPLEMENTED(); |
| 461 return NULL; | 461 return NULL; |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 std::string track_id = base::UTF16ToUTF8(track.id()); | |
| 466 scoped_refptr<WebRtcAudioCapturer> capturer; | |
| 467 if (GetWebRtcAudioDevice()) | |
| 468 capturer = GetWebRtcAudioDevice()->GetDefaultCapturer(); | |
| 469 | |
| 470 scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 465 scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 471 CreateLocalAudioTrack(track_id, | 466 CreateLocalAudioTrack(base::UTF16ToUTF8(track.id()), |
| 472 capturer, | 467 source_data->GetAudioCapturer(), |
| 473 webaudio_source.get(), | 468 webaudio_source.get(), |
| 474 source_data->local_audio_source(), | 469 source_data->local_audio_source(), |
| 475 &track_constraints)); | 470 &track_constraints)); |
| 476 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); | 471 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); |
| 477 | 472 |
| 478 audio_track->set_enabled(track.isEnabled()); | 473 audio_track->set_enabled(track.isEnabled()); |
| 479 | 474 |
| 480 // Pass the pointer of the source provider to the blink audio track. | 475 // Pass the pointer of the source provider to the blink audio track. |
| 481 blink::WebMediaStreamTrack writable_track = track; | 476 blink::WebMediaStreamTrack writable_track = track; |
| 482 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>( | 477 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>( |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 // processed before returning. We wait for the above task to finish before | 918 // processed before returning. We wait for the above task to finish before |
| 924 // letting the the function continue to avoid any potential race issues. | 919 // letting the the function continue to avoid any potential race issues. |
| 925 chrome_worker_thread_.Stop(); | 920 chrome_worker_thread_.Stop(); |
| 926 } else { | 921 } else { |
| 927 NOTREACHED() << "Worker thread not running."; | 922 NOTREACHED() << "Worker thread not running."; |
| 928 } | 923 } |
| 929 } | 924 } |
| 930 } | 925 } |
| 931 | 926 |
| 932 scoped_refptr<WebRtcAudioCapturer> | 927 scoped_refptr<WebRtcAudioCapturer> |
| 933 MediaStreamDependencyFactory::MaybeCreateAudioCapturer( | 928 MediaStreamDependencyFactory::CreateAudioCapturer( |
| 934 int render_view_id, | 929 int render_view_id, |
| 935 const StreamDeviceInfo& device_info) { | 930 const StreamDeviceInfo& device_info) { |
| 936 // TODO(xians): Handle the cases when gUM is called without a proper render | 931 // TODO(xians): Handle the cases when gUM is called without a proper render |
| 937 // view, for example, by an extension. | 932 // view, for example, by an extension. |
| 938 DCHECK_GE(render_view_id, 0); | 933 DCHECK_GE(render_view_id, 0); |
| 939 | 934 |
| 940 scoped_refptr<WebRtcAudioCapturer> capturer = | 935 return WebRtcAudioCapturer::CreateCapturer(render_view_id, device_info, |
| 941 GetWebRtcAudioDevice()->GetDefaultCapturer(); | 936 GetWebRtcAudioDevice()); |
| 942 | |
| 943 // If the default capturer does not exist or |render_view_id| == -1, create | |
| 944 // a new capturer. | |
| 945 bool is_new_capturer = false; | |
| 946 if (!capturer.get()) { | |
| 947 capturer = WebRtcAudioCapturer::CreateCapturer(); | |
| 948 is_new_capturer = true; | |
| 949 } | |
| 950 | |
| 951 if (!capturer->Initialize( | |
| 952 render_view_id, | |
| 953 static_cast<media::ChannelLayout>( | |
| 954 device_info.device.input.channel_layout), | |
| 955 device_info.device.input.sample_rate, | |
| 956 device_info.device.input.frames_per_buffer, | |
| 957 device_info.session_id, | |
| 958 device_info.device.id, | |
| 959 device_info.device.matched_output.sample_rate, | |
| 960 device_info.device.matched_output.frames_per_buffer, | |
| 961 device_info.device.input.effects)) { | |
| 962 return NULL; | |
| 963 } | |
| 964 | |
| 965 // Add the capturer to the WebRtcAudioDeviceImpl if it is a new capturer. | |
| 966 if (is_new_capturer) | |
| 967 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); | |
| 968 | |
| 969 return capturer; | |
| 970 } | 937 } |
| 971 | 938 |
| 972 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( | 939 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( |
| 973 webrtc::MediaStreamTrackInterface* native_track, | 940 webrtc::MediaStreamTrackInterface* native_track, |
| 974 const blink::WebMediaStreamTrack& webkit_track, | 941 const blink::WebMediaStreamTrack& webkit_track, |
| 975 bool is_local_track) { | 942 bool is_local_track) { |
| 976 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); | 943 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); |
| 977 blink::WebMediaStreamTrack track = webkit_track; | 944 blink::WebMediaStreamTrack track = webkit_track; |
| 978 | 945 |
| 979 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { | 946 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 if (!aec_dump_file_stream) { | 1010 if (!aec_dump_file_stream) { |
| 1044 VLOG(1) << "Could not open AEC dump file."; | 1011 VLOG(1) << "Could not open AEC dump file."; |
| 1045 base::ClosePlatformFile(aec_dump_file); | 1012 base::ClosePlatformFile(aec_dump_file); |
| 1046 } else { | 1013 } else { |
| 1047 // |pc_factory_| takes ownership of |aec_dump_file_stream|. | 1014 // |pc_factory_| takes ownership of |aec_dump_file_stream|. |
| 1048 pc_factory_->StartAecDump(aec_dump_file_stream); | 1015 pc_factory_->StartAecDump(aec_dump_file_stream); |
| 1049 } | 1016 } |
| 1050 } | 1017 } |
| 1051 | 1018 |
| 1052 } // namespace content | 1019 } // namespace content |
| OLD | NEW |