summaryrefslogtreecommitdiff
path: root/libavcodec/mediacodec_wrapper.c
diff options
context:
space:
mode:
authorMatthieu Bouron <matthieu.bouron@gmail.com>2018-02-21 14:15:42 +0100
committerMatthieu Bouron <matthieu.bouron@gmail.com>2018-03-03 21:18:35 +0100
commitc55ba52a6a0698e0d6a9f7698f7dcc384764505a (patch)
tree2f32db0800a27c6f947fbac4eb46ac118d08d14b /libavcodec/mediacodec_wrapper.c
parentcc9875dc29383dd2c82dee3736e0cf53008a865e (diff)
downloadffmpeg-c55ba52a6a0698e0d6a9f7698f7dcc384764505a.tar.gz
avcodec/mediacodec_wrapper: load and use MediaFormat.constainsKey()
Avoids triggering an exception in MediaFormat getter functions if the key does not exist.
Diffstat (limited to 'libavcodec/mediacodec_wrapper.c')
-rw-r--r--libavcodec/mediacodec_wrapper.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index dbc37bf463..9436b3c994 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -111,6 +111,8 @@ struct JNIAMediaFormatFields {
jmethodID init_id;
+ jmethodID contains_key_id;
+
jmethodID get_integer_id;
jmethodID get_long_id;
jmethodID get_float_id;
@@ -132,6 +134,8 @@ static const struct FFJniField jni_amediaformat_mapping[] = {
{ "android/media/MediaFormat", "<init>", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, init_id), 1 },
+ { "android/media/MediaFormat", "containsKey", "(Ljava/lang/String;)Z", FF_JNI_METHOD,offsetof(struct JNIAMediaFormatFields, contains_key_id), 1 },
+
{ "android/media/MediaFormat", "getInteger", "(Ljava/lang/String;)I", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_integer_id), 1 },
{ "android/media/MediaFormat", "getLong", "(Ljava/lang/String;)J", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_long_id), 1 },
{ "android/media/MediaFormat", "getFloat", "(Ljava/lang/String;)F", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_float_id), 1 },
@@ -738,6 +742,7 @@ int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *
JNIEnv *env = NULL;
jstring key = NULL;
+ jboolean contains_key;
av_assert0(format != NULL);
@@ -749,6 +754,12 @@ int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *
goto fail;
}
+ contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
+ if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
+ ret = 0;
+ goto fail;
+ }
+
*out = (*env)->CallIntMethod(env, format->object, format->jfields.get_integer_id, key);
if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
ret = 0;
@@ -770,6 +781,7 @@ int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *
JNIEnv *env = NULL;
jstring key = NULL;
+ jboolean contains_key;
av_assert0(format != NULL);
@@ -781,6 +793,12 @@ int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *
goto fail;
}
+ contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
+ if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
+ ret = 0;
+ goto fail;
+ }
+
*out = (*env)->CallLongMethod(env, format->object, format->jfields.get_long_id, key);
if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
ret = 0;
@@ -802,6 +820,7 @@ int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *ou
JNIEnv *env = NULL;
jstring key = NULL;
+ jboolean contains_key;
av_assert0(format != NULL);
@@ -813,6 +832,12 @@ int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *ou
goto fail;
}
+ contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
+ if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
+ ret = 0;
+ goto fail;
+ }
+
*out = (*env)->CallFloatMethod(env, format->object, format->jfields.get_float_id, key);
if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
ret = 0;
@@ -834,6 +859,7 @@ int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** d
JNIEnv *env = NULL;
jstring key = NULL;
+ jboolean contains_key;
jobject result = NULL;
av_assert0(format != NULL);
@@ -846,6 +872,12 @@ int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** d
goto fail;
}
+ contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
+ if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
+ ret = 0;
+ goto fail;
+ }
+
result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_bytebuffer_id, key);
if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
ret = 0;
@@ -885,6 +917,7 @@ int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const ch
JNIEnv *env = NULL;
jstring key = NULL;
+ jboolean contains_key;
jstring result = NULL;
av_assert0(format != NULL);
@@ -897,6 +930,12 @@ int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const ch
goto fail;
}
+ contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
+ if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
+ ret = 0;
+ goto fail;
+ }
+
result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_string_id, key);
if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
ret = 0;