create_modular_peer_connection_factory.cc (1609B)
1 /* 2 * Copyright 2025 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "api/create_modular_peer_connection_factory.h" 12 13 #include <utility> 14 15 #include "api/peer_connection_interface.h" 16 #include "api/scoped_refptr.h" 17 #include "api/sequence_checker.h" 18 #include "pc/peer_connection_factory.h" 19 #include "pc/peer_connection_factory_proxy.h" 20 #include "rtc_base/thread.h" 21 22 namespace webrtc { 23 24 scoped_refptr<PeerConnectionFactoryInterface> 25 CreateModularPeerConnectionFactory( 26 PeerConnectionFactoryDependencies dependencies) { 27 // The PeerConnectionFactory must be created on the signaling thread. 28 if (dependencies.signaling_thread && 29 !dependencies.signaling_thread->IsCurrent()) { 30 return dependencies.signaling_thread->BlockingCall([&dependencies] { 31 return CreateModularPeerConnectionFactory(std::move(dependencies)); 32 }); 33 } 34 35 auto pc_factory = PeerConnectionFactory::Create(std::move(dependencies)); 36 if (!pc_factory) { 37 return nullptr; 38 } 39 // Verify that the invocation and the initialization ended up agreeing on the 40 // thread. 41 RTC_DCHECK_RUN_ON(pc_factory->signaling_thread()); 42 return PeerConnectionFactoryProxy::Create( 43 pc_factory->signaling_thread(), pc_factory->worker_thread(), pc_factory); 44 } 45 46 } // namespace webrtc