From patchwork Mon Jun 17 03:42:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13574 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 A15A9447BCA for ; Mon, 17 Jun 2019 06:49:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8BD8968A0C7; Mon, 17 Jun 2019 06:49:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3FA60689A7A for ; Mon, 17 Jun 2019 06:49:49 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id x17so8234486wrl.9 for ; Sun, 16 Jun 2019 20:49:49 -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=buQxwywBFBJfk1b8KAs70t6juQxN7KVKSXOQ/I9tccc=; b=qduztlRDu6VSpzysSU5c4OouFJRMa0reFQfNn+wsXJrneDl37o8U4D3jpInxlfnoGb Nfn2zLMm7vP9npYhoF3HSPfDthbAjzZESNZwk+PLGu38RVQ35u0vL0foafQyl6+lORx9 Uui1ms9pHTWKqwKbbBv8IrjkJubOQOK+ZDYnOUtOlerXYRFaAahWlWgxAL1Cvtwr4rd2 Vg9GbTLVHOvOEoyTHpN9WoxtLfg5sKwMZhtbIfyPut0lupUVA6aVFcAyBuNV/Bjv/xh+ 8GXCMpApRzowslriKJpw4UDUa+n/2EUTUnY7kURYm5y/1QSnOZy2UT5q2rsHv3hiolAr bk8A== 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=buQxwywBFBJfk1b8KAs70t6juQxN7KVKSXOQ/I9tccc=; b=g/lNq66ttBsBGC4Ft/bDLHZ+VW5OGhLavHQLimTIuMwg2zZnOC0dpO7O3my5kA/VAb +Uutjc+j2PYl1GUR6nUlrDXL+tJeUg1yq661Kr3we6y2rWCQvAbUoSIeyewv40JTGxyO cDsfnuaoVlnPV1CPnlYUYsnnWpM/PbNOHGnPxiFW9SvgSUuaPf55M5VeFtDG5R3IHcM3 qNQxq5NMMLsrg86KlzZq8OurD3+Vu1NJ0FD6+tsHpT0iw5tw8najjKlvIC/cKUeFv057 EUaE+GHPJSPOe4rX1ysQlvkFs+HNzTXOw6oexgIKKo8peOl5TaPGtIuYNSLzJwz/NR02 bsEg== X-Gm-Message-State: APjAAAWOTTNCkY8EesoJMbVQ6pknPm0FC3MGNRO5fj4+NwZr2AeoAbPR kffCzfUuXV5OHiLT8XetqfcXHytX X-Google-Smtp-Source: APXvYqy/VB12bVJKr3vy4i8TcLJFnywW/a0gajuseSBV/ecabPZvW1CjnYO4mCtZecLaI3DkEwmfVA== X-Received: by 2002:adf:b1ca:: with SMTP id r10mr21016276wra.156.1560743039632; Sun, 16 Jun 2019 20:43:59 -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.43.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:43:59 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:13 +0200 Message-Id: <20190617034223.21195-9-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 08/18] h264_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 h264_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/h264_metadata_bsf.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index b95d2341dc..18c5ae807d 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -283,21 +283,20 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, return 0; } -static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { H264MetadataContext *ctx = bsf->priv_data; - AVPacket *in = NULL; CodedBitstreamFragment *au = &ctx->access_unit; int err, i, j, has_sps; H264RawAUD aud; uint8_t *displaymatrix_side_data = NULL; size_t displaymatrix_side_data_size = 0; - 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; @@ -518,7 +517,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) int size; int write = 0; - data = av_packet_get_side_data(in, AV_PKT_DATA_DISPLAYMATRIX, &size); + data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size); if (data && size >= 9 * sizeof(int32_t)) { int32_t matrix[9]; int hflip, vflip; @@ -578,18 +577,14 @@ static int h264_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; - if (displaymatrix_side_data) { - err = av_packet_add_side_data(out, AV_PKT_DATA_DISPLAYMATRIX, + err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, displaymatrix_side_data, displaymatrix_side_data_size); if (err) { @@ -608,8 +603,7 @@ fail: av_freep(&displaymatrix_side_data); if (err < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return err; }