1/* 2 * Copyright (c) 2011 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 <android/log.h> 12#include <pthread.h> 13#include <stdio.h> 14#include <string.h> 15#include <unistd.h> 16 17#include "webrtc/video_engine/test/auto_test/android/jni/org_webrtc_vieautotest_vie_autotest.h" 18 19#include "webrtc/video_engine/test/auto_test/interface/vie_autotest_android.h" 20 21#define WEBRTC_LOG_TAG "*WEBRTCN*" 22 23// VideoEngine data struct 24typedef struct 25{ 26 JavaVM* jvm; 27} VideoEngineData; 28 29// Global variables 30JavaVM* webrtcGlobalVM; 31 32// Global variables visible in this file 33static VideoEngineData vieData; 34 35// "Local" functions (i.e. not Java accessible) 36#define WEBRTC_TRACE_MAX_MESSAGE_SIZE 1024 37 38static bool GetSubAPIs(VideoEngineData& vieData); 39static bool ReleaseSubAPIs(VideoEngineData& vieData); 40 41// 42// General functions 43// 44 45// JNI_OnLoad 46jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) { 47 if (!vm) { 48 __android_log_write(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG, 49 "JNI_OnLoad did not receive a valid VM pointer"); 50 return -1; 51 } 52 53 JNIEnv* env; 54 if (JNI_OK != vm->GetEnv(reinterpret_cast<void**> (&env), 55 JNI_VERSION_1_4)) { 56 __android_log_write(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG, 57 "JNI_OnLoad could not get JNI env"); 58 return -1; 59 } 60 61 // Init ViE data 62 vieData.jvm = vm; 63 64 return JNI_VERSION_1_4; 65} 66 67// Class: org_webrtc_vieautotest_ViEAutotest 68// Method: RunTest 69// Signature: (IILandroid/opengl/GLSurfaceView;Landroid/opengl/GLSurfaceView;)I 70JNIEXPORT jint JNICALL 71Java_org_webrtc_vieautotest_ViEAutotest_RunTest__IILandroid_opengl_GLSurfaceView_2Landroid_opengl_GLSurfaceView_2( 72 JNIEnv* env, 73 jobject context, 74 jint testType, 75 jint subtestType, 76 jobject glView1, 77 jobject glView2) 78{ 79 int numErrors = -1; 80 numErrors = ViEAutoTestAndroid::RunAutotest(testType, subtestType, glView1, 81 glView2, vieData.jvm, env, 82 context); 83 return numErrors; 84} 85 86// Class: org_webrtc_vieautotest_ViEAutotest 87// Method: RunTest 88// Signature: (IILandroid/view/SurfaceView;Landroid/view/SurfaceView;)I 89JNIEXPORT jint JNICALL 90Java_org_webrtc_vieautotest_ViEAutotest_RunTest__IILandroid_view_SurfaceView_2Landroid_view_SurfaceView_2( 91 JNIEnv* env, 92 jobject context, 93 jint testType, 94 jint subtestType, 95 jobject surfaceHolder1, 96 jobject surfaceHolder2) 97{ 98 int numErrors = -1; 99 numErrors = ViEAutoTestAndroid::RunAutotest(testType, subtestType, 100 surfaceHolder1, surfaceHolder2, 101 vieData.jvm, env, context); 102 return numErrors; 103} 104 105// 106//local function 107// 108 109bool GetSubAPIs(VideoEngineData& vieData) { 110 bool retVal = true; 111 //vieData.base = ViEBase::GetInterface(vieData.vie); 112 //if (vieData.base == NULL) 113 { 114 __android_log_write(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG, 115 "Could not get Base API"); 116 retVal = false; 117 } 118 return retVal; 119} 120 121bool ReleaseSubAPIs(VideoEngineData& vieData) { 122 bool releaseOk = true; 123 //if (vieData.base) 124 { 125 //if (vieData.base->Release() != 0) 126 if (false) { 127 __android_log_write(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG, 128 "Release base sub-API failed"); 129 releaseOk = false; 130 } 131 else { 132 //vieData.base = NULL; 133 } 134 } 135 136 return releaseOk; 137} 138