From patchwork Fri Mar 19 05:58:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26466 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 C1179449D11 for ; Fri, 19 Mar 2021 07:59:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB47768A67E; Fri, 19 Mar 2021 07:59:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D006A68A60C for ; Fri, 19 Mar 2021 07:59:39 +0200 (EET) Received: by mail-ej1-f52.google.com with SMTP id ce10so7739117ejb.6 for ; Thu, 18 Mar 2021 22:59: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:reply-to :mime-version:content-transfer-encoding; bh=Ano5hR6SisKC1O1SNKIpITSp3Ott5Gcg1z5eNwo15IU=; b=gn/AeaQg3YNt0N1EL4IflnSNJtvejkk3RJfwKhNf9HS2zPm2IotfZf3Hh5tUZyoddn 0xrPcMLAh9GXVw5201gaBPnGN2fJLQBJbo7mQ2tGPanl4flauLFu180o0T53o3sXqdS8 RzFItgWSj/zqAj1sfvWQhVyZOOUfvjsCC8iSDqE6hNZ/NyExPd5tEEjHAdye4OdCFpqB Avilw6tAS/fGxjUMW42u1ojrqSvIa2f/ptiMBDTlfw4v5R83yO7ycjvtxsuW+bZEI3Yf LctvUMHmjY3oBKoEEF/tYsrRuaqZsf6xKV89dUgX6xWcPdXqOivJYmILrctLbDPkMcW6 J8ug== 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:reply-to:mime-version:content-transfer-encoding; bh=Ano5hR6SisKC1O1SNKIpITSp3Ott5Gcg1z5eNwo15IU=; b=JpReMHPZeOc3XiBfB89KLb0m1wCVNzdFisHdg6MRcE+cB4tbkwa4iHKRa5XfsucnKO uINEC1mCPEsyzD1gzKB3X0uKXhty7pOeM0Dt8KKqxbCElVAT/eJ8uWZQ5SarZHD0dL60 1WDtPFfuPFMDXxEOsDphOjocxqzFZsXxK63YhBMrI5Iv5xEwP9uX6fbs0tQo34Bu78hg lldwDzxW9jsQELTLs1IFySfuPqTQMfIN03ZVaplR5EJ7wVi37Kdztfy9pqIxK1FADH2Q z6jItoS9fVlXLqscSi5N7qm27gGO0vg5GsWUou74NuOVgEEGedQCxqe4KaqNPvFrXUXN gKyw== X-Gm-Message-State: AOAM533+rxT8+1CeDe74FkZkavQC1BulRptQxDt8lQ+K5o9Qkbd2HvcI bSER8olgy5EO4ItuzcIbQz57M4CJGJ/pJQ== X-Google-Smtp-Source: ABdhPJzu2iTH/t4Pm0lS2hqGEv54KGS3tip4WmvbkeSR5roNUiJVAFmq4RArNxHd8xIU3VL0DwHNfg== X-Received: by 2002:a17:906:70d:: with SMTP id y13mr2426826ejb.170.1616133579050; Thu, 18 Mar 2021 22:59:39 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id x17sm3109344ejd.68.2021.03.18.22.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 22:59:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Mar 2021 06:58:50 +0100 Message-Id: <20210319055904.2264501-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> References: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] avformat/matroskadec: Reuse AVFormatInternal.parse_pkt 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" Before 8d78e90a6ba96646f7f25aff6ca3e12e71cec164 the Matroska demuxer used stack packets to hold temporary packets; now it uses a temporary packet allocated by the Matroska demuxer. Yet because it used stack packets the code has always properly reset the packet on error, while on success these temporary packets were put into a packet list via avpriv_packet_list_put(), which already resets the source packet. This means that this code is compatible with just reusing AVFormatInternal.parse_pkt (which is unused while one is in the demuxer's read_packet() function). Compared to before 8d78e90a6 this no longer wastes one initialization per AVPacket read (the resetting of the stack packet performed by av_packet_move_ref() in avpriv_packet_list_put() was for naught). Signed-off-by: Andreas Rheinhardt --- libavformat/internal.h | 3 +++ libavformat/matroskadec.c | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index a810d51bba..c730332031 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -98,6 +98,9 @@ struct AVFormatInternal { * for short periods that are guaranteed not to overlap * with calls to av_read_frame() (or ff_read_packet()) * or with each other. + * It may be used by demuxers as a replacement for + * stack packets (unless they call one of the aforementioned + * functions with their own AVFormatContext). * Every user has to ensure that this packet is blank * after using it. */ diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 9acfdf5b32..1dc188c946 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -381,6 +381,8 @@ typedef struct MatroskaDemuxContext { /* byte position of the segment inside the stream */ int64_t segment_start; + /* This packet coincides with AVFormatInternal.parse_pkt + * and is not owned by us. */ AVPacket *pkt; /* the packet queue */ @@ -2945,9 +2947,7 @@ static int matroska_read_header(AVFormatContext *s) } ebml_free(ebml_syntax, &ebml); - matroska->pkt = av_packet_alloc(); - if (!matroska->pkt) - return AVERROR(ENOMEM); + matroska->pkt = s->internal->parse_pkt; /* The next thing is a segment. */ pos = avio_tell(matroska->ctx->pb); @@ -3528,7 +3528,6 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, if (!pkt_size && !additional_size) goto no_output; - av_packet_unref(pkt); if (!buf) pkt->buf = av_buffer_create(pkt_data, pkt_size + AV_INPUT_BUFFER_PADDING_SIZE, NULL, NULL, 0); @@ -3902,7 +3901,6 @@ static int matroska_read_close(AVFormatContext *s) int n; matroska_clear_queue(matroska); - av_packet_free(&matroska->pkt); for (n = 0; n < matroska->tracks.nb_elem; n++) if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)