From patchwork Wed Aug 14 07:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc-Antoine ARNAUD X-Patchwork-Id: 51010 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a746:0:b0:489:2eb3:e4c4 with SMTP id f6csp739203vqm; Wed, 14 Aug 2024 00:59:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWK/Zj+6bA1kyIbyiXRGNTtLBnw+k5ls2CLMZJAs/wGrOhlQH+bqSwhfXvqYVg5gPJJTnB6CVGZoRj9UTkg/Vy/P1LQ5aQa8Tv2+w== X-Google-Smtp-Source: AGHT+IEwiKiI9IBtfTwXNA8CK+IDLmApknXAqAvgoDJOteOi/Sc8dkYcQRbpFAHGkO/8iJvVg0eK X-Received: by 2002:a05:651c:2212:b0:2f0:19da:c039 with SMTP id 38308e7fff4ca-2f3aa2f58f5mr6028451fa.6.1723622377026; Wed, 14 Aug 2024 00:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723622376; cv=none; d=google.com; s=arc-20160816; b=i+pCUA+5bQLSHdgRiggn+PEnbHrUAFe3HhgLiKPU2Hv5EEtGSXOa1mUJMrNVUdlPAf QOJjhoi7f/zEeD/wts6PXdqUgw67b1P+FwHq35n6iCKbEiuVatAb+F5B5UI2jH9COm9j GdioXEXso30edb7ccm2l6a7efheviiPOiLYntkjRY42aJUa7XdaQnwgFC+4qCTvET5Mq MvGhqag7LsIOaPSUBwbkaotIbdABy2p+hjSyqwj7Umm/QWKFLvBrWIpX3MtXNxogp+p0 G/Gum3YkNRxYgxdwCV7mqULqMMe7Dq59cqlDSaIzI0f5WEjQtpvKb3OEQBRCxJddftVx /uoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=gsSTJJMQGoF1VdydFvMIc7Ax4WYxizviRTwkm81LCfU=; fh=qIKMPQ0WIlCOJ5tYFeKZn20/nitovp7T9NT4xv7Flp8=; b=Ddv5Cv9ziuMylxEKY3nksfXkQFmdgar96wjyTrZGd7gUOdj0RIhfr2rQWRyFoxG60i xZ9Ry0ZXvfSQzkSx6p6XBlbAY0Af8L2ank1FsMWsE2pHZg0yXiBKW5gw1Dg6df4m5Rtf KyGEvDryZDlsaxAHKEVtqMZKAtEjxvha+IsLLsN61G55a8cSurwkBaazwz8eENKiZ+bU rGrO7F+h360c8ZQmdqUnC0BBRTvFdsTjqdAHdtG+TjAjiCa+nb+R5tFIFTmHBf9iORTW uKKc2kRp+Ceux5MvdakWs8+0fEQpnFcnO+Ys1rr+N3FrI3AF50rdljeMHPu7RwPC/94x A3Kg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@media-io-com.20230601.gappssmtp.com header.s=20230601 header.b=WG6l7WDy; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=luminvent.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a80f41bc2fesi195692666b.910.2024.08.14.00.59.36; Wed, 14 Aug 2024 00:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@media-io-com.20230601.gappssmtp.com header.s=20230601 header.b=WG6l7WDy; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=luminvent.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8E14D68DADC; Wed, 14 Aug 2024 10:59:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 359C968DA9D for ; Wed, 14 Aug 2024 10:59:17 +0300 (EEST) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a7a843bef98so176042666b.2 for ; Wed, 14 Aug 2024 00:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=media-io-com.20230601.gappssmtp.com; s=20230601; t=1723622356; x=1724227156; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VYcNHF2F0xAtsGpQNCst1Hw/eon/kQrM7/+5bL4koLU=; b=WG6l7WDyzihEvGOh7NqHkOHEMRDG4xwsPO/4aZ3kOw3wmHefnyiWiD8NOok3UY1RpZ k/Whyqa1NDlixxd3ya+amMpNzamExoQmxrAMSmuNWP8YVlpWzkCQ1h2n3V/IX1vNgQlz jgVPLswtDKOcgLUnZyrp5JlsL7OEFLsEO1qjbYnC2FWQJhk9kbkcgfmJ6qidkccfEIvB EQWEMpqV4eC7OkHux+0s9PBZERBwXFSrXhru4GeyfCPDpDToRYnei2Wvc0o7hnzG+u6b 54h8AtNI3rCJBc9514HEsuOranxAe7eEPZO/li0mVP1IVo/O5UdtvephBash5reHlw5K S1Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723622356; x=1724227156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VYcNHF2F0xAtsGpQNCst1Hw/eon/kQrM7/+5bL4koLU=; b=QnRtCPwCyD5bcAxbBt61H9v+FzlW6m9R2JLkkh+BZMs7Slr0id2VdLOWciSLAj0ZMY dpZHXyAImS3piAd6hVgEW0aHqbRDmPQzamHibLy/XBOkFsij5iHmLHw/KDyCDYEUDAj4 aLfmfx5MbvooMoyIXwK6Uq6OeN10BIsGYjFczDA23TKLgpuoGOwnqTvq8aJ5mCCvvZAS WtTZShP1nNQJppCpXGxQd+V9UI5vzydn9NmOSnentX1v6MAjBBbwlGoKLzBf+3lv2Mvw hRHxp85+FFst7vvPoLsaFAlnV0jzhUHclqJIMdNQxpGnQ7Q//dYnERQWH4whEwf2mxX2 eQuA== X-Gm-Message-State: AOJu0Yx3N3ntuYmIyDwbPhIpFfeiiVNPt1VYibxfSco4NalyRvmOgoIT y8BUkAlhqp5wZakA5kH7l3NsfQT0uo9Nh3rtTEOjC/acQPqbgS4XejUiP4h+s9fM8BSxTaX10Yz wQGtbMg== X-Received: by 2002:a17:907:f194:b0:a7a:bae8:f299 with SMTP id a640c23a62f3a-a83670342d3mr123453666b.51.1723622355893; Wed, 14 Aug 2024 00:59:15 -0700 (PDT) Received: from MBPdeMacAntoine.numericable.fr.numericable.fr (154.217.245.213.rev.sfr.net. [213.245.217.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a80f3f45b8bsm143287866b.42.2024.08.14.00.59.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 14 Aug 2024 00:59:15 -0700 (PDT) From: Marc-Antoine Arnaud To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Aug 2024 09:59:08 +0200 Message-Id: <20240814075908.92916-2-marc-antoine.arnaud@luminvent.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240814075908.92916-1-marc-antoine.arnaud@luminvent.com> References: <20240814075908.92916-1-marc-antoine.arnaud@luminvent.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/mxf: stop parsing if index table is coherent 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 Cc: Marc-Antoine Arnaud Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 72yYrcXryuw2 sponsored by nxtedition --- libavformat/mxfdec.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index df958819300..83f9e5fc9e0 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -2063,6 +2063,52 @@ static int mxf_compute_ptses_fake_index(MXFContext *mxf, MXFIndexTable *index_ta return 0; } +static int mxf_validate_coherent_index_tables(MXFContext *mxf, int *is_coherent) { + int i, j, ret, nb_sorted_segments = 0; + MXFIndexTable *index_tables; + int nb_index_tables = 0; + int coherent_index_tables = 1; + MXFIndexTableSegment **sorted_segments = NULL; + + ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments); + + index_tables = av_calloc(nb_index_tables, sizeof(MXFIndexTable)); + if (!index_tables) { + av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate index tables\n"); + av_free(sorted_segments); + return AVERROR(ENOMEM); + } + + /* distribute sorted segments to index tables */ + for (i = j = 0; i < nb_sorted_segments; i++) { + if (i != 0 && sorted_segments[i-1]->index_sid != sorted_segments[i]->index_sid) { + /* next IndexSID */ + j++; + } + + index_tables[j].nb_segments++; + } + + for (i = j = 0; j < nb_index_tables; i += index_tables[j++].nb_segments) { + if (sorted_segments[i]->index_start_position) { + av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i starts at EditUnit %"PRId64" - seeking may not work as expected\n", + sorted_segments[i]->index_sid, sorted_segments[i]->index_start_position); + coherent_index_tables = 0; + } + } + + av_free(sorted_segments); + + if (ret == 0 && coherent_index_tables) { + *is_coherent = 1; + } else { + *is_coherent = 0; + } + + return 0; +} + + /** * Sorts and collects index table segments into index tables. * Also computes PTSes if possible. @@ -3752,6 +3798,16 @@ static int mxf_read_header(AVFormatContext *s) if (!essence_offset) essence_offset = klv.offset; + if (mxf->mxf_inspect_mode == 1) { + int ret_local, coherent_index_tables; + ret_local = mxf_validate_coherent_index_tables(mxf, &coherent_index_tables); + + // Break only if index table is coherent + if (ret_local == 0 && coherent_index_tables == 1) { + break; + } + } + /* seek to footer, previous partition or stop */ if (mxf_parse_handle_essence(mxf) <= 0) break;