44 (*java_vm)->DetachCurrentThread(
java_vm);
74 ret = (*java_vm)->GetEnv(
java_vm, (
void **)&env, JNI_VERSION_1_6);
77 if ((*java_vm)->AttachCurrentThread(
java_vm, &env,
NULL) != 0) {
78 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to attach the JNI environment to the current thread\n");
90 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to get the JNI environment attached to this thread\n");
102 const char *utf_chars =
NULL;
110 utf_chars = (*env)->GetStringUTFChars(env,
string, &
copy);
111 if ((*env)->ExceptionCheck(env)) {
112 (*env)->ExceptionClear(env);
119 (*env)->ReleaseStringUTFChars(env,
string, utf_chars);
120 if ((*env)->ExceptionCheck(env)) {
121 (*env)->ExceptionClear(env);
133 ret = (*env)->NewStringUTF(env, utf_chars);
134 if ((*env)->ExceptionCheck(env)) {
135 (*env)->ExceptionClear(env);
152 jclass class_class =
NULL;
153 jmethodID get_name_id =
NULL;
155 jclass exception_class =
NULL;
156 jmethodID get_message_id =
NULL;
158 jstring
string =
NULL;
162 exception_class = (*env)->GetObjectClass(env, exception);
163 if ((*env)->ExceptionCheck(env)) {
164 (*env)->ExceptionClear(env);
170 class_class = (*env)->GetObjectClass(env, exception_class);
171 if ((*env)->ExceptionCheck(env)) {
172 (*env)->ExceptionClear(env);
178 get_name_id = (*env)->GetMethodID(env, class_class,
"getName",
"()Ljava/lang/String;");
179 if ((*env)->ExceptionCheck(env)) {
180 (*env)->ExceptionClear(env);
186 string = (*env)->CallObjectMethod(env, exception_class, get_name_id);
187 if ((*env)->ExceptionCheck(env)) {
188 (*env)->ExceptionClear(env);
196 (*env)->DeleteLocalRef(env,
string);
200 get_message_id = (*env)->GetMethodID(env, exception_class,
"getMessage",
"()Ljava/lang/String;");
201 if ((*env)->ExceptionCheck(env)) {
202 (*env)->ExceptionClear(env);
203 av_log(log_ctx,
AV_LOG_ERROR,
"Could not find method java/lang/Throwable.getMessage()\n");
208 string = (*env)->CallObjectMethod(env, exception, get_message_id);
209 if ((*env)->ExceptionCheck(env)) {
210 (*env)->ExceptionClear(env);
218 (*env)->DeleteLocalRef(env,
string);
239 (*env)->DeleteLocalRef(env, class_class);
240 (*env)->DeleteLocalRef(env, exception_class);
241 (*env)->DeleteLocalRef(env,
string);
250 jthrowable exception;
254 if (!(*(env))->ExceptionCheck((env))) {
259 (*(env))->ExceptionClear((env));
263 exception = (*env)->ExceptionOccurred(env);
264 (*(env))->ExceptionClear((env));
267 (*env)->DeleteLocalRef(env, exception);
271 (*env)->DeleteLocalRef(env, exception);
282 jclass last_clazz =
NULL;
284 for (
i = 0; jfields_mapping[
i].
name;
i++) {
293 clazz = (*env)->FindClass(env, jfields_mapping[
i].
name);
298 last_clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
299 global ? (*env)->NewGlobalRef(env, clazz) : clazz;
302 (*env)->DeleteLocalRef(env, clazz);
314 jfieldID field_id = (*env)->GetFieldID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
319 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = field_id;
323 jfieldID field_id = (*env)->GetStaticFieldID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
328 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = field_id;
332 jmethodID method_id = (*env)->GetMethodID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
337 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = method_id;
341 jmethodID method_id = (*env)->GetStaticMethodID(env, last_clazz, jfields_mapping[
i].method, jfields_mapping[
i].
signature);
346 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) = method_id;
372 for (
i = 0; jfields_mapping[
i].
name;
i++) {
377 jclass clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset);
382 (*env)->DeleteGlobalRef(env, clazz);
384 (*env)->DeleteLocalRef(env, clazz);
387 *(jclass*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
391 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
395 *(jfieldID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
399 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;
403 *(jmethodID*)((uint8_t*)jfields + jfields_mapping[
i].
offset) =
NULL;