From patchwork Wed Nov 27 12:22:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16451 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 C34F3449287 for ; Wed, 27 Nov 2019 14:23:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9CC8368B0B5; Wed, 27 Nov 2019 14:23:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58F1268B07C for ; Wed, 27 Nov 2019 14:23:02 +0200 (EET) Received: by mail-wm1-f53.google.com with SMTP id y23so232873wma.0 for ; Wed, 27 Nov 2019 04:23:02 -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=C6dmlWk0RITa4xviB5QYGJ5+fg12cM9XT9gRklxBuZc=; b=M3v9fd0V30gBtE7fXmrYF1tJuuSIP9XRJT9SySAzKm2cVzTBtIMeuu9uBbKuXpyGoD uDn4UT5tdroaG78l9rOzLRF+9oVuCfMWFsmnaz/BKYkQR0keh694g8W3WPauPfg581PY 9tMf7BkKmIkO6BNgAIp8O+h7lczIi2CxkxA+TNomxCCTWhD/QEH44+1EBlebIvTTWENk 4TbpByLH0yy9QObHO545ak1MZJ1o7sx84sNq30OJEBsbBp21T6KPZBzK09Z9hiz9cphe nB1i8bRbwjTA6aSu+AsoYIyPy0E556IpvsT9upx2bIy7WZwQmNAJe6nCSVUO1eYFdq3d /cvQ== 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=C6dmlWk0RITa4xviB5QYGJ5+fg12cM9XT9gRklxBuZc=; b=uJDTJTzf5eH9BJDrfRqz+mTdFViqnhydMNQuC4jXHeIbnOA/pfPV1VwqpNbIvb2VO1 P+LNhYsx5AvnS35+nhqFbxNFHBeKGejaEHtFR5Bs1vNPU/A+LnXPO9o13I2HY83WH14h yslwFqeV1p0eyu2ncwUW4sjK6K5blQs30DynDxc5Bg1ehDjz5onyq1BvZwE2HpDgCxqm gXq7EPJH6HmcfmPIqlDyH/pWJxxDHMdN+Y5dLb8gGp9iY+CBt/9X1rK7L/au1QCmmkXY wJp4Hr7qijYwgS4zgKDltOhc+NTsZcKtE+Pmf5pPT8LgcppVRwbhoovL4y/fHJGPFkFB qljg== X-Gm-Message-State: APjAAAWEqXzlBd6tCczAly94mYZQXd+upJRXEeDXvidhShy++HHz4IbC ZGJ6BomZ1MxE9mjUVvEPXc3jJxam X-Google-Smtp-Source: APXvYqztHvH9zeQ0O9knVv2oIVziQPzMAOf5wmASzB9gINLIpeaWQxxqGq5P4FMQV6jVLQQahhXfkA== X-Received: by 2002:a1c:3c86:: with SMTP id j128mr4085646wma.137.1574857381697; Wed, 27 Nov 2019 04:23:01 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id r2sm6905614wma.44.2019.11.27.04.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 04:23:01 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Nov 2019 13:22:06 +0100 Message-Id: <20191127122211.6352-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127122211.6352-1-andreas.rheinhardt@gmail.com> References: <20191127122211.6352-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] avformat/apetag: Avoid allocation for small tags 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" By using avio_get_dyn_buf() + ffio_free_dyn_buf() instead of avio_close_dyn_buf() + av_free() one can avoid an allocation + copy for small tags. Furthermore, it simplifies freeing. Signed-off-by: Andreas Rheinhardt --- libavformat/apetag.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 8cb3f4a23a..4e19f49bf1 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -186,11 +186,11 @@ int ff_ape_write_tag(AVFormatContext *s) { AVDictionaryEntry *e = NULL; int size, ret, count = 0; - AVIOContext *dyn_bc = NULL; - uint8_t *dyn_buf = NULL; + AVIOContext *dyn_bc; + uint8_t *dyn_buf; if ((ret = avio_open_dyn_buf(&dyn_bc)) < 0) - goto end; + return ret; ff_standardize_creation_time(s); while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) { @@ -211,7 +211,7 @@ int ff_ape_write_tag(AVFormatContext *s) if (!count) goto end; - size = avio_close_dyn_buf(dyn_bc, &dyn_buf); + size = avio_get_dyn_buf(dyn_bc, &dyn_buf); if (size <= 0) goto end; size += APE_TAG_FOOTER_BYTES; @@ -239,9 +239,7 @@ int ff_ape_write_tag(AVFormatContext *s) ffio_fill(s->pb, 0, 8); // reserved end: - if (dyn_bc && !dyn_buf) - avio_close_dyn_buf(dyn_bc, &dyn_buf); - av_freep(&dyn_buf); + ffio_free_dyn_buf(&dyn_bc); return ret; }