From patchwork Wed Jun 19 23:45:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13622 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 2AE58448AA5 for ; Thu, 20 Jun 2019 02:55:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 108DB68AAE4; Thu, 20 Jun 2019 02:55:43 +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 9376168AAEB for ; Thu, 20 Jun 2019 02:55:39 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id n4so993678wrw.13 for ; Wed, 19 Jun 2019 16:55:39 -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=kkjWdD4cVPYv16qPapkERDybCZlWAyLfXgYx8e5rd6c=; b=F6Jn7QWGuGFBvuY8tCN4KVuvsbHSdVWakqfSIyFm3nGbTBpZ7YNPQmH6jY4kpsmmaX jUhDQYEXnCPQp4il6XYbbQy3PVQd5olwHhG4eS1o/RGVOEyzVXsA4SaoZwY/QouIamhi H3HIExylPpEFpcFqbw13ZT5Dn7z3kryb92eFQfda00DNqNnRKPj+trXj38A/nLPL81/D yF3wGKBteLPm73GX8Acbqc4IcGkKj2+mMv378aEPXRdVl9/ypQCGNZffp7quikxsw6CC RZAdeFZ6yX31n1pL/BtH3M7GNoXALS9J8Z0MAxlmyhwxeqV2K3nIZcPQzJsVFca+dP2T /8UA== 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=kkjWdD4cVPYv16qPapkERDybCZlWAyLfXgYx8e5rd6c=; b=aOu9wUfn6W507jIdJU5BcF4VL5G5ZO3S4YaPj3bmAsv7UlsFx0QRcKctBYLhpFaB2j fMwsRW9Ruc0MpyQT+ljnf43nJxeHm4ZSnfDorMWJ7vI8UUcoJgp/dhgCzg1akWnnX/g8 rKlt0Z/cffJD+X+f/2dtpoeSehICmA8Xu0ileP96FfrcPYW7GphZ7h6jgr6JPFx4vc1B 6gmMxXqhNxiypHse55er10XVUCJwE0wCqQiWseZPRMvR/rP54trJOWG9VVMFDEL5Pdqt GNAVfq3OjOekSd+5McE5030SLAaR/B4JM4okkwKSarhcGZJ5BnQB6N8Myp5nK7QFIfx5 nyng== X-Gm-Message-State: APjAAAUgYmrt3DZGE7XmZ5Yo/U/g4wkq8IJ4yXqFOftzhgrQUm3kKKMu zVqx2nLN3jS+SsVQiYbL/iwOC2Xw X-Google-Smtp-Source: APXvYqyuR9XIf0rUr9MqIuAwo0fQ6c/M7h0vBxiDkw59FAtS5Kcfu+JiHDOsxWxc9T3UXhMvhuDxGA== X-Received: by 2002:adf:dc09:: with SMTP id t9mr9845430wri.69.1560988538886; Wed, 19 Jun 2019 16:55:38 -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.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:05 +0200 Message-Id: <20190619234521.15619-7-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 15/31] 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 3436f3d0a3..6009a1990d 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; @@ -312,23 +311,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; }