From patchwork Mon Jan 13 14:51: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: 17324 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 7FD534491EF for ; Mon, 13 Jan 2020 17:16:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 66A3E68AF75; Mon, 13 Jan 2020 17:16:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6640668AF4B for ; Mon, 13 Jan 2020 17:16:27 +0200 (EET) Received: by mail-lj1-f193.google.com with SMTP id a13so10476803ljm.10 for ; Mon, 13 Jan 2020 07:16:27 -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=oj/Sj67nBSp4ftBpiCzS61w2o47VL+WUcSnzEZcJffY=; b=IXRNCyhidSyPFa+D9LY2cXMTHb/qi8Dlodc4l037iK0k/m4KZ6PwFiDgps7qtSsve6 HRDAJ9/aM6G5KJg0jKMtb6Asnb8rEKb8xdIErPAqvxD1pd9aciSecobooRi67Sx7Su1d spd4y7Qi7RnuyL47x20f+XuyTLxlv3VEh8/6S0/ivj2nw6yXCCt97glxXtGBjQtpLvyh qK8cMLpwHIs3FyVODYSgXBGHM8YKO5IMz540bthuNL+7gmunBKTykMX8UUgFIuI5RsFK T/pUJrts2OMtaZlLDkk+N9JCDAXIFqqeLva3BrS6HKRXGOWTxCgmc1KljRWe2FqXN+hO fNMg== 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=oj/Sj67nBSp4ftBpiCzS61w2o47VL+WUcSnzEZcJffY=; b=I1P2gXhqht8rMddCx8M/8r8fIVwryd4SHu2sEneCE6vdUDO3knzu30RMSxm7tBAkT1 JG3wWGGr2CO9kQg3voo6KcfkgWM18Ij9mhUUi1GJE2/HwkBrLAuKfpESS+A4UdFezqNu dUcbR89MgXdhdYneDqIwUc5Nji0zjYXk+jZU/OHW9Lc9aofGc3Sw7ETlB7Tb9Y8rP85/ ZeeXOH0uQNrM7uuzJXZftUWxt0xUA70nZdkwgNCgRxZdzsKtmp/0RW6Uu4v2+WEJhUSB eyU28hCKAOf4mgfgew5UZs6V+9bF5mAhRBlm+ST+7JrG5HaOmle/Bg+Qak6+VI+8AE5A mJrA== X-Gm-Message-State: APjAAAXeW1d5TUEU9MuHquIKHY9KTlOXz0dUhaOMJnn6EEI+DRVNZqA/ PQk+QiHAg6SJ0dXaRkTDxOZpEn23 X-Google-Smtp-Source: APXvYqy4lmwHBWbojv/gRcWr94tdc98sd4aGjeE+09vkpUr9Yr6ZDhKG3CdbT5yxVFOr96io/xm0yg== X-Received: by 2002:a5d:4d8d:: with SMTP id b13mr19967615wru.6.1578927101166; Mon, 13 Jan 2020 06:51:41 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id u14sm14955198wrm.51.2020.01.13.06.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 06:51:40 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Jan 2020 15:51:34 +0100 Message-Id: <20200113145134.24086-1-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 21/21] avformat/matroskaenc: Simplify writing Void elements 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" Reserving space in Matroska works by writing a Void element. And until now this worked as follows: The current position was recorded and the EBML ID as well as the length field written; then the new position was recorded to know how much more to write. Afterwards the actual writing has been performed via ffio_fill(). But it is unnecessary to explicitly use the positions (obtained via avio_tell()) to find out how much still needs to be written, because the length of the ID and the length field are known. So rewrite the function to no longer use them. Also, given that ffio_fill() uses an int parameter and given that no current caller (and no sane future caller) will want to reserve several GB of space, make the size parameter of put_ebml_void() itself an int. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 258638e459..e74d59d271 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -288,21 +288,22 @@ static void put_ebml_string(AVIOContext *pb, uint32_t elementid, * * @param size The number of bytes to reserve, which must be at least 2. */ -static void put_ebml_void(AVIOContext *pb, uint64_t size) +static void put_ebml_void(AVIOContext *pb, int size) { - int64_t currentpos = avio_tell(pb); - av_assert0(size >= 2); put_ebml_id(pb, EBML_ID_VOID); // we need to subtract the length needed to store the size from the // size we need to reserve so 2 cases, we use 8 bytes to store the // size if possible, 1 byte otherwise - if (size < 10) - put_ebml_num(pb, size - 2, 0); - else - put_ebml_num(pb, size - 9, 8); - ffio_fill(pb, 0, currentpos + size - avio_tell(pb)); + if (size < 10) { + size -= 2; + put_ebml_num(pb, size, 0); + } else { + size -= 9; + put_ebml_num(pb, size, 8); + } + ffio_fill(pb, 0, size); } static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,