From patchwork Wed Apr 1 10:46:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18568 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 4513D44A30B for ; Wed, 1 Apr 2020 13:47:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 30B9A68B19A; Wed, 1 Apr 2020 13:47:37 +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 B320368AFCC for ; Wed, 1 Apr 2020 13:47:29 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id h9so29939143wrc.8 for ; Wed, 01 Apr 2020 03:47:29 -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=KRKxIqf9wehAMZHL9yBm349pd9PUVRy2cqWb8z0sANQ=; b=FE3D9/R0hjES83VzgA6UUIgi6FWfpumgxvgm89GxOmIvsWKmBCZS4GeeMFte6B0WwI LLTw1mWSqL04m0bo2uEomlDz5cy6zAVmKGIlPZVj0DfAOQ/sewyOUmzku7TGDJ9OgBL6 ZbBv6y+adMqcTQoIO71rn0y28x2VgZwfE1uCdyOOp+8OXLNvFrH6JNL4d3739QCNRA0P Vd2P/6DJT/aWXuXk5p3xW9L14h+yy1tfviUGLyv/o1wt70LelrgOPlC4CoOUUZr0Znpd BmEGSMZn5gjO0f/XI8JB0NalxcKIIA5z4RmVoVPPwQUcqr/3tf/kX79WvU5MB0Hop5NL /iUQ== 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=KRKxIqf9wehAMZHL9yBm349pd9PUVRy2cqWb8z0sANQ=; b=W550Y7TMfc6WmWD1SfgyPiTC31XER6Cy/N6ChYtOBjffkqKRhF8QSDACmpFogN7pWj VtKBFlR/okwdoz5hrENG8rSsXJanKQDViqa7xAsNj02VD4SwgT6NgOPXjWTmjnaIx2Zy xionKMgERIupwGlrHPB9Dbyqpc0uJI/9DbvYpdbnCGnQQZw/2yDRznKq0rW3ky7kYpup OpiH3M3VA12f2PzcCdo2q7ttTDiR19U/RDa1zSuwGdO/yFQr2V5ZYwaO4f4zgBcRKC6k fyuc275ML3pbe5dz70iWWNfmq/sIN/pCl6eXFm9PzqjQVho5UoUJ58tk59OcD7e+5wea IgzQ== X-Gm-Message-State: ANhLgQ2u9sQatO0+OB627/lg26YID6DUo9BNDn5LCjBFpqLhSaJ3fzn4 WEYawyjKu/Uc+DlYrr/Xon+v7nTS X-Google-Smtp-Source: ADFU+vuztVHp5WDlQqhzAMmnhwym95de2xyW8JG9ur2qwEGCCurYpfK0aulF9uCW2lGXf59GgayBkw== X-Received: by 2002:a05:6000:1205:: with SMTP id e5mr26972000wrx.73.1585738048659; Wed, 01 Apr 2020 03:47:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w3sm2427800wrn.31.2020.04.01.03.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 03:47:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Apr 2020 12:46:34 +0200 Message-Id: <20200401104634.25461-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401104634.25461-1-andreas.rheinhardt@gmail.com> References: <20200401104634.25461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/3] 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" 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 2ca4527dfe..955803bc57 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2456,7 +2456,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 @@ -2479,11 +2478,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); @@ -2510,7 +2512,7 @@ static int mkv_write_trailer(AVFormatContext *s) ffio_free_dyn_buf(&cues); goto after_cues; } 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; @@ -2526,18 +2528,16 @@ 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); } after_cues: - currentpos = avio_tell(pb); - ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos); if (ret < 0) return ret; @@ -2583,7 +2583,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) {