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 4031D4CAF6 for ; Wed, 14 Aug 2024 07:59:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6242368DADA; Wed, 14 Aug 2024 10:59:23 +0300 (EEST) 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-Google-Smtp-Source: AGHT+IEPxGK6o+eP9DJVLbF+UBVshUyTYOO+17ZntROdFkBSgM3oNbtTfucJEpaXeJ0DSTd2/iPMPg== 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 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: 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; -- 2.39.3 (Apple Git-146) _______________________________________________ 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".