From patchwork Tue Mar 28 11:30:50 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: 40886 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp2096091pzh; Tue, 28 Mar 2023 04:31:04 -0700 (PDT) X-Google-Smtp-Source: AKy350aG0G896ul+lBjSSs7lNYl+shnjUxR5agEj8smSU5K9+NTCy/2z2hOZ0SWY/Mq711qlulWe X-Received: by 2002:aa7:cb92:0:b0:4fc:9a22:e0d2 with SMTP id r18-20020aa7cb92000000b004fc9a22e0d2mr13535850edt.14.1680003064215; Tue, 28 Mar 2023 04:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680003064; cv=none; d=google.com; s=arc-20160816; b=Fn9fxBDHzpoIB9DqE6bNY1EyNHG4Iwxay3qM5zZfmyLs6jnagGxNHrOefKNbAeuAU1 8LT6flHVQI21IRnSDT6ziS43OBbw8b1oarj0P51bYs9br8IMUiJnhb8eMuykObDX7W59 7TgHK4DTt5ZKPDZKOcC/P71drmp0LPM6hZJ/3nW/eqrVtyOxq7uQwvyoZBrGVxwpIc8p JCZbEIg+/xC7xcnBjxplwv+J8d4q026XrDzPBNRAom/LyNXwQluVnoQ693pYTApJfDKt yW6JuW87gblE46acfDpEaG2PVx7HK7nS+itJ987+09V6KLoKhoh6AO9pdohCpJLOHG0C 75FA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=oFr/5JmKzrFM0ySYBLt0dNwCqXFmGCN0ePfiCyY6BS0=; b=eTrMezNetQzdn1D0jK2JTQ2eUi3NOAHpo7GAj12gxyjx+W6RKST30FIYZaNXdiojMB JtqiWC2KoFIieJ7L6/uKolDeWPfbhS+xigIultmXRPfLNKJEjCU34PVGI+y7ufYWcq0g tt0CXd6LzPnF9ciRA+Aw5wwLXtwkedlODiHqzU2AhuIpmE5PB7OadcLRFFYBnid0fVwC wCnTZruMBKiUd/mtinxqQnHytJIK6V9DvWFs/uzRFkoRAeY1bhhkcxTFAgTMiZHZgybf YeJQ8St7EAsQN5TEsrawNERUPweqUTM7h1MpHiuQfoVMIHLKd1YlKuZIBz77MQshVw4B JkjA== 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=UdXQ4GA8; 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 b12-20020aa7df8c000000b00501e229b755si19881596edy.437.2023.03.28.04.31.03; Tue, 28 Mar 2023 04:31:04 -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=UdXQ4GA8; 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 09E5068C586; Tue, 28 Mar 2023 14:31:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CBF768C586 for ; Tue, 28 Mar 2023 14:30:53 +0300 (EEST) Received: by mail-lj1-f174.google.com with SMTP id a11so12150972lji.6 for ; Tue, 28 Mar 2023 04:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; t=1680003052; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tNhNEECKdvktKSJMG7Ilz9XzS2HVGl5Mj8KwN5dwBiY=; b=UdXQ4GA8yCA0w3co5GWHvw/eQzFXqqlgqlTwXtF4MbJ0s5zkwrXYe/TvETPpKqkxWw G55DoXdGLj/PJpnmTeD2g1I8qVIsdxImJo+6k/nxbKjaECcHj1di0dyhbzv25yEuDRvL +8+07nB9PUaEkLWhgAoKyfoeCQnY2LDw23SRxLKn4nor18sctt/e2nDIELw1gDP3ob2U 7aoeByR+O+5dFALe8Ic9+wIzuSEMtxwOBHR8llzlXYlrDpCBFTtGFyctHrPRmDy2kHeO IDdsDbAvKGYnOk8oA6dV8IfVBmjsOslkvsbJhMulySSMzpNevzqZfqJRgOGyLin9K/56 aSyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680003052; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tNhNEECKdvktKSJMG7Ilz9XzS2HVGl5Mj8KwN5dwBiY=; b=2+mvPnQb7MjhMK62J9bpFFH+u5p/wJ9dqOsQvSprv1gfQKeRMu02oBOz55bU4LgyfJ tgAbBpwJmVusaEybKxgm2i91YNfHa/Qki+2ZvjRK1G32/HegMNIOVpbZqa4jH/DmOXil oZcsPsrXqdWJ4gtptyOiOMYp0eJkgUjOsOHOapB2gVKxJq7W5ZN4tFIOXUhPLf25k05d FW475muPCuHCeloxwy6aje9Gjcd60ODh4CVlgYaJy8g9YWQCaGKgG3tnpQnodwJIRttJ X8AyJZQS3JfMlpPLmQnxWOOTTwwZtfKatVQAtGOt+W/aiODXPYHe7fTE3p57GPZsgkQ1 hpqQ== X-Gm-Message-State: AAQBX9eC6DdzxN4GOJja659/QRFVREGL8VQxkxQmN6w6du3yycpGZDos SSKoyAGju40TihIL0Fxfw0Ky9fOeKmH87tiOs4k4Zw== X-Received: by 2002:a05:651c:446:b0:29b:d51d:38f9 with SMTP id g6-20020a05651c044600b0029bd51d38f9mr5078062ljg.46.1680003052562; Tue, 28 Mar 2023 04:30:52 -0700 (PDT) Received: from localhost (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id g27-20020a2eb0db000000b002935a8d9351sm5033745ljl.55.2023.03.28.04.30.52 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Mar 2023 04:30:52 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Mar 2023 14:30:50 +0300 Message-Id: <20230328113051.3951-1-martin@martin.st> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCHv3 1/2] 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 Cc: Michael Niedermayer , Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 92AAU8wSlRqh 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. Reposting as part of the updated other patch, as it the previously posted v3 didn't get any comments. --- libavformat/seek.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index a236e285c0..faa47f961f 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; } } From patchwork Tue Mar 28 11:30:51 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: 40887 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp2096224pzh; Tue, 28 Mar 2023 04:31:14 -0700 (PDT) X-Google-Smtp-Source: AKy350bJscOiXM99lpaS+ncG0IjjPGZw10XiQmRXBrsLm3aKLW3/1/WhxQQQ/+fMpUKhYMuOHEyH X-Received: by 2002:a05:6402:15a:b0:4f9:deb4:b984 with SMTP id s26-20020a056402015a00b004f9deb4b984mr15744854edu.9.1680003074092; Tue, 28 Mar 2023 04:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680003074; cv=none; d=google.com; s=arc-20160816; b=UxCwjfjGLFufdLf6bnIS8cKkbwhZOxCzTLl6336t5B+KcS+eea5dZs4Gh59sOyaeql Elo3+iUiQHgh91k840bTdDU8FdWFhfaBGJeAlzx5fT9oEOVeXlRAEiez+1cV+8vWIHJy WTzIUdZ3NRvN+kr7bn/keiESjYBF0NGnP/tKY1gSJUpQ68qT5lEnSxYhctvf0meeQYI4 CSmnv9eyKNavOKJlmTAB2lIuataDQQWnvCZg7UeGRL/yRTfmruRE9TkrNWhkcERxlksU jO7rKfL3Jo1fmXGhFhyJh32T2NWyods0cnkvBSSOZowBFJgjTYOl6GfGWbakvIh+cqfv YP9Q== 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=0Y27oem8c4sI+r1PMx/TJDx2d7OT/dsz5heHNiIn1do=; b=WY7YD/+yX4dl9zyY1tUr1Csj/n9LNaQNMEDZlUROE6FnNWX47uuO/jNCLsWGeuDX6d dxQJ2+DFNsqmi+OCoqUUtJuoJDZBIeUhlred5+LWQ3PjQEzwyPVssgPhDoSXofZ/K+yh X/jAq1VMqJbqrt+YNyN+dRReX59p3zK4JuxG94CGlt/m4d6s+7gcA9gKUQ1Q4vrE7TxU Pm3tC0WqlJy9LmKrrkucwjqdiCl6IjzoOhidpPI+vQKgA0UGHEzQfLoVUNqvrKtKO4FA JxPjgzGbSJN+bAfEHFt6Q56E7s2ZxRDSPa9c/NadL9ifLUbxwp4XDZk130M9UPsAIliK /U9A== 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=sneRvUm5; 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 r21-20020aa7da15000000b004fd2b07230esi29143026eds.64.2023.03.28.04.31.13; Tue, 28 Mar 2023 04:31:14 -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=sneRvUm5; 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 15B4A68CB31; Tue, 28 Mar 2023 14:31:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1B7168C312 for ; Tue, 28 Mar 2023 14:30:53 +0300 (EEST) Received: by mail-lj1-f182.google.com with SMTP id e21so12158635ljn.7 for ; Tue, 28 Mar 2023 04:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; t=1680003053; 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=LVoblLr9aNFk1CTG60kuB3OlrjyCsXz20Xy7fBAGDyw=; b=sneRvUm5/zcJiBdqpSff9qn5v2MLtVETjdosACbK69ErZNmtV+vyI4UhcL7roHLjiR HPrMH9EZosJPppN2PvBAL2nOu7BbZ/9K+6Tmr2xzGzptwu2AjVu5/0oNUrhGJedIGzR0 K1X7tSVcXeeMDgDI3xMA4Qz85CRP66rUSoQFdqYn559Vx5o0m9tv62SbjiRS4Nrc9byD GObQ+pgUuX+QsRhgIJuy9g/Y3hyWyoojDvA6K7OigIKWo6u69cA5DHP8uQ0hktYJ4aNh 1pVGg/CdFnkLnrY7ru4CqzEY8W4FKnVA+UNTFLEr+HCAqkVYBqySieIRAgDYACpXNfah /eYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680003053; 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=LVoblLr9aNFk1CTG60kuB3OlrjyCsXz20Xy7fBAGDyw=; b=BNQP9u+jbSEatGRsJ5fOWzmGjssJh9QB26Z9pDZF7Mx3sJB/cDZ6GY0CllUApnnqOa /8syIwzicGoTpbhPOHwwEejttCt6/vGUmYWpQyWGh3hEWIxXhTNkiJmkVsBC35KODFda rFq+5eyaPCJ4y2FRyF+FIZ5Lo40PSvmjGBZIu8cx6sQJDb267xeEQ+ppGKHyjcjFdYmj zFBu57m0/D3RoJiBCVMQPwG0IjLFDSPbs/nEK8+xtw8fki3qB3kTDToUS+ohnROVdMAv dV6GN6QgAnTnlmgUgHye8TWiuwK8yxX8gjjJJqbxpUHetbJdI1wi7UjUqSJdJN7Ljotl NdWQ== X-Gm-Message-State: AAQBX9dxL3DvYzD9mQorMODkVqGrt5Ym5qDKExGLmvXN1sT+ZuUj6qma FdSoFgI5oN8GUW/u9Ns0P0leVWxxb7lzGzBR9ksJeg== X-Received: by 2002:a2e:7812:0:b0:29c:9739:bc24 with SMTP id t18-20020a2e7812000000b0029c9739bc24mr4933153ljc.39.1680003053191; Tue, 28 Mar 2023 04:30:53 -0700 (PDT) Received: from localhost (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id f13-20020a2e918d000000b0029c13f4d526sm4116937ljg.79.2023.03.28.04.30.52 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Mar 2023 04:30:52 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Mar 2023 14:30:51 +0300 Message-Id: <20230328113051.3951-2-martin@martin.st> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230328113051.3951-1-martin@martin.st> References: <20230328113051.3951-1-martin@martin.st> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCHv2 2/2] libavformat: Improve ff_configure_buffers_for_index for excessive deltas 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: Michael Niedermayer , Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QyTUM6oEPN4f Previously, the ff_configure_buffers_for_index function had upper sanity limits of 16 MB (1<<24) for buffer_size and 8 MB (1<<23) for short_seek_threshold. However, if the index contained entries with a much larger delta, setting pos_delta to a value larger than the sanity limit, we would end up not increasing the buffer size at all. Instead, ignore the individual deltas that are excessive, but increase the buffer size based on the deltas that are below the sanity limit. Only count deltas that are below 1<<23, 8 MB; pos_delta gets doubled before setting the buffer size - this matches the previous maximum buffer size of 1<<24, 16 MB. This can happen e.g. with a mov file with some tracks containing some samples that belong in the start of the file, at the end of the mdat, while the rest of the file is mostly reasonably interleaved; previously those samples caused the maximum pos_delta to skyrocket, skipping any buffer size enlargement. Signed-off-by: Martin Storsjö --- v2: Ignore entries that are out of range instead of clipping to the maximum allowed. --- libavformat/seek.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index faa47f961f..386312cd3a 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -204,7 +204,9 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) const AVIndexEntry *const e1 = &sti1->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); - skip = FFMAX(skip, e1->size); + if (e1->size < (1 << 23)) + skip = FFMAX(skip, e1->size); + 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); @@ -212,7 +214,8 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) continue; cur_delta = FFABS(e1->pos - e2->pos); - pos_delta = FFMAX(pos_delta, cur_delta); + if (cur_delta < (1 << 23)) + pos_delta = FFMAX(pos_delta, cur_delta); break; } } @@ -222,7 +225,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) pos_delta *= 2; ctx = ffiocontext(s->pb); /* XXX This could be adjusted depending on protocol*/ - if (s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) { + if (s->pb->buffer_size < pos_delta) { av_log(s, AV_LOG_VERBOSE, "Reconfiguring buffers to size %"PRId64"\n", pos_delta); /* realloc the buffer and the original data will be retained */ @@ -234,9 +237,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, pos_delta/2); } - if (skip < (1<<23)) { - ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, skip); - } + ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, skip); } int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)