From 4e76bcfd5001db152167c6dec598d25b0e337f94 Mon Sep 17 00:00:00 2001 From: Thomas Guillem <thomas@gllm.fr> Date: Tue, 29 Oct 2019 11:14:56 +0100 Subject: [PATCH] mediacodec: fix video aspect ratio on Amazon devices The AVC MediaCodec implementation of Amazon Fire TV devices report the surface output size instead of the input video size. These are the only know devices that need this HACK. --- modules/codec/omxil/mediacodec_jni.c | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c index ba2e92f21e81..63e2a934648f 100644 --- a/modules/codec/omxil/mediacodec_jni.c +++ b/modules/codec/omxil/mediacodec_jni.c @@ -314,6 +314,36 @@ struct mc_api_sys jobject input_buffers, output_buffers; }; +static char *GetManufacturer(JNIEnv *env) +{ + char *manufacturer = NULL; + + jclass clazz = (*env)->FindClass(env, "android/os/Build"); + if (CHECK_EXCEPTION()) + return NULL; + + jfieldID id = (*env)->GetStaticFieldID(env, clazz, "MANUFACTURER", + "Ljava/lang/String;"); + if (CHECK_EXCEPTION()) + goto end; + + jstring jstr = (*env)->GetStaticObjectField(env, clazz, id); + + if (CHECK_EXCEPTION()) + goto end; + + const char *str = (*env)->GetStringUTFChars(env, jstr, 0); + if (str) + { + manufacturer = strdup(str); + (*env)->ReleaseStringUTFChars(env, jstr, str); + } + +end: + (*env)->DeleteLocalRef(env, clazz); + return manufacturer; +} + /***************************************************************************** * MediaCodec_GetName *****************************************************************************/ @@ -456,6 +486,22 @@ char* MediaCodec_GetName(vlc_object_t *p_obj, const char *psz_mime, bool ignore_size = false; + /* The AVC MediaCodec implementation on Amazon fire TV seems to + * report the Output surface size instead of the AVC size. This + * bug is specific to Amazon devices since other MTK + * implementations report the correct size. The manufacturer is + * checked only if the codec matches the MKT AVC one in order + * to avoid extra manufacturer check for other every devices. + * */ + static const char mtk_avc[] = "OMX.MTK.VIDEO.DECODER.AVC"; + if (strncmp(psz_name, mtk_avc, sizeof(mtk_avc) - 1) == 0) + { + char *manufacturer = GetManufacturer(env); + if (manufacturer && strcmp(manufacturer, "Amazon") == 0) + ignore_size = true; + free(manufacturer); + } + if (ignore_size) { *p_quirks |= MC_API_VIDEO_QUIRKS_IGNORE_SIZE; -- GitLab