2015-09-28 10:52:22 +02:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-09-28 10:52:22 +02:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-09-28 10:52:22 +02:00
|
|
|
*/
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
|
|
|
|
|
#define WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
|
2015-09-28 10:52:22 +02:00
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
2016-07-01 05:10:51 -07:00
|
|
|
#include "webrtc/api/android/jni/jni_helpers.h"
|
|
|
|
|
#include "webrtc/api/android/jni/native_handle_impl.h"
|
2015-09-28 10:52:22 +02:00
|
|
|
#include "webrtc/base/refcount.h"
|
|
|
|
|
#include "webrtc/base/scoped_ref_ptr.h"
|
2015-11-16 13:52:24 -08:00
|
|
|
#include "webrtc/common_video/include/video_frame_buffer.h"
|
2015-09-28 10:52:22 +02:00
|
|
|
|
|
|
|
|
namespace webrtc_jni {
|
|
|
|
|
|
|
|
|
|
// Helper class to create and synchronize access to an Android SurfaceTexture.
|
|
|
|
|
// It is used for creating webrtc::VideoFrameBuffers from a SurfaceTexture when
|
|
|
|
|
// the SurfaceTexture has been updated.
|
|
|
|
|
// When the VideoFrameBuffer is released, this class returns the buffer to the
|
|
|
|
|
// java SurfaceTextureHelper so it can be updated safely. The VideoFrameBuffer
|
|
|
|
|
// can be released on an arbitrary thread.
|
|
|
|
|
// SurfaceTextureHelper is reference counted to make sure that it is not
|
|
|
|
|
// destroyed while a VideoFrameBuffer is in use.
|
|
|
|
|
// This class is the C++ counterpart of the java class SurfaceTextureHelper.
|
2016-05-27 00:27:59 -07:00
|
|
|
// It owns the corresponding java object, and calls the java dispose
|
|
|
|
|
// method when destroyed.
|
2015-09-28 10:52:22 +02:00
|
|
|
// Usage:
|
2016-03-14 03:59:38 -07:00
|
|
|
// 1. Create an instance of this class.
|
|
|
|
|
// 2. Get the Java SurfaceTextureHelper with GetJavaSurfaceTextureHelper().
|
2015-09-28 10:52:22 +02:00
|
|
|
// 3. Register a listener to the Java SurfaceListener and start producing
|
|
|
|
|
// new buffers.
|
2015-12-18 00:37:06 -08:00
|
|
|
// 4. Call CreateTextureFrame to wrap the Java texture in a VideoFrameBuffer.
|
2015-09-28 10:52:22 +02:00
|
|
|
class SurfaceTextureHelper : public rtc::RefCountInterface {
|
|
|
|
|
public:
|
2016-05-09 08:28:45 -07:00
|
|
|
// Might return null if creating the Java SurfaceTextureHelper fails.
|
|
|
|
|
static rtc::scoped_refptr<SurfaceTextureHelper> create(
|
|
|
|
|
JNIEnv* jni, const char* thread_name, jobject j_egl_context);
|
2016-03-14 03:59:38 -07:00
|
|
|
|
|
|
|
|
jobject GetJavaSurfaceTextureHelper() const;
|
2015-09-28 10:52:22 +02:00
|
|
|
|
|
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateTextureFrame(
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
2015-11-19 10:43:36 +01:00
|
|
|
const NativeHandleImpl& native_handle);
|
2015-09-28 10:52:22 +02:00
|
|
|
|
2016-05-26 08:34:40 -07:00
|
|
|
// May be called on arbitrary thread.
|
|
|
|
|
void ReturnTextureFrame() const;
|
|
|
|
|
|
2015-09-28 10:52:22 +02:00
|
|
|
protected:
|
|
|
|
|
~SurfaceTextureHelper();
|
2016-05-09 08:28:45 -07:00
|
|
|
SurfaceTextureHelper(JNIEnv* jni, jobject j_surface_texture_helper);
|
2015-09-28 10:52:22 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const ScopedGlobalRef<jobject> j_surface_texture_helper_;
|
|
|
|
|
const jmethodID j_return_texture_method_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc_jni
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
|