From patchwork Fri Jan 24 22:48:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17525 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 6C3B5449962 for ; Sat, 25 Jan 2020 00:48:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 57FD068AF17; Sat, 25 Jan 2020 00:48:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48C0768AFD7 for ; Sat, 25 Jan 2020 00:48:52 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id q6so3893287wro.9 for ; Fri, 24 Jan 2020 14:48:52 -0800 (PST) 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=2A8KKkro2JC1Djp528xnb3VkPSfJxWnjODbQKXsAXO4=; b=Qsh6FlSorG8y8kytbgiUsaCsfuWNH/6YJwzTZgUf7LwLigQm9qM8lACOB9DeJNJ6+G fPMrUY5bCW/a2JYBsSS8GBMbpDP+2ifXtp+w2odcKeMtd1SXPbdbNFk2U/SKHUA5l7xL sg07yO/bSUEg6oBuQeQqJnb6piMTxE7n4tt+0GJ+OS0GZsav5Wdmt5tdPbff/mgCp3iv LvhuglTMtp8Fv5xzWLsyuDrYAkCyCPr4Pztm6TW++xiI0O2FY1wc63GStp5cWjgf0lRW xxzUQpzv9VAtee1G7RgVJ7v8tH7AbQ9hAnjha+Ldvg+YQFUK9wnIh//ah1MDyQmE9iX+ qKZg== 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=2A8KKkro2JC1Djp528xnb3VkPSfJxWnjODbQKXsAXO4=; b=eH6ZFhqlcmXrzPyJ6Tsy/dAhQJPwSf5u/DbBanwvzA1u8DdkkdD2O4q1ZZb5biax4n jnuQ+QhM3oHmAfJNZjb8QYk4bfdQNHZol7rJ1sxrv6JDDGwyq4NgCffIY4Z5OXbsKuDT QWJBNSx/kDiDAhCmSypM+NpJ74alQt+W5M39uBE/8m7UCHEB0wY/AAtx5I9M5ga0Iy+3 IUaiu5K+L4oset8oWslWiRayC7Z0b9nFUd2ZidzetsLxdbDdtjM5ZclDEZgsZVLDCc6V tdAxuEDfPcLDKJFZerBar4GWWg78oVJzY3l7nlKFvaRhV85jxeF1/g1RzNN9o3hzhwt5 x9Ag== X-Gm-Message-State: APjAAAXOMgCDScGd2eORjzF5gFtRCo6uuaUtKWZC3ZewbprHR32GbuAQ iPqb/im1T0aDiQkM8UUy/ZBiFP2j X-Google-Smtp-Source: APXvYqwteOU0GpG4JEwITVb5X8WNv1l9FZrnUumA8apoLb++55KD9VdwVBdWwYdow9see1VGlmVANA== X-Received: by 2002:a5d:4983:: with SMTP id r3mr6365506wrq.134.1579906131221; Fri, 24 Jan 2020 14:48:51 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id z25sm8977594wmf.14.2020.01.24.14.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 14:48:50 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 23:48:32 +0100 Message-Id: <20200124224833.17579-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123160832.2020-1-andreas.rheinhardt@gmail.com> References: <20200123160832.2020-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/12] avformat/hevc: Clarify documentation of filter_ps 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" and use it to avoid unnecessary initializations and frees in ff_hevc_annexb2mp4() and ff_hevc_annexb2mp4_buf(): Even if the caller does not want to strip HEVC parameter sets away when converting from Annex B to mp4, a pointer has been initialized to NULL and later freed while still being NULL despite having not been used at all. The reason for this is that there is still a jump to the end of the function in order to set a variable (returned via a pointer argument) containing the number of parameter set NAL units stripped away to zero. But if the caller does not want to strip these parameter sets away, it is pointless to set this variable. Document this behaviour and remove the jump. Also document that said number won't be set on error (in case of ff_hevc_annexb2mp4_buf(), this was actually the behaviour anyway) and remove the jump to the end on error, too; this also allows to avoid initializing the pointer mentioned above. Signed-off-by: Andreas Rheinhardt --- libavformat/hevc.c | 8 +++----- libavformat/hevc.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavformat/hevc.c b/libavformat/hevc.c index 616e9ed49a..b07897d9a5 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -1000,16 +1000,15 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, int size, int filter_ps, int *ps_count) { int num_ps = 0, ret = 0; - uint8_t *buf, *end, *start = NULL; + uint8_t *buf, *end, *start; if (!filter_ps) { - ret = ff_avc_parse_nal_units(pb, buf_in, size); - goto end; + return ff_avc_parse_nal_units(pb, buf_in, size); } ret = ff_avc_parse_nal_units_buf(buf_in, &start, &size); if (ret < 0) - goto end; + return ret; ret = 0; buf = start; @@ -1037,7 +1036,6 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, buf += len; } -end: av_free(start); if (ps_count) *ps_count = num_ps; diff --git a/libavformat/hevc.h b/libavformat/hevc.h index 0f56325c1c..3ff4614022 100644 --- a/libavformat/hevc.h +++ b/libavformat/hevc.h @@ -42,9 +42,10 @@ * @param buf_in address of the buffer holding the input data * @param size size (in bytes) of the input buffer * @param filter_ps whether to write parameter set NAL units to the output (0) - * or to discard them (non-zero) - * @param ps_count address of the variable where the number of discarded - * parameter set NAL units shall be written, may be NULL + * or to count but discard them (non-zero) + * @param ps_count if filter_ps is nonzero, address of the variable where the + * number of discarded parameter set NAL units shall be written + * on success; otherwise ignored; may be NULL * @return the amount (in bytes) of data written in case of success, a negative * value corresponding to an AVERROR code in case of failure */ @@ -68,9 +69,10 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, * @param buf_out on success, address of the variable holding the address of * the output buffer * @param filter_ps whether to write parameter set NAL units to the output (0) - * or to discard them (non-zero) - * @param ps_count address of the variable where the number of discarded - * parameter set NAL units shall be written, may be NULL + * or to count but discard them (non-zero) + * @param ps_count if filter_ps is nonzero, address of the variable where the + * number of discarded parameter set NAL units shall be written + * on success; otherwise ignored; may be NULL * @return 0 in case of success, a negative value corresponding to an AVERROR * code in case of failure * @note *buf_out will be treated as uninitialized on input and won't be freed.