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 46DAC4570D for ; Tue, 21 Mar 2023 17:07:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EABE868C1E9; Tue, 21 Mar 2023 19:06:59 +0200 (EET) Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D060568C1C0 for ; Tue, 21 Mar 2023 19:06:52 +0200 (EET) Received: by mail-oi1-f174.google.com with SMTP id q30so4508860oiw.13 for ; Tue, 21 Mar 2023 10:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679418411; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=YHNGPyx2u42vIUhkeIS/rO0A49TDJB37+oj9wAhWw0M=; b=eLn7iS/byezH/wjY/R1OGrT8A9lrAqtPRAUsfhmv1TkISjhZq0e+WSyj6ZPW0v6Hof uIOHNGfkh1c5QlqRTCskIDHek27uHb7UdqjoWuUUdyHyZBEeVrdiRBIrpAvFe0s7Tn3F 1yWOy7tqQMkF9eYHM3JZF/ujRCdt0G164Uv2rvnlHaJhtrfuh4KvKad46g3uPr4hhPif +QnyV0wQekvC1OQsQKAcxrNdLmYekiPr1/oXwmbNL4ZWT3AxJOv+F8IFGhT/a7UPYDLt OJn+dCxwit+yoIf4niThM3BOcF2K9buns1uZ7e3iX87W9/0NNga+fvXfRI+gNOevf4T+ IX4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679418411; 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=YHNGPyx2u42vIUhkeIS/rO0A49TDJB37+oj9wAhWw0M=; b=wU/4UwZNy0duaP1vX5dgLWWM3PVSGWD3BdMWjYXpT6wS39sxeQWgMLbbH8kyBnBmTG 4d+dbvkJpCMewLxq9OVGR37ztoEiI0xrzxw/e+RvhPScYgP4zTrh4SGbMSSA/gru/9TB bzhjqUd/u7sz2DAe6c1DYjrl/1AyPCcdsr5Oi08UaxkBVaJmcZxH7idKlj7X+AaMZhOY 9L9RNCPlEY5tsJo0dkxkFvyugE3bb7NVQi7U7JFFTBYc8tdLLo013DyCqzSorzJCOSRf oK0NdpgJRdT8e/OGu9Y65bQJldXksmAYsUJxeWco/M8j3YsT6RNY83Sn3Ebgs5QJvDIx D65A== X-Gm-Message-State: AO0yUKVLebDjFaCccbSHVvqQnBJHMeHjoP7/DfLXROPVQA+VkPlkeHu5 fA9n1WYcx66sOEov82L+TdXVdM/IYr8= X-Google-Smtp-Source: AK7set9ycX+Fs1dA7DZ89/kDMWeyZG/aTRRs3ijnqW3UFPdFm0QR7ZA5ma9wB+L33vcVrQRVZI+sKg== X-Received: by 2002:a54:4001:0:b0:386:9691:f115 with SMTP id x1-20020a544001000000b003869691f115mr1296880oie.41.1679418411042; Tue, 21 Mar 2023 10:06:51 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id b11-20020aca1b0b000000b003872148d322sm845876oib.22.2023.03.21.10.06.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 10:06:50 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Mar 2023 14:06:31 -0300 Message-Id: <20230321170637.10907-1-jamrial@gmail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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 --- libavformat/matroskadec.c | 60 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3a888e3ada..60f9a78fe8 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 + 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); } - 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".