xref: /aosp_15_r20/external/webrtc/examples/androidnativeapi/jni/android_call_client.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_ANDROID_CALL_CLIENT_H_
12 #define EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
13 
14 #include <jni.h>
15 
16 #include <memory>
17 #include <string>
18 
19 #include "api/peer_connection_interface.h"
20 #include "api/scoped_refptr.h"
21 #include "api/sequence_checker.h"
22 #include "rtc_base/synchronization/mutex.h"
23 #include "sdk/android/native_api/jni/scoped_java_ref.h"
24 #include "sdk/android/native_api/video/video_source.h"
25 
26 namespace webrtc_examples {
27 
28 class AndroidCallClient {
29  public:
30   AndroidCallClient();
31   ~AndroidCallClient();
32 
33   void Call(JNIEnv* env,
34             const webrtc::JavaRef<jobject>& local_sink,
35             const webrtc::JavaRef<jobject>& remote_sink);
36   void Hangup(JNIEnv* env);
37   // A helper method for Java code to delete this object. Calls delete this.
38   void Delete(JNIEnv* env);
39 
40   webrtc::ScopedJavaLocalRef<jobject> GetJavaVideoCapturerObserver(JNIEnv* env);
41 
42  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   webrtc::SequenceChecker 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_);
66   rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
67       RTC_GUARDED_BY(thread_checker_);
68 
69   webrtc::Mutex pc_mutex_;
70   rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
71       RTC_GUARDED_BY(pc_mutex_);
72 };
73 
74 }  // namespace webrtc_examples
75 
76 #endif  // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
77