OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * libjingle |
| 3 * Copyright 2015 Google Inc. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 * this list of conditions and the following disclaimer in the documentation |
| 12 * and/or other materials provided with the distribution. |
| 13 * 3. The name of the author may not be used to endorse or promote products |
| 14 * derived from this software without specific prior written permission. |
| 15 * |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 * |
| 27 */ |
| 28 |
| 29 |
| 30 #include "talk/app/webrtc/java/jni/surfacetexturehelper_jni.h" |
| 31 |
| 32 #include "talk/app/webrtc/java/jni/classreferenceholder.h" |
| 33 #include "webrtc/base/checks.h" |
| 34 |
| 35 namespace webrtc_jni { |
| 36 |
| 37 class SurfaceTextureHelper::TextureBuffer : public webrtc::NativeHandleBuffer { |
| 38 public: |
| 39 TextureBuffer(int width, |
| 40 int height, |
| 41 const rtc::scoped_refptr<SurfaceTextureHelper>& pool, |
| 42 const NativeHandleImpl& native_handle) |
| 43 : webrtc::NativeHandleBuffer(&native_handle_, width, height), |
| 44 native_handle_(native_handle), |
| 45 pool_(pool) {} |
| 46 |
| 47 ~TextureBuffer() { |
| 48 pool_->ReturnTextureFrame(); |
| 49 } |
| 50 |
| 51 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
| 52 RTC_NOTREACHED() |
| 53 << "SurfaceTextureHelper::NativeToI420Buffer not implemented."; |
| 54 return nullptr; |
| 55 } |
| 56 |
| 57 private: |
| 58 NativeHandleImpl native_handle_; |
| 59 const rtc::scoped_refptr<SurfaceTextureHelper> pool_; |
| 60 }; |
| 61 |
| 62 SurfaceTextureHelper::SurfaceTextureHelper(JNIEnv* jni, |
| 63 jobject egl_shared_context) |
| 64 : j_surface_texture_helper_class_( |
| 65 jni, |
| 66 jni->FindClass("org/webrtc/SurfaceTextureHelper")), |
| 67 j_surface_texture_helper_( |
| 68 jni, |
| 69 jni->NewObject(*j_surface_texture_helper_class_, |
| 70 GetMethodID(jni, |
| 71 *j_surface_texture_helper_class_, |
| 72 "<init>", |
| 73 "(Landroid/opengl/EGLContext;)V"), |
| 74 egl_shared_context)), |
| 75 j_return_texture_method_( |
| 76 GetMethodID(jni, |
| 77 *j_surface_texture_helper_class_, |
| 78 "returnTextureFrame", |
| 79 "()V")) { |
| 80 CHECK_EXCEPTION(jni) << "error during initialization of SurfaceTextureHelper"; |
| 81 } |
| 82 |
| 83 SurfaceTextureHelper::~SurfaceTextureHelper() { |
| 84 } |
| 85 |
| 86 void SurfaceTextureHelper::ReturnTextureFrame() const { |
| 87 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 88 jni->CallVoidMethod(*j_surface_texture_helper_, j_return_texture_method_); |
| 89 |
| 90 CHECK_EXCEPTION( |
| 91 jni) << "error during SurfaceTextureHelper.returnTextureFrame"; |
| 92 } |
| 93 |
| 94 rtc::scoped_refptr<webrtc::VideoFrameBuffer> |
| 95 SurfaceTextureHelper::CreateTextureFrame(int width, int height, |
| 96 const NativeHandleImpl& native_handle) { |
| 97 return new rtc::RefCountedObject<TextureBuffer>( |
| 98 width, height, this, native_handle); |
| 99 } |
| 100 |
| 101 } // namespace webrtc_jni |
OLD | NEW |