android_call_client.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
  11. #define EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_
  12. #include <jni.h>
  13. #include <memory>
  14. #include <string>
  15. #include "api/peer_connection_interface.h"
  16. #include "api/scoped_refptr.h"
  17. #include "rtc_base/synchronization/mutex.h"
  18. #include "rtc_base/thread_checker.h"
  19. #include "sdk/android/native_api/jni/scoped_java_ref.h"
  20. #include "sdk/android/native_api/video/video_source.h"
  21. namespace webrtc_examples {
  22. class AndroidCallClient {
  23. public:
  24. AndroidCallClient();
  25. ~AndroidCallClient();
  26. void Call(JNIEnv* env,
  27. const webrtc::JavaRef<jobject>& local_sink,
  28. const webrtc::JavaRef<jobject>& remote_sink);
  29. void Hangup(JNIEnv* env);
  30. // A helper method for Java code to delete this object. Calls delete this.
  31. void Delete(JNIEnv* env);
  32. webrtc::ScopedJavaLocalRef<jobject> GetJavaVideoCapturerObserver(JNIEnv* env);
  33. private:
  34. class PCObserver;
  35. void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
  36. void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
  37. void Connect() RTC_RUN_ON(thread_checker_);
  38. rtc::ThreadChecker thread_checker_;
  39. bool call_started_ RTC_GUARDED_BY(thread_checker_);
  40. const std::unique_ptr<PCObserver> pc_observer_;
  41. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_
  42. RTC_GUARDED_BY(thread_checker_);
  43. std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
  44. std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
  45. std::unique_ptr<rtc::Thread> signaling_thread_
  46. RTC_GUARDED_BY(thread_checker_);
  47. std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> local_sink_
  48. RTC_GUARDED_BY(thread_checker_);
  49. std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
  50. RTC_GUARDED_BY(thread_checker_);
  51. rtc::scoped_refptr<webrtc::JavaVideoTrackSourceInterface> video_source_
  52. RTC_GUARDED_BY(thread_checker_);
  53. webrtc::Mutex pc_mutex_;
  54. rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_
  55. RTC_GUARDED_BY(pc_mutex_);
  56. };
  57. } // namespace webrtc_examples
  58. #endif // EXAMPLES_ANDROIDNATIVEAPI_JNI_ANDROID_CALL_CLIENT_H_