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