From patchwork Tue Jun 21 03:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 36364 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1991909pzb; Mon, 20 Jun 2022 20:22:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u0Nfw8A+sg+IS7l4Hvm3JYXopgfFQOI22o3ngrGZEo1vWsh3s/k7JA2iW08gC0ZSuehOic X-Received: by 2002:a17:907:2992:b0:70c:4ddf:5d88 with SMTP id eu18-20020a170907299200b0070c4ddf5d88mr23366013ejc.20.1655781747793; Mon, 20 Jun 2022 20:22:27 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g19-20020a170906349300b0071208964108si14097814ejb.635.2022.06.20.20.22.26; Mon, 20 Jun 2022 20:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=qcvOe19j; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F17468B609; Tue, 21 Jun 2022 06:22:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075034.outbound.protection.outlook.com [40.92.75.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 61B2268B5C8 for ; Tue, 21 Jun 2022 06:22:16 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M7exU15OTrZDZBp0vjbVh6hCF2duGxito7wMtEb4XaQX/+iDEhnDHYIfJ4dzFReZrtCWAe9/uDyYmpMIm7LuP6QaVGDxLJfMUl3p8YWuabn00CNotapdI/V1tJc7e5Ufxs0UgKjJPfMRJrZvZLktMn982/qR718D3Vz2wLZ3C77fn+zOHL16aAj6QK5Wlef9VJfq5mSYYl8iSMSK2kLp3MmYRyav408lvhwaUTztBp96TAQ3wP2DiVIYMbp/tNrgRpXnHAzw7ZcooNV9CMCf1QJD/43a4fwlfUgS0BmNIJgQCGJuJE6P5+VNC0W/+n1ylu57tof9fBo889WZDKmx1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mdgaoLgcb/8SDe9HOn/BaCvkLO5Lh+LZvZefiANaNwM=; b=mfh5G8LTjJ6clIhMsy5A8lBtxcZQmX7edcXhEYWCKPwpYom906N/Zbc1TkP6wBS8S6k/8olmlmepdbeiB6c4YBeaA68vps0/I8+PP7BHwzc/U9+q9ootELZalbMu2qaL+NIKS6oh+pKb6PcZoO+56XlxPAIx3oYezDmOq3cDQgN1O9MzO2Q51QfxfENYhsovCUC7jdPM7Vz6wPdWKB4EpyHLHF8ruKTogKPZJE5qoR7eeAULgJ2Pk9yMZqpUiwXznrWkavhLpYKWMDqEwYRx9Uc660HzPQUauDVWcNWVezs3Cyc3pjUu/RKTn1y7NO+5Iu6IXe59gjPdVQNrPHlWtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mdgaoLgcb/8SDe9HOn/BaCvkLO5Lh+LZvZefiANaNwM=; b=qcvOe19jJcSzJd7KlpjgINCPFAsKp6n0SUJJ/SJ9mwWNLz/ETS7p8pel2Zad9tuNjDVRFUBlodRZnRYu59Vdjv0/EGQfs7Gj7kCZTM4JMINlq5nLZ5pG7rj8CTrCgYDQcdCMLSxMjTfJ4M/+fuU/0b+n5giSwelEqicRAVouqv369qcedRvq+GmJf2VNV0GhVyMR8tU1vX9vnMdKCUByYkh97RCHlkwy+Hpsb4ITiX9IVhr5CLnHS00NKGjjBBs49yi35wBk54UAFOnJVRUB/0vuKrY0sWMAToVkjYJhecOTOxK889I0oBL5h5cn4vFCOG3O/YORcvoSy/aPIFc++A== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AM8PR01MB7962.eurprd01.prod.exchangelabs.com (2603:10a6:20b:36d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.13; Tue, 21 Jun 2022 03:22:14 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 03:22:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Jun 2022 05:22:07 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Y4qD+wtcR2Qlw2XFXfPSn5HgdN4tIUC1] X-ClientProxiedBy: AS9PR01CA0024.eurprd01.prod.exchangelabs.com (2603:10a6:20b:540::29) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220621032207.3325324-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff9bb2c8-8b07-4676-fe49-08da53353cb3 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiStnrXejT7dVEa0U1z4ilPmI/nKZGxPu8ovZoHS8YmFqA4kAjGGAXLBSy3z9NHlzuLx1TBebmVi5r1JaJYZ5mhi4/+W90+xM8WmwJhOVH6adzr1O7icDg8snA7yeKsyNsdd/gMYH1+U10yA4wqD5bM94XDFlew+tN8QwdQKgPUXIsaRJZFHg2SPFaAcHNUd0jLONP7x7DP5YlOOIdS4d1RMcpkPHV3XLmFg5qDiIu/An8FOPzHCEO+dZL6fsZg3NgDgDYpdmwFdS96tn+g1JgsqR8Ve1XdOtmXyYPlynFnMLU5Xb5pw8LIdSLMx3lpIHzktqHjEbJMr8uLkrDuRJnC8h/BjJ4R1mNqoX2zIWkCnE1QuNvsTPV5zJts2NRPMXXyDYelI9GwelxScee9DHnYhneMcWMuCFhn9bLrZb7Nus5L6yJewMed/N3SoGEVMVdGMJbwjS5D14FyHgB8euBlMIQ/6vSkyyVwrNQ1ati5G3YF3WwR0CYwyr0bdqgIuZNXpD3Vr6S54Xs4/Rb4CcGjAK/jo7j4QqgU2zK5KsuwkdL85jV3nAQCaX5N9UxOAq/mRbAfBGQIIDuDVsZZ7YCXM8TBA0lbjr2jkS00wzmmYV3nXiTZTCYfyv9T6NDQj8rV3qaYfM1kPV0Z0o99x2GjYNmDSDjgdwHtONXYwh10FDnM9kpmwhUrtyR20VSJtpcNKSkedckRoY42CSqq03rXt/kfbcyRrMFL/IVDCWQOgdQNIOe8dmIYbw57lzhKgMbg= X-MS-TrafficTypeDiagnostic: AM8PR01MB7962:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pnsecn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X-MS-Exchange-CrossTenant-Network-Message-Id: ff9bb2c8-8b07-4676-fe49-08da53353cb3 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 03:22:14.5803 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR01MB7962 Subject: [FFmpeg-devel] [PATCH 7/7] avformat/matroskaenc: Reuse dynamic buffer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: /t9hRDg2ZPeT Avoids some allocations. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index acb50017b6..bfc397dbe6 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -222,7 +222,8 @@ typedef struct MatroskaMuxContext { * to write the length field of EBML Masters. * Every user has to reset the buffer after using it and * different uses may not overlap. It is currently used in - * mkv_write_tag(). */ + * mkv_write_tag(), in mkv_assemble_cues() as well as in + * mkv_update_codecprivate() and mkv_write_track(). */ AVIOContext *tmp_bc; AVPacket *cur_audio_pkt; @@ -941,17 +942,10 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts, return 0; } -static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, +static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint, const mkv_cues *cues, mkv_track *tracks, int num_tracks, uint64_t offset) { - AVIOContext *cuepoint; - int ret; - - ret = avio_open_dyn_buf(&cuepoint); - if (ret < 0) - return ret; - for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries; entry < end;) { uint64_t pts = entry->pts; @@ -981,14 +975,13 @@ static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, end_ebml_master(cuepoint, track_positions); } while (++entry < end && entry->pts == pts); size = avio_get_dyn_buf(cuepoint, &buf); - if ((ret = cuepoint->error) < 0) - break; + if (cuepoint->error < 0) + return cuepoint->error; put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size); ffio_reset_dyn_buf(cuepoint); } - ffio_free_dyn_buf(&cuepoint); - return ret; + return 0; } static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, @@ -2964,7 +2957,7 @@ redo_cues: if (ret < 0) return ret; - ret = mkv_assemble_cues(s->streams, cues, &mkv->cues, + ret = mkv_assemble_cues(s->streams, cues, mkv->tmp_bc, &mkv->cues, mkv->tracks, s->nb_streams, offset); if (ret < 0) { ffio_free_dyn_buf(&cues);