Sami Kalliomäki | 3e77afd | 2018-03-08 16:43:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROIDCALLCLIENT_H_ |
| 12 | #define EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROIDCALLCLIENT_H_ |
| 13 | |
| 14 | #include <jni.h> |
| 15 | |
| 16 | #include <memory> |
| 17 | #include <string> |
| 18 | |
| 19 | #include "api/peerconnectioninterface.h" |
| 20 | #include "rtc_base/criticalsection.h" |
| 21 | #include "rtc_base/scoped_ref_ptr.h" |
| 22 | #include "rtc_base/thread_checker.h" |
| 23 | #include "sdk/android/native_api/jni/scoped_java_ref.h" |
| 24 | |
| 25 | namespace webrtc_examples { |
| 26 | |
| 27 | class AndroidCallClient { |
| 28 | public: |
| 29 | AndroidCallClient(); |
| 30 | |
| 31 | void Call(JNIEnv* env, |
| 32 | const webrtc::JavaRef<jobject>& cls, |
| 33 | const webrtc::JavaRef<jobject>& local_sink, |
| 34 | const webrtc::JavaRef<jobject>& remote_sink); |
| 35 | void Hangup(JNIEnv* env, const webrtc::JavaRef<jobject>& cls); |
| 36 | // A helper method for Java code to delete this object. Calls delete this. |
| 37 | void Delete(JNIEnv* env, const webrtc::JavaRef<jobject>& cls); |
| 38 | |
| 39 | private: |
| 40 | class PCObserver; |
| 41 | |
| 42 | void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_); |
| 43 | void CreatePeerConnection() RTC_RUN_ON(thread_checker_); |
| 44 | void Connect() RTC_RUN_ON(thread_checker_); |
| 45 | |
| 46 | rtc::ThreadChecker thread_checker_; |
| 47 | |
| 48 | bool call_started_ RTC_GUARDED_BY(thread_checker_); |
| 49 | |
| 50 | const std::unique_ptr<PCObserver> pc_observer_; |
| 51 | |
| 52 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_ |
| 53 | RTC_GUARDED_BY(thread_checker_); |
| 54 | std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_); |
| 55 | std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_); |
| 56 | std::unique_ptr<rtc::Thread> signaling_thread_ |
| 57 | RTC_GUARDED_BY(thread_checker_); |
| 58 | |
| 59 | std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> local_sink_ |
| 60 | RTC_GUARDED_BY(thread_checker_); |
| 61 | std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_ |
| 62 | RTC_GUARDED_BY(thread_checker_); |
| 63 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_ |
| 64 | RTC_GUARDED_BY(thread_checker_); |
| 65 | |
| 66 | rtc::CriticalSection pc_mutex_; |
| 67 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ |
| 68 | RTC_GUARDED_BY(pc_mutex_); |
| 69 | }; |
| 70 | |
| 71 | } // namespace webrtc_examples |
| 72 | |
| 73 | #endif // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROIDCALLCLIENT_H_ |