blob: c32d7d2e11c8927e1294074705af9e02a2492a67 [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
Harald Alvestrand98462622019-01-30 14:57:03 +010016#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
21namespace webrtc {
22
23namespace {
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.
28class IceTransportWithTransportChannel : public IceTransportInterface {
29 public:
30 IceTransportWithTransportChannel(
31 std::unique_ptr<cricket::IceTransportInternal> internal)
32 : internal_(std::move(internal)) {}
33
34 ~IceTransportWithTransportChannel() override {
35 RTC_DCHECK_RUN_ON(&thread_checker_);
36 }
37
38 cricket::IceTransportInternal* internal() override {
39 RTC_DCHECK_RUN_ON(&thread_checker_);
40 return internal_.get();
41 }
42
43 private:
Raphael Kubo da Costa448c3872019-02-13 10:17:50 +010044 const rtc::ThreadChecker thread_checker_{};
Harald Alvestrand98462622019-01-30 14:57:03 +010045 const std::unique_ptr<cricket::IceTransportInternal> internal_
46 RTC_GUARDED_BY(thread_checker_);
47};
48
49} // namespace
50
51rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
52 cricket::PortAllocator* port_allocator) {
Steve Anton6fdfec12019-07-01 14:07:33 -070053 IceTransportInit init;
54 init.set_port_allocator(port_allocator);
55 return CreateIceTransport(std::move(init));
56}
57
58rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
59 IceTransportInit init) {
Harald Alvestrand98462622019-01-30 14:57:03 +010060 return new rtc::RefCountedObject<IceTransportWithTransportChannel>(
Mirko Bonadei317a1f02019-09-17 17:06:18 +020061 std::make_unique<cricket::P2PTransportChannel>(
Steve Anton6fdfec12019-07-01 14:07:33 -070062 "", 0, init.port_allocator(), init.async_resolver_factory(),
63 init.event_log()));
Harald Alvestrand98462622019-01-30 14:57:03 +010064}
65
66} // namespace webrtc