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 |
11 | 11 |
12 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" | 12 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" |
13 | 13 |
14 #include "webrtc/api/java/jni/classreferenceholder.h" | 14 #include "webrtc/api/java/jni/classreferenceholder.h" |
15 #include "webrtc/base/bind.h" | 15 #include "webrtc/base/bind.h" |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 | 17 |
18 namespace webrtc_jni { | 18 namespace webrtc_jni { |
19 | 19 |
20 SurfaceTextureHelper::SurfaceTextureHelper( | 20 rtc::scoped_refptr<SurfaceTextureHelper> SurfaceTextureHelper::create( |
21 JNIEnv* jni, const char* thread_name, jobject j_egl_context) | 21 JNIEnv* jni, |
22 : j_surface_texture_helper_(jni, jni->CallStaticObjectMethod( | 22 const char* thread_name, |
23 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), | 23 jobject j_egl_context) { |
24 GetStaticMethodID(jni, | 24 jobject j_surface_texture_helper = jni->CallStaticObjectMethod( |
25 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), | 25 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), |
26 "create", | 26 GetStaticMethodID(jni, FindClass(jni, "org/webrtc/SurfaceTextureHelper"), |
27 "(Ljava/lang/String;Lorg/webrtc/EglBase$Context;)" | 27 "create", |
28 "Lorg/webrtc/SurfaceTextureHelper;"), | 28 "(Ljava/lang/String;Lorg/webrtc/EglBase$Context;)" |
29 jni->NewStringUTF(thread_name), j_egl_context)), | 29 "Lorg/webrtc/SurfaceTextureHelper;"), |
30 j_return_texture_method_( | 30 jni->NewStringUTF(thread_name), j_egl_context); |
31 GetMethodID(jni, | 31 CHECK_EXCEPTION(jni) |
32 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), | 32 << "error during initialization of Java SurfaceTextureHelper"; |
33 "returnTextureFrame", | 33 if (IsNull(jni, j_surface_texture_helper)) |
34 "()V")) { | 34 return nullptr; |
| 35 return new rtc::RefCountedObject<SurfaceTextureHelper>( |
| 36 jni, j_surface_texture_helper); |
| 37 } |
| 38 |
| 39 SurfaceTextureHelper::SurfaceTextureHelper(JNIEnv* jni, |
| 40 jobject j_surface_texture_helper) |
| 41 : j_surface_texture_helper_(jni, j_surface_texture_helper), |
| 42 j_return_texture_method_( |
| 43 GetMethodID(jni, |
| 44 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), |
| 45 "returnTextureFrame", |
| 46 "()V")) { |
35 CHECK_EXCEPTION(jni) << "error during initialization of SurfaceTextureHelper"; | 47 CHECK_EXCEPTION(jni) << "error during initialization of SurfaceTextureHelper"; |
36 } | 48 } |
37 | 49 |
38 SurfaceTextureHelper::~SurfaceTextureHelper() { | 50 SurfaceTextureHelper::~SurfaceTextureHelper() { |
39 } | 51 } |
40 | 52 |
41 jobject SurfaceTextureHelper::GetJavaSurfaceTextureHelper() const { | 53 jobject SurfaceTextureHelper::GetJavaSurfaceTextureHelper() const { |
42 return *j_surface_texture_helper_; | 54 return *j_surface_texture_helper_; |
43 } | 55 } |
44 | 56 |
45 void SurfaceTextureHelper::ReturnTextureFrame() const { | 57 void SurfaceTextureHelper::ReturnTextureFrame() const { |
46 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 58 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
47 jni->CallVoidMethod(*j_surface_texture_helper_, j_return_texture_method_); | 59 jni->CallVoidMethod(*j_surface_texture_helper_, j_return_texture_method_); |
48 | 60 |
49 CHECK_EXCEPTION( | 61 CHECK_EXCEPTION( |
50 jni) << "error during SurfaceTextureHelper.returnTextureFrame"; | 62 jni) << "error during SurfaceTextureHelper.returnTextureFrame"; |
51 } | 63 } |
52 | 64 |
53 rtc::scoped_refptr<webrtc::VideoFrameBuffer> | 65 rtc::scoped_refptr<webrtc::VideoFrameBuffer> |
54 SurfaceTextureHelper::CreateTextureFrame(int width, int height, | 66 SurfaceTextureHelper::CreateTextureFrame(int width, int height, |
55 const NativeHandleImpl& native_handle) { | 67 const NativeHandleImpl& native_handle) { |
56 return new rtc::RefCountedObject<AndroidTextureBuffer>( | 68 return new rtc::RefCountedObject<AndroidTextureBuffer>( |
57 width, height, native_handle, *j_surface_texture_helper_, | 69 width, height, native_handle, *j_surface_texture_helper_, |
58 rtc::Bind(&SurfaceTextureHelper::ReturnTextureFrame, this)); | 70 rtc::Bind(&SurfaceTextureHelper::ReturnTextureFrame, this)); |
59 } | 71 } |
60 | 72 |
61 } // namespace webrtc_jni | 73 } // namespace webrtc_jni |
OLD | NEW |