Commit Graph

4066 Commits

Author SHA1 Message Date
Timothy Gu 44304ae322 all: Add missing header guards 2016-01-28 19:49:48 -08:00
James Almer b624f0660b x86: Add ymm_reg struct
Needed to declare 32-byte long constants

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2016-01-28 00:41:19 +01:00
Derek Buitenhuis 21f9468402 avutil: Rename FF_CEIL_COMPAT to AV_CEIL_COMPAT
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>
2016-01-27 16:36:46 +00:00
Michael Niedermayer f3ace85d88 avutil/opt: check for and handle errors in av_opt_set_dict2()
Previously errors could result in random entries to be lost.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-26 17:36:08 +01:00
Hendrik Leppkes c2869b4640 avutil: add P010 pixel format
P010 is the 10-bit variant of NV12 (planar luma, packed chroma), using two
bytes per component to store 10-bit data plus 6-bit zeroes in the LSBs.
2016-01-26 11:54:01 +01:00
Vittorio Giovara 6695f178a5 pixdesc: Use AV_CEIL_RSHIFT in documentation 2016-01-25 12:02:20 -05:00
Vittorio Giovara 1546a41ada pixdesc: Drop unneeded deprecation warning guards 2016-01-25 12:01:12 -05:00
Geza Lore cc602061ee x86inc: Add debug symbols indicating sizes of compiled functions
Some debuggers/profilers use this metadata to determine which function a
given instruction is in; without it they get can confused by local labels
(if you haven't stripped those). On the other hand, some tools are still
confused even with this metadata. e.g. this fixes `gdb`, but not `perf`.

Currently only implemented for ELF.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:46:28 +01:00
Henrik Gramner 002c47798d x86inc: Avoid creating unnecessary local labels
The REP_RET workaround is only needed on old AMD cpus, and the labels clutter
up the symbol table and confuse debugging/profiling tools, so use EQU to
create SHN_ABS symbols instead of creating local labels. Furthermore, skip
the workaround completely in functions that definitely won't run on such cpus.

Note that EQU is just creating a local label when using nasm instead of yasm.
This is probably a bug, but at least it doesn't break anything.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:44:25 +01:00
Henrik Gramner fd6ecac38e x86inc: Simplify AUTO_REP_RET
cpuflags is never undefined any more, it's set to 0 instead.

Also fix an incorrect comment.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:43:39 +01:00
Henrik Gramner 5ca8e195e5 x86inc: Use more consistent indentation
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:42:59 +01:00
Henrik Gramner 91ed050f42 x86inc: Preserve arguments when allocating stack space
When allocating stack space with a larger alignment than the known stack
alignment a temporary register is used for storing the stack pointer.
Ensure that this isn't one of the registers used for passing arguments.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:41:59 +01:00
Henrik Gramner 715eb7ca24 x86inc: Improve FMA instruction handling
* Correctly handle FMA instructions with memory operands.
 * Print a warning if FMA instructions are used without the correct cpuflag.
 * Simplify the instantiation code.
 * Clarify documentation.

Only the last operand in FMA3 instructions can be a memory operand. When
converting FMA4 instructions to FMA3 instructions we can utilize the fact
that multiply is a commutative operation and reorder operands if necessary
to ensure that a memory operand is used only as the last operand.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:30:30 +01:00
Henrik Gramner f60f06d989 x86inc: Be more verbose in assertion failures
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:30:07 +01:00
Henrik Gramner 7adcd4e841 x86inc: Make cpuflag() and notcpuflag() return 0 or 1
Makes it possible to use them in arithmetic expressions.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-23 20:19:19 +01:00
Anton Khirnov d336bfcf69 pixdesc: fix and extend doxy for av_pix_fmt_get_chroma_sub_sample()
The parameters in the docs are currently swapped.
2016-01-23 20:16:42 +01:00
Neil Birkbeck 17399f6a9f Add missing conversions from side data enum to name
Add names for recently added enums to av_frame_side_data_name.

Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-22 01:58:59 +01:00
Geza Lore d39c229e54 x86inc: Add debug symbols indicating sizes of compiled functions
Some debuggers/profilers use this metadata to determine which function a
given instruction is in; without it they get can confused by local labels
(if you haven't stripped those). On the other hand, some tools are still
confused even with this metadata. e.g. this fixes `gdb`, but not `perf`.

Currently only implemented for ELF.
2016-01-21 23:19:46 +01:00
Henrik Gramner d3662777e0 x86inc: Avoid creating unnecessary local labels
The REP_RET workaround is only needed on old AMD cpus, and the labels clutter
up the symbol table and confuse debugging/profiling tools, so use EQU to
create SHN_ABS symbols instead of creating local labels. Furthermore, skip
the workaround completely in functions that definitely won't run on such cpus.

Note that EQU is just creating a local label when using nasm instead of yasm.
This is probably a bug, but at least it doesn't break anything.
2016-01-21 23:19:46 +01:00
Henrik Gramner 87b587d4fe x86inc: Simplify AUTO_REP_RET
cpuflags is never undefined any more, it's set to 0 instead.

Also fix an incorrect comment.
2016-01-21 23:19:46 +01:00
Henrik Gramner 2d60b18cf0 x86inc: Use more consistent indentation 2016-01-21 23:19:46 +01:00
Henrik Gramner dfe771dc5a x86inc: Preserve arguments when allocating stack space
When allocating stack space with a larger alignment than the known stack
alignment a temporary register is used for storing the stack pointer.
Ensure that this isn't one of the registers used for passing arguments.
2016-01-21 23:19:46 +01:00
Henrik Gramner b1496008ee x86inc: Improve FMA instruction handling
* Correctly handle FMA instructions with memory operands.
 * Print a warning if FMA instructions are used without the correct cpuflag.
 * Simplify the instantiation code.
 * Clarify documentation.

Only the last operand in FMA3 instructions can be a memory operand. When
converting FMA4 instructions to FMA3 instructions we can utilize the fact
that multiply is a commutative operation and reorder operands if necessary
to ensure that a memory operand is used only as the last operand.
2016-01-21 23:19:46 +01:00
Henrik Gramner 6cbd0fdf28 x86inc: Be more verbose in assertion failures 2016-01-21 23:19:46 +01:00
James Almer a2e1b66460 x86/intmath: disable sse av_clip functions when using ICC
It seems to miscompile them

Should fix fate-ra-288 and fate-twinvq

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-21 16:50:51 -03:00
Clément Bœsch d96f0fbe59 lavu: add pthread asserts if ASSERT_LEVEL>1 2016-01-20 21:08:50 +01:00
Neil Birkbeck d91718107c libavutil: add mastering display metadata sidedata
Adding mastering display metadata struct to avutil. The mastering display metadata contains information
about the mastering display color volume (SMPTE 2086:2014).

This info comes from HEVC in the SEI_TYPE_MASTERING_DISPLAY_INFO and is soon to be included in MKV:
https://mailarchive.ietf.org/arch/search/?email_list=cellar&gbt=1&index=sZyfPTM-QY69P-0omfOIiTN622o
so it is similar to SEI FPA / stereo_mode in MKV and as such this patch follows how AVStereo3D is implemented.

I'll add support to HEVC in a follow-up (and MKV when spec is approved).

Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-19 16:43:31 +01:00
Hendrik Leppkes a04a9434b5 Merge commit '73c8c0341cce9e1a6c4169721f5123f97fc4be2f'
* commit '73c8c0341cce9e1a6c4169721f5123f97fc4be2f':
  arm: Fix vfp dead code elimination with have_vfp_vm

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-19 08:51:12 +01:00
James Almer dee579ffcd x86/fixed_dsp: add ff_butterflies_fixed_sse2
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-16 21:09:38 -03:00
Ganesh Ajjanagadde 5989add4ab lavu/x86/lls: add fma3 optimizations for update_lls
This improves accuracy (very slightly) and speed for processors having
fma3.

Sample benchmark (fate flac-16-lpc-cholesky, Haswell):
old:
5993610 decicycles in ff_lpc_calc_coefs,      64 runs,      0 skips
5951528 decicycles in ff_lpc_calc_coefs,     128 runs,      0 skips

new:
5252410 decicycles in ff_lpc_calc_coefs,      64 runs,      0 skips
5232869 decicycles in ff_lpc_calc_coefs,     128 runs,      0 skips

Tested with FATE and --disable-fma3, also examined contents of
lavu/lls-test.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Henrik Gramner <henrik@gramner.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2016-01-15 16:46:13 -05:00
James Almer 36778627e2 x86/intmath: add missing early clobber to output operands
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-15 13:32:58 -03:00
Andreas Cadhalpun f8bc0137bd lavu: prevent overflow in av_clip_intp2_c
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>
2016-01-15 00:32:54 +01:00
Ganesh Ajjanagadde a0a47a09b0 lavu/libm: add isfinite fallback
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2016-01-13 20:00:19 -05:00
Michael Niedermayer 9ca64c31d2 avutil/common: Protect GET_BYTE in GET_UTF8() by ()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-13 03:09:08 +01:00
Timothy Gu d64d6edfc7 Correct two build/built typos
Found-by: Leo Izen <leo.izen@gmail.com> as thebombzen on IRC
Signed-off-by: Timothy Gu <timothygu99@gmail.com>
2016-01-11 20:53:11 -08:00
Clément Bœsch e8bc642202 lavu: add AV_CEIL_RSHIFT and use it in various places
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-01-11 15:32:56 -05:00
Martin Storsjö 73c8c0341c arm: Fix vfp dead code elimination with have_vfp_vm
This fixes builds with --disable-vfp.

Checking for the armv6 cpu flag is incorrect, since vfpv2 isn't
armv6 specific.

Signed-off-by: Martin Storsjö <martin@martin.st>
2016-01-08 23:52:59 +02:00
James Almer dc79824deb x86/float_dsp: zero extend offset from ff_scalarproduct_float_sse
Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:32 -03:00
James Almer 4ee38ed7f9 x86/float_dsp: zero extend len from ff_butterflies_float_sse implicitly
Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:27 -03:00
James Almer 7f520524f6 x86/float_dsp: remove len check from ff_butterflies_float_sse
The function documentation explicitly mentions it needs to be a multiple of 4.

Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:24 -03:00
James Almer 28d5a3a74a lavu: rename and move ff_parity to av_parity
av_popcount is not defined in intmath.h.

Reviewed-by: ubitux
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-07 20:04:24 -03:00
Clément Bœsch 2ce29d1765 lavu: add ff_parity() 2016-01-07 22:51:31 +01:00
Clément Bœsch 04826b7ff0 lavu/common: add an explanation to FF_CEIL_RSHIFT() 2016-01-07 22:34:04 +01:00
Clément Bœsch 84a967df03 lavu/common: fix FF_CEIL_RSHIFT() range comment 2016-01-07 22:20:22 +01:00
James Almer f4c1a48483 x86/intmath: add sse optimized av_clipf and av_clipd
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-07 14:24:01 -03:00
Hendrik Leppkes 957667d198 avutil/cpu: add missing entry for vfp_vm to av_parse_cpu_caps 2016-01-02 19:07:08 +01:00
Hendrik Leppkes e754c8e8ca Merge commit 'e2710e790c09e49e86baa58c6063af0097cc8cb0'
* commit 'e2710e790c09e49e86baa58c6063af0097cc8cb0':
  arm: add a cpu flag for the VFPv2 vector mode

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 11:01:29 +01:00
Hendrik Leppkes af2e6f3215 Merge commit '64034849dad8410bedbe1def4c533490fb85cc4a'
* commit '64034849dad8410bedbe1def4c533490fb85cc4a':
  arm64: add cycle counter support

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 10:26:42 +01:00
Hendrik Leppkes 4cf66a8193 Merge commit '50078c1c8070dd8d1c329e8117ff30ec72489039'
* commit '50078c1c8070dd8d1c329e8117ff30ec72489039':
  libavutil: move FFALIGN macro from common.h to macros.h

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 10:25:12 +01:00
Ganesh Ajjanagadde 0e9fe3e3c9 lavu/eval: replace pow(10,x) by ff_exp10(x)
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:48:13 -08:00
Ganesh Ajjanagadde 11388b5a8f lavu/internal: add ff_exp10
Fast, reasonably accurate 10^x. Alternative of detection of libm exp10 at configure
time is not worth the trouble, since it is anyway not POSIX or ISO C,
and currently only the GNU libm has it. Furthermore, GNU libm's variant
is ~ 2x slower, and is ironically not correctly rounded (2 ulp off) to justify all
that slowdown.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:12:49 -08:00
Ganesh Ajjanagadde 73616b1f21 lavu/libm,configure: remove exp10, exp10f detection
Subsequent commit introduces ff_exp10 instead.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:12:49 -08:00
Ganesh Ajjanagadde 5630ed5be6 lavu/libm: misc, minor changes
Addition of comments marking the end of ifdef blocks, correction of an
incorrect (at double precision) M_LN2, removal of an unnecessary undef.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 09:25:20 -08:00
Ganesh Ajjanagadde e29db08cf7 lavu/libm: add exp10 support
exp10 is a function available in GNU libm. Looks like no other common
libm has it. This adds support for it to FFmpeg.

There are essentially 2 ways of handling the fallback:
1. Using pow(10, x)
2. Using exp2(M_LOG2_10 * x).

First one represents a Pareto improvement, with no speed or accuracy
regression anywhere, but speed improvement limited to GNU libm.

Second one represents a slight accuracy loss (relative error ~ 1e-13)
for non GNU libm. Speedup of > 2x is obtained on non GNU libm platforms,
~30% on GNU libm. These are "average case numbers", another benefit is
the lack of triggering of the well-known terrible worst case paths
through pow.

Based on reviews, second one chosen. Comment added accordingly.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-23 09:22:59 -08:00
Ganesh Ajjanagadde dd68cde28a lavu/libm: add erf hack and make dynaudnorm available everywhere
Source code is from Boost:
http://www.boost.org/doc/libs/1_46_1/boost/math/special_functions/erf.hpp
with appropriate modifications for FFmpeg.

Tested on interval -6 to 6 (beyond which it saturates), +/-NAN, +/-INFINITY
under -fsanitize=undefined on clang to test for possible undefined behavior.

This function turns out to actually be essentially as accurate and faster than the
libm (GNU/BSD's/Mac OS X), and I can think of 3 reasons why upstream
does not use this:
1. They are not aware of it.
2. They are concerned about licensing - this applies especially to GNU
libm.
3. They do not know and/or appreciate the benefits of rational
approximations over polynomial approximations. Boost uses them to great
effect, see e.g swr/resample for bessel derived from them, which is also
similarly superior to libm variants.

First, performance.
sample benchmark (clang -O3, Haswell, GNU/Linux):

3e8 values evenly spaced from 0 to 6
time (libm):
./test  13.39s user 0.00s system 100% cpu 13.376 total
time (boost based):
./test  9.20s user 0.00s system 100% cpu 9.190 total

Second, accuracy.
1e8 eval pts from 0 to 6
maxdiff (absolute): 2.2204460492503131e-16
occuring at point where libm erf is correctly rounded, this is not.

Illustration of superior rounding of this function:
arg   : 0.83999999999999997
erf   : 0.76514271145499457
boost : 0.76514271145499446
real  : 0.76514271145499446

i.e libm is actually incorrectly rounded. Note that this is clear from:
https://github.com/JuliaLang/openlibm/blob/master/src/s_erf.c (the Sun
implementation used by both BSD and GNU libm's), where only 1 ulp is
guaranteed.

Reasons it is not easy/worthwhile to create a "correctly rounded"
variant of this function (i.e 0.5ulp):
1. Upstream libm's don't do it anyway, so we can't guarantee this unless
we force this implementation on all platforms. This is not easy, as the
linker would complain unless measures are taken.
2. Nothing in FFmpeg cares or can care about such things, due to the
above and FFmpeg's nature.
3. Creating a correctly rounded function will in practice need some use of long
double/fma. long double, although C89/C90, unfortunately has problems on
ppc. This needs fixing of toolchain flags/configure. In any case this
will be slower for miniscule gain.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-21 09:03:11 -08:00
Ganesh Ajjanagadde 062e3e2382 lavu/libm: add copysign hack
For systems with broken libms.
Tested with NAN, -NAN, INFINITY, -INFINITY, +/-x for regular double x and
combinations of these.

Old versions of MSVC need some UINT64_C hackery.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-19 14:05:49 -08:00
Ganesh Ajjanagadde 0dd8a3d71e lavu/intmath: add faster clz support
This should be useful for the sofalizer filter.

Reviewed-by: Kieran Kunhya <kierank@ob-encoder.com>
Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-19 09:35:34 -08:00
Marton Balint 752ab408b4 lavu/error: add missing error messages for errors supported on all platforms
We need these if we have no strerror_r.

Descriptions are taken from doc/errno.txt except for ENOMEM.

Signed-off-by: Marton Balint <cus@passwd.hu>
2015-12-18 04:04:14 +01:00
Ganesh Ajjanagadde 39f8c7961d lavu/random_seed: use arc4random() when available
arc4random() was designed as a superior interface for system random
number generation, designed for OpenBSD and subsequently incorporated by
other BSD's, Mac OS X, and some non-standard libc's. It is thus an improvement to
use it whenever available.

As a side note, this may or may not get included in glibc, and there is
a proposal to create a posix_random family based on these ideas:
http://austingroupbugs.net/view.php?id=859.

Tested on Mac OS X.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-17 08:12:41 -08:00
Ganesh Ajjanagadde 4fa6f09c2c lavu/eval: remove pow and exp2 for postfixes
These postfixes can be computed statically, and there is no need to
waste runtime resources.

Tested with FATE.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-16 07:56:54 -05:00
erankor 23ac99dc17 libavutil: add aes-ctr support
for supporting mp4 cenc encoding/decoding

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-15 14:16:28 +01:00
Janne Grunau e2710e790c arm: add a cpu flag for the VFPv2 vector mode
The vector mode was deprecated in ARMv7-A/VFPv3 and various cpu
implementations do not support it in hardware. Vector mode code will
depending the OS either be emulated in software or result in an illegal
instruction on cpus which does not support it. This was not really
problem in practice since NEON implementations of the same functions are
preferred. It will however become a problem for checkasm which tests
every cpu flag separately.

Since this is a cpu feature newer cpu do not support anymore the
behaviour of this flag differs from the other flags. It can be only
activated by runtime cpu feature selection.
2015-12-14 16:42:35 +01:00
Janne Grunau 64034849da arm64: add cycle counter support
The ISB (instruction synchronization barrier) might be too heavy for
START/STOPTIMER use but should be more accurate in checkasm where the
timing overhead is subtracted.
2015-12-14 16:42:35 +01:00
Janne Grunau 50078c1c80 libavutil: move FFALIGN macro from common.h to macros.h
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.
2015-12-14 16:16:55 +01:00
Michael Niedermayer 5e8b9e746f avutil/softfloat: Assert that the exponent did not overflow the legal range in av_normalize1_sf()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-11 13:39:21 +01:00
Michael Niedermayer bc8b1e694c avutil/mathematics: Fix division by 0
Fixes: CID1341571

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-09 17:39:38 +01:00
Clément Bœsch 503d8bf74a lavu/frame: use AVPALETTE_SIZE instead of 1024 2015-12-08 17:50:40 +01:00
Clément Bœsch dd1d9b80c9 lavu/opencl: restore #if HAVE_THREADS
Fix regression since a8bb81a.

Spotted-by: RiCON
2015-12-07 20:28:30 +01:00
Timothy Gu 006d3e97fc cosmetics: Fix weird indentations 2015-12-07 10:43:43 -08:00
Clément Bœsch a8bb81a05c lavc, lavu: use avutil/thread.h instead of redundant conditional includes 2015-12-07 17:25:51 +01:00
Clément Bœsch 5e0c47d41c avutil/threadmessage: fix build without HAVE_THREADS, new attempt 2015-12-07 16:39:57 +01:00
Clément Bœsch d4b1b33e69 avutil/threadmessage: fix build without HAVE_THREADS 2015-12-07 14:28:34 +01:00
Clément Bœsch bd5c860fdb avutil/threadmessage: split the pthread condition in two
Fix a dead lock under certain conditions. Let's assume we have a queue of 1
message max, 2 senders, and 1 receiver.

Scenario (real record obtained with debug added):
    [...]
    SENDER #0: acquired lock
    SENDER #0: queue is full, wait
    SENDER #1: acquired lock
    SENDER #1: queue is full, wait
    RECEIVER: acquired lock
    RECEIVER: reading a msg from the queue
    RECEIVER: signal the cond
    RECEIVER: acquired lock
    RECEIVER: queue is empty, wait
    SENDER #0: writing a msg the queue
    SENDER #0: signal the cond
    SENDER #0: acquired lock
    SENDER #0: queue is full, wait
    SENDER #1: queue is full, wait

Translated:
 - initially the queue contains 1/1 message with 2 senders blocking on
   it, waiting to push another message.
 - Meanwhile the receiver is obtaining the lock, read the message,
   signal & release the lock. For some reason it is able to acquire the
   lock again before the signal wakes up one of the sender. Since it
   just emptied the queue, the reader waits for the queue to fill up
   again.
 - The signal finally reaches one of the sender, which writes a message
   and then signal the condition. Unfortunately, instead of waking up
   the reader, it actually wakes up the other worker (signal = notify
   the condition just for 1 waiter), who can't push another message in
   the queue because it's full.
 - Meanwhile, the receiver is still waiting. Deadlock.

This scenario can be triggered with for example:
    tests/api/api-threadmessage-test 1 2 100 100 1 1000 1000

One working solution is to make av_thread_message_queue_{send,recv}()
call pthread_cond_broadcast() instead of pthread_cond_signal() so both
senders and receivers are unlocked when work is done (be it reading or
writing).

This second solution replaces the condition with two: one to notify the
senders, and one to notify the receivers. This prevents senders from
notifying other senders instead of a reader, and the other way around.
It also avoid broadcasting to everyone like the first solution, and is,
as a result in theory more optimized.
2015-12-07 11:39:28 +01:00
Clément Bœsch f98abe0ee7 avutil/threadmessage: add av_thread_message_flush() 2015-12-07 11:39:28 +01:00
Reynaldo H. Verdejo Pinochet 21c34cb261 libavutil: add version component accessor macros
Pretty standard macros, these should help libav*
users avoid repeating ver.si.on parsing code,
which aids in compatibility-checking tasks like
identifying FFmpeg from Libav (_MICRO >= 100 check).
Something many are doing since we are not
intercompatible anymore.

Signed-off-by: Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
2015-12-06 01:01:51 -08:00
Hendrik Leppkes d6b988b505 libavutil/tablegen: add missing math.h include 2015-12-04 14:49:35 +01:00
Michael Niedermayer b46dcd5209 avutil/timecode: Fix fps check
The fps variable is explicitly set to -1 in case of some errors, the check must
thus be signed or the code setting it needs to use 0 as error code
the type of the field could be changed as well but its in an installed header

Fixes: integer overflow
Fixes: 9982cc157b1ea90429435640a989122f/asan_generic_3ad004a_3799_22cf198d9cd09928e2d9ad250474fa58.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-03 04:09:48 +01:00
Ganesh Ajjanagadde 1bb7db217d avutil/crc: avoid needless space wastage of hardcoded crc table
There was no reason AFAIK for making AV_CRC_24_IEEE 12. This simply
resulted in wasted space under --enable-hardcoded-tables:
dynamic: 1318672 libavutil/libavutil.so.55
old    : 1330680 libavutil/libavutil.so.55
new    : 1326488 libavutil/libavutil.so.55

Minor version number is bumped, with ifdefry due to API breakage.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-02 18:31:56 -05:00
Michael Niedermayer 97b8db334a avutil/rational: Test av_rescale_rnd() with combinations of "special" values
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-02 21:38:11 +01:00
Michael Niedermayer f03c2ceec1 avutil/mathematics: return INT64_MIN (=AV_NOPTS_VALUE) from av_rescale_rnd() for overflows
Fixes integer overflow
Fixes: mozilla bug 1229167

Found-by: Tyson Smith
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-02 21:38:11 +01:00
Ganesh Ajjanagadde 538e8ab512 avutil/tablegen: add tablegen libm compatibility shims
This is useful for build-time table generation (--enable-hardcoded-tables),
by providing compat shims for hosts that have broken libms.

This file is deliberately kept minimal; functions can always be added on
an as-needed basis.

Reviewed-by: Clément Bœsch <u@pkh.me>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-01 19:05:19 -05:00
Michael Niedermayer 25e37f5ea9 avutil/mathematics: Do not treat INT64_MIN as positive in av_rescale_rnd
The code expects actual positive numbers and gives completely wrong
results if INT64_MIN is treated as positive
Instead clip it into the valid range that is add 1 and treat it as
negative

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-01 13:26:12 +01:00
Michael Niedermayer 3a9cb18855 avutil/integer: Fix av_mod_i() with negative dividend
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-01 13:26:12 +01:00
Ganesh Ajjanagadde 68e79b27a5 avutil/lls: speed up performance of solve_lls
This is a trivial rewrite of the loops that results in better
prefetching and associated cache efficiency. Essentially, the problem is
that modern prefetching logic is based on finite state Markov memory, a reasonable
assumption that is used elsewhere in CPU's in for instance branch
predictors.

Surrounding loops all iterate forward through the array, making the
predictor think of prefetching in the forward direction, but the
intermediate loop is unnecessarily in the backward direction.

Speedup is nontrivial. Benchmarks obtained by 10^6 iterations within
solve_lls, with START/STOP_TIMER. File is tests/data/fate/flac-16-lpc-cholesky.err.
Hardware: x86-64, Haswell, GNU/Linux.

new:
  17291 decicycles in solve_lls, 2096706 runs,    446 skips
  17255 decicycles in solve_lls, 4193657 runs,    647 skips
  17231 decicycles in solve_lls, 8384997 runs,   3611 skips
  17189 decicycles in solve_lls,16771010 runs,   6206 skips
  17132 decicycles in solve_lls,33544757 runs,   9675 skips
  17092 decicycles in solve_lls,67092404 runs,  16460 skips
  17058 decicycles in solve_lls,134188213 runs,  29515 skips

old:
  18009 decicycles in solve_lls, 2096665 runs,    487 skips
  17805 decicycles in solve_lls, 4193320 runs,    984 skips
  17779 decicycles in solve_lls, 8386855 runs,   1753 skips
  18289 decicycles in solve_lls,16774280 runs,   2936 skips
  18158 decicycles in solve_lls,33548104 runs,   6328 skips
  18420 decicycles in solve_lls,67091793 runs,  17071 skips
  18310 decicycles in solve_lls,134187219 runs,  30509 skips

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-11-26 09:20:46 -05:00
Ganesh Ajjanagadde 29af74e4e3 avutil/libm: fix isnan compatibility hack
Commit 14ea4151d7 had a bug in that the
conversion of the uint64_t result to an int (the return signature) would
lead to implementation defined behavior, and in this case simply
returned 0 for NAN. A fix via AND'ing the result with 1 does the trick,
simply by ensuring a 0 or 1 return value.

Patch tested with FATE on x86-64, GNU/Linux by forcing the compatibility
code via an ifdef hack suggested by Michael.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-11-24 21:33:13 -05:00
Timothy Gu 7c91b3021c imgutils: Use designated initializers for AVClass
More readable and less breakable.
2015-11-23 18:30:25 -08:00
Matt Oliver e9ec28c95e avutil/x86/bswap: Remove warning about bswap intrinsics with msvc.
Signed-off-by: Matt Oliver <protogonoi@gmail.com>
2015-11-23 23:03:32 +11:00
Clément Bœsch 56bdf61baa avutil/motion_vector: export subpel motion information
FATE test changes because of the switch from shift to division.
2015-11-23 10:55:15 +01:00
Derek Buitenhuis e12f403678 Merge commit '588b6215b4c74945994eb9636b0699028c069ed2'
* commit '588b6215b4c74945994eb9636b0699028c069ed2':
  rtmpcrypt: Do the xtea decryption in little endian mode
  xtea: Add functions for little endian mode

  Conflicts:
      libavutil/xtea.c

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2015-11-22 14:29:09 +00:00
Ganesh Ajjanagadde 401c93ddb7 avutil/eval: change sqrt to hypot
This improves the mathematical behavior of hypotenuse computation.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-11-21 08:51:49 -05:00
Ganesh Ajjanagadde 275aca8fba configure+libm.h: add hypot emulation
It is known that the naive sqrt(x*x + y*y) approach for computing the
hypotenuse suffers from overflow and accuracy issues, see e.g
http://www.johndcook.com/blog/2010/06/02/whats-so-hard-about-finding-a-hypotenuse/.
This adds hypot support to FFmpeg, a C99 function.

On platforms without hypot, this patch does a reaonable workaround, that
although not as accurate as GNU libm, is readable and does not suffer
from the overflow issue. Improvements can be made separately.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-11-21 08:51:49 -05:00
Ganesh Ajjanagadde 14ea4151d7 avutil/libm: correct isnan, isinf compat hacks
isnan and isinf are actually macros as per the standard. In particular,
the existing implementation has incorrect signature. Furthermore, this
results in undefined behavior for e.g double values outside float range
as per the standard.

This patch corrects the undefined behavior for all usage within FFmpeg.

Note that long double is not handled as it is not used in FFmpeg.
Furthermore, even if at some point long double gets used, it is likely
not needed to modify the macro in practice for usage in FFmpeg. See
below for analysis.

Getting long double to work strictly per the spec is significantly harder
since a long double may be an IEEE 128 bit quad (very rare), 80 bit
extended precision value (on GCC/Clang), or simply double (on recent Microsoft).
On the other hand, any potential future usage of long double is likely
for precision (when a platform offers extra precision) and not for range, since
the range anyway varies and is not as portable as IEEE 754 single/double
precision. In such cases, the implicit cast to a double is well defined
and isinf and isnan should work as intended.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-11-21 08:51:49 -05:00
Derek Buitenhuis 3d2363fbf9 Merge commit '1fc94724f1fd52944bb5ae571475c621da4b77a0'
* commit '1fc94724f1fd52944bb5ae571475c621da4b77a0':
  xtea: Clarify that the current API works in big endian mode

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2015-11-19 14:14:20 +00:00
Michael Niedermayer fc91eeab0b avutil/mem: Add av_fast_mallocz()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-18 22:05:16 +01:00
Michael Niedermayer 5c3dee7dad avutil: Move av_rint64_clip_* to internal.h
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>
2015-11-15 03:47:09 +01:00
Ganesh Ajjanagadde 6f520ce1a6 avutil/common: add av_rint64_clip
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>
2015-11-13 21:48:16 -05:00
Martin Storsjö 92d107a171 xtea: Add functions for little endian mode
Signed-off-by: Martin Storsjö <martin@martin.st>
2015-11-13 21:53:54 +02:00
Martin Storsjö 1fc94724f1 xtea: Clarify that the current API works in big endian mode
Signed-off-by: Martin Storsjö <martin@martin.st>
2015-11-13 21:53:51 +02:00
Matt Oliver 58d32c00be avutil/x86/intmath: Fix intrinsic header include when using newer gcc with older icc.
Signed-off-by: Matt Oliver <protogonoi@gmail.com>
2015-11-12 16:54:08 +11:00
Matt Oliver 9b9c9ef3b4 avutil/x86/bswap: Add msvc bswap instrinsics.
This adds msvc optimisations as well as fixing an error in icl whereby it will generate invalid code otherwise.

Signed-off-by: Matt Oliver <protogonoi@gmail.com>
2015-11-12 16:53:44 +11:00