From: Zhao Zhili <quinkblack@foxmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Zhao Zhili <zhilizhao@tencent.com> Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/mediacodec_wrapper: use hardcoded value of profiles from MediaCodecInfo Date: Mon, 28 Nov 2022 00:55:03 +0800 Message-ID: <tencent_6134A93E2156759C4CE0845B3C3583808209@qq.com> (raw) In-Reply-To: <20221127165504.24796-1-quinkblack@foxmail.com> From: Zhao Zhili <zhilizhao@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 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next parent reply other threads:[~2022-11-27 16:55 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <20221127165504.24796-1-quinkblack@foxmail.com> 2022-11-27 16:55 ` Zhao Zhili [this message] 2022-11-27 16:55 ` [FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: configure profile Zhao Zhili
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_6134A93E2156759C4CE0845B3C3583808209@qq.com \ --to=quinkblack@foxmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=zhilizhao@tencent.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git