From patchwork Tue Apr 28 08:36:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19310 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 BA54E44A1EE for ; Tue, 28 Apr 2020 12:30:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 93E0F68BDE1; Tue, 28 Apr 2020 12:30:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0EA2A68BDDE for ; Tue, 28 Apr 2020 12:30:25 +0300 (EEST) Received: by mail-ej1-f68.google.com with SMTP id rh22so16688247ejb.12 for ; Tue, 28 Apr 2020 02:30:25 -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:mime-version :content-transfer-encoding; bh=22OXbt8DrB/Eq816XLMFZYhm9RLizcASD1FqmatfSgk=; b=bKPBpXNJTrTV+cJChQpHjRF+66z1W+YCsrVg6zjSVzngM6iE1KIoYOkvsO2+QIhO84 bzv0si6MaC3JbsrOiIErcEUqE2Z1+SMqe/QlbrpQ747tz3sRaDfyNbPZkZuHnvX7lhhA JF7uPWInYqKTPnLgrfbFyD1mIdwxtJCtbbhQrogWwaLE5c1iK6SjepuK5uzwaiHPQiU/ 1Qt8mWxFQLsHB6k73202YQjvvlHaTTLhAbF6zYqRjH+Ix44WR98/lS4MHgUlJbcFirEY Bwbx5IoI4exEABBK977hilNwB5M7wshaPpzInajESuQqqV2acgoVGps+No9iS4aCLwFo t2VA== 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:mime-version :content-transfer-encoding; bh=22OXbt8DrB/Eq816XLMFZYhm9RLizcASD1FqmatfSgk=; b=eqTCymTHBSvjiqw1MQfhMk44lNZM8tfjMS1IkCVWGmGG4dxazOfwhSE9uLQpL5jAzV vYWAsf0PRn5qfCtPB5yp3nWsbdgJitwX6PWhsC54tN9tE+a2q+fREVD7Aaeoi/unHI0l ygtoWVoau7b/x3a22ZITWnJqywMRxelWvcOyWcNdinGPl4riVy/QFvetp8fHDV659Ocu SzgTf2owzUjhYGuFPxoM5qAmbbzfgTyfKpHkODib1vE40YyIgYA+symrDvlzXXLczUv6 0NIi115dRLdo7/Qhx8Ba2zVmJPaEBFUzYpCxRCePGcHQL/xF+/GswFpfKXBizO6gHdX+ gm4w== X-Gm-Message-State: AGi0PuZL9neL0QVJO2IfkuwhnrZVdcWhjnNMno3EvP6zdhUA4XBRRl98 kr0i+N+OW5quIpvLftSvzR6qh7pO X-Google-Smtp-Source: APiQypIlG80b0JuuMqQQT6FzZpGS15bWkDb8Y2VV6ny5tdzrrJg50PrURw+GOTZTnq8oB64RQsn+Ug== X-Received: by 2002:adf:83c2:: with SMTP id 60mr31545229wre.169.1588063014449; Tue, 28 Apr 2020 01:36:54 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:36:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:39 +0200 Message-Id: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avformat/matroskaenc: Write SeekHead when livestreaming 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" Commit 6fd300ac6c2c3871736ce0e6df95603255004dc6 added support for WebM Chunk livestreaming; in this case, both the header as well as each Cluster is written to a file of its own, so that even if the AVIOContext seems seekable, the muxer has to behave as if it were not. Yet one of the added checks makes no sense: It ensures that no SeekHead is written preliminarily (and hence no SeekHead is written at all) if the option for livestreaming is set, although one should write the SeekHead in this case when writing the Header. E.g. the WebM-DASH specification [1] never forbids writing a SeekHead and in some instances (that don't apply here) even requires it (if Cues are written after the Clusters). [1]: https://sites.google.com/a/webmproject.org/wiki/adaptive-streaming/webm-dash-specification Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 784973a951..dd77ae64bc 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1896,7 +1896,7 @@ static int mkv_write_header(AVFormatContext *s) if (ret < 0) return ret; - if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { + if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) || mkv->is_live) { ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb)); if (ret < 0) return ret; From patchwork Tue Apr 28 08:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19299 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 E9A2344B819 for ; Tue, 28 Apr 2020 11:40:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C6AD768BDEC; Tue, 28 Apr 2020 11:40:10 +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 E7C7F68BC1A for ; Tue, 28 Apr 2020 11:40:04 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id x18so23595811wrq.2 for ; Tue, 28 Apr 2020 01:40:04 -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=Nla5j8xYpQm2rJ9ebjj/2LusNa+8/GPgXyuKnI+HJQA=; b=k7vBD2QfiWVz/Z1tWIS+hPIvvM9k5ryiyZR6/caCiKGEZDvlB6IZqpCs6WLFwfS6Is z8XNs+eF2FZoCL1O8MW1lgYfaZiTKPU7gfMH4BPSg3P5vO6CxJzOAj3B5r+97u4votgy 67+FEoysS8USFd+Cu0+cNjIJTNDIHf6nIXpZVxpk1pnFNPzZ67oH6qc7Qgs3t00GJe3O VEnK+6LXiMI1W5QHFzmxTpfLN7gpi2th1+ZUZJtxaJwkEGM6Kq4uO62F9dhdFYH5Dxzr s4Q2j1BmZUCN+hHOOsdn4vOZ0OOKPWrd3nAenBSg7lt/p/wxsVg/R+L4kCnwp2PUGlJ/ 7fvQ== 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=Nla5j8xYpQm2rJ9ebjj/2LusNa+8/GPgXyuKnI+HJQA=; b=cEuZ9FHh4NgHBQB0jcMlq5fZBnROHnM7zOiddJkY2I/P7dQYVk9aB2KIe3ZXv/xNAG wrLhANdpqfuPQqo+0gEbBkch+f1UoLrKTKIauFcWdue1mkBAsIgsd9KIF93WHP1YpygM XVjmexqsVElb7AH7etrSTismlMhQuZjRsFNEJsR6MFgtwzdrLNkhzcTISanX+DEmr4Tu iewGAbb4X+MWWsKY3N7rNyg8QEG4/ef9KsoZAfhQnA29nV3bU5CNkwlF6QN31/S2JYDh lYB2RSH5i9Zvs6FlTshGC6Yihdc1J9x7ylqWJ6Y6n0ZfD939hD7zN4zdYHPYk/3m7Wxw lBmg== X-Gm-Message-State: AGi0PuY+U6Dtk4s8k2xd31AgBpCLNrLO5Zk/Jadt1GgITbvq1AmZva00 uPyVVx9m9tGIAhKLcqYPn/9D53c1 X-Google-Smtp-Source: APiQypIUJd6w1skMqGv2lbr431vaZ5rpsAvamjv+Fnirst7YekgoiW4Hb/NAZP4KPKB9jMHJiewNCA== X-Received: by 2002:adf:cc81:: with SMTP id p1mr34078920wrj.372.1588063203945; Tue, 28 Apr 2020 01:40:03 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:03 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:40 +0200 Message-Id: <20200428083645.4909-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] avformat/matroskaenc: Replace impossible condition with assert 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" If a FLAC track uses an unconventional channel layout, the Matroska muxer adds a WAVEFORMATEXTENSIBLE_CHANNEL_MASK VorbisComment to the CodecPrivate to preserve this information. And given that FLAC uses 24bit length fields, the muxer checks if the length is more than this and errors out if it is. Yet this can never happen, because we create the AVDictionary that is the source for the VorbisComment. It only contains exactly one entry that can't grow infinitely large (in fact, the length of the VorbisComment is <= 4 + 33 + 1 + 18 + strlen(LIBAVFORMAT_IDENT)). So we can simply assert the size to be < (1 << 24) - 4. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index dd77ae64bc..018108b96b 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -631,10 +631,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); len = ff_vorbiscomment_length(dict, vendor, NULL, 0); - if (len >= (1 << 24) - 4) { - av_dict_free(&dict); - return AVERROR(EINVAL); - } + av_assert1(len < (1 << 24) - 4); data = av_malloc(len + 4); if (!data) { From patchwork Tue Apr 28 08:36:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19300 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 1308344B819 for ; Tue, 28 Apr 2020 11:40:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0D7068BDF2; Tue, 28 Apr 2020 11:40:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EF2AF68BDFA for ; Tue, 28 Apr 2020 11:40:05 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id z6so1881483wml.2 for ; Tue, 28 Apr 2020 01:40:05 -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=cilQ+RYBpMsAbRn/+MOCrVomGgcGUmUxFOafDs5EX6E=; b=Scm0Y/FUVuSIH1wI6o+35bFdl5aV8hyyrvzUV4DHxZAE+U6OrX2lwxMFch5CP8oFO/ 7HbMT9Ve/ia23cdoVS0Dm+U5c/Rwkc1cKp70atm6GdVmDBRaQxBlsQvupTwapjn3BNU9 psl3JkuTM6uNnkjCw6eHhG2KfvBUE9AGWV+Jfl/FKyiWgUlUY35hj6PZ73g7pKFNZqBH 4JNxQov9JeUPPbaKuhsxtH2GVXl1tpIaq03HRLvJyB6FEvO/sxV/kssrc/33qPjcMmZv bcPs/oPojjeNxO+5unlbTCnOeFzlKciQJWxfHsc8RrCfVHbYgQfSKjfQ2NUmdCFOlbIh NRJA== 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=cilQ+RYBpMsAbRn/+MOCrVomGgcGUmUxFOafDs5EX6E=; b=M/qiQd1J690e0Zz9nEQbRPgr/SeAr8jMz9xdo3PPr3FDu2yo+xiHBcsGO+vT0LyDDv UqNgV0rNA40t+zsfSQjonBGqaCSjKlszU+uxJwCQRFL6BtLxhGpQEfvq+kDf2BC3qVmK IFt8eZnpyHFvMsE+EvbeE5RZ2+XIAmecaprt2HofBjwGnnPptprukqGreajOatw3LdPY +OK3zHxL7tPnKoLtV/tiesShPDzBcSDrbl0iC4dioeBHVqvq/AJGDDE0Pbz39b0I6o1V fCd9bYTo26lxnhlUtvcqysWRkeBa94RvH0QaD02vNQ8ioVrIcZ3QPODmCDp8U1lUAVAt 3G5g== X-Gm-Message-State: AGi0PuZSJkzc9tygh7qvw3qN1HUP/u42EYovapk5AW0DgszeWK0cEKZz exVzE82lV4FSW62KTKUk9DAOK8Yq X-Google-Smtp-Source: APiQypI3v6aZRdd+xPi21x/K4DqD/GmBliiMNBAuMcxYcwnYVqaWzXF4lyoD3OJPrnCxfMq2YGkXEA== X-Received: by 2002:a7b:c0d5:: with SMTP id s21mr3249100wmh.107.1588063204952; Tue, 28 Apr 2020 01:40:04 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:04 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:41 +0200 Message-Id: <20200428083645.4909-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] avformat/vorbiscomment: Replace AVDictionary ** by const AVDictionary * 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" ff_vorbiscomment_write() used an AVDictionary ** parameter for a dictionary whose contents ought to be written; yet this can be replaced by AVDictionary * since commit 042ca05f0fdc5f4d56a3e9b94bc9cd67bca9a4bc; and this in turn can be replaced by const AVDictionary * to indicate that the dictionary isn't modified; the latter also applies to ff_vorbiscomment_length(). Signed-off-by: Andreas Rheinhardt --- libavformat/flacenc.c | 2 +- libavformat/matroskaenc.c | 2 +- libavformat/oggenc.c | 2 +- libavformat/vorbiscomment.c | 10 +++++----- libavformat/vorbiscomment.h | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index a043274df6..0e88e18355 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -76,7 +76,7 @@ static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m, bytestream_put_byte(&p, last_block ? 0x84 : 0x04); bytestream_put_be24(&p, len); - ff_vorbiscomment_write(&p, m, vendor, NULL, 0); + ff_vorbiscomment_write(&p, *m, vendor, NULL, 0); avio_write(pb, p0, len+4); av_freep(&p0); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 018108b96b..58bcdb904f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -643,7 +643,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, AV_WB24(data + 1, len); p = data + 4; - ff_vorbiscomment_write(&p, &dict, vendor, NULL, 0); + ff_vorbiscomment_write(&p, dict, vendor, NULL, 0); avio_write(pb, data, len + 4); diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index fbd14fedf9..cc9a899a4c 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -308,7 +308,7 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact, p0 = p; p += offset; - ff_vorbiscomment_write(&p, m, vendor, chapters, nb_chapters); + ff_vorbiscomment_write(&p, *m, vendor, chapters, nb_chapters); if (framing_bit) bytestream_put_byte(&p, 1); diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c index fb5c655a23..edaeae2772 100644 --- a/libavformat/vorbiscomment.c +++ b/libavformat/vorbiscomment.c @@ -38,7 +38,7 @@ const AVMetadataConv ff_vorbiscomment_metadata_conv[] = { { 0 } }; -int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, +int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters) { int64_t len = 8; @@ -62,7 +62,7 @@ int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, return len; } -int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, +int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters) { @@ -74,11 +74,11 @@ int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, cm_count += av_dict_count(chapters[i]->metadata) + 1; } } - if (*m) { - int count = av_dict_count(*m) + cm_count; + if (m) { + int count = av_dict_count(m) + cm_count; AVDictionaryEntry *tag = NULL; bytestream_put_le32(p, count); - while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) { + while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) { int64_t len1 = strlen(tag->key); int64_t len2 = strlen(tag->value); if (len1+1+len2 > UINT32_MAX) diff --git a/libavformat/vorbiscomment.h b/libavformat/vorbiscomment.h index 4ff3dd6c27..af9bd75cd7 100644 --- a/libavformat/vorbiscomment.h +++ b/libavformat/vorbiscomment.h @@ -34,7 +34,7 @@ * For no string, set to an empty string. * @return The length in bytes. */ -int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, +int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters); /** @@ -49,7 +49,7 @@ int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, * @param chapters The chapters to write. * @param nb_chapters The number of chapters to write. */ -int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, +int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters); From patchwork Tue Apr 28 08:36:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19301 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 2B7C044B819 for ; Tue, 28 Apr 2020 11:40:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1730768BE17; Tue, 28 Apr 2020 11:40:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8124268BDF0 for ; Tue, 28 Apr 2020 11:40:07 +0300 (EEST) Received: by mail-wm1-f44.google.com with SMTP id 188so1765270wmc.2 for ; Tue, 28 Apr 2020 01:40:07 -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=m7c5qcpD3i55Zijacg3Q14hfwfDzLZ5gORONi2+B/h4=; b=RepwhczFbd4VGPFtpTvuMVPpr6DRkvNp/iivGLm+L5bEAx4bLvS93pv1/OZXeWwqaM NQ5DoarZmEQDRpK+xgpUEQhjKJZ1Hxyl3g8ryzuoXrZiw+SVjsfdvF9Q6vBOh7faF/Um 6PumnBFOD3RMFxzGI8VZwDUUkgu3YHYauntsyRECEUnQ1QxJ5Y5zy1spq6uIr0x7/rdc VUCuP2RkyJfSfFpMS68U/i2Ry9g57xC6A4dYmRmEZs2JFZZ732SCTjQETO0CN6L+t17O MhRJRiQCvm+cwVx9Scbr7Iy1wrT5gjvKsI1aktHmIpPgqJob2GpN3L7HUrZ/kqqhTaNU wONQ== 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=m7c5qcpD3i55Zijacg3Q14hfwfDzLZ5gORONi2+B/h4=; b=aW/eDgVOB69ruALvD7XeejpzugApmqXpAXOu5AbqescRIGoMKWFJ/n3rgy32HrhwIc mxa9E6vYv7VC1Qn8XXQXDxJzfmKn5NrMfIc9ZLXBWIcTAP6r9d0A5wW4CKZZKyw2wEJI h5iQEsuzeDVFhyUQ+9+vs6ZbpzSdVVJx48jw+8dWd5nA2CsyWdeVU15zEXlsX96ZV8Oq fRgjDsiEp3VzuMsyNYc/XIgDKfjA0dv/vNpvFuywmJdJv+w/aacDYqwdnKja0z88Dyax qvGsgYEGPrqYqKxaKzwsbbBzfpJRGNFPC8v1DJUWWoqfcvs0I4tgnIob8ph/tefUGfA2 NSwA== X-Gm-Message-State: AGi0PubeQJNncSkJlJcEG+2G9w4ZgYF+HR/Qd5JTsNovaKFzDVAecG/I NTiKIRwmm9/uNJovVeS7kVmfOQI+ X-Google-Smtp-Source: APiQypLMYfyBJ10Q/rN5Md6A2y516K1+6V8v+sZS/iZZFPx7Zmsj0tXYgCr5tguzWVXz+jxK/bGBrw== X-Received: by 2002:a1c:7f91:: with SMTP id a139mr3151664wmd.164.1588063206357; Tue, 28 Apr 2020 01:40:06 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:05 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:42 +0200 Message-Id: <20200428083645.4909-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] avformat/vorbiscomment: Switch to AVIOContext from bytestream API 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" ff_vorbiscomment_write() used up until now the bytestream API to write VorbisComments. Therefore the caller had to provide a sufficiently large buffer to write the output. Yet two of the three callers (namely the FLAC and the Matroska muxer) actually want the output to be written via an AVIOContext; therefore they allocated buffers of the right size just for this purpose (i.e. they get freed immediately afterwards). Only the Ogg muxer actually wants a buffer. But given that it is easy to wrap a buffer into an AVIOContext this commit changes ff_vorbiscomment_write() to use an AVIOContext for its output. Signed-off-by: Andreas Rheinhardt --- libavformat/flacenc.c | 18 ++++----------- libavformat/matroskaenc.c | 18 ++++----------- libavformat/oggenc.c | 12 +++++----- libavformat/vorbiscomment.c | 44 ++++++++++++++++++------------------- libavformat/vorbiscomment.h | 9 ++++---- 5 files changed, 40 insertions(+), 61 deletions(-) diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index 0e88e18355..b947a3b067 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -29,7 +29,6 @@ #include "id3v2.h" #include "internal.h" #include "vorbiscomment.h" -#include "libavcodec/bytestream.h" typedef struct FlacMuxerContext { @@ -62,25 +61,16 @@ static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m, { const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; int64_t len; - uint8_t *p, *p0; ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL); len = ff_vorbiscomment_length(*m, vendor, NULL, 0); if (len >= ((1<<24) - 4)) return AVERROR(EINVAL); - p0 = av_malloc(len+4); - if (!p0) - return AVERROR(ENOMEM); - p = p0; - - bytestream_put_byte(&p, last_block ? 0x84 : 0x04); - bytestream_put_be24(&p, len); - ff_vorbiscomment_write(&p, *m, vendor, NULL, 0); - - avio_write(pb, p0, len+4); - av_freep(&p0); - p = NULL; + + avio_w8(pb, last_block ? 0x84 : 0x04); + avio_wb24(pb, len); + ff_vorbiscomment_write(pb, *m, vendor, NULL, 0); return 0; } diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 58bcdb904f..3513a1697a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -624,7 +624,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ? "Lavf" : LIBAVFORMAT_IDENT; AVDictionary *dict = NULL; - uint8_t buf[32], *data, *p; + uint8_t buf[32]; int64_t len; snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); @@ -633,21 +633,11 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, len = ff_vorbiscomment_length(dict, vendor, NULL, 0); av_assert1(len < (1 << 24) - 4); - data = av_malloc(len + 4); - if (!data) { - av_dict_free(&dict); - return AVERROR(ENOMEM); - } - - data[0] = 0x84; - AV_WB24(data + 1, len); - - p = data + 4; - ff_vorbiscomment_write(&p, dict, vendor, NULL, 0); + avio_w8(pb, 0x84); + avio_wb24(pb, len); - avio_write(pb, data, len + 4); + ff_vorbiscomment_write(pb, dict, vendor, NULL, 0); - av_freep(&data); av_dict_free(&dict); } diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index cc9a899a4c..3aff3c7a08 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -294,8 +294,9 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact, AVChapter **chapters, unsigned int nb_chapters) { const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; + AVIOContext pb; int64_t size; - uint8_t *p, *p0; + uint8_t *p; ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL); @@ -305,15 +306,14 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact, p = av_mallocz(size); if (!p) return NULL; - p0 = p; - p += offset; - ff_vorbiscomment_write(&p, *m, vendor, chapters, nb_chapters); + ffio_init_context(&pb, p + offset, size - offset, 1, NULL, NULL, NULL, NULL); + ff_vorbiscomment_write(&pb, *m, vendor, chapters, nb_chapters); if (framing_bit) - bytestream_put_byte(&p, 1); + avio_w8(&pb, 1); *header_len = size; - return p0; + return p; } static int ogg_build_flac_headers(AVCodecParameters *par, diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c index edaeae2772..a929634cc0 100644 --- a/libavformat/vorbiscomment.c +++ b/libavformat/vorbiscomment.c @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "avio.h" #include "avformat.h" #include "metadata.h" #include "vorbiscomment.h" -#include "libavcodec/bytestream.h" #include "libavutil/dict.h" /** @@ -62,13 +62,13 @@ int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string return len; } -int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, +int ff_vorbiscomment_write(AVIOContext *pb, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters) { int cm_count = 0; - bytestream_put_le32(p, strlen(vendor_string)); - bytestream_put_buffer(p, vendor_string, strlen(vendor_string)); + avio_wl32(pb, strlen(vendor_string)); + avio_write(pb, vendor_string, strlen(vendor_string)); if (chapters && nb_chapters) { for (int i = 0; i < nb_chapters; i++) { cm_count += av_dict_count(chapters[i]->metadata) + 1; @@ -77,16 +77,16 @@ int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, if (m) { int count = av_dict_count(m) + cm_count; AVDictionaryEntry *tag = NULL; - bytestream_put_le32(p, count); + avio_wl32(pb, count); while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) { int64_t len1 = strlen(tag->key); int64_t len2 = strlen(tag->value); if (len1+1+len2 > UINT32_MAX) return AVERROR(EINVAL); - bytestream_put_le32(p, len1+1+len2); - bytestream_put_buffer(p, tag->key, len1); - bytestream_put_byte(p, '='); - bytestream_put_buffer(p, tag->value, len2); + avio_wl32(pb, len1 + 1 + len2); + avio_write(pb, tag->key, len1); + avio_w8(pb, '='); + avio_write(pb, tag->value, len2); } for (int i = 0; i < nb_chapters; i++) { AVChapter *chp = chapters[i]; @@ -101,11 +101,11 @@ int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, s = s % 60; snprintf(chapter_number, sizeof(chapter_number), "%03d", i); snprintf(chapter_time, sizeof(chapter_time), "%02d:%02d:%02d.%03d", h, m, s, ms); - bytestream_put_le32(p, 10+1+12); - bytestream_put_buffer(p, "CHAPTER", 7); - bytestream_put_buffer(p, chapter_number, 3); - bytestream_put_byte(p, '='); - bytestream_put_buffer(p, chapter_time, 12); + avio_wl32(pb, 10 + 1 + 12); + avio_write(pb, "CHAPTER", 7); + avio_write(pb, chapter_number, 3); + avio_w8(pb, '='); + avio_write(pb, chapter_time, 12); tag = NULL; while ((tag = av_dict_get(chapters[i]->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { @@ -113,18 +113,18 @@ int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, int64_t len2 = strlen(tag->value); if (len1+1+len2+10 > UINT32_MAX) return AVERROR(EINVAL); - bytestream_put_le32(p, 10+len1+1+len2); - bytestream_put_buffer(p, "CHAPTER", 7); - bytestream_put_buffer(p, chapter_number, 3); + avio_wl32(pb, 10 + len1 + 1 + len2); + avio_write(pb, "CHAPTER", 7); + avio_write(pb, chapter_number, 3); if (!strcmp(tag->key, "title")) - bytestream_put_buffer(p, "NAME", 4); + avio_write(pb, "NAME", 4); else - bytestream_put_buffer(p, tag->key, len1); - bytestream_put_byte(p, '='); - bytestream_put_buffer(p, tag->value, len2); + avio_write(pb, tag->key, len1); + avio_w8(pb, '='); + avio_write(pb, tag->value, len2); } } } else - bytestream_put_le32(p, 0); + avio_wl32(pb, 0); return 0; } diff --git a/libavformat/vorbiscomment.h b/libavformat/vorbiscomment.h index af9bd75cd7..7cacd0b2a0 100644 --- a/libavformat/vorbiscomment.h +++ b/libavformat/vorbiscomment.h @@ -38,18 +38,17 @@ int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string AVChapter **chapters, unsigned int nb_chapters); /** - * Write a VorbisComment into a buffer. The buffer, p, must have enough - * data to hold the whole VorbisComment. The minimum size required can be - * obtained by passing the same AVDictionary and vendor_string to + * Write a VorbisComment into an AVIOContext. The output size can be obtained + * in advance by passing the same chapters, AVDictionary and vendor_string to * ff_vorbiscomment_length() * - * @param p The buffer in which to write. + * @param pb The AVIOContext to write the output. * @param m The metadata struct to write. * @param vendor_string The vendor string to write. * @param chapters The chapters to write. * @param nb_chapters The number of chapters to write. */ -int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m, +int ff_vorbiscomment_write(AVIOContext *pb, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters); From patchwork Tue Apr 28 08:36:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19302 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 E110844B819 for ; Tue, 28 Apr 2020 11:40:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE7C868BE29; Tue, 28 Apr 2020 11:40:16 +0300 (EEST) 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 8847168BE09 for ; Tue, 28 Apr 2020 11:40:08 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id k13so23643495wrw.7 for ; Tue, 28 Apr 2020 01:40:08 -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=GBRMxTwFDLcdeqrc5dOzmlLpfeGy/V2cbOZ2Qqdz/74=; b=WmbfgS5uO8vMdFEkiGXOoGfBtBxVVjjUpqGoPMDIVUl8hjedIW5uzxgq9T984pEoY8 ofrKCfLpy86Ny4cEjt7tQYp0UEZSB0ntd4cPShCBeZcnF65qJGFYlQyefUKtngtJjT2g EI7VdNQDzWOjOWC8P2hHWJjIE1L+J+kxzK9KjrCEgP04rD7T9mt9A64K7+4wHwBybYdT Cn++PC5mCdqC6fXyOFnngyxxXoMoacWpExzECalLsa63PqyrpLHd1dlPFq96uhGlm9ca gwrPAiObPaAOAXlNpa9Sv3CFsAEu+jYsuRCSlwp5H8t80CmIVwwxzHlrr+Jb67fn96+q DMOg== 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=GBRMxTwFDLcdeqrc5dOzmlLpfeGy/V2cbOZ2Qqdz/74=; b=En6/VIjfOSAgvSo+QTNnDTZszz4KYS5oTXaW0y01BcLKj7D+kTpdTUOQ2pTVukNyRB 6JMewvYGLHOMl79LQe+CNSqSiVLnA1usjnFaxHWqALKUj/ow8SgaHgjkiFKNHM2HkRfB 735s7NECekphsD27kCmTf9RXrgdN0TYSwUtoVv3Baa1un2IjM+9vk9ovvNEAC/R0MrLG 0V2DcKjGX40dZYM1WS0JtmWJlvlIC8/G5uTd+WvKsy1wt0V22x06ghu/3cdW2kIMN/cp AzcZWfxX2iiXj3TMraqGK0x6tmEoOS2vgIM2lJYdSeZDQvJ5sRyPPqJBDYXQ9oA4DGhg hJsQ== X-Gm-Message-State: AGi0PuZlXfYw6DqfxrGDN6f8bC7KuZxSoV/qr0C4A8sEvtrwuhAOVwaz b+VohUVS+J3W7dxClq1TNF8nlxr9 X-Google-Smtp-Source: APiQypJt6nb9ktAPpuM+39nD7G+ucQMP2i4YN0A6GcXXhZ5274/U3G1bnBFrqWyIN1SjQZQCVZAqTQ== X-Received: by 2002:a5d:5273:: with SMTP id l19mr31971982wrc.42.1588063207630; Tue, 28 Apr 2020 01:40:07 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:43 +0200 Message-Id: <20200428083645.4909-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avformat/matroskaenc: Make sure UIDs of delayed chapters are != 0 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" This has previously only been checked if the chapters were initially available, but not if they were only written in the trailer. Signed-off-by: Andreas Rheinhardt --- Any Tags pertaining to Chapters added late are currently ignored/lost, too. The Matroska specifications allow multiple Tags elements (our demuxer doesn't ...), so one could write a second Tags element at the end. I'm working on it. libavformat/matroskaenc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 3513a1697a..668b18e9ee 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1437,6 +1437,12 @@ static int mkv_write_chapters(AVFormatContext *s) if (!s->nb_chapters || mkv->wrote_chapters) return 0; + for (i = 0; i < s->nb_chapters; i++) + if (!s->chapters[i]->id) { + mkv->chapter_id_offset = 1; + break; + } + mkv_add_seekhead_entry(mkv, MATROSKA_ID_CHAPTERS, avio_tell(pb)); ret = start_ebml_master_crc32(&dyn_cp, mkv); @@ -1863,12 +1869,6 @@ static int mkv_write_header(AVFormatContext *s) if (ret < 0) return ret; - for (i = 0; i < s->nb_chapters; i++) - if (!s->chapters[i]->id) { - mkv->chapter_id_offset = 1; - break; - } - ret = mkv_write_chapters(s); if (ret < 0) return ret; @@ -1879,6 +1879,7 @@ static int mkv_write_header(AVFormatContext *s) return ret; } + /* Must come after mkv_write_chapters() because of chapter_id_offset */ ret = mkv_write_tags(s); if (ret < 0) return ret; From patchwork Tue Apr 28 08:36:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19303 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 E5E9E44B819 for ; Tue, 28 Apr 2020 11:40:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CBE0B68BE1B; Tue, 28 Apr 2020 11:40:17 +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 C8A0F68BE09 for ; Tue, 28 Apr 2020 11:40:13 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id g13so23609963wrb.8 for ; Tue, 28 Apr 2020 01:40:13 -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=PPxAj4wtIxs6GppaBffQ3A4cV1ykZsmvXYUdhBQDXFU=; b=WLfH0qPomxH1n0+JgMhrNqx3XZNvuOoUIiO7D4Od2MXrqO5d5i/myJ0gQsc7c+BjWQ T3wZADhWsNCSRvf3u+am06E886wGmH5Mt9ZK/fREOF7tdXCQtUd/cFiiv+G4uPxMAc0l 9jI6XomLFbq7h9DKY0DGG6rwtaFbO56Oejmx4cr6ou6tBV7wOsDK1fSnI11yv0BazKi9 GeW/NJ2dAUjJUjazR0lT7RThcukG1+1KdP2MmhwOyFJbKuEOVW/Hv31jPHUFuR1ftBL/ bhGBSKIHOvleCY6Zxt1pJMmwYStH6ui4/T1olrD9Kd7AUEHYx1lePSgj2xqS2Eu3a+88 Fr5w== 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=PPxAj4wtIxs6GppaBffQ3A4cV1ykZsmvXYUdhBQDXFU=; b=caQ0bHG36MuhUrhDV9cFAPkZh4hVi2SNhJ53JXzBw+KZNuquMdoh4HkCSnqV8kbrHd +rHdlH7bc5Hh13kLwcw/4yt00CD8XqMB/ySV6oUbllPE9kz4ea3KFiUXHEJo6LWm1hxT EU/mj8od4f9dsdxuMckENQuOopuIiwFk6rBaltwBvP8SGujyMc6jB8kLSIMHhsLpqn4b cQxtsj7NMVlI+z7iB9NTNrUgdwyhMN0mlzNCWgV/qj44q8JJiWKvgXYggwBX0Wu/CgND g9S5B9koFvMvXZU/wfDRKLSe7D72WkuEHGeLWULGgpAAh9bHclEGHYPWD59HV6xhSnej 2gDA== X-Gm-Message-State: AGi0PuYn+Llw6ED3gFjHqS2CSP/mgr+ZSj/kSxmHTUqUw0sMkWAo760u sh5GCiuNBVpIg6z2vIgPWjt1SwgS X-Google-Smtp-Source: APiQypKO4OWlbjAy9/cpTPFnvYHY5/ZW7La+udvXeNUqx9u1wQUXKl1vYKUVSkpFgZoPP5DrxwgyBw== X-Received: by 2002:adf:d091:: with SMTP id y17mr31044011wrh.418.1588063208714; Tue, 28 Apr 2020 01:40:08 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:44 +0200 Message-Id: <20200428083645.4909-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avformat/matroskaenc: Fix memleak upon encountering bogus chapter 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" Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 668b18e9ee..09f08c1e9f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1463,6 +1463,7 @@ static int mkv_write_chapters(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Invalid chapter start (%"PRId64") or end (%"PRId64").\n", chapterstart, chapterend); + ffio_free_dyn_buf(&dyn_cp); return AVERROR_INVALIDDATA; } From patchwork Tue Apr 28 08:36:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19304 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 E64C244B819 for ; Tue, 28 Apr 2020 11:40:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF7F268BE51; Tue, 28 Apr 2020 11:40:21 +0300 (EEST) 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 A466A68BE10 for ; Tue, 28 Apr 2020 11:40:10 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id g12so1868264wmh.3 for ; Tue, 28 Apr 2020 01:40:10 -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=gOR7krMdE/LC2CxgmlV5mEF39vTIyUTbNzDzdyqjdF8=; b=G7H67xpBNDkLK2ByoYrFLYP8N54mMNUR/HkhvCE72JciLzl3GukZiuoGqQPoyCE1Zu KbV8WdM07JI3hbaa/tyUWf2gTQhQKEI4pZ0VI/6Sa717GNTw4kj6vC44X9vZesxzehlT rdN5zIJcYz6IzQrOimmUdCbxGRv78dPnQkiOENzLF3m0DOqfFfnZxNWkF5TiK37OHp7a SXkkeGU0Nv1CLjGaGaGzaq6eQ+aMcj3pL/ip4cansGzTw1NakLmqRpjJjJM8Pgp7v/wz eQQPTXfbflht/CrzSOrydt0dx8hrchw7uQFAY1FTA2PMeTVtKooGPz5HctEDT+IrTwrv ug1Q== 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=gOR7krMdE/LC2CxgmlV5mEF39vTIyUTbNzDzdyqjdF8=; b=b128EWSRbUX/ZSzwEU4FaDskdPjGGvpo6Zq6QtQri8BiHfr5wLF5TUhGJ6qM53KsX/ mBS0aEFBKdiyQGDnk/dq+qroaPlhavLEPV7BdqYzpML90MmTa1S/zeySneip5fJ3Nz0T WYkxLiy5+A8Pw73f1iG1KS5Nb/bU6/f8G6wT95MkC+fYpxKGrj8v58HalRI0KFdSuGBg P85Kx3p/LyVvMsLtvRjAoaZ2WygDh5B3ynNq9DZPk2YGIDgx5HY2CIaFEtbZFPPgQBpT wc5VAqd9qgy+UmfZQpV3B0IRcTnet3Z5E0hYM4BoXT4EOfUEuucJG+kLW0+W0MP3Gwda bauA== X-Gm-Message-State: AGi0PuZ7Xfn5FgagJq5ADnH+amnQP7jXlpJiwbw1MF73d0IQg9Ddx7hO mQo0cHQjk0FehESiQn+3zr+2PPfb X-Google-Smtp-Source: APiQypI8UHkvOtK38YSjTEol8QsQPdykJDpLu8IRpcdrej6gGxlST9Scx49ZkQahNJT9wYuIpgKqpg== X-Received: by 2002:a1c:dd8a:: with SMTP id u132mr3155627wmg.87.1588063209799; Tue, 28 Apr 2020 01:40:09 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w11sm2258351wmi.32.2020.04.28.01.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 01:40:09 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 10:36:45 +0200 Message-Id: <20200428083645.4909-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> References: <20200428083645.4909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] avformat/matroskaenc: Check mimetypes earlier 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" This avoids errors lateron after the file header has already been partially written. Signed-off-by: Andreas Rheinhardt --- Also avoids a memleak in case of missing mimetype metadata. libavformat/matroskaenc.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 09f08c1e9f..a1b613290c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1687,6 +1687,23 @@ static int mkv_write_tags(AVFormatContext *s) return 0; } +static const char *get_mimetype(const AVStream *st) +{ + const AVDictionaryEntry *t; + + if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) + return t->value; + if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { + const AVCodecDescriptor *desc = avcodec_descriptor_get(st->codecpar->codec_id); + if (desc && desc->mime_types) { + return desc->mime_types[0]; + } else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT) + return "text/plain"; + } + + return NULL; +} + static int mkv_write_attachments(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; @@ -1707,7 +1724,7 @@ static int mkv_write_attachments(AVFormatContext *s) mkv_track *track = &mkv->tracks[i]; ebml_master attached_file; const AVDictionaryEntry *t; - const char *mimetype = NULL; + const char *mimetype; if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; @@ -1721,21 +1738,9 @@ static int mkv_write_attachments(AVFormatContext *s) return AVERROR(EINVAL); } put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, t->value); - if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) - mimetype = t->value; - else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) { - const AVCodecDescriptor *desc = avcodec_descriptor_get(st->codecpar->codec_id); - if (desc && desc->mime_types) { - mimetype = desc->mime_types[0]; - } else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT) - mimetype = "text/plain"; - } - if (!mimetype) { - av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and " - "it cannot be deduced from the codec id.\n", i); - return AVERROR(EINVAL); - } + mimetype = get_mimetype(st); + av_assert0(mimetype); put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype); put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size); put_ebml_uid(dyn_cp, MATROSKA_ID_FILEUID, track->uid); @@ -2672,6 +2677,10 @@ static int mkv_init(struct AVFormatContext *s) if (mkv->mode == MODE_WEBM) { av_log(s, AV_LOG_WARNING, "Stream %d will be ignored " "as WebM doesn't support attachments.\n", i); + } else if (!get_mimetype(st)) { + av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype " + "tag and it cannot be deduced from the codec id.\n", i); + return AVERROR(EINVAL); } mkv->nb_attachments++; continue;