From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5617D45C63 for ; Thu, 30 Mar 2023 02:05:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E44768C3C7; Thu, 30 Mar 2023 05:05:24 +0300 (EEST) Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 54DDE68C0B8 for ; Thu, 30 Mar 2023 05:05:18 +0300 (EEST) Received: by mail-ot1-f47.google.com with SMTP id f19-20020a9d5f13000000b00693ce5a2f3eso9279358oti.8 for ; Wed, 29 Mar 2023 19:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680141916; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=hQMnMiMV2ffdjGJMsO8FBvcmnuvy+fkilVhDRb6ShgQ=; b=Gk4vgxuQ2a9SLTdliiZkIq9BtBs1CJmvOuIelGw96Ksf9Y9ZirXmKzwx6y/8RsJsIb YTCGrncELkqIcjTHxXOUITo5a/ngi+T0Pd/1K2Mu+Z/KPKVCGWHp/U+dLw936NYYnE7e lWehZxeIKiksTJCI5ls7k2rNXKulVJOKvzPkmwrvsdAUhJGYOLiGE6/I67ew2ue9VAYA VITCwO1j5ye1PXaCt0ChYeS3RKuATF9dWraKEc5ISvL6i1cjOSqGAAWIcXJRwQCcvIwe maIj1LMXf8XRJ2UdYCmfbhYqC5KDFHRrbvSYW42my4ICODaB5Mhjnz6L9I92kErl+Zj2 TzTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680141916; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hQMnMiMV2ffdjGJMsO8FBvcmnuvy+fkilVhDRb6ShgQ=; b=qhzEUZHttp7UWiu4cHJoTxxvNNQPt4oIy3+EmrIuhlIf1naqXZyrrl1Cru+27i5wRm d3PrP1MPOOPMsnQ4TOVEm14ahMOdaHt9xcVxp7E1JgYt3avBkoMGmWV8CuuzZ/8f0HP/ DqTqaVhrN2El9zkYBtI/c7UU8hsSHwlRQOygF0Hm7Zt2PocU20p+PO4OMCZr87/JXaFQ nmKIZct1aAY0LbBb7I0v40ZNHNUOofaQR0FJR5RgjKXxDGuK/IsJbLcpGIj8Q0x1uOR4 qRryrhGKp5RMquUbW2G/D3mSCXml/8qwryhCR2TgSck97UAhxABO7ogtMTdMb7dFwegr 0OGg== X-Gm-Message-State: AO0yUKWVevVjOKdPHiVkun6KgY1svjjlYDAvBsVoSnZT7G08VYwwo8dS JuvX3cIsBZWx3EqQFQs5DEnvucYp76E= X-Google-Smtp-Source: AK7set+HHr7DoIv7nmQS1WmJ218FVHaQzPq4tVBIw/Kw/w8QXtovj3aWbPSch3UtBXGk7zu6DgnhFw== X-Received: by 2002:a9d:6a8a:0:b0:69f:25:19dd with SMTP id l10-20020a9d6a8a000000b0069f002519ddmr9975975otq.14.1680141916602; Wed, 29 Mar 2023 19:05:16 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id f23-20020a9d5e97000000b00684152e9ff2sm14221540otl.0.2023.03.29.19.05.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 19:05:15 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Mar 2023 23:04:42 -0300 Message-Id: <20230330020448.9146-1-jamrial@gmail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/7] avformat/matroskadec: support parsing more than one BlockMore element X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- Changes since v2: Cast 8 to size_t and fixed a return value. libavformat/matroskadec.c | 62 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3a888e3ada..b7f9870f3d 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -349,13 +349,17 @@ typedef struct MatroskaLevel { uint64_t length; } MatroskaLevel; +typedef struct MatroskaBlockMore { + uint64_t additional_id; + EbmlBin additional; +} MatroskaBlockMore; + typedef struct MatroskaBlock { uint64_t duration; CountedElement reference; uint64_t non_simple; EbmlBin bin; - uint64_t additional_id; - EbmlBin additional; + EbmlList blockmore; int64_t discard_padding; } MatroskaBlock; @@ -759,13 +763,13 @@ static EbmlSyntax matroska_segments[] = { }; static EbmlSyntax matroska_blockmore[] = { - { MATROSKA_ID_BLOCKADDID, EBML_UINT, 0, 0, offsetof(MatroskaBlock,additional_id), { .u = 1 } }, - { MATROSKA_ID_BLOCKADDITIONAL, EBML_BIN, 0, 0, offsetof(MatroskaBlock,additional) }, + { MATROSKA_ID_BLOCKADDID, EBML_UINT, 0, 0, offsetof(MatroskaBlockMore,additional_id), { .u = 1 } }, + { MATROSKA_ID_BLOCKADDITIONAL, EBML_BIN, 0, 0, offsetof(MatroskaBlockMore,additional) }, CHILD_OF(matroska_blockadditions) }; static EbmlSyntax matroska_blockadditions[] = { - { MATROSKA_ID_BLOCKMORE, EBML_NEST, 0, 0, 0, {.n = matroska_blockmore} }, + { MATROSKA_ID_BLOCKMORE, EBML_NEST, 0, sizeof(MatroskaBlockMore), offsetof(MatroskaBlock, blockmore), { .n = matroska_blockmore } }, CHILD_OF(matroska_blockgroup) }; @@ -3610,12 +3614,28 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, return 0; } +static int matroska_parse_block_additional(MatroskaDemuxContext *matroska, + AVPacket *pkt, + const uint8_t *data, int size, uint64_t id) +{ + uint8_t *side_data = av_packet_new_side_data(pkt, + AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, + size + (size_t)8); + if (!side_data) + return AVERROR(ENOMEM); + + AV_WB64(side_data, id); + memcpy(side_data + 8, data, size); + + return 0; +} + static int matroska_parse_frame(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, AVBufferRef *buf, uint8_t *data, int pkt_size, uint64_t timecode, uint64_t lace_duration, int64_t pos, int is_keyframe, - uint8_t *additional, uint64_t additional_id, int additional_size, + MatroskaBlockMore *blockmore, int nb_blockmore, int64_t discard_padding) { uint8_t *pkt_data = data; @@ -3647,7 +3667,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, buf = NULL; } - if (!pkt_size && !additional_size) + if (!pkt_size && !nb_blockmore) goto no_output; if (!buf) @@ -3666,16 +3686,18 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, pkt->flags = is_keyframe; pkt->stream_index = st->index; - if (additional_size > 0) { - uint8_t *side_data = av_packet_new_side_data(pkt, - AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, - additional_size + 8); - if (!side_data) { + for (int i = 0; i < nb_blockmore; i++) { + MatroskaBlockMore *more = &blockmore[i]; + + if (!more->additional.size) + continue; + + res = matroska_parse_block_additional(matroska, pkt, more->additional.data, + more->additional.size, more->additional_id); + if (res < 0) { av_packet_unref(pkt); - return AVERROR(ENOMEM); + return res; } - AV_WB64(side_data, additional_id); - memcpy(side_data + 8, additional, additional_size); } if (discard_padding) { @@ -3721,7 +3743,7 @@ fail: static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf, uint8_t *data, int size, int64_t pos, uint64_t cluster_time, uint64_t block_duration, int is_keyframe, - uint8_t *additional, uint64_t additional_id, int additional_size, + MatroskaBlockMore *blockmore, int nb_blockmore, int64_t cluster_pos, int64_t discard_padding) { uint64_t timecode = AV_NOPTS_VALUE; @@ -3856,7 +3878,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf res = matroska_parse_frame(matroska, track, st, buf, out_data, out_size, timecode, lace_duration, pos, !n ? is_keyframe : 0, - additional, additional_id, additional_size, + blockmore, nb_blockmore, discard_padding); if (res) return res; @@ -3897,14 +3919,12 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) if (res >= 0 && block->bin.size > 0) { int is_keyframe = block->non_simple ? block->reference.count == 0 : -1; - uint8_t* additional = block->additional.size > 0 ? - block->additional.data : NULL; res = matroska_parse_block(matroska, block->bin.buf, block->bin.data, block->bin.size, block->bin.pos, cluster->timecode, block->duration, - is_keyframe, additional, block->additional_id, - block->additional.size, cluster->pos, + is_keyframe, block->blockmore.elem, + block->blockmore.nb_elem, cluster->pos, block->discard_padding); } -- 2.40.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".