magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_base/refcount.h" |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 12 | #include "sdk/android/generated_base_jni/jni/JniCommon_jni.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "sdk/android/src/jni/jni_helpers.h" |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 14 | |
Sami Kalliomäki | cb98b11 | 2017-10-16 11:20:26 +0200 | [diff] [blame] | 15 | namespace webrtc { |
| 16 | namespace jni { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 17 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 18 | static void JNI_JniCommon_AddRef(JNIEnv* jni, |
| 19 | const JavaParamRef<jclass>&, |
| 20 | jlong j_native_ref_counted_pointer) { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 21 | reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer) |
| 22 | ->AddRef(); |
| 23 | } |
| 24 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 25 | static void JNI_JniCommon_ReleaseRef(JNIEnv* jni, |
| 26 | const JavaParamRef<jclass>&, |
| 27 | jlong j_native_ref_counted_pointer) { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 28 | reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer) |
| 29 | ->Release(); |
| 30 | } |
| 31 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 32 | static ScopedJavaLocalRef<jobject> JNI_JniCommon_AllocateByteBuffer( |
| 33 | JNIEnv* jni, |
| 34 | const JavaParamRef<jclass>&, |
| 35 | jint size) { |
Sami Kalliomäki | cb98b11 | 2017-10-16 11:20:26 +0200 | [diff] [blame] | 36 | void* new_data = ::operator new(size); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 37 | return NewDirectByteBuffer(jni, new_data, size); |
Sami Kalliomäki | cb98b11 | 2017-10-16 11:20:26 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 40 | static 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äki | cb98b11 | 2017-10-16 11:20:26 +0200 | [diff] [blame] | 45 | ::operator delete(data); |
| 46 | } |
| 47 | |
| 48 | } // namespace jni |
| 49 | } // namespace webrtc |