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 "rtc_base/ref_count.h"
12 #include "sdk/android/generated_base_jni/JniCommon_jni.h"
13 #include "sdk/android/src/jni/jni_helpers.h"
14
15 namespace webrtc {
16 namespace jni {
17
JNI_JniCommon_AddRef(JNIEnv * jni,jlong j_native_ref_counted_pointer)18 static void JNI_JniCommon_AddRef(JNIEnv* jni,
19 jlong j_native_ref_counted_pointer) {
20 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
21 ->AddRef();
22 }
23
JNI_JniCommon_ReleaseRef(JNIEnv * jni,jlong j_native_ref_counted_pointer)24 static void JNI_JniCommon_ReleaseRef(JNIEnv* jni,
25 jlong j_native_ref_counted_pointer) {
26 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
27 ->Release();
28 }
29
JNI_JniCommon_AllocateByteBuffer(JNIEnv * jni,jint size)30 static ScopedJavaLocalRef<jobject> JNI_JniCommon_AllocateByteBuffer(
31 JNIEnv* jni,
32 jint size) {
33 void* new_data = ::operator new(size);
34 return NewDirectByteBuffer(jni, new_data, size);
35 }
36
JNI_JniCommon_FreeByteBuffer(JNIEnv * jni,const JavaParamRef<jobject> & byte_buffer)37 static void JNI_JniCommon_FreeByteBuffer(
38 JNIEnv* jni,
39 const JavaParamRef<jobject>& byte_buffer) {
40 void* data = jni->GetDirectBufferAddress(byte_buffer.obj());
41 ::operator delete(data);
42 }
43
44 } // namespace jni
45 } // namespace webrtc
46