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