From patchwork Wed Jun 19 23:45:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13618 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6CBC2448AA5 for ; Thu, 20 Jun 2019 02:55:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5352668AAD3; Thu, 20 Jun 2019 02:55:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E46D68AAC2 for ; Thu, 20 Jun 2019 02:55:20 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id g135so1164960wme.4 for ; Wed, 19 Jun 2019 16:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g2kuZNunVO1sNXG07oBNloxT9QKCwtZ6zAYEPno1RG4=; b=NyNLIF4gPSOXLfT+vJNKVTqOLBCuM0qBy8g8PutlGy1w1kLG3kKrzLPLIxUiZrhLo0 1ZTi9410wMo87HmzbAgD8ywvdtjuSKvTV2648ylrwqnMQ0S/NmPaNVZEaOHjNjd1s/gh XJIH9TJrVQYr4CugWlHavlKF01ab5A8uz2PHEQVAcIWnu9u5VvEty5ji0dKd+Dm2QFmm WzFf492Viy8WYD0bZwCDJgSE3vfUzgSGXdKTp6SxW1Ct4W28ehXWQJQT7E852eP/ZP1c h8NK+uewutvhPRIxKce4UGpRpfKN4IzDKsxnj8WQlsBkCIkLzaJIEMZ3CS+gJVyQj3mq ZPMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g2kuZNunVO1sNXG07oBNloxT9QKCwtZ6zAYEPno1RG4=; b=O+8eIItbuGIxS3zaKVUflEaCDY/Lk7bxwyPRKkxD6TDhqgnC9z/Vtkr1loVvgiOI8L quSNBo8mLYlYMddvvu/PMPMShnhsJMdnFvixI/u3Svi0hyD+y4+duIGHyvI/L5xXKIuQ fMIqy+gSYyNgqE5kMdjXnpxCeV1QHHMl1uwpT9RNOoQWdXoxyRwgRVvlqqhn3WmxUd6s S+IW4iV4PDat7id6CmqBpDI0fXX1mm81kfcrOm+KbKK+Zylj0wtpx8hbdYTQwJLPwhPK 1pKpow3rwW/EjoB2qHz/m3w03Dnd923+d27PKzr++n8X3owdMSgnp6pablRMyUAWyB2m LYsQ== X-Gm-Message-State: APjAAAWvXIlRLlygy+un7/DyQqsZAw9dUO058fleBLCSeFeUCc1hIKfn D8v8mHSGy/hCHLU1hpod2rehlDds X-Google-Smtp-Source: APXvYqxikbNvg2MpSr4lLuTsphCCEOAEyS/a7+M6UmZyRRhvi1CGkT1oaBUHjAWrdd88dT+vo1P7pA== X-Received: by 2002:a1c:7e14:: with SMTP id z20mr9731080wmc.83.1560988519353; Wed, 19 Jun 2019 16:55:19 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id t63sm2758989wmt.6.2019.06.19.16.55.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:01 +0200 Message-Id: <20190619234521.15619-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619234521.15619-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> <20190619234521.15619-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/31] cbs: Remove superfluous checks for ff_cbs_delete_unit X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" ff_cbs_delete_unit never fails if the index of the unit to delete is valid; document this behaviour explicitly and remove the checks for whether ff_cbs_delete_unit failed, because all the callers of ff_cbs_delete_unit already made sure the index to be valid. And add some comments to the callers to ensure that it stays that way. Signed-off-by: Andreas Rheinhardt --- libavcodec/av1_metadata_bsf.c | 12 +++++------- libavcodec/cbs.h | 2 ++ libavcodec/filter_units_bsf.c | 1 + libavcodec/h264_metadata_bsf.c | 10 ++++------ libavcodec/h264_redundant_pps_bsf.c | 5 ++--- libavcodec/h265_metadata_bsf.c | 2 ++ 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index bb2ca2075b..9345095277 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -151,6 +151,8 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) // If a Temporal Delimiter is present, it must be the first OBU. if (frag->units[0].type == AV1_OBU_TEMPORAL_DELIMITER) { if (ctx->td == REMOVE) + // This call never fails because we have already excluded + // fragments without a single unit. ff_cbs_delete_unit(ctx->cbc, frag, 0); } else if (ctx->td == INSERT) { td = (AV1RawOBU) { @@ -167,13 +169,9 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) if (ctx->delete_padding) { for (i = frag->nb_units - 1; i >= 0; i--) { - if (frag->units[i].type == AV1_OBU_PADDING) { - err = ff_cbs_delete_unit(ctx->cbc, frag, i); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to delete Padding OBU.\n"); - goto fail; - } - } + if (frag->units[i].type == AV1_OBU_PADDING) + // This call never fails as the fragment has a unit at pos. i. + ff_cbs_delete_unit(ctx->cbc, frag, i); } } diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 5260a39c63..e1e6055ceb 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -380,6 +380,8 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx, /** * Delete a unit from a fragment and free all memory it uses. + * + * Never returns failure if position is >= 0 and < frag->nb_units. */ int ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 380f23e5a7..3068e464f0 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -124,6 +124,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) } if (ctx->mode == REMOVE ? j < ctx->nb_types : j >= ctx->nb_types) + // This call never fails as the fragment has a unit at pos. i. ff_cbs_delete_unit(ctx->cbc, frag, i); } diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index f7ca1f0f09..e3c29cc9ad 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -309,6 +309,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) // If an AUD is present, it must be the first NAL unit. if (au->units[0].type == H264_NAL_AUD) { if (ctx->aud == REMOVE) + // This call never fails because we have already excluded + // access units without a single unit. ff_cbs_delete_unit(ctx->cbc, au, 0); } else { if (ctx->aud == INSERT) { @@ -428,12 +430,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) for (i = au->nb_units - 1; i >= 0; i--) { if (au->units[i].type == H264_NAL_FILLER_DATA) { // Filler NAL units. - err = ff_cbs_delete_unit(ctx->cbc, au, i); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to delete " - "filler NAL.\n"); - goto fail; - } + // This call never fails as the fragment has a unit at pos. i. + ff_cbs_delete_unit(ctx->cbc, au, i); continue; } diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index db8717d69a..f59c4f57c0 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -95,9 +95,8 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) if (!au_has_sps) { av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS " "at %"PRId64".\n", in->pts); - err = ff_cbs_delete_unit(ctx->input, au, i); - if (err < 0) - goto fail; + // This call never fails as the fragment has a unit at pos. i. + ff_cbs_delete_unit(ctx->input, au, i); } } if (nal->type == H264_NAL_SLICE || diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c index 0683cc2f9d..3436f3d0a3 100644 --- a/libavcodec/h265_metadata_bsf.c +++ b/libavcodec/h265_metadata_bsf.c @@ -256,6 +256,8 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) // If an AUD is present, it must be the first NAL unit. if (au->units[0].type == HEVC_NAL_AUD) { if (ctx->aud == REMOVE) + // This call never fails because we have already excluded + // access units without a single unit. ff_cbs_delete_unit(ctx->cbc, au, 0); } else { if (ctx->aud == INSERT) {