| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc/peer_connection_dependency_factory.h" | 5 #include "content/renderer/media/webrtc/peer_connection_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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 : network_manager_(NULL), | 168 : network_manager_(NULL), |
| 169 p2p_socket_dispatcher_(p2p_socket_dispatcher), | 169 p2p_socket_dispatcher_(p2p_socket_dispatcher), |
| 170 signaling_thread_(NULL), | 170 signaling_thread_(NULL), |
| 171 worker_thread_(NULL), | 171 worker_thread_(NULL), |
| 172 chrome_signaling_thread_("Chrome_libJingle_Signaling"), | 172 chrome_signaling_thread_("Chrome_libJingle_Signaling"), |
| 173 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { | 173 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { |
| 174 } | 174 } |
| 175 | 175 |
| 176 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() { | 176 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() { |
| 177 CleanupPeerConnectionFactory(); | 177 CleanupPeerConnectionFactory(); |
| 178 if (aec_dump_message_filter_.get()) | |
| 179 aec_dump_message_filter_->RemoveDelegate(this); | |
| 180 } | 178 } |
| 181 | 179 |
| 182 blink::WebRTCPeerConnectionHandler* | 180 blink::WebRTCPeerConnectionHandler* |
| 183 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler( | 181 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler( |
| 184 blink::WebRTCPeerConnectionHandlerClient* client) { | 182 blink::WebRTCPeerConnectionHandlerClient* client) { |
| 185 // Save histogram data so we can see how much PeerConnetion is used. | 183 // Save histogram data so we can see how much PeerConnetion is used. |
| 186 // The histogram counts the number of calls to the JS API | 184 // The histogram counts the number of calls to the JS API |
| 187 // webKitRTCPeerConnection. | 185 // webKitRTCPeerConnection. |
| 188 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION); | 186 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION); |
| 189 | 187 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 net::EnsureNSSSSLInit(); | 314 net::EnsureNSSSSLInit(); |
| 317 #endif | 315 #endif |
| 318 | 316 |
| 319 base::WaitableEvent start_signaling_event(true, false); | 317 base::WaitableEvent start_signaling_event(true, false); |
| 320 chrome_signaling_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 318 chrome_signaling_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 321 &PeerConnectionDependencyFactory::InitializeSignalingThread, | 319 &PeerConnectionDependencyFactory::InitializeSignalingThread, |
| 322 base::Unretained(this), | 320 base::Unretained(this), |
| 323 RenderThreadImpl::current()->GetGpuFactories(), | 321 RenderThreadImpl::current()->GetGpuFactories(), |
| 324 &start_signaling_event)); | 322 &start_signaling_event)); |
| 325 | 323 |
| 326 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing | |
| 327 // is removed. | |
| 328 if (!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) { | |
| 329 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); | |
| 330 // In unit tests not creating a message filter, |aec_dump_message_filter_| | |
| 331 // will be NULL. We can just ignore that. Other unit tests and browser tests | |
| 332 // ensure that we do get the filter when we should. | |
| 333 if (aec_dump_message_filter_.get()) | |
| 334 aec_dump_message_filter_->AddDelegate(this); | |
| 335 } | |
| 336 | |
| 337 start_signaling_event.Wait(); | 324 start_signaling_event.Wait(); |
| 338 CHECK(signaling_thread_); | 325 CHECK(signaling_thread_); |
| 339 } | 326 } |
| 340 | 327 |
| 341 void PeerConnectionDependencyFactory::InitializeSignalingThread( | 328 void PeerConnectionDependencyFactory::InitializeSignalingThread( |
| 342 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories, | 329 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories, |
| 343 base::WaitableEvent* event) { | 330 base::WaitableEvent* event) { |
| 344 DCHECK(chrome_signaling_thread_.task_runner()->BelongsToCurrentThread()); | 331 DCHECK(chrome_signaling_thread_.task_runner()->BelongsToCurrentThread()); |
| 345 DCHECK(worker_thread_); | 332 DCHECK(worker_thread_); |
| 346 DCHECK(p2p_socket_dispatcher_.get()); | 333 DCHECK(p2p_socket_dispatcher_.get()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 456 |
| 470 StartLocalAudioTrack(audio_track.get()); | 457 StartLocalAudioTrack(audio_track.get()); |
| 471 | 458 |
| 472 // Pass the ownership of the native local audio track to the blink track. | 459 // Pass the ownership of the native local audio track to the blink track. |
| 473 blink::WebMediaStreamTrack writable_track = track; | 460 blink::WebMediaStreamTrack writable_track = track; |
| 474 writable_track.setExtraData(audio_track.release()); | 461 writable_track.setExtraData(audio_track.release()); |
| 475 } | 462 } |
| 476 | 463 |
| 477 void PeerConnectionDependencyFactory::StartLocalAudioTrack( | 464 void PeerConnectionDependencyFactory::StartLocalAudioTrack( |
| 478 WebRtcLocalAudioTrack* audio_track) { | 465 WebRtcLocalAudioTrack* audio_track) { |
| 479 // Add the WebRtcAudioDevice as the sink to the local audio track. | |
| 480 // TODO(xians): Remove the following line of code after the APM in WebRTC is | |
| 481 // completely deprecated. See http://crbug/365672. | |
| 482 if (!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) | |
| 483 audio_track->AddSink(GetWebRtcAudioDevice()); | |
| 484 | |
| 485 // Start the audio track. This will hook the |audio_track| to the capturer | 466 // Start the audio track. This will hook the |audio_track| to the capturer |
| 486 // as the sink of the audio, and only start the source of the capturer if | 467 // as the sink of the audio, and only start the source of the capturer if |
| 487 // it is the first audio track connecting to the capturer. | 468 // it is the first audio track connecting to the capturer. |
| 488 audio_track->Start(); | 469 audio_track->Start(); |
| 489 } | 470 } |
| 490 | 471 |
| 491 scoped_refptr<WebAudioCapturerSource> | 472 scoped_refptr<WebAudioCapturerSource> |
| 492 PeerConnectionDependencyFactory::CreateWebAudioSource( | 473 PeerConnectionDependencyFactory::CreateWebAudioSource( |
| 493 blink::WebMediaStreamSource* source) { | 474 blink::WebMediaStreamSource* source) { |
| 494 DVLOG(1) << "PeerConnectionDependencyFactory::CreateWebAudioSource()"; | 475 DVLOG(1) << "PeerConnectionDependencyFactory::CreateWebAudioSource()"; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 DCHECK(CalledOnValidThread()); | 606 DCHECK(CalledOnValidThread()); |
| 626 return chrome_worker_thread_.message_loop_proxy(); | 607 return chrome_worker_thread_.message_loop_proxy(); |
| 627 } | 608 } |
| 628 | 609 |
| 629 scoped_refptr<base::MessageLoopProxy> | 610 scoped_refptr<base::MessageLoopProxy> |
| 630 PeerConnectionDependencyFactory::GetWebRtcSignalingThread() const { | 611 PeerConnectionDependencyFactory::GetWebRtcSignalingThread() const { |
| 631 DCHECK(CalledOnValidThread()); | 612 DCHECK(CalledOnValidThread()); |
| 632 return chrome_signaling_thread_.message_loop_proxy(); | 613 return chrome_signaling_thread_.message_loop_proxy(); |
| 633 } | 614 } |
| 634 | 615 |
| 635 void PeerConnectionDependencyFactory::OnAecDumpFile( | |
| 636 const IPC::PlatformFileForTransit& file_handle) { | |
| 637 DCHECK(CalledOnValidThread()); | |
| 638 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()); | |
| 639 DCHECK(PeerConnectionFactoryCreated()); | |
| 640 | |
| 641 base::File file = IPC::PlatformFileForTransitToFile(file_handle); | |
| 642 DCHECK(file.IsValid()); | |
| 643 | |
| 644 // |pc_factory_| always takes ownership of |aec_dump_file|. If StartAecDump() | |
| 645 // fails, |aec_dump_file| will be closed. | |
| 646 if (!GetPcFactory()->StartAecDump(file.TakePlatformFile())) | |
| 647 DVLOG(1) << "Could not start AEC dump."; | |
| 648 } | |
| 649 | |
| 650 void PeerConnectionDependencyFactory::OnDisableAecDump() { | |
| 651 DCHECK(CalledOnValidThread()); | |
| 652 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()); | |
| 653 // Do nothing. We never disable AEC dump for non-track-processing case. | |
| 654 } | |
| 655 | |
| 656 void PeerConnectionDependencyFactory::OnIpcClosing() { | |
| 657 DCHECK(CalledOnValidThread()); | |
| 658 aec_dump_message_filter_ = NULL; | |
| 659 } | |
| 660 | |
| 661 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { | 616 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { |
| 662 if (audio_device_.get()) | 617 if (audio_device_.get()) |
| 663 return; | 618 return; |
| 664 | 619 |
| 665 audio_device_ = new WebRtcAudioDeviceImpl(); | 620 audio_device_ = new WebRtcAudioDeviceImpl(); |
| 666 } | 621 } |
| 667 | 622 |
| 668 } // namespace content | 623 } // namespace content |
| OLD | NEW |