diff --git a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc index 6d4891ee59..45396b6e83 100644 --- a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc +++ b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc @@ -34,6 +34,34 @@ namespace webrtc_jni { +namespace { + +class CameraTextureBuffer : public webrtc::NativeHandleBuffer { + public: + CameraTextureBuffer(int width, int height, + const NativeHandleImpl& native_handle, + const rtc::Callback0& no_longer_used) + : webrtc::NativeHandleBuffer(&native_handle_, width, height), + native_handle_(native_handle), + no_longer_used_cb_(no_longer_used) {} + + ~CameraTextureBuffer() { + no_longer_used_cb_(); + } + + rtc::scoped_refptr NativeToI420Buffer() override { + RTC_NOTREACHED() + << "CameraTextureBuffer::NativeToI420Buffer not implemented."; + return nullptr; + } + + private: + NativeHandleImpl native_handle_; + rtc::Callback0 no_longer_used_cb_; +}; + +} // anonymous namespace + jobject AndroidVideoCapturerJni::application_context_ = nullptr; // static @@ -185,7 +213,7 @@ void AndroidVideoCapturerJni::OnTextureFrame(int width, int64_t timestamp_ns, const NativeHandleImpl& handle) { rtc::scoped_refptr buffer( - new rtc::RefCountedObject( + new rtc::RefCountedObject( width, height, handle, rtc::Bind(&AndroidVideoCapturerJni::ReturnBuffer, this, timestamp_ns))); diff --git a/talk/app/webrtc/java/jni/native_handle_impl.cc b/talk/app/webrtc/java/jni/native_handle_impl.cc index ed9ad8e891..98af4d8b7d 100644 --- a/talk/app/webrtc/java/jni/native_handle_impl.cc +++ b/talk/app/webrtc/java/jni/native_handle_impl.cc @@ -44,24 +44,4 @@ NativeHandleImpl::NativeHandleImpl(JNIEnv* jni, jni->ReleaseFloatArrayElements(j_transform_matrix, transform_matrix_ptr, 0); } -AndroidTextureBuffer::AndroidTextureBuffer( - int width, - int height, - const NativeHandleImpl& native_handle, - const rtc::Callback0& no_longer_used) - : webrtc::NativeHandleBuffer(&native_handle_, width, height), - native_handle_(native_handle), - no_longer_used_cb_(no_longer_used) {} - -AndroidTextureBuffer::~AndroidTextureBuffer() { - no_longer_used_cb_(); -} - -rtc::scoped_refptr -AndroidTextureBuffer::NativeToI420Buffer() { - RTC_NOTREACHED() - << "AndroidTextureBuffer::NativeToI420Buffer not implemented."; - return nullptr; -} - } // namespace webrtc_jni diff --git a/talk/app/webrtc/java/jni/native_handle_impl.h b/talk/app/webrtc/java/jni/native_handle_impl.h index 16d3d7cdde..370039e50e 100644 --- a/talk/app/webrtc/java/jni/native_handle_impl.h +++ b/talk/app/webrtc/java/jni/native_handle_impl.h @@ -31,8 +31,6 @@ #include -#include "webrtc/common_video/interface/video_frame_buffer.h" - namespace webrtc_jni { // Wrapper for texture object. @@ -45,20 +43,6 @@ struct NativeHandleImpl { float sampling_matrix[16]; }; -class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { - public: - AndroidTextureBuffer(int width, - int height, - const NativeHandleImpl& native_handle, - const rtc::Callback0& no_longer_used); - ~AndroidTextureBuffer(); - rtc::scoped_refptr NativeToI420Buffer() override; - - private: - NativeHandleImpl native_handle_; - rtc::Callback0 no_longer_used_cb_; -}; - } // namespace webrtc_jni #endif // TALK_APP_WEBRTC_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ diff --git a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc index ad1db1a5f4..d161aa4aff 100644 --- a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc +++ b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc @@ -30,11 +30,35 @@ #include "talk/app/webrtc/java/jni/surfacetexturehelper_jni.h" #include "talk/app/webrtc/java/jni/classreferenceholder.h" -#include "webrtc/base/bind.h" #include "webrtc/base/checks.h" namespace webrtc_jni { +class SurfaceTextureHelper::TextureBuffer : public webrtc::NativeHandleBuffer { + public: + TextureBuffer(int width, + int height, + const rtc::scoped_refptr& pool, + const NativeHandleImpl& native_handle) + : webrtc::NativeHandleBuffer(&native_handle_, width, height), + native_handle_(native_handle), + pool_(pool) {} + + ~TextureBuffer() { + pool_->ReturnTextureFrame(); + } + + rtc::scoped_refptr NativeToI420Buffer() override { + RTC_NOTREACHED() + << "SurfaceTextureHelper::NativeToI420Buffer not implemented."; + return nullptr; + } + + private: + NativeHandleImpl native_handle_; + const rtc::scoped_refptr pool_; +}; + SurfaceTextureHelper::SurfaceTextureHelper(JNIEnv* jni, jobject egl_shared_context) : j_surface_texture_helper_class_( @@ -69,9 +93,8 @@ void SurfaceTextureHelper::ReturnTextureFrame() const { rtc::scoped_refptr SurfaceTextureHelper::CreateTextureFrame(int width, int height, const NativeHandleImpl& native_handle) { - return new rtc::RefCountedObject( - width, height, native_handle, - rtc::Bind(&SurfaceTextureHelper::ReturnTextureFrame, this)); + return new rtc::RefCountedObject( + width, height, this, native_handle); } } // namespace webrtc_jni diff --git a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h index 5bd94b5f1b..49e2315236 100644 --- a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h +++ b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h @@ -72,6 +72,7 @@ class SurfaceTextureHelper : public rtc::RefCountInterface { ~SurfaceTextureHelper(); private: + class TextureBuffer; // May be called on arbitrary thread. void ReturnTextureFrame() const;