Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Matthieu Bouron <matthieu.bouron@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Matthieu Bouron <matthieu.bouron@gmail.com>
Subject: [FFmpeg-devel] [PATCH v2 6/6] avcodec/mediacodec_wrapper: remove unnecessary NULL checks before calling Delete{Global, Local}Ref()
Date: Tue, 27 Feb 2024 15:50:42 +0100
Message-ID: <20240227145536.281991-7-matthieu.bouron@gmail.com> (raw)
In-Reply-To: <20240227145536.281991-1-matthieu.bouron@gmail.com>

Delete{Global,Local}Ref already handle NULL.
---
 libavcodec/mediacodec_wrapper.c | 189 ++++++++------------------------
 1 file changed, 47 insertions(+), 142 deletions(-)

diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 78cd28f53d..306359071e 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -549,10 +549,8 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
             goto done;
         }
 
-        if (codec_name) {
-            (*env)->DeleteLocalRef(env, codec_name);
-            codec_name = NULL;
-        }
+        (*env)->DeleteLocalRef(env, codec_name);
+        codec_name = NULL;
 
         /* Skip software decoders */
         if (
@@ -616,10 +614,8 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
 
                 found_codec = profile == supported_profile;
 
-                if (profile_level) {
-                    (*env)->DeleteLocalRef(env, profile_level);
-                    profile_level = NULL;
-                }
+                (*env)->DeleteLocalRef(env, profile_level);
+                profile_level = NULL;
 
                 if (found_codec) {
                     break;
@@ -627,20 +623,14 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e
             }
 
 done_with_type:
-            if (profile_levels) {
-                (*env)->DeleteLocalRef(env, profile_levels);
-                profile_levels = NULL;
-            }
+            (*env)->DeleteLocalRef(env, profile_levels);
+            profile_levels = NULL;
 
-            if (capabilities) {
-                (*env)->DeleteLocalRef(env, capabilities);
-                capabilities = NULL;
-            }
+            (*env)->DeleteLocalRef(env, capabilities);
+            capabilities = NULL;
 
-            if (type) {
-                (*env)->DeleteLocalRef(env, type);
-                type = NULL;
-            }
+            (*env)->DeleteLocalRef(env, type);
+            type = NULL;
 
             av_freep(&supported_type);
 
@@ -650,15 +640,11 @@ done_with_type:
         }
 
 done_with_info:
-        if (info) {
-            (*env)->DeleteLocalRef(env, info);
-            info = NULL;
-        }
+        (*env)->DeleteLocalRef(env, info);
+        info = NULL;
 
-        if (types) {
-            (*env)->DeleteLocalRef(env, types);
-            types = NULL;
-        }
+        (*env)->DeleteLocalRef(env, types);
+        types = NULL;
 
         if (found_codec) {
             break;
@@ -668,33 +654,13 @@ done_with_info:
     }
 
 done:
-    if (codec_name) {
-        (*env)->DeleteLocalRef(env, codec_name);
-    }
-
-    if (info) {
-        (*env)->DeleteLocalRef(env, info);
-    }
-
-    if (type) {
-        (*env)->DeleteLocalRef(env, type);
-    }
-
-    if (types) {
-        (*env)->DeleteLocalRef(env, types);
-    }
-
-    if (capabilities) {
-        (*env)->DeleteLocalRef(env, capabilities);
-    }
-
-    if (profile_level) {
-        (*env)->DeleteLocalRef(env, profile_level);
-    }
-
-    if (profile_levels) {
-        (*env)->DeleteLocalRef(env, profile_levels);
-    }
+    (*env)->DeleteLocalRef(env, codec_name);
+    (*env)->DeleteLocalRef(env, info);
+    (*env)->DeleteLocalRef(env, type);
+    (*env)->DeleteLocalRef(env, types);
+    (*env)->DeleteLocalRef(env, capabilities);
+    (*env)->DeleteLocalRef(env, profile_level);
+    (*env)->DeleteLocalRef(env, profile_levels);
 
     av_freep(&supported_type);
 
@@ -741,9 +707,7 @@ static FFAMediaFormat *mediaformat_jni_new(void)
     }
 
 fail:
-    if (object) {
-        (*env)->DeleteLocalRef(env, object);
-    }
+    (*env)->DeleteLocalRef(env, object);
 
     if (!format->object) {
         ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format);
@@ -828,9 +792,7 @@ static char* mediaformat_jni_toString(FFAMediaFormat* ctx)
 
     ret = ff_jni_jstring_to_utf_chars(env, description, format);
 fail:
-    if (description) {
-        (*env)->DeleteLocalRef(env, description);
-    }
+    (*env)->DeleteLocalRef(env, description);
 
     return ret;
 }
@@ -867,9 +829,7 @@ static int mediaformat_jni_getInt32(FFAMediaFormat* ctx, const char *name, int32
 
     ret = 1;
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 
     return ret;
 }
@@ -906,9 +866,7 @@ static int mediaformat_jni_getInt64(FFAMediaFormat* ctx, const char *name, int64
 
     ret = 1;
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 
     return ret;
 }
@@ -945,9 +903,7 @@ static int mediaformat_jni_getFloat(FFAMediaFormat* ctx, const char *name, float
 
     ret = 1;
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 
     return ret;
 }
@@ -999,13 +955,8 @@ static int mediaformat_jni_getBuffer(FFAMediaFormat* ctx, const char *name, void
 
     ret = 1;
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
-
-    if (result) {
-        (*env)->DeleteLocalRef(env, result);
-    }
+    (*env)->DeleteLocalRef(env, key);
+    (*env)->DeleteLocalRef(env, result);
 
     return ret;
 }
@@ -1049,13 +1000,8 @@ static int mediaformat_jni_getString(FFAMediaFormat* ctx, const char *name, cons
 
     ret = 1;
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
-
-    if (result) {
-        (*env)->DeleteLocalRef(env, result);
-    }
+    (*env)->DeleteLocalRef(env, key);
+    (*env)->DeleteLocalRef(env, result);
 
     return ret;
 }
@@ -1081,9 +1027,7 @@ static void mediaformat_jni_setInt32(FFAMediaFormat* ctx, const char* name, int3
     }
 
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 }
 
 static void mediaformat_jni_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
@@ -1107,9 +1051,7 @@ static void mediaformat_jni_setInt64(FFAMediaFormat* ctx, const char* name, int6
     }
 
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 }
 
 static void mediaformat_jni_setFloat(FFAMediaFormat* ctx, const char* name, float value)
@@ -1133,9 +1075,7 @@ static void mediaformat_jni_setFloat(FFAMediaFormat* ctx, const char* name, floa
     }
 
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
+    (*env)->DeleteLocalRef(env, key);
 }
 
 static void mediaformat_jni_setString(FFAMediaFormat* ctx, const char* name, const char* value)
@@ -1165,13 +1105,8 @@ static void mediaformat_jni_setString(FFAMediaFormat* ctx, const char* name, con
     }
 
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
-
-    if (string) {
-        (*env)->DeleteLocalRef(env, string);
-    }
+    (*env)->DeleteLocalRef(env, key);
+    (*env)->DeleteLocalRef(env, string);
 }
 
 static void mediaformat_jni_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
@@ -1213,13 +1148,8 @@ static void mediaformat_jni_setBuffer(FFAMediaFormat* ctx, const char* name, voi
     }
 
 fail:
-    if (key) {
-        (*env)->DeleteLocalRef(env, key);
-    }
-
-    if (buffer) {
-        (*env)->DeleteLocalRef(env, buffer);
-    }
+    (*env)->DeleteLocalRef(env, key);
+    (*env)->DeleteLocalRef(env, buffer);
 }
 
 static int codec_init_static_fields(FFAMediaCodecJni *codec)
@@ -1352,26 +1282,13 @@ static inline FFAMediaCodec *codec_create(int method, const char *arg)
 
     ret = 0;
 fail:
-    if (jarg) {
-        (*env)->DeleteLocalRef(env, jarg);
-    }
-
-    if (object) {
-        (*env)->DeleteLocalRef(env, object);
-    }
-
-    if (buffer_info) {
-        (*env)->DeleteLocalRef(env, buffer_info);
-    }
+    (*env)->DeleteLocalRef(env, jarg);
+    (*env)->DeleteLocalRef(env, object);
+    (*env)->DeleteLocalRef(env, buffer_info);
 
     if (ret < 0) {
-        if (codec->object) {
-            (*env)->DeleteGlobalRef(env, codec->object);
-        }
-
-        if (codec->buffer_info) {
-            (*env)->DeleteGlobalRef(env, codec->buffer_info);
-        }
+        (*env)->DeleteGlobalRef(env, codec->object);
+        (*env)->DeleteGlobalRef(env, codec->buffer_info);
 
         ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec);
         av_freep(&codec);
@@ -1692,13 +1609,8 @@ static uint8_t* mediacodec_jni_getInputBuffer(FFAMediaCodec* ctx, size_t idx, si
     ret = (*env)->GetDirectBufferAddress(env, buffer);
     *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
 fail:
-    if (buffer) {
-        (*env)->DeleteLocalRef(env, buffer);
-    }
-
-    if (input_buffers) {
-        (*env)->DeleteLocalRef(env, input_buffers);
-    }
+    (*env)->DeleteLocalRef(env, buffer);
+    (*env)->DeleteLocalRef(env, input_buffers);
 
     return ret;
 }
@@ -1740,13 +1652,8 @@ static uint8_t* mediacodec_jni_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, s
     ret = (*env)->GetDirectBufferAddress(env, buffer);
     *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
 fail:
-    if (buffer) {
-        (*env)->DeleteLocalRef(env, buffer);
-    }
-
-    if (output_buffers) {
-        (*env)->DeleteLocalRef(env, output_buffers);
-    }
+    (*env)->DeleteLocalRef(env, buffer);
+    (*env)->DeleteLocalRef(env, output_buffers);
 
     return ret;
 }
@@ -1768,9 +1675,7 @@ static FFAMediaFormat* mediacodec_jni_getOutputFormat(FFAMediaCodec* ctx)
 
     ret = mediaformat_jni_newFromObject(mediaformat);
 fail:
-    if (mediaformat) {
-        (*env)->DeleteLocalRef(env, mediaformat);
-    }
+    (*env)->DeleteLocalRef(env, mediaformat);
 
     return ret;
 }
-- 
2.44.0

_______________________________________________
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".

  parent reply	other threads:[~2024-02-27 14:56 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 22:50 [FFmpeg-devel] Add protocol for Android content providers Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 1/7] avcodec: move ffjni to avutil/jniutils Matthieu Bouron
2024-02-14 18:18   ` Michael Niedermayer
2024-02-14 22:23     ` Matthieu Bouron
2024-02-14 23:31   ` Mark Thompson
2024-02-15  7:40     ` Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 2/7] avutil: add av_jni_{get, set}_android_app_ctx helper Matthieu Bouron
2024-02-27 13:42   ` Andreas Rheinhardt
2024-02-27 14:46     ` Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 3/7] avformat: add Android content resolver protocol support Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 4/7] avutil/jni: use size_t to store structure offsets Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 5/7] avutil/jni: remove unnecessary NULL checks before calling DeleteLocalRef() Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 6/7] avcodec/mediacodec_wrapper: use an OFFSET() macro where relevant Matthieu Bouron
2024-02-13 22:50 ` [FFmpeg-devel] [PATCH 7/7] avcodec/mediacodec_wrapper: remove unnecessary NULL checks before calling Delete{Global, Local}Ref() Matthieu Bouron
2024-02-15  4:13 ` [FFmpeg-devel] Add protocol for Android content providers Zhao Zhili
2024-02-15  7:57   ` Matthieu Bouron
2024-02-15  8:46     ` Zhao Zhili
2024-02-15  9:13       ` Matthieu Bouron
2024-02-24 11:29         ` Matthieu Bouron
2024-02-27  7:17           ` Matthieu Bouron
2024-02-27 13:14             ` Zhao Zhili
2024-02-27 13:19               ` Matthieu Bouron
2024-02-27 14:50 ` [FFmpeg-devel] Add protocol for Android content providers (v2) Matthieu Bouron
2024-02-27 14:50   ` [FFmpeg-devel] [PATCH v2 1/6] avcodec: add av_jni_{get, set}_android_app_ctx helper Matthieu Bouron
2024-03-04 11:30     ` Andreas Rheinhardt
2024-03-04 15:11       ` Matthieu Bouron
2024-03-04 16:35         ` Matthieu Bouron
2024-03-04 19:36           ` Matthieu Bouron
2024-02-27 14:50   ` [FFmpeg-devel] [PATCH v2 2/6] avformat: add Android content resolver protocol support Matthieu Bouron
2024-03-04 19:37     ` Matthieu Bouron
2024-03-17  4:33       ` Zhao Zhili
2024-03-17 22:34         ` Matthieu Bouron
2024-02-27 14:50   ` [FFmpeg-devel] [PATCH v2 3/6] avutil/jni: use size_t to store structure offsets Matthieu Bouron
2024-03-04 20:10     ` Andreas Rheinhardt
2024-03-05  7:58       ` Matthieu Bouron
2024-02-27 14:50   ` [FFmpeg-devel] [PATCH v2 4/6] avutil/jni: remove unnecessary NULL checks before calling DeleteLocalRef() Matthieu Bouron
2024-02-27 14:50   ` [FFmpeg-devel] [PATCH v2 5/6] avcodec/mediacodec_wrapper: use an OFFSET() macro where relevant Matthieu Bouron
2024-02-27 14:50   ` Matthieu Bouron [this message]
2024-03-04  8:21   ` [FFmpeg-devel] Add protocol for Android content providers (v2) Matthieu Bouron
2024-03-14  8:04     ` Matthieu Bouron
2024-03-17 22:28   ` [FFmpeg-devel] Add protocol for Android content providers (v4) Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 1/6] avcodec: add av_jni_{get, set}_android_app_ctx helper Matthieu Bouron
2024-03-17 22:38       ` Andreas Rheinhardt
2024-03-17 22:43         ` Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 2/6] avformat: add Android content resolver protocol support Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 3/6] avcodec/jni: use size_t to store structure offsets Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 4/6] avcodec/jni: remove unnecessary NULL checks before calling DeleteLocalRef() Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 5/6] avcodec/mediacodec_wrapper: use an OFFSET() macro where relevant Matthieu Bouron
2024-03-17 22:28     ` [FFmpeg-devel] [PATCH v4 6/6] avcodec/mediacodec_wrapper: remove unnecessary NULL checks before calling Delete{Global, Local}Ref() Matthieu Bouron
2024-03-19 17:49     ` [FFmpeg-devel] Add protocol for Android content providers (v4) Matthieu Bouron
2024-03-23 10:40       ` Matthieu Bouron

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=20240227145536.281991-7-matthieu.bouron@gmail.com \
    --to=matthieu.bouron@gmail.com \
    --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