Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 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 | |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 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: |
| 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 Costa | 448c387 | 2019-02-13 09:17:50 | [diff] [blame] | 44 | const rtc::ThreadChecker thread_checker_{}; |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 45 | const std::unique_ptr<cricket::IceTransportInternal> internal_ |
| 46 | RTC_GUARDED_BY(thread_checker_); |
| 47 | }; |
| 48 | |
| 49 | } // namespace |
| 50 | |
| 51 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 52 | cricket::PortAllocator* port_allocator) { |
Steve Anton | 6fdfec1 | 2019-07-01 21:07:33 | [diff] [blame] | 53 | IceTransportInit init; |
| 54 | init.set_port_allocator(port_allocator); |
| 55 | return CreateIceTransport(std::move(init)); |
| 56 | } |
| 57 | |
| 58 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 59 | IceTransportInit init) { |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 60 | return new rtc::RefCountedObject<IceTransportWithTransportChannel>( |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 61 | std::make_unique<cricket::P2PTransportChannel>( |
Steve Anton | 6fdfec1 | 2019-07-01 21:07:33 | [diff] [blame] | 62 | "", 0, init.port_allocator(), init.async_resolver_factory(), |
| 63 | init.event_log())); |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace webrtc |