Sami Kalliomäki | f6515cd | 2017-11-02 11:25:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * 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. |
| 9 | */ |
| 10 | |
| 11 | #include <jni.h> |
| 12 | |
| 13 | #include "sdk/android/src/jni/jni_helpers.h" |
| 14 | #include "third_party/libyuv/include/libyuv/convert.h" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | namespace jni { |
| 18 | |
| 19 | JNI_FUNCTION_DECLARATION(void, |
| 20 | YuvHelper_I420Copy, |
| 21 | JNIEnv* jni, |
| 22 | jclass, |
| 23 | jobject j_src_y, |
| 24 | jint src_stride_y, |
| 25 | jobject j_src_u, |
| 26 | jint src_stride_u, |
| 27 | jobject j_src_v, |
| 28 | jint src_stride_v, |
| 29 | jobject j_dst_y, |
| 30 | jint dst_stride_y, |
| 31 | jobject j_dst_u, |
| 32 | jint dst_stride_u, |
| 33 | jobject j_dst_v, |
| 34 | jint dst_stride_v, |
| 35 | jint width, |
| 36 | jint height) { |
| 37 | const uint8_t* src_y = |
| 38 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_y)); |
| 39 | const uint8_t* src_u = |
| 40 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_u)); |
| 41 | const uint8_t* src_v = |
| 42 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_v)); |
| 43 | uint8_t* dst_y = static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_y)); |
| 44 | uint8_t* dst_u = static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_u)); |
| 45 | uint8_t* dst_v = static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_v)); |
| 46 | |
| 47 | libyuv::I420Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 48 | src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, |
| 49 | dst_v, dst_stride_v, width, height); |
| 50 | } |
| 51 | |
| 52 | JNI_FUNCTION_DECLARATION(void, |
| 53 | YuvHelper_I420ToNV12, |
| 54 | JNIEnv* jni, |
| 55 | jclass, |
| 56 | jobject j_src_y, |
| 57 | jint src_stride_y, |
| 58 | jobject j_src_u, |
| 59 | jint src_stride_u, |
| 60 | jobject j_src_v, |
| 61 | jint src_stride_v, |
| 62 | jobject j_dst_y, |
| 63 | jint dst_stride_y, |
| 64 | jobject j_dst_uv, |
| 65 | jint dst_stride_uv, |
| 66 | jint width, |
| 67 | jint height) { |
| 68 | const uint8_t* src_y = |
| 69 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_y)); |
| 70 | const uint8_t* src_u = |
| 71 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_u)); |
| 72 | const uint8_t* src_v = |
| 73 | static_cast<const uint8_t*>(jni->GetDirectBufferAddress(j_src_v)); |
| 74 | uint8_t* dst_y = static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_y)); |
| 75 | uint8_t* dst_uv = |
| 76 | static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_uv)); |
| 77 | |
| 78 | libyuv::I420ToNV12(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 79 | src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, |
| 80 | width, height); |
| 81 | } |
| 82 | |
| 83 | } // namespace jni |
| 84 | } // namespace webrtc |