diff mbox series

[FFmpeg-devel,2/2] avcodec/mediacodec_wrapper: use MediaCodecInfo.isSoftwareOnly() when available

Message ID DB6PR0901MB149543CCB55D61AAE59A9664EC869@DB6PR0901MB1495.eurprd09.prod.outlook.com
State Accepted
Commit a7425f712aeed6e18204a68810529895fdbdb1be
Headers show
Series [FFmpeg-devel,1/2] avcodec/mediacodec_wrapper: clean up ff_AMediaCodecList_getCodecNameByType a bit | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

sfan5 Feb. 17, 2021, 3:51 p.m. UTC
Subject: [PATCH 2/2] avcodec/mediacodec_wrapper: use
 MediaCodecInfo.isSoftwareOnly() when available

Added in Android 10 it provides a reliable way of filtering out
software decoders, unlike existing string-based checks.
---
 libavcodec/mediacodec_wrapper.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Matthieu Bouron March 8, 2021, 9:12 a.m. UTC | #1
On Wed, Feb 17, 2021 at 04:51:09PM +0100, sfan5 wrote:
> 

> From 22ebde779f61fb030633a881ef320264ea446b6b Mon Sep 17 00:00:00 2001
> From: sfan5 <sfan5@live.de>
> Date: Thu, 11 Feb 2021 20:48:54 +0100
> Subject: [PATCH 2/2] avcodec/mediacodec_wrapper: use
>  MediaCodecInfo.isSoftwareOnly() when available
> 
> Added in Android 10 it provides a reliable way of filtering out
> software decoders, unlike existing string-based checks.
> ---
>  libavcodec/mediacodec_wrapper.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
> index f1945bcfc0..c829941d6b 100644
> --- a/libavcodec/mediacodec_wrapper.c
> +++ b/libavcodec/mediacodec_wrapper.c
> @@ -45,6 +45,7 @@ struct JNIAMediaCodecListFields {
>      jmethodID get_codec_capabilities_id;
>      jmethodID get_supported_types_id;
>      jmethodID is_encoder_id;
> +    jmethodID is_software_only_id;
>  
>      jclass codec_capabilities_class;
>      jfieldID color_formats_id;
> @@ -81,6 +82,7 @@ static const struct FFJniField jni_amediacodeclist_mapping[] = {
>          { "android/media/MediaCodecInfo", "getCapabilitiesForType", "(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_capabilities_id), 1 },
>          { "android/media/MediaCodecInfo", "getSupportedTypes", "()[Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_supported_types_id), 1 },
>          { "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_encoder_id), 1 },
> +        { "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_software_only_id), 0 },
>  
>      { "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, codec_capabilities_class), 1 },
>          { "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", "[I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, color_formats_id), 1 },
> @@ -441,6 +443,17 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
>              goto done_with_info;
>          }
>  
> +        if (jfields.is_software_only_id) {
> +            int is_software_only = (*env)->CallBooleanMethod(env, info, jfields.is_software_only_id);
> +            if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
> +                goto done;
> +            }
> +
> +            if (is_software_only) {
> +                goto done_with_info;
> +            }
> +        }
> +
>          codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id);
>          if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
>              goto done;
> -- 
> 2.30.1
> 

LGTM, I'll push the patch in two days if there is no objection.
Thanks,
Matthieu Bouron March 10, 2021, 1:23 p.m. UTC | #2
On Mon, Mar 08, 2021 at 10:12:38AM +0100, Matthieu Bouron wrote:
> On Wed, Feb 17, 2021 at 04:51:09PM +0100, sfan5 wrote:
> > 
> 
> > From 22ebde779f61fb030633a881ef320264ea446b6b Mon Sep 17 00:00:00 2001
> > From: sfan5 <sfan5@live.de>
> > Date: Thu, 11 Feb 2021 20:48:54 +0100
> > Subject: [PATCH 2/2] avcodec/mediacodec_wrapper: use
> >  MediaCodecInfo.isSoftwareOnly() when available
> > 
> > Added in Android 10 it provides a reliable way of filtering out
> > software decoders, unlike existing string-based checks.
> > ---
> >  libavcodec/mediacodec_wrapper.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> > 
> > diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
> > index f1945bcfc0..c829941d6b 100644
> > --- a/libavcodec/mediacodec_wrapper.c
> > +++ b/libavcodec/mediacodec_wrapper.c
> > @@ -45,6 +45,7 @@ struct JNIAMediaCodecListFields {
> >      jmethodID get_codec_capabilities_id;
> >      jmethodID get_supported_types_id;
> >      jmethodID is_encoder_id;
> > +    jmethodID is_software_only_id;
> >  
> >      jclass codec_capabilities_class;
> >      jfieldID color_formats_id;
> > @@ -81,6 +82,7 @@ static const struct FFJniField jni_amediacodeclist_mapping[] = {
> >          { "android/media/MediaCodecInfo", "getCapabilitiesForType", "(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_capabilities_id), 1 },
> >          { "android/media/MediaCodecInfo", "getSupportedTypes", "()[Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_supported_types_id), 1 },
> >          { "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_encoder_id), 1 },
> > +        { "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_software_only_id), 0 },
> >  
> >      { "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, codec_capabilities_class), 1 },
> >          { "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", "[I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, color_formats_id), 1 },
> > @@ -441,6 +443,17 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
> >              goto done_with_info;
> >          }
> >  
> > +        if (jfields.is_software_only_id) {
> > +            int is_software_only = (*env)->CallBooleanMethod(env, info, jfields.is_software_only_id);
> > +            if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
> > +                goto done;
> > +            }
> > +
> > +            if (is_software_only) {
> > +                goto done_with_info;
> > +            }
> > +        }
> > +
> >          codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id);
> >          if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
> >              goto done;
> > -- 
> > 2.30.1
> > 
> 
> LGTM, I'll push the patch in two days if there is no objection.
> Thanks,

Applied as a7425f712aeed6e18204a68810529895fdbdb1be.
Thanks.
diff mbox series

Patch

diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index f1945bcfc0..c829941d6b 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -45,6 +45,7 @@  struct JNIAMediaCodecListFields {
     jmethodID get_codec_capabilities_id;
     jmethodID get_supported_types_id;
     jmethodID is_encoder_id;
+    jmethodID is_software_only_id;
 
     jclass codec_capabilities_class;
     jfieldID color_formats_id;
@@ -81,6 +82,7 @@  static const struct FFJniField jni_amediacodeclist_mapping[] = {
         { "android/media/MediaCodecInfo", "getCapabilitiesForType", "(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_capabilities_id), 1 },
         { "android/media/MediaCodecInfo", "getSupportedTypes", "()[Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_supported_types_id), 1 },
         { "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_encoder_id), 1 },
+        { "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_software_only_id), 0 },
 
     { "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, codec_capabilities_class), 1 },
         { "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", "[I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, color_formats_id), 1 },
@@ -441,6 +443,17 @@  char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
             goto done_with_info;
         }
 
+        if (jfields.is_software_only_id) {
+            int is_software_only = (*env)->CallBooleanMethod(env, info, jfields.is_software_only_id);
+            if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
+                goto done;
+            }
+
+            if (is_software_only) {
+                goto done_with_info;
+            }
+        }
+
         codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id);
         if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
             goto done;