From patchwork Wed Jun 19 23:45:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13621 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 4175F448AA5 for ; Thu, 20 Jun 2019 02:55:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1EBD068AB11; Thu, 20 Jun 2019 02:55:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BD68B68AAF0 for ; Thu, 20 Jun 2019 02:55:33 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id p11so1036308wre.7 for ; Wed, 19 Jun 2019 16:55:33 -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=mVtCtB0Cs8k5osTPQQ4CEfLy+NVkgGtXbyAa/wmkeFE=; b=kGLgtPlQfxb15n40LUjfU3uAshJ4ieRdLc5FMoXoII0H7Mkll0sK4YnXpyawOWdUnj IMnhaSyl8i9B2dBoQ7DoSwlo1E4dqHYF6m9NQzTaZss8PfVamOG9NrfnJjm4Lz/MSDz1 o3vgGezz2M76LX1apjuvhVoL3TpTVfQGnHkdf08hQyxlzk3Qwrg4cFPc2bMyh6PHDwMM dbLygq2KakJ+ErrSZXv1lRrvz+wLWV2joqHe5bORLr05LmR6sacjPAO7qZAZfK9qFQ82 lVXq1zgojhFs9mdXqkFkREl8yhVoQgQXqHUxOEh8Jd6wj4iEP/4QygRGP/7C+Fz7NxMT cLig== 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=mVtCtB0Cs8k5osTPQQ4CEfLy+NVkgGtXbyAa/wmkeFE=; b=dpwzaxpKM03UkiYF2yzyyOZt5cz/bp/Z5pn+5SJ6Vkvv/4iPDFJys+uQyE49CzE/7d ldPjbZhMkVbnZbHo9m9A0cdcf4QFs0+ddDw7CBbVtwpiYZkBbkWB1xKfNEdhQyuX7kOZ YwqzDBH4hjvfCUjMe1WPaFVmjR0doOliTvrxJZ8GC9NNYNC2VUc6eLul//kkLCj2WbYF IH65f7M4teCAiEYwytgUMAI2PdYeYmwszXIQGhY6htnQV/9w/UF0ktubjl1BKy6/4gvl 0OhNMVZ05hwVCK7r/GRhmwwbbJXqaIbGeGgB+W2t2aqK9CKvwjryJ6/xQMH7EGnSV2Ue rQ+A== X-Gm-Message-State: APjAAAVzUoxikJ6tKgMRifcxJYqCkIJ64iqnGdONy9zYMjxV048pcr+p 1RCBkb1WEY+gXezcMX0Lq7O7WGvQ X-Google-Smtp-Source: APXvYqxb3XeX9QDdggqOjHRldut09bwIa4YKXgRvdGY2F+cJhaO0ApioQdF7eexJ0Eo2dhpy9p1ZDg== X-Received: by 2002:adf:e50b:: with SMTP id j11mr25687989wrm.351.1560988533156; Wed, 19 Jun 2019 16:55:33 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id t63sm2758989wmt.6.2019.06.19.16.55.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:03 +0200 Message-Id: <20190619234521.15619-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619234521.15619-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> <20190619234521.15619-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/31] h264_redundant_pps: 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_redundant_pps 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_redundant_pps_bsf.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index f59c4f57c0..e1f8f673f9 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -66,19 +66,18 @@ static int h264_redundant_pps_fixup_slice(H264RedundantPPSContext *ctx, return 0; } -static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) +static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt) { H264RedundantPPSContext *ctx = bsf->priv_data; - AVPacket *in; CodedBitstreamFragment *au = &ctx->access_unit; int au_has_sps; 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->input, au, in); + err = ff_cbs_read_packet(ctx->input, au, pkt); if (err < 0) goto fail; @@ -94,7 +93,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) goto fail; if (!au_has_sps) { av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS " - "at %"PRId64".\n", in->pts); + "at %"PRId64".\n", pkt->pts); // This call never fails as the fragment has a unit at pos. i. ff_cbs_delete_unit(ctx->input, au, i); } @@ -106,21 +105,15 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) } } - err = ff_cbs_write_packet(ctx->output, out, au); - if (err < 0) - goto fail; - - - err = av_packet_copy_props(out, in); + err = ff_cbs_write_packet(ctx->output, pkt, au); if (err < 0) goto fail; err = 0; fail: ff_cbs_fragment_reset(ctx->output, au); - av_packet_free(&in); if (err < 0) - av_packet_unref(out); + av_packet_unref(pkt); return err; }