blob: a0507e3f7fbc46ad4444a4a763202b3498c95f26 [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
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"
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020024#include "sdk/android/native_api/video/videosource.h"
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010025
26namespace webrtc_examples {
27
28class AndroidCallClient {
29 public:
30 AndroidCallClient();
31
32 void Call(JNIEnv* env,
33 const webrtc::JavaRef<jobject>& cls,
34 const webrtc::JavaRef<jobject>& local_sink,
35 const webrtc::JavaRef<jobject>& remote_sink);
36 void Hangup(JNIEnv* env, const webrtc::JavaRef<jobject>& cls);
37 // A helper method for Java code to delete this object. Calls delete this.
38 void Delete(JNIEnv* env, const webrtc::JavaRef<jobject>& cls);
39
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020040 webrtc::ScopedJavaLocalRef<jobject> GetJavaVideoCapturerObserver(
41 JNIEnv* env,
42 const webrtc::JavaRef<jobject>& cls);
43
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010044 private:
45 class PCObserver;
46
47 void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
48 void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
49 void Connect() RTC_RUN_ON(thread_checker_);
50
51 rtc::ThreadChecker thread_checker_;
52
53 bool call_started_ RTC_GUARDED_BY(thread_checker_);
54
55 const std::unique_ptr<PCObserver> pc_observer_;
56
57 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_
58 RTC_GUARDED_BY(thread_checker_);
59 std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
60 std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
61 std::unique_ptr<rtc::Thread> signaling_thread_
62 RTC_GUARDED_BY(thread_checker_);
63
64 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> local_sink_
65 RTC_GUARDED_BY(thread_checker_);
66 std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
67 RTC_GUARDED_BY(thread_checker_);
Sami Kalliomäkic475ac12018-05-16 15:49:18 +020068 rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
Sami Kalliomäki3e77afd2018-03-08 16:43:16 +010069 RTC_GUARDED_BY(thread_checker_);
70
71 rtc::CriticalSection pc_mutex_;
72 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
73 RTC_GUARDED_BY(pc_mutex_);
74};
75
76} // namespace webrtc_examples
77
78#endif // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROIDCALLCLIENT_H_