1 /*
2 * Copyright (c) 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 "sdk/android/src/jni/wrapped_native_i420_buffer.h"
12
13 #include "sdk/android/generated_video_jni/WrappedNativeI420Buffer_jni.h"
14 #include "sdk/android/src/jni/jni_helpers.h"
15
16 namespace webrtc {
17 namespace jni {
18
19 // TODO(magjed): Write a test for this function.
WrapI420Buffer(JNIEnv * jni,const rtc::scoped_refptr<I420BufferInterface> & i420_buffer)20 ScopedJavaLocalRef<jobject> WrapI420Buffer(
21 JNIEnv* jni,
22 const rtc::scoped_refptr<I420BufferInterface>& i420_buffer) {
23 ScopedJavaLocalRef<jobject> y_buffer =
24 NewDirectByteBuffer(jni, const_cast<uint8_t*>(i420_buffer->DataY()),
25 i420_buffer->StrideY() * i420_buffer->height());
26 ScopedJavaLocalRef<jobject> u_buffer =
27 NewDirectByteBuffer(jni, const_cast<uint8_t*>(i420_buffer->DataU()),
28 i420_buffer->StrideU() * i420_buffer->ChromaHeight());
29 ScopedJavaLocalRef<jobject> v_buffer =
30 NewDirectByteBuffer(jni, const_cast<uint8_t*>(i420_buffer->DataV()),
31 i420_buffer->StrideV() * i420_buffer->ChromaHeight());
32
33 return Java_WrappedNativeI420Buffer_Constructor(
34 jni, i420_buffer->width(), i420_buffer->height(), y_buffer,
35 i420_buffer->StrideY(), u_buffer, i420_buffer->StrideU(), v_buffer,
36 i420_buffer->StrideV(), jlongFromPointer(i420_buffer.get()));
37 }
38
39 } // namespace jni
40 } // namespace webrtc
41