From patchwork Mon Jun 17 03:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13578 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 B7A344400A9 for ; Mon, 17 Jun 2019 06:50:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 978FA68A2FA; Mon, 17 Jun 2019 06:50:33 +0300 (EEST) 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 50FB5689D68 for ; Mon, 17 Jun 2019 06:50:31 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id f17so4943696wme.2 for ; Sun, 16 Jun 2019 20:50:31 -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=5Yd8wZssCoI2CFyxAUmSmTUkg7dENCgSuXQUgWwAxlk=; b=L3hm7bDYG0Kp+rMICNHJWO25HxnIb1Pq00N8ZaJCKtNaEZ0mcpKwlXT6VwYeL3oSMv 5ywNrUjcroYokuLCu+OsILEkG0P8l2KDqH5GUpR7oKGLi5/YqU+y0c6SkBLWTK79P0vs tE0zUJSXQCREJnNXy3DoPx5EwfMjIXLaOH4vwDk6ayO0lIpDeJE3h78Z57iyxR6nHRmu SJoDQQSBDGg0vobvYvS4EVCwXOUbVsdoZlXcNce8sz7IorYKnj2yw9qNTo415mUpYlqs GjQSfywBtIkVyF9Rw2XJOp9gqdSDROwX8VNlm7nMBYg6bQNB89rRpeIiBZabHdnSKhJ5 ggRw== 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=5Yd8wZssCoI2CFyxAUmSmTUkg7dENCgSuXQUgWwAxlk=; b=XKGEm+NWnLN6cUnL/+s/+NxPKZgF2GXKBqeH5QOHaymIFHSzXb6TuKinmMLZwI526m tIU3vibtyqHxWalnlBEpckriHR7UD7VaOzP0ja5jH4cN3RJ/6KQWxWEK+yQwmT9oOA4x jzcnP3895Gh2kld772ZgV6CamVXR+bYhFgHeVu6IcLt5h5KZg0/Lye8kVYB/Uf4dyoiS yJJX9/28jkZoHT3B4zsEYBGPY7Ajq/ArXtDJ0kN6x+4dKK2bMVkouxmHMhd5orN0ZwK2 dERqItOKKWb21NG1kemBWAyYn8eRzaxW5q3BfMuYDw/BvrCD08dgCn7O5vlWY0BIy/mM zZMg== X-Gm-Message-State: APjAAAWkYv9PHxgvb27Jj/JOrozzR3noKcnAbeeQf/76jUj8qeGsuvWx nWY4y7M5KKdCKvaPQE1EUAj61zrC X-Google-Smtp-Source: APXvYqz5XZ0ofpNGYkmKyvh1mkseu6iU9HFflzlHq09UmNhLwV0cRGZfkMhl17TgM2hrG0epJbz5OA== X-Received: by 2002:a7b:cbcb:: with SMTP id n11mr16258650wmi.146.1560743044674; Sun, 16 Jun 2019 20:44:04 -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.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:44:04 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:19 +0200 Message-Id: <20190617034223.21195-15-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 14/18] h265_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 h265_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/h265_metadata_bsf.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c index 0683cc2f9d..2fb74aea5a 100644 --- a/libavcodec/h265_metadata_bsf.c +++ b/libavcodec/h265_metadata_bsf.c @@ -230,18 +230,17 @@ static int h265_metadata_update_sps(AVBSFContext *bsf, return 0; } -static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { H265MetadataContext *ctx = bsf->priv_data; - AVPacket *in = NULL; CodedBitstreamFragment *au = &ctx->access_unit; 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, au, in); + err = ff_cbs_read_packet(ctx->cbc, au, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -310,23 +309,18 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) } } - err = ff_cbs_write_packet(ctx->cbc, out, au); + err = ff_cbs_write_packet(ctx->cbc, pkt, au); 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, au); if (err < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return err; }