[FFmpeg-devel] [PATCH 4/5] lavu/jni: let avpriv_init_jfields load application classes
Matthieu Bouron
matthieu.bouron at gmail.com
Fri Oct 9 18:26:52 CEST 2015
From: Matthieu Bouron <matthieu.bouron at stupeflix.com>
---
libavutil/jni_internal.c | 25 +++++++++++++++++++++----
libavutil/jni_internal.h | 1 +
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/libavutil/jni_internal.c b/libavutil/jni_internal.c
index 58eb570..78d13a4 100644
--- a/libavutil/jni_internal.c
+++ b/libavutil/jni_internal.c
@@ -257,14 +257,31 @@ int avpriv_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField
int mandatory = jfields_mapping[i].mandatory;
enum FFJniFieldType type = jfields_mapping[i].type;
- if (type == FF_JNI_CLASS) {
+ if (type == FF_JNI_CLASS || type == FF_JNI_APPLICATION_CLASS) {
jclass clazz;
last_clazz = NULL;
- clazz = (*env)->FindClass(env, jfields_mapping[i].name);
- if ((ret = avpriv_jni_exception_check(env, mandatory, log_ctx) && mandatory) < 0) {
- goto done;
+ if (application_class_loader && type == FF_JNI_APPLICATION_CLASS) {
+
+ jobject tmp = avpriv_jni_utf_chars_to_jstring(env, jfields_mapping[i].name, log_ctx);
+ if (!tmp) {
+ ret = AVERROR_EXTERNAL;
+ goto done;
+ }
+
+ clazz = (*env)->CallObjectMethod(env, application_class_loader, find_class_id, tmp);
+ if ((ret = avpriv_jni_exception_check(env, 1, log_ctx)) < 0 && mandatory) {
+ goto done;
+ }
+
+ (*env)->DeleteLocalRef(env, tmp);
+
+ } else {
+ clazz = (*env)->FindClass(env, jfields_mapping[i].name);
+ if ((ret = avpriv_jni_exception_check(env, mandatory, log_ctx) && mandatory) < 0) {
+ goto done;
+ }
}
last_clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[i].offset) =
diff --git a/libavutil/jni_internal.h b/libavutil/jni_internal.h
index 24c4b4e..c1c206d 100644
--- a/libavutil/jni_internal.h
+++ b/libavutil/jni_internal.h
@@ -88,6 +88,7 @@ int avpriv_jni_exception_check(JNIEnv *env, int log, void *log_ctx);
enum FFJniFieldType {
FF_JNI_CLASS,
+ FF_JNI_APPLICATION_CLASS,
FF_JNI_FIELD,
FF_JNI_METHOD,
FF_JNI_STATIC_METHOD
--
2.6.1
More information about the ffmpeg-devel
mailing list