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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 P2PSocketDispatcher* p2p_socket_dispatcher) | 165 P2PSocketDispatcher* p2p_socket_dispatcher) |
166 : network_manager_(NULL), | 166 : network_manager_(NULL), |
167 p2p_socket_dispatcher_(p2p_socket_dispatcher), | 167 p2p_socket_dispatcher_(p2p_socket_dispatcher), |
168 signaling_thread_(NULL), | 168 signaling_thread_(NULL), |
169 worker_thread_(NULL), | 169 worker_thread_(NULL), |
170 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { | 170 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { |
171 } | 171 } |
172 | 172 |
173 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() { | 173 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() { |
174 CleanupPeerConnectionFactory(); | 174 CleanupPeerConnectionFactory(); |
| 175 if (aec_dump_message_filter_) |
| 176 aec_dump_message_filter_->RemoveDelegate(this); |
175 } | 177 } |
176 | 178 |
177 blink::WebRTCPeerConnectionHandler* | 179 blink::WebRTCPeerConnectionHandler* |
178 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler( | 180 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler( |
179 blink::WebRTCPeerConnectionHandlerClient* client) { | 181 blink::WebRTCPeerConnectionHandlerClient* client) { |
180 // Save histogram data so we can see how much PeerConnetion is used. | 182 // Save histogram data so we can see how much PeerConnetion is used. |
181 // The histogram counts the number of calls to the JS API | 183 // The histogram counts the number of calls to the JS API |
182 // webKitRTCPeerConnection. | 184 // webKitRTCPeerConnection. |
183 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION); | 185 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION); |
184 | 186 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 decoder_factory.release())); | 342 decoder_factory.release())); |
341 CHECK(factory); | 343 CHECK(factory); |
342 | 344 |
343 pc_factory_ = factory; | 345 pc_factory_ = factory; |
344 webrtc::PeerConnectionFactoryInterface::Options factory_options; | 346 webrtc::PeerConnectionFactoryInterface::Options factory_options; |
345 factory_options.disable_sctp_data_channels = false; | 347 factory_options.disable_sctp_data_channels = false; |
346 factory_options.disable_encryption = | 348 factory_options.disable_encryption = |
347 cmd_line->HasSwitch(switches::kDisableWebRtcEncryption); | 349 cmd_line->HasSwitch(switches::kDisableWebRtcEncryption); |
348 pc_factory_->SetOptions(factory_options); | 350 pc_factory_->SetOptions(factory_options); |
349 | 351 |
350 // |aec_dump_file| will be invalid when dump is not enabled. | 352 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing |
351 if (aec_dump_file_.IsValid()) | 353 // is removed. |
352 StartAecDump(aec_dump_file_.Pass()); | 354 if (!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) { |
| 355 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); |
| 356 // In unit tests not creating a message filter, |aec_dump_message_filter_| |
| 357 // will be NULL. We can just ignore that. Other unit tests and browser tests |
| 358 // ensure that we do get the filter when we should. |
| 359 if (aec_dump_message_filter_) |
| 360 aec_dump_message_filter_->AddDelegate(this); |
| 361 } |
353 } | 362 } |
354 | 363 |
355 bool PeerConnectionDependencyFactory::PeerConnectionFactoryCreated() { | 364 bool PeerConnectionDependencyFactory::PeerConnectionFactoryCreated() { |
356 return pc_factory_.get() != NULL; | 365 return pc_factory_.get() != NULL; |
357 } | 366 } |
358 | 367 |
359 scoped_refptr<webrtc::PeerConnectionInterface> | 368 scoped_refptr<webrtc::PeerConnectionInterface> |
360 PeerConnectionDependencyFactory::CreatePeerConnection( | 369 PeerConnectionDependencyFactory::CreatePeerConnection( |
361 const webrtc::PeerConnectionInterface::IceServers& ice_servers, | 370 const webrtc::PeerConnectionInterface::IceServers& ice_servers, |
362 const webrtc::MediaConstraintsInterface* constraints, | 371 const webrtc::MediaConstraintsInterface* constraints, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 static_cast<webrtc::AudioTrackInterface*>(native_track), | 614 static_cast<webrtc::AudioTrackInterface*>(native_track), |
606 is_local_track)); | 615 is_local_track)); |
607 } | 616 } |
608 | 617 |
609 scoped_refptr<base::MessageLoopProxy> | 618 scoped_refptr<base::MessageLoopProxy> |
610 PeerConnectionDependencyFactory::GetWebRtcWorkerThread() const { | 619 PeerConnectionDependencyFactory::GetWebRtcWorkerThread() const { |
611 DCHECK(CalledOnValidThread()); | 620 DCHECK(CalledOnValidThread()); |
612 return chrome_worker_thread_.message_loop_proxy(); | 621 return chrome_worker_thread_.message_loop_proxy(); |
613 } | 622 } |
614 | 623 |
615 bool PeerConnectionDependencyFactory::OnControlMessageReceived( | 624 void PeerConnectionDependencyFactory::OnAecDumpFile( |
616 const IPC::Message& message) { | 625 const IPC::PlatformFileForTransit& file_handle) { |
617 bool handled = true; | 626 DCHECK(CalledOnValidThread()); |
618 IPC_BEGIN_MESSAGE_MAP(PeerConnectionDependencyFactory, message) | 627 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()); |
619 IPC_MESSAGE_HANDLER(MediaStreamMsg_EnableAecDump, OnAecDumpFile) | 628 DCHECK(PeerConnectionFactoryCreated()); |
620 IPC_MESSAGE_HANDLER(MediaStreamMsg_DisableAecDump, OnDisableAecDump) | |
621 IPC_MESSAGE_UNHANDLED(handled = false) | |
622 IPC_END_MESSAGE_MAP() | |
623 return handled; | |
624 } | |
625 | 629 |
626 void PeerConnectionDependencyFactory::OnAecDumpFile( | |
627 IPC::PlatformFileForTransit file_handle) { | |
628 DCHECK(!aec_dump_file_.IsValid()); | |
629 base::File file = IPC::PlatformFileForTransitToFile(file_handle); | 630 base::File file = IPC::PlatformFileForTransitToFile(file_handle); |
630 DCHECK(file.IsValid()); | 631 DCHECK(file.IsValid()); |
631 | 632 |
632 if (MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) { | 633 // |pc_factory_| always takes ownership of |aec_dump_file|. If StartAecDump() |
633 EnsureWebRtcAudioDeviceImpl(); | 634 // fails, |aec_dump_file| will be closed. |
634 GetWebRtcAudioDevice()->EnableAecDump(file.Pass()); | 635 if (!GetPcFactory()->StartAecDump(file.TakePlatformFile())) |
635 return; | 636 VLOG(1) << "Could not start AEC dump."; |
636 } | |
637 | |
638 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing | |
639 // is removed. | |
640 if (PeerConnectionFactoryCreated()) | |
641 StartAecDump(file.Pass()); | |
642 else | |
643 aec_dump_file_ = file.Pass(); | |
644 } | 637 } |
645 | 638 |
646 void PeerConnectionDependencyFactory::OnDisableAecDump() { | 639 void PeerConnectionDependencyFactory::OnDisableAecDump() { |
647 if (MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) { | 640 DCHECK(CalledOnValidThread()); |
648 // Do nothing if OnAecDumpFile() has never been called. | 641 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()); |
649 if (GetWebRtcAudioDevice()) | 642 // Do nothing. We never disable AEC dump for non-track-processing case. |
650 GetWebRtcAudioDevice()->DisableAecDump(); | |
651 return; | |
652 } | |
653 | |
654 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing | |
655 // is removed. | |
656 if (aec_dump_file_.IsValid()) | |
657 aec_dump_file_.Close(); | |
658 } | 643 } |
659 | 644 |
660 void PeerConnectionDependencyFactory::StartAecDump(base::File aec_dump_file) { | 645 void PeerConnectionDependencyFactory::OnIpcClosing() { |
661 // |pc_factory_| always takes ownership of |aec_dump_file|. If StartAecDump() | 646 DCHECK(CalledOnValidThread()); |
662 // fails, |aec_dump_file| will be closed. | 647 aec_dump_message_filter_ = NULL; |
663 if (!GetPcFactory()->StartAecDump(aec_dump_file.TakePlatformFile())) | |
664 VLOG(1) << "Could not start AEC dump."; | |
665 } | 648 } |
666 | 649 |
667 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { | 650 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { |
668 if (audio_device_) | 651 if (audio_device_) |
669 return; | 652 return; |
670 | 653 |
671 audio_device_ = new WebRtcAudioDeviceImpl(); | 654 audio_device_ = new WebRtcAudioDeviceImpl(); |
672 } | 655 } |
673 | 656 |
674 } // namespace content | 657 } // namespace content |
OLD | NEW |