Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [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 14:57:03 +0100 | [diff] [blame] | 16 | #include "p2p/base/ice_transport_internal.h" |
Philipp Hancke | 2f5f5fa | 2021-03-21 20:37:35 +0100 | [diff] [blame] | 17 | #include "p2p/base/p2p_constants.h" |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 18 | #include "p2p/base/p2p_transport_channel.h" |
| 19 | #include "p2p/base/port_allocator.h" |
| 20 | #include "rtc_base/thread.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | namespace { |
| 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. |
| 29 | class 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: |
Artem Titov | c8421c4 | 2021-02-02 10:57:19 +0100 | [diff] [blame] | 45 | const SequenceChecker thread_checker_{}; |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 46 | const std::unique_ptr<cricket::IceTransportInternal> internal_ |
| 47 | RTC_GUARDED_BY(thread_checker_); |
| 48 | }; |
| 49 | |
| 50 | } // namespace |
| 51 | |
| 52 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 53 | cricket::PortAllocator* port_allocator) { |
Steve Anton | 6fdfec1 | 2019-07-01 14:07:33 -0700 | [diff] [blame] | 54 | IceTransportInit init; |
| 55 | init.set_port_allocator(port_allocator); |
| 56 | return CreateIceTransport(std::move(init)); |
| 57 | } |
| 58 | |
| 59 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 60 | IceTransportInit init) { |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 61 | if (init.async_resolver_factory()) { |
| 62 | // Backwards compatibility mode |
Tomas Gunnarsson | c1d5891 | 2021-04-22 19:21:43 +0200 | [diff] [blame] | 63 | return rtc::make_ref_counted<IceTransportWithTransportChannel>( |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 64 | std::make_unique<cricket::P2PTransportChannel>( |
| 65 | "", cricket::ICE_CANDIDATE_COMPONENT_RTP, init.port_allocator(), |
| 66 | init.async_resolver_factory(), init.event_log())); |
| 67 | } else { |
Tomas Gunnarsson | c1d5891 | 2021-04-22 19:21:43 +0200 | [diff] [blame] | 68 | return rtc::make_ref_counted<IceTransportWithTransportChannel>( |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 69 | cricket::P2PTransportChannel::Create( |
| 70 | "", cricket::ICE_CANDIDATE_COMPONENT_RTP, init.port_allocator(), |
| 71 | init.async_dns_resolver_factory(), init.event_log())); |
| 72 | } |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } // namespace webrtc |