blob: 5ab61f4736e3e141286a9e9e16dd1aedaebf3dfb [file] [log] [blame]
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +01001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
12#define EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010013
14#include <jni.h>
15
16#include <memory>
17#include <string>
18
Steve Anton10542f22019-01-11 09:11:00 -080019#include "api/peer_connection_interface.h"
20#include "rtc_base/critical_section.h"
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010021#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"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "sdk/android/native_api/video/video_source.h"
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010025
26namespace webrtc_examples {
27
28class AndroidCallClient {
29 public:
30 AndroidCallClient();
Mirko Bonadei94ef4242018-07-20 13:33:06 +020031 ~AndroidCallClient();
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010032
33 void Call(JNIEnv* env,
34 const webrtc::JavaRef<jobject>& cls,
35 const webrtc::JavaRef<jobject>& local_sink,
36 const webrtc::JavaRef<jobject>& remote_sink);
37 void Hangup(JNIEnv* env, const webrtc::JavaRef<jobject>& cls);
38 // A helper method for Java code to delete this object. Calls delete this.
39 void Delete(JNIEnv* env, const webrtc::JavaRef<jobject>& cls);
40
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020041 webrtc::ScopedJavaLocalRef<jobject> GetJavaVideoCapturerObserver(
42 JNIEnv* env,
43 const webrtc::JavaRef<jobject>& cls);
44
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010045 private:
46 class PCObserver;
47
48 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
49 void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
50 void Connect() RTC_RUN_ON(thread_checker_);
51
52 rtc::ThreadChecker thread_checker_;
53
54 bool call_started_ RTC_GUARDED_BY(thread_checker_);
55
56 const std::unique_ptr<PCObserver> pc_observer_;
57
58 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_
59 RTC_GUARDED_BY(thread_checker_);
60 std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
61 std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
62 std::unique_ptr<rtc::Thread> signaling_thread_
63 RTC_GUARDED_BY(thread_checker_);
64
65 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> local_sink_
66 RTC_GUARDED_BY(thread_checker_);
67 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
68 RTC_GUARDED_BY(thread_checker_);
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020069 rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010070 RTC_GUARDED_BY(thread_checker_);
71
72 rtc::CriticalSection pc_mutex_;
73 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
74 RTC_GUARDED_BY(pc_mutex_);
75};
76
77} // namespace webrtc_examples
78
Steve Anton10542f22019-01-11 09:11:00 -080079#endif // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_