Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: webrtc/api/java/jni/androidvideocapturer_jni.cc

Issue 1840193007: Android: Handle SurfaceTextureHelper ctor failure for decoder and capturer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressing perkj@s comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, 23 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni,
24 jobject appliction_context) { 24 jobject appliction_context) {
25 if (application_context_) { 25 if (application_context_) {
26 jni->DeleteGlobalRef(application_context_); 26 jni->DeleteGlobalRef(application_context_);
27 } 27 }
28 application_context_ = NewGlobalRef(jni, appliction_context); 28 application_context_ = NewGlobalRef(jni, appliction_context);
29 29
30 return 0; 30 return 0;
31 } 31 }
32 32
33 AndroidVideoCapturerJni::AndroidVideoCapturerJni( 33 AndroidVideoCapturerJni::AndroidVideoCapturerJni(JNIEnv* jni,
34 JNIEnv* jni, 34 jobject j_video_capturer,
35 jobject j_video_capturer, 35 jobject j_egl_context)
36 jobject j_egl_context)
37 : j_video_capturer_(jni, j_video_capturer), 36 : j_video_capturer_(jni, j_video_capturer),
38 j_video_capturer_class_( 37 j_video_capturer_class_(jni, FindClass(jni, "org/webrtc/VideoCapturer")),
39 jni, FindClass(jni, "org/webrtc/VideoCapturer")),
40 j_observer_class_( 38 j_observer_class_(
41 jni, 39 jni,
42 FindClass(jni, 40 FindClass(jni,
43 "org/webrtc/VideoCapturer$NativeObserver")), 41 "org/webrtc/VideoCapturer$NativeObserver")),
44 surface_texture_helper_(new rtc::RefCountedObject<SurfaceTextureHelper>( 42 surface_texture_helper_(SurfaceTextureHelper::create(
45 jni, "Camera SurfaceTextureHelper", j_egl_context)), 43 jni, "Camera SurfaceTextureHelper", j_egl_context)),
46 capturer_(nullptr) { 44 capturer_(nullptr) {
47 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; 45 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor";
48 thread_checker_.DetachFromThread(); 46 thread_checker_.DetachFromThread();
49 } 47 }
50 48
51 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { 49 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() {
52 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; 50 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor";
53 jni()->CallVoidMethod( 51 jni()->CallVoidMethod(
54 *j_video_capturer_, 52 *j_video_capturer_,
55 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); 53 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V"));
56 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.dispose()"; 54 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.dispose()";
57 jni()->CallVoidMethod( 55 if (surface_texture_helper_) {
58 surface_texture_helper_->GetJavaSurfaceTextureHelper(), 56 jni()->CallVoidMethod(
59 GetMethodID(jni(), FindClass(jni(), "org/webrtc/SurfaceTextureHelper"), 57 surface_texture_helper_->GetJavaSurfaceTextureHelper(),
60 "dispose", "()V")); 58 GetMethodID(jni(), FindClass(jni(), "org/webrtc/SurfaceTextureHelper"),
59 "dispose", "()V"));
60 }
61 CHECK_EXCEPTION(jni()) << "error during SurfaceTextureHelper.dispose()"; 61 CHECK_EXCEPTION(jni()) << "error during SurfaceTextureHelper.dispose()";
62 } 62 }
63 63
64 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, 64 void AndroidVideoCapturerJni::Start(int width, int height, int framerate,
65 webrtc::AndroidVideoCapturer* capturer) { 65 webrtc::AndroidVideoCapturer* capturer) {
66 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; 66 LOG(LS_INFO) << "AndroidVideoCapturerJni start";
67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 67 RTC_DCHECK(thread_checker_.CalledOnValidThread());
68 { 68 {
69 rtc::CritScope cs(&capturer_lock_); 69 rtc::CritScope cs(&capturer_lock_);
70 RTC_CHECK(capturer_ == nullptr); 70 RTC_CHECK(capturer_ == nullptr);
71 RTC_CHECK(invoker_.get() == nullptr); 71 RTC_CHECK(invoker_.get() == nullptr);
72 capturer_ = capturer; 72 capturer_ = capturer;
73 invoker_.reset(new rtc::GuardedAsyncInvoker()); 73 invoker_.reset(new rtc::GuardedAsyncInvoker());
74 } 74 }
75 jobject j_frame_observer = 75 jobject j_frame_observer =
76 jni()->NewObject(*j_observer_class_, 76 jni()->NewObject(*j_observer_class_,
77 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), 77 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"),
78 jlongFromPointer(this)); 78 jlongFromPointer(this));
79 CHECK_EXCEPTION(jni()) << "error during NewObject"; 79 CHECK_EXCEPTION(jni()) << "error during NewObject";
80 80
81 jmethodID m = GetMethodID( 81 jmethodID m = GetMethodID(
82 jni(), *j_video_capturer_class_, "startCapture", 82 jni(), *j_video_capturer_class_, "startCapture",
83 "(IIILorg/webrtc/SurfaceTextureHelper;Landroid/content/Context;" 83 "(IIILorg/webrtc/SurfaceTextureHelper;Landroid/content/Context;"
84 "Lorg/webrtc/VideoCapturer$CapturerObserver;)V"); 84 "Lorg/webrtc/VideoCapturer$CapturerObserver;)V");
85 jni()->CallVoidMethod(*j_video_capturer_, 85 jni()->CallVoidMethod(
86 m, width, height, 86 *j_video_capturer_, m, width, height, framerate,
87 framerate, 87 surface_texture_helper_
88 surface_texture_helper_->GetJavaSurfaceTextureHelper(), 88 ? surface_texture_helper_->GetJavaSurfaceTextureHelper()
89 application_context_, 89 : nullptr,
90 j_frame_observer); 90 application_context_, j_frame_observer);
91 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.startCapture"; 91 CHECK_EXCEPTION(jni()) << "error during VideoCapturer.startCapture";
92 } 92 }
93 93
94 void AndroidVideoCapturerJni::Stop() { 94 void AndroidVideoCapturerJni::Stop() {
95 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; 95 LOG(LS_INFO) << "AndroidVideoCapturerJni stop";
96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 96 RTC_DCHECK(thread_checker_.CalledOnValidThread());
97 { 97 {
98 rtc::CritScope cs(&capturer_lock_); 98 rtc::CritScope cs(&capturer_lock_);
99 // Destroying |invoker_| will cancel all pending calls to |capturer_|. 99 // Destroying |invoker_| will cancel all pending calls to |capturer_|.
100 invoker_ = nullptr; 100 invoker_ = nullptr;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) 240 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest)
241 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, 241 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height,
242 jint j_fps) { 242 jint j_fps) {
243 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; 243 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest";
244 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( 244 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest(
245 j_width, j_height, j_fps); 245 j_width, j_height, j_fps);
246 } 246 }
247 247
248 } // namespace webrtc_jni 248 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/api/java/jni/androidmediadecoder_jni.cc ('k') | webrtc/api/java/jni/surfacetexturehelper_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698