OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 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 WEBRTC_API_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | |
12 #define WEBRTC_API_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | |
13 | |
14 #include <memory> | |
15 #include <string> | |
16 | |
17 #include "webrtc/api/androidvideocapturer.h" | |
18 #include "webrtc/api/android/jni/jni_helpers.h" | |
19 #include "webrtc/base/asyncinvoker.h" | |
20 #include "webrtc/base/constructormagic.h" | |
21 #include "webrtc/base/criticalsection.h" | |
22 #include "webrtc/base/thread_checker.h" | |
23 #include "webrtc/common_video/include/i420_buffer_pool.h" | |
24 | |
25 namespace webrtc_jni { | |
26 | |
27 struct NativeHandleImpl; | |
28 class SurfaceTextureHelper; | |
29 | |
30 // AndroidVideoCapturerJni implements AndroidVideoCapturerDelegate. | |
31 // The purpose of the delegate is to hide the JNI specifics from the C++ only | |
32 // AndroidVideoCapturer. | |
33 class AndroidVideoCapturerJni : public webrtc::AndroidVideoCapturerDelegate { | |
34 public: | |
35 static int SetAndroidObjects(JNIEnv* jni, jobject appliction_context); | |
36 | |
37 AndroidVideoCapturerJni(JNIEnv* jni, | |
38 jobject j_video_capturer, | |
39 jobject j_egl_context); | |
40 | |
41 void Start(int width, int height, int framerate, | |
42 webrtc::AndroidVideoCapturer* capturer) override; | |
43 void Stop() override; | |
44 | |
45 std::vector<cricket::VideoFormat> GetSupportedFormats() override; | |
46 | |
47 // Called from VideoCapturer::NativeObserver on a Java thread. | |
48 void OnCapturerStarted(bool success); | |
49 void OnMemoryBufferFrame(void* video_frame, int length, int width, | |
50 int height, int rotation, int64_t timestamp_ns); | |
51 void OnTextureFrame(int width, int height, int rotation, int64_t timestamp_ns, | |
52 const NativeHandleImpl& handle); | |
53 void OnOutputFormatRequest(int width, int height, int fps); | |
54 | |
55 protected: | |
56 ~AndroidVideoCapturerJni(); | |
57 | |
58 private: | |
59 JNIEnv* jni(); | |
60 | |
61 // To avoid deducing Args from the 3rd parameter of AsyncCapturerInvoke. | |
62 template <typename T> | |
63 struct Identity { | |
64 typedef T type; | |
65 }; | |
66 | |
67 // Helper function to make safe asynchronous calls to |capturer_|. The calls | |
68 // are not guaranteed to be delivered. | |
69 template <typename... Args> | |
70 void AsyncCapturerInvoke( | |
71 const rtc::Location& posted_from, | |
72 void (webrtc::AndroidVideoCapturer::*method)(Args...), | |
73 typename Identity<Args>::type... args); | |
74 | |
75 const ScopedGlobalRef<jobject> j_video_capturer_; | |
76 const ScopedGlobalRef<jclass> j_video_capturer_class_; | |
77 const ScopedGlobalRef<jclass> j_observer_class_; | |
78 | |
79 // Used on the Java thread running the camera. | |
80 webrtc::I420BufferPool pre_scale_pool_; | |
81 webrtc::I420BufferPool post_scale_pool_; | |
82 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper_; | |
83 rtc::ThreadChecker thread_checker_; | |
84 | |
85 // |capturer| is a guaranteed to be a valid pointer between a call to | |
86 // AndroidVideoCapturerDelegate::Start | |
87 // until AndroidVideoCapturerDelegate::Stop. | |
88 rtc::CriticalSection capturer_lock_; | |
89 webrtc::AndroidVideoCapturer* capturer_ GUARDED_BY(capturer_lock_); | |
90 // |invoker_| is used to communicate with |capturer_| on the thread Start() is | |
91 // called on. | |
92 std::unique_ptr<rtc::GuardedAsyncInvoker> invoker_ GUARDED_BY(capturer_lock_); | |
93 | |
94 static jobject application_context_; | |
95 | |
96 RTC_DISALLOW_COPY_AND_ASSIGN(AndroidVideoCapturerJni); | |
97 }; | |
98 | |
99 } // namespace webrtc_jni | |
100 | |
101 #endif // WEBRTC_API_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | |
OLD | NEW |