From patchwork Wed Nov 27 12:22:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16452 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 E60E6449287 for ; Wed, 27 Nov 2019 14:23:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C9D5768B0D6; Wed, 27 Nov 2019 14:23:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2348868B0B5 for ; Wed, 27 Nov 2019 14:23:03 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id s14so435807wmh.4 for ; Wed, 27 Nov 2019 04:23:03 -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=ALZBKxIvF78NmbjMmGWme/kGlPd5oEwXfM/Mcr3lXVQ=; b=X5ccoOKk/jk8MTxscpJC6R84nBhcasfAmlqQDNyV4gTKKDAv11ylZ2BtJDAvytKVJc Mek3RXX9Lhmhbzatum3MKCoV4I8trsebNriUE1RXgrwhVZNPH/zv5cg2sGjnIQu6IuBB uiNCwep2C5JS7Ma2/jU+5Dql89R7733lTwuOuHgClOURR90YIiS+7z/cfSor+O/qpaeu Yscr2LxUIauBV2YcCKMbjjcjpsPTl/yS1b8C3fZfesrR1O9CEUJGNQTwOBGieAGh5I9v 5Y1i8a4U2jIGD8i170Rz5cYippcGTbZNYhPMHgNGnyvdpDfJ+Xf7H9W+QOGeLDe/we8k Yf8Q== 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=ALZBKxIvF78NmbjMmGWme/kGlPd5oEwXfM/Mcr3lXVQ=; b=uCMcdA1FEl8LLSfSoSZPqFcpq6eGtu0nuWoxhHjkV5c8q4e2sQVRjhIhoHCK829TBS S2sVcFTq2aqjUGnFc0LXD/A2l98wLu1AXpm1GuHRJAIAlANQQjgyyTuoD+HKPLiDU+IT niZ1Ccjjw8VkqMf190fremtk067+CFYjhToe/3nvOEwy7RFpOPuzR+6sMx34zC0fVCGU 0RNUxpkETkVmH8321boebKwEVHxaAL/hE9KzCVuONQCSmB6CqMWNeHgt7XtBmAizvAng u+GGKXn8jLv5Xj9eRL5LMlShUl/AffmUkjDezG1ypPjJ88Pu1rw/IeY7aeZWM3DvEfS+ NsOQ== X-Gm-Message-State: APjAAAXXbp9j3xciQaMCJ1jbBdK4dhVpUrlpwRoZ83AcfoOgy/mpz42O AqqfJzH5EzMTx5SeCRt2o+wzuwbr X-Google-Smtp-Source: APXvYqx0qs1Z3VzE+Ek9ISOmw2VjwScjvTPJ4gBr47+cLk/gq941V9nzjxESPGHKgh8fg+znP00/OQ== X-Received: by 2002:a1c:f303:: with SMTP id q3mr3933965wmq.98.1574857382547; Wed, 27 Nov 2019 04:23:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 04:23:02 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Nov 2019 13:22:07 +0100 Message-Id: <20191127122211.6352-3-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 3/7] avformat/av1: Avoid allocation for small headers 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 headers. Furthermore, it simplifies freeing. Signed-off-by: Andreas Rheinhardt --- libavformat/av1.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavformat/av1.c b/libavformat/av1.c index 03669dfd2a..132f4e987b 100644 --- a/libavformat/av1.c +++ b/libavformat/av1.c @@ -326,7 +326,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) AV1SequenceParameters seq_params; PutBitContext pbc; uint8_t header[4]; - uint8_t *seq = NULL, *meta = NULL; + uint8_t *seq, *meta; int64_t obu_size; int start_pos, type, temporal_id, spatial_id; int ret, nb_seq = 0, seq_size, meta_size; @@ -376,7 +376,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) buf += len; } - seq_size = avio_close_dyn_buf(seq_pb, &seq); + seq_size = avio_get_dyn_buf(seq_pb, &seq); if (!seq_size) { ret = AVERROR_INVALIDDATA; goto fail; @@ -401,17 +401,13 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) avio_write(pb, header, sizeof(header)); avio_write(pb, seq, seq_size); - meta_size = avio_close_dyn_buf(meta_pb, &meta); + meta_size = avio_get_dyn_buf(meta_pb, &meta); if (meta_size) avio_write(pb, meta, meta_size); fail: - if (!seq) - avio_close_dyn_buf(seq_pb, &seq); - if (!meta) - avio_close_dyn_buf(meta_pb, &meta); - av_free(seq); - av_free(meta); + ffio_free_dyn_buf(&seq_pb); + ffio_free_dyn_buf(&meta_pb); return ret; }