1 /* 2 * Copyright 2019 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/ice_transport_factory.h" 12 13 #include <memory> 14 #include <utility> 15 16 #include "api/make_ref_counted.h" 17 #include "p2p/base/ice_transport_internal.h" 18 #include "p2p/base/p2p_constants.h" 19 #include "p2p/base/p2p_transport_channel.h" 20 #include "p2p/base/port_allocator.h" 21 #include "rtc_base/thread.h" 22 23 namespace webrtc { 24 25 namespace { 26 27 // This implementation of IceTransportInterface is used in cases where 28 // the only reference to the P2PTransport will be through this class. 29 // It must be constructed, accessed and destroyed on the signaling thread. 30 class IceTransportWithTransportChannel : public IceTransportInterface { 31 public: IceTransportWithTransportChannel(std::unique_ptr<cricket::IceTransportInternal> internal)32 IceTransportWithTransportChannel( 33 std::unique_ptr<cricket::IceTransportInternal> internal) 34 : internal_(std::move(internal)) {} 35 ~IceTransportWithTransportChannel()36 ~IceTransportWithTransportChannel() override { 37 RTC_DCHECK_RUN_ON(&thread_checker_); 38 } 39 internal()40 cricket::IceTransportInternal* internal() override { 41 RTC_DCHECK_RUN_ON(&thread_checker_); 42 return internal_.get(); 43 } 44 45 private: 46 const SequenceChecker thread_checker_{}; 47 const std::unique_ptr<cricket::IceTransportInternal> internal_ 48 RTC_GUARDED_BY(thread_checker_); 49 }; 50 51 } // namespace 52 CreateIceTransport(cricket::PortAllocator * port_allocator)53rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( 54 cricket::PortAllocator* port_allocator) { 55 IceTransportInit init; 56 init.set_port_allocator(port_allocator); 57 return CreateIceTransport(std::move(init)); 58 } 59 CreateIceTransport(IceTransportInit init)60rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( 61 IceTransportInit init) { 62 return rtc::make_ref_counted<IceTransportWithTransportChannel>( 63 cricket::P2PTransportChannel::Create( 64 "", cricket::ICE_CANDIDATE_COMPONENT_RTP, std::move(init))); 65 } 66 67 } // namespace webrtc 68