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 SDK_ANDROID_SRC_JNI_PC_OWNED_FACTORY_AND_THREADS_H_ 12 #define SDK_ANDROID_SRC_JNI_PC_OWNED_FACTORY_AND_THREADS_H_ 13 14 #include <jni.h> 15 #include <memory> 16 #include <utility> 17 18 #include "api/peer_connection_interface.h" 19 #include "rtc_base/thread.h" 20 21 namespace webrtc { 22 namespace jni { 23 24 // Helper struct for working around the fact that CreatePeerConnectionFactory() 25 // comes in two flavors: either entirely automagical (constructing its own 26 // threads and deleting them on teardown, but no external codec factory support) 27 // or entirely manual (requires caller to delete threads after factory 28 // teardown). This struct takes ownership of its ctor's arguments to present a 29 // single thing for Java to hold and eventually free. 30 class OwnedFactoryAndThreads { 31 public: 32 OwnedFactoryAndThreads( 33 std::unique_ptr<rtc::Thread> network_thread, 34 std::unique_ptr<rtc::Thread> worker_thread, 35 std::unique_ptr<rtc::Thread> signaling_thread, 36 rtc::NetworkMonitorFactory* network_monitor_factory, 37 const rtc::scoped_refptr<PeerConnectionFactoryInterface>& factory); 38 39 ~OwnedFactoryAndThreads(); 40 factory()41 PeerConnectionFactoryInterface* factory() { return factory_.get(); } network_thread()42 rtc::Thread* network_thread() { return network_thread_.get(); } signaling_thread()43 rtc::Thread* signaling_thread() { return signaling_thread_.get(); } worker_thread()44 rtc::Thread* worker_thread() { return worker_thread_.get(); } network_monitor_factory()45 rtc::NetworkMonitorFactory* network_monitor_factory() { 46 return network_monitor_factory_; 47 } clear_network_monitor_factory()48 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } 49 50 private: 51 const std::unique_ptr<rtc::Thread> network_thread_; 52 const std::unique_ptr<rtc::Thread> worker_thread_; 53 const std::unique_ptr<rtc::Thread> signaling_thread_; 54 rtc::NetworkMonitorFactory* network_monitor_factory_; 55 const rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; 56 }; 57 58 } // namespace jni 59 } // namespace webrtc 60 61 #endif // SDK_ANDROID_SRC_JNI_PC_OWNED_FACTORY_AND_THREADS_H_ 62