1/* 2 * Copyright (c) 2013 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 <jni.h> 12 13#include <assert.h> 14 15#include "webrtc/examples/android/media_demo/jni/jni_helpers.h" 16#include "webrtc/examples/android/media_demo/jni/video_engine_jni.h" 17#include "webrtc/examples/android/media_demo/jni/voice_engine_jni.h" 18#include "webrtc/modules/video_capture/video_capture_internal.h" 19#include "webrtc/modules/video_render/video_render_internal.h" 20#include "webrtc/voice_engine/include/voe_base.h" 21 22// Macro for native functions that can be found by way of jni-auto discovery. 23// Note extern "C" is needed for "discovery" of native methods to work. 24#define JOWW(rettype, name) \ 25 extern "C" rettype JNIEXPORT JNICALL Java_org_webrtc_webrtcdemo_##name 26 27static JavaVM* g_vm = NULL; 28 29extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { 30 // Only called once. 31 CHECK(!g_vm, "OnLoad called more than once"); 32 g_vm = vm; 33 return JNI_VERSION_1_4; 34} 35 36JOWW(void, NativeWebRtcContextRegistry_register)( 37 JNIEnv* jni, 38 jclass, 39 jobject context) { 40 webrtc_examples::SetVoeDeviceObjects(g_vm); 41 webrtc_examples::SetVieDeviceObjects(g_vm); 42 CHECK(webrtc::SetCaptureAndroidVM(g_vm, context) == 0, 43 "Failed to register android objects to video capture"); 44 CHECK(webrtc::SetRenderAndroidVM(g_vm) == 0, 45 "Failed to register android objects to video render"); 46 CHECK(webrtc::VoiceEngine::SetAndroidObjects(g_vm, jni, context) == 0, 47 "Failed to register android objects to voice engine"); 48} 49 50JOWW(void, NativeWebRtcContextRegistry_unRegister)( 51 JNIEnv* jni, 52 jclass) { 53 CHECK(webrtc::SetCaptureAndroidVM(NULL, NULL) == 0, 54 "Failed to unregister android objects from video capture"); 55 CHECK(webrtc::SetRenderAndroidVM(NULL) == 0, 56 "Failed to unregister android objects from video render"); 57 CHECK(webrtc::VoiceEngine::SetAndroidObjects(NULL, NULL, NULL) == 0, 58 "Failed to unregister android objects from voice engine"); 59 webrtc_examples::ClearVieDeviceObjects(); 60 webrtc_examples::ClearVoeDeviceObjects(); 61} 62