From patchwork Tue Mar 21 12:37:28 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: 40750 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp2546719pzb; Tue, 21 Mar 2023 05:37:40 -0700 (PDT) X-Google-Smtp-Source: AK7set9ceZLSPCMEFjk4PF56C+lhafqpp4fsmQBi/uMAScpiCxKKvj/comVeC51hYCJ3ZVsHDzpl X-Received: by 2002:aa7:dd44:0:b0:4fd:2346:7225 with SMTP id o4-20020aa7dd44000000b004fd23467225mr2727951edw.34.1679402259892; Tue, 21 Mar 2023 05:37:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679402259; cv=none; d=google.com; s=arc-20160816; b=MWj0tmF2DHrbxxqfo4ihohcj3kb/wUt+T283P5jLv1iPS1uahLoRZlKzFMxXqxqArB dsKnB0Z+eIEIoTJWJQz38X9N+TH0Jj8xqjWF1ZxnV/MUUVbrgmmkRdgW1t1yAV6elvPN 6vMj7dA9bvnp4046TDuF7OKgPYbf00dEwVhRmzxOfq4Tj6J7dwAdE3RC+rNZkFi7IUlP cuz4sKkFmAO87qUQW57XH8FKKSFovUFSFb50XQn/vPi9pT7+cQ/zDYoa9hYxcBoSGijp 6xZVq/9DSmK9tVyy7mlQyzgBgVNGwaR+r6n/yT9x8GCVMqgoTGFeVMbgjswIPP1UDFhn +SnA== 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=3yoI53Xa1v5bk/Ion4mTwOla2k9sYf8SkAYCDwFqJ3k=; b=qd+oN6z4pI5Y8q1s10wV+s3m3Y78zW4M37/7zV+b5+ojZiKPwXWFgo15XHxuNf1wFQ JhALDvMjgxIl93kjC9eP4cR87GlNgIk2VcM6CGW+/nAMuV7UGyApkrEiGSrhk3UJ0OlU dj9joSDSch9r2AsLi5YHWeOG/F/S9ObYNOPQnOY6KUR9YxTum9RUvt6tAq3L3gdDJsLC 6yNCKr/7XIWvEaS3lHASrHlEIKlWGpF26300qQgGtndFKgwqY8fo0gHs72g66J9iNh9z Nw7zDebCFTgACHMzVv39uKNkyeMZQIH/QmH2IBkoY3I6GPKyGosI8q0vdawPEdOOgOiD ITBQ== 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=HMql7FpG; 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 e9-20020a50fb89000000b004fe93335704si12761640edq.420.2023.03.21.05.37.39; Tue, 21 Mar 2023 05:37:39 -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=HMql7FpG; 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 1E5AA68C67D; Tue, 21 Mar 2023 14:37:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E38968C59C for ; Tue, 21 Mar 2023 14:37:31 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id g18so15348988ljl.3 for ; Tue, 21 Mar 2023 05:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; t=1679402250; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3G+En7D9shfO6h0uMykOlSJEndE05s1U4ugorJUedao=; b=HMql7FpGHwDPM7pRVFJmFR1ahRzrsubbm4Qhyv0OqcvneFdLsRTdhvF8qSvfz1EPJz xwPwolDVL8UHDRqgfvtjWx2rxi/I18xHhqzDXtrXxpkfGF29a2fkLR+AsCMJfWRNXf05 6GNygl8kGq3ojIQvT0o4L8m5C5gkXEAGRBpR8N7txlTRyoThOgkZrrq9cLpOA/DkrYd4 N2cNhFBuZQi8ON2l7H4CEZvKzG7BzTY/4+/Ezv57pQD3+0nWV6DKb/3al0G4K2dR50oh Z8MEBRCGGnJSjbbKBc2Prjo/gBrcWBPhHEMNoUxiyPHmsz0rQ5HwGQnUvL28BtBhF/Hq SLxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679402250; 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=3G+En7D9shfO6h0uMykOlSJEndE05s1U4ugorJUedao=; b=m3yNMsaCJD87LvS1Kk1aaYbwGK8bVUQbWQjHZYQH1cfTXxCt/x9dT+d4Lx1z/rhFeP dhXcddaew5vSMFXT0f1PTs/97M1V8j0/QHIqC2qg2F1snnTl1g6z5aK9tM9/4BSN3y54 4gK28YhOpA73cnpHPB8Hs8fIloGv6Z6MGT+ptODCzWOTMjnA/CqL2b712nUZavXJtyff w+dawnFxTHWbJU07Uxhmfyn0Hd0mTUBZJY/OHikiI+Kq7U3XC4SjVvgDdWsr6ne7CVI3 Kd83574ctgQ8TFEiJFY6UHJLoyHEBU6rMftB8+t2T4QaN6UrzXiBov5Wzk28ZOODoQ05 6NxQ== X-Gm-Message-State: AO0yUKUJAE8sf4lB96wgS9wfkeFpiWC0FylLb6R+mEPUMwRG5YF/IZPk 4VSweyHqoqQ74u96aKY4UxARz3GNKH4wl96Q48vcOg== X-Received: by 2002:a2e:b1d2:0:b0:29a:4a25:d961 with SMTP id e18-20020a2eb1d2000000b0029a4a25d961mr819399lja.45.1679402250583; Tue, 21 Mar 2023 05:37:30 -0700 (PDT) Received: from localhost (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id g14-20020a19ee0e000000b004dc4c5149dasm2145309lfb.301.2023.03.21.05.37.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Mar 2023 05:37:30 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Mar 2023 14:37:28 +0200 Message-Id: <20230321123729.74124-1-martin@martin.st> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YmIs2sIP1NAz 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 analysis showed a need for even larger buffer sizes (for a really badly interleaved file), over the sanity limits, we previously didn't increase the buffer sizes at all. Instead, if the file shows a need for really large buffers and short_seek_threshold, just set them to the maximum sanity limit; while it might not be enough for all cases in the file, it might be enough for most of it. 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ö --- libavformat/seek.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index a236e285c0..818549dfef 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -220,7 +220,8 @@ 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)) { + pos_delta = FFMIN(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 */ @@ -232,9 +233,8 @@ 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); - } + skip = FFMIN(skip, 1<<23); + ctx->short_seek_threshold = FFMAX(ctx->short_seek_threshold, skip); } int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)