OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 return 0; | 30 return 0; |
31 } | 31 } |
32 | 32 |
33 AndroidVideoCapturerJni::AndroidVideoCapturerJni( | 33 AndroidVideoCapturerJni::AndroidVideoCapturerJni( |
34 JNIEnv* jni, | 34 JNIEnv* jni, |
35 jobject j_video_capturer, | 35 jobject j_video_capturer, |
36 jobject j_surface_texture_helper) | 36 jobject j_surface_texture_helper) |
37 : j_video_capturer_(jni, j_video_capturer), | 37 : j_video_capturer_(jni, j_video_capturer), |
38 j_video_capturer_class_( | 38 j_video_capturer_class_( |
39 jni, FindClass(jni, "org/webrtc/VideoCapturerAndroid")), | 39 jni, FindClass(jni, "org/webrtc/VideoCapturer")), |
40 j_observer_class_( | 40 j_observer_class_( |
41 jni, | 41 jni, |
42 FindClass(jni, | 42 FindClass(jni, |
43 "org/webrtc/VideoCapturerAndroid$NativeObserver")), | 43 "org/webrtc/VideoCapturer$NativeObserver")), |
44 surface_texture_helper_(new rtc::RefCountedObject<SurfaceTextureHelper>( | 44 surface_texture_helper_(new rtc::RefCountedObject<SurfaceTextureHelper>( |
45 jni, j_surface_texture_helper)), | 45 jni, j_surface_texture_helper)), |
46 capturer_(nullptr) { | 46 capturer_(nullptr) { |
47 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; | 47 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; |
48 thread_checker_.DetachFromThread(); | 48 thread_checker_.DetachFromThread(); |
49 } | 49 } |
50 | 50 |
51 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { | 51 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { |
52 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; | 52 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; |
53 jni()->CallVoidMethod( | 53 jni()->CallVoidMethod( |
54 *j_video_capturer_, | 54 *j_video_capturer_, |
55 GetMethodID(jni(), *j_video_capturer_class_, "release", "()V")); | 55 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); |
56 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.release()"; | 56 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.dispose()"; |
57 } | 57 } |
58 | 58 |
59 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, | 59 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, |
60 webrtc::AndroidVideoCapturer* capturer) { | 60 webrtc::AndroidVideoCapturer* capturer) { |
61 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; | 61 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; |
62 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 62 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
63 { | 63 { |
64 rtc::CritScope cs(&capturer_lock_); | 64 rtc::CritScope cs(&capturer_lock_); |
65 RTC_CHECK(capturer_ == nullptr); | 65 RTC_CHECK(capturer_ == nullptr); |
66 RTC_CHECK(invoker_.get() == nullptr); | 66 RTC_CHECK(invoker_.get() == nullptr); |
67 capturer_ = capturer; | 67 capturer_ = capturer; |
68 invoker_.reset(new rtc::GuardedAsyncInvoker()); | 68 invoker_.reset(new rtc::GuardedAsyncInvoker()); |
69 } | 69 } |
70 jobject j_frame_observer = | 70 jobject j_frame_observer = |
71 jni()->NewObject(*j_observer_class_, | 71 jni()->NewObject(*j_observer_class_, |
72 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), | 72 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), |
73 jlongFromPointer(this)); | 73 jlongFromPointer(this)); |
74 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 74 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
75 | 75 |
76 jmethodID m = GetMethodID( | 76 jmethodID m = GetMethodID( |
77 jni(), *j_video_capturer_class_, "startCapture", | 77 jni(), *j_video_capturer_class_, "startCapture", |
78 "(IIILandroid/content/Context;" | 78 "(IIILandroid/content/Context;" |
79 "Lorg/webrtc/VideoCapturerAndroid$CapturerObserver;)V"); | 79 "Lorg/webrtc/VideoCapturer$CapturerObserver;)V"); |
80 jni()->CallVoidMethod(*j_video_capturer_, | 80 jni()->CallVoidMethod(*j_video_capturer_, |
81 m, width, height, | 81 m, width, height, |
82 framerate, | 82 framerate, |
83 application_context_, | 83 application_context_, |
84 j_frame_observer); | 84 j_frame_observer); |
85 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.startCapture"; | 85 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.startCapture"; |
86 } | 86 } |
87 | 87 |
88 void AndroidVideoCapturerJni::Stop() { | 88 void AndroidVideoCapturerJni::Stop() { |
89 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; | 89 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; |
90 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 90 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
91 { | 91 { |
92 rtc::CritScope cs(&capturer_lock_); | 92 rtc::CritScope cs(&capturer_lock_); |
93 // Destroying |invoker_| will cancel all pending calls to |capturer_|. | 93 // Destroying |invoker_| will cancel all pending calls to |capturer_|. |
94 invoker_ = nullptr; | 94 invoker_ = nullptr; |
95 capturer_ = nullptr; | 95 capturer_ = nullptr; |
96 } | 96 } |
97 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, | 97 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, |
98 "stopCapture", "()V"); | 98 "stopCapture", "()V"); |
99 jni()->CallVoidMethod(*j_video_capturer_, m); | 99 jni()->CallVoidMethod(*j_video_capturer_, m); |
100 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.stopCapture"; | 100 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.stopCapture"; |
101 LOG(LS_INFO) << "AndroidVideoCapturerJni stop done"; | 101 LOG(LS_INFO) << "AndroidVideoCapturerJni stop done"; |
102 } | 102 } |
103 | 103 |
104 template <typename... Args> | 104 template <typename... Args> |
105 void AndroidVideoCapturerJni::AsyncCapturerInvoke( | 105 void AndroidVideoCapturerJni::AsyncCapturerInvoke( |
106 const char* method_name, | 106 const char* method_name, |
107 void (webrtc::AndroidVideoCapturer::*method)(Args...), | 107 void (webrtc::AndroidVideoCapturer::*method)(Args...), |
108 typename Identity<Args>::type... args) { | 108 typename Identity<Args>::type... args) { |
109 rtc::CritScope cs(&capturer_lock_); | 109 rtc::CritScope cs(&capturer_lock_); |
110 if (!invoker_) { | 110 if (!invoker_) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 int height, | 171 int height, |
172 int fps) { | 172 int fps) { |
173 AsyncCapturerInvoke("OnOutputFormatRequest", | 173 AsyncCapturerInvoke("OnOutputFormatRequest", |
174 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, | 174 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, |
175 width, height, fps); | 175 width, height, fps); |
176 } | 176 } |
177 | 177 |
178 JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); } | 178 JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); } |
179 | 179 |
180 JOW(void, | 180 JOW(void, |
181 VideoCapturerAndroid_00024NativeObserver_nativeOnByteBufferFrameCaptured) | 181 VideoCapturer_00024NativeObserver_nativeOnByteBufferFrameCaptured) |
182 (JNIEnv* jni, jclass, jlong j_capturer, jbyteArray j_frame, jint length, | 182 (JNIEnv* jni, jclass, jlong j_capturer, jbyteArray j_frame, jint length, |
183 jint width, jint height, jint rotation, jlong timestamp) { | 183 jint width, jint height, jint rotation, jlong timestamp) { |
184 jboolean is_copy = true; | 184 jboolean is_copy = true; |
185 jbyte* bytes = jni->GetByteArrayElements(j_frame, &is_copy); | 185 jbyte* bytes = jni->GetByteArrayElements(j_frame, &is_copy); |
186 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) | 186 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) |
187 ->OnMemoryBufferFrame(bytes, length, width, height, rotation, timestamp); | 187 ->OnMemoryBufferFrame(bytes, length, width, height, rotation, timestamp); |
188 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); | 188 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); |
189 } | 189 } |
190 | 190 |
191 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnTextureFrameCaptured) | 191 JOW(void, VideoCapturer_00024NativeObserver_nativeOnTextureFrameCaptured) |
192 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 192 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
193 jint j_oes_texture_id, jfloatArray j_transform_matrix, | 193 jint j_oes_texture_id, jfloatArray j_transform_matrix, |
194 jint j_rotation, jlong j_timestamp) { | 194 jint j_rotation, jlong j_timestamp) { |
195 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) | 195 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) |
196 ->OnTextureFrame(j_width, j_height, j_rotation, j_timestamp, | 196 ->OnTextureFrame(j_width, j_height, j_rotation, j_timestamp, |
197 NativeHandleImpl(jni, j_oes_texture_id, | 197 NativeHandleImpl(jni, j_oes_texture_id, |
198 j_transform_matrix)); | 198 j_transform_matrix)); |
199 } | 199 } |
200 | 200 |
201 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) | 201 JOW(void, VideoCapturer_00024NativeObserver_nativeCapturerStarted) |
202 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { | 202 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { |
203 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; | 203 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; |
204 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( | 204 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( |
205 j_success); | 205 j_success); |
206 } | 206 } |
207 | 207 |
208 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) | 208 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
209 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 209 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
210 jint j_fps) { | 210 jint j_fps) { |
211 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 211 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
212 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 212 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
213 j_width, j_height, j_fps); | 213 j_width, j_height, j_fps); |
214 } | 214 } |
215 | 215 |
216 JOW(jlong, VideoCapturerAndroid_nativeCreateVideoCapturer) | |
217 (JNIEnv* jni, jclass, | |
218 jobject j_video_capturer, jobject j_surface_texture_helper) { | |
219 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = | |
220 new rtc::RefCountedObject<AndroidVideoCapturerJni>( | |
221 jni, j_video_capturer, j_surface_texture_helper); | |
222 rtc::scoped_ptr<cricket::VideoCapturer> capturer( | |
223 new webrtc::AndroidVideoCapturer(delegate)); | |
224 // Caller takes ownership of the cricket::VideoCapturer* pointer. | |
225 return jlongFromPointer(capturer.release()); | |
226 } | |
227 | |
228 } // namespace webrtc_jni | 216 } // namespace webrtc_jni |
OLD | NEW |