OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 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 WEBRTC_API_ORTCFACTORY_H_ |
| 12 #define WEBRTC_API_ORTCFACTORY_H_ |
| 13 |
| 14 #include <memory> |
| 15 |
| 16 #include "webrtc/api/udptransportinterface.h" |
| 17 #include "webrtc/base/network.h" |
| 18 #include "webrtc/base/thread.h" |
| 19 #include "webrtc/p2p/base/packetsocketfactory.h" |
| 20 |
| 21 namespace webrtc { |
| 22 |
| 23 // WARNING: This is experimental/under development, so use at your own risk; no |
| 24 // guarantee about API stability is guaranteed here yet. |
| 25 // |
| 26 // This class is the ORTC analog of PeerConnectionFactory. It acts as a factory |
| 27 // for ORTC objects that can be connected to each other. |
| 28 // |
| 29 // Some of these objects may not be represented by the ORTC specification, but |
| 30 // follow the same general principles. |
| 31 // |
| 32 // On object lifetimes: The factory should not be destroyed before destroying |
| 33 // the objects it created, and the objects passed into the factory should not |
| 34 // be destroyed before destroying the factory (since it doesn't take |
| 35 // ownership). |
| 36 class OrtcFactory { |
| 37 public: |
| 38 // |network_thread| is the thread on which packets are sent and received. |
| 39 // If null, a new rtc::Thread with a default socket server is created. |
| 40 // |
| 41 // |worker_thread| is used for CPU-intensive operations. |
| 42 // If null, a new rtc::Thread is created. |
| 43 // |
| 44 // |signaling_thread| is used for callbacks to the consumer of the API. If |
| 45 // null, the current thread will be used, which assumes that the API consumer |
| 46 // is running a message loop on this thread (either using an existing |
| 47 // rtc::Thread, or by calling rtc::Thread::Current()->ProcessMessages). |
| 48 // |
| 49 // |network_manager| is used to determine which network interfaces are |
| 50 // available. This is used for ICE, for example. If null, a default |
| 51 // implementation will be used. Only accessed on |network_thread|. |
| 52 // |
| 53 // |socket_factory| is used (on the network thread) for creating sockets. If |
| 54 // it's null, a default implementation will be used, which assumes |
| 55 // |network_thread| is a normal rtc::Thread. |
| 56 // |
| 57 // Note that the OrtcFactory does not take ownership of any of the objects |
| 58 // passed in. |
| 59 OrtcFactory(rtc::Thread* network_thread, |
| 60 rtc::Thread* worker_thread, |
| 61 rtc::Thread* signaling_thread, |
| 62 rtc::NetworkManager* network_manager, |
| 63 rtc::PacketSocketFactory* socket_factory); |
| 64 // Constructor for convenience which uses default implementations of |
| 65 // everything (though does still require that the current thread runs a |
| 66 // message loop; see above). |
| 67 OrtcFactory() : OrtcFactory(nullptr, nullptr, nullptr, nullptr, nullptr) {} |
| 68 ~OrtcFactory(); |
| 69 |
| 70 // Create a UDP transport with IP address family |family|, using a port |
| 71 // within the specified range. |
| 72 // |
| 73 // |family| must be AF_INET or AF_INET6. |
| 74 // |
| 75 // |min_port|/|max_port| values of 0 indicate no range restriction. |
| 76 // |
| 77 // Returns nullptr if the transport wasn't successfully created. |
| 78 std::unique_ptr<UdpTransportInterface> CreateUdpTransport(int family, |
| 79 uint16_t min_port, |
| 80 uint16_t max_port); |
| 81 // Method for convenience that has no port range restrictions. |
| 82 std::unique_ptr<UdpTransportInterface> CreateUdpTransport(int family) { |
| 83 return CreateUdpTransport(family, 0, 0); |
| 84 } |
| 85 |
| 86 private: |
| 87 rtc::Thread* network_thread_; |
| 88 rtc::Thread* worker_thread_; |
| 89 rtc::Thread* signaling_thread_; |
| 90 rtc::NetworkManager* network_manager_; |
| 91 rtc::PacketSocketFactory* socket_factory_; |
| 92 // Which of these objects do we own (we constructed a default implementation) |
| 93 // vs. were passed in? |
| 94 bool owns_network_thread_ = false; |
| 95 bool owns_worker_thread_ = false; |
| 96 bool wraps_signaling_thread_ = false; |
| 97 bool owns_network_manager_ = false; |
| 98 bool owns_socket_factory_ = false; |
| 99 }; |
| 100 |
| 101 } // namespace webrtc |
| 102 |
| 103 #endif // WEBRTC_API_ORTCFACTORY_H_ |
OLD | NEW |