blob: b781815718dfd89f2d175060b3ef69a4b4e88e7e [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
Magnus Jedverta3002db2016-05-13 12:51:04 +020041 // First crop, then scale to dst resolution, and then rotate.
42 rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate(
43 int cropped_width,
44 int cropped_height,
45 int dst_width,
Per71f5a9a2015-12-11 09:32:37 +010046 int dst_height,
47 webrtc::VideoRotation rotation);
Pera3c20bb2015-11-26 13:41:44 +010048
magjed52a30e32015-10-12 06:53:20 -070049 private:
Per488e75f2015-11-19 10:43:36 +010050 NativeHandleImpl native_handle_;
nissec490e012015-12-10 06:23:33 -080051 // Raw object pointer, relying on the caller, i.e.,
52 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep
53 // a global reference. TODO(nisse): Make this a reference to the C++
54 // SurfaceTextureHelper instead, but that requires some refactoring
55 // of AndroidVideoCapturerJni.
56 jobject surface_texture_helper_;
magjed52a30e32015-10-12 06:53:20 -070057 rtc::Callback0<void> no_longer_used_cb_;
58};
59
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000060} // namespace webrtc_jni
61
Henrik Kjellander15583c12016-02-10 10:53:12 +010062#endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_