From patchwork Fri Mar 11 17:16:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 34708 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp1887391nkb; Fri, 11 Mar 2022 09:17:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxidBWmIDGR/6rYnu6ecNbd4wTJGAnXV0zr/eTw6/X1DGEh6XM3aYWFIAk3suYxOCmmFo+u X-Received: by 2002:aa7:cb09:0:b0:413:2be4:c9fa with SMTP id s9-20020aa7cb09000000b004132be4c9famr9828353edt.106.1647019072237; Fri, 11 Mar 2022 09:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647019072; cv=none; d=google.com; s=arc-20160816; b=LlWPsKTHfTGdpoSCrAJA3T2wYb/urULyRsFUbWbHwNP2mRY6yuAOg7hzAXFVWYnbV+ 4b9wfpDGMdLaZRGWTAHYvTJ7m4UYOAyTYVsN9thDW+kteLTpjVUsYWtTOXxumbZ2IUwV 6CrsjtabUV5GKtImAdj8jaK0ho9kJ6ukEfB/Zw0QpyqhlbO+r+VEtAvfKXCLcHZjOpl+ OQzT9HYEaYs35AUO95ojriAsdvbTdpwBAqHc3BQ1SzCkmy0/FeB3fEAuFa6NhsL1Lg9S 0CLQcAxSXDfAnfAYHbZJ70e5JPIA0VWlq134wInDurb/66/sw1P5v/Mh5YYVlxDtFO2q /a8w== 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:delivered-to; bh=fgwoQcMuJXRW1xDaDoC403xdzJ/9zoi8mBVTsT36ozY=; b=lTnjpXOGYAJrYtVYKeTWvBO3EEhoj1OrvbQWI7u3rvDrl8lSeJTwTLDhdWnBPY7B4g QG9Pr7mYdy0iZiDEqQdXay3Ztx9V2N6raASzQc9pFhJMTj7hPRJ3LXK3vM3b/pbt6uIR uFLnA4R5WHwP6LqotTa38nwsXK6EvOnZVmF6Xqy3ERNklGrrR1c3cO2opZHlxykBLrLP a5zrEkcukYN8fdXlnuRHTkCDtSLxC34LBYG4hT4HVwirkcqtI2fmzVX5SjNlNVIPlnIa n226rMDXG5Pullv3r0VIe2Bwgw3g7EJ/gtQ5b28IVQxvbFqZP9hGwq/nLYCKTXUITajt pfjA== ARC-Authentication-Results: i=1; mx.google.com; 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 13-20020a170906058d00b006d13ca5ed5csi5396639ejn.997.2022.03.11.09.17.51; Fri, 11 Mar 2022 09:17:52 -0800 (PST) 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; 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 6894468B1C8; Fri, 11 Mar 2022 19:17:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5894668B1A5 for ; Fri, 11 Mar 2022 19:17:30 +0200 (EET) Received: by mail-pg1-f180.google.com with SMTP id 27so7948897pgk.10 for ; Fri, 11 Mar 2022 09:17:30 -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=gUcOGhzP9/CeuWzjsmQw5nFvwyBteALnaThn0x+j89o=; b=0sssZqQVJMjKyi+f1jUpqCqDCDlVIyDSClrkfFhj3BLysYP5BujqBtzHcZKsDelfvk xKTUzsLqMd29wkxBfx5CxgiAtKyZ95TaBCjKSH7NBeeBw7Y85BoAW3veKSZqK/23az+z Kd8/bkQ9AvCkDoLmeqpqNh/leoWBcdy9uN8HZCNwwlw1GIqu1XV77fX8kNk9l36j3oNR QrPcQy3yFP3/IGrPZo+qmFLkQSSTVRlaoJHgfr/e4ljb7StQMBb6lidGbUD56ODfGfJP rBdegQfALN5HsLpaSAR32a03hrsUmWlXOK9enLfQzCr+CFK5VP5fWWvgg13L/HdVP16Z 2Oow== X-Gm-Message-State: AOAM532ydi4tADcalzlbqj2UQwdI6PlQTvMmll/6HR1aHct1o84uOm54 Pzs4mjfAKWleIkEJpItsPhFo63+X6Lo= X-Received: by 2002:a65:63d9:0:b0:374:6b38:c6b3 with SMTP id n25-20020a6563d9000000b003746b38c6b3mr9336215pgv.195.1647019048004; Fri, 11 Mar 2022 09:17:28 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id s1-20020a056a00178100b004f731a1a952sm11978524pfg.168.2022.03.11.09.17.26 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Mar 2022 09:17:27 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Fri, 11 Mar 2022 09:17:23 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Mar 2022 09:16:50 -0800 Message-Id: <20220311171653.17420-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220311171653.17420-1-pal@sandflow.com> References: <20220311171653.17420-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/7] avformat/seek: add ff_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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aCzL1NxHwg/d From: Pierre-Anthony Lemieux Refactors a function used by avformat/concat and avformat/imf. --- libavformat/internal.h | 20 ++++++++++++++++++++ libavformat/seek.c | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/libavformat/internal.h b/libavformat/internal.h index f24c68703f..5529403a68 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -1023,4 +1023,24 @@ void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputForm */ int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size); +/** + * 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 ff_rescale_interval(AVRational tb_in, AVRational tb_out, + int64_t *min_ts, int64_t *ts, int64_t *max_ts); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/seek.c b/libavformat/seek.c index 405ca316b3..890aea7f8a 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -751,3 +751,13 @@ int avformat_flush(AVFormatContext *s) ff_read_frame_flush(s); return 0; } + +void ff_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); +}