Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_ |
| 12 | #define WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_ |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 13 | |
| 14 | #include <jni.h> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/java/jni/jni_helpers.h" |
| 17 | #include "webrtc/api/java/jni/native_handle_impl.h" |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 18 | #include "webrtc/base/refcount.h" |
| 19 | #include "webrtc/base/scoped_ref_ptr.h" |
kjellander | 6f8ce06 | 2015-11-16 13:52:24 -0800 | [diff] [blame] | 20 | #include "webrtc/common_video/include/video_frame_buffer.h" |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 21 | |
| 22 | namespace webrtc_jni { |
| 23 | |
| 24 | // Helper class to create and synchronize access to an Android SurfaceTexture. |
| 25 | // It is used for creating webrtc::VideoFrameBuffers from a SurfaceTexture when |
| 26 | // the SurfaceTexture has been updated. |
| 27 | // When the VideoFrameBuffer is released, this class returns the buffer to the |
| 28 | // java SurfaceTextureHelper so it can be updated safely. The VideoFrameBuffer |
| 29 | // can be released on an arbitrary thread. |
| 30 | // SurfaceTextureHelper is reference counted to make sure that it is not |
| 31 | // destroyed while a VideoFrameBuffer is in use. |
| 32 | // This class is the C++ counterpart of the java class SurfaceTextureHelper. |
| 33 | // Usage: |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 34 | // 1. Create an instance of this class. |
| 35 | // 2. Get the Java SurfaceTextureHelper with GetJavaSurfaceTextureHelper(). |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 36 | // 3. Register a listener to the Java SurfaceListener and start producing |
| 37 | // new buffers. |
perkj | 88518a2 | 2015-12-18 00:37:06 -0800 | [diff] [blame] | 38 | // 4. Call CreateTextureFrame to wrap the Java texture in a VideoFrameBuffer. |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 39 | class SurfaceTextureHelper : public rtc::RefCountInterface { |
| 40 | public: |
magjed | 82b750b | 2016-03-31 00:54:15 -0700 | [diff] [blame] | 41 | SurfaceTextureHelper(JNIEnv* jni, |
| 42 | const char* thread_name, |
| 43 | jobject j_egl_context); |
magjed | 0dc2316 | 2016-03-14 03:59:38 -0700 | [diff] [blame] | 44 | |
| 45 | jobject GetJavaSurfaceTextureHelper() const; |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 46 | |
| 47 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateTextureFrame( |
| 48 | int width, |
| 49 | int height, |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 50 | const NativeHandleImpl& native_handle); |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 51 | |
| 52 | protected: |
| 53 | ~SurfaceTextureHelper(); |
| 54 | |
| 55 | private: |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 56 | // May be called on arbitrary thread. |
| 57 | void ReturnTextureFrame() const; |
| 58 | |
Per | 3e9eb4b | 2015-09-28 10:52:22 +0200 | [diff] [blame] | 59 | const ScopedGlobalRef<jobject> j_surface_texture_helper_; |
| 60 | const jmethodID j_return_texture_method_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace webrtc_jni |
| 64 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 65 | #endif // WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_ |