blob: 13992f596038cd24abf6fa0cd28357a3c005efdf [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"
Mirko Bonadeid9708072019-01-25 20:26:48 +010020#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/critical_section.h"
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010022#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,
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010034 const webrtc::JavaRef<jobject>& local_sink,
35 const webrtc::JavaRef<jobject>& remote_sink);
Mirko Bonadei96ea8c02019-07-29 15:33:57 +020036 void Hangup(JNIEnv* env);
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010037 // A helper method for Java code to delete this object. Calls delete this.
Mirko Bonadei96ea8c02019-07-29 15:33:57 +020038 void Delete(JNIEnv* env);
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010039
Mirko Bonadei96ea8c02019-07-29 15:33:57 +020040 webrtc::ScopedJavaLocalRef<jobject> GetJavaVideoCapturerObserver(JNIEnv* env);
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020041
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010042 private:
43 class PCObserver;
44
45 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
46 void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
47 void Connect() RTC_RUN_ON(thread_checker_);
48
49 rtc::ThreadChecker thread_checker_;
50
51 bool call_started_ RTC_GUARDED_BY(thread_checker_);
52
53 const std::unique_ptr<PCObserver> pc_observer_;
54
55 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_
56 RTC_GUARDED_BY(thread_checker_);
57 std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
58 std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
59 std::unique_ptr<rtc::Thread> signaling_thread_
60 RTC_GUARDED_BY(thread_checker_);
61
62 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> local_sink_
63 RTC_GUARDED_BY(thread_checker_);
64 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
65 RTC_GUARDED_BY(thread_checker_);
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020066 rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010067 RTC_GUARDED_BY(thread_checker_);
68
69 rtc::CriticalSection pc_mutex_;
70 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
71 RTC_GUARDED_BY(pc_mutex_);
72};
73
74} // namespace webrtc_examples
75
Steve Anton10542f22019-01-11 09:11:00 -080076#endif // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_