static jobject android_os_Parcel_dupFileDescriptor(JNIEnv* env, jclass clazz, jobject orig) { if (orig == NULL) { jniThrowNullPointerException(env, NULL); return NULL; } int origfd = jniGetFDFromFileDescriptor(env, orig); if (origfd < 0) { jniThrowException(env, "java/lang/IllegalArgumentException", "bad FileDescriptor"); return NULL; } int fd = dup(origfd); if (fd < 0) { jniThrowIOException(env, errno); return NULL; } jobject object = jniCreateFileDescriptor(env, fd); if (object == NULL) { close(fd); } return object; }
static void socket_writeba (JNIEnv *env, jobject object, jbyteArray buffer, jint off, jint len, jobject fileDescriptor) { int fd; int err; jbyte* byteBuffer; if (fileDescriptor == NULL || buffer == NULL) { jniThrowNullPointerException(env, NULL); return; } if (off < 0 || len < 0 || (off + len) > env->GetArrayLength(buffer)) { jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", NULL); return; } fd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (env->ExceptionCheck()) { return; } byteBuffer = env->GetByteArrayElements(buffer,NULL); if (NULL == byteBuffer) { // an exception will have been thrown return; } err = socket_write_all(env, object, fd, byteBuffer + off, len); UNUSED(err); // A return of -1 above means an exception is pending env->ReleaseByteArrayElements(buffer, byteBuffer, JNI_ABORT); }
static void android_graphics_getPixelFormatInfo( JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) { PixelFormatInfo info; status_t err; // we need this for backward compatibility with PixelFormat's // deprecated constants switch (format) { case HAL_PIXEL_FORMAT_YCbCr_422_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; case HAL_PIXEL_FORMAT_YCrCb_420_SP: case HAL_PIXEL_FORMAT_YCbCr_420_SP: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 12; goto done; case HAL_PIXEL_FORMAT_YCbCr_422_I: // defined as the bytes per pixel of the Y plane info.bytesPerPixel = 1; info.bitsPerPixel = 16; goto done; } err = getPixelFormatInfo(format, &info); if (err < 0) { jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } done: env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); }
static void nativeSetPageBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, PageBox pageBox, jobject box) { FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); FPDF_PAGE page = FPDF_LoadPage(document, pageIndex); if (!page) { jniThrowException(env, "java/lang/IllegalStateException", "cannot open page"); return; } const int left = env->GetIntField(box, gRectClassInfo.left); const int top = env->GetIntField(box, gRectClassInfo.top); const int right = env->GetIntField(box, gRectClassInfo.right); const int bottom = env->GetIntField(box, gRectClassInfo.bottom); if (pageBox == PAGE_BOX_MEDIA) { FPDFPage_SetMediaBox(page, left, top, right, bottom); } else { FPDFPage_SetCropBox(page, left, top, right, bottom); } FPDF_ClosePage(page); }
JNIEXPORT void android_media_omxmediaplayer_seekTo(JNIEnv *env, jobject thiz, int msec) { IPlayer* mp = getOMXMediaPlayer(env, thiz); if (mp == NULL ) { jniThrowException(env, "java/lang/IllegalStateException", NULL); return; } int playTime = 0; mp->getCurrentPosition(&playTime); int mediaDiff = msec - playTime; // msec mediaDiff = mediaDiff>0 ? mediaDiff : -mediaDiff; if(mediaDiff > 2000) // 2sec { PPLOGD("jni seekTo: %d(msec)", msec); mp->seekTo(msec); PPLOGD("jni seekTo: %d(msec) end", msec); } else { mp->notify(MEDIA_SEEK_COMPLETE, 0, 0); } }
/* void glDebugMessageInsertKHR ( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf ) */ static void android_glDebugMessageInsertKHR__IIIILjava_lang_String_2 (JNIEnv *_env, jobject _this, jint source, jint type, jint id, jint severity, jstring buf) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; const char* _nativebuf = 0; jint _length = 0; if (!buf) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "buf == null"; goto exit; } _nativebuf = _env->GetStringUTFChars(buf, 0); _length = _env->GetStringUTFLength(buf); glDebugMessageInsertKHR( (GLenum)source, (GLenum)type, (GLuint)id, (GLenum)severity, (GLsizei)_length, (GLchar *)_nativebuf ); exit: if (_nativebuf) { _env->ReleaseStringUTFChars(buf, _nativebuf); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } }
static jboolean SystemProperties_get_boolean(JNIEnv *env, jobject clazz, jstring keyJ, jboolean defJ) { int len; const char* key; char buf[PROPERTY_VALUE_MAX]; jboolean result = defJ; if (keyJ == NULL) { jniThrowException(env, "java/lang/NullPointerException", "key must not be null."); goto error; } key = env->GetStringUTFChars(keyJ, NULL); len = property_get(key, buf, ""); if (len == 1) { char ch = buf[0]; if (ch == '0' || ch == 'n') result = false; else if (ch == '1' || ch == 'y') result = true; } else if (len > 1) { if (!strcmp(buf, "no") || !strcmp(buf, "false") || !strcmp(buf, "off")) { result = false; } else if (!strcmp(buf, "yes") || !strcmp(buf, "true") || !strcmp(buf, "on")) { result = true; } } env->ReleaseStringUTFChars(keyJ, key); error: return result; }
static jlong harmony_io_readImpl(JNIEnv* env, jobject, jint fd, jbyteArray byteArray, jint offset, jint nbytes) { if (nbytes == 0) { return 0; } jbyte* bytes = env->GetByteArrayElements(byteArray, NULL); jlong rc = TEMP_FAILURE_RETRY(read(fd, bytes + offset, nbytes)); env->ReleaseByteArrayElements(byteArray, bytes, 0); if (rc == 0) { return -1; } if (rc == -1) { if (errno == EAGAIN) { jniThrowException(env, "java/io/InterruptedIOException", "Read timed out"); } else { jniThrowIOException(env, errno); } } return rc; }
static jobject socket_get_peer_credentials(JNIEnv *env, jobject object, jobject fileDescriptor) { int err; int fd; if (fileDescriptor == NULL) { jniThrowException(env, "java/lang/NullPointerException", NULL); return NULL; } fd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (env->ExceptionOccurred() != NULL) { return NULL; } struct ucred creds; memset(&creds, 0, sizeof(creds)); socklen_t szCreds = sizeof(creds); err = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds); if (err < 0) { jniThrowIOException(env, errno); return NULL; } if (szCreds == 0) { return NULL; } return env->NewObject(class_Credentials, method_CredentialsInit, creds.pid, creds.uid, creds.gid); }
/* throw a SQLiteException for a given error code, sqlite3message, and user message */ void throw_sqlite3_exception(JNIEnv* env, int errcode, const char* sqlite3Message, const char* message) { const char* exceptionClass; switch (errcode) { case SQLITE_IOERR: exceptionClass = "android/database/sqlite/SQLiteDiskIOException"; break; case SQLITE_CORRUPT: case SQLITE_NOTADB: // treat "unsupported file format" error as corruption also exceptionClass = "android/database/sqlite/SQLiteDatabaseCorruptException"; break; case SQLITE_CONSTRAINT: exceptionClass = "android/database/sqlite/SQLiteConstraintException"; break; case SQLITE_ABORT: exceptionClass = "android/database/sqlite/SQLiteAbortException"; break; case SQLITE_DONE: exceptionClass = "android/database/sqlite/SQLiteDoneException"; break; case SQLITE_FULL: exceptionClass = "android/database/sqlite/SQLiteFullException"; break; case SQLITE_MISUSE: exceptionClass = "android/database/sqlite/SQLiteMisuseException"; break; case SQLITE_PERM: exceptionClass = "android/database/sqlite/SQLiteAccessPermException"; break; case SQLITE_BUSY: exceptionClass = "android/database/sqlite/SQLiteDatabaseLockedException"; break; case SQLITE_LOCKED: exceptionClass = "android/database/sqlite/SQLiteTableLockedException"; break; case SQLITE_READONLY: exceptionClass = "android/database/sqlite/SQLiteReadOnlyDatabaseException"; break; case SQLITE_CANTOPEN: exceptionClass = "android/database/sqlite/SQLiteCantOpenDatabaseException"; break; case SQLITE_TOOBIG: exceptionClass = "android/database/sqlite/SQLiteBlobTooBigException"; break; case SQLITE_RANGE: exceptionClass = "android/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException"; break; case SQLITE_NOMEM: exceptionClass = "android/database/sqlite/SQLiteOutOfMemoryException"; break; case SQLITE_MISMATCH: exceptionClass = "android/database/sqlite/SQLiteDatatypeMismatchException"; break; case SQLITE_UNCLOSED: exceptionClass = "android/database/sqlite/SQLiteUnfinalizedObjectsException"; break; default: exceptionClass = "android/database/sqlite/SQLiteException"; break; } if (sqlite3Message != NULL && message != NULL) { char* fullMessage = (char *)malloc(strlen(sqlite3Message) + strlen(message) + 3); if (fullMessage != NULL) { strcpy(fullMessage, sqlite3Message); strcat(fullMessage, ": "); strcat(fullMessage, message); jniThrowException(env, exceptionClass, fullMessage); free(fullMessage); } else { jniThrowException(env, exceptionClass, sqlite3Message); } } else if (sqlite3Message != NULL) { jniThrowException(env, exceptionClass, sqlite3Message); } else { jniThrowException(env, exceptionClass, message); } }
/* public native void dbopen(String path, int flags, String locale); */ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags) { int err; sqlite3 * handle = NULL; sqlite3_stmt * statement = NULL; char const * path8 = env->GetStringUTFChars(pathString, NULL); int sqliteFlags; // register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called. registerLoggingFunc(path8); // convert our flags into the sqlite flags if (flags & CREATE_IF_NECESSARY) { sqliteFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; } else if (flags & OPEN_READONLY) { sqliteFlags = SQLITE_OPEN_READONLY; } else { sqliteFlags = SQLITE_OPEN_READWRITE; } err = sqlite3_open_v2(path8, &handle, sqliteFlags, NULL); if (err != SQLITE_OK) { LOGE("sqlite3_open_v2(\"%s\", &handle, %d, NULL) failed\n", path8, sqliteFlags); throw_sqlite3_exception(env, handle); goto done; } // The soft heap limit prevents the page cache allocations from growing // beyond the given limit, no matter what the max page cache sizes are // set to. The limit does not, as of 3.5.0, affect any other allocations. sqlite3_soft_heap_limit(sSqliteSoftHeapLimit); // Set the default busy handler to retry for 1000ms and then return SQLITE_BUSY err = sqlite3_busy_timeout(handle, 1000 /* ms */); if (err != SQLITE_OK) { LOGE("sqlite3_busy_timeout(handle, 1000) failed for \"%s\"\n", path8); throw_sqlite3_exception(env, handle); goto done; } #ifdef DB_INTEGRITY_CHECK static const char* integritySql = "pragma integrity_check(1);"; err = sqlite3_prepare_v2(handle, integritySql, -1, &statement, NULL); if (err != SQLITE_OK) { LOGE("sqlite_prepare_v2(handle, \"%s\") failed for \"%s\"\n", integritySql, path8); throw_sqlite3_exception(env, handle); goto done; } // first is OK or error message err = sqlite3_step(statement); if (err != SQLITE_ROW) { LOGE("integrity check failed for \"%s\"\n", integritySql, path8); throw_sqlite3_exception(env, handle); goto done; } else { const char *text = (const char*)sqlite3_column_text(statement, 0); if (strcmp(text, "ok") != 0) { LOGE("integrity check failed for \"%s\": %s\n", integritySql, path8, text); jniThrowException(env, "android/database/sqlite/SQLiteDatabaseCorruptException", text); goto done; } } #endif err = register_android_functions(handle, UTF16_STORAGE); if (err) { throw_sqlite3_exception(env, handle); goto done; } LOGV("Opened '%s' - %p\n", path8, handle); env->SetIntField(object, offset_db_handle, (int) handle); handle = NULL; // The caller owns the handle now. done: // Release allocated resources if (path8 != NULL) env->ReleaseStringUTFChars(pathString, path8); if (statement != NULL) sqlite3_finalize(statement); if (handle != NULL) sqlite3_close(handle); }
/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ static jstring android_glGetActiveAttrib1 (JNIEnv *_env, jobject _this, jint program, jint index, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset) { jint _exception = 0; const char * _exceptionType; const char * _exceptionMessage; GLint *size_base = (GLint *) 0; jint _sizeRemaining; GLint *size = (GLint *) 0; GLenum *type_base = (GLenum *) 0; jint _typeRemaining; GLenum *type = (GLenum *) 0; jstring result = 0; GLint len = 0; glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len); if (!len) { return _env->NewStringUTF(""); } char* buf = (char*) malloc(len); if (buf == NULL) { jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); return NULL; } if (!size_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "size == null"; goto exit; } if (sizeOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "sizeOffset < 0"; goto exit; } _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; size_base = (GLint *) _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); size = size_base + sizeOffset; if (!type_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "type == null"; goto exit; } if (typeOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "typeOffset < 0"; goto exit; } _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; type_base = (GLenum *) _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); type = type_base + typeOffset; glGetActiveAttrib( (GLuint)program, (GLuint)index, (GLsizei)len, NULL, (GLint *)size, (GLenum *)type, (char *)buf ); exit: if (type_base) { _env->ReleasePrimitiveArrayCritical(type_ref, type_base, _exception ? JNI_ABORT: 0); } if (size_base) { _env->ReleasePrimitiveArrayCritical(size_ref, size_base, _exception ? JNI_ABORT: 0); } if (_exception != 1) { result = _env->NewStringUTF(buf); } if (buf) { free(buf); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } if (result == 0) { result = _env->NewStringUTF(""); } return result; }
/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */ static void android_glGetActiveAttrib__III_3II_3II_3II_3BI (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jintArray length_ref, jint lengthOffset, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset, jbyteArray name_ref, jint nameOffset) { jint _exception = 0; const char * _exceptionType; const char * _exceptionMessage; GLsizei *length_base = (GLsizei *) 0; jint _lengthRemaining; GLsizei *length = (GLsizei *) 0; GLint *size_base = (GLint *) 0; jint _sizeRemaining; GLint *size = (GLint *) 0; GLenum *type_base = (GLenum *) 0; jint _typeRemaining; GLenum *type = (GLenum *) 0; char *name_base = (char *) 0; jint _nameRemaining; char *name = (char *) 0; if (!length_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length == null"; goto exit; } if (lengthOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "lengthOffset < 0"; goto exit; } _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset; length_base = (GLsizei *) _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0); length = length_base + lengthOffset; if (!size_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "size == null"; goto exit; } if (sizeOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "sizeOffset < 0"; goto exit; } _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset; size_base = (GLint *) _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0); size = size_base + sizeOffset; if (!type_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "type == null"; goto exit; } if (typeOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "typeOffset < 0"; goto exit; } _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset; type_base = (GLenum *) _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0); type = type_base + typeOffset; if (!name_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "name == null"; goto exit; } if (nameOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "nameOffset < 0"; goto exit; } _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset; name_base = (char *) _env->GetPrimitiveArrayCritical(name_ref, (jboolean *)0); name = name_base + nameOffset; glGetActiveAttrib( (GLuint)program, (GLuint)index, (GLsizei)bufsize, (GLsizei *)length, (GLint *)size, (GLenum *)type, (char *)name ); exit: if (name_base) { _env->ReleasePrimitiveArrayCritical(name_ref, name_base, _exception ? JNI_ABORT: 0); } if (type_base) { _env->ReleasePrimitiveArrayCritical(type_ref, type_base, _exception ? JNI_ABORT: 0); } if (size_base) { _env->ReleasePrimitiveArrayCritical(size_ref, size_base, _exception ? JNI_ABORT: 0); } if (length_base) { _env->ReleasePrimitiveArrayCritical(length_ref, length_base, _exception ? JNI_ABORT: 0); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } }
/* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */ static void android_glGetShaderSource__II_3II_3BI (JNIEnv *_env, jobject _this, jint shader, jint bufsize, jintArray length_ref, jint lengthOffset, jbyteArray source_ref, jint sourceOffset) { jint _exception = 0; const char * _exceptionType; const char * _exceptionMessage; GLsizei *length_base = (GLsizei *) 0; jint _lengthRemaining; GLsizei *length = (GLsizei *) 0; char *source_base = (char *) 0; jint _sourceRemaining; char *source = (char *) 0; if (!length_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length == null"; goto exit; } if (lengthOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "lengthOffset < 0"; goto exit; } _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset; length_base = (GLsizei *) _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0); length = length_base + lengthOffset; if (!source_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "source == null"; goto exit; } if (sourceOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "sourceOffset < 0"; goto exit; } _sourceRemaining = _env->GetArrayLength(source_ref) - sourceOffset; source_base = (char *) _env->GetPrimitiveArrayCritical(source_ref, (jboolean *)0); source = source_base + sourceOffset; glGetShaderSource( (GLuint)shader, (GLsizei)bufsize, (GLsizei *)length, (char *)source ); exit: if (source_base) { _env->ReleasePrimitiveArrayCritical(source_ref, source_base, _exception ? JNI_ABORT: 0); } if (length_base) { _env->ReleasePrimitiveArrayCritical(length_ref, length_base, _exception ? JNI_ABORT: 0); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } }
void doThrowIOE(JNIEnv* env, const char* msg) { jniThrowException(env, "java/io/IOException", msg); }
void doThrowISE(JNIEnv* env, const char* msg) { jniThrowException(env, "java/lang/IllegalStateException", msg); }
static void jniThrowExpatException(JNIEnv* env, XML_Error error) { const char* message = XML_ErrorString(error); jniThrowException(env, "org/apache/harmony/xml/ExpatException", message); }
/* EGLContext eglCreateContext ( EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list ) */ static jobject android_eglCreateContext (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject share_context, jintArray attrib_list_ref, jint offset) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; EGLContext _returnValue = (EGLContext) 0; EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); EGLContext share_context_native = (EGLContext) fromEGLHandle(_env, eglcontextGetHandleID, share_context); bool attrib_list_sentinel = false; EGLint *attrib_list_base = (EGLint *) 0; jint _remaining; EGLint *attrib_list = (EGLint *) 0; if (!attrib_list_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list == null"; goto exit; } if (offset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "offset < 0"; goto exit; } _remaining = _env->GetArrayLength(attrib_list_ref) - offset; attrib_list_base = (EGLint *) _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); attrib_list = attrib_list_base + offset; attrib_list_sentinel = false; for (int i = _remaining - 1; i >= 0; i--) { if (attrib_list[i] == EGL_NONE){ attrib_list_sentinel = true; break; } } if (attrib_list_sentinel == false) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list must contain EGL_NONE!"; goto exit; } _returnValue = eglCreateContext( (EGLDisplay)dpy_native, (EGLConfig)config_native, (EGLContext)share_context_native, (EGLint *)attrib_list ); exit: if (attrib_list_base) { _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, JNI_ABORT); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } return toEGLHandle(_env, eglcontextClass, eglcontextConstructor, _returnValue); }
void signalExceptionForError(JNIEnv* env, jobject obj, status_t err, bool canThrowRemoteException) { switch (err) { case UNKNOWN_ERROR: jniThrowException(env, "java/lang/RuntimeException", "Unknown error"); break; case NO_MEMORY: jniThrowException(env, "java/lang/OutOfMemoryError", NULL); break; case INVALID_OPERATION: jniThrowException(env, "java/lang/UnsupportedOperationException", NULL); break; case BAD_VALUE: jniThrowException(env, "java/lang/IllegalArgumentException", NULL); break; case BAD_INDEX: jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL); break; case BAD_TYPE: jniThrowException(env, "java/lang/IllegalArgumentException", NULL); break; case NAME_NOT_FOUND: jniThrowException(env, "java/util/NoSuchElementException", NULL); break; case PERMISSION_DENIED: jniThrowException(env, "java/lang/SecurityException", NULL); break; case NOT_ENOUGH_DATA: jniThrowException(env, "android/os/ParcelFormatException", "Not enough data"); break; case NO_INIT: jniThrowException(env, "java/lang/RuntimeException", "Not initialized"); break; case ALREADY_EXISTS: jniThrowException(env, "java/lang/RuntimeException", "Item already exists"); break; case DEAD_OBJECT: // DeadObjectException is a checked exception, only throw from certain methods. jniThrowException(env, canThrowRemoteException ? "android/os/DeadObjectException" : "java/lang/RuntimeException", NULL); break; case UNKNOWN_TRANSACTION: jniThrowException(env, "java/lang/RuntimeException", "Unknown transaction code"); break; case FAILED_TRANSACTION: ALOGE("!!! FAILED BINDER TRANSACTION !!!"); // TransactionTooLargeException is a checked exception, only throw from certain methods. // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION // but it is not the only one. The Binder driver can return BR_FAILED_REPLY // for other reasons also, such as if the transaction is malformed or // refers to an FD that has been closed. We should change the driver // to enable us to distinguish these cases in the future. jniThrowException(env, canThrowRemoteException ? "android/os/TransactionTooLargeException" : "java/lang/RuntimeException", NULL); break; case FDS_NOT_ALLOWED: jniThrowException(env, "java/lang/RuntimeException", "Not allowed to write file descriptors here"); break; case -EBADF: jniThrowException(env, "java/lang/RuntimeException", "Bad file descriptor"); break; case -ENFILE: jniThrowException(env, "java/lang/RuntimeException", "File table overflow"); break; case -EMFILE: jniThrowException(env, "java/lang/RuntimeException", "Too many open files"); break; case -EFBIG: jniThrowException(env, "java/lang/RuntimeException", "File too large"); break; case -ENOSPC: jniThrowException(env, "java/lang/RuntimeException", "No space left on device"); break; case -ESPIPE: jniThrowException(env, "java/lang/RuntimeException", "Illegal seek"); break; case -EROFS: jniThrowException(env, "java/lang/RuntimeException", "Read-only file system"); break; case -EMLINK: jniThrowException(env, "java/lang/RuntimeException", "Too many links"); break; default: ALOGE("Unknown binder error code. 0x%" PRIx32, err); String8 msg; msg.appendFormat("Unknown binder error code. 0x%" PRIx32, err); // RemoteException is a checked exception, only throw from certain methods. jniThrowException(env, canThrowRemoteException ? "android/os/RemoteException" : "java/lang/RuntimeException", msg.string()); break; } }
/* EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */ static jboolean android_eglChooseConfig (JNIEnv *_env, jobject _this, jobject dpy, jintArray attrib_list_ref, jint attrib_listOffset, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; EGLBoolean _returnValue = (EGLBoolean) 0; EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); bool attrib_list_sentinel = false; EGLint *attrib_list_base = (EGLint *) 0; jint _attrib_listRemaining; EGLint *attrib_list = (EGLint *) 0; jint _configsRemaining; EGLConfig *configs = (EGLConfig *) 0; EGLint *num_config_base = (EGLint *) 0; jint _num_configRemaining; EGLint *num_config = (EGLint *) 0; if (!attrib_list_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list == null"; goto exit; } if (attrib_listOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_listOffset < 0"; goto exit; } _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - attrib_listOffset; attrib_list_base = (EGLint *) _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); attrib_list = attrib_list_base + attrib_listOffset; attrib_list_sentinel = false; for (int i = _attrib_listRemaining - 1; i >= 0; i--) { if (attrib_list[i] == EGL_NONE){ attrib_list_sentinel = true; break; } } if (attrib_list_sentinel == false) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list must contain EGL_NONE!"; goto exit; } if (!configs_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "configs == null"; goto exit; } if (configsOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "configsOffset < 0"; goto exit; } _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset; if (_configsRemaining < config_size) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length - configsOffset < config_size < needed"; goto exit; } configs = new EGLConfig[_configsRemaining]; if (!num_config_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "num_config == null"; goto exit; } if (num_configOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "num_configOffset < 0"; goto exit; } _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset; if (_num_configRemaining < 1) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length - num_configOffset < 1 < needed"; goto exit; } num_config_base = (EGLint *) _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0); num_config = num_config_base + num_configOffset; _returnValue = eglChooseConfig( (EGLDisplay)dpy_native, (EGLint *)attrib_list, (EGLConfig *)configs, (EGLint)config_size, (EGLint *)num_config ); exit: if (num_config_base) { _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base, _exception ? JNI_ABORT: 0); } if (attrib_list_base) { _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, JNI_ABORT); } if (configs) { for (int i = 0; i < _configsRemaining; i++) { jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]); _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new); } delete[] configs; } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } return (jboolean)_returnValue; }
/* EGLBoolean eglGetConfigs ( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config ) */ static jboolean android_eglGetConfigs (JNIEnv *_env, jobject _this, jobject dpy, jobjectArray configs_ref, jint configsOffset, jint config_size, jintArray num_config_ref, jint num_configOffset) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; EGLBoolean _returnValue = (EGLBoolean) 0; EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); jint _configsRemaining; EGLConfig *configs = (EGLConfig *) 0; EGLint *num_config_base = (EGLint *) 0; jint _num_configRemaining; EGLint *num_config = (EGLint *) 0; if (!configs_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "configs == null"; goto exit; } if (configsOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "configsOffset < 0"; goto exit; } _configsRemaining = _env->GetArrayLength(configs_ref) - configsOffset; if (_configsRemaining < config_size) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length - configsOffset < config_size < needed"; goto exit; } configs = new EGLConfig[_configsRemaining]; if (!num_config_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "num_config == null"; goto exit; } if (num_configOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "num_configOffset < 0"; goto exit; } _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset; num_config_base = (EGLint *) _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0); num_config = num_config_base + num_configOffset; _returnValue = eglGetConfigs( (EGLDisplay)dpy_native, (EGLConfig *)configs, (EGLint)config_size, (EGLint *)num_config ); exit: if (num_config_base) { _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base, _exception ? JNI_ABORT: 0); } if (configs) { for (int i = 0; i < _configsRemaining; i++) { jobject configs_new = toEGLHandle(_env, eglconfigClass, eglconfigConstructor, configs[i]); _env->SetObjectArrayElement(configs_ref, i + configsOffset, configs_new); } delete[] configs; } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } return (jboolean)_returnValue; }
/* EGLBoolean eglInitialize ( EGLDisplay dpy, EGLint *major, EGLint *minor ) */ static jboolean android_eglInitialize (JNIEnv *_env, jobject _this, jobject dpy, jintArray major_ref, jint majorOffset, jintArray minor_ref, jint minorOffset) { jint _exception = 0; const char * _exceptionType = NULL; const char * _exceptionMessage = NULL; EGLBoolean _returnValue = (EGLBoolean) 0; EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); EGLint *major_base = (EGLint *) 0; jint _majorRemaining; EGLint *major = (EGLint *) 0; EGLint *minor_base = (EGLint *) 0; jint _minorRemaining; EGLint *minor = (EGLint *) 0; if (!major_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "major == null"; goto exit; } if (majorOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "majorOffset < 0"; goto exit; } _majorRemaining = _env->GetArrayLength(major_ref) - majorOffset; if (_majorRemaining < 1) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length - majorOffset < 1 < needed"; goto exit; } major_base = (EGLint *) _env->GetPrimitiveArrayCritical(major_ref, (jboolean *)0); major = major_base + majorOffset; if (!minor_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "minor == null"; goto exit; } if (minorOffset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "minorOffset < 0"; goto exit; } _minorRemaining = _env->GetArrayLength(minor_ref) - minorOffset; if (_minorRemaining < 1) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "length - minorOffset < 1 < needed"; goto exit; } minor_base = (EGLint *) _env->GetPrimitiveArrayCritical(minor_ref, (jboolean *)0); minor = minor_base + minorOffset; _returnValue = eglInitialize( (EGLDisplay)dpy_native, (EGLint *)major, (EGLint *)minor ); exit: if (minor_base) { _env->ReleasePrimitiveArrayCritical(minor_ref, minor_base, _exception ? JNI_ABORT: 0); } if (major_base) { _env->ReleasePrimitiveArrayCritical(major_ref, major_base, _exception ? JNI_ABORT: 0); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } return (jboolean)_returnValue; }
void doThrowAIOOBE(JNIEnv* env) { jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", NULL); }
JNIEXPORT void JNICALL Java_com_lge_ccdevs_tracker_CameraPreview_native_1cv_1init__Landroid_graphics_Bitmap_2_3F (JNIEnv *env, jobject thiz, jobject srcimg, jfloatArray pts) { jclass clazz; clazz = env->FindClass(kClassPathName); if (clazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find com/lge/ccdevs/tracker/CameraActivity"); return; } fields.bitmapClazz = env->FindClass("android/graphics/Bitmap"); if (fields.bitmapClazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find android/graphics/Bitmap"); return; } fields.fileClazz = env->FindClass("java/io/File"); if (fields.fileClazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find java/io/File"); return; } // convert img AndroidBitmapInfo bInfo; char *bPixs; int bRet; if ((bRet = AndroidBitmap_getInfo(env, srcimg, &bInfo)) < 0) { LOGE("AndroidBitmap_getInfo failed(src)! error = %d", bRet); return; } if (bInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { LOGE("Bitmap(src) format is not RGBA_8888!"); return; } if ((bRet = AndroidBitmap_lockPixels(env, srcimg, (void**)&bPixs)) < 0) { LOGE("AndroidBitmap_lockPixels() failed(src)! error = %d", bRet); return; } IplImage* bimg = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 4); memcpy(bimg->imageData, bPixs, bimg->imageSize); AndroidBitmap_unlockPixels(env, srcimg); IplImage* img = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 3); cvCvtColor(bimg, img, CV_RGBA2BGR); // test capture Converter::saveJPG("/sdcard/tracker/matcher_init.jpg", img); // convert to float[8] jfloat* fpts = env->GetFloatArrayElements(pts,0); float points[8]; for(int i=0; i<8; i++) { points[i] = fpts[i]; } LOGE("#### assign initial pts = (%f,%f), (%f,%f), (%f,%f), (%f,%f) )", points[0], points[1], points[2], points[3], points[4], points[5], points[6], points[7] ); matcher = new Matcher(img, points); res_pts = new float[8]; cvReleaseImage( &bimg ); cvReleaseImage( &img ); }
void doThrowIAE(JNIEnv* env, const char* msg) { jniThrowException(env, "java/lang/IllegalArgumentException", msg); }
int AssetManagerGlue::retrieveArray(int id, NativeArray<int>& array) { const ResTable& res(getResources()); ResTable_config config; Res_value value; ssize_t block; const size_t NV = array.length(); // Now lock down the resource object and start pulling stuff from it. res.lock(); const ResTable::bag_entry* arrayEnt = NULL; uint32_t arrayTypeSetFlags = 0; ssize_t bagOff = res.getBagLocked(id, &arrayEnt, &arrayTypeSetFlags); const ResTable::bag_entry* endArrayEnt = arrayEnt + (bagOff >= 0 ? bagOff : 0); size_t i = 0; off_t offset = 0; uint32_t typeSetFlags; while (i < NV && arrayEnt < endArrayEnt) { block = arrayEnt->stringBlock; typeSetFlags = arrayTypeSetFlags; config.density = 0; value = arrayEnt->map.value; uint32_t resid = 0; if (value.dataType != Res_value::TYPE_NULL) { // Take care of resolving the found resource to its final value. //printf("Resolving attribute reference\n"); ssize_t newBlock = res.resolveReference(&value, block, &resid, &typeSetFlags, &config); #if THROW_ON_BAD_ID if (newBlock == BAD_INDEX) { jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); return JNI_FALSE; } #endif if (newBlock >= 0) block = newBlock; } // Deal with the special @null value -- it turns back to TYPE_NULL. if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) { value.dataType = Res_value::TYPE_NULL; } //printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data); // Write the final value back to Java. array.set(offset + STYLE_TYPE, value.dataType); array.set(offset + STYLE_DATA, value.data); array.set(offset + STYLE_ASSET_COOKIE, (int)(long)res.getTableCookie(block)); array.set(offset + STYLE_RESOURCE_ID, resid); array.set(offset + STYLE_CHANGING_CONFIGURATIONS, typeSetFlags); array.set(offset + STYLE_DENSITY, config.density); offset += STYLE_NUM_ENTRIES; i+= STYLE_NUM_ENTRIES; arrayEnt++; } i /= STYLE_NUM_ENTRIES; res.unlock(); return i; }
void doThrowOOME(JNIEnv* env, const char* msg) { jniThrowException(env, "java/lang/OutOfMemoryError", msg); }
static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) { if (jniThrowException(env, exc, msg) != 0) assert(false); }
/* EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list ) */ static jobject android_eglCreateWindowSurfaceTexture (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jobject win, jintArray attrib_list_ref, jint offset) { jint _exception = 0; const char * _exceptionType = ""; const char * _exceptionMessage = ""; EGLSurface _returnValue = (EGLSurface) 0; EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy); EGLConfig config_native = (EGLConfig) fromEGLHandle(_env, eglconfigGetHandleID, config); int attrib_list_sentinel = 0; EGLint *attrib_list_base = (EGLint *) 0; jint _remaining; EGLint *attrib_list = (EGLint *) 0; android::sp<ANativeWindow> window; android::sp<android::IGraphicBufferProducer> producer; if (!attrib_list_ref) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list == null"; goto exit; } if (offset < 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "offset < 0"; goto exit; } if (win == NULL) { not_valid_surface: _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; goto exit; } producer = android::SurfaceTexture_getProducer(_env, win); if (producer == NULL) goto not_valid_surface; window = new android::Surface(producer, true); if (window == NULL) goto not_valid_surface; _remaining = _env->GetArrayLength(attrib_list_ref) - offset; attrib_list_base = (EGLint *) _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0); attrib_list = attrib_list_base + offset; attrib_list_sentinel = 0; for (int i = _remaining - 1; i >= 0; i--) { if (*((EGLint*)(attrib_list + i)) == EGL_NONE){ attrib_list_sentinel = 1; break; } } if (attrib_list_sentinel == 0) { _exception = 1; _exceptionType = "java/lang/IllegalArgumentException"; _exceptionMessage = "attrib_list must contain EGL_NONE!"; goto exit; } _returnValue = eglCreateWindowSurface( (EGLDisplay)dpy_native, (EGLConfig)config_native, (EGLNativeWindowType)window.get(), (EGLint *)attrib_list ); exit: if (attrib_list_base) { _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base, JNI_ABORT); } if (_exception) { jniThrowException(_env, _exceptionType, _exceptionMessage); } return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); }
JNIEXPORT void JNICALL Java_com_lge_ccdevs_tracker_CameraPreview_native_1cv_1init__Landroid_graphics_Bitmap_2Landroid_graphics_RectF_2 (JNIEnv *env, jobject thiz, jobject srcimg, jobject rgn) { jclass clazz; clazz = env->FindClass(kClassPathName); if (clazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find com/lge/ccdevs/tracker/CameraActivity"); return; } fields.bitmapClazz = env->FindClass("android/graphics/Bitmap"); if (fields.bitmapClazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find android/graphics/Bitmap"); return; } fields.fileClazz = env->FindClass("java/io/File"); if (fields.fileClazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find java/io/File"); return; } fields.rectfClazz = env->FindClass("android/graphics/RectF"); if (fields.rectfClazz == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find android/graphics/RectF"); return; } fields.rectfConstructor = env->GetMethodID(fields.rectfClazz, "<init>", "(FFFF)V"); if (fields.rectfConstructor == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Can't find RectF constructor"); return; } fields.rectf_left_ID = env->GetFieldID(fields.rectfClazz, "left", "F"); fields.rectf_top_ID = env->GetFieldID(fields.rectfClazz, "top", "F"); fields.rectf_right_ID = env->GetFieldID(fields.rectfClazz, "right", "F"); fields.rectf_bottom_ID = env->GetFieldID(fields.rectfClazz, "bottom", "F"); // convert img AndroidBitmapInfo bInfo; char *bPixs; int bRet; if ((bRet = AndroidBitmap_getInfo(env, srcimg, &bInfo)) < 0) { LOGE("AndroidBitmap_getInfo failed(src)! error = %d", bRet); return; } if (bInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { LOGE("Bitmap(src) format is not RGBA_8888!"); return; } if ((bRet = AndroidBitmap_lockPixels(env, srcimg, (void**)&bPixs)) < 0) { LOGE("AndroidBitmap_lockPixels() failed(src)! error = %d", bRet); return; } IplImage* bimg = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 4); memcpy(bimg->imageData, bPixs, bimg->imageSize); AndroidBitmap_unlockPixels(env, srcimg); IplImage* img = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 3); cvCvtColor(bimg, img, CV_RGBA2BGR); // test capture Converter::saveJPG("/sdcard/tracker/tracker_init.jpg", img); // convert RectF float left = env->GetFloatField(rgn, fields.rectf_left_ID); float top = env->GetFloatField(rgn, fields.rectf_top_ID); float right = env->GetFloatField(rgn, fields.rectf_right_ID); float bottom = env->GetFloatField(rgn, fields.rectf_bottom_ID); LOGE("#### assign initial box = ( %f, %f, %f, %f )",left,top,right,bottom); tracker = new Tracker(img, cvRect(left,top,right-left,bottom-top)); cvReleaseImage( &bimg ); cvReleaseImage( &img ); }