[FFmpeg-devel] [PATCH 2/3] avcodec/mediacodec_wrapper: use hardcoded value of profiles from MediaCodecInfo
Zhao Zhili
quinkblack at foxmail.com
Sun Nov 27 18:55:03 EET 2022
From: Zhao Zhili <zhilizhao at tencent.com>
Those are static const values and documented at
https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel
No runtime query is needed. Now the method can be used without JVM.
---
libavcodec/mediacodec_wrapper.c | 98 +++++++++++----------------------
1 file changed, 33 insertions(+), 65 deletions(-)
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 193eac8da6..7ddf93ccc7 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -57,19 +57,6 @@ struct JNIAMediaCodecListFields {
jclass codec_profile_level_class;
jfieldID profile_id;
jfieldID level_id;
-
- jfieldID avc_profile_baseline_id;
- jfieldID avc_profile_main_id;
- jfieldID avc_profile_extended_id;
- jfieldID avc_profile_high_id;
- jfieldID avc_profile_high10_id;
- jfieldID avc_profile_high422_id;
- jfieldID avc_profile_high444_id;
-
- jfieldID hevc_profile_main_id;
- jfieldID hevc_profile_main10_id;
- jfieldID hevc_profile_main10_hdr10_id;
-
};
static const struct FFJniField jni_amediacodeclist_mapping[] = {
@@ -95,18 +82,6 @@ static const struct FFJniField jni_amediacodeclist_mapping[] = {
{ "android/media/MediaCodecInfo$CodecProfileLevel", "profile", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, profile_id), 1 },
{ "android/media/MediaCodecInfo$CodecProfileLevel", "level", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, level_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileBaseline", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_baseline_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileMain", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_main_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileExtended", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_extended_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high10_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh422", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high422_id), 1 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh444", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high444_id), 1 },
-
- { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main_id), 0 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main10_id), 0 },
- { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain10HDR10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main10_hdr10_id), 0 },
-
{ NULL }
};
@@ -326,71 +301,64 @@ static const FFAMediaCodec media_codec_jni;
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
{
- int ret = -1;
-
- JNIEnv *env = NULL;
- struct JNIAMediaCodecListFields jfields = { 0 };
- jfieldID field_id = 0;
-
- JNI_GET_ENV_OR_RETURN(env, avctx, -1);
-
- if (ff_jni_init_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, avctx) < 0) {
- goto done;
- }
+ // Copy and modified from MediaCodecInfo.java
+ static const int AVCProfileBaseline = 0x01;
+ static const int AVCProfileMain = 0x02;
+ static const int AVCProfileExtended = 0x04;
+ static const int AVCProfileHigh = 0x08;
+ static const int AVCProfileHigh10 = 0x10;
+ static const int AVCProfileHigh422 = 0x20;
+ static const int AVCProfileHigh444 = 0x40;
+ static const int AVCProfileConstrainedBaseline = 0x10000;
+ static const int AVCProfileConstrainedHigh = 0x80000;
+
+ static const int HEVCProfileMain = 0x01;
+ static const int HEVCProfileMain10 = 0x02;
+ static const int HEVCProfileMainStill = 0x04;
+ static const int HEVCProfileMain10HDR10 = 0x1000;
+ static const int HEVCProfileMain10HDR10Plus = 0x2000;
+
+ // Unused yet.
+ (void)AVCProfileConstrainedHigh;
+ (void)HEVCProfileMain10HDR10;
+ (void)HEVCProfileMain10HDR10Plus;
if (avctx->codec_id == AV_CODEC_ID_H264) {
switch(avctx->profile) {
case FF_PROFILE_H264_BASELINE:
+ return AVCProfileBaseline;
case FF_PROFILE_H264_CONSTRAINED_BASELINE:
- field_id = jfields.avc_profile_baseline_id;
- break;
+ return AVCProfileConstrainedBaseline;
case FF_PROFILE_H264_MAIN:
- field_id = jfields.avc_profile_main_id;
+ return AVCProfileMain;
break;
case FF_PROFILE_H264_EXTENDED:
- field_id = jfields.avc_profile_extended_id;
- break;
+ return AVCProfileExtended;
case FF_PROFILE_H264_HIGH:
- field_id = jfields.avc_profile_high_id;
- break;
+ return AVCProfileHigh;
case FF_PROFILE_H264_HIGH_10:
case FF_PROFILE_H264_HIGH_10_INTRA:
- field_id = jfields.avc_profile_high10_id;
- break;
+ return AVCProfileHigh10;
case FF_PROFILE_H264_HIGH_422:
case FF_PROFILE_H264_HIGH_422_INTRA:
- field_id = jfields.avc_profile_high422_id;
- break;
+ return AVCProfileHigh422;
case FF_PROFILE_H264_HIGH_444:
case FF_PROFILE_H264_HIGH_444_INTRA:
case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
- field_id = jfields.avc_profile_high444_id;
- break;
+ return AVCProfileHigh444;
}
} else if (avctx->codec_id == AV_CODEC_ID_HEVC) {
switch (avctx->profile) {
case FF_PROFILE_HEVC_MAIN:
+ return HEVCProfileMain;
case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
- field_id = jfields.hevc_profile_main_id;
- break;
+ return HEVCProfileMainStill;
case FF_PROFILE_HEVC_MAIN_10:
- field_id = jfields.hevc_profile_main10_id;
- break;
+ return HEVCProfileMain10;
}
}
- if (field_id) {
- ret = (*env)->GetStaticIntField(env, jfields.codec_profile_level_class, field_id);
- if (ff_jni_exception_check(env, 1, avctx) < 0) {
- ret = -1;
- goto done;
- }
- }
-
-done:
- ff_jni_reset_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, avctx);
-
- return ret;
+ return -1;
}
char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
--
2.25.1
More information about the ffmpeg-devel
mailing list