blob: 6cc399aef744b8f128fd2c4a052bdb0c7bc50f82 [file] [log] [blame]
Harald Alvestrand98462622019-01-30 14:57:03 +01001/*
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 "absl/memory/memory.h"
17#include "p2p/base/ice_transport_internal.h"
18#include "p2p/base/p2p_transport_channel.h"
19#include "p2p/base/port_allocator.h"
20#include "rtc_base/thread.h"
21
22namespace webrtc {
23
24namespace {
25
26// This implementation of IceTransportInterface is used in cases where
27// the only reference to the P2PTransport will be through this class.
28// It must be constructed, accessed and destroyed on the signaling thread.
29class IceTransportWithTransportChannel : public IceTransportInterface {
30 public:
31 IceTransportWithTransportChannel(
32 std::unique_ptr<cricket::IceTransportInternal> internal)
33 : internal_(std::move(internal)) {}
34
35 ~IceTransportWithTransportChannel() override {
36 RTC_DCHECK_RUN_ON(&thread_checker_);
37 }
38
39 cricket::IceTransportInternal* internal() override {
40 RTC_DCHECK_RUN_ON(&thread_checker_);
41 return internal_.get();
42 }
43
44 private:
Raphael Kubo da Costa448c3872019-02-13 10:17:50 +010045 const rtc::ThreadChecker thread_checker_{};
Harald Alvestrand98462622019-01-30 14:57:03 +010046 const std::unique_ptr<cricket::IceTransportInternal> internal_
47 RTC_GUARDED_BY(thread_checker_);
48};
49
50} // namespace
51
52rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
53 cricket::PortAllocator* port_allocator) {
54 return new rtc::RefCountedObject<IceTransportWithTransportChannel>(
55 absl::make_unique<cricket::P2PTransportChannel>("", 0, port_allocator));
56}
57
58} // namespace webrtc