* [FFmpeg-devel] [PATCH 2/3] avcodec/mediacodec_wrapper: use hardcoded value of profiles from MediaCodecInfo
[not found] <20221127165504.24796-1-quinkblack@foxmail.com>
@ 2022-11-27 16:55 ` Zhao Zhili
2022-11-27 16:55 ` [FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: configure profile Zhao Zhili
1 sibling, 0 replies; 2+ messages in thread
From: Zhao Zhili @ 2022-11-27 16:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: configure profile
[not found] <20221127165504.24796-1-quinkblack@foxmail.com>
2022-11-27 16:55 ` [FFmpeg-devel] [PATCH 2/3] avcodec/mediacodec_wrapper: use hardcoded value of profiles from MediaCodecInfo Zhao Zhili
@ 2022-11-27 16:55 ` Zhao Zhili
1 sibling, 0 replies; 2+ messages in thread
From: Zhao Zhili @ 2022-11-27 16:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
---
libavcodec/mediacodecenc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 693faca118..69246ad693 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -213,6 +213,11 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
+ ret = ff_AMediaCodecProfile_getProfileFromAVCodecContext(avctx);
+ if (ret > 0) {
+ av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
+ ff_AMediaFormat_setInt32(format, "profile", ret);
+ }
ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec);
ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
--
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-27 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20221127165504.24796-1-quinkblack@foxmail.com>
2022-11-27 16:55 ` [FFmpeg-devel] [PATCH 2/3] avcodec/mediacodec_wrapper: use hardcoded value of profiles from MediaCodecInfo Zhao Zhili
2022-11-27 16:55 ` [FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: configure profile Zhao Zhili
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