43 (*java_vm)->DetachCurrentThread(
java_vm);
73 ret = (*java_vm)->GetEnv(
java_vm, (
void **)&env, JNI_VERSION_1_6);
76 if ((*java_vm)->AttachCurrentThread(
java_vm, &env,
NULL) != 0) {
77 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to attach the JNI environment to the current thread\n");
89 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to get the JNI environment attached to this thread\n");
101 const char *utf_chars =
NULL;
109 utf_chars = (*env)->GetStringUTFChars(env,
string, &
copy);
110 if ((*env)->ExceptionCheck(env)) {
111 (*env)->ExceptionClear(env);
118 (*env)->ReleaseStringUTFChars(env,
string, utf_chars);
119 if ((*env)->ExceptionCheck(env)) {
120 (*env)->ExceptionClear(env);
132 ret = (*env)->NewStringUTF(env, utf_chars);
133 if ((*env)->ExceptionCheck(env)) {
134 (*env)->ExceptionClear(env);
151 jclass class_class =
NULL;
152 jmethodID get_name_id =
NULL;
154 jclass exception_class =
NULL;
155 jmethodID get_message_id =
NULL;
157 jstring
string =
NULL;
161 exception_class = (*env)->GetObjectClass(env, exception);
162 if ((*env)->ExceptionCheck(env)) {
163 (*env)->ExceptionClear(env);
169 class_class = (*env)->GetObjectClass(env, exception_class);
170 if ((*env)->ExceptionCheck(env)) {
171 (*env)->ExceptionClear(env);
177 get_name_id = (*env)->GetMethodID(env, class_class,
"getName",
"()Ljava/lang/String;");
178 if ((*env)->ExceptionCheck(env)) {
179 (*env)->ExceptionClear(env);
185 string = (*env)->CallObjectMethod(env, exception_class, get_name_id);
186 if ((*env)->ExceptionCheck(env)) {
187 (*env)->ExceptionClear(env);
195 (*env)->DeleteLocalRef(env,
string);
199 get_message_id = (*env)->GetMethodID(env, exception_class,
"getMessage",
"()Ljava/lang/String;");
200 if ((*env)->ExceptionCheck(env)) {
201 (*env)->ExceptionClear(env);
202 av_log(log_ctx,
AV_LOG_ERROR,
"Could not find method java/lang/Throwable.getMessage()\n");
207 string = (*env)->CallObjectMethod(env, exception, get_message_id);
208 if ((*env)->ExceptionCheck(env)) {
209 (*env)->ExceptionClear(env);
217 (*env)->DeleteLocalRef(env,
string);
239 (*env)->DeleteLocalRef(env, class_class);
242 if (exception_class) {
243 (*env)->DeleteLocalRef(env, exception_class);
247 (*env)->DeleteLocalRef(env,
string);
257 jthrowable exception;
261 if (!(*(env))->ExceptionCheck((env))) {
266 (*(env))->ExceptionClear((env));
270 exception = (*env)->ExceptionOccurred(env);
271 (*(env))->ExceptionClear((env));
274 (*env)->DeleteLocalRef(env, exception);
278 (*env)->DeleteLocalRef(env, exception);
289 jclass last_clazz =
NULL;
291 for (
i = 0; jfields_mapping[
i].
name;
i++) {
300 clazz = (*env)->FindClass(env, jfields_mapping[
i].
name);
305 last_clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
306 global ? (*env)->NewGlobalRef(env, clazz) : clazz;
309 (*env)->DeleteLocalRef(env, clazz);
321 jfieldID field_id = (*env)->GetFieldID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
326 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = field_id;
330 jfieldID field_id = (*env)->GetStaticFieldID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
335 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = field_id;
339 jmethodID method_id = (*env)->GetMethodID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
344 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = method_id;
348 jmethodID method_id = (*env)->GetStaticMethodID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
353 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = method_id;
379 for (
i = 0; jfields_mapping[
i].
name;
i++) {
384 jclass clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset);
389 (*env)->DeleteGlobalRef(env, clazz);
391 (*env)->DeleteLocalRef(env, clazz);
394 *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
398 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
402 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
406 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
410 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;