From patchwork Tue Dec 3 11:34:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16558 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 A075F449675 for ; Tue, 3 Dec 2019 13:35:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E8F168B1D9; Tue, 3 Dec 2019 13:35:11 +0200 (EET) 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 31C9868AAF5 for ; Tue, 3 Dec 2019 13:35:05 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id z7so3163658wrl.13 for ; Tue, 03 Dec 2019 03:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KLdtxjpNeN0fBMgczw3Z4+xLQu4SkRuc949oqJ8rH0g=; b=iaM06XeogWkqhwMu0191QDBr4sdMVntpR/8yQV4y9DQzCa8FALeNLiW4bc9Pexkz6y e66g9VlcWxDmn2+8lUMNBbLrcdVW9E+ZwTir6DvTNz/6IWuXcrKCPZ4f50Xq38635eTb q9hr9wZnpmpGPQE2dIWoYOpb1UtmvLwZ8T4W5wzfS8MMdS+29nAJQWI+8f9K51fNF3m7 orJ7rBJLf/CTdmDE6AjDyGZ6oRiT8KIDGISctSFpHSutvvORQKXl56oVGJrb/qmNF8hy WZNuJCVeVFBxu52O4Bdf4mDiDmeKn86+7mMHXMYQ0NQK2OJOMCfFFlE6bnlYK2luZR0/ 9J0Q== 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:mime-version :content-transfer-encoding; bh=KLdtxjpNeN0fBMgczw3Z4+xLQu4SkRuc949oqJ8rH0g=; b=Pw/7pCBbRB0x1UToaF6Eyi6dfA4S2nv8OkOBEgb0E2i2afQUQL30F1d6YRg+zoHvF5 VIgIHv51UxhRleEHhm9UoPuxnWyBGOGKKQtB4dDlUILdZ6TVJLiPFg++uqW2FVInd4wk U0WzlLOZIWbP+okO0zexp7spm4q2nyScDarC1EoPOL+mVAzpEphtZzP1Bh5RSvkD7tnk ZV7FcHiQzByvXCcE8Pn934giJVEt7D1UQOlJuAA1lTOdJ0v6ipSc6+4KX9dWaeFiE1JM ZsRLcqnD6ThN/8/0AQ7Y0oH6be4U2NnAYCEw/ItNPdjO7sg7KZLH14fUxs6bt8qSRHy7 guhA== X-Gm-Message-State: APjAAAXVSrCYlVuV4CS2WVuE5XGjZ4G6HZo8Tp5u6Zvks5jcH84P2MFX eNyVbkLYWJKfyI6D2CmEf7cd92jU X-Google-Smtp-Source: APXvYqwOLSz5m8AdfEvWedULXZ74zehzSsz8Ybgar81keTYnWq/NOhJi+RuKjDi2bD1R25//mmNs1A== X-Received: by 2002:a05:6000:1052:: with SMTP id c18mr4681767wrx.268.1575372904413; Tue, 03 Dec 2019 03:35:04 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id n10sm3223737wrt.14.2019.12.03.03.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 03:35:03 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Dec 2019 12:34:53 +0100 Message-Id: <20191203113453.9701-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/ttaenc: Don't unnecessarily copy packets 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" When the tta muxer writes the actual packet data at the end of the muxing process, it repeatedly copies the packets contained in the linked list of stored packets to an AVPacket located on the stack via ff_packet_list_get(), writes the data and unrefs the packet. But when one is willing to traverse and free the linked list oneself, one can get rid of the copying. This also means that the tta muxer does not rely on sizeof(AVPacket) any more. Signed-off-by: Andreas Rheinhardt --- libavformat/ttaenc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index 73c29ae936..84e3937141 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -122,13 +122,16 @@ static int tta_write_packet(AVFormatContext *s, AVPacket *pkt) static void tta_queue_flush(AVFormatContext *s) { TTAMuxContext *tta = s->priv_data; - AVPacket pkt; - - while (tta->queue) { - ff_packet_list_get(&tta->queue, &tta->queue_end, &pkt); - avio_write(s->pb, pkt.data, pkt.size); - av_packet_unref(&pkt); + AVPacketList *entry = tta->queue; + + while (entry) { + AVPacketList *next = entry->next; + avio_write(s->pb, entry->pkt.data, entry->pkt.size); + av_packet_unref(&entry->pkt); + av_free(entry); + entry = next; } + tta->queue = tta->queue_end = NULL; } static int tta_write_trailer(AVFormatContext *s)