From patchwork Mon Jun 17 03:42:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13567 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 5DB53447BCA for ; Mon, 17 Jun 2019 06:49:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3C16E689A11; Mon, 17 Jun 2019 06:49:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 953716801A4 for ; Mon, 17 Jun 2019 06:49:10 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id p13so8222202wru.10 for ; Sun, 16 Jun 2019 20:49:10 -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=GV4lYLN4Ec92OGIAbBfV5y2XCTE/JhYVKrCdZCBbm0k=; b=BnyH3WTpCQ+bAbRzhYWO7dBkkTehN+lPB7CL6duaTxf8Q4iApEPt6tj0BWUHQpBf9W S6KSPUZPbuOrsE4+sT/mcR5jPe91DGlAC9aq/b56SszL6Sel+IsXF0KqNkijIRZIQFff ZEI2W8DUG30qjlV8QvJvtGJ5o3XwFXhfKoZHQcf7hqQ4AI1EJPWqNGqGTkNROD/ZmAot Q+8JKcIMta5FqN9poV0n8cir6Af6O9+Jn0d50Ut+hWJysIOHMpyk5u9zUKntPPk1EzRb R3FzO/u9/Y5ktO869w9ut7A1uosn10G+rrG7dT3J+/8K5kkKSfatLKxo9pteYKr5Ptt7 1eDw== 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=GV4lYLN4Ec92OGIAbBfV5y2XCTE/JhYVKrCdZCBbm0k=; b=hlDR30h9rfuBlSLCwB/RO71XOpJGfJiw9YeyIQ7jvKZQEUSCKRR9DaHctrc43glsrs MnsYlGO3d3CYCnHENGsxXj2pdP0HTj/DwMHGlg6wiNo8xvSsYs1SoJ43xm8GParPP9dF 3DAKVijDNUDakxl4ysMrQvJgmH9LwC9FCfBMgtFqVx7TEBqhuYDWLIJIK/KS/GmG27Y5 yX2MdgdgTNefxbHeAvd0h7BkiF9rqPbNxH/aLO0zMB+B0ol9PaVla+6/TTb1bxHByFdg X38xNuec23IpmXcza275zGHguoS82+jUh36Q37+a/y9vJxcgflPz8xua/algUGE57Mve QTCQ== X-Gm-Message-State: APjAAAUMdq1pSfTkNXaZqY10Q2kU8ZEUPYukFUVa9i+kzdTMs5cmQehm MMsc8erbE8BAbDlAlITRlN/pogE7 X-Google-Smtp-Source: APXvYqywXgN8Sk3oJDrc/BD2Nzm6FIW1p+W8SeZq6VP9lbDjqVE3V+UfRh4mzXinN9vdL4jxlZIIpw== X-Received: by 2002:a5d:430c:: with SMTP id h12mr18577240wrq.163.1560743037902; Sun, 16 Jun 2019 20:43:57 -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.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:43:57 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:11 +0200 Message-Id: <20190617034223.21195-7-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 06/18] filter_units: 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 filter_units 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 (or, in case of passthrough, to av_packet_move_ref). (b) has been made possible by the recent changes to ff_cbs_write_packet. Signed-off-by: Andreas Rheinhardt --- libavcodec/filter_units_bsf.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 8c501e1726..f3691a5755 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -98,24 +98,20 @@ invalid: return AVERROR(EINVAL); } -static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) +static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) { FilterUnitsContext *ctx = bsf->priv_data; CodedBitstreamFragment *frag = &ctx->fragment; - AVPacket *in = NULL; int err, i, j; - err = ff_bsf_get_packet(bsf, &in); + err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; - if (ctx->mode == NOOP) { - av_packet_move_ref(out, in); - av_packet_free(&in); + if (ctx->mode == NOOP) return 0; - } - 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; @@ -139,21 +135,16 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) goto fail; } - 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; - fail: if (err < 0) - av_packet_unref(out); + av_packet_unref(pkt); ff_cbs_fragment_reset(ctx->cbc, frag); - av_packet_free(&in); return err; }