blob: 2d4bbeded3eaebf2a4a6a27a8fca49a1a3b039cb [file] [log] [blame]
magjedb1c74532017-08-27 13:47:20 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/refcount.h"
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010012#include "sdk/android/generated_base_jni/jni/JniCommon_jni.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "sdk/android/src/jni/jni_helpers.h"
magjedb1c74532017-08-27 13:47:20 -070014
Sami Kalliomäkicb98b112017-10-16 11:20:26 +020015namespace webrtc {
16namespace jni {
magjedb1c74532017-08-27 13:47:20 -070017
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010018static void JNI_JniCommon_AddRef(JNIEnv* jni,
19 const JavaParamRef<jclass>&,
20 jlong j_native_ref_counted_pointer) {
magjedb1c74532017-08-27 13:47:20 -070021 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
22 ->AddRef();
23}
24
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010025static void JNI_JniCommon_ReleaseRef(JNIEnv* jni,
26 const JavaParamRef<jclass>&,
27 jlong j_native_ref_counted_pointer) {
magjedb1c74532017-08-27 13:47:20 -070028 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
29 ->Release();
30}
31
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010032static ScopedJavaLocalRef<jobject> JNI_JniCommon_AllocateByteBuffer(
33 JNIEnv* jni,
34 const JavaParamRef<jclass>&,
35 jint size) {
Sami Kalliomäkicb98b112017-10-16 11:20:26 +020036 void* new_data = ::operator new(size);
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010037 return NewDirectByteBuffer(jni, new_data, size);
Sami Kalliomäkicb98b112017-10-16 11:20:26 +020038}
39
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010040static void JNI_JniCommon_FreeByteBuffer(
41 JNIEnv* jni,
42 const JavaParamRef<jclass>&,
43 const JavaParamRef<jobject>& byte_buffer) {
44 void* data = jni->GetDirectBufferAddress(byte_buffer.obj());
Sami Kalliomäkicb98b112017-10-16 11:20:26 +020045 ::operator delete(data);
46}
47
48} // namespace jni
49} // namespace webrtc