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 25 matching lines...) Expand all Loading... |
36 : j_video_capturer_(jni, j_video_capturer), | 36 : j_video_capturer_(jni, j_video_capturer), |
37 j_video_capturer_class_(jni, FindClass(jni, "org/webrtc/VideoCapturer")), | 37 j_video_capturer_class_(jni, FindClass(jni, "org/webrtc/VideoCapturer")), |
38 j_observer_class_( | 38 j_observer_class_( |
39 jni, | 39 jni, |
40 FindClass(jni, | 40 FindClass(jni, |
41 "org/webrtc/VideoCapturer$NativeObserver")), | 41 "org/webrtc/VideoCapturer$NativeObserver")), |
42 surface_texture_helper_(SurfaceTextureHelper::create( | 42 surface_texture_helper_(SurfaceTextureHelper::create( |
43 jni, "Camera SurfaceTextureHelper", j_egl_context)), | 43 jni, "Camera SurfaceTextureHelper", j_egl_context)), |
44 capturer_(nullptr) { | 44 capturer_(nullptr) { |
45 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; | 45 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; |
| 46 jobject j_frame_observer = |
| 47 jni->NewObject(*j_observer_class_, |
| 48 GetMethodID(jni, *j_observer_class_, "<init>", "(J)V"), |
| 49 jlongFromPointer(this)); |
| 50 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 51 jni->CallVoidMethod( |
| 52 *j_video_capturer_, |
| 53 GetMethodID(jni, *j_video_capturer_class_, "initialize", |
| 54 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" |
| 55 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), |
| 56 surface_texture_helper_ |
| 57 ? surface_texture_helper_->GetJavaSurfaceTextureHelper() |
| 58 : nullptr, |
| 59 application_context_, j_frame_observer); |
| 60 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; |
46 thread_checker_.DetachFromThread(); | 61 thread_checker_.DetachFromThread(); |
47 } | 62 } |
48 | 63 |
49 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { | 64 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { |
50 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; | 65 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; |
51 jni()->CallVoidMethod( | 66 jni()->CallVoidMethod( |
52 *j_video_capturer_, | 67 *j_video_capturer_, |
53 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); | 68 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); |
54 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.dispose()"; | 69 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.dispose()"; |
55 } | 70 } |
56 | 71 |
57 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, | 72 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, |
58 webrtc::AndroidVideoCapturer* capturer) { | 73 webrtc::AndroidVideoCapturer* capturer) { |
59 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; | 74 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; |
60 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 75 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
61 { | 76 { |
62 rtc::CritScope cs(&capturer_lock_); | 77 rtc::CritScope cs(&capturer_lock_); |
63 RTC_CHECK(capturer_ == nullptr); | 78 RTC_CHECK(capturer_ == nullptr); |
64 RTC_CHECK(invoker_.get() == nullptr); | 79 RTC_CHECK(invoker_.get() == nullptr); |
65 capturer_ = capturer; | 80 capturer_ = capturer; |
66 invoker_.reset(new rtc::GuardedAsyncInvoker()); | 81 invoker_.reset(new rtc::GuardedAsyncInvoker()); |
67 } | 82 } |
68 jobject j_frame_observer = | 83 jmethodID m = |
69 jni()->NewObject(*j_observer_class_, | 84 GetMethodID(jni(), *j_video_capturer_class_, "startCapture", "(III)V"); |
70 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), | 85 jni()->CallVoidMethod(*j_video_capturer_, m, width, height, framerate); |
71 jlongFromPointer(this)); | |
72 CHECK_EXCEPTION(jni()) << "error during NewObject"; | |
73 | |
74 jmethodID m = GetMethodID( | |
75 jni(), *j_video_capturer_class_, "startCapture", | |
76 "(IIILorg/webrtc/SurfaceTextureHelper;Landroid/content/Context;" | |
77 "Lorg/webrtc/VideoCapturer$CapturerObserver;)V"); | |
78 jni()->CallVoidMethod( | |
79 *j_video_capturer_, m, width, height, framerate, | |
80 surface_texture_helper_ | |
81 ? surface_texture_helper_->GetJavaSurfaceTextureHelper() | |
82 : nullptr, | |
83 application_context_, j_frame_observer); | |
84 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.startCapture"; | 86 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.startCapture"; |
85 } | 87 } |
86 | 88 |
87 void AndroidVideoCapturerJni::Stop() { | 89 void AndroidVideoCapturerJni::Stop() { |
88 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; | 90 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; |
89 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 91 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
90 { | 92 { |
91 // TODO(nisse): Consider moving this block until *after* the call to | 93 // TODO(nisse): Consider moving this block until *after* the call to |
92 // stopCapturer. stopCapturer should ensure that we get no | 94 // stopCapturer. stopCapturer should ensure that we get no |
93 // more frames, and then we shouldn't need the if (!capturer_) | 95 // more frames, and then we shouldn't need the if (!capturer_) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 341 |
340 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) | 342 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
341 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 343 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
342 jint j_fps) { | 344 jint j_fps) { |
343 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 345 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
344 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 346 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
345 j_width, j_height, j_fps); | 347 j_width, j_height, j_fps); |
346 } | 348 } |
347 | 349 |
348 } // namespace webrtc_jni | 350 } // namespace webrtc_jni |
OLD | NEW |