From patchwork Sun Mar 17 22:28:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 47151 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:958e:b0:1a3:31a3:7958 with SMTP id iu14csp700558pzb; Sun, 17 Mar 2024 15:32:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVaDGh+ILZWW4pSTF2fielHneTeynOdiEpzTllUuMtrfW+E9omqTORniALYj+kLkJidk2JUyTqahX7YUlDz2rzTDZ1X+JrTTJi1lQ== X-Google-Smtp-Source: AGHT+IE3V5vsd4j3VbUUCV1NkutygXbdnOdHbGDWZAoqrVJaI5Gh0Mmo9DNzaDpGY5mYhDxCRsRQ X-Received: by 2002:a17:907:7797:b0:a46:485a:3163 with SMTP id ky23-20020a170907779700b00a46485a3163mr6649128ejc.6.1710714733884; Sun, 17 Mar 2024 15:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710714733; cv=none; d=google.com; s=arc-20160816; b=YuS4Ja/aN0MpfbHYvGVxSk2DVLZ0ql9tNq8x859AAGsEy+jOGv+CRUL5F3PKejASME YVSR3vlXxGlkAn9gMeTNK73TyEg7JTZGQFWLeV3E2h518OMYmQ7rIqdNAG12sSsFwVfZ 8EVA2DnB5TuCiHJjQGPL4EZcLOP86DTIfDOU9naHYrRJqXoTb89opJG8ZJW5tN0szsFz +XZ1QZIUWyPYr9bJ5Je2WA6yYwwyNNi5oeAr2jH0hXpBBzE927BTnKdVnoIwBTvjgu1Q sKZUbTlt7omw7EjNAN96Gh79RAL59Z+tz7BHpegTH71iTE8OpI1pFXqihyZllYT4aW1G 8r6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=pIxgB99eOwL5+uuew2H7uifaqdYTQg81cHpN8nQny8o=; fh=bsOL+ub9JEnfNazRgCdgjxJAChubFVskZxBzYcxeDLU=; b=dtKqgfJNs1qpajPX/7jOubl/hVHxwoTpP08RvyT5c8UyFoeAjQDB7dWPFiCrYW48z5 mfi6gG+36QimWRSTGw7bKvi3Il18Y3znDCPIRfir0K0vhP00uvvcblNvV9cC3+R3XFJw /uewv2DasFi7hS7eDeUv9X3cxHbHkqjHN/R1Ws18zPAslVypcWrJYh27RCk0zhiYGvY1 PRHaj0JvscR8E9KcFGu0QhClaBbOWo9hO30b3q2aBCha63qFqzCYqQyMeRApMPEgXB4R NXgR8Q0UO1g1YnMmBfSFl7jvppJZEwGOhxfCGu3HvxNS+aFUMfez0mZicKhUjzKMo2cy Sp7Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=LvBKUlNm; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h7-20020a17090619c700b00a4535a7db44si3815370ejd.51.2024.03.17.15.32.13; Sun, 17 Mar 2024 15:32:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=LvBKUlNm; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 172AC68D226; Mon, 18 Mar 2024 00:31:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8296B68D1CD for ; Mon, 18 Mar 2024 00:31:10 +0200 (EET) Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33ec8f13c62so2728435f8f.0 for ; Sun, 17 Mar 2024 15:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710714670; x=1711319470; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DDzOVF3maP9Po5HKxlvTyuOnMaRpz7ktNvC2kYuDWn8=; b=LvBKUlNm9Bbaja0bOu+h3XZjgIGWixZ1sQOgPddekNjAm8HKR5DbRjz53QWH3TbgKW G+A/2yvRkAxdJliVayaTGOGFmWbiID8QSHMjh5JyhR6b6khklPyHniALcSl/xvllykEq ISbCMoOkWcn4d9g29hQSnPpb0P28+XAms3tL99VA+FMnnj4dZMwpQiMQRDKn6tSMpd1K dvzg0kp8SmfuMYn360Y3KSRr0sWJj4EGcX0ty0sGPHRyaWZCGxPa0/nQmM93TW9Ug9ej jz9zkipIbz2IMTK230dPuOhzAwjrp3ZnPAxQRghLdEjjGP8Q1imA2kMis6FE3WwkCG46 AVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710714670; x=1711319470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DDzOVF3maP9Po5HKxlvTyuOnMaRpz7ktNvC2kYuDWn8=; b=ak/81PkG7lIgp8r4cqHnGyovE4oqPk57pUGqgRuVCbzWkRGyfVI6QeMgsOhSS77VR6 Q48kKxVjyn8Owpo118zlEDXmR02InHF4e5d0LwHlRGKvlmfX/f2ScOFNom3wbrCcIKI1 o1Tl/Rj7o4q7lxE3EUbYhtWjwUwZNNNYik8f9pa4hzkqvI6xFO4cWwmbnbjL7O4MouKh Y9YdQTF6PjqhGgSkeA1ymw1sJ7CyhvS3avwppSbUbKhi3QtHe7x/fXBQescz+06+RQXR wd27s/solrGwUa8ghhXOSyxXxvtDM35fZQzPJRbZ7pyErySKxVXY6Z3extwjsv+K3L+4 iWow== X-Gm-Message-State: AOJu0Yx5kmOS9KYysXOFTxtCJtEF9tQ2mh7TF/VMlilsH0Uii/qEM7ZS 5sR2JAC+kP52PdLXlGF1CLgy7OmWNA5Rsp9gHIa4fPjufMFFFHQca+tD0Zzo X-Received: by 2002:a05:6000:1c6:b0:33d:f60e:5c6c with SMTP id t6-20020a05600001c600b0033df60e5c6cmr6446116wrx.53.1710714669763; Sun, 17 Mar 2024 15:31:09 -0700 (PDT) Received: from localhost.localdomain (2a01cb040b6872000000000000000afa.ipv6.abo.wanadoo.fr. [2a01:cb04:b68:7200::afa]) by smtp.gmail.com with ESMTPSA id g18-20020a05600c4ed200b00413f3b16a26sm12183682wmq.35.2024.03.17.15.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 15:31:09 -0700 (PDT) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Mar 2024 23:28:37 +0100 Message-ID: <20240317223102.49414-7-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317223102.49414-1-matthieu.bouron@gmail.com> References: <20240227145536.281991-1-matthieu.bouron@gmail.com> <20240317223102.49414-1-matthieu.bouron@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 6/6] avcodec/mediacodec_wrapper: remove unnecessary NULL checks before calling Delete{Global, Local}Ref() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Matthieu Bouron Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OOJq83pdSOnC 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; }