From patchwork Sun Jan 26 05:10:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17551 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 E52C044338E for ; Sun, 26 Jan 2020 07:10:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0F8268AF18; Sun, 26 Jan 2020 07:10:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BDAAE68AD3C for ; Sun, 26 Jan 2020 07:10:40 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id c84so3574305wme.4 for ; Sat, 25 Jan 2020 21:10:40 -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=Y45Cgo9NiKgLApgj8N+kU5MblO8Z1JiAc1fU0p2Lgmc=; b=fD1Mb5MxZmNIzV6s3uW/QtPBqdbzRHSnW4IBHjJLfvWw2WyGIGr/U04xJdOAgARhVh UPILtshRqJQ6A/DS8Madb79iQ8LCYUlEpK9J5b/4gpYebqqo9CWfKgblDxDqCi2Vx+34 k0iyQH2PA2af7STEx7FOEvvkAFs60x8BP0agZCJavyUtnE97VLkpFYVtbfyhR7IViwij RtNmdAiL0oU4N2NlClIHwpocdpMjRYIgbMoFe1XtrV2ZdjgpnZstKUxgxRi4bPgDFxTv s3Vym4i72IZnJQLGrfCLzjWyDZH4Vvb12YuyVolyPF2Z95ceFSr20+SqjjzOEDhW3E+k k3Hg== 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=Y45Cgo9NiKgLApgj8N+kU5MblO8Z1JiAc1fU0p2Lgmc=; b=qse9jLxW3jPN69t6Ox2gLqBBAfn0d/ahCZZiSSrBgsrJ/c5sQX3Q9OHw+w0VLEOiO+ kB+nce1LPKjSw9zCav3YL7nL8vLMvo05GTKGbeqL/WwHR91PhPoqpWgvqIJDV98rqn/o 8hCtxkOKbp9bXCPyOjuXKwi5HuBi2E7G9Vm2UUouqf4cmkxDjP4F+PejuDH//G+FTFoV LaMbAMN1W5ech1gsxqNyqg9PW56GAAHuiNS/iRuZz3gLwSgQMJ0x5hgSuvKRXRsRj3Eg 5yg5RWWb/XbLHiLm7cCcYJP8hN2gRgGAccoaoXsbvW2wG9yerAXX0yV2gxWpidwjr2qn f9pg== X-Gm-Message-State: APjAAAWE9v9Bec8ArlHhRt0bAPNc5d94CnzxVf7SpHEwApQOIU4jJvMR eBgMFYhjGPQ7uq8+2SMgJw/zKrJO X-Google-Smtp-Source: APXvYqwtks651Gvs/nl8wubyMQ2r5TNr/zqriua8TUh6LM9kNXVjGvTpG5fOeGlejZROg/MGkgrY7A== X-Received: by 2002:a05:600c:2152:: with SMTP id v18mr5745375wml.11.1580015439968; Sat, 25 Jan 2020 21:10:39 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id y139sm13486305wmd.24.2020.01.25.21.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2020 21:10:39 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Jan 2020 06:10:28 +0100 Message-Id: <20200126051028.27455-2-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 30/30] avformat/matroskaenc: Improve BlockAdditions 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" 8ffcc826 added support for muxing BlockAdditions with BlockAddID equal to one. The restriction to BlockAddID == 1 probably resulted from a limitation to what was needed; yet over time this led to three occurences of "(side_data_size && additional_id == 1)". This commit changes this by setting side_data_size to 0 if additional_id != 1. It also stops hardcoding 1 for the value of BlockAddID to write; but it still upholds the requirement that it is 1. See below. Despite BlockAddID actually having a default value of 1, it is still written, because until very recently (namely dbc50f8a) our demuxer used a wrong default value of 0. Furthermore, use put_ebml_binary() to write the BlockAdditional element. (The Matroska specifications have evolved and now the BlockAddID 1 is reserved for the codec (as described in the codec's codec mapping), BlockMore elements with BlockAddID > 1 are now of a more codec-independent nature and require a BlockAdditionalMapping in the track's TrackEntry. Given that this muxer does not support writing said BlockAdditionalMapping yet (actually, none have been defined yet), we have to uphold the requirement that BlockAddID == 1.) Signed-off-by: Andreas Rheinhardt --- Btw: When writing BlockAdditions in Matroska mode, one also has to write the MaxBlockAdditionID in the corresponding TrackEntry. Yet we don't (and we don't have the information to do that reliably when writing the header). libavformat/matroskaenc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 8fc672a31f..de3fff2043 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2046,7 +2046,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, uint8_t *data = NULL, *side_data = NULL; int offset = 0, size = pkt->size, side_data_size = 0; int64_t ts = track->write_dts ? pkt->dts : pkt->pts; - uint64_t additional_id = 0; + uint64_t additional_id; int64_t discard_padding = 0; uint8_t track_number = (mkv->is_dash ? mkv->dash_track_number : (pkt->stream_index + 1)); ebml_master block_group, block_additions, block_more; @@ -2100,16 +2100,16 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, &side_data_size); if (side_data) { - if (side_data_size < 8) { + // Only the Codec-specific BlockMore (id == 1) is currently supported. + if (side_data_size < 8 || (additional_id = AV_RB64(side_data)) != 1) { side_data_size = 0; } else { - additional_id = AV_RB64(side_data); side_data += 8; side_data_size -= 8; } } - if ((side_data_size && additional_id == 1) || discard_padding) { + if (side_data_size || discard_padding) { block_group = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 0); blockid = MATROSKA_ID_BLOCK; } @@ -2133,17 +2133,18 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, put_ebml_sint(pb, MATROSKA_ID_DISCARDPADDING, discard_padding); } - if (side_data_size && additional_id == 1) { + if (side_data_size) { block_additions = start_ebml_master(pb, MATROSKA_ID_BLOCKADDITIONS, 0); block_more = start_ebml_master(pb, MATROSKA_ID_BLOCKMORE, 0); - put_ebml_uint(pb, MATROSKA_ID_BLOCKADDID, 1); - put_ebml_id(pb, MATROSKA_ID_BLOCKADDITIONAL); - put_ebml_num(pb, side_data_size, 0); - avio_write(pb, side_data, side_data_size); + /* Until dbc50f8a our demuxer used a wrong default value + * of BlockAddID, so we write it unconditionally. */ + put_ebml_uint (pb, MATROSKA_ID_BLOCKADDID, additional_id); + put_ebml_binary(pb, MATROSKA_ID_BLOCKADDITIONAL, + side_data, side_data_size); end_ebml_master(pb, block_more); end_ebml_master(pb, block_additions); } - if ((side_data_size && additional_id == 1) || discard_padding) { + if (side_data_size || discard_padding) { end_ebml_master(pb, block_group); } }