Reland of Android: Put common native VideoFrameBuffer implementation in androidvideocapturer_jni (patchset #1 id:1 of https://codereview.webrtc.org/1389283003/ )

Reason for revert:
Nothing wrong with the original CL, the bug was in rtc::Bind(), which is fixed now (https://codereview.webrtc.org/1403683004/).

Original issue's description:
> Revert of Android: Put common native VideoFrameBuffer implementation in androidvideocapturer_jni (patchset #1 id:1 of https://codereview.webrtc.org/1391403004/ )
>
> Reason for revert:
> Crashes on AppRTCDemo disconnect
>
> Original issue's description:
> > Android: Put common native VideoFrameBuffer implementation in native_handle_impl.cc
> >
> > BUG=webrtc:4993
> > R=perkj@webrtc.org
> >
> > Committed: https://crrev.com/60472216da0644b49ed5f9fa51c51d4874afafa7
> > Cr-Commit-Position: refs/heads/master@{#10248}
>
> TBR=perkj@webrtc.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4993
>
> Committed: https://crrev.com/962c26bfd6c3eb3cf7402daaab89404ae38dd534
> Cr-Commit-Position: refs/heads/master@{#10249}

TBR=perkj@webrtc.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4993

Review URL: https://codereview.webrtc.org/1397373002

Cr-Commit-Position: refs/heads/master@{#10254}
diff --git a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
index 45396b6..6d4891e 100644
--- a/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
+++ b/talk/app/webrtc/java/jni/androidvideocapturer_jni.cc
@@ -34,34 +34,6 @@
 
 namespace webrtc_jni {
 
-namespace {
-
-class CameraTextureBuffer : public webrtc::NativeHandleBuffer {
- public:
-  CameraTextureBuffer(int width, int height,
-      const NativeHandleImpl& native_handle,
-      const rtc::Callback0<void>& 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<VideoFrameBuffer> NativeToI420Buffer() override {
-    RTC_NOTREACHED()
-        << "CameraTextureBuffer::NativeToI420Buffer not implemented.";
-    return nullptr;
-  }
-
- private:
-  NativeHandleImpl native_handle_;
-  rtc::Callback0<void> no_longer_used_cb_;
-};
-
-}  // anonymous namespace
-
 jobject AndroidVideoCapturerJni::application_context_ = nullptr;
 
 // static
@@ -213,7 +185,7 @@
                                              int64_t timestamp_ns,
                                              const NativeHandleImpl& handle) {
   rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
-      new rtc::RefCountedObject<CameraTextureBuffer>(
+      new rtc::RefCountedObject<AndroidTextureBuffer>(
           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 98af4d8..ed9ad8e 100644
--- a/talk/app/webrtc/java/jni/native_handle_impl.cc
+++ b/talk/app/webrtc/java/jni/native_handle_impl.cc
@@ -44,4 +44,24 @@
   jni->ReleaseFloatArrayElements(j_transform_matrix, transform_matrix_ptr, 0);
 }
 
+AndroidTextureBuffer::AndroidTextureBuffer(
+    int width,
+    int height,
+    const NativeHandleImpl& native_handle,
+    const rtc::Callback0<void>& 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<webrtc::VideoFrameBuffer>
+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 370039e..16d3d7c 100644
--- a/talk/app/webrtc/java/jni/native_handle_impl.h
+++ b/talk/app/webrtc/java/jni/native_handle_impl.h
@@ -31,6 +31,8 @@
 
 #include <jni.h>
 
+#include "webrtc/common_video/interface/video_frame_buffer.h"
+
 namespace webrtc_jni {
 
 // Wrapper for texture object.
@@ -43,6 +45,20 @@
   float sampling_matrix[16];
 };
 
+class AndroidTextureBuffer : public webrtc::NativeHandleBuffer {
+ public:
+  AndroidTextureBuffer(int width,
+                       int height,
+                       const NativeHandleImpl& native_handle,
+                       const rtc::Callback0<void>& no_longer_used);
+  ~AndroidTextureBuffer();
+  rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
+
+ private:
+  NativeHandleImpl native_handle_;
+  rtc::Callback0<void> 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 d161aa4..ad1db1a 100644
--- a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc
+++ b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc
@@ -30,35 +30,11 @@
 #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<SurfaceTextureHelper>& pool,
-                const NativeHandleImpl& native_handle)
-      : webrtc::NativeHandleBuffer(&native_handle_, width, height),
-        native_handle_(native_handle),
-        pool_(pool) {}
-
-  ~TextureBuffer() {
-    pool_->ReturnTextureFrame();
-  }
-
-  rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
-    RTC_NOTREACHED()
-        << "SurfaceTextureHelper::NativeToI420Buffer not implemented.";
-    return nullptr;
-  }
-
- private:
-  NativeHandleImpl native_handle_;
-  const rtc::scoped_refptr<SurfaceTextureHelper> pool_;
-};
-
 SurfaceTextureHelper::SurfaceTextureHelper(JNIEnv* jni,
                                            jobject egl_shared_context)
     : j_surface_texture_helper_class_(
@@ -93,8 +69,9 @@
 rtc::scoped_refptr<webrtc::VideoFrameBuffer>
 SurfaceTextureHelper::CreateTextureFrame(int width, int height,
     const NativeHandleImpl& native_handle) {
-  return new rtc::RefCountedObject<TextureBuffer>(
-      width, height, this, native_handle);
+  return new rtc::RefCountedObject<AndroidTextureBuffer>(
+      width, height, native_handle,
+      rtc::Bind(&SurfaceTextureHelper::ReturnTextureFrame, this));
 }
 
 }  // namespace webrtc_jni
diff --git a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h
index 49e2315..5bd94b5 100644
--- a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h
+++ b/talk/app/webrtc/java/jni/surfacetexturehelper_jni.h
@@ -72,7 +72,6 @@
   ~SurfaceTextureHelper();
 
  private:
-  class TextureBuffer;
   //  May be called on arbitrary thread.
   void ReturnTextureFrame() const;