From patchwork Wed Jan 1 00:58:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17097 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a05:6214:1865:0:0:0:0 with SMTP id eh5csp220482qvb; Tue, 31 Dec 2019 17:02:04 -0800 (PST) X-Google-Smtp-Source: APXvYqzjZc9/u59cMJ3e/eqQrh//P+4FOkhFCP152UOEj0/pjunlQ4i6l0MWUD9fPEy5ydZ5VXZV X-Received: by 2002:aa7:da42:: with SMTP id w2mr79229310eds.3.1577840524450; Tue, 31 Dec 2019 17:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577840524; cv=none; d=google.com; s=arc-20160816; b=xCzNBNvQjigDFXUA/u959J2HgTXI80nsVtgJM+r/P4WVVr81FuAVT5qCwrD0u+V4Ny BVgZnyBXz8OlrIJUq+PGYiUOI0xM6b+bBDWOTvLOisBowmvQRsC7/LbTXkLE5Teaxqb0 1C+38dnkfN2vinztJu6IGql9yk7c3VdxdN2GHrOmIfadoOJSY/j8XOMDJsQRbi/LUE6x baN5tNpfN0/tjxF53uo522yogFmTQv5qXVgcY0iR34fAESZv08LJOJM6WsWquNMwUbSw 8ibokrfO/uw7d9mif/xxWPouogbn3fu5/9gQolpZs1/iReBzzB6lix8BSY8jq0XzhVby p3uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=0w4p1KfyfaNyFSMrzAT6LCdISnrG76wSuC337FeACVE=; b=y8YfYF3BAvUYbH7aG/x9cnW/ttJwuMTP4Jco0la/mDSLZznS0TOaaclEkyyBtjCWBM o4Li0X2oLcD2DX0MsBuJYPfdyOCYsAL+mjdQDwM1miTGIEY6ex00b/Af6y8jM7+/BEjc 1xS6tnhHrklEVYiYCs2Ri16sNuUZK8qiVJOW8hQumWKKKyfMrDbUNJXToo1Kh/SmMDxn A0e3JacIC5fbW0QZtTRcYnRH/Tz/fEzkLjApJSVzuQkaxtC/h02PfkvNKan0zINOBKfM 9WEsYy87VmbPEZBB8gRAfr5YjYQZNoL5bZrnXVkbOsbe8LMF97GfqWiLbVRV0xM/QImf ZtEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=kZ3ndYnD; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k5si31539631edx.80.2019.12.31.17.02.04; Tue, 31 Dec 2019 17:02:04 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=kZ3ndYnD; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 821F768AE68; Wed, 1 Jan 2020 02:59:28 +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 F17D568ADE4 for ; Wed, 1 Jan 2020 02:59:17 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id z7so36141936wrl.13 for ; Tue, 31 Dec 2019 16:59:17 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=31O6WEM3hG8R0JBd1jMwCA258ObawktcOWWYeH5F6bo=; b=kZ3ndYnD7aznPr/mQn68S0z104MLdxzY9x6rPLBfUXJKqkqYCSBpf4iboxZjxnMJku tI5oHl0+UwBV7wfChLqEUBidwzQqs36waK5I9SqwRfwV4T7FRvOZRxNNUIfx8dgK1mb1 +lfAbuDg8z+hDFO7iM1VAuDTIsMJQiZyeLq3iooXFgBRAocTnR21BF72UxYoMQuttmA6 3JWGPtiPjBt5ELQGVLBrXystKFtng1cow1YEBnSG7b395Y8SH28g0oQBJfABdM6tv5t/ 7MGw1U+K+rcQqNJYNGgsoIXkwMcYFGF1ov4BjTdaOgXotmP8ZF1y7JI2UGpdrLwYGxlj oq5A== 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=31O6WEM3hG8R0JBd1jMwCA258ObawktcOWWYeH5F6bo=; b=J1/U6dC1EFNJxdvtKRdUhOe+X3ulGcliar/WfOxmkGRPxCMucUEG3tNNVNHtk4bEOL 19vwnoJzLqJR6ii+npPni/ojI3S1A+Prw1ffW9PtGVCtKBz/rGgA1S0UiirySTPvpCEx 64EggTUGvVpiz1Lb440Q8UVAvk0lojkJ5wT1oFVWkprZC1/Aff4TtjX2XHVCyLwGvmV2 Mjs4YBg0W+D0EFal+C0j7UWTidgNWVZ8ue3jpWXelpmTZXwX3D8AIRGuKas8yCa6WAsH BzhAK+6ZTFYJQ745jcam4Y+Aprl+45Rwsd/hNJ9pueXYWuo1F3hUE/OR2fS4ekhyXZcQ RBsA== X-Gm-Message-State: APjAAAU3y40T5ntTM+Mivm7N/7d42LwdCssl4annI77gyMOb2vMTc1KE NYZ1htxeGlj7Os6sRNIFrNys1rny X-Received: by 2002:adf:b591:: with SMTP id c17mr72342240wre.108.1577840357329; Tue, 31 Dec 2019 16:59:17 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id w17sm52431655wrt.89.2019.12.31.16.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2019 16:59:16 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jan 2020 01:58:37 +0100 Message-Id: <20200101005837.11356-21-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200101005837.11356-1-andreas.rheinhardt@gmail.com> References: <20200101005837.11356-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/20] avformat/matroskaenc: Avoid seek when writing Cues at the front 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" X-TUID: eGDNqBWVWm41 Content-Length: 4325 When the Cues are written in front of the Cluster, the muxer would seek to the beginning (to where the Cues ought to be written) and write the Cues; afterwards it would seek back to the end of the file only to seek to the beginning once again to update several elements there. This commit removes the seek to the end. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 24317d3819..95d97a10c5 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2449,7 +2449,6 @@ static int mkv_write_trailer(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb = s->pb; - int64_t currentpos; int ret; // check if we have an audio packet cached @@ -2472,11 +2471,14 @@ static int mkv_write_trailer(AVFormatContext *s) if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { - int64_t ret64; + int64_t endpos, ret64; + + endpos = avio_tell(pb); if (mkv->cues.num_entries) { AVIOContext *cues; uint64_t size; + int64_t cuespos = endpos; int length_size = 0; ret = start_ebml_master_crc32(&cues, mkv); @@ -2499,7 +2501,7 @@ static int mkv_write_trailer(AVFormatContext *s) mkv->reserve_cues_space, size); mkv->reserve_cues_space = 0; } else { - currentpos = avio_tell(pb); + cuespos = mkv->cues_pos; if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) { ffio_free_dyn_buf(&cues); return ret64; @@ -2515,17 +2517,15 @@ static int mkv_write_trailer(AVFormatContext *s) } } } - mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, avio_tell(pb)); + mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos); end_ebml_master_crc32(pb, &cues, mkv, MATROSKA_ID_CUES, length_size); if (mkv->reserve_cues_space) { if (size < mkv->reserve_cues_space) put_ebml_void(pb, mkv->reserve_cues_space - size); - avio_seek(pb, currentpos, SEEK_SET); - } + } else + endpos = avio_tell(pb); } - currentpos = avio_tell(pb); - ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos); if (ret < 0) return ret; @@ -2571,7 +2571,7 @@ static int mkv_write_trailer(AVFormatContext *s) end_ebml_master_crc32(pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 0); } - avio_seek(pb, currentpos, SEEK_SET); + avio_seek(pb, endpos, SEEK_SET); } if (!mkv->is_live) {