• 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 #ifndef P2P_BASE_DEFAULT_ICE_TRANSPORT_FACTORY_H_
12 #define P2P_BASE_DEFAULT_ICE_TRANSPORT_FACTORY_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "api/ice_transport_interface.h"
18 #include "p2p/base/p2p_transport_channel.h"
19 #include "rtc_base/thread.h"
20 
21 namespace webrtc {
22 
23 // The default ICE transport wraps the implementation of IceTransportInternal
24 // provided by P2PTransportChannel. This default transport is not thread safe
25 // and must be constructed, used and destroyed on the same network thread on
26 // which the internal P2PTransportChannel lives.
27 class DefaultIceTransport : public IceTransportInterface {
28  public:
29   explicit DefaultIceTransport(
30       std::unique_ptr<cricket::P2PTransportChannel> internal);
31   ~DefaultIceTransport();
32 
internal()33   cricket::IceTransportInternal* internal() override {
34     RTC_DCHECK_RUN_ON(&thread_checker_);
35     return internal_.get();
36   }
37 
38  private:
39   const rtc::ThreadChecker thread_checker_{};
40   std::unique_ptr<cricket::P2PTransportChannel> internal_
41       RTC_GUARDED_BY(thread_checker_);
42 };
43 
44 class DefaultIceTransportFactory : public IceTransportFactory {
45  public:
46   DefaultIceTransportFactory() = default;
47   ~DefaultIceTransportFactory() = default;
48 
49   // Must be called on the network thread and returns a DefaultIceTransport.
50   rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
51       const std::string& transport_name,
52       int component,
53       IceTransportInit init) override;
54 };
55 
56 }  // namespace webrtc
57 
58 #endif  // P2P_BASE_DEFAULT_ICE_TRANSPORT_FACTORY_H_
59