summaryrefslogtreecommitdiff
path: root/libavutil/common.h
Commit message (Collapse)AuthorAge
* Remove obsolete version.h inclusionsAndreas Rheinhardt2022-02-24
| | | | | | | Forgotten in e7bd47e657bbf9e1ce9915e93bc80cb1a29fb7f3. Reviewed-by: Martin Storsjö <martin@martin.st> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* libavutil/common: clip nan value to aminMark Reid2021-11-15
| | | | | | | | | | | | Changes av_clipf to return amin if a is nan. Before if a is nan av_clipf_c returned nan and av_clipf_sse would return amax. Now the both should behave the same. This works because nan > amin is false. The max(nan, amin) will be amin. Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/common, macros: Move several macros from common.h to macros.hAndreas Rheinhardt2021-07-29
| | | | | | | | | | | | common.h currently contains several things: Math macros, UTF-8 macros, other fundamental macros; furthermore it also contains miscellaneous math functions and it (directly and indirectly) includes lots of other headers. This commit moves the "other fundamental macros" to macros.h which is a more fitting place. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/common: Move everything inside inclusion guardsAndreas Rheinhardt2021-02-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libavutil/common.h is a public header that provides generic math functions whereas libavutil/intmath.h is a private header that contains plattform-specific optimized versions of said math functions. common.h includes intmath.h (when building the FFmpeg libraries) so that the optimized versions are used for them. This interdependency sometimes causes trouble: intmath.h once contained an inlined ff_sqrt function that relied upon av_log2_16bit. In case there was no optimized logarithm available on this plattform, intmath.h needed to include common.h to get the generic implementation and this has been done after the optimized versions (if any) have been provided so that common.h used the optimized versions; it also needed to be done before ff_sqrt. Yet when intmath.h was included from common.h and if an ordinary inclusion guard was used by common.h, the #include "common.h" in intmath.h was a no-op and therefore av_log2_16bit was still unknown at the end of intmath.h (and also in ff_sqrt) if no optimized version was available. Before a955b5965825631986ba854d007d4e934e466c7d this was solved by duplicating the #ifndef av_log2_16bit check after the inclusion of common.h in intmath.h; said commit instead moved these checks to the end of common.h, outside the inclusion guards and made common.h include itself to get these unguarded defines. This is still the current state of affairs. Yet this is unnecessary since 9734b8ba56d05e970c353dfd5baafa43fdb08024 as said commit removed ff_sqrt as well as the #include "common.h" from intmath.h. Therefore this commit moves everything inside the inclusion guards and makes common.h not include itself. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* libavutil/common: Add FFABS64U()Michael Niedermayer2021-02-10
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Add FFABSU() for a signed -> unsigned ABSMichael Niedermayer2021-01-26
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Implement av_sat_add64_c() with fewer branchesMichael Niedermayer2020-10-24
| | | | | | | | No benchmark because this is not used in any speed relevant pathes nor is it used where __builtin_add_overflow is available. So I do not know how to realistically benchmark it. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Fix integer overflow in av_ceil_log2_c()Michael Niedermayer2020-06-30
| | | | | | | | Fixes: left shift of 1913647649 by 1 places cannot be represented in type 'int' Fixes: 23572/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMALOSSLESS_fuzzer-5082619795734528 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.Dale Curtis2020-05-27
| | | | | Signed-off-by: Dale Curtis <dalecurtis@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Add saturated add/sub operations for int64_t.Dale Curtis2020-05-15
| | | | | | | | | Many places are using their own custom code for handling overflow around timestamps or other int64_t values. There are enough of these now that having some common saturated math functions seems sound. Signed-off-by: Dale Curtis <dalecurtis@chromium.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: warn about possible move of the data pointer after the last 0 ↵Marton Balint2020-01-31
| | | | | | byte in GET_UTF8 Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/common: put ERROR statements into separate code blocks in GET_UTF8/16Marton Balint2020-01-31
| | | | | | To be able to safely use more than one statement in ERROR. Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/common: add parenthesis around GET_16BIT in GET_UTF16Marton Balint2020-01-31
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/common: use unsigned int in GET_UTF8Marton Balint2020-01-31
| | | | | | Right shift of signed value is implementation defined. Signed-off-by: Marton Balint <cus@passwd.hu>
* avutil/common: Fix underflow for ROUNDED_DIV with unsigned integerMengye Lv2019-10-06
| | | | | | | | | | | | When used ROUNDED_DIV(a,b), if a is unsigned integer zero, it's will lead to an underflow issue(it called unsigned integer wrapping). Fixes #8062 Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Mengye Lv <mengyelv@tencent.com> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avutil/common: Fix undefined shiftAndreas Rheinhardt2019-09-18
| | | | | | | | | av_mod_uintp2_c uses a bitwise AND with (1 << p) - 1 to clear the high bits of an unsigned int. But this is undefined if p == 31, because 1 is an int and 2^31 is not representable in an int. So make 1 unsigned. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Fix undefined behavior in av_clip_uintp2_c()Michael Niedermayer2018-06-15
| | | | | | | | Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself Fixes: 8521/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5639024952737792 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/common: Fix integer overflow in av_clip_uint8_c() and av_clip_uint16_c()Michael Niedermayer2018-02-17
| | | | | | | | Fixes: 5567/clusterfuzz-testcase-minimized-5769966247739392 Fixes: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* libavutil: Add saturating subtraction functionsAndrew D'Addesio2017-12-04
| | | | | | | | | Add av_sat_sub32 and av_sat_dsub32 as the subtraction analogues to av_sat_add32/av_sat_dadd32. Also clarify the formulas for dadd32/dsub32. Signed-off-by: Andrew D'Addesio <modchipv12@gmail.com>
* avutil: Rename FF_CEIL_COMPAT to AV_CEIL_COMPATDerek Buitenhuis2016-01-27
| | | | | | | | | | Libav, for some reason, merged this as a public API function. This will aid in future merges. A define is left for backwards compat, just in case some person used it, since it is in a public header. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* lavu: prevent overflow in av_clip_intp2_cAndreas Cadhalpun2016-01-15
| | | | | | | | This fixes ubsan runtime error: signed integer overflow: 8388608 + 2140274688 cannot be represented in type 'int' Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
* avutil/common: Protect GET_BYTE in GET_UTF8() by ()Michael Niedermayer2016-01-13
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavu: rename and move ff_parity to av_parityJames Almer2016-01-07
| | | | | | | av_popcount is not defined in intmath.h. Reviewed-by: ubitux Signed-off-by: James Almer <jamrial@gmail.com>
* lavu/common: add an explanation to FF_CEIL_RSHIFT()Clément Bœsch2016-01-07
|
* lavu/common: fix FF_CEIL_RSHIFT() range commentClément Bœsch2016-01-07
|
* Merge commit '50078c1c8070dd8d1c329e8117ff30ec72489039'Hendrik Leppkes2016-01-02
|\ | | | | | | | | | | | | * commit '50078c1c8070dd8d1c329e8117ff30ec72489039': libavutil: move FFALIGN macro from common.h to macros.h Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * libavutil: move FFALIGN macro from common.h to macros.hJanne Grunau2015-12-14
| | | | | | | | | | | | | | | | | | Include macros.h explicitly in common.h so that external code using FFALIGN does not break. It was already implicitly included through version.h. Include macros.h in lls.h and internal.h for FFALIGN. lls.h was including common.h only for FFALIGN and internal.h was missing the include for FFALIGN. `make checkheaders` did not catch it because it's an internal header.
* | avutil: Move av_rint64_clip_* to internal.hMichael Niedermayer2015-11-15
| | | | | | | | | | | | | | | | | | | | The function is renamed to ff_rint64_clip() This should avoid build failures on VS2012 Feel free to changes this to a different solution Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/common: add av_rint64_clipGanesh Ajjanagadde2015-11-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The rationale for this function is reflected in the documentation for it, and is copied here: Clip a double value into the long long amin-amax range. This function is needed because conversion of floating point to integers when it does not fit in the integer's representation does not necessarily saturate correctly (usually converted to a cvttsd2si on x86) which saturates numbers > INT64_MAX to INT64_MIN. The standard marks such conversions as undefined behavior, allowing this sort of mathematically bogus conversions. This provides a safe alternative that is slower obviously but assures safety and better mathematical behavior. API: @param a value to clip @param amin minimum value of the clip range @param amax maximum value of the clip range @return clipped value Note that a priori if one can guarantee from the calling side that the double is in range, it is safe to simply do an explicit/implicit cast, and that will be far faster. However, otherwise this function should be used. avutil minor version is bumped. Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* | avutil/common: add FFDIFFSIGN macroGanesh Ajjanagadde2015-11-03
| | | | | | | | | | | | | | | | | | | | | | This is of use for defining comparator callbacks. Common approaches like return x-y are not safe due to the risks of overflow. Furthermore, the (x > y) - (x < y) trick is optimized to branchless code. This also documents this macro accordingly. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* | Merge commit 'cdfe45ad371b7a8e6135b6c063b6b2a93152cb3a'Hendrik Leppkes2015-09-05
|\| | | | | | | | | | | | | * commit 'cdfe45ad371b7a8e6135b6c063b6b2a93152cb3a': lavu: Drop deprecated av_reverse function Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * lavu: Drop deprecated av_reverse functionVittorio Giovara2015-08-28
| | | | | | | | Deprecated in 10/2012.
* | avutil/common: Add FFNABS()Michael Niedermayer2015-09-03
| | | | | | | | | | | | | | This macro avoids the undefined corner case with the *_MIN values Previous version Reviewed-by: Ganesh Ajjanagadde <gajjanag@mit.edu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/common: Document FFABS() corner caseMichael Niedermayer2015-09-03
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | libavutil: add av_mod_uintp2James Almer2015-03-20
| | | | | | | | | | Reviewed-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: James Almer <jamrial@gmail.com>
* | avutil/common: minor simplification in av_clip_intp2_c()Michael Niedermayer2015-03-02
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/common: Fix integer overflow in av_clip_int8/16_cMichael Niedermayer2015-02-25
| | | | | | | | | | | | | | Fixes: signal_sigsegv_30420a5_2388_cov_1489993561_integra_lavf.mp4 Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'bf07d813f6c88b5a76980f321cf7272d799c4216'Michael Niedermayer2015-02-21
|\| | | | | | | | | | | | | * commit 'bf07d813f6c88b5a76980f321cf7272d799c4216': libavutil: Add av_clip_intp2 Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * libavutil: Add av_clip_intp2Peter Meerwald2015-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there already is a function, av_clip_uintp2() that clips a signed integer to an unsigned power-of-two range, i.e. 0,2^p-1 this patch adds a function av_clip_intp2() that clips a signed integer to a signed power-of-two range, i.e. -(2^p),(2^p-1) the new function can be used as a special case for av_clip(), e.g. av_clip(x, -8192, 8191) can be rewritten as av_clip_intp2(x, 13) there are ARM instructions, usat and ssat resp., which map nicely to these functions (see next patch) Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2013-11-24
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: Add missing #includes for *INT64_MAX and *INT64_C Conflicts: ffmpeg.c ffmpeg_filter.c ffplay.c libavformat/assdec.c libavformat/avidec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Add missing #includes for *INT64_MAX and *INT64_CDiego Biurrun2013-11-23
| |
| * Use the avstring.h locale-independent character type functionsReimar Döffinger2013-03-07
| | | | | | | | | | | | Make sure the behavior does not change with the locale. Signed-off-by: Martin Storsjö <martin@martin.st>
* | avutil/common: error out with clear message if __STDC_CONSTANT_MACROS is not ↵Michael Niedermayer2013-11-05
| | | | | | | | | | | | defined with c++ Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | lavu/common: add warning to GET_UTF8 doxyStefano Sabatini2013-10-04
| | | | | | | | Should prevent wrong uses, or at least decrease their chance.
* | libavutil: cast truncated values to uint32_tAlfred E. Heggestad2013-08-27
| | | | | | | | | | | | | | | | | | programs using ffmpeg that are compiled with -Wshorten-64-to-32 gives a warning when using header files common.h and rational.h cast 64-bit truncated values to (uint32_t) to avoid the warning Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | lavu/common: make FF_CEIL_RSHIFT faster when shift is constant.Clément Bœsch2013-05-13
| | | | | | | | | | See "[PATCH] lavfi/lut: use FF_CEIL_RSHIFT for chroma w/h rounding." thread for more information.
* | lavu: add FF_CEIL_RSHIFT and use it in various places.Clément Bœsch2013-05-09
| |
* | lavu: fix GET_UTF8 macro.Nicolas George2013-04-24
| | | | | | | | | | Prevent 0xFE and 0xFF from being considered the start of non-standard 7-bytes sequences. No noticeable effect on speed.
* | lavu: add av_clipd_cPaul B Mahol2013-04-18
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | Remove incorrect use of ctype.h functions.Reimar Döffinger2013-03-03
| | | | | | | | | | | | | | As far as I can tell the code should not change behaviour depending on locale in any of these places. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>