blob: 859c3713b465bf1e5ffd3508132e2656a8e2b709 [file] [log] [blame]
glaznev@webrtc.org18c92472015-02-18 18:42:55 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
glaznev@webrtc.org18c92472015-02-18 18:42:55 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
glaznev@webrtc.org18c92472015-02-18 18:42:55 +00009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
12#define WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000013
Magnus Jedvert6781ea42015-10-02 13:56:04 +020014#include <jni.h>
15
kjellander6f8ce062015-11-16 13:52:24 -080016#include "webrtc/common_video/include/video_frame_buffer.h"
Per71f5a9a2015-12-11 09:32:37 +010017#include "webrtc/common_video/rotation.h"
magjed52a30e32015-10-12 06:53:20 -070018
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000019namespace webrtc_jni {
20
Per9b3f56e2015-04-09 13:44:16 +020021// Wrapper for texture object.
Per488e75f2015-11-19 10:43:36 +010022struct NativeHandleImpl {
23 NativeHandleImpl(JNIEnv* jni,
24 jint j_oes_texture_id,
25 jfloatArray j_transform_matrix);
Per9b3f56e2015-04-09 13:44:16 +020026
Magnus Jedvert91b348c2015-10-07 22:57:06 +020027 const int oes_texture_id;
28 float sampling_matrix[16];
Peter Boströmeb66e802015-06-05 11:08:03 +020029};
30
magjed52a30e32015-10-12 06:53:20 -070031class AndroidTextureBuffer : public webrtc::NativeHandleBuffer {
32 public:
33 AndroidTextureBuffer(int width,
34 int height,
Per488e75f2015-11-19 10:43:36 +010035 const NativeHandleImpl& native_handle,
nissec490e012015-12-10 06:23:33 -080036 jobject surface_texture_helper,
magjed52a30e32015-10-12 06:53:20 -070037 const rtc::Callback0<void>& no_longer_used);
38 ~AndroidTextureBuffer();
39 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
40
Per71f5a9a2015-12-11 09:32:37 +010041 rtc::scoped_refptr<AndroidTextureBuffer> ScaleAndRotate(
Pera3c20bb2015-11-26 13:41:44 +010042 int dst_widht,
Per71f5a9a2015-12-11 09:32:37 +010043 int dst_height,
44 webrtc::VideoRotation rotation);
Pera3c20bb2015-11-26 13:41:44 +010045
magjed52a30e32015-10-12 06:53:20 -070046 private:
Per488e75f2015-11-19 10:43:36 +010047 NativeHandleImpl native_handle_;
nissec490e012015-12-10 06:23:33 -080048 // Raw object pointer, relying on the caller, i.e.,
49 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep
50 // a global reference. TODO(nisse): Make this a reference to the C++
51 // SurfaceTextureHelper instead, but that requires some refactoring
52 // of AndroidVideoCapturerJni.
53 jobject surface_texture_helper_;
magjed52a30e32015-10-12 06:53:20 -070054 rtc::Callback0<void> no_longer_used_cb_;
55};
56
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000057} // namespace webrtc_jni
58
Henrik Kjellander15583c12016-02-10 10:53:12 +010059#endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_