From patchwork Fri Mar 24 22:19:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 40814 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp4461pzb; Fri, 24 Mar 2023 15:19:47 -0700 (PDT) X-Google-Smtp-Source: AKy350beofyKnydaTB+QxBEVK2fUEByPuUziugIRTtxJKDYyIFPki0dMOhqamrpnmoB+u9PHJ9Su X-Received: by 2002:a17:906:519d:b0:939:5398:768e with SMTP id y29-20020a170906519d00b009395398768emr3247484ejk.7.1679696386790; Fri, 24 Mar 2023 15:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679696386; cv=none; d=google.com; s=arc-20160816; b=IAgdTqZsJMk6NmMAxPKxygpvJNzW6sKsOmbSLb6CGgDJmCrp/l6i/j3/Yph0108PID aTnS6g20MA5M9AY3/yOZRsK/zRaLOL0Xro3cFeW1SXgnk5UBMB/uzIGMCaHQv4qXIcnx PBsyWXPeO9hdqhgShPG03V3bHW4S70UcTu5rGH2bquFPAWCzeZc7PD/SjKZQETbcEUGI VPhNOPKNGo7+pxu5lKWr+P8eC7C4XZnn36bYqLXdDJgyeY7C8+awjM1QX+2wMI9GEgLT P3d8NBjJpLP3gV22X7ODndu4gREOQ6XfGNNJh2yOtt3hkuohJ6KZPehyO0jty1CIQOzX rJJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=qk/sB5W48W+1slKxry+NAwrAa27x/sLexe9zlOmaLu0=; b=ZqSqRIrzP4FsuoTHodQEbr1l8jTCDGrkSdte2yr1k993RjfjcMLf8xyOpKmWDQADfs WZvaDH98go93v1FmRBuE1zLED70hRwipy8DxpeGQjGvozuzRWbHOZxu2Gitk2LWByVkE zUbtGPlrhujmLdEtMz2TEWi3+Um+nhgPYC5OeDHxJV5owsnZv/ikUDX1wogbRu5KPxlx 7hvlfiPg+8HoXUG1e9wN2avY91jrcGiZDeve7iBeWsEMdXJGCaWv2XGDaSsXmrHuokpg 7u44+5sBJkbJurQ6bbPUyEvb6MYKH/kiX73+77oU7Go66OCLPoBjKAOdRqrq99dj1zbN SVnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=s2aSwJRw; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id lu10-20020a170906faca00b0092beffa3359si1019985ejb.14.2023.03.24.15.19.46; Fri, 24 Mar 2023 15:19:46 -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=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=s2aSwJRw; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C8A8468C8EA; Sat, 25 Mar 2023 00:19:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8DD5468C7CD for ; Sat, 25 Mar 2023 00:19:37 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id y15so4003860lfa.7 for ; Fri, 24 Mar 2023 15:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; t=1679696376; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DRZWO6MDfftx0aZyljEJxKxxfkofG6pgER3y4ov52Qg=; b=s2aSwJRwzpYge/PwebKwbd8RdfOw+zISifxbDuFSDwo7ECuxVjIbHLxyiD9sz0PPrm annZZAnsg66VFW+UpqSaVAf8Arza1r9DfVhchcp+Jk/Qx8TK64TBgJefXjdaBEiib1Y6 niL8Bq5I79hYSwxfI/6MBkbZARIwd1m+Oecofps28fupnhjA8RL13+pYI88nhoM2nrBm hzQLnQHQNE2A7ABn4y2cdVpVZX0Of4gzzlXyCIUxOKXcwzZciYbwfZnYinHaWvFEM3Ff avj+ByuC/X5jHnGY4zJ7fxJXovJ0rqebbaVT2F1X+auNwq74GRbD1yNqpduxzyunvlXP DC8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679696376; 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=DRZWO6MDfftx0aZyljEJxKxxfkofG6pgER3y4ov52Qg=; b=MNVzZdwcFBCZ6IT8X0QrUHbONII8e0yCge/OcMEo/PGtQO5ulsZRO/KR3+8MrlHoFu fj1Z4BID4/HOvWnqY2k9q0EPNunXn62oxehBSvUQbVjP+0459ggQFrZ6bIv0VuFyvbYC IdbSZdhnJkbsBsa8l7uFuCDxPK1W+qj1JqlblBRmqEqErhjlRjy2l1s5xyu+nMCC44VU 5WP9isjAPZoqapoj+ddNVtX0pJUbAYCMAze+ySOdjx0VS17WkVhAQDfdIUfVx583bJdo OxLCO0hsUXwELF4DWSOFq32srL/MIlZ+ChEl19lFoaOdfzns6Geelv0EgYPyCwEOUsBU NLyg== X-Gm-Message-State: AAQBX9d/ynL41G+O0yKdAh2bQzUYM8vt8SuWJBhFCBYOGdF/xAzh4ku9 2Sw2oblM3WP74iC7qVBuSqBn7mljJhsyyMjjWSCQqw== X-Received: by 2002:a19:a40a:0:b0:4eb:982:adf with SMTP id q10-20020a19a40a000000b004eb09820adfmr81lfc.26.1679696376330; Fri, 24 Mar 2023 15:19:36 -0700 (PDT) Received: from localhost (host-97-187.parnet.fi. [77.234.97.187]) by smtp.gmail.com with ESMTPSA id o13-20020ac2434d000000b004dc4c1e1e97sm3484721lfl.264.2023.03.24.15.19.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 24 Mar 2023 15:19:36 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Mar 2023 00:19:35 +0200 Message-Id: <20230324221935.48890-1-martin@martin.st> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] libavformat: Account for negative position differences in ff_configure_buffers_for_index 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: e4/x8zxMGdg3 When scanning through the index, account for the fact that the compared samples may be located in an unexpected order in the file; this function is mainly interested in the absolute difference between file locations. Signed-off-by: Martin Storsjö --- v3: Avoid mixed declarations and statements. --- libavformat/seek.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index 818549dfef..ec563cdd12 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -208,9 +208,11 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) for (; i2 < sti2->nb_index_entries; i2++) { const AVIndexEntry *const e2 = &sti2->index_entries[i2]; int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); + int64_t cur_delta; if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) continue; - pos_delta = FFMAX(pos_delta, e1->pos - e2->pos); + cur_delta = FFABS(e1->pos - e2->pos); + pos_delta = FFMAX(pos_delta, cur_delta); break; } }