[FFmpeg-cvslog] av_rescale: support passing MIN/MAX through

Michael Niedermayer git at videolan.org
Thu Jan 3 00:08:19 CET 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Jan  2 23:19:23 2013 +0100| [740e740895557a3b11715ccb203b7d882496046f] | committer: Michael Niedermayer

av_rescale: support passing MIN/MAX through

Reviewed-by: Clément Bœsch <ubitux at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=740e740895557a3b11715ccb203b7d882496046f
---

 libavutil/mathematics.c |    8 +++++++-
 libavutil/mathematics.h |    7 +++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index 6c2f6c0..f9cf87d 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -61,7 +61,13 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
     int64_t r=0;
     av_assert2(c > 0);
     av_assert2(b >=0);
-    av_assert2((unsigned)rnd<=5 && rnd!=4);
+    av_assert2((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4);
+
+    if (rnd & AV_ROUND_PASS_MINMAX) {
+        if (a == INT64_MIN || a == INT64_MAX)
+            return a;
+        rnd -= AV_ROUND_PASS_MINMAX;
+    }
 
     if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
 
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index 0021d52..479161e 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -70,6 +70,7 @@ enum AVRounding {
     AV_ROUND_DOWN     = 2, ///< Round toward -infinity.
     AV_ROUND_UP       = 3, ///< Round toward +infinity.
     AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
+    AV_ROUND_PASS_MINMAX = 8192, ///< Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE
 };
 
 /**
@@ -88,6 +89,9 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
 /**
  * Rescale a 64-bit integer with specified rounding.
  * A simple a*b/c isn't possible as it can overflow.
+ *
+ * @return rescaled value a or if AV_ROUND_PASS_MINMAX is set and a is
+ *         INT64_MIN or INT64_MAX than a is passed through unchanged.
  */
 int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
 
@@ -98,6 +102,9 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
 
 /**
  * Rescale a 64-bit integer by 2 rational numbers with specified rounding.
+ *
+ * @return rescaled value a or if AV_ROUND_PASS_MINMAX is set and a is
+ *         INT64_MIN or INT64_MAX than a is passed through unchanged.
  */
 int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
                          enum AVRounding) av_const;



More information about the ffmpeg-cvslog mailing list