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 F1EA240EA8 for ; Fri, 11 Mar 2022 17:17:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 354B068B1BC; Fri, 11 Mar 2022 19:17:36 +0200 (EET) 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-Google-Smtp-Source: ABdhPJzSKpq0ebhU+dSUUYXrD7lwIYzm29AerS9xfMyKNwdlFsnyOmEVrGAiyvWuB9Su87FnD6zYJQ== 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 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. --- 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); +} -- 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".