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 82CCF402D9 for ; Mon, 21 Feb 2022 06:03:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C4A768AF1E; Mon, 21 Feb 2022 08:03:03 +0200 (EET) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C420468B0B8 for ; Mon, 21 Feb 2022 08:02:56 +0200 (EET) Received: by mail-pj1-f44.google.com with SMTP id v4so14195627pjh.2 for ; Sun, 20 Feb 2022 22:02:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p+jBEihliCU3ULiQwgU1G7R9hr0S5soLD9WYjFytmsw=; b=vvBGnHlq4qH1/Z9qvTotCIE85LSGpVBQbTuPanb51vXKjQZg12UYqSgWbpgoqc3HVx 4oxb2pvgLHshNVTCym3UMfvX1loY6wgPuJBovVTrFl35/RewZ+nS/BSg63lzQayaySAr rMytbr4m1HcQme7y2YWORlbNVIxu77EZr4P9CwYQqcNgPt4XerC+Eoxfh3dcx+bc8svu SjfRpPMpBJGh5NUQYbIUSToYjRFjvzKrWTZCcfmNLt0NYJ17vhxX1L9AfEzY2LhzIMre QY59EAZc1Qq808/mZERWBv4UFfChAYFQYazsWOjOJBulKpIdeQo2RWIhZ/fWtyRI5pQH 9a1w== X-Gm-Message-State: AOAM531H4+bGPSyu8n/tOnHPdH8OIRLYElDzQbamAvkMNv0AUVB/3rEa 1hiqKf+Q0wDYwtxm56vkEfhbuuVLV20= X-Google-Smtp-Source: ABdhPJxUDRwfixMLM8yjZN6vpYfKZmtznguj5H6v7glykJJY/sOkNNdBSGv6kmRpENq2oR5YQ5gH3Q== X-Received: by 2002:a17:903:292:b0:14e:e31c:b8c2 with SMTP id j18-20020a170903029200b0014ee31cb8c2mr17614692plr.153.1645423374831; Sun, 20 Feb 2022 22:02:54 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id ip8sm6151126pjb.6.2022.02.20.22.02.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Feb 2022 22:02:54 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sun, 20 Feb 2022 22:02:41 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Feb 2022 22:02:27 -0800 Message-Id: <20220221060230.6665-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220221060230.6665-1-pal@sandflow.com> References: <20220221060230.6665-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/7] avutil/mathematics: add av_rescale_interval() function 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: Pierre-Anthony Lemieux 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: From: Pierre-Anthony Lemieux Refactors a function used by avformat/concat and avformat/imf. --- libavutil/mathematics.c | 10 ++++++++++ libavutil/mathematics.h | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index f4e541fa24..2c7f57b950 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -212,3 +212,13 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i return av_sat_add64(av_rescale_q(old + 1, inc_tb, ts_tb), ts - old_ts); } } + +void av_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts) +{ + *ts = av_rescale_q (* ts, tb_in, tb_out); + *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, + AV_ROUND_UP | AV_ROUND_PASS_MINMAX); + *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, + AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX); +} diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h index 64d4137a60..eb8a3f4002 100644 --- a/libavutil/mathematics.h +++ b/libavutil/mathematics.h @@ -161,6 +161,27 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd) av_const; +/** + * Rescales a timestamp and the endpoints of an interval to which the temstamp + * belongs, from a timebase `tb_in` to a timebase `tb_out`. + * + * The upper (lower) bound of the output interval is rounded up (down) such that + * the output interval always falls within the intput interval. The timestamp is + * rounded to the nearest integer and halfway cases away from zero, and can + * therefore fall outside of the output interval. + * + * Useful to simplify the rescaling of the arguments of AVInputFormat::read_seek2() + * + * @param[in] tb_in Timebase of the input `min_ts`, `ts` and `max_ts` + * @param[in] tb_out Timebase of the ouput `min_ts`, `ts` and `max_ts` + * @param[in,out] min_ts Lower bound of the interval + * @param[in,out] ts Timestamp + * @param[in,out] max_ts Upper bound of the interval + */ +void av_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts); + + /** * Compare two timestamps each in its own time base. * -- 2.17.1 _______________________________________________ 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".