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 1209F40B6B for ; Mon, 7 Mar 2022 22:16:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 149A368AFE9; Tue, 8 Mar 2022 00:16:24 +0200 (EET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B065268A7A1 for ; Tue, 8 Mar 2022 00:16:18 +0200 (EET) Received: by mail-pf1-f170.google.com with SMTP id t5so15650209pfg.4 for ; Mon, 07 Mar 2022 14:16:18 -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=gds4VZe5jtySS56ro4KaO92EQRdmEAgo3tCJoKwzewM=; b=qo/0JMTVxpy9DV6aJryNn2uZKVemzqyFp8l4yH9dCBmTQ1CEGjbOJycsTBXjBPSH7p NKfHfHjdaOuS2dWn4g0eSwqOLaGTi2vpRLvJjoFlhnpkcUCtLXLSX4YC/00MAn+/xTk2 8+LrTiwQsknwIRSZqJLpfN02JtE0GRQ8/CYrkYPVuYBJzL/QstI+5NqoZ+gcl9R84/z5 CEEE57G81Tbbb5e0tjIS0WkBMbFpEljL+1xGPX0Mtl16DCBczc6w4y5RuEb1N8RAzw43 kFdfdZJf5IO/rh4ywbJqYtvXdODx8CK2UPqu31/oyT9s14wUgVbX8QdPAo445Xmdxkpc VZlw== X-Gm-Message-State: AOAM533/Z3LEbjEXHSth40WCTBw9GgOsA9/DmWeERFTs9eWG3z/PZwKA 8VsKMo5dy/dArZMCkOjvDFZUVxDKV00= X-Google-Smtp-Source: ABdhPJxKvPxeWDtrlV/BGRbGlR+HiqKUklZx3IceM8thA67DpuGJFzHFEP4HXi/FMZoELFDnghIb2w== X-Received: by 2002:a63:6906:0:b0:36c:8493:dadf with SMTP id e6-20020a636906000000b0036c8493dadfmr11726643pgc.80.1646691376727; Mon, 07 Mar 2022 14:16:16 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id g12-20020a056a0023cc00b004f707cc97f9sm4421421pfc.52.2022.03.07.14.16.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 14:16:16 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Mon, 07 Mar 2022 14:15:52 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Mar 2022 14:15:39 -0800 Message-Id: <20220307221542.3265-4-pal@sandflow.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220307221542.3265-1-pal@sandflow.com> References: <20220307221542.3265-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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/avio_internal.h | 21 +++++++++++++++++++++ libavformat/seek.c | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index 1f5e3d474b..ef2ec7864f 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -23,6 +23,7 @@ #include "url.h" #include "libavutil/log.h" +#include "libavutil/rational.h" extern const AVClass ff_avio_class; @@ -281,4 +282,24 @@ int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp); int64_t ff_read_string_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp, int64_t max_len); +/** + * 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_AVIO_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".