From patchwork Mon Jun 17 03:42:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13575 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 EFA37447BCA for ; Mon, 17 Jun 2019 06:49:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D5FD9689BE0; Mon, 17 Jun 2019 06:49:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7FF8C68A728 for ; Mon, 17 Jun 2019 06:49:57 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 207so7645242wma.1 for ; Sun, 16 Jun 2019 20:49:57 -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=blMGFBA6swIw+J7Lkc58gHlyGtHEIgyhzcYvQwP6a3w=; b=C1a6i2g7++fy0rGOSvY6AVQ6hWkjAQyiceou46817LjJ8eDMUSylxKCr+RBuuRJRK8 sFRf1ORC2LFy1y0qYx/zYmbvbO6tiA1NYlx/jUWjwrBDUObrnWsBM4RLoq64orxeiCwy YwuiSNQEBvq2cOXVxViTfyvTMr6ovao3h1DeLOlzWur3bDLDc6C8q3IIpXPblzF5sROi apLnL9fNLAN4uRJgROJnyt1sMMtu+Zy7P6wjzLu0RPJor5GYHjiXcxbQHRu5UhOBOAFs iV0msrkJJOTAyGjXspiJzWknlzUXf08Ab5Nj4A94kffBaVrgQY0EazbMW9eAEg5AaNnW 9Z/g== 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=blMGFBA6swIw+J7Lkc58gHlyGtHEIgyhzcYvQwP6a3w=; b=AMcLOgjdLuhdg8MXBzlEFWTHL5GbBTF/6Zz7lYs/6brWLUZu7ir/P3hF8TUhqSE0RG FHWsQEUz/4vX4rEPzfIbKaWPOSCXDUH1PhCqU2RfXWOl5CS2BRHiQHdzkt28fmXjUK6P ih91oI8t3sZsZ1yFns29IPAFihV2zusbHcpBgb//OZzA0ZUFM6QqSMh1finhNH+rZ3sZ IGHY2m/Bz6MsBbZRYpebahBc2aHfsWvuy94gwG2ZVvFu5I36xGk2kWfwvlKVt9EM7X71 bft0LIR0k8ARUtGEtUfps1LchSyWyoVDmKKHTSRxddFBe653WdOwdX/E8GMk2sX/Uh+1 ERfw== X-Gm-Message-State: APjAAAXLTd6W/XCfA49oP3FaEzO/PCkISPpTrrYGZFgYqKcID67hPsy8 b5F6Kzf/ez6qJ7zRjxWYoKMnbapR X-Google-Smtp-Source: APXvYqzv5rUD9B/e1uoVSPwcEarxz4g8qQopzvbHP+z82Vwp03/JUZ4Jl8IuNUwQTXxJGA+g93gFBQ== X-Received: by 2002:a1c:740f:: with SMTP id p15mr11504782wmc.103.1560743048062; Sun, 16 Jun 2019 20:44:08 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id x83sm9632889wmb.42.2019.06.16.20.44.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:44:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:23 +0200 Message-Id: <20190617034223.21195-19-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/18] vp9_metadata: Avoid allocations and copies of packet structures 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" This commit changes vp9_metadata to (a) use ff_bsf_get_packet_ref instead of ff_bsf_get_packet (thereby avoiding one malloc and free per filtered packet) and (b) to use only one packet structure at all, thereby avoiding a call to av_packet_copy_props. (b) has been made possible by the recent changes to ff_cbs_write_packet. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_metadata_bsf.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c index b79f08af6c..1bde1b96aa 100644 --- a/libavcodec/vp9_metadata_bsf.c +++ b/libavcodec/vp9_metadata_bsf.c @@ -37,18 +37,17 @@ typedef struct VP9MetadataContext { } VP9MetadataContext; -static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { VP9MetadataContext *ctx = bsf->priv_data; - AVPacket *in = NULL; CodedBitstreamFragment *frag = &ctx->fragment; int err, i; - err = ff_bsf_get_packet(bsf, &in); + err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; - err = ff_cbs_read_packet(ctx->cbc, frag, in); + err = ff_cbs_read_packet(ctx->cbc, frag, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -74,23 +73,18 @@ static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out) } } - err = ff_cbs_write_packet(ctx->cbc, out, frag); + err = ff_cbs_write_packet(ctx->cbc, pkt, frag); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; } - err = av_packet_copy_props(out, in); - if (err < 0) - goto fail; - err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, frag); if (err < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return err; }