From patchwork Thu Apr 16 23:54:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19014 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 E7F8C448684 for ; Fri, 17 Apr 2020 02:54:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CA90568BCF5; Fri, 17 Apr 2020 02:54:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2338D680055 for ; Fri, 17 Apr 2020 02:54:48 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id k1so893319wrx.4 for ; Thu, 16 Apr 2020 16:54:48 -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=5t9KgwuBnUokqdNonpa5jP43onn6io5KdGpOwQpblWU=; b=GuCKfA+2LotSaZbEYIw19mpOeozmAt789/1Bz7GJpFOVYshigKhWY5ymaWp+lBdZsj NVRJRBfzog4BNQdOAifLVaHQlxVclatuBG4mkowMN/aHmB+Azde1DnJeOuXOch9xhMhQ d1J6rHVzFgDuHssAbvuMQnxn2lP0tvPvZea9w3fE3U8+LXS0aCE3lwrNo7EHCN9VOjm4 Narn0vZ3O38QXYuk3uPVOyt//fnfnm1MnsfBuJHa/cUxUYQY4ZLi8Bg0g4Os2QB/eoHU 8IoFC3oDcAuh1mWGATyQWFvR8gWkq4yrkuHPVYMDY/QmNetuWaszscwvyKISJBjieL6B 3LGA== 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=5t9KgwuBnUokqdNonpa5jP43onn6io5KdGpOwQpblWU=; b=gqFd7/6t1jJ9w4f7Ve+NgoCoLaNo0kuxaGYJBGpP9Ptzg8gSPM0vTkjnib00Aa4OJU AjQhVmuYtmpNv0F/GpCPPPuRpz9mcLLEH6MMuze0U+SY5UINa6O6kh81ppTFjcH+u6OG fSCZpg5fydmK6Wh0teY403QrU+BlJGqd1JxntNnsCCmKxxjVFxzQHsf92sdrefrS5EgW a4nySFowbCrunuM422qVtT+qw22JtAkQZIC6bDnDixXp5xKzD8BxsW3JTC5T7VaXKTdW kHpEglcMxfHQy7JgjYXG8l3KY4D1vbmefoLmzBH7kI46gC6jNb//NzEmaxyBnKuOuEjV /NCg== X-Gm-Message-State: AGi0PuasujZbyXfJPoZSog+ROK3nHwhvbccpGN80lUswCF0NFuSz/1zj sAb2d4JvbxUw1DTiYZqvwKb1+YAc X-Google-Smtp-Source: APiQypJvwec0tOkAm2yVpbHzmqyefkv2IZKP9/y/XBPkfX4scSL/9IimpEHvH4Hx/iloPDwV8l2LEg== X-Received: by 2002:adf:db0a:: with SMTP id s10mr761779wri.361.1587081286843; Thu, 16 Apr 2020 16:54:46 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id i17sm5603488wml.23.2020.04.16.16.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 16:54:46 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Apr 2020 01:54:33 +0200 Message-Id: <20200416235435.20409-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415210614.29152-1-andreas.rheinhardt@gmail.com> References: <20200415210614.29152-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/matroskaenc: Rename functions to better reflect what they do 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" EBML uses variable length integers both for the EBML IDs as well as for the EBML lengths; Matroska also uses them for the TrackNumber in (Simple)Blocks and for the lengths of laces when EBML lacing is used. When encoding EBML lengths, certain encodings have a special meaning, namely that the element has an unknown length. This is not so when encoding general EBML variable length integers. Yet the functions called ebml_num_size() and put_ebml_num() had this special meaning hardcoded, i.e. they are there to write EBML lengths and not general EBML numbers. So rename them. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 53 ++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 407920172d..7cea813dc0 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -190,30 +190,31 @@ static void put_ebml_size_unknown(AVIOContext *pb, int bytes) } /** - * Calculate how many bytes are needed to represent a given number in EBML. + * Calculate how many bytes are needed to represent the length field + * of an EBML element whose payload has a given length. */ -static int ebml_num_size(uint64_t num) +static int ebml_length_size(uint64_t length) { int bytes = 0; - num++; + length++; do { bytes++; - } while (num >>= 7); + } while (length >>= 7); return bytes; } /** - * Write a number in EBML variable length format. + * Write a length as EBML variable length integer. * * @param bytes The number of bytes that need to be used to write the number. * If zero, the minimal number of bytes will be used. */ -static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes) +static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes) { - int i, needed_bytes = ebml_num_size(num); + int i, needed_bytes = ebml_length_size(length); // sizes larger than this are currently undefined in EBML - av_assert0(num < (1ULL << 56) - 1); + av_assert0(length < (1ULL << 56) - 1); if (bytes == 0) bytes = needed_bytes; @@ -221,9 +222,9 @@ static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes) // the bytes that we ought to use. av_assert0(bytes >= needed_bytes); - num |= 1ULL << bytes * 7; + length |= 1ULL << bytes * 7; for (i = bytes - 1; i >= 0; i--) - avio_w8(pb, (uint8_t)(num >> i * 8)); + avio_w8(pb, (uint8_t)(length >> i * 8)); } /** @@ -232,7 +233,7 @@ static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes) static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid) { put_ebml_id(pb, elementid); - put_ebml_num(pb, 8, 0); + put_ebml_length(pb, 8, 0); avio_wb64(pb, uid); } @@ -244,7 +245,7 @@ static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val) bytes++; put_ebml_id(pb, elementid); - put_ebml_num(pb, bytes, 0); + put_ebml_length(pb, bytes, 0); for (i = bytes - 1; i >= 0; i--) avio_w8(pb, (uint8_t)(val >> i * 8)); } @@ -257,7 +258,7 @@ static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val) while (tmp>>=8) bytes++; put_ebml_id(pb, elementid); - put_ebml_num(pb, bytes, 0); + put_ebml_length(pb, bytes, 0); for (i = bytes - 1; i >= 0; i--) avio_w8(pb, (uint8_t)(val >> i * 8)); } @@ -265,7 +266,7 @@ static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val) static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val) { put_ebml_id(pb, elementid); - put_ebml_num(pb, 8, 0); + put_ebml_length(pb, 8, 0); avio_wb64(pb, av_double2int(val)); } @@ -273,7 +274,7 @@ static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size) { put_ebml_id(pb, elementid); - put_ebml_num(pb, size, 0); + put_ebml_length(pb, size, 0); avio_write(pb, buf, size); } @@ -299,10 +300,10 @@ static void put_ebml_void(AVIOContext *pb, int size) // size if possible, 1 byte otherwise if (size < 10) { size -= 2; - put_ebml_num(pb, size, 0); + put_ebml_length(pb, size, 0); } else { size -= 9; - put_ebml_num(pb, size, 8); + put_ebml_length(pb, size, 8); } ffio_fill(pb, 0, size); } @@ -310,7 +311,7 @@ static void put_ebml_void(AVIOContext *pb, int size) static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize) { - int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; + int bytes = expectedsize ? ebml_length_size(expectedsize) : 8; put_ebml_id(pb, elementid); put_ebml_size_unknown(pb, bytes); @@ -323,7 +324,7 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) if (avio_seek(pb, master.pos - master.sizebytes, SEEK_SET) < 0) return; - put_ebml_num(pb, pos - master.pos, master.sizebytes); + put_ebml_length(pb, pos - master.pos, master.sizebytes); avio_seek(pb, pos, SEEK_SET); } @@ -349,7 +350,7 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, put_ebml_id(pb, id); size = avio_get_dyn_buf(*dyn_cp, &buf); - put_ebml_num(pb, size, length_size); + put_ebml_length(pb, size, length_size); if (mkv->write_crc) { skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); @@ -376,7 +377,7 @@ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext *dyn_ *pos = avio_tell(pb); put_ebml_id(pb, id); - put_ebml_num(pb, size, 0); + put_ebml_length(pb, size, 0); avio_write(pb, buf, size); } @@ -461,7 +462,7 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, MAX_SEEKENTRY_SIZE); put_ebml_id(dyn_cp, MATROSKA_ID_SEEKID); - put_ebml_num(dyn_cp, ebml_id_size(entry->elementid), 0); + put_ebml_length(dyn_cp, ebml_id_size(entry->elementid), 0); put_ebml_id(dyn_cp, entry->elementid); put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); @@ -1891,7 +1892,7 @@ static int mkv_write_header(AVFormatContext *s) static int mkv_blockgroup_size(int pkt_size) { int size = pkt_size + 4; - size += ebml_num_size(size); + size += ebml_length_size(size); size += 2; // EBML ID for block and block duration size += 9; // max size of block duration incl. length field return size; @@ -2030,7 +2031,7 @@ static int mkv_write_block(AVFormatContext *s, AVIOContext *pb, } put_ebml_id(pb, blockid); - put_ebml_num(pb, size + 4, 0); + put_ebml_length(pb, size + 4, 0); // this assumes stream_index is less than 126 avio_w8(pb, 0x80 | track_number); avio_wb16(pb, ts - mkv->cluster_pts); @@ -2098,7 +2099,7 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *p blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(size)); put_ebml_id(pb, MATROSKA_ID_BLOCK); - put_ebml_num(pb, size + 4, 0); + put_ebml_length(pb, size + 4, 0); avio_w8(pb, 0x80 | track->track_num); // this assumes track_num is less than 126 avio_wb16(pb, ts - mkv->cluster_pts); avio_w8(pb, flags); @@ -2443,7 +2444,7 @@ static int mkv_write_trailer(AVFormatContext *s) if (mkv->reserve_cues_space) { size = avio_tell(cues); - length_size = ebml_num_size(size); + length_size = ebml_length_size(size); size += 4 + length_size; if (mkv->reserve_cues_space < size) { av_log(s, AV_LOG_WARNING,