From patchwork Mon Mar 7 22:15:39 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: 34634 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1905566nkx; Mon, 7 Mar 2022 14:16:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSdb6CSaX/lyll1jjhtUTPdwaLYKLIOUV8MrsBlzYjq5+VResp1g8jD0lCz5U0+ex5nkTV X-Received: by 2002:a50:e60f:0:b0:415:9509:32a2 with SMTP id y15-20020a50e60f000000b00415950932a2mr13053043edm.235.1646691411279; Mon, 07 Mar 2022 14:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646691411; cv=none; d=google.com; s=arc-20160816; b=pBz4it7YIp6iKYZ/+RRYS+s8kbsSyHdVh3b77pND+p+M9l4VuX5vCKaQJ3X85h4GrW 3xeHEgiDyY9JrN2CsJxbJC4pVZjbvhe0+umk6CXz8+FfljYIHY6Tnz7pEr9AQugMwtH8 H749LMzxrKaQw/oBY0WV1eizCpr9G+58Uugj9Brx3zR54Au2e/kmLGfYV19mzfLHTAD7 9nIlsM66Nx7kXv2UWKpQLmTYLtIehOFGJ9uUvJZqDiBXq087fkAkio16g8hfZOr+TUu8 zFoU9FXqjQYjpBUm2o22riPOMOffMy50dwq58nIrqiQkha2XnXeKjv6fK17znwN1y8SU yhQQ== 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=iVEBAtSCicEIyOD+IpZCCZUGSgTAEXajly20z8MNumc=; b=exxlpORNK/G5R9K8r2s7TYzuIOLVQz5RKWRM0HULy8Wrf72CJoHrNCToQNkmlrKEiY LZJmKTAfi9fgRm7VbbpFUhiUvBNvsOgwfh5e4bQwOdXMHz02SOhYEMU8aTY3G4gyqVrT 7WyNpkpZoEkho7VGO81oEeKD1Qcsk6hQS7HF3ygX1vnFQGrApc1du2GIG3jjV6z6d01m pHHM/oPcprBjEX4Qg5mDC8gMQfSiFVIlX4BJQ6Wf5iQ9/+q5bcVgyUFIzu3IGnM6GQBS YM2AdNaI47urzUoOK8VUiUhRG99WvS/GwW2ScBe3pGsvJDQhWF1Gu0rr72982dU4fRzQ JUVg== 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 k6-20020a170906054600b006a79e13f94esi8031733eja.294.2022.03.07.14.16.50; Mon, 07 Mar 2022 14:16:51 -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 4A17068B19F; Tue, 8 Mar 2022 00:16:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xVrmB6WMJfVo 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); +}