Chromium Code Reviews| 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 static JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); } | |
|
magjed_webrtc
2015/09/27 11:26:40
I don't think this is a good practice. Pass the JN
perkj_webrtc
2015/09/28 07:22:47
Done.
| |
| 38 | |
| 39 class SurfaceTextureHelper::TextureBuffer : public webrtc::NativeHandleBuffer { | |
| 40 public: | |
| 41 TextureBuffer(int width, | |
| 42 int height, | |
| 43 const rtc::scoped_refptr<SurfaceTextureHelper>& pool, | |
| 44 const NativeHandleImpl& native_handle) | |
| 45 : webrtc::NativeHandleBuffer(&native_handle_, width, height), | |
| 46 native_handle_(native_handle), | |
| 47 pool_(pool) {} | |
| 48 | |
| 49 ~TextureBuffer() { | |
| 50 pool_->ReturnTextureFrame(); | |
| 51 } | |
| 52 | |
| 53 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | |
| 54 RTC_CHECK(false) | |
|
magjed_webrtc
2015/09/27 11:26:40
s/RTC_CHECK/RTC_NOTREACHED/g
perkj_webrtc
2015/09/28 07:22:47
Well, that is a DCHECK. I wanted to make sure it a
magjed_webrtc
2015/09/28 08:19:37
I see. It's up to you.
| |
| 55 << "SurfaceTextureHelper::NativeToI420Buffer not implemented."; | |
| 56 return nullptr; | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 NativeHandleImpl native_handle_; | |
| 61 rtc::scoped_refptr<SurfaceTextureHelper> pool_; | |
|
magjed_webrtc
2015/09/27 11:26:40
Make this const if ReturnTextureFrame() can be mad
perkj_webrtc
2015/09/28 07:22:47
Done.
| |
| 62 }; | |
| 63 | |
| 64 rtc::scoped_refptr<SurfaceTextureHelper> | |
| 65 SurfaceTextureHelper::Create(jobject shared_egl_context) { | |
|
magjed_webrtc
2015/09/27 11:26:41
There is no need for a factory method, use the con
perkj_webrtc
2015/09/28 07:22:47
Done.
| |
| 66 return new rtc::RefCountedObject<SurfaceTextureHelper>( | |
| 67 shared_egl_context); | |
| 68 } | |
| 69 | |
| 70 SurfaceTextureHelper::SurfaceTextureHelper(jobject egl_shared_context) | |
| 71 : j_surface_texture_helper_class_( | |
| 72 jni(), | |
| 73 FindClass(jni(), "org/webrtc/SurfaceTextureHelper")), | |
|
magjed_webrtc
2015/09/27 11:26:40
Replace FindClass(...) with:
jni->FindClass("org/w
perkj_webrtc
2015/09/28 07:22:47
Done.
| |
| 74 j_surface_texture_helper_( | |
| 75 jni(), | |
| 76 jni()->NewObject(*j_surface_texture_helper_class_, | |
| 77 GetMethodID(jni(), | |
| 78 *j_surface_texture_helper_class_, | |
| 79 "<init>", | |
| 80 "(Landroid/opengl/EGLContext;)V"), | |
| 81 egl_shared_context)), | |
| 82 j_return_texture_method_( | |
| 83 GetMethodID(jni(), | |
| 84 FindClass(jni(), "org/webrtc/SurfaceTextureHelper"), | |
| 85 "returnTextureFrame", | |
| 86 "()V")) { | |
| 87 CHECK_EXCEPTION(jni()) | |
| 88 << "error during initialization of SurfaceTextureHelper"; | |
| 89 } | |
| 90 | |
| 91 SurfaceTextureHelper::~SurfaceTextureHelper() { | |
| 92 } | |
| 93 | |
| 94 void SurfaceTextureHelper::ReturnTextureFrame() { | |
| 95 jni()->CallVoidMethod(*j_surface_texture_helper_, j_return_texture_method_); | |
| 96 | |
| 97 CHECK_EXCEPTION( | |
| 98 jni()) << "error during SurfaceTextureHelper.returnTextureFrame"; | |
| 99 } | |
| 100 | |
| 101 rtc::scoped_refptr<webrtc::VideoFrameBuffer> | |
| 102 SurfaceTextureHelper::CreateTextureFrame(int width, int height, | |
| 103 const NativeHandleImpl& native_handle) { | |
| 104 return new rtc::RefCountedObject<TextureBuffer>( | |
| 105 width, height, this, native_handle); | |
| 106 } | |
| 107 | |
| 108 } // namespace webrtc_jni | |
| OLD | NEW |