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_SDK_ANDROID_SRC_JNI_OWNEDFACTORYANDTHREADS_H_ |
| 12 #define WEBRTC_SDK_ANDROID_SRC_JNI_OWNEDFACTORYANDTHREADS_H_ |
| 13 |
| 14 #include <jni.h> |
| 15 #include <memory> |
| 16 #include <utility> |
| 17 |
| 18 #include "webrtc/api/peerconnectioninterface.h" |
| 19 #include "webrtc/base/thread.h" |
| 20 |
| 21 using cricket::WebRtcVideoDecoderFactory; |
| 22 using cricket::WebRtcVideoEncoderFactory; |
| 23 using rtc::Thread; |
| 24 using webrtc::PeerConnectionFactoryInterface; |
| 25 |
| 26 namespace webrtc_jni { |
| 27 |
| 28 PeerConnectionFactoryInterface* factoryFromJava(jlong j_p); |
| 29 |
| 30 // Helper struct for working around the fact that CreatePeerConnectionFactory() |
| 31 // comes in two flavors: either entirely automagical (constructing its own |
| 32 // threads and deleting them on teardown, but no external codec factory support) |
| 33 // or entirely manual (requires caller to delete threads after factory |
| 34 // teardown). This struct takes ownership of its ctor's arguments to present a |
| 35 // single thing for Java to hold and eventually free. |
| 36 class OwnedFactoryAndThreads { |
| 37 public: |
| 38 OwnedFactoryAndThreads(std::unique_ptr<Thread> network_thread, |
| 39 std::unique_ptr<Thread> worker_thread, |
| 40 std::unique_ptr<Thread> signaling_thread, |
| 41 WebRtcVideoEncoderFactory* encoder_factory, |
| 42 WebRtcVideoDecoderFactory* decoder_factory, |
| 43 rtc::NetworkMonitorFactory* network_monitor_factory, |
| 44 PeerConnectionFactoryInterface* factory) |
| 45 : network_thread_(std::move(network_thread)), |
| 46 worker_thread_(std::move(worker_thread)), |
| 47 signaling_thread_(std::move(signaling_thread)), |
| 48 encoder_factory_(encoder_factory), |
| 49 decoder_factory_(decoder_factory), |
| 50 network_monitor_factory_(network_monitor_factory), |
| 51 factory_(factory) {} |
| 52 |
| 53 ~OwnedFactoryAndThreads(); |
| 54 |
| 55 PeerConnectionFactoryInterface* factory() { return factory_; } |
| 56 Thread* signaling_thread() { return signaling_thread_.get(); } |
| 57 Thread* worker_thread() { return worker_thread_.get(); } |
| 58 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } |
| 59 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } |
| 60 rtc::NetworkMonitorFactory* network_monitor_factory() { |
| 61 return network_monitor_factory_; |
| 62 } |
| 63 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } |
| 64 void InvokeJavaCallbacksOnFactoryThreads(); |
| 65 |
| 66 private: |
| 67 void JavaCallbackOnFactoryThreads(); |
| 68 |
| 69 const std::unique_ptr<Thread> network_thread_; |
| 70 const std::unique_ptr<Thread> worker_thread_; |
| 71 const std::unique_ptr<Thread> signaling_thread_; |
| 72 WebRtcVideoEncoderFactory* encoder_factory_; |
| 73 WebRtcVideoDecoderFactory* decoder_factory_; |
| 74 rtc::NetworkMonitorFactory* network_monitor_factory_; |
| 75 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. |
| 76 }; |
| 77 |
| 78 } // namespace webrtc_jni |
| 79 |
| 80 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_OWNEDFACTORYANDTHREADS_H_ |
OLD | NEW |