Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: webrtc/api/ortcfactory.cc

Issue 2632613002: Adding OrtcFactory, and changing UdpTransport to match current plan. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/ortcfactory.cc
diff --git a/webrtc/api/ortcfactory.cc b/webrtc/api/ortcfactory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef1b8e3b07c444b11b3ff9b6688f98f36e9a258e
--- /dev/null
+++ b/webrtc/api/ortcfactory.cc
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/api/ortcfactory.h"
+
+#include <string>
+#include <utility> // For std::move.
+
+#include "webrtc/base/bind.h"
+#include "webrtc/base/asyncpacketsocket.h"
+#include "webrtc/p2p/base/basicpacketsocketfactory.h"
+#include "webrtc/p2p/base/udptransportchannel.h"
+
+namespace webrtc {
+
+OrtcFactory::OrtcFactory(rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ rtc::NetworkManager* network_manager,
+ rtc::PacketSocketFactory* socket_factory)
+ : network_thread_(network_thread),
+ worker_thread_(worker_thread),
+ signaling_thread_(signaling_thread),
+ network_manager_(network_manager),
+ socket_factory_(socket_factory) {
+ if (!network_thread_) {
+ network_thread_ = rtc::Thread::CreateWithSocketServer().release();
+ network_thread_->Start();
+ owns_network_thread_ = true;
+ }
+ if (!worker_thread_) {
+ worker_thread_ = rtc::Thread::Create().release();
+ worker_thread_->Start();
+ owns_worker_thread_ = true;
+ }
+ if (signaling_thread_) {
+ RTC_DCHECK_RUN_ON(signaling_thread_);
+ } else {
+ signaling_thread_ = rtc::Thread::Current();
+ if (!signaling_thread_) {
+ // If this thread isn't already wrapped by an rtc::Thread, create a
+ // wrapper and own it in this class.
+ signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
+ wraps_signaling_thread_ = true;
+ }
+ }
+ if (!network_manager_) {
+ network_manager_ = new rtc::BasicNetworkManager();
+ owns_network_manager_ = true;
+ }
+ if (!socket_factory_) {
+ socket_factory_ = new rtc::BasicPacketSocketFactory(network_thread_);
+ owns_socket_factory_ = true;
+ }
+}
+
+OrtcFactory::~OrtcFactory() {
+ RTC_DCHECK_RUN_ON(signaling_thread_);
+ if (owns_network_thread_) {
+ delete network_thread_;
+ }
+ if (owns_worker_thread_) {
+ delete worker_thread_;
+ }
+ if (wraps_signaling_thread_) {
+ rtc::ThreadManager::Instance()->UnwrapCurrentThread();
+ }
+ if (owns_network_manager_) {
+ delete network_manager_;
+ }
+ if (owns_socket_factory_) {
+ delete socket_factory_;
+ }
+}
+
+std::unique_ptr<UdpTransportInterface> OrtcFactory::CreateUdpTransport(
+ int family,
+ uint16_t min_port,
+ uint16_t max_port) {
+ if (!network_thread_->IsCurrent()) {
+ RTC_DCHECK_RUN_ON(signaling_thread_);
+ return network_thread_->Invoke<std::unique_ptr<UdpTransportInterface>>(
+ RTC_FROM_HERE, rtc::Bind(&OrtcFactory::CreateUdpTransport, this, family,
+ min_port, max_port));
+ }
+ std::unique_ptr<rtc::AsyncPacketSocket> socket(
+ socket_factory_->CreateUdpSocket(
+ rtc::SocketAddress(rtc::GetAnyIP(family), 0), min_port, max_port));
+ if (!socket) {
+ LOG(INFO) << "Local socket allocation failure.";
+ return nullptr;
+ }
+ LOG(INFO) << "Created UDP socket with address "
+ << socket->GetLocalAddress().ToSensitiveString() << ".";
+ // Use proxy so that calls to the returned object are invoked on the network
+ // thread.
+ return UdpTransportProxy::Create(
+ signaling_thread_, network_thread_,
+ new cricket::UdpTransport(std::string(), std::move(socket)));
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/api/ortcfactory.h ('k') | webrtc/api/ortcfactory_unittest.cc » ('j') | webrtc/api/proxy.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698