From: "Tomas Härdin" <git@haerdin.se> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 3/4] lavc/mediacodec_wrapper: Add function for probing supported color formats Date: Fri, 24 Feb 2023 10:00:53 +0100 Message-ID: <db70ac39c0799d92d8829031dab089ec78ad0462.camel@haerdin.se> (raw) In-Reply-To: <fd61547526fef3c8367f249297d3588b9c1fe2e3.camel@haerdin.se> [-- Attachment #1: Type: text/plain, Size: 1 bytes --] [-- Attachment #2: 0003-lavc-mediacodec_wrapper-Add-function-for-probing-sup.patch --] [-- Type: text/x-patch, Size: 6206 bytes --] From 557f23650726af7f4881d29411de02f9f8bc78f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se> Date: Wed, 11 Jan 2023 22:25:39 +0100 Subject: [PATCH 3/4] lavc/mediacodec_wrapper: Add function for probing supported color formats This patch has been released by Epic Games' legal department. --- libavcodec/mediacodec_wrapper.c | 112 ++++++++++++++++++++++++++++++++ libavcodec/mediacodec_wrapper.h | 15 +++++ 2 files changed, 127 insertions(+) diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index 82eead2833..9d2560205f 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -532,6 +532,118 @@ done: return name; } +int ff_AMediaCodec_color_formats_intersect(const char *codec_name, const char *mime, + const int *in_formats, int nin_formats, + int *out_formats, void *log_ctx) +{ + int ret, found_codec = 0; + jstring jmime = NULL; + JNIEnv *env = NULL; + struct JNIAMediaCodecListFields jfields = { 0 }; + struct JNIAMediaFormatFields mediaformat_jfields = { 0 }; + + JNI_GET_ENV_OR_RETURN(env, log_ctx, -1); + + if ((ret = ff_jni_init_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx)) < 0) { + goto done; + } + + if ((ret = ff_jni_init_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx)) < 0) { + goto done; + } + + // convert const char* to java.lang.String + jmime = ff_jni_utf_chars_to_jstring(env, mime, log_ctx); + if (!jmime) { + goto done; + } + + int codec_count = (*env)->CallStaticIntMethod(env, jfields.mediacodec_list_class, jfields.get_codec_count_id); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done; + } + + for (int i = 0; i < codec_count && !found_codec; i++) { + jobject info = (*env)->CallStaticObjectMethod(env, jfields.mediacodec_list_class, jfields.get_codec_info_at_id, i); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + continue; + } + + char *name = NULL; + jboolean is_copy; + jintArray color_formats = NULL; + jobject capabilities = NULL; + jobject jcodec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done_with_info; + } + + if (!(name = ff_jni_jstring_to_utf_chars(env, jcodec_name, log_ctx))) { + goto done_with_info; + } + + if (strcmp(name, codec_name)) { + goto done_with_info; + } + + capabilities = (*env)->CallObjectMethod(env, info, jfields.get_codec_capabilities_id, jmime); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done_with_info; + } + + color_formats = (*env)->GetObjectField(env, capabilities, jfields.color_formats_id); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done_with_info; + } + + int color_count = (*env)->GetArrayLength(env, color_formats); + int *elems = (*env)->GetIntArrayElements(env, color_formats, &is_copy); + ret = 0; + found_codec = 1; + + // out_formats = intersect(in_formats, elems) + for (int j = 0; j < nin_formats; j++) { + for (int k = 0; k < color_count; k++) { + if (elems[k] == in_formats[j]) { + out_formats[ret++] = in_formats[j]; + break; + } + } + } + + (*env)->ReleaseIntArrayElements(env, color_formats, elems, JNI_ABORT); + +done_with_info: + if (color_formats) { + (*env)->DeleteLocalRef(env, color_formats); + } + + if (capabilities) { + (*env)->DeleteLocalRef(env, capabilities); + } + + if (jcodec_name) { + (*env)->DeleteLocalRef(env, jcodec_name); + } + + if (info) { + (*env)->DeleteLocalRef(env, info); + } + + av_freep(&name); + } + +done: + if (jmime) { + (*env)->DeleteLocalRef(env, jmime); + } + + ff_jni_reset_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx); + ff_jni_reset_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx); + + return found_codec ? ret : -1; +} + static FFAMediaFormat *mediaformat_jni_new(void) { JNIEnv *env = NULL; diff --git a/libavcodec/mediacodec_wrapper.h b/libavcodec/mediacodec_wrapper.h index 1b81e6db84..7ab32c4dc7 100644 --- a/libavcodec/mediacodec_wrapper.h +++ b/libavcodec/mediacodec_wrapper.h @@ -2,6 +2,7 @@ * Android MediaCodec Wrapper * * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com> + * Modifications by Epic Games, Inc., 2023. * * This file is part of FFmpeg. * @@ -230,6 +231,20 @@ FFAMediaCodec* ff_AMediaCodec_createCodecByName(const char *name, int ndk); FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk); FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk); +/** + * Intersects the given list of color formats with the formats actually supported by the named codec. + * @param[in] codec_name Name of the codec + * @param[in] mime MIME format. Typically "video/avc" or "video/hevc" + * @param[in] in_formats Array of input color formats + * @param[in] nin_formats Number of elements in in_formats + * @param[out] out_formats Computed intersection of in_formats and supported formats + * @param[in] log_ctx Logging context + * @return Size of out_formats or negative in case of error + */ +int ff_AMediaCodec_color_formats_intersect(const char *codec_name, const char *mime, + const int *in_formats, int nin_formats, + int *out_formats, void *log_ctx); + static inline int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, -- 2.30.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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 prev parent reply other threads:[~2023-02-24 9:00 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-24 8:59 [FFmpeg-devel] [PATCH 1/4] lavc/mediacodecenc: Add pix2color_fmt() and color2pix_fmt() Tomas Härdin 2023-02-24 9:00 ` [FFmpeg-devel] [PATCH 2/4] lavc/mediacodec_wrapper: Refactor ff_AMediaCodecList_getCodecNameByType() Tomas Härdin 2023-02-28 12:13 ` "zhilizhao(赵志立)" 2023-02-24 9:00 ` Tomas Härdin [this message] 2023-02-28 12:18 ` [FFmpeg-devel] [PATCH 3/4] lavc/mediacodec_wrapper: Add function for probing supported color formats "zhilizhao(赵志立)" 2023-02-24 9:03 ` [FFmpeg-devel] [PATCH 4/4] lavc/mediacodecenc: List supported pixel formats on configuration error Tomas Härdin 2023-02-28 12:25 ` "zhilizhao(赵志立)" 2023-02-28 12:02 ` [FFmpeg-devel] [PATCH 1/4] lavc/mediacodecenc: Add pix2color_fmt() and color2pix_fmt() "zhilizhao(赵志立)"
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=db70ac39c0799d92d8829031dab089ec78ad0462.camel@haerdin.se \ --to=git@haerdin.se \ --cc=ffmpeg-devel@ffmpeg.org \ /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