• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2015 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 #include "sdk/android/src/jni/jni_helpers.h"
11 
12 #include <vector>
13 
14 #include "sdk/android/native_api/jni/java_types.h"
15 
16 namespace webrtc {
17 namespace jni {
18 
NewDirectByteBuffer(JNIEnv * env,void * address,jlong capacity)19 ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
20                                                 void* address,
21                                                 jlong capacity) {
22   ScopedJavaLocalRef<jobject> buffer(
23       env, env->NewDirectByteBuffer(address, capacity));
24   CHECK_EXCEPTION(env) << "error NewDirectByteBuffer";
25   return buffer;
26 }
27 
NewGlobalRef(JNIEnv * jni,jobject o)28 jobject NewGlobalRef(JNIEnv* jni, jobject o) {
29   jobject ret = jni->NewGlobalRef(o);
30   CHECK_EXCEPTION(jni) << "error during NewGlobalRef";
31   RTC_CHECK(ret);
32   return ret;
33 }
34 
DeleteGlobalRef(JNIEnv * jni,jobject o)35 void DeleteGlobalRef(JNIEnv* jni, jobject o) {
36   jni->DeleteGlobalRef(o);
37   CHECK_EXCEPTION(jni) << "error during DeleteGlobalRef";
38 }
39 
40 // Scope Java local references to the lifetime of this object.  Use in all C++
41 // callbacks (i.e. entry points that don't originate in a Java callstack
42 // through a "native" method call).
ScopedLocalRefFrame(JNIEnv * jni)43 ScopedLocalRefFrame::ScopedLocalRefFrame(JNIEnv* jni) : jni_(jni) {
44   RTC_CHECK(!jni_->PushLocalFrame(0)) << "Failed to PushLocalFrame";
45 }
~ScopedLocalRefFrame()46 ScopedLocalRefFrame::~ScopedLocalRefFrame() {
47   jni_->PopLocalFrame(nullptr);
48 }
49 
50 }  // namespace jni
51 }  // namespace webrtc
52