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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 web_stream->videoTracks(video_tracks); | 298 web_stream->videoTracks(video_tracks); |
299 for (size_t i = 0; i < video_tracks.size(); ++i) { | 299 for (size_t i = 0; i < video_tracks.size(); ++i) { |
300 const blink::WebMediaStreamSource& source = video_tracks[i].source(); | 300 const blink::WebMediaStreamSource& source = video_tracks[i].source(); |
301 MediaStreamSourceExtraData* source_data = | 301 MediaStreamSourceExtraData* source_data = |
302 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 302 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
303 | 303 |
304 // Check if the source has already been created. This happens when the same | 304 // Check if the source has already been created. This happens when the same |
305 // source is used in multiple MediaStreams as a result of calling | 305 // source is used in multiple MediaStreams as a result of calling |
306 // getUserMedia. | 306 // getUserMedia. |
307 if (source_data->video_source()) | 307 if (source_data->video_source()) |
308 continue; | 308 continue; |
perkj_chrome
2014/01/12 21:53:06
indentation
no longer working on chromium
2014/01/13 16:59:59
Done.
| |
309 | 309 |
310 const bool is_screencast = | 310 const bool is_screencast = |
311 source_data->device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || | 311 source_data->device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || |
312 source_data->device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 312 source_data->device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE; |
313 source_data->SetVideoSource( | 313 source_data->SetVideoSource( |
314 CreateLocalVideoSource(source_data->device_info().session_id, | 314 CreateLocalVideoSource(source_data->device_info().session_id, |
315 is_screencast, | 315 is_screencast, |
316 &native_video_constraints).get()); | 316 &native_video_constraints).get()); |
317 source_observer->AddSource(source_data->video_source()); | 317 source_observer->AddSource(source_data->video_source()); |
318 } | 318 } |
(...skipping 41 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 | 448 |
449 scoped_refptr<WebAudioCapturerSource> webaudio_source; | 449 scoped_refptr<WebAudioCapturerSource> webaudio_source; |
450 if (!source_data) { | 450 if (!source_data) { |
451 if (source.requiresAudioConsumer()) { | 451 if (source.requiresAudioConsumer()) { |
452 // We're adding a WebAudio MediaStream. | 452 // We're adding a WebAudio MediaStream. |
453 // Create a specific capturer for each WebAudio consumer. | 453 // Create a specific capturer for each WebAudio consumer. |
454 webaudio_source = CreateWebAudioSource(&source, &track_constraints); | 454 webaudio_source = CreateWebAudioSource(&source, &track_constraints); |
455 source_data = | 455 source_data = |
456 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 456 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
457 } else { | 457 } else { |
458 // TODO(xians): Check with perkj on if this comment is valid. | |
perkj_chrome
2014/01/12 21:53:06
Yes. CreateNativeAudioMediaStreamTrack is called w
no longer working on chromium
2014/01/13 16:59:59
Done with removing the TODO. Good to know, thanks.
| |
458 // TODO(perkj): Implement support for sources from | 459 // TODO(perkj): Implement support for sources from |
459 // remote MediaStreams. | 460 // remote MediaStreams. |
460 NOTIMPLEMENTED(); | 461 NOTIMPLEMENTED(); |
461 return NULL; | 462 return NULL; |
462 } | 463 } |
463 } | 464 } |
464 | 465 |
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( | 466 scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
471 CreateLocalAudioTrack(track_id, | 467 CreateLocalAudioTrack(base::UTF16ToUTF8(track.id()), |
472 capturer, | 468 source_data->GetAudioCapturer(), |
473 webaudio_source.get(), | 469 webaudio_source.get(), |
474 source_data->local_audio_source(), | 470 source_data->local_audio_source(), |
475 &track_constraints)); | 471 &track_constraints)); |
476 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); | 472 AddNativeTrackToBlinkTrack(audio_track.get(), track, true); |
477 | 473 |
478 audio_track->set_enabled(track.isEnabled()); | 474 audio_track->set_enabled(track.isEnabled()); |
479 | 475 |
480 // Pass the pointer of the source provider to the blink audio track. | 476 // Pass the pointer of the source provider to the blink audio track. |
481 blink::WebMediaStreamTrack writable_track = track; | 477 blink::WebMediaStreamTrack writable_track = track; |
482 writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>( | 478 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 | 919 // processed before returning. We wait for the above task to finish before |
924 // letting the the function continue to avoid any potential race issues. | 920 // letting the the function continue to avoid any potential race issues. |
925 chrome_worker_thread_.Stop(); | 921 chrome_worker_thread_.Stop(); |
926 } else { | 922 } else { |
927 NOTREACHED() << "Worker thread not running."; | 923 NOTREACHED() << "Worker thread not running."; |
928 } | 924 } |
929 } | 925 } |
930 } | 926 } |
931 | 927 |
932 scoped_refptr<WebRtcAudioCapturer> | 928 scoped_refptr<WebRtcAudioCapturer> |
933 MediaStreamDependencyFactory::MaybeCreateAudioCapturer( | 929 MediaStreamDependencyFactory::CreateAudioCapturer( |
934 int render_view_id, | 930 int render_view_id, |
935 const StreamDeviceInfo& device_info) { | 931 const StreamDeviceInfo& device_info) { |
936 // TODO(xians): Handle the cases when gUM is called without a proper render | 932 // TODO(xians): Handle the cases when gUM is called without a proper render |
937 // view, for example, by an extension. | 933 // view, for example, by an extension. |
938 DCHECK_GE(render_view_id, 0); | 934 DCHECK_GE(render_view_id, 0); |
939 | 935 |
940 scoped_refptr<WebRtcAudioCapturer> capturer = | 936 scoped_refptr<WebRtcAudioCapturer> capturer = |
941 GetWebRtcAudioDevice()->GetDefaultCapturer(); | 937 WebRtcAudioCapturer::CreateCapturer(render_view_id, device_info); |
942 | 938 |
943 // If the default capturer does not exist or |render_view_id| == -1, create | 939 // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware |
944 // a new capturer. | 940 // information from the capturer. |
945 bool is_new_capturer = false; | 941 if (capturer) |
perkj_chrome
2014/01/12 21:53:06
Can capturer be null?
no longer working on chromium
2014/01/13 16:59:59
Yes, CreateCapturer will return a NULL if it fails
| |
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); | 942 GetWebRtcAudioDevice()->AddAudioCapturer(capturer); |
perkj_chrome
2014/01/12 21:53:06
Rename method to SetAudioCapturer if there can be
no longer working on chromium
2014/01/13 16:59:59
A couple of days ago I landed a workaround to fix
| |
968 | 943 |
969 return capturer; | 944 return capturer; |
970 } | 945 } |
971 | 946 |
972 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( | 947 void MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack( |
973 webrtc::MediaStreamTrackInterface* native_track, | 948 webrtc::MediaStreamTrackInterface* native_track, |
974 const blink::WebMediaStreamTrack& webkit_track, | 949 const blink::WebMediaStreamTrack& webkit_track, |
975 bool is_local_track) { | 950 bool is_local_track) { |
976 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); | 951 DCHECK(!webkit_track.isNull() && !webkit_track.extraData()); |
977 blink::WebMediaStreamTrack track = webkit_track; | 952 blink::WebMediaStreamTrack track = webkit_track; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1043 if (!aec_dump_file_stream) { | 1018 if (!aec_dump_file_stream) { |
1044 VLOG(1) << "Could not open AEC dump file."; | 1019 VLOG(1) << "Could not open AEC dump file."; |
1045 base::ClosePlatformFile(aec_dump_file); | 1020 base::ClosePlatformFile(aec_dump_file); |
1046 } else { | 1021 } else { |
1047 // |pc_factory_| takes ownership of |aec_dump_file_stream|. | 1022 // |pc_factory_| takes ownership of |aec_dump_file_stream|. |
1048 pc_factory_->StartAecDump(aec_dump_file_stream); | 1023 pc_factory_->StartAecDump(aec_dump_file_stream); |
1049 } | 1024 } |
1050 } | 1025 } |
1051 | 1026 |
1052 } // namespace content | 1027 } // namespace content |
OLD | NEW |