42 (*java_vm)->DetachCurrentThread(
java_vm);
72 ret = (*java_vm)->GetEnv(
java_vm, (
void **)&env, JNI_VERSION_1_6);
75 if ((*java_vm)->AttachCurrentThread(
java_vm, &env,
NULL) != 0) {
76 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to attach the JNI environment to the current thread\n");
88 av_log(log_ctx,
AV_LOG_ERROR,
"Failed to get the JNI environment attached to this thread\n");
100 const char *utf_chars =
NULL;
108 utf_chars = (*env)->GetStringUTFChars(env,
string, ©);
109 if ((*env)->ExceptionCheck(env)) {
110 (*env)->ExceptionClear(env);
117 (*env)->ReleaseStringUTFChars(env,
string, utf_chars);
118 if ((*env)->ExceptionCheck(env)) {
119 (*env)->ExceptionClear(env);
131 ret = (*env)->NewStringUTF(env, utf_chars);
132 if ((*env)->ExceptionCheck(env)) {
133 (*env)->ExceptionClear(env);
150 jclass class_class =
NULL;
151 jmethodID get_name_id =
NULL;
153 jclass exception_class =
NULL;
154 jmethodID get_message_id =
NULL;
156 jstring
string =
NULL;
160 exception_class = (*env)->GetObjectClass(env, exception);
161 if ((*env)->ExceptionCheck(env)) {
162 (*env)->ExceptionClear(env);
168 class_class = (*env)->GetObjectClass(env, exception_class);
169 if ((*env)->ExceptionCheck(env)) {
170 (*env)->ExceptionClear(env);
176 get_name_id = (*env)->GetMethodID(env, class_class,
"getName",
"()Ljava/lang/String;");
177 if ((*env)->ExceptionCheck(env)) {
178 (*env)->ExceptionClear(env);
184 string = (*env)->CallObjectMethod(env, exception_class, get_name_id);
185 if ((*env)->ExceptionCheck(env)) {
186 (*env)->ExceptionClear(env);
194 (*env)->DeleteLocalRef(env,
string);
198 get_message_id = (*env)->GetMethodID(env, exception_class,
"getMessage",
"()Ljava/lang/String;");
199 if ((*env)->ExceptionCheck(env)) {
200 (*env)->ExceptionClear(env);
201 av_log(log_ctx,
AV_LOG_ERROR,
"Could not find method java/lang/Throwable.getMessage()\n");
206 string = (*env)->CallObjectMethod(env, exception, get_message_id);
207 if ((*env)->ExceptionCheck(env)) {
208 (*env)->ExceptionClear(env);
216 (*env)->DeleteLocalRef(env,
string);
220 if (name && message) {
222 }
else if (name && !message) {
224 }
else if (!name && message) {
238 (*env)->DeleteLocalRef(env, class_class);
241 if (exception_class) {
242 (*env)->DeleteLocalRef(env, exception_class);
246 (*env)->DeleteLocalRef(env,
string);
256 jthrowable exception;
260 if (!(*(env))->ExceptionCheck((env))) {
265 (*(env))->ExceptionClear((env));
269 exception = (*env)->ExceptionOccurred(env);
270 (*(env))->ExceptionClear((env));
273 (*env)->DeleteLocalRef(env, exception);
277 (*env)->DeleteLocalRef(env, exception);
288 jclass last_clazz =
NULL;
290 for (i = 0; jfields_mapping[i].
name; i++) {
291 int mandatory = jfields_mapping[i].
mandatory;
299 clazz = (*env)->FindClass(env, jfields_mapping[i].
name);
304 last_clazz = *(jclass*)((
uint8_t*)jfields + jfields_mapping[i].
offset) =
305 global ? (*env)->NewGlobalRef(env, clazz) : clazz;
308 (*env)->DeleteLocalRef(env, clazz);
320 jfieldID field_id = (*env)->GetFieldID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].
signature);
325 *(jfieldID*)((
uint8_t*)jfields + jfields_mapping[i].
offset) = field_id;
329 jfieldID field_id = (*env)->GetStaticFieldID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].
signature);
334 *(jfieldID*)((
uint8_t*)jfields + jfields_mapping[i].
offset) = field_id;
338 jmethodID method_id = (*env)->GetMethodID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].
signature);
343 *(jmethodID*)((
uint8_t*)jfields + jfields_mapping[i].
offset) = method_id;
347 jmethodID method_id = (*env)->GetStaticMethodID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].
signature);
352 *(jmethodID*)((
uint8_t*)jfields + jfields_mapping[i].
offset) = method_id;
378 for (i = 0; jfields_mapping[i].
name; i++) {
383 jclass clazz = *(jclass*)((
uint8_t*)jfields + jfields_mapping[i].
offset);
388 (*env)->DeleteGlobalRef(env, clazz);
390 (*env)->DeleteLocalRef(env, clazz);
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static void copy(const float *p1, float *p2, const int length)
#define pthread_mutex_lock(a)
ptrdiff_t const GLvoid * data
int ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
jstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static void jni_create_pthread_key(void)
static const char signature[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static pthread_once_t once
static pthread_key_t current_env
void * av_jni_get_java_vm(void *log_ctx)
char * ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx)
static void jni_detach_env(void *data)
int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx)
#define pthread_mutex_unlock(a)
static void error(const char *err)
#define PTHREAD_MUTEX_INITIALIZER
#define AV_BPRINT_SIZE_AUTOMATIC
char * av_strdup(const char *s)
Duplicate a string.
int ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error, void *log_ctx)
static pthread_mutex_t lock
JNIEnv * ff_jni_get_env(void *log_ctx)
#define PTHREAD_ONCE_INIT
#define AVERROR_EXTERNAL
Generic error in an external library.
static av_always_inline int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))