From a6a750c7ef240b72ce01e9653343a0ddf247d196 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 20 Apr 2016 11:40:40 +0200 Subject: tests: Move all test programs to a subdirectory --- .gitignore | 1 - common.mak | 7 +- libavcodec/Makefile | 2 +- libavcodec/arm/dct-test.c | 40 --- libavcodec/dct-test.c | 471 --------------------------- libavcodec/fft-fixed-test.c | 20 -- libavcodec/fft-test.c | 513 ------------------------------ libavcodec/golomb-test.c | 97 ------ libavcodec/iirfilter-test.c | 54 ---- libavcodec/ppc/dct-test.c | 32 -- libavcodec/rangecoder-test.c | 64 ---- libavcodec/tests/.gitignore | 6 + libavcodec/tests/arm/dct.c | 40 +++ libavcodec/tests/dct.c | 472 +++++++++++++++++++++++++++ libavcodec/tests/fft-fixed.c | 20 ++ libavcodec/tests/fft.c | 513 ++++++++++++++++++++++++++++++ libavcodec/tests/golomb.c | 97 ++++++ libavcodec/tests/iirfilter.c | 54 ++++ libavcodec/tests/ppc/dct.c | 32 ++ libavcodec/tests/rangecoder.c | 64 ++++ libavcodec/tests/x86/dct.c | 86 +++++ libavcodec/x86/dct-test.c | 86 ----- libavdevice/tests/timefilter.c | 92 ++++++ libavdevice/timefilter-test.c | 92 ------ libavfilter/filtfmts-test.c | 124 -------- libavfilter/tests/.gitignore | 1 + libavfilter/tests/filtfmts.c | 124 ++++++++ libavformat/movenc-test.c | 672 --------------------------------------- libavformat/noproxy-test.c | 43 --- libavformat/rtmpdh-test.c | 158 --------- libavformat/seek-test.c | 129 -------- libavformat/srtp-test.c | 167 ---------- libavformat/tests/.gitignore | 5 + libavformat/tests/movenc.c | 672 +++++++++++++++++++++++++++++++++++++++ libavformat/tests/noproxy.c | 43 +++ libavformat/tests/rtmpdh.c | 158 +++++++++ libavformat/tests/seek.c | 130 ++++++++ libavformat/tests/srtp.c | 167 ++++++++++ libavformat/tests/url.c | 55 ++++ libavformat/url-test.c | 55 ---- libavresample/avresample-test.c | 341 -------------------- libavresample/tests/.gitignore | 1 + libavresample/tests/avresample.c | 342 ++++++++++++++++++++ libavutil/adler32-test.c | 51 --- libavutil/aes-test.c | 92 ------ libavutil/atomic-test.c | 35 -- libavutil/avstring-test.c | 69 ---- libavutil/base64-test.c | 84 ----- libavutil/blowfish-test.c | 190 ----------- libavutil/cpu-test.c | 136 -------- libavutil/crc-test.c | 45 --- libavutil/des-test.c | 128 -------- libavutil/des.c | 2 +- libavutil/eval-test.c | 145 --------- libavutil/fifo-test.c | 51 --- libavutil/float_dsp-test.c | 296 ----------------- libavutil/hmac-test.c | 92 ------ libavutil/lfg-test.c | 56 ---- libavutil/lls-test.c | 54 ---- libavutil/md5-test.c | 54 ---- libavutil/opt-test.c | 110 ------- libavutil/parseutils-test.c | 116 ------- libavutil/sha-test.c | 69 ---- libavutil/tests/.gitignore | 21 ++ libavutil/tests/adler32.c | 51 +++ libavutil/tests/aes.c | 92 ++++++ libavutil/tests/atomic.c | 35 ++ libavutil/tests/avstring.c | 69 ++++ libavutil/tests/base64.c | 84 +++++ libavutil/tests/blowfish.c | 190 +++++++++++ libavutil/tests/cpu.c | 136 ++++++++ libavutil/tests/crc.c | 45 +++ libavutil/tests/des.c | 128 ++++++++ libavutil/tests/eval.c | 145 +++++++++ libavutil/tests/fifo.c | 51 +++ libavutil/tests/float_dsp.c | 296 +++++++++++++++++ libavutil/tests/hmac.c | 92 ++++++ libavutil/tests/lfg.c | 56 ++++ libavutil/tests/lls.c | 54 ++++ libavutil/tests/md5.c | 54 ++++ libavutil/tests/opt.c | 110 +++++++ libavutil/tests/parseutils.c | 116 +++++++ libavutil/tests/sha.c | 69 ++++ libavutil/tests/tree.c | 110 +++++++ libavutil/tests/xtea.c | 120 +++++++ libavutil/tree-test.c | 110 ------- libavutil/xtea-test.c | 120 ------- library.mak | 7 +- libswscale/colorspace-test.c | 162 ---------- libswscale/swscale-test.c | 411 ------------------------ libswscale/tests/.gitignore | 2 + libswscale/tests/colorspace.c | 163 ++++++++++ libswscale/tests/swscale.c | 412 ++++++++++++++++++++++++ tests/fate-run.sh | 2 +- tests/fate/fft.mak | 8 +- tests/fate/filter-video.mak | 2 +- tests/fate/libavcodec.mak | 16 +- tests/fate/libavdevice.mak | 4 +- tests/fate/libavformat.mak | 20 +- tests/fate/libavutil.mak | 72 ++--- tests/fate/seek.mak | 4 +- 101 files changed, 5948 insertions(+), 5908 deletions(-) delete mode 100644 libavcodec/arm/dct-test.c delete mode 100644 libavcodec/dct-test.c delete mode 100644 libavcodec/fft-fixed-test.c delete mode 100644 libavcodec/fft-test.c delete mode 100644 libavcodec/golomb-test.c delete mode 100644 libavcodec/iirfilter-test.c delete mode 100644 libavcodec/ppc/dct-test.c delete mode 100644 libavcodec/rangecoder-test.c create mode 100644 libavcodec/tests/.gitignore create mode 100644 libavcodec/tests/arm/dct.c create mode 100644 libavcodec/tests/dct.c create mode 100644 libavcodec/tests/fft-fixed.c create mode 100644 libavcodec/tests/fft.c create mode 100644 libavcodec/tests/golomb.c create mode 100644 libavcodec/tests/iirfilter.c create mode 100644 libavcodec/tests/ppc/dct.c create mode 100644 libavcodec/tests/rangecoder.c create mode 100644 libavcodec/tests/x86/dct.c delete mode 100644 libavcodec/x86/dct-test.c create mode 100644 libavdevice/tests/timefilter.c delete mode 100644 libavdevice/timefilter-test.c delete mode 100644 libavfilter/filtfmts-test.c create mode 100644 libavfilter/tests/.gitignore create mode 100644 libavfilter/tests/filtfmts.c delete mode 100644 libavformat/movenc-test.c delete mode 100644 libavformat/noproxy-test.c delete mode 100644 libavformat/rtmpdh-test.c delete mode 100644 libavformat/seek-test.c delete mode 100644 libavformat/srtp-test.c create mode 100644 libavformat/tests/.gitignore create mode 100644 libavformat/tests/movenc.c create mode 100644 libavformat/tests/noproxy.c create mode 100644 libavformat/tests/rtmpdh.c create mode 100644 libavformat/tests/seek.c create mode 100644 libavformat/tests/srtp.c create mode 100644 libavformat/tests/url.c delete mode 100644 libavformat/url-test.c delete mode 100644 libavresample/avresample-test.c create mode 100644 libavresample/tests/.gitignore create mode 100644 libavresample/tests/avresample.c delete mode 100644 libavutil/adler32-test.c delete mode 100644 libavutil/aes-test.c delete mode 100644 libavutil/atomic-test.c delete mode 100644 libavutil/avstring-test.c delete mode 100644 libavutil/base64-test.c delete mode 100644 libavutil/blowfish-test.c delete mode 100644 libavutil/cpu-test.c delete mode 100644 libavutil/crc-test.c delete mode 100644 libavutil/des-test.c delete mode 100644 libavutil/eval-test.c delete mode 100644 libavutil/fifo-test.c delete mode 100644 libavutil/float_dsp-test.c delete mode 100644 libavutil/hmac-test.c delete mode 100644 libavutil/lfg-test.c delete mode 100644 libavutil/lls-test.c delete mode 100644 libavutil/md5-test.c delete mode 100644 libavutil/opt-test.c delete mode 100644 libavutil/parseutils-test.c delete mode 100644 libavutil/sha-test.c create mode 100644 libavutil/tests/.gitignore create mode 100644 libavutil/tests/adler32.c create mode 100644 libavutil/tests/aes.c create mode 100644 libavutil/tests/atomic.c create mode 100644 libavutil/tests/avstring.c create mode 100644 libavutil/tests/base64.c create mode 100644 libavutil/tests/blowfish.c create mode 100644 libavutil/tests/cpu.c create mode 100644 libavutil/tests/crc.c create mode 100644 libavutil/tests/des.c create mode 100644 libavutil/tests/eval.c create mode 100644 libavutil/tests/fifo.c create mode 100644 libavutil/tests/float_dsp.c create mode 100644 libavutil/tests/hmac.c create mode 100644 libavutil/tests/lfg.c create mode 100644 libavutil/tests/lls.c create mode 100644 libavutil/tests/md5.c create mode 100644 libavutil/tests/opt.c create mode 100644 libavutil/tests/parseutils.c create mode 100644 libavutil/tests/sha.c create mode 100644 libavutil/tests/tree.c create mode 100644 libavutil/tests/xtea.c delete mode 100644 libavutil/tree-test.c delete mode 100644 libavutil/xtea-test.c delete mode 100644 libswscale/colorspace-test.c delete mode 100644 libswscale/swscale-test.c create mode 100644 libswscale/tests/.gitignore create mode 100644 libswscale/tests/colorspace.c create mode 100644 libswscale/tests/swscale.c diff --git a/.gitignore b/.gitignore index a191731ee0..5464bba7e6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ *.so.* *.swp *.ver -*-test /.config /.version /avconv diff --git a/common.mak b/common.mak index 832025d10c..d62f899dad 100644 --- a/common.mak +++ b/common.mak @@ -15,8 +15,8 @@ LDLIBS = $(FFLIBS:%=%$(BUILDSUF)) FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS) OBJS := $(sort $(OBJS:%=$(SUBDIR)%)) -TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o) -TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF)) +TESTOBJS := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o) +TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF)) HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o) HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF)) TOOLS += $(TOOLS-yes) @@ -58,8 +58,7 @@ LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a define RULES clean:: - $(RM) $(HOSTPROGS) - $(RM) $(TOOLS) + $(RM) $(HOSTPROGS) $(TESTPROGS) $(TOOLS) endef $(eval $(RULES)) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index d12c52e819..503ffd0eb4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -813,7 +813,7 @@ HOSTPROGS = aac_tablegen \ CLEANFILES = *_tables.c *_tables.h *_tablegen$(HOSTEXESUF) -$(SUBDIR)dct-test$(EXESUF): $(SUBDIR)dctref.o $(SUBDIR)aandcttab.o +$(SUBDIR)tests/dct$(EXESUF): $(SUBDIR)dctref.o $(SUBDIR)aandcttab.o $(SUBDIR)dv_tablegen$(HOSTEXESUF): $(SUBDIR)dvdata_host.o TRIG_TABLES = cos cos_fixed sin diff --git a/libavcodec/arm/dct-test.c b/libavcodec/arm/dct-test.c deleted file mode 100644 index 70e5c1cb82..0000000000 --- a/libavcodec/arm/dct-test.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "idct.h" - -static const struct algo fdct_tab_arch[] = { - { 0 } -}; - -static const struct algo idct_tab_arch[] = { - { "SIMPLE-ARM", ff_simple_idct_arm, FF_IDCT_PERM_NONE }, - { "INT-ARM", ff_j_rev_dct_arm, FF_IDCT_PERM_LIBMPEG2 }, -#if HAVE_ARMV5TE - { "SIMPLE-ARMV5TE", ff_simple_idct_armv5te, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ARMV5TE }, -#endif -#if HAVE_ARMV6 - { "SIMPLE-ARMV6", ff_simple_idct_armv6, FF_IDCT_PERM_LIBMPEG2, AV_CPU_FLAG_ARMV6 }, -#endif -#if HAVE_NEON - { "SIMPLE-NEON", ff_simple_idct_neon, FF_IDCT_PERM_PARTTRANS, AV_CPU_FLAG_NEON }, -#endif - { 0 } -}; diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c deleted file mode 100644 index 262319e1b4..0000000000 --- a/libavcodec/dct-test.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * (c) 2001 Fabrice Bellard - * 2007 Marc Hoffman - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * DCT test (c) 2001 Fabrice Bellard - * Started from sample code by Juan J. Sierralta P. - */ - -#include "config.h" -#include -#include -#include -#if HAVE_UNISTD_H -#include -#endif -#include - -#include "libavutil/cpu.h" -#include "libavutil/common.h" -#include "libavutil/lfg.h" -#include "libavutil/time.h" - -#include "dct.h" -#include "idctdsp.h" -#include "simple_idct.h" -#include "xvididct.h" -#include "aandcttab.h" -#include "faandct.h" -#include "faanidct.h" -#include "dctref.h" - -struct algo { - const char *name; - void (*func)(int16_t *block); - enum idct_permutation_type perm_type; - int cpu_flag; - int nonspec; -}; - -static const struct algo fdct_tab[] = { - { "REF-DBL", ff_ref_fdct, FF_IDCT_PERM_NONE }, - { "IJG-AAN-INT", ff_fdct_ifast, FF_IDCT_PERM_NONE }, - { "IJG-LLM-INT", ff_jpeg_fdct_islow_8, FF_IDCT_PERM_NONE }, -#if CONFIG_FAANDCT - { "FAAN", ff_faandct, FF_IDCT_PERM_NONE }, -#endif /* CONFIG_FAANDCT */ -}; - -static const struct algo idct_tab[] = { - { "REF-DBL", ff_ref_idct, FF_IDCT_PERM_NONE }, - { "INT", ff_j_rev_dct, FF_IDCT_PERM_LIBMPEG2 }, - { "SIMPLE-C", ff_simple_idct_8, FF_IDCT_PERM_NONE }, -#if CONFIG_FAANIDCT - { "FAANI", ff_faanidct, FF_IDCT_PERM_NONE }, -#endif /* CONFIG_FAANIDCT */ -#if CONFIG_MPEG4_DECODER - { "XVID", ff_xvid_idct, FF_IDCT_PERM_NONE, 0, 1 }, -#endif /* CONFIG_MPEG4_DECODER */ -}; - -#if ARCH_ARM -#include "arm/dct-test.c" -#elif ARCH_PPC -#include "ppc/dct-test.c" -#elif ARCH_X86 -#include "x86/dct-test.c" -#else -static const struct algo fdct_tab_arch[] = { { 0 } }; -static const struct algo idct_tab_arch[] = { { 0 } }; -#endif - -#define AANSCALE_BITS 12 - -#define NB_ITS 20000 -#define NB_ITS_SPEED 50000 - -DECLARE_ALIGNED(16, static int16_t, block)[64]; -DECLARE_ALIGNED(8, static int16_t, block1)[64]; - -static void init_block(int16_t block[64], int test, int is_idct, AVLFG *prng) -{ - int i, j; - - memset(block, 0, 64 * sizeof(*block)); - - switch (test) { - case 0: - for (i = 0; i < 64; i++) - block[i] = (av_lfg_get(prng) % 512) - 256; - if (is_idct) { - ff_ref_fdct(block); - for (i = 0; i < 64; i++) - block[i] >>= 3; - } - break; - case 1: - j = av_lfg_get(prng) % 10 + 1; - for (i = 0; i < j; i++) - block[av_lfg_get(prng) % 64] = av_lfg_get(prng) % 512 - 256; - break; - case 2: - block[ 0] = av_lfg_get(prng) % 4096 - 2048; - block[63] = (block[0] & 1) ^ 1; - break; - } -} - -static void permute(int16_t dst[64], const int16_t src[64], - enum idct_permutation_type perm_type) -{ - int i; - -#if ARCH_X86 - if (permute_x86(dst, src, perm_type)) - return; -#endif - - switch (perm_type) { - case FF_IDCT_PERM_LIBMPEG2: - for (i = 0; i < 64; i++) - dst[(i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2)] = src[i]; - break; - case FF_IDCT_PERM_PARTTRANS: - for (i = 0; i < 64; i++) - dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i]; - break; - default: - for (i = 0; i < 64; i++) - dst[i] = src[i]; - break; - } -} - -static int dct_error(const struct algo *dct, int test, int is_idct, int speed) -{ - void (*ref)(int16_t *block) = is_idct ? ff_ref_idct : ff_ref_fdct; - int it, i, scale; - int err_inf, v; - int64_t err2, ti, ti1, it1, err_sum = 0; - int64_t sysErr[64], sysErrMax = 0; - int maxout = 0; - int blockSumErrMax = 0, blockSumErr; - AVLFG prng; - double omse, ome; - int spec_err; - - av_lfg_init(&prng, 1); - - err_inf = 0; - err2 = 0; - for (i = 0; i < 64; i++) - sysErr[i] = 0; - for (it = 0; it < NB_ITS; it++) { - init_block(block1, test, is_idct, &prng); - permute(block, block1, dct->perm_type); - - dct->func(block); - emms_c(); - - if (!strcmp(dct->name, "IJG-AAN-INT")) { - for (i = 0; i < 64; i++) { - scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i]; - block[i] = (block[i] * scale) >> AANSCALE_BITS; - } - } - - ref(block1); - - blockSumErr = 0; - for (i = 0; i < 64; i++) { - int err = block[i] - block1[i]; - err_sum += err; - v = abs(err); - if (v > err_inf) - err_inf = v; - err2 += v * v; - sysErr[i] += block[i] - block1[i]; - blockSumErr += v; - if (abs(block[i]) > maxout) - maxout = abs(block[i]); - } - if (blockSumErrMax < blockSumErr) - blockSumErrMax = blockSumErr; - } - for (i = 0; i < 64; i++) - sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i])); - - for (i = 0; i < 64; i++) { - if (i % 8 == 0) - printf("\n"); - printf("%7d ", (int) sysErr[i]); - } - printf("\n"); - - omse = (double) err2 / NB_ITS / 64; - ome = (double) err_sum / NB_ITS / 64; - - spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015); - - printf("%s %s: ppe=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", - is_idct ? "IDCT" : "DCT", dct->name, err_inf, - omse, ome, (double) sysErrMax / NB_ITS, - maxout, blockSumErrMax); - - if (spec_err && !dct->nonspec) - return 1; - - if (!speed) - return 0; - - /* speed test */ - init_block(block, test, is_idct, &prng); - permute(block1, block, dct->perm_type); - - ti = av_gettime_relative(); - it1 = 0; - do { - for (it = 0; it < NB_ITS_SPEED; it++) { - memcpy(block, block1, sizeof(block)); - dct->func(block); - } - it1 += NB_ITS_SPEED; - ti1 = av_gettime_relative() - ti; - } while (ti1 < 1000000); - emms_c(); - - printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name, - (double) it1 * 1000.0 / (double) ti1); - - return 0; -} - -DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; -DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64]; - -static void idct248_ref(uint8_t *dest, int linesize, int16_t *block) -{ - static int init; - static double c8[8][8]; - static double c4[4][4]; - double block1[64], block2[64], block3[64]; - double s, sum, v; - int i, j, k; - - if (!init) { - init = 1; - - for (i = 0; i < 8; i++) { - sum = 0; - for (j = 0; j < 8; j++) { - s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0); - c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0); - sum += c8[i][j] * c8[i][j]; - } - } - - for (i = 0; i < 4; i++) { - sum = 0; - for (j = 0; j < 4; j++) { - s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0); - c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0); - sum += c4[i][j] * c4[i][j]; - } - } - } - - /* butterfly */ - s = 0.5 * sqrt(2.0); - for (i = 0; i < 4; i++) { - for (j = 0; j < 8; j++) { - block1[8 * (2 * i) + j] = - (block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s; - block1[8 * (2 * i + 1) + j] = - (block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s; - } - } - - /* idct8 on lines */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) { - sum = 0; - for (k = 0; k < 8; k++) - sum += c8[k][j] * block1[8 * i + k]; - block2[8 * i + j] = sum; - } - } - - /* idct4 */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 4; j++) { - /* top */ - sum = 0; - for (k = 0; k < 4; k++) - sum += c4[k][j] * block2[8 * (2 * k) + i]; - block3[8 * (2 * j) + i] = sum; - - /* bottom */ - sum = 0; - for (k = 0; k < 4; k++) - sum += c4[k][j] * block2[8 * (2 * k + 1) + i]; - block3[8 * (2 * j + 1) + i] = sum; - } - } - - /* clamp and store the result */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) { - v = block3[8 * i + j]; - if (v < 0) v = 0; - else if (v > 255) v = 255; - dest[i * linesize + j] = (int) rint(v); - } - } -} - -static void idct248_error(const char *name, - void (*idct248_put)(uint8_t *dest, int line_size, - int16_t *block), - int speed) -{ - int it, i, it1, ti, ti1, err_max, v; - AVLFG prng; - - av_lfg_init(&prng, 1); - - /* just one test to see if code is correct (precision is less - important here) */ - err_max = 0; - for (it = 0; it < NB_ITS; it++) { - /* XXX: use forward transform to generate values */ - for (i = 0; i < 64; i++) - block1[i] = av_lfg_get(&prng) % 256 - 128; - block1[0] += 1024; - - for (i = 0; i < 64; i++) - block[i] = block1[i]; - idct248_ref(img_dest1, 8, block); - - for (i = 0; i < 64; i++) - block[i] = block1[i]; - idct248_put(img_dest, 8, block); - - for (i = 0; i < 64; i++) { - v = abs((int) img_dest[i] - (int) img_dest1[i]); - if (v == 255) - printf("%d %d\n", img_dest[i], img_dest1[i]); - if (v > err_max) - err_max = v; - } - } - printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max); - - if (!speed) - return; - - ti = av_gettime_relative(); - it1 = 0; - do { - for (it = 0; it < NB_ITS_SPEED; it++) { - for (i = 0; i < 64; i++) - block[i] = block1[i]; - idct248_put(img_dest, 8, block); - } - it1 += NB_ITS_SPEED; - ti1 = av_gettime_relative() - ti; - } while (ti1 < 1000000); - emms_c(); - - printf("%s %s: %0.1f kdct/s\n", 1 ? "IDCT248" : "DCT248", name, - (double) it1 * 1000.0 / (double) ti1); -} - -static void help(void) -{ - printf("dct-test [-i] []\n" - "test-number 0 -> test with random matrixes\n" - " 1 -> test with random sparse matrixes\n" - " 2 -> do 3. test from MPEG-4 std\n" - "-i test IDCT implementations\n" - "-4 test IDCT248 implementations\n" - "-t speed test\n"); -} - -#if !HAVE_GETOPT -#include "compat/getopt.c" -#endif - -int main(int argc, char **argv) -{ - int test_idct = 0, test_248_dct = 0; - int c, i; - int test = 1; - int speed = 0; - int err = 0; - - ff_ref_dct_init(); - - for (;;) { - c = getopt(argc, argv, "ih4t"); - if (c == -1) - break; - switch (c) { - case 'i': - test_idct = 1; - break; - case '4': - test_248_dct = 1; - break; - case 't': - speed = 1; - break; - default: - case 'h': - help(); - return 0; - } - } - - if (optind < argc) - test = atoi(argv[optind]); - - printf("Libav DCT/IDCT test\n"); - - if (test_248_dct) { - idct248_error("SIMPLE-C", ff_simple_idct248_put, speed); - } else { - const int cpu_flags = av_get_cpu_flags(); - if (test_idct) { - for (i = 0; i < FF_ARRAY_ELEMS(idct_tab); i++) - err |= dct_error(&idct_tab[i], test, test_idct, speed); - - for (i = 0; idct_tab_arch[i].name; i++) - if (!(~cpu_flags & idct_tab_arch[i].cpu_flag)) - err |= dct_error(&idct_tab_arch[i], test, test_idct, speed); - } -#if CONFIG_FDCTDSP - else { - for (i = 0; i < FF_ARRAY_ELEMS(fdct_tab); i++) - err |= dct_error(&fdct_tab[i], test, test_idct, speed); - - for (i = 0; fdct_tab_arch[i].name; i++) - if (!(~cpu_flags & fdct_tab_arch[i].cpu_flag)) - err |= dct_error(&fdct_tab_arch[i], test, test_idct, speed); - } -#endif /* CONFIG_FDCTDSP */ - } - - if (err) - printf("Error: %d.\n", err); - - return !!err; -} diff --git a/libavcodec/fft-fixed-test.c b/libavcodec/fft-fixed-test.c deleted file mode 100644 index d6ea987fa3..0000000000 --- a/libavcodec/fft-fixed-test.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#define FFT_FLOAT 0 -#include "fft-test.c" diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c deleted file mode 100644 index 83b5546f08..0000000000 --- a/libavcodec/fft-test.c +++ /dev/null @@ -1,513 +0,0 @@ -/* - * (c) 2002 Fabrice Bellard - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * FFT and MDCT tests. - */ - -#include "config.h" - -#include -#if HAVE_UNISTD_H -#include -#endif -#include -#include -#include - -#include "libavutil/cpu.h" -#include "libavutil/lfg.h" -#include "libavutil/log.h" -#include "libavutil/mathematics.h" -#include "libavutil/time.h" - -#include "fft.h" -#if FFT_FLOAT -#include "dct.h" -#include "rdft.h" -#endif - -/* reference fft */ - -#define MUL16(a, b) ((a) * (b)) - -#define CMAC(pre, pim, are, aim, bre, bim) \ - { \ - pre += (MUL16(are, bre) - MUL16(aim, bim)); \ - pim += (MUL16(are, bim) + MUL16(bre, aim)); \ - } - -#if FFT_FLOAT -#define RANGE 1.0 -#define REF_SCALE(x, bits) (x) -#define FMT "%10.6f" -#else -#define RANGE 16384 -#define REF_SCALE(x, bits) ((x) / (1 << (bits))) -#define FMT "%6d" -#endif - -static struct { - float re, im; -} *exptab; - -static int fft_ref_init(int nbits, int inverse) -{ - int i, n = 1 << nbits; - - exptab = av_malloc((n / 2) * sizeof(*exptab)); - if (!exptab) - return AVERROR(ENOMEM); - - for (i = 0; i < (n / 2); i++) { - double alpha = 2 * M_PI * (float) i / (float) n; - double c1 = cos(alpha), s1 = sin(alpha); - if (!inverse) - s1 = -s1; - exptab[i].re = c1; - exptab[i].im = s1; - } - return 0; -} - -static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) -{ - int i, j; - int n = 1 << nbits; - int n2 = n >> 1; - - for (i = 0; i < n; i++) { - double tmp_re = 0, tmp_im = 0; - FFTComplex *q = tab; - for (j = 0; j < n; j++) { - double s, c; - int k = (i * j) & (n - 1); - if (k >= n2) { - c = -exptab[k - n2].re; - s = -exptab[k - n2].im; - } else { - c = exptab[k].re; - s = exptab[k].im; - } - CMAC(tmp_re, tmp_im, c, s, q->re, q->im); - q++; - } - tabr[i].re = REF_SCALE(tmp_re, nbits); - tabr[i].im = REF_SCALE(tmp_im, nbits); - } -} - -#if CONFIG_MDCT -static void imdct_ref(FFTSample *out, FFTSample *in, int nbits) -{ - int i, k, n = 1 << nbits; - - for (i = 0; i < n; i++) { - double sum = 0; - for (k = 0; k < n / 2; k++) { - int a = (2 * i + 1 + (n / 2)) * (2 * k + 1); - double f = cos(M_PI * a / (double) (2 * n)); - sum += f * in[k]; - } - out[i] = REF_SCALE(-sum, nbits - 2); - } -} - -/* NOTE: no normalisation by 1 / N is done */ -static void mdct_ref(FFTSample *output, FFTSample *input, int nbits) -{ - int i, k, n = 1 << nbits; - - /* do it by hand */ - for (k = 0; k < n / 2; k++) { - double s = 0; - for (i = 0; i < n; i++) { - double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n)); - s += input[i] * cos(a); - } - output[k] = REF_SCALE(s, nbits - 1); - } -} -#endif /* CONFIG_MDCT */ - -#if FFT_FLOAT -#if CONFIG_DCT -static void idct_ref(float *output, float *input, int nbits) -{ - int i, k, n = 1 << nbits; - - /* do it by hand */ - for (i = 0; i < n; i++) { - double s = 0.5 * input[0]; - for (k = 1; k < n; k++) { - double a = M_PI * k * (i + 0.5) / n; - s += input[k] * cos(a); - } - output[i] = 2 * s / n; - } -} - -static void dct_ref(float *output, float *input, int nbits) -{ - int i, k, n = 1 << nbits; - - /* do it by hand */ - for (k = 0; k < n; k++) { - double s = 0; - for (i = 0; i < n; i++) { - double a = M_PI * k * (i + 0.5) / n; - s += input[i] * cos(a); - } - output[k] = s; - } -} -#endif /* CONFIG_DCT */ -#endif /* FFT_FLOAT */ - -static FFTSample frandom(AVLFG *prng) -{ - return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE; -} - -static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale) -{ - int i, err = 0; - double error = 0, max = 0; - - for (i = 0; i < n; i++) { - double e = fabs(tab1[i] - (tab2[i] / scale)) / RANGE; - if (e >= 1e-3) { - av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n", - i, tab1[i], tab2[i]); - err = 1; - } - error += e * e; - if (e > max) - max = e; - } - av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error) / n); - return err; -} - -static void help(void) -{ - av_log(NULL, AV_LOG_INFO, - "usage: fft-test [-h] [-s] [-i] [-n b]\n" - "-h print this help\n" - "-s speed test\n" - "-m (I)MDCT test\n" - "-d (I)DCT test\n" - "-r (I)RDFT test\n" - "-i inverse transform test\n" - "-n b set the transform size to 2^b\n" - "-f x set scale factor for output data of (I)MDCT to x\n"); -} - -enum tf_transform { - TRANSFORM_FFT, - TRANSFORM_MDCT, - TRANSFORM_RDFT, - TRANSFORM_DCT, -}; - -#if !HAVE_GETOPT -#include "compat/getopt.c" -#endif - -int main(int argc, char **argv) -{ - FFTComplex *tab, *tab1, *tab_ref; - FFTSample *tab2; - enum tf_transform transform = TRANSFORM_FFT; - FFTContext m, s; -#if FFT_FLOAT - RDFTContext r; - DCTContext d; -#endif /* FFT_FLOAT */ - int it, i, err = 1; - int do_speed = 0, do_inverse = 0; - int fft_nbits = 9, fft_size; - double scale = 1.0; - AVLFG prng; - - av_lfg_init(&prng, 1); - - for (;;) { - int c = getopt(argc, argv, "hsimrdn:f:c:"); - if (c == -1) - break; - switch (c) { - case 'h': - help(); - return 1; - case 's': - do_speed = 1; - break; - case 'i': - do_inverse = 1; - break; - case 'm': - transform = TRANSFORM_MDCT; - break; - case 'r': - transform = TRANSFORM_RDFT; - break; - case 'd': - transform = TRANSFORM_DCT; - break; - case 'n': - fft_nbits = atoi(optarg); - break; - case 'f': - scale = atof(optarg); - break; - case 'c': - { - int cpuflags = av_parse_cpu_flags(optarg); - if (cpuflags < 0) - return 1; - av_set_cpu_flags_mask(cpuflags); - break; - } - } - } - - fft_size = 1 << fft_nbits; - tab = av_malloc(fft_size * sizeof(FFTComplex)); - tab1 = av_malloc(fft_size * sizeof(FFTComplex)); - tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); - tab2 = av_malloc(fft_size * sizeof(FFTSample)); - - if (!(tab && tab1 && tab_ref && tab2)) - goto cleanup; - - switch (transform) { -#if CONFIG_MDCT - case TRANSFORM_MDCT: - av_log(NULL, AV_LOG_INFO, "Scale factor is set to %f\n", scale); - if (do_inverse) - av_log(NULL, AV_LOG_INFO, "IMDCT"); - else - av_log(NULL, AV_LOG_INFO, "MDCT"); - ff_mdct_init(&m, fft_nbits, do_inverse, scale); - break; -#endif /* CONFIG_MDCT */ - case TRANSFORM_FFT: - if (do_inverse) - av_log(NULL, AV_LOG_INFO, "IFFT"); - else - av_log(NULL, AV_LOG_INFO, "FFT"); - ff_fft_init(&s, fft_nbits, do_inverse); - if (err = fft_ref_init(fft_nbits, do_inverse) < 0) - goto cleanup; - break; -#if FFT_FLOAT -#if CONFIG_RDFT - case TRANSFORM_RDFT: - if (do_inverse) - av_log(NULL, AV_LOG_INFO, "IDFT_C2R"); - else - av_log(NULL, AV_LOG_INFO, "DFT_R2C"); - ff_rdft_init(&r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C); - if (err = fft_ref_init(fft_nbits, do_inverse) < 0) - goto cleanup; - break; -#endif /* CONFIG_RDFT */ -#if CONFIG_DCT - case TRANSFORM_DCT: - if (do_inverse) - av_log(NULL, AV_LOG_INFO, "DCT_III"); - else - av_log(NULL, AV_LOG_INFO, "DCT_II"); - ff_dct_init(&d, fft_nbits, do_inverse ? DCT_III : DCT_II); - break; -#endif /* CONFIG_DCT */ -#endif /* FFT_FLOAT */ - default: - av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n"); - goto cleanup; - } - av_log(NULL, AV_LOG_INFO, " %d test\n", fft_size); - - /* generate random data */ - - for (i = 0; i < fft_size; i++) { - tab1[i].re = frandom(&prng); - tab1[i].im = frandom(&prng); - } - - /* checking result */ - av_log(NULL, AV_LOG_INFO, "Checking...\n"); - - switch (transform) { -#if CONFIG_MDCT - case TRANSFORM_MDCT: - if (do_inverse) { - imdct_ref(&tab_ref->re, &tab1->re, fft_nbits); - m.imdct_calc(&m, tab2, &tab1->re); - err = check_diff(&tab_ref->re, tab2, fft_size, scale); - } else { - mdct_ref(&tab_ref->re, &tab1->re, fft_nbits); - m.mdct_calc(&m, tab2, &tab1->re); - err = check_diff(&tab_ref->re, tab2, fft_size / 2, scale); - } - break; -#endif /* CONFIG_MDCT */ - case TRANSFORM_FFT: - memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); - s.fft_permute(&s, tab); - s.fft_calc(&s, tab); - - fft_ref(tab_ref, tab1, fft_nbits); - err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 1.0); - break; -#if FFT_FLOAT -#if CONFIG_RDFT - case TRANSFORM_RDFT: - { - int fft_size_2 = fft_size >> 1; - if (do_inverse) { - tab1[0].im = 0; - tab1[fft_size_2].im = 0; - for (i = 1; i < fft_size_2; i++) { - tab1[fft_size_2 + i].re = tab1[fft_size_2 - i].re; - tab1[fft_size_2 + i].im = -tab1[fft_size_2 - i].im; - } - - memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); - tab2[1] = tab1[fft_size_2].re; - - r.rdft_calc(&r, tab2); - fft_ref(tab_ref, tab1, fft_nbits); - for (i = 0; i < fft_size; i++) { - tab[i].re = tab2[i]; - tab[i].im = 0; - } - err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 0.5); - } else { - for (i = 0; i < fft_size; i++) { - tab2[i] = tab1[i].re; - tab1[i].im = 0; - } - r.rdft_calc(&r, tab2); - fft_ref(tab_ref, tab1, fft_nbits); - tab_ref[0].im = tab_ref[fft_size_2].re; - err = check_diff(&tab_ref->re, tab2, fft_size, 1.0); - } - break; - } -#endif /* CONFIG_RDFT */ -#if CONFIG_DCT - case TRANSFORM_DCT: - memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); - d.dct_calc(&d, &tab->re); - if (do_inverse) - idct_ref(&tab_ref->re, &tab1->re, fft_nbits); - else - dct_ref(&tab_ref->re, &tab1->re, fft_nbits); - err = check_diff(&tab_ref->re, &tab->re, fft_size, 1.0); - break; -#endif /* CONFIG_DCT */ -#endif /* FFT_FLOAT */ - } - - /* do a speed test */ - - if (do_speed) { - int64_t time_start, duration; - int nb_its; - - av_log(NULL, AV_LOG_INFO, "Speed test...\n"); - /* we measure during about 1 seconds */ - nb_its = 1; - for (;;) { - time_start = av_gettime_relative(); - for (it = 0; it < nb_its; it++) { - switch (transform) { - case TRANSFORM_MDCT: - if (do_inverse) - m.imdct_calc(&m, &tab->re, &tab1->re); - else - m.mdct_calc(&m, &tab->re, &tab1->re); - break; - case TRANSFORM_FFT: - memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); - s.fft_calc(&s, tab); - break; -#if FFT_FLOAT - case TRANSFORM_RDFT: - memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); - r.rdft_calc(&r, tab2); - break; - case TRANSFORM_DCT: - memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); - d.dct_calc(&d, tab2); - break; -#endif /* FFT_FLOAT */ - } - } - duration = av_gettime_relative() - time_start; - if (duration >= 1000000) - break; - nb_its *= 2; - } - av_log(NULL, AV_LOG_INFO, - "time: %0.1f us/transform [total time=%0.2f s its=%d]\n", - (double) duration / nb_its, - (double) duration / 1000000.0, - nb_its); - } - - switch (transform) { -#if CONFIG_MDCT - case TRANSFORM_MDCT: - ff_mdct_end(&m); - break; -#endif /* CONFIG_MDCT */ - case TRANSFORM_FFT: - ff_fft_end(&s); - break; -#if FFT_FLOAT -#if CONFIG_RDFT - case TRANSFORM_RDFT: - ff_rdft_end(&r); - break; -#endif /* CONFIG_RDFT */ -#if CONFIG_DCT - case TRANSFORM_DCT: - ff_dct_end(&d); - break; -#endif /* CONFIG_DCT */ -#endif /* FFT_FLOAT */ - } - -cleanup: - av_free(tab); - av_free(tab1); - av_free(tab2); - av_free(tab_ref); - av_free(exptab); - - if (err) - printf("Error: %d.\n", err); - - return !!err; -} diff --git a/libavcodec/golomb-test.c b/libavcodec/golomb-test.c deleted file mode 100644 index e740a20aea..0000000000 --- a/libavcodec/golomb-test.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "libavutil/mem.h" - -#include "get_bits.h" -#include "golomb.h" -#include "put_bits.h" - -#define COUNT 8191 -#define SIZE (COUNT * 4) - -int main(void) -{ - int i, ret = 0; - uint8_t *temp; - PutBitContext pb; - GetBitContext gb; - - temp = av_malloc(SIZE); - if (!temp) - return 2; - - init_put_bits(&pb, temp, SIZE); - for (i = 0; i < COUNT; i++) - set_ue_golomb(&pb, i); - flush_put_bits(&pb); - - init_get_bits(&gb, temp, 8 * SIZE); - for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 25); - - j = get_ue_golomb(&gb); - if (j != i) { - fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", - i, j, s); - ret = 1; - } - } - -#define EXTEND(i) (i << 3 | i & 7) - init_put_bits(&pb, temp, SIZE); - for (i = 0; i < COUNT; i++) - set_ue_golomb(&pb, EXTEND(i)); - flush_put_bits(&pb); - - init_get_bits(&gb, temp, 8 * SIZE); - for (i = 0; i < COUNT; i++) { - int j, s = show_bits_long(&gb, 32); - - j = get_ue_golomb_long(&gb); - if (j != EXTEND(i)) { - fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " - "bits: %8x\n", EXTEND(i), j, s); - ret = 1; - } - } - - init_put_bits(&pb, temp, SIZE); - for (i = 0; i < COUNT; i++) - set_se_golomb(&pb, i - COUNT / 2); - flush_put_bits(&pb); - - init_get_bits(&gb, temp, 8 * SIZE); - for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 25); - - j = get_se_golomb(&gb); - if (j != i - COUNT / 2) { - fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", - i - COUNT / 2, j, s); - ret = 1; - } - } - - av_free(temp); - - return ret; -} diff --git a/libavcodec/iirfilter-test.c b/libavcodec/iirfilter-test.c deleted file mode 100644 index 5aa156cb90..0000000000 --- a/libavcodec/iirfilter-test.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include - -#include "libavutil/libm.h" - -#include "iirfilter.h" - -#define FILT_ORDER 4 -#define SIZE 1024 - -int main(void) -{ - struct FFIIRFilterCoeffs *fcoeffs = NULL; - struct FFIIRFilterState *fstate = NULL; - float cutoff_coeff = 0.4; - int16_t x[SIZE], y[SIZE]; - int i; - - fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH, - FF_FILTER_MODE_LOWPASS, FILT_ORDER, - cutoff_coeff, 0.0, 0.0); - fstate = ff_iir_filter_init_state(FILT_ORDER); - - for (i = 0; i < SIZE; i++) - x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE)); - - ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1); - - for (i = 0; i < SIZE; i++) - printf("%6d %6d\n", x[i], y[i]); - - ff_iir_filter_free_coeffs(fcoeffs); - ff_iir_filter_free_state(fstate); - return 0; -} diff --git a/libavcodec/ppc/dct-test.c b/libavcodec/ppc/dct-test.c deleted file mode 100644 index 2acbe2aeb0..0000000000 --- a/libavcodec/ppc/dct-test.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "fdct.h" - -static const struct algo fdct_tab_arch[] = { -#if HAVE_ALTIVEC && HAVE_BIGENDIAN - { "altivecfdct", ff_fdct_altivec, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ALTIVEC }, -#endif - { 0 } -}; - -static const struct algo idct_tab_arch[] = { - { 0 } -}; diff --git a/libavcodec/rangecoder-test.c b/libavcodec/rangecoder-test.c deleted file mode 100644 index f4c76c01f0..0000000000 --- a/libavcodec/rangecoder-test.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "libavutil/lfg.h" -#include "libavutil/log.h" - -#include "rangecoder.h" - -#define SIZE 10240 - -int main(void) -{ - RangeCoder c; - uint8_t b[9 * SIZE]; - uint8_t r[9 * SIZE]; - int i; - uint8_t state[10]; - AVLFG prng; - - av_lfg_init(&prng, 1); - - ff_init_range_encoder(&c, b, SIZE); - ff_build_rac_states(&c, 0.05 * (1LL << 32), 128 + 64 + 32 + 16); - - memset(state, 128, sizeof(state)); - - for (i = 0; i < SIZE; i++) - r[i] = av_lfg_get(&prng) % 7; - - for (i = 0; i < SIZE; i++) - put_rac(&c, state, r[i] & 1); - - ff_rac_terminate(&c); - - ff_init_range_decoder(&c, b, SIZE); - - memset(state, 128, sizeof(state)); - - for (i = 0; i < SIZE; i++) - if ((r[i] & 1) != get_rac(&c, state)) { - av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); - return 1; - } - - return 0; -} diff --git a/libavcodec/tests/.gitignore b/libavcodec/tests/.gitignore new file mode 100644 index 0000000000..31fa59b018 --- /dev/null +++ b/libavcodec/tests/.gitignore @@ -0,0 +1,6 @@ +/dct +/fft +/fft-fixed +/golomb +/iirfilter +/rangecoder diff --git a/libavcodec/tests/arm/dct.c b/libavcodec/tests/arm/dct.c new file mode 100644 index 0000000000..d18cb52b60 --- /dev/null +++ b/libavcodec/tests/arm/dct.c @@ -0,0 +1,40 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavcodec/arm/idct.h" + +static const struct algo fdct_tab_arch[] = { + { 0 } +}; + +static const struct algo idct_tab_arch[] = { + { "SIMPLE-ARM", ff_simple_idct_arm, FF_IDCT_PERM_NONE }, + { "INT-ARM", ff_j_rev_dct_arm, FF_IDCT_PERM_LIBMPEG2 }, +#if HAVE_ARMV5TE + { "SIMPLE-ARMV5TE", ff_simple_idct_armv5te, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ARMV5TE }, +#endif +#if HAVE_ARMV6 + { "SIMPLE-ARMV6", ff_simple_idct_armv6, FF_IDCT_PERM_LIBMPEG2, AV_CPU_FLAG_ARMV6 }, +#endif +#if HAVE_NEON + { "SIMPLE-NEON", ff_simple_idct_neon, FF_IDCT_PERM_PARTTRANS, AV_CPU_FLAG_NEON }, +#endif + { 0 } +}; diff --git a/libavcodec/tests/dct.c b/libavcodec/tests/dct.c new file mode 100644 index 0000000000..6c6a4e0d0d --- /dev/null +++ b/libavcodec/tests/dct.c @@ -0,0 +1,472 @@ +/* + * (c) 2001 Fabrice Bellard + * 2007 Marc Hoffman + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * DCT test (c) 2001 Fabrice Bellard + * Started from sample code by Juan J. Sierralta P. + */ + +#include "config.h" +#include +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include + +#include "libavutil/cpu.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/lfg.h" +#include "libavutil/time.h" + +#include "libavcodec/aandcttab.h" +#include "libavcodec/dct.h" +#include "libavcodec/dctref.h" +#include "libavcodec/faandct.h" +#include "libavcodec/faanidct.h" +#include "libavcodec/idctdsp.h" +#include "libavcodec/simple_idct.h" +#include "libavcodec/xvididct.h" + +struct algo { + const char *name; + void (*func)(int16_t *block); + enum idct_permutation_type perm_type; + int cpu_flag; + int nonspec; +}; + +static const struct algo fdct_tab[] = { + { "REF-DBL", ff_ref_fdct, FF_IDCT_PERM_NONE }, + { "IJG-AAN-INT", ff_fdct_ifast, FF_IDCT_PERM_NONE }, + { "IJG-LLM-INT", ff_jpeg_fdct_islow_8, FF_IDCT_PERM_NONE }, +#if CONFIG_FAANDCT + { "FAAN", ff_faandct, FF_IDCT_PERM_NONE }, +#endif /* CONFIG_FAANDCT */ +}; + +static const struct algo idct_tab[] = { + { "REF-DBL", ff_ref_idct, FF_IDCT_PERM_NONE }, + { "INT", ff_j_rev_dct, FF_IDCT_PERM_LIBMPEG2 }, + { "SIMPLE-C", ff_simple_idct_8, FF_IDCT_PERM_NONE }, +#if CONFIG_FAANIDCT + { "FAANI", ff_faanidct, FF_IDCT_PERM_NONE }, +#endif /* CONFIG_FAANIDCT */ +#if CONFIG_MPEG4_DECODER + { "XVID", ff_xvid_idct, FF_IDCT_PERM_NONE, 0, 1 }, +#endif /* CONFIG_MPEG4_DECODER */ +}; + +#if ARCH_ARM +#include "arm/dct.c" +#elif ARCH_PPC +#include "ppc/dct.c" +#elif ARCH_X86 +#include "x86/dct.c" +#else +static const struct algo fdct_tab_arch[] = { { 0 } }; +static const struct algo idct_tab_arch[] = { { 0 } }; +#endif + +#define AANSCALE_BITS 12 + +#define NB_ITS 20000 +#define NB_ITS_SPEED 50000 + +DECLARE_ALIGNED(16, static int16_t, block)[64]; +DECLARE_ALIGNED(8, static int16_t, block1)[64]; + +static void init_block(int16_t block[64], int test, int is_idct, AVLFG *prng) +{ + int i, j; + + memset(block, 0, 64 * sizeof(*block)); + + switch (test) { + case 0: + for (i = 0; i < 64; i++) + block[i] = (av_lfg_get(prng) % 512) - 256; + if (is_idct) { + ff_ref_fdct(block); + for (i = 0; i < 64; i++) + block[i] >>= 3; + } + break; + case 1: + j = av_lfg_get(prng) % 10 + 1; + for (i = 0; i < j; i++) + block[av_lfg_get(prng) % 64] = av_lfg_get(prng) % 512 - 256; + break; + case 2: + block[ 0] = av_lfg_get(prng) % 4096 - 2048; + block[63] = (block[0] & 1) ^ 1; + break; + } +} + +static void permute(int16_t dst[64], const int16_t src[64], + enum idct_permutation_type perm_type) +{ + int i; + +#if ARCH_X86 + if (permute_x86(dst, src, perm_type)) + return; +#endif + + switch (perm_type) { + case FF_IDCT_PERM_LIBMPEG2: + for (i = 0; i < 64; i++) + dst[(i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2)] = src[i]; + break; + case FF_IDCT_PERM_PARTTRANS: + for (i = 0; i < 64; i++) + dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i]; + break; + default: + for (i = 0; i < 64; i++) + dst[i] = src[i]; + break; + } +} + +static int dct_error(const struct algo *dct, int test, int is_idct, int speed) +{ + void (*ref)(int16_t *block) = is_idct ? ff_ref_idct : ff_ref_fdct; + int it, i, scale; + int err_inf, v; + int64_t err2, ti, ti1, it1, err_sum = 0; + int64_t sysErr[64], sysErrMax = 0; + int maxout = 0; + int blockSumErrMax = 0, blockSumErr; + AVLFG prng; + double omse, ome; + int spec_err; + + av_lfg_init(&prng, 1); + + err_inf = 0; + err2 = 0; + for (i = 0; i < 64; i++) + sysErr[i] = 0; + for (it = 0; it < NB_ITS; it++) { + init_block(block1, test, is_idct, &prng); + permute(block, block1, dct->perm_type); + + dct->func(block); + emms_c(); + + if (!strcmp(dct->name, "IJG-AAN-INT")) { + for (i = 0; i < 64; i++) { + scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i]; + block[i] = (block[i] * scale) >> AANSCALE_BITS; + } + } + + ref(block1); + + blockSumErr = 0; + for (i = 0; i < 64; i++) { + int err = block[i] - block1[i]; + err_sum += err; + v = abs(err); + if (v > err_inf) + err_inf = v; + err2 += v * v; + sysErr[i] += block[i] - block1[i]; + blockSumErr += v; + if (abs(block[i]) > maxout) + maxout = abs(block[i]); + } + if (blockSumErrMax < blockSumErr) + blockSumErrMax = blockSumErr; + } + for (i = 0; i < 64; i++) + sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i])); + + for (i = 0; i < 64; i++) { + if (i % 8 == 0) + printf("\n"); + printf("%7d ", (int) sysErr[i]); + } + printf("\n"); + + omse = (double) err2 / NB_ITS / 64; + ome = (double) err_sum / NB_ITS / 64; + + spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015); + + printf("%s %s: ppe=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", + is_idct ? "IDCT" : "DCT", dct->name, err_inf, + omse, ome, (double) sysErrMax / NB_ITS, + maxout, blockSumErrMax); + + if (spec_err && !dct->nonspec) + return 1; + + if (!speed) + return 0; + + /* speed test */ + init_block(block, test, is_idct, &prng); + permute(block1, block, dct->perm_type); + + ti = av_gettime_relative(); + it1 = 0; + do { + for (it = 0; it < NB_ITS_SPEED; it++) { + memcpy(block, block1, sizeof(block)); + dct->func(block); + } + it1 += NB_ITS_SPEED; + ti1 = av_gettime_relative() - ti; + } while (ti1 < 1000000); + emms_c(); + + printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name, + (double) it1 * 1000.0 / (double) ti1); + + return 0; +} + +DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; +DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64]; + +static void idct248_ref(uint8_t *dest, int linesize, int16_t *block) +{ + static int init; + static double c8[8][8]; + static double c4[4][4]; + double block1[64], block2[64], block3[64]; + double s, sum, v; + int i, j, k; + + if (!init) { + init = 1; + + for (i = 0; i < 8; i++) { + sum = 0; + for (j = 0; j < 8; j++) { + s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0); + c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0); + sum += c8[i][j] * c8[i][j]; + } + } + + for (i = 0; i < 4; i++) { + sum = 0; + for (j = 0; j < 4; j++) { + s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0); + c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0); + sum += c4[i][j] * c4[i][j]; + } + } + } + + /* butterfly */ + s = 0.5 * sqrt(2.0); + for (i = 0; i < 4; i++) { + for (j = 0; j < 8; j++) { + block1[8 * (2 * i) + j] = + (block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s; + block1[8 * (2 * i + 1) + j] = + (block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s; + } + } + + /* idct8 on lines */ + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + sum = 0; + for (k = 0; k < 8; k++) + sum += c8[k][j] * block1[8 * i + k]; + block2[8 * i + j] = sum; + } + } + + /* idct4 */ + for (i = 0; i < 8; i++) { + for (j = 0; j < 4; j++) { + /* top */ + sum = 0; + for (k = 0; k < 4; k++) + sum += c4[k][j] * block2[8 * (2 * k) + i]; + block3[8 * (2 * j) + i] = sum; + + /* bottom */ + sum = 0; + for (k = 0; k < 4; k++) + sum += c4[k][j] * block2[8 * (2 * k + 1) + i]; + block3[8 * (2 * j + 1) + i] = sum; + } + } + + /* clamp and store the result */ + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + v = block3[8 * i + j]; + if (v < 0) v = 0; + else if (v > 255) v = 255; + dest[i * linesize + j] = (int) rint(v); + } + } +} + +static void idct248_error(const char *name, + void (*idct248_put)(uint8_t *dest, int line_size, + int16_t *block), + int speed) +{ + int it, i, it1, ti, ti1, err_max, v; + AVLFG prng; + + av_lfg_init(&prng, 1); + + /* just one test to see if code is correct (precision is less + important here) */ + err_max = 0; + for (it = 0; it < NB_ITS; it++) { + /* XXX: use forward transform to generate values */ + for (i = 0; i < 64; i++) + block1[i] = av_lfg_get(&prng) % 256 - 128; + block1[0] += 1024; + + for (i = 0; i < 64; i++) + block[i] = block1[i]; + idct248_ref(img_dest1, 8, block); + + for (i = 0; i < 64; i++) + block[i] = block1[i]; + idct248_put(img_dest, 8, block); + + for (i = 0; i < 64; i++) { + v = abs((int) img_dest[i] - (int) img_dest1[i]); + if (v == 255) + printf("%d %d\n", img_dest[i], img_dest1[i]); + if (v > err_max) + err_max = v; + } + } + printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max); + + if (!speed) + return; + + ti = av_gettime_relative(); + it1 = 0; + do { + for (it = 0; it < NB_ITS_SPEED; it++) { + for (i = 0; i < 64; i++) + block[i] = block1[i]; + idct248_put(img_dest, 8, block); + } + it1 += NB_ITS_SPEED; + ti1 = av_gettime_relative() - ti; + } while (ti1 < 1000000); + emms_c(); + + printf("%s %s: %0.1f kdct/s\n", 1 ? "IDCT248" : "DCT248", name, + (double) it1 * 1000.0 / (double) ti1); +} + +static void help(void) +{ + printf("dct-test [-i] []\n" + "test-number 0 -> test with random matrixes\n" + " 1 -> test with random sparse matrixes\n" + " 2 -> do 3. test from MPEG-4 std\n" + "-i test IDCT implementations\n" + "-4 test IDCT248 implementations\n" + "-t speed test\n"); +} + +#if !HAVE_GETOPT +#include "compat/getopt.c" +#endif + +int main(int argc, char **argv) +{ + int test_idct = 0, test_248_dct = 0; + int c, i; + int test = 1; + int speed = 0; + int err = 0; + + ff_ref_dct_init(); + + for (;;) { + c = getopt(argc, argv, "ih4t"); + if (c == -1) + break; + switch (c) { + case 'i': + test_idct = 1; + break; + case '4': + test_248_dct = 1; + break; + case 't': + speed = 1; + break; + default: + case 'h': + help(); + return 0; + } + } + + if (optind < argc) + test = atoi(argv[optind]); + + printf("Libav DCT/IDCT test\n"); + + if (test_248_dct) { + idct248_error("SIMPLE-C", ff_simple_idct248_put, speed); + } else { + const int cpu_flags = av_get_cpu_flags(); + if (test_idct) { + for (i = 0; i < FF_ARRAY_ELEMS(idct_tab); i++) + err |= dct_error(&idct_tab[i], test, test_idct, speed); + + for (i = 0; idct_tab_arch[i].name; i++) + if (!(~cpu_flags & idct_tab_arch[i].cpu_flag)) + err |= dct_error(&idct_tab_arch[i], test, test_idct, speed); + } +#if CONFIG_FDCTDSP + else { + for (i = 0; i < FF_ARRAY_ELEMS(fdct_tab); i++) + err |= dct_error(&fdct_tab[i], test, test_idct, speed); + + for (i = 0; fdct_tab_arch[i].name; i++) + if (!(~cpu_flags & fdct_tab_arch[i].cpu_flag)) + err |= dct_error(&fdct_tab_arch[i], test, test_idct, speed); + } +#endif /* CONFIG_FDCTDSP */ + } + + if (err) + printf("Error: %d.\n", err); + + return !!err; +} diff --git a/libavcodec/tests/fft-fixed.c b/libavcodec/tests/fft-fixed.c new file mode 100644 index 0000000000..6edd810b25 --- /dev/null +++ b/libavcodec/tests/fft-fixed.c @@ -0,0 +1,20 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define FFT_FLOAT 0 +#include "fft.c" diff --git a/libavcodec/tests/fft.c b/libavcodec/tests/fft.c new file mode 100644 index 0000000000..db1ce9807f --- /dev/null +++ b/libavcodec/tests/fft.c @@ -0,0 +1,513 @@ +/* + * (c) 2002 Fabrice Bellard + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * FFT and MDCT tests. + */ + +#include "config.h" + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#include + +#include "libavutil/cpu.h" +#include "libavutil/lfg.h" +#include "libavutil/log.h" +#include "libavutil/mathematics.h" +#include "libavutil/time.h" + +#include "libavcodec/fft.h" +#if FFT_FLOAT +#include "libavcodec/dct.h" +#include "libavcodec/rdft.h" +#endif + +/* reference fft */ + +#define MUL16(a, b) ((a) * (b)) + +#define CMAC(pre, pim, are, aim, bre, bim) \ + { \ + pre += (MUL16(are, bre) - MUL16(aim, bim)); \ + pim += (MUL16(are, bim) + MUL16(bre, aim)); \ + } + +#if FFT_FLOAT +#define RANGE 1.0 +#define REF_SCALE(x, bits) (x) +#define FMT "%10.6f" +#else +#define RANGE 16384 +#define REF_SCALE(x, bits) ((x) / (1 << (bits))) +#define FMT "%6d" +#endif + +static struct { + float re, im; +} *exptab; + +static int fft_ref_init(int nbits, int inverse) +{ + int i, n = 1 << nbits; + + exptab = av_malloc((n / 2) * sizeof(*exptab)); + if (!exptab) + return AVERROR(ENOMEM); + + for (i = 0; i < (n / 2); i++) { + double alpha = 2 * M_PI * (float) i / (float) n; + double c1 = cos(alpha), s1 = sin(alpha); + if (!inverse) + s1 = -s1; + exptab[i].re = c1; + exptab[i].im = s1; + } + return 0; +} + +static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) +{ + int i, j; + int n = 1 << nbits; + int n2 = n >> 1; + + for (i = 0; i < n; i++) { + double tmp_re = 0, tmp_im = 0; + FFTComplex *q = tab; + for (j = 0; j < n; j++) { + double s, c; + int k = (i * j) & (n - 1); + if (k >= n2) { + c = -exptab[k - n2].re; + s = -exptab[k - n2].im; + } else { + c = exptab[k].re; + s = exptab[k].im; + } + CMAC(tmp_re, tmp_im, c, s, q->re, q->im); + q++; + } + tabr[i].re = REF_SCALE(tmp_re, nbits); + tabr[i].im = REF_SCALE(tmp_im, nbits); + } +} + +#if CONFIG_MDCT +static void imdct_ref(FFTSample *out, FFTSample *in, int nbits) +{ + int i, k, n = 1 << nbits; + + for (i = 0; i < n; i++) { + double sum = 0; + for (k = 0; k < n / 2; k++) { + int a = (2 * i + 1 + (n / 2)) * (2 * k + 1); + double f = cos(M_PI * a / (double) (2 * n)); + sum += f * in[k]; + } + out[i] = REF_SCALE(-sum, nbits - 2); + } +} + +/* NOTE: no normalisation by 1 / N is done */ +static void mdct_ref(FFTSample *output, FFTSample *input, int nbits) +{ + int i, k, n = 1 << nbits; + + /* do it by hand */ + for (k = 0; k < n / 2; k++) { + double s = 0; + for (i = 0; i < n; i++) { + double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n)); + s += input[i] * cos(a); + } + output[k] = REF_SCALE(s, nbits - 1); + } +} +#endif /* CONFIG_MDCT */ + +#if FFT_FLOAT +#if CONFIG_DCT +static void idct_ref(float *output, float *input, int nbits) +{ + int i, k, n = 1 << nbits; + + /* do it by hand */ + for (i = 0; i < n; i++) { + double s = 0.5 * input[0]; + for (k = 1; k < n; k++) { + double a = M_PI * k * (i + 0.5) / n; + s += input[k] * cos(a); + } + output[i] = 2 * s / n; + } +} + +static void dct_ref(float *output, float *input, int nbits) +{ + int i, k, n = 1 << nbits; + + /* do it by hand */ + for (k = 0; k < n; k++) { + double s = 0; + for (i = 0; i < n; i++) { + double a = M_PI * k * (i + 0.5) / n; + s += input[i] * cos(a); + } + output[k] = s; + } +} +#endif /* CONFIG_DCT */ +#endif /* FFT_FLOAT */ + +static FFTSample frandom(AVLFG *prng) +{ + return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE; +} + +static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale) +{ + int i, err = 0; + double error = 0, max = 0; + + for (i = 0; i < n; i++) { + double e = fabs(tab1[i] - (tab2[i] / scale)) / RANGE; + if (e >= 1e-3) { + av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n", + i, tab1[i], tab2[i]); + err = 1; + } + error += e * e; + if (e > max) + max = e; + } + av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error) / n); + return err; +} + +static void help(void) +{ + av_log(NULL, AV_LOG_INFO, + "usage: fft-test [-h] [-s] [-i] [-n b]\n" + "-h print this help\n" + "-s speed test\n" + "-m (I)MDCT test\n" + "-d (I)DCT test\n" + "-r (I)RDFT test\n" + "-i inverse transform test\n" + "-n b set the transform size to 2^b\n" + "-f x set scale factor for output data of (I)MDCT to x\n"); +} + +enum tf_transform { + TRANSFORM_FFT, + TRANSFORM_MDCT, + TRANSFORM_RDFT, + TRANSFORM_DCT, +}; + +#if !HAVE_GETOPT +#include "compat/getopt.c" +#endif + +int main(int argc, char **argv) +{ + FFTComplex *tab, *tab1, *tab_ref; + FFTSample *tab2; + enum tf_transform transform = TRANSFORM_FFT; + FFTContext m, s; +#if FFT_FLOAT + RDFTContext r; + DCTContext d; +#endif /* FFT_FLOAT */ + int it, i, err = 1; + int do_speed = 0, do_inverse = 0; + int fft_nbits = 9, fft_size; + double scale = 1.0; + AVLFG prng; + + av_lfg_init(&prng, 1); + + for (;;) { + int c = getopt(argc, argv, "hsimrdn:f:c:"); + if (c == -1) + break; + switch (c) { + case 'h': + help(); + return 1; + case 's': + do_speed = 1; + break; + case 'i': + do_inverse = 1; + break; + case 'm': + transform = TRANSFORM_MDCT; + break; + case 'r': + transform = TRANSFORM_RDFT; + break; + case 'd': + transform = TRANSFORM_DCT; + break; + case 'n': + fft_nbits = atoi(optarg); + break; + case 'f': + scale = atof(optarg); + break; + case 'c': + { + int cpuflags = av_parse_cpu_flags(optarg); + if (cpuflags < 0) + return 1; + av_set_cpu_flags_mask(cpuflags); + break; + } + } + } + + fft_size = 1 << fft_nbits; + tab = av_malloc(fft_size * sizeof(FFTComplex)); + tab1 = av_malloc(fft_size * sizeof(FFTComplex)); + tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); + tab2 = av_malloc(fft_size * sizeof(FFTSample)); + + if (!(tab && tab1 && tab_ref && tab2)) + goto cleanup; + + switch (transform) { +#if CONFIG_MDCT + case TRANSFORM_MDCT: + av_log(NULL, AV_LOG_INFO, "Scale factor is set to %f\n", scale); + if (do_inverse) + av_log(NULL, AV_LOG_INFO, "IMDCT"); + else + av_log(NULL, AV_LOG_INFO, "MDCT"); + ff_mdct_init(&m, fft_nbits, do_inverse, scale); + break; +#endif /* CONFIG_MDCT */ + case TRANSFORM_FFT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO, "IFFT"); + else + av_log(NULL, AV_LOG_INFO, "FFT"); + ff_fft_init(&s, fft_nbits, do_inverse); + if (err = fft_ref_init(fft_nbits, do_inverse) < 0) + goto cleanup; + break; +#if FFT_FLOAT +#if CONFIG_RDFT + case TRANSFORM_RDFT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO, "IDFT_C2R"); + else + av_log(NULL, AV_LOG_INFO, "DFT_R2C"); + ff_rdft_init(&r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C); + if (err = fft_ref_init(fft_nbits, do_inverse) < 0) + goto cleanup; + break; +#endif /* CONFIG_RDFT */ +#if CONFIG_DCT + case TRANSFORM_DCT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO, "DCT_III"); + else + av_log(NULL, AV_LOG_INFO, "DCT_II"); + ff_dct_init(&d, fft_nbits, do_inverse ? DCT_III : DCT_II); + break; +#endif /* CONFIG_DCT */ +#endif /* FFT_FLOAT */ + default: + av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n"); + goto cleanup; + } + av_log(NULL, AV_LOG_INFO, " %d test\n", fft_size); + + /* generate random data */ + + for (i = 0; i < fft_size; i++) { + tab1[i].re = frandom(&prng); + tab1[i].im = frandom(&prng); + } + + /* checking result */ + av_log(NULL, AV_LOG_INFO, "Checking...\n"); + + switch (transform) { +#if CONFIG_MDCT + case TRANSFORM_MDCT: + if (do_inverse) { + imdct_ref(&tab_ref->re, &tab1->re, fft_nbits); + m.imdct_calc(&m, tab2, &tab1->re); + err = check_diff(&tab_ref->re, tab2, fft_size, scale); + } else { + mdct_ref(&tab_ref->re, &tab1->re, fft_nbits); + m.mdct_calc(&m, tab2, &tab1->re); + err = check_diff(&tab_ref->re, tab2, fft_size / 2, scale); + } + break; +#endif /* CONFIG_MDCT */ + case TRANSFORM_FFT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); + s.fft_permute(&s, tab); + s.fft_calc(&s, tab); + + fft_ref(tab_ref, tab1, fft_nbits); + err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 1.0); + break; +#if FFT_FLOAT +#if CONFIG_RDFT + case TRANSFORM_RDFT: + { + int fft_size_2 = fft_size >> 1; + if (do_inverse) { + tab1[0].im = 0; + tab1[fft_size_2].im = 0; + for (i = 1; i < fft_size_2; i++) { + tab1[fft_size_2 + i].re = tab1[fft_size_2 - i].re; + tab1[fft_size_2 + i].im = -tab1[fft_size_2 - i].im; + } + + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); + tab2[1] = tab1[fft_size_2].re; + + r.rdft_calc(&r, tab2); + fft_ref(tab_ref, tab1, fft_nbits); + for (i = 0; i < fft_size; i++) { + tab[i].re = tab2[i]; + tab[i].im = 0; + } + err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 0.5); + } else { + for (i = 0; i < fft_size; i++) { + tab2[i] = tab1[i].re; + tab1[i].im = 0; + } + r.rdft_calc(&r, tab2); + fft_ref(tab_ref, tab1, fft_nbits); + tab_ref[0].im = tab_ref[fft_size_2].re; + err = check_diff(&tab_ref->re, tab2, fft_size, 1.0); + } + break; + } +#endif /* CONFIG_RDFT */ +#if CONFIG_DCT + case TRANSFORM_DCT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); + d.dct_calc(&d, &tab->re); + if (do_inverse) + idct_ref(&tab_ref->re, &tab1->re, fft_nbits); + else + dct_ref(&tab_ref->re, &tab1->re, fft_nbits); + err = check_diff(&tab_ref->re, &tab->re, fft_size, 1.0); + break; +#endif /* CONFIG_DCT */ +#endif /* FFT_FLOAT */ + } + + /* do a speed test */ + + if (do_speed) { + int64_t time_start, duration; + int nb_its; + + av_log(NULL, AV_LOG_INFO, "Speed test...\n"); + /* we measure during about 1 seconds */ + nb_its = 1; + for (;;) { + time_start = av_gettime_relative(); + for (it = 0; it < nb_its; it++) { + switch (transform) { + case TRANSFORM_MDCT: + if (do_inverse) + m.imdct_calc(&m, &tab->re, &tab1->re); + else + m.mdct_calc(&m, &tab->re, &tab1->re); + break; + case TRANSFORM_FFT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); + s.fft_calc(&s, tab); + break; +#if FFT_FLOAT + case TRANSFORM_RDFT: + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); + r.rdft_calc(&r, tab2); + break; + case TRANSFORM_DCT: + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); + d.dct_calc(&d, tab2); + break; +#endif /* FFT_FLOAT */ + } + } + duration = av_gettime_relative() - time_start; + if (duration >= 1000000) + break; + nb_its *= 2; + } + av_log(NULL, AV_LOG_INFO, + "time: %0.1f us/transform [total time=%0.2f s its=%d]\n", + (double) duration / nb_its, + (double) duration / 1000000.0, + nb_its); + } + + switch (transform) { +#if CONFIG_MDCT + case TRANSFORM_MDCT: + ff_mdct_end(&m); + break; +#endif /* CONFIG_MDCT */ + case TRANSFORM_FFT: + ff_fft_end(&s); + break; +#if FFT_FLOAT +#if CONFIG_RDFT + case TRANSFORM_RDFT: + ff_rdft_end(&r); + break; +#endif /* CONFIG_RDFT */ +#if CONFIG_DCT + case TRANSFORM_DCT: + ff_dct_end(&d); + break; +#endif /* CONFIG_DCT */ +#endif /* FFT_FLOAT */ + } + +cleanup: + av_free(tab); + av_free(tab1); + av_free(tab2); + av_free(tab_ref); + av_free(exptab); + + if (err) + printf("Error: %d.\n", err); + + return !!err; +} diff --git a/libavcodec/tests/golomb.c b/libavcodec/tests/golomb.c new file mode 100644 index 0000000000..7587402e24 --- /dev/null +++ b/libavcodec/tests/golomb.c @@ -0,0 +1,97 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/mem.h" + +#include "libavcodec/get_bits.h" +#include "libavcodec/put_bits.h" +#include "libavcodec/golomb.h" + +#define COUNT 8191 +#define SIZE (COUNT * 4) + +int main(void) +{ + int i, ret = 0; + uint8_t *temp; + PutBitContext pb; + GetBitContext gb; + + temp = av_malloc(SIZE); + if (!temp) + return 2; + + init_put_bits(&pb, temp, SIZE); + for (i = 0; i < COUNT; i++) + set_ue_golomb(&pb, i); + flush_put_bits(&pb); + + init_get_bits(&gb, temp, 8 * SIZE); + for (i = 0; i < COUNT; i++) { + int j, s = show_bits(&gb, 25); + + j = get_ue_golomb(&gb); + if (j != i) { + fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", + i, j, s); + ret = 1; + } + } + +#define EXTEND(i) (i << 3 | i & 7) + init_put_bits(&pb, temp, SIZE); + for (i = 0; i < COUNT; i++) + set_ue_golomb(&pb, EXTEND(i)); + flush_put_bits(&pb); + + init_get_bits(&gb, temp, 8 * SIZE); + for (i = 0; i < COUNT; i++) { + int j, s = show_bits_long(&gb, 32); + + j = get_ue_golomb_long(&gb); + if (j != EXTEND(i)) { + fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " + "bits: %8x\n", EXTEND(i), j, s); + ret = 1; + } + } + + init_put_bits(&pb, temp, SIZE); + for (i = 0; i < COUNT; i++) + set_se_golomb(&pb, i - COUNT / 2); + flush_put_bits(&pb); + + init_get_bits(&gb, temp, 8 * SIZE); + for (i = 0; i < COUNT; i++) { + int j, s = show_bits(&gb, 25); + + j = get_se_golomb(&gb); + if (j != i - COUNT / 2) { + fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", + i - COUNT / 2, j, s); + ret = 1; + } + } + + av_free(temp); + + return ret; +} diff --git a/libavcodec/tests/iirfilter.c b/libavcodec/tests/iirfilter.c new file mode 100644 index 0000000000..a6001a3270 --- /dev/null +++ b/libavcodec/tests/iirfilter.c @@ -0,0 +1,54 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "libavutil/libm.h" + +#include "libavcodec/iirfilter.h" + +#define FILT_ORDER 4 +#define SIZE 1024 + +int main(void) +{ + struct FFIIRFilterCoeffs *fcoeffs = NULL; + struct FFIIRFilterState *fstate = NULL; + float cutoff_coeff = 0.4; + int16_t x[SIZE], y[SIZE]; + int i; + + fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH, + FF_FILTER_MODE_LOWPASS, FILT_ORDER, + cutoff_coeff, 0.0, 0.0); + fstate = ff_iir_filter_init_state(FILT_ORDER); + + for (i = 0; i < SIZE; i++) + x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE)); + + ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1); + + for (i = 0; i < SIZE; i++) + printf("%6d %6d\n", x[i], y[i]); + + ff_iir_filter_free_coeffs(fcoeffs); + ff_iir_filter_free_state(fstate); + return 0; +} diff --git a/libavcodec/tests/ppc/dct.c b/libavcodec/tests/ppc/dct.c new file mode 100644 index 0000000000..3d160d33e0 --- /dev/null +++ b/libavcodec/tests/ppc/dct.c @@ -0,0 +1,32 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavcodec/ppc/fdct.h" + +static const struct algo fdct_tab_arch[] = { +#if HAVE_ALTIVEC && HAVE_BIGENDIAN + { "altivecfdct", ff_fdct_altivec, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ALTIVEC }, +#endif + { 0 } +}; + +static const struct algo idct_tab_arch[] = { + { 0 } +}; diff --git a/libavcodec/tests/rangecoder.c b/libavcodec/tests/rangecoder.c new file mode 100644 index 0000000000..26bb589928 --- /dev/null +++ b/libavcodec/tests/rangecoder.c @@ -0,0 +1,64 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/lfg.h" +#include "libavutil/log.h" + +#include "libavcodec/rangecoder.h" + +#define SIZE 10240 + +int main(void) +{ + RangeCoder c; + uint8_t b[9 * SIZE]; + uint8_t r[9 * SIZE]; + int i; + uint8_t state[10]; + AVLFG prng; + + av_lfg_init(&prng, 1); + + ff_init_range_encoder(&c, b, SIZE); + ff_build_rac_states(&c, 0.05 * (1LL << 32), 128 + 64 + 32 + 16); + + memset(state, 128, sizeof(state)); + + for (i = 0; i < SIZE; i++) + r[i] = av_lfg_get(&prng) % 7; + + for (i = 0; i < SIZE; i++) + put_rac(&c, state, r[i] & 1); + + ff_rac_terminate(&c); + + ff_init_range_decoder(&c, b, SIZE); + + memset(state, 128, sizeof(state)); + + for (i = 0; i < SIZE; i++) + if ((r[i] & 1) != get_rac(&c, state)) { + av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); + return 1; + } + + return 0; +} diff --git a/libavcodec/tests/x86/dct.c b/libavcodec/tests/x86/dct.c new file mode 100644 index 0000000000..2ddb55510e --- /dev/null +++ b/libavcodec/tests/x86/dct.c @@ -0,0 +1,86 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavcodec/x86/fdct.h" +#include "libavcodec/x86/xvididct.h" +#include "libavcodec/x86/simple_idct.h" + +static const struct algo fdct_tab_arch[] = { +#if HAVE_MMX_INLINE + { "MMX", ff_fdct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX }, +#endif +#if HAVE_MMXEXT_INLINE + { "MMXEXT", ff_fdct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT }, +#endif +#if HAVE_SSE2_INLINE + { "SSE2", ff_fdct_sse2, FF_IDCT_PERM_NONE, AV_CPU_FLAG_SSE2 }, +#endif + { 0 } +}; + +static const struct algo idct_tab_arch[] = { +#if HAVE_MMX_INLINE + { "SIMPLE-MMX", ff_simple_idct_mmx, FF_IDCT_PERM_SIMPLE, AV_CPU_FLAG_MMX }, +#endif +#if CONFIG_MPEG4_DECODER +#if HAVE_MMX_INLINE + { "XVID-MMX", ff_xvid_idct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX, 1 }, +#endif +#if HAVE_MMXEXT_INLINE + { "XVID-MMXEXT", ff_xvid_idct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT, 1 }, +#endif +#if HAVE_SSE2_INLINE + { "XVID-SSE2", ff_xvid_idct_sse2, FF_IDCT_PERM_SSE2, AV_CPU_FLAG_SSE2, 1 }, +#endif +#endif /* CONFIG_MPEG4_DECODER */ + { 0 } +}; + +static short idct_simple_mmx_perm[64] = { + 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, + 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, + 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, + 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, + 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, + 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, + 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, + 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, +}; + +static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; + +static int permute_x86(int16_t dst[64], const int16_t src[64], + enum idct_permutation_type perm_type) +{ + int i; + + switch (perm_type) { + case FF_IDCT_PERM_SIMPLE: + for (i = 0; i < 64; i++) + dst[idct_simple_mmx_perm[i]] = src[i]; + return 1; + case FF_IDCT_PERM_SSE2: + for (i = 0; i < 64; i++) + dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i]; + return 1; + } + + return 0; +} diff --git a/libavcodec/x86/dct-test.c b/libavcodec/x86/dct-test.c deleted file mode 100644 index 9d4aaf5415..0000000000 --- a/libavcodec/x86/dct-test.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "fdct.h" -#include "xvididct.h" -#include "simple_idct.h" - -static const struct algo fdct_tab_arch[] = { -#if HAVE_MMX_INLINE - { "MMX", ff_fdct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX }, -#endif -#if HAVE_MMXEXT_INLINE - { "MMXEXT", ff_fdct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT }, -#endif -#if HAVE_SSE2_INLINE - { "SSE2", ff_fdct_sse2, FF_IDCT_PERM_NONE, AV_CPU_FLAG_SSE2 }, -#endif - { 0 } -}; - -static const struct algo idct_tab_arch[] = { -#if HAVE_MMX_INLINE - { "SIMPLE-MMX", ff_simple_idct_mmx, FF_IDCT_PERM_SIMPLE, AV_CPU_FLAG_MMX }, -#endif -#if CONFIG_MPEG4_DECODER -#if HAVE_MMX_INLINE - { "XVID-MMX", ff_xvid_idct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX, 1 }, -#endif -#if HAVE_MMXEXT_INLINE - { "XVID-MMXEXT", ff_xvid_idct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT, 1 }, -#endif -#if HAVE_SSE2_INLINE - { "XVID-SSE2", ff_xvid_idct_sse2, FF_IDCT_PERM_SSE2, AV_CPU_FLAG_SSE2, 1 }, -#endif -#endif /* CONFIG_MPEG4_DECODER */ - { 0 } -}; - -static short idct_simple_mmx_perm[64] = { - 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, - 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, - 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, - 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, - 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, - 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, - 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, - 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, -}; - -static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; - -static int permute_x86(int16_t dst[64], const int16_t src[64], - enum idct_permutation_type perm_type) -{ - int i; - - switch (perm_type) { - case FF_IDCT_PERM_SIMPLE: - for (i = 0; i < 64; i++) - dst[idct_simple_mmx_perm[i]] = src[i]; - return 1; - case FF_IDCT_PERM_SSE2: - for (i = 0; i < 64; i++) - dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i]; - return 1; - } - - return 0; -} diff --git a/libavdevice/tests/timefilter.c b/libavdevice/tests/timefilter.c new file mode 100644 index 0000000000..8c7cba2cac --- /dev/null +++ b/libavdevice/tests/timefilter.c @@ -0,0 +1,92 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/common.h" +#include "libavutil/lfg.h" + +#include "libavdevice/timefilter.h" + +#define LFG_MAX ((1LL << 32) - 1) + +int main(void) +{ + AVLFG prng; + double n0, n1; +#define SAMPLES 1000 + double ideal[SAMPLES]; + double samples[SAMPLES]; + for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) { + for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) { + double best_error = 1000000000; + double bestpar0 = 1; + double bestpar1 = 0.001; + int better, i; + + av_lfg_init(&prng, 123); + for (i = 0; i < SAMPLES; i++) { + ideal[i] = 10 + i + n1 * i / (1000); + samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL); + } + + do { + double par0, par1; + better = 0; + for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) { + for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) { + double error = 0; + TimeFilter *tf = ff_timefilter_new(1, par0, par1); + if (!tf) { + printf("Could not allocate memory for timefilter.\n"); + exit(1); + } + for (i = 0; i < SAMPLES; i++) { + double filtered; + filtered = ff_timefilter_update(tf, samples[i], 1); + error += (filtered - ideal[i]) * (filtered - ideal[i]); + } + ff_timefilter_destroy(tf); + if (error < best_error) { + best_error = error; + bestpar0 = par0; + bestpar1 = par1; + better = 1; + } + } + } + } while (better); +#if 0 + double lastfil = 9; + TimeFilter *tf = ff_timefilter_new(1, bestpar0, bestpar1); + for (i = 0; i < SAMPLES; i++) { + double filtered; + filtered = ff_timefilter_update(tf, samples[i], 1); + printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i], + samples[FFMAX(i, 1)] - samples[FFMAX(i - 1, 0)], filtered - lastfil); + lastfil = filtered; + } + ff_timefilter_destroy(tf); +#else + printf(" [%f %f %9f]", bestpar0, bestpar1, best_error); +#endif + } + printf("\n"); + } + return 0; +} diff --git a/libavdevice/timefilter-test.c b/libavdevice/timefilter-test.c deleted file mode 100644 index 5e93f3c8d3..0000000000 --- a/libavdevice/timefilter-test.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "libavutil/common.h" -#include "libavutil/lfg.h" - -#include "timefilter.h" - -#define LFG_MAX ((1LL << 32) - 1) - -int main(void) -{ - AVLFG prng; - double n0, n1; -#define SAMPLES 1000 - double ideal[SAMPLES]; - double samples[SAMPLES]; - for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) { - for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) { - double best_error = 1000000000; - double bestpar0 = 1; - double bestpar1 = 0.001; - int better, i; - - av_lfg_init(&prng, 123); - for (i = 0; i < SAMPLES; i++) { - ideal[i] = 10 + i + n1 * i / (1000); - samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL); - } - - do { - double par0, par1; - better = 0; - for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) { - for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) { - double error = 0; - TimeFilter *tf = ff_timefilter_new(1, par0, par1); - if (!tf) { - printf("Could not allocate memory for timefilter.\n"); - exit(1); - } - for (i = 0; i < SAMPLES; i++) { - double filtered; - filtered = ff_timefilter_update(tf, samples[i], 1); - error += (filtered - ideal[i]) * (filtered - ideal[i]); - } - ff_timefilter_destroy(tf); - if (error < best_error) { - best_error = error; - bestpar0 = par0; - bestpar1 = par1; - better = 1; - } - } - } - } while (better); -#if 0 - double lastfil = 9; - TimeFilter *tf = ff_timefilter_new(1, bestpar0, bestpar1); - for (i = 0; i < SAMPLES; i++) { - double filtered; - filtered = ff_timefilter_update(tf, samples[i], 1); - printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i], - samples[FFMAX(i, 1)] - samples[FFMAX(i - 1, 0)], filtered - lastfil); - lastfil = filtered; - } - ff_timefilter_destroy(tf); -#else - printf(" [%f %f %9f]", bestpar0, bestpar1, best_error); -#endif - } - printf("\n"); - } - return 0; -} diff --git a/libavfilter/filtfmts-test.c b/libavfilter/filtfmts-test.c deleted file mode 100644 index cc04654222..0000000000 --- a/libavfilter/filtfmts-test.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2009 Stefano Sabatini - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "libavutil/mem.h" -#include "libavutil/pixdesc.h" - -#include "libavfilter/avfilter.h" -#include "libavfilter/formats.h" - -int main(int argc, char **argv) -{ - AVFilter *filter; - AVFilterContext *filter_ctx; - AVFilterGraph *graph_ctx; - const char *filter_name; - const char *filter_args = NULL; - int i, j, ret = 0; - - av_log_set_level(AV_LOG_DEBUG); - - if (!argv[1]) { - fprintf(stderr, "Missing filter name as argument\n"); - return 1; - } - - filter_name = argv[1]; - if (argv[2]) - filter_args = argv[2]; - - /* allocate graph */ - graph_ctx = avfilter_graph_alloc(); - if (!graph_ctx) - return 1; - - avfilter_register_all(); - - /* get a corresponding filter and open it */ - if (!(filter = avfilter_get_by_name(filter_name))) { - fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name); - return 1; - } - - /* open filter and add it to the graph */ - if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) { - fprintf(stderr, "Impossible to open filter with name '%s'\n", - filter_name); - return 1; - } - if (avfilter_init_str(filter_ctx, filter_args) < 0) { - fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", - filter_name, filter_args); - return 1; - } - - /* create a link for each of the input pads */ - for (i = 0; i < filter_ctx->nb_inputs; i++) { - AVFilterLink *link = av_mallocz(sizeof(AVFilterLink)); - if (!link) { - fprintf(stderr, "Unable to allocate memory for filter input link\n"); - ret = 1; - goto fail; - } - link->type = avfilter_pad_get_type(filter_ctx->filter->inputs, i); - filter_ctx->inputs[i] = link; - } - for (i = 0; i < filter_ctx->nb_outputs; i++) { - AVFilterLink *link = av_mallocz(sizeof(AVFilterLink)); - if (!link) { - fprintf(stderr, "Unable to allocate memory for filter output link\n"); - ret = 1; - goto fail; - } - link->type = avfilter_pad_get_type(filter_ctx->filter->outputs, i); - filter_ctx->outputs[i] = link; - } - - if (filter->query_formats) - filter->query_formats(filter_ctx); - else - ff_default_query_formats(filter_ctx); - - /* print the supported formats in input */ - for (i = 0; i < filter_ctx->nb_inputs; i++) { - AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats; - for (j = 0; j < fmts->nb_formats; j++) - printf("INPUT[%d] %s: %s\n", - i, avfilter_pad_get_name(filter_ctx->filter->inputs, i), - av_get_pix_fmt_name(fmts->formats[j])); - } - - /* print the supported formats in output */ - for (i = 0; i < filter_ctx->nb_outputs; i++) { - AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats; - for (j = 0; j < fmts->nb_formats; j++) - printf("OUTPUT[%d] %s: %s\n", - i, avfilter_pad_get_name(filter_ctx->filter->outputs, i), - av_get_pix_fmt_name(fmts->formats[j])); - } - -fail: - avfilter_free(filter_ctx); - avfilter_graph_free(&graph_ctx); - fflush(stdout); - return ret; -} diff --git a/libavfilter/tests/.gitignore b/libavfilter/tests/.gitignore new file mode 100644 index 0000000000..a55b3866b3 --- /dev/null +++ b/libavfilter/tests/.gitignore @@ -0,0 +1 @@ +/filtfmts diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c new file mode 100644 index 0000000000..cc04654222 --- /dev/null +++ b/libavfilter/tests/filtfmts.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2009 Stefano Sabatini + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/mem.h" +#include "libavutil/pixdesc.h" + +#include "libavfilter/avfilter.h" +#include "libavfilter/formats.h" + +int main(int argc, char **argv) +{ + AVFilter *filter; + AVFilterContext *filter_ctx; + AVFilterGraph *graph_ctx; + const char *filter_name; + const char *filter_args = NULL; + int i, j, ret = 0; + + av_log_set_level(AV_LOG_DEBUG); + + if (!argv[1]) { + fprintf(stderr, "Missing filter name as argument\n"); + return 1; + } + + filter_name = argv[1]; + if (argv[2]) + filter_args = argv[2]; + + /* allocate graph */ + graph_ctx = avfilter_graph_alloc(); + if (!graph_ctx) + return 1; + + avfilter_register_all(); + + /* get a corresponding filter and open it */ + if (!(filter = avfilter_get_by_name(filter_name))) { + fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name); + return 1; + } + + /* open filter and add it to the graph */ + if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) { + fprintf(stderr, "Impossible to open filter with name '%s'\n", + filter_name); + return 1; + } + if (avfilter_init_str(filter_ctx, filter_args) < 0) { + fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", + filter_name, filter_args); + return 1; + } + + /* create a link for each of the input pads */ + for (i = 0; i < filter_ctx->nb_inputs; i++) { + AVFilterLink *link = av_mallocz(sizeof(AVFilterLink)); + if (!link) { + fprintf(stderr, "Unable to allocate memory for filter input link\n"); + ret = 1; + goto fail; + } + link->type = avfilter_pad_get_type(filter_ctx->filter->inputs, i); + filter_ctx->inputs[i] = link; + } + for (i = 0; i < filter_ctx->nb_outputs; i++) { + AVFilterLink *link = av_mallocz(sizeof(AVFilterLink)); + if (!link) { + fprintf(stderr, "Unable to allocate memory for filter output link\n"); + ret = 1; + goto fail; + } + link->type = avfilter_pad_get_type(filter_ctx->filter->outputs, i); + filter_ctx->outputs[i] = link; + } + + if (filter->query_formats) + filter->query_formats(filter_ctx); + else + ff_default_query_formats(filter_ctx); + + /* print the supported formats in input */ + for (i = 0; i < filter_ctx->nb_inputs; i++) { + AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats; + for (j = 0; j < fmts->nb_formats; j++) + printf("INPUT[%d] %s: %s\n", + i, avfilter_pad_get_name(filter_ctx->filter->inputs, i), + av_get_pix_fmt_name(fmts->formats[j])); + } + + /* print the supported formats in output */ + for (i = 0; i < filter_ctx->nb_outputs; i++) { + AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats; + for (j = 0; j < fmts->nb_formats; j++) + printf("OUTPUT[%d] %s: %s\n", + i, avfilter_pad_get_name(filter_ctx->filter->outputs, i), + av_get_pix_fmt_name(fmts->formats[j])); + } + +fail: + avfilter_free(filter_ctx); + avfilter_graph_free(&graph_ctx); + fflush(stdout); + return ret; +} diff --git a/libavformat/movenc-test.c b/libavformat/movenc-test.c deleted file mode 100644 index e7b67e1e7a..0000000000 --- a/libavformat/movenc-test.c +++ /dev/null @@ -1,672 +0,0 @@ -/* - * Copyright (c) 2015 Martin Storsjo - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "libavutil/intreadwrite.h" -#include "libavutil/mathematics.h" -#include "libavutil/md5.h" - -#include "avformat.h" - -#if HAVE_UNISTD_H -#include -#endif - -#if !HAVE_GETOPT -#include "compat/getopt.c" -#endif - -#define HASH_SIZE 16 - -static const uint8_t h264_extradata[] = { - 0x01, 0x4d, 0x40, 0x1e, 0xff, 0xe1, 0x00, 0x02, 0x67, 0x4d, 0x01, 0x00, 0x02, 0x68, 0xef -}; -static const uint8_t aac_extradata[] = { - 0x12, 0x10 -}; - - -const char *format = "mp4"; -AVFormatContext *ctx; -uint8_t iobuf[32768]; -AVDictionary *opts; - -int write_file; -const char *cur_name; -FILE* out; -int out_size; -struct AVMD5* md5; -uint8_t hash[HASH_SIZE]; - -AVStream *video_st, *audio_st; -int64_t audio_dts, video_dts; - -int bframes; -int64_t duration; -int64_t audio_duration; -int frames; -int gop_size; -int64_t next_p_pts; -enum AVPictureType last_picture; -int skip_write; -int skip_write_audio; -int clear_duration; - -int num_warnings; - -int check_faults; - - -static void count_warnings(void *avcl, int level, const char *fmt, va_list vl) -{ - if (level == AV_LOG_WARNING) - num_warnings++; -} - -static void init_count_warnings(void) -{ - av_log_set_callback(count_warnings); - num_warnings = 0; -} - -static void reset_count_warnings(void) -{ - av_log_set_callback(av_log_default_callback); -} - -static int io_write(void *opaque, uint8_t *buf, int size) -{ - out_size += size; - av_md5_update(md5, buf, size); - if (out) - fwrite(buf, 1, size, out); - return size; -} - -static void init_out(const char *name) -{ - char buf[100]; - cur_name = name; - snprintf(buf, sizeof(buf), "%s.%s", cur_name, format); - - av_md5_init(md5); - if (write_file) { - out = fopen(buf, "wb"); - if (!out) - perror(buf); - } - out_size = 0; -} - -static void close_out(void) -{ - int i; - av_md5_final(md5, hash); - for (i = 0; i < HASH_SIZE; i++) - printf("%02x", hash[i]); - printf(" %d %s\n", out_size, cur_name); - if (out) - fclose(out); - out = NULL; -} - -static void check_func(int value, int line, const char *msg, ...) -{ - if (!value) { - va_list ap; - va_start(ap, msg); - printf("%d: ", line); - vprintf(msg, ap); - printf("\n"); - check_faults++; - va_end(ap); - } -} -#define check(value, ...) check_func(value, __LINE__, __VA_ARGS__) - -static void init_fps(int bf, int audio_preroll, int fps) -{ - AVStream *st; - ctx = avformat_alloc_context(); - if (!ctx) - exit(1); - ctx->oformat = av_guess_format(format, NULL, NULL); - if (!ctx->oformat) - exit(1); - ctx->pb = avio_alloc_context(iobuf, sizeof(iobuf), AVIO_FLAG_WRITE, NULL, NULL, io_write, NULL); - if (!ctx->pb) - exit(1); - ctx->flags |= AVFMT_FLAG_BITEXACT; - - st = avformat_new_stream(ctx, NULL); - if (!st) - exit(1); - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->codecpar->codec_id = AV_CODEC_ID_H264; - st->codecpar->width = 640; - st->codecpar->height = 480; - st->time_base.num = 1; - st->time_base.den = 30; - st->codecpar->extradata_size = sizeof(h264_extradata); - st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codecpar->extradata) - exit(1); - memcpy(st->codecpar->extradata, h264_extradata, sizeof(h264_extradata)); - video_st = st; - - st = avformat_new_stream(ctx, NULL); - if (!st) - exit(1); - st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->codecpar->codec_id = AV_CODEC_ID_AAC; - st->codecpar->sample_rate = 44100; - st->codecpar->channels = 2; - st->time_base.num = 1; - st->time_base.den = 44100; - st->codecpar->extradata_size = sizeof(aac_extradata); - st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codecpar->extradata) - exit(1); - memcpy(st->codecpar->extradata, aac_extradata, sizeof(aac_extradata)); - audio_st = st; - - if (avformat_write_header(ctx, &opts) < 0) - exit(1); - av_dict_free(&opts); - - frames = 0; - gop_size = 30; - duration = video_st->time_base.den / fps; - audio_duration = 1024LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; - if (audio_preroll) - audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; - - bframes = bf; - video_dts = bframes ? -duration : 0; - audio_dts = -audio_preroll; -} - -static void init(int bf, int audio_preroll) -{ - init_fps(bf, audio_preroll, 30); -} - -static void mux_frames(int n) -{ - int end_frames = frames + n; - while (1) { - AVPacket pkt; - uint8_t pktdata[4]; - av_init_packet(&pkt); - - if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) { - pkt.dts = pkt.pts = audio_dts; - pkt.stream_index = 1; - pkt.duration = audio_duration; - audio_dts += audio_duration; - } else { - if (frames == end_frames) - break; - pkt.dts = video_dts; - pkt.stream_index = 0; - pkt.duration = duration; - if ((frames % gop_size) == 0) { - pkt.flags |= AV_PKT_FLAG_KEY; - last_picture = AV_PICTURE_TYPE_I; - pkt.pts = pkt.dts + duration; - video_dts = pkt.pts; - } else { - if (last_picture == AV_PICTURE_TYPE_P) { - last_picture = AV_PICTURE_TYPE_B; - pkt.pts = pkt.dts; - video_dts = next_p_pts; - } else { - last_picture = AV_PICTURE_TYPE_P; - if (((frames + 1) % gop_size) == 0) { - pkt.pts = pkt.dts + duration; - video_dts = pkt.pts; - } else { - next_p_pts = pkt.pts = pkt.dts + 2 * duration; - video_dts += duration; - } - } - } - if (!bframes) - pkt.pts = pkt.dts; - frames++; - } - - if (clear_duration) - pkt.duration = 0; - AV_WB32(pktdata, pkt.pts); - pkt.data = pktdata; - pkt.size = 4; - if (skip_write) - continue; - if (skip_write_audio && pkt.stream_index == 1) - continue; - av_write_frame(ctx, &pkt); - } -} - -static void mux_gops(int n) -{ - mux_frames(gop_size * n); -} - -static void skip_gops(int n) -{ - skip_write = 1; - mux_gops(n); - skip_write = 0; -} - -static void signal_init_ts(void) -{ - AVPacket pkt; - av_init_packet(&pkt); - pkt.size = 0; - pkt.data = NULL; - - pkt.stream_index = 0; - pkt.dts = video_dts; - pkt.pts = 0; - av_write_frame(ctx, &pkt); - - pkt.stream_index = 1; - pkt.dts = pkt.pts = audio_dts; - av_write_frame(ctx, &pkt); -} - -static void finish(void) -{ - av_write_trailer(ctx); - av_free(ctx->pb); - avformat_free_context(ctx); - ctx = NULL; -} - -static void help(void) -{ - printf("movenc-test [-w]\n" - "-w write output into files\n"); -} - -int main(int argc, char **argv) -{ - int c; - uint8_t header[HASH_SIZE]; - uint8_t content[HASH_SIZE]; - int empty_moov_pos; - int prev_pos; - - for (;;) { - c = getopt(argc, argv, "wh"); - if (c == -1) - break; - switch (c) { - case 'w': - write_file = 1; - break; - default: - case 'h': - help(); - return 0; - } - } - - av_register_all(); - - md5 = av_md5_alloc(); - if (!md5) - return 1; - - // Write a fragmented file with an initial moov that actually contains some - // samples. One moov+mdat with 1 second of data and one moof+mdat with 1 - // second of data. - init_out("non-empty-moov"); - av_dict_set(&opts, "movflags", "frag_keyframe", 0); - init(0, 0); - mux_gops(2); - finish(); - close_out(); - - // Write a similar file, but with B-frames and audio preroll, handled - // via an edit list. - init_out("non-empty-moov-elst"); - av_dict_set(&opts, "movflags", "frag_keyframe", 0); - av_dict_set(&opts, "use_editlist", "1", 0); - init(1, 1); - mux_gops(2); - finish(); - close_out(); - - // Use B-frames but no audio-preroll, but without an edit list. - // Due to avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO, the dts - // of the first audio packet is > 0, but it is set to zero since edit - // lists aren't used, increasing the duration of the first packet instead. - init_out("non-empty-moov-no-elst"); - av_dict_set(&opts, "movflags", "frag_keyframe", 0); - av_dict_set(&opts, "use_editlist", "0", 0); - init(1, 0); - mux_gops(2); - finish(); - close_out(); - - format = "ismv"; - // Write an ISMV, with B-frames and audio preroll. - init_out("ismv"); - av_dict_set(&opts, "movflags", "frag_keyframe", 0); - init(1, 1); - mux_gops(2); - finish(); - close_out(); - format = "mp4"; - - // An initial moov that doesn't contain any samples, followed by two - // moof+mdat pairs. - init_out("empty-moov"); - av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); - init(0, 0); - mux_gops(2); - finish(); - close_out(); - memcpy(content, hash, HASH_SIZE); - - // Similar to the previous one, but with input that doesn't start at - // pts/dts 0. avoid_negative_ts behaves in the same way as - // in non-empty-moov-no-elst above. - init_out("empty-moov-no-elst"); - av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); - init(1, 0); - mux_gops(2); - finish(); - close_out(); - - // Same as the previous one, but disable avoid_negative_ts (which - // would require using an edit list, but with empty_moov, one can't - // write a sensible edit list, when the start timestamps aren't known). - // This should trigger a warning - we check that the warning is produced. - init_count_warnings(); - init_out("empty-moov-no-elst-no-adjust"); - av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); - av_dict_set(&opts, "avoid_negative_ts", "0", 0); - init(1, 0); - mux_gops(2); - finish(); - close_out(); - - reset_count_warnings(); - check(num_warnings > 0, "No warnings printed for unhandled start offset"); - - // Verify that delay_moov produces the same as empty_moov for - // simple input - init_out("delay-moov"); - av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); - init(0, 0); - mux_gops(2); - finish(); - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "delay_moov differs from empty_moov"); - - // Test writing content that requires an edit list using delay_moov - init_out("delay-moov-elst"); - av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); - init(1, 1); - mux_gops(2); - finish(); - close_out(); - - // Test writing a file with one track lacking packets, with delay_moov. - skip_write_audio = 1; - init_out("delay-moov-empty-track"); - av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); - init(0, 0); - mux_gops(2); - // The automatic flushing shouldn't output anything, since we're still - // waiting for data for some tracks - check(out_size == 0, "delay_moov flushed prematurely"); - // When closed (or manually flushed), all the written data should still - // be output. - finish(); - close_out(); - check(out_size > 0, "delay_moov didn't output anything"); - - // Check that manually flushing still outputs things as expected. This - // produces two fragments, while the one above produces only one. - init_out("delay-moov-empty-track-flush"); - av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0); - init(0, 0); - mux_gops(1); - av_write_frame(ctx, NULL); // Force writing the moov - check(out_size > 0, "No moov written"); - av_write_frame(ctx, NULL); - mux_gops(1); - av_write_frame(ctx, NULL); - finish(); - close_out(); - - skip_write_audio = 0; - - - - // Verify that the header written by delay_moov when manually flushed - // is identical to the one by empty_moov. - init_out("empty-moov-header"); - av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); - init(0, 0); - close_out(); - memcpy(header, hash, HASH_SIZE); - init_out("empty-moov-content"); - mux_gops(2); - // Written 2 seconds of content, with an automatic flush after 1 second. - check(out_size > 0, "No automatic flush?"); - empty_moov_pos = prev_pos = out_size; - // Manually flush the second fragment - av_write_frame(ctx, NULL); - check(out_size > prev_pos, "No second fragment flushed?"); - prev_pos = out_size; - // Check that an extra flush doesn't output any more data - av_write_frame(ctx, NULL); - check(out_size == prev_pos, "More data written?"); - close_out(); - memcpy(content, hash, HASH_SIZE); - // Ignore the trailer written here - finish(); - - init_out("delay-moov-header"); - av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0); - init(0, 0); - check(out_size == 0, "Output written during init with delay_moov"); - mux_gops(1); // Write 1 second of content - av_write_frame(ctx, NULL); // Force writing the moov - close_out(); - check(!memcmp(hash, header, HASH_SIZE), "delay_moov header differs from empty_moov"); - init_out("delay-moov-content"); - av_write_frame(ctx, NULL); // Flush the first fragment - check(out_size == empty_moov_pos, "Manually flushed content differs from automatically flushed, %d vs %d", out_size, empty_moov_pos); - mux_gops(1); // Write the rest of the content - av_write_frame(ctx, NULL); // Flush the second fragment - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "delay_moov content differs from empty_moov"); - finish(); - - - // Verify that we can produce an identical second fragment without - // writing the first one. First write the reference fragments that - // we want to reproduce. - av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash", 0); - init(0, 0); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the first fragment - init_out("empty-moov-second-frag"); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - memcpy(content, hash, HASH_SIZE); - finish(); - - // Produce the same second fragment without actually writing the first - // one before. - av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash+frag_discont", 0); - av_dict_set(&opts, "fragment_index", "2", 0); - av_dict_set(&opts, "avoid_negative_ts", "0", 0); - av_dict_set(&opts, "use_editlist", "0", 0); - init(0, 0); - skip_gops(1); - init_out("empty-moov-second-frag-discont"); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); - finish(); - - // Produce the same thing by using delay_moov, which requires a slightly - // different call sequence. - av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); - av_dict_set(&opts, "fragment_index", "2", 0); - init(0, 0); - skip_gops(1); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the moov - init_out("delay-moov-second-frag-discont"); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); - finish(); - - - // Test discontinuously written fragments with B-frames (where the - // assumption of starting at pts=0 works) but not with audio preroll - // (which can't be guessed). - av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0); - init(1, 0); - mux_gops(1); - init_out("delay-moov-elst-init"); - av_write_frame(ctx, NULL); // Output the moov - close_out(); - memcpy(header, hash, HASH_SIZE); - av_write_frame(ctx, NULL); // Output the first fragment - init_out("delay-moov-elst-second-frag"); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - memcpy(content, hash, HASH_SIZE); - finish(); - - av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); - av_dict_set(&opts, "fragment_index", "2", 0); - init(1, 0); - skip_gops(1); - mux_gops(1); // Write the second fragment - init_out("delay-moov-elst-init-discont"); - av_write_frame(ctx, NULL); // Output the moov - close_out(); - check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs"); - init_out("delay-moov-elst-second-frag-discont"); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); - finish(); - - - // Test discontinuously written fragments with B-frames and audio preroll, - // properly signaled. - av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0); - init(1, 1); - mux_gops(1); - init_out("delay-moov-elst-signal-init"); - av_write_frame(ctx, NULL); // Output the moov - close_out(); - memcpy(header, hash, HASH_SIZE); - av_write_frame(ctx, NULL); // Output the first fragment - init_out("delay-moov-elst-signal-second-frag"); - mux_gops(1); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - memcpy(content, hash, HASH_SIZE); - finish(); - - av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); - av_dict_set(&opts, "fragment_index", "2", 0); - init(1, 1); - signal_init_ts(); - skip_gops(1); - mux_gops(1); // Write the second fragment - init_out("delay-moov-elst-signal-init-discont"); - av_write_frame(ctx, NULL); // Output the moov - close_out(); - check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs"); - init_out("delay-moov-elst-signal-second-frag-discont"); - av_write_frame(ctx, NULL); // Output the second fragment - close_out(); - check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); - finish(); - - - // Test VFR content, with sidx atoms (which declare the pts duration - // of a fragment, forcing overriding the start pts of the next one). - // Here, the fragment duration in pts is significantly different from - // the duration in dts. The video stream starts at dts=-10,pts=0, and - // the second fragment starts at dts=155,pts=156. The trun duration sum - // of the first fragment is 165, which also is written as - // baseMediaDecodeTime in the tfdt in the second fragment. The sidx for - // the first fragment says earliest_presentation_time = 0 and - // subsegment_duration = 156, which also matches the sidx in the second - // fragment. For the audio stream, the pts and dts durations also don't - // match - the input stream starts at pts=-2048, but that part is excluded - // by the edit list. - init_out("vfr"); - av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0); - init_fps(1, 1, 3); - mux_frames(gop_size/2); - duration /= 10; - mux_frames(gop_size/2); - mux_gops(1); - finish(); - close_out(); - - // Test VFR content, with cleared duration fields. In these cases, - // the muxer must guess the duration of the last packet of each - // fragment. As long as the framerate doesn't vary (too much) at the - // fragment edge, it works just fine. Additionally, when automatically - // cutting fragments, the muxer already know the timestamps of the next - // packet for one stream (in most cases the video stream), avoiding - // having to use guesses for that one. - init_count_warnings(); - clear_duration = 1; - init_out("vfr-noduration"); - av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0); - init_fps(1, 1, 3); - mux_frames(gop_size/2); - duration /= 10; - mux_frames(gop_size/2); - mux_gops(1); - finish(); - close_out(); - clear_duration = 0; - reset_count_warnings(); - check(num_warnings > 0, "No warnings printed for filled in durations"); - - av_free(md5); - - return check_faults > 0 ? 1 : 0; -} diff --git a/libavformat/noproxy-test.c b/libavformat/noproxy-test.c deleted file mode 100644 index e6cc421413..0000000000 --- a/libavformat/noproxy-test.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2013 Martin Storsjo - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "network.h" - -static void test(const char *pattern, const char *host) -{ - int res = ff_http_match_no_proxy(pattern, host); - printf("The pattern \"%s\" %s the hostname %s\n", - pattern ? pattern : "(null)", res ? "matches" : "does not match", - host); -} - -int main(void) -{ - test(NULL, "domain.com"); - test("example.com domain.com", "domain.com"); - test("example.com other.com", "domain.com"); - test("example.com,domain.com", "domain.com"); - test("example.com,domain.com", "otherdomain.com"); - test("example.com, *.domain.com", "sub.domain.com"); - test("example.com, *.domain.com", "domain.com"); - test("example.com, .domain.com", "domain.com"); - test("*", "domain.com"); - return 0; -} diff --git a/libavformat/rtmpdh-test.c b/libavformat/rtmpdh-test.c deleted file mode 100644 index 603bb79ebc..0000000000 --- a/libavformat/rtmpdh-test.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "rtmpdh.c" - -#include - -static int test_random_shared_secret(void) -{ - FF_DH *peer1 = NULL, *peer2 = NULL; - int ret; - uint8_t pubkey1[128], pubkey2[128]; - uint8_t sharedkey1[128], sharedkey2[128]; - - peer1 = ff_dh_init(1024); - peer2 = ff_dh_init(1024); - if (!peer1 || !peer2) { - ret = AVERROR(ENOMEM); - goto fail; - } - if ((ret = ff_dh_generate_public_key(peer1)) < 0) - goto fail; - if ((ret = ff_dh_generate_public_key(peer2)) < 0) - goto fail; - if ((ret = ff_dh_write_public_key(peer1, pubkey1, sizeof(pubkey1))) < 0) - goto fail; - if ((ret = ff_dh_write_public_key(peer2, pubkey2, sizeof(pubkey2))) < 0) - goto fail; - if ((ret = ff_dh_compute_shared_secret_key(peer1, pubkey2, sizeof(pubkey2), - sharedkey1, sizeof(sharedkey1))) < 0) - goto fail; - if ((ret = ff_dh_compute_shared_secret_key(peer2, pubkey1, sizeof(pubkey1), - sharedkey2, sizeof(sharedkey2))) < 0) - goto fail; - if (memcmp(sharedkey1, sharedkey2, sizeof(sharedkey1))) { - printf("Mismatched generated shared key\n"); - ret = AVERROR_INVALIDDATA; - } else { - printf("Generated shared key ok\n"); - } -fail: - ff_dh_free(peer1); - ff_dh_free(peer2); - return ret; -} - -static const char *private_key = - "976C18FCADC255B456564F74F3EEDA59D28AF6B744D743F2357BFD2404797EF896EF1A" - "7C1CBEAAA3AB60AF3192D189CFF3F991C9CBBFD78119FCA2181384B94011943B6D6F28" - "9E1B708E2D1A0C7771169293F03DA27E561F15F16F0AC9BC858C77A80FA98FD088A232" - "19D08BE6F165DE0B02034B18705829FAD0ACB26A5B75EF"; -static const char *public_key = - "F272ECF8362257C5D2C3CC2229CF9C0A03225BC109B1DBC76A68C394F256ACA3EF5F64" - "FC270C26382BF315C19E97A76104A716FC998A651E8610A3AE6CF65D8FAE5D3F32EEA0" - "0B32CB9609B494116A825D7142D17B88E3D20EDD98743DE29CF37A23A9F6A58B960591" - "3157D5965FCB46DDA73A1F08DD897BAE88DFE6FC937CBA"; -static const uint8_t public_key_bin[] = { - 0xf2, 0x72, 0xec, 0xf8, 0x36, 0x22, 0x57, 0xc5, 0xd2, 0xc3, 0xcc, 0x22, - 0x29, 0xcf, 0x9c, 0x0a, 0x03, 0x22, 0x5b, 0xc1, 0x09, 0xb1, 0xdb, 0xc7, - 0x6a, 0x68, 0xc3, 0x94, 0xf2, 0x56, 0xac, 0xa3, 0xef, 0x5f, 0x64, 0xfc, - 0x27, 0x0c, 0x26, 0x38, 0x2b, 0xf3, 0x15, 0xc1, 0x9e, 0x97, 0xa7, 0x61, - 0x04, 0xa7, 0x16, 0xfc, 0x99, 0x8a, 0x65, 0x1e, 0x86, 0x10, 0xa3, 0xae, - 0x6c, 0xf6, 0x5d, 0x8f, 0xae, 0x5d, 0x3f, 0x32, 0xee, 0xa0, 0x0b, 0x32, - 0xcb, 0x96, 0x09, 0xb4, 0x94, 0x11, 0x6a, 0x82, 0x5d, 0x71, 0x42, 0xd1, - 0x7b, 0x88, 0xe3, 0xd2, 0x0e, 0xdd, 0x98, 0x74, 0x3d, 0xe2, 0x9c, 0xf3, - 0x7a, 0x23, 0xa9, 0xf6, 0xa5, 0x8b, 0x96, 0x05, 0x91, 0x31, 0x57, 0xd5, - 0x96, 0x5f, 0xcb, 0x46, 0xdd, 0xa7, 0x3a, 0x1f, 0x08, 0xdd, 0x89, 0x7b, - 0xae, 0x88, 0xdf, 0xe6, 0xfc, 0x93, 0x7c, 0xba -}; -static const uint8_t peer_public_key[] = { - 0x58, 0x66, 0x05, 0x49, 0x94, 0x23, 0x2b, 0x66, 0x52, 0x13, 0xff, 0x46, - 0xf2, 0xb3, 0x79, 0xa9, 0xee, 0xae, 0x1a, 0x13, 0xf0, 0x71, 0x52, 0xfb, - 0x93, 0x4e, 0xee, 0x97, 0x05, 0x73, 0x50, 0x7d, 0xaf, 0x02, 0x07, 0x72, - 0xac, 0xdc, 0xa3, 0x95, 0x78, 0xee, 0x9a, 0x19, 0x71, 0x7e, 0x99, 0x9f, - 0x2a, 0xd4, 0xb3, 0xe2, 0x0c, 0x1d, 0x1a, 0x78, 0x4c, 0xde, 0xf1, 0xad, - 0xb4, 0x60, 0xa8, 0x51, 0xac, 0x71, 0xec, 0x86, 0x70, 0xa2, 0x63, 0x36, - 0x92, 0x7c, 0xe3, 0x87, 0xee, 0xe4, 0xf1, 0x62, 0x24, 0x74, 0xb4, 0x04, - 0xfa, 0x5c, 0xdf, 0xba, 0xfa, 0xa3, 0xc2, 0xbb, 0x62, 0x27, 0xd0, 0xf4, - 0xe4, 0x43, 0xda, 0x8a, 0x88, 0x69, 0x60, 0xe2, 0xdb, 0x75, 0x2a, 0x98, - 0x9d, 0xb5, 0x50, 0xe3, 0x99, 0xda, 0xe0, 0xa6, 0x14, 0xc9, 0x80, 0x12, - 0xf9, 0x3c, 0xac, 0x06, 0x02, 0x7a, 0xde, 0x74 -}; -static const uint8_t shared_secret[] = { - 0xb2, 0xeb, 0xcb, 0x71, 0xf3, 0x61, 0xfb, 0x5b, 0x4e, 0x5c, 0x4c, 0xcf, - 0x5c, 0x08, 0x5f, 0x96, 0x26, 0x77, 0x1d, 0x31, 0xf1, 0xe1, 0xf7, 0x4b, - 0x92, 0xac, 0x82, 0x2a, 0x88, 0xc7, 0x83, 0xe1, 0xc7, 0xf3, 0xd3, 0x1a, - 0x7d, 0xc8, 0x31, 0xe3, 0x97, 0xe4, 0xec, 0x31, 0x0e, 0x8f, 0x73, 0x1a, - 0xe4, 0xf6, 0xd8, 0xc8, 0x94, 0xff, 0xa0, 0x03, 0x84, 0x03, 0x0f, 0xa5, - 0x30, 0x5d, 0x67, 0xe0, 0x7a, 0x3b, 0x5f, 0xed, 0x4c, 0xf5, 0xbc, 0x18, - 0xea, 0xd4, 0x77, 0xa9, 0x07, 0xb3, 0x54, 0x0b, 0x02, 0xd9, 0xc6, 0xb8, - 0x66, 0x5e, 0xec, 0xa4, 0xcd, 0x47, 0xed, 0xc9, 0x38, 0xc6, 0x91, 0x08, - 0xf3, 0x85, 0x9b, 0x69, 0x16, 0x78, 0x0d, 0xb7, 0x74, 0x51, 0xaa, 0x5b, - 0x4d, 0x74, 0xe4, 0x29, 0x2e, 0x9e, 0x8e, 0xf7, 0xe5, 0x42, 0x83, 0xb0, - 0x65, 0xb0, 0xce, 0xc6, 0xb2, 0x8f, 0x5b, 0xb0 -}; - -static int test_ref_data(void) -{ - FF_DH *dh; - int ret = AVERROR(ENOMEM); - uint8_t pubkey_test[128]; - uint8_t sharedkey_test[128]; - - dh = ff_dh_init(1024); - if (!dh) - goto fail; - bn_hex2bn(dh->priv_key, private_key, ret); - if (!ret) - goto fail; - bn_hex2bn(dh->pub_key, public_key, ret); - if (!ret) - goto fail; - if ((ret = ff_dh_write_public_key(dh, pubkey_test, sizeof(pubkey_test))) < 0) - goto fail; - if (memcmp(pubkey_test, public_key_bin, sizeof(pubkey_test))) { - printf("Mismatched generated public key\n"); - ret = AVERROR_INVALIDDATA; - goto fail; - } else { - printf("Generated public key ok\n"); - } - if ((ret = ff_dh_compute_shared_secret_key(dh, peer_public_key, sizeof(peer_public_key), - sharedkey_test, sizeof(sharedkey_test))) < 0) - goto fail; - if (memcmp(shared_secret, sharedkey_test, sizeof(sharedkey_test))) { - printf("Mismatched generated shared key\n"); - ret = AVERROR_INVALIDDATA; - } else { - printf("Generated shared key ok\n"); - } -fail: - ff_dh_free(dh); - return ret; -} - -int main(void) -{ - if (test_random_shared_secret() < 0) - return 1; - if (test_ref_data() < 0) - return 1; - return 0; -} diff --git a/libavformat/seek-test.c b/libavformat/seek-test.c deleted file mode 100644 index 97062d5dfc..0000000000 --- a/libavformat/seek-test.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2003 Fabrice Bellard - * Copyright (c) 2007 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "libavutil/common.h" -#include "libavutil/mathematics.h" -#include "libavformat/avformat.h" - -static char buffer[20]; - -static const char *ret_str(int v) -{ - switch (v) { - case AVERROR_EOF: return "-EOF"; - case AVERROR(EIO): return "-EIO"; - case AVERROR(ENOMEM): return "-ENOMEM"; - case AVERROR(EINVAL): return "-EINVAL"; - default: - snprintf(buffer, sizeof(buffer), "%2d", v); - return buffer; - } -} - -static void ts_str(char buffer[60], int64_t ts, AVRational base) -{ - double tsval; - if (ts == AV_NOPTS_VALUE) { - strcpy(buffer, " NOPTS "); - return; - } - tsval = ts * av_q2d(base); - snprintf(buffer, 60, "%9f", tsval); -} - -int main(int argc, char **argv) -{ - const char *filename; - AVFormatContext *ic = NULL; - int i, ret, stream_id; - int64_t timestamp; - AVDictionary *format_opts = NULL; - - av_dict_set(&format_opts, "channels", "1", 0); - av_dict_set(&format_opts, "sample_rate", "22050", 0); - - /* initialize libavcodec, and register all codecs and formats */ - av_register_all(); - - if (argc != 2) { - printf("usage: %s input_file\n" - "\n", argv[0]); - return 1; - } - - filename = argv[1]; - - ret = avformat_open_input(&ic, filename, NULL, &format_opts); - av_dict_free(&format_opts); - if (ret < 0) { - fprintf(stderr, "cannot open %s\n", filename); - return 1; - } - - ret = avformat_find_stream_info(ic, NULL); - if (ret < 0) { - fprintf(stderr, "%s: could not find codec parameters\n", filename); - return 1; - } - - for(i=0; ; i++){ - AVPacket pkt = { 0 }; - AVStream *av_uninit(st); - char ts_buf[60]; - - if(ret>=0){ - ret= av_read_frame(ic, &pkt); - if(ret>=0){ - char dts_buf[60]; - st= ic->streams[pkt.stream_index]; - ts_str(dts_buf, pkt.dts, st->time_base); - ts_str(ts_buf, pkt.pts, st->time_base); - printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size); - av_packet_unref(&pkt); - } else - printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace - printf("\n"); - } - - if(i>25) break; - - stream_id= (i>>1)%(ic->nb_streams+1) - 1; - timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE; - if(stream_id>=0){ - st= ic->streams[stream_id]; - timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base); - } - //FIXME fully test the new seek API - if(i&1) ret = avformat_seek_file(ic, stream_id, INT64_MIN, timestamp, timestamp, 0); - else ret = avformat_seek_file(ic, stream_id, timestamp, timestamp, INT64_MAX, 0); - ts_str(ts_buf, timestamp, stream_id < 0 ? AV_TIME_BASE_Q : st->time_base); - printf("ret:%-10s st:%2d flags:%d ts:%s\n", ret_str(ret), stream_id, i&1, ts_buf); - } - - avformat_close_input(&ic); - - return 0; -} diff --git a/libavformat/srtp-test.c b/libavformat/srtp-test.c deleted file mode 100644 index fe8749cb66..0000000000 --- a/libavformat/srtp-test.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include - -#include "rtpdec.h" -#include "srtp.h" - -static const char *aes128_80_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; - -static const uint8_t rtp_aes128_80[] = { - // RTP header - 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0x62, 0x69, 0x76, 0xca, 0xc5, - // HMAC - 0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99, -}; - -static const uint8_t rtcp_aes128_80[] = { - // RTCP header - 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda, - 0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35, - // RTCP index - 0x80, 0x00, 0x00, 0x03, - // HMAC - 0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde, -}; - -static const char *aes128_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; - -static const uint8_t rtp_aes128_32[] = { - // RTP header - 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0x62, 0x69, 0x76, 0xca, 0xc5, - // HMAC - 0xa1, 0xac, 0x1b, 0xb4, -}; - -static const uint8_t rtcp_aes128_32[] = { - // RTCP header - 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b, - 0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34, - // RTCP index - 0x80, 0x00, 0x00, 0x04, - // HMAC - 0x5b, 0xd2, 0xa9, 0x9d, -}; - -static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; - -static const uint8_t rtp_aes128_80_32[] = { - // RTP header - 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0x62, 0x69, 0x76, 0xca, 0xc5, - // HMAC - 0xa1, 0xac, 0x1b, 0xb4, -}; - -static const uint8_t rtcp_aes128_80_32[] = { - // RTCP header - 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, - // encrypted payload - 0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53, - 0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9, - // RTCP index - 0x80, 0x00, 0x00, 0x05, - // HMAC - 0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10, -}; - -static void print_data(const uint8_t *buf, int len) -{ - int i; - for (i = 0; i < len; i++) - printf("%02x", buf[i]); - printf("\n"); -} - -static int test_decrypt(struct SRTPContext *srtp, const uint8_t *in, int len, - uint8_t *out) -{ - memcpy(out, in, len); - if (!ff_srtp_decrypt(srtp, out, &len)) { - print_data(out, len); - return len; - } else - return -1; -} - -static void test_encrypt(const uint8_t *data, int in_len, const char *suite, - const char *key) -{ - struct SRTPContext enc = { 0 }, dec = { 0 }; - int len; - char buf[RTP_MAX_PACKET_LENGTH]; - ff_srtp_set_crypto(&enc, suite, key); - ff_srtp_set_crypto(&dec, suite, key); - len = ff_srtp_encrypt(&enc, data, in_len, buf, sizeof(buf)); - if (!ff_srtp_decrypt(&dec, buf, &len)) { - if (len == in_len && !memcmp(buf, data, len)) - printf("Decrypted content matches input\n"); - else - printf("Decrypted content doesn't match input\n"); - } else { - printf("Decryption failed\n"); - } - ff_srtp_free(&enc); - ff_srtp_free(&dec); -} - -int main(void) -{ - static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80"; - static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32"; - static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32"; - static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD"; - uint8_t buf[RTP_MAX_PACKET_LENGTH]; - struct SRTPContext srtp = { 0 }; - int len; - ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key); - len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf); - test_encrypt(buf, len, aes128_80_suite, test_key); - test_encrypt(buf, len, aes128_32_suite, test_key); - test_encrypt(buf, len, aes128_80_32_suite, test_key); - test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf); - test_encrypt(buf, len, aes128_80_suite, test_key); - test_encrypt(buf, len, aes128_32_suite, test_key); - test_encrypt(buf, len, aes128_80_32_suite, test_key); - ff_srtp_free(&srtp); - - memset(&srtp, 0, sizeof(srtp)); // Clear the context - ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key); - test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf); - test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf); - ff_srtp_free(&srtp); - - memset(&srtp, 0, sizeof(srtp)); // Clear the context - ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key); - test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf); - test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf); - ff_srtp_free(&srtp); - return 0; -} diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore new file mode 100644 index 0000000000..cfd51f22e9 --- /dev/null +++ b/libavformat/tests/.gitignore @@ -0,0 +1,5 @@ +/movenc +/noproxy +/seek +/srtp +/url diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c new file mode 100644 index 0000000000..711e1579b2 --- /dev/null +++ b/libavformat/tests/movenc.c @@ -0,0 +1,672 @@ +/* + * Copyright (c) 2015 Martin Storsjo + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavutil/intreadwrite.h" +#include "libavutil/mathematics.h" +#include "libavutil/md5.h" + +#include "libavformat/avformat.h" + +#if HAVE_UNISTD_H +#include +#endif + +#if !HAVE_GETOPT +#include "compat/getopt.c" +#endif + +#define HASH_SIZE 16 + +static const uint8_t h264_extradata[] = { + 0x01, 0x4d, 0x40, 0x1e, 0xff, 0xe1, 0x00, 0x02, 0x67, 0x4d, 0x01, 0x00, 0x02, 0x68, 0xef +}; +static const uint8_t aac_extradata[] = { + 0x12, 0x10 +}; + + +const char *format = "mp4"; +AVFormatContext *ctx; +uint8_t iobuf[32768]; +AVDictionary *opts; + +int write_file; +const char *cur_name; +FILE* out; +int out_size; +struct AVMD5* md5; +uint8_t hash[HASH_SIZE]; + +AVStream *video_st, *audio_st; +int64_t audio_dts, video_dts; + +int bframes; +int64_t duration; +int64_t audio_duration; +int frames; +int gop_size; +int64_t next_p_pts; +enum AVPictureType last_picture; +int skip_write; +int skip_write_audio; +int clear_duration; + +int num_warnings; + +int check_faults; + + +static void count_warnings(void *avcl, int level, const char *fmt, va_list vl) +{ + if (level == AV_LOG_WARNING) + num_warnings++; +} + +static void init_count_warnings(void) +{ + av_log_set_callback(count_warnings); + num_warnings = 0; +} + +static void reset_count_warnings(void) +{ + av_log_set_callback(av_log_default_callback); +} + +static int io_write(void *opaque, uint8_t *buf, int size) +{ + out_size += size; + av_md5_update(md5, buf, size); + if (out) + fwrite(buf, 1, size, out); + return size; +} + +static void init_out(const char *name) +{ + char buf[100]; + cur_name = name; + snprintf(buf, sizeof(buf), "%s.%s", cur_name, format); + + av_md5_init(md5); + if (write_file) { + out = fopen(buf, "wb"); + if (!out) + perror(buf); + } + out_size = 0; +} + +static void close_out(void) +{ + int i; + av_md5_final(md5, hash); + for (i = 0; i < HASH_SIZE; i++) + printf("%02x", hash[i]); + printf(" %d %s\n", out_size, cur_name); + if (out) + fclose(out); + out = NULL; +} + +static void check_func(int value, int line, const char *msg, ...) +{ + if (!value) { + va_list ap; + va_start(ap, msg); + printf("%d: ", line); + vprintf(msg, ap); + printf("\n"); + check_faults++; + va_end(ap); + } +} +#define check(value, ...) check_func(value, __LINE__, __VA_ARGS__) + +static void init_fps(int bf, int audio_preroll, int fps) +{ + AVStream *st; + ctx = avformat_alloc_context(); + if (!ctx) + exit(1); + ctx->oformat = av_guess_format(format, NULL, NULL); + if (!ctx->oformat) + exit(1); + ctx->pb = avio_alloc_context(iobuf, sizeof(iobuf), AVIO_FLAG_WRITE, NULL, NULL, io_write, NULL); + if (!ctx->pb) + exit(1); + ctx->flags |= AVFMT_FLAG_BITEXACT; + + st = avformat_new_stream(ctx, NULL); + if (!st) + exit(1); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_H264; + st->codecpar->width = 640; + st->codecpar->height = 480; + st->time_base.num = 1; + st->time_base.den = 30; + st->codecpar->extradata_size = sizeof(h264_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) + exit(1); + memcpy(st->codecpar->extradata, h264_extradata, sizeof(h264_extradata)); + video_st = st; + + st = avformat_new_stream(ctx, NULL); + if (!st) + exit(1); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AAC; + st->codecpar->sample_rate = 44100; + st->codecpar->channels = 2; + st->time_base.num = 1; + st->time_base.den = 44100; + st->codecpar->extradata_size = sizeof(aac_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) + exit(1); + memcpy(st->codecpar->extradata, aac_extradata, sizeof(aac_extradata)); + audio_st = st; + + if (avformat_write_header(ctx, &opts) < 0) + exit(1); + av_dict_free(&opts); + + frames = 0; + gop_size = 30; + duration = video_st->time_base.den / fps; + audio_duration = 1024LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; + if (audio_preroll) + audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; + + bframes = bf; + video_dts = bframes ? -duration : 0; + audio_dts = -audio_preroll; +} + +static void init(int bf, int audio_preroll) +{ + init_fps(bf, audio_preroll, 30); +} + +static void mux_frames(int n) +{ + int end_frames = frames + n; + while (1) { + AVPacket pkt; + uint8_t pktdata[4]; + av_init_packet(&pkt); + + if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) { + pkt.dts = pkt.pts = audio_dts; + pkt.stream_index = 1; + pkt.duration = audio_duration; + audio_dts += audio_duration; + } else { + if (frames == end_frames) + break; + pkt.dts = video_dts; + pkt.stream_index = 0; + pkt.duration = duration; + if ((frames % gop_size) == 0) { + pkt.flags |= AV_PKT_FLAG_KEY; + last_picture = AV_PICTURE_TYPE_I; + pkt.pts = pkt.dts + duration; + video_dts = pkt.pts; + } else { + if (last_picture == AV_PICTURE_TYPE_P) { + last_picture = AV_PICTURE_TYPE_B; + pkt.pts = pkt.dts; + video_dts = next_p_pts; + } else { + last_picture = AV_PICTURE_TYPE_P; + if (((frames + 1) % gop_size) == 0) { + pkt.pts = pkt.dts + duration; + video_dts = pkt.pts; + } else { + next_p_pts = pkt.pts = pkt.dts + 2 * duration; + video_dts += duration; + } + } + } + if (!bframes) + pkt.pts = pkt.dts; + frames++; + } + + if (clear_duration) + pkt.duration = 0; + AV_WB32(pktdata, pkt.pts); + pkt.data = pktdata; + pkt.size = 4; + if (skip_write) + continue; + if (skip_write_audio && pkt.stream_index == 1) + continue; + av_write_frame(ctx, &pkt); + } +} + +static void mux_gops(int n) +{ + mux_frames(gop_size * n); +} + +static void skip_gops(int n) +{ + skip_write = 1; + mux_gops(n); + skip_write = 0; +} + +static void signal_init_ts(void) +{ + AVPacket pkt; + av_init_packet(&pkt); + pkt.size = 0; + pkt.data = NULL; + + pkt.stream_index = 0; + pkt.dts = video_dts; + pkt.pts = 0; + av_write_frame(ctx, &pkt); + + pkt.stream_index = 1; + pkt.dts = pkt.pts = audio_dts; + av_write_frame(ctx, &pkt); +} + +static void finish(void) +{ + av_write_trailer(ctx); + av_free(ctx->pb); + avformat_free_context(ctx); + ctx = NULL; +} + +static void help(void) +{ + printf("movenc-test [-w]\n" + "-w write output into files\n"); +} + +int main(int argc, char **argv) +{ + int c; + uint8_t header[HASH_SIZE]; + uint8_t content[HASH_SIZE]; + int empty_moov_pos; + int prev_pos; + + for (;;) { + c = getopt(argc, argv, "wh"); + if (c == -1) + break; + switch (c) { + case 'w': + write_file = 1; + break; + default: + case 'h': + help(); + return 0; + } + } + + av_register_all(); + + md5 = av_md5_alloc(); + if (!md5) + return 1; + + // Write a fragmented file with an initial moov that actually contains some + // samples. One moov+mdat with 1 second of data and one moof+mdat with 1 + // second of data. + init_out("non-empty-moov"); + av_dict_set(&opts, "movflags", "frag_keyframe", 0); + init(0, 0); + mux_gops(2); + finish(); + close_out(); + + // Write a similar file, but with B-frames and audio preroll, handled + // via an edit list. + init_out("non-empty-moov-elst"); + av_dict_set(&opts, "movflags", "frag_keyframe", 0); + av_dict_set(&opts, "use_editlist", "1", 0); + init(1, 1); + mux_gops(2); + finish(); + close_out(); + + // Use B-frames but no audio-preroll, but without an edit list. + // Due to avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO, the dts + // of the first audio packet is > 0, but it is set to zero since edit + // lists aren't used, increasing the duration of the first packet instead. + init_out("non-empty-moov-no-elst"); + av_dict_set(&opts, "movflags", "frag_keyframe", 0); + av_dict_set(&opts, "use_editlist", "0", 0); + init(1, 0); + mux_gops(2); + finish(); + close_out(); + + format = "ismv"; + // Write an ISMV, with B-frames and audio preroll. + init_out("ismv"); + av_dict_set(&opts, "movflags", "frag_keyframe", 0); + init(1, 1); + mux_gops(2); + finish(); + close_out(); + format = "mp4"; + + // An initial moov that doesn't contain any samples, followed by two + // moof+mdat pairs. + init_out("empty-moov"); + av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); + init(0, 0); + mux_gops(2); + finish(); + close_out(); + memcpy(content, hash, HASH_SIZE); + + // Similar to the previous one, but with input that doesn't start at + // pts/dts 0. avoid_negative_ts behaves in the same way as + // in non-empty-moov-no-elst above. + init_out("empty-moov-no-elst"); + av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); + init(1, 0); + mux_gops(2); + finish(); + close_out(); + + // Same as the previous one, but disable avoid_negative_ts (which + // would require using an edit list, but with empty_moov, one can't + // write a sensible edit list, when the start timestamps aren't known). + // This should trigger a warning - we check that the warning is produced. + init_count_warnings(); + init_out("empty-moov-no-elst-no-adjust"); + av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); + av_dict_set(&opts, "avoid_negative_ts", "0", 0); + init(1, 0); + mux_gops(2); + finish(); + close_out(); + + reset_count_warnings(); + check(num_warnings > 0, "No warnings printed for unhandled start offset"); + + // Verify that delay_moov produces the same as empty_moov for + // simple input + init_out("delay-moov"); + av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); + init(0, 0); + mux_gops(2); + finish(); + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "delay_moov differs from empty_moov"); + + // Test writing content that requires an edit list using delay_moov + init_out("delay-moov-elst"); + av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); + init(1, 1); + mux_gops(2); + finish(); + close_out(); + + // Test writing a file with one track lacking packets, with delay_moov. + skip_write_audio = 1; + init_out("delay-moov-empty-track"); + av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0); + init(0, 0); + mux_gops(2); + // The automatic flushing shouldn't output anything, since we're still + // waiting for data for some tracks + check(out_size == 0, "delay_moov flushed prematurely"); + // When closed (or manually flushed), all the written data should still + // be output. + finish(); + close_out(); + check(out_size > 0, "delay_moov didn't output anything"); + + // Check that manually flushing still outputs things as expected. This + // produces two fragments, while the one above produces only one. + init_out("delay-moov-empty-track-flush"); + av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0); + init(0, 0); + mux_gops(1); + av_write_frame(ctx, NULL); // Force writing the moov + check(out_size > 0, "No moov written"); + av_write_frame(ctx, NULL); + mux_gops(1); + av_write_frame(ctx, NULL); + finish(); + close_out(); + + skip_write_audio = 0; + + + + // Verify that the header written by delay_moov when manually flushed + // is identical to the one by empty_moov. + init_out("empty-moov-header"); + av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0); + init(0, 0); + close_out(); + memcpy(header, hash, HASH_SIZE); + init_out("empty-moov-content"); + mux_gops(2); + // Written 2 seconds of content, with an automatic flush after 1 second. + check(out_size > 0, "No automatic flush?"); + empty_moov_pos = prev_pos = out_size; + // Manually flush the second fragment + av_write_frame(ctx, NULL); + check(out_size > prev_pos, "No second fragment flushed?"); + prev_pos = out_size; + // Check that an extra flush doesn't output any more data + av_write_frame(ctx, NULL); + check(out_size == prev_pos, "More data written?"); + close_out(); + memcpy(content, hash, HASH_SIZE); + // Ignore the trailer written here + finish(); + + init_out("delay-moov-header"); + av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0); + init(0, 0); + check(out_size == 0, "Output written during init with delay_moov"); + mux_gops(1); // Write 1 second of content + av_write_frame(ctx, NULL); // Force writing the moov + close_out(); + check(!memcmp(hash, header, HASH_SIZE), "delay_moov header differs from empty_moov"); + init_out("delay-moov-content"); + av_write_frame(ctx, NULL); // Flush the first fragment + check(out_size == empty_moov_pos, "Manually flushed content differs from automatically flushed, %d vs %d", out_size, empty_moov_pos); + mux_gops(1); // Write the rest of the content + av_write_frame(ctx, NULL); // Flush the second fragment + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "delay_moov content differs from empty_moov"); + finish(); + + + // Verify that we can produce an identical second fragment without + // writing the first one. First write the reference fragments that + // we want to reproduce. + av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash", 0); + init(0, 0); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the first fragment + init_out("empty-moov-second-frag"); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + memcpy(content, hash, HASH_SIZE); + finish(); + + // Produce the same second fragment without actually writing the first + // one before. + av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash+frag_discont", 0); + av_dict_set(&opts, "fragment_index", "2", 0); + av_dict_set(&opts, "avoid_negative_ts", "0", 0); + av_dict_set(&opts, "use_editlist", "0", 0); + init(0, 0); + skip_gops(1); + init_out("empty-moov-second-frag-discont"); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); + finish(); + + // Produce the same thing by using delay_moov, which requires a slightly + // different call sequence. + av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); + av_dict_set(&opts, "fragment_index", "2", 0); + init(0, 0); + skip_gops(1); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the moov + init_out("delay-moov-second-frag-discont"); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); + finish(); + + + // Test discontinuously written fragments with B-frames (where the + // assumption of starting at pts=0 works) but not with audio preroll + // (which can't be guessed). + av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0); + init(1, 0); + mux_gops(1); + init_out("delay-moov-elst-init"); + av_write_frame(ctx, NULL); // Output the moov + close_out(); + memcpy(header, hash, HASH_SIZE); + av_write_frame(ctx, NULL); // Output the first fragment + init_out("delay-moov-elst-second-frag"); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + memcpy(content, hash, HASH_SIZE); + finish(); + + av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); + av_dict_set(&opts, "fragment_index", "2", 0); + init(1, 0); + skip_gops(1); + mux_gops(1); // Write the second fragment + init_out("delay-moov-elst-init-discont"); + av_write_frame(ctx, NULL); // Output the moov + close_out(); + check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs"); + init_out("delay-moov-elst-second-frag-discont"); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); + finish(); + + + // Test discontinuously written fragments with B-frames and audio preroll, + // properly signaled. + av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0); + init(1, 1); + mux_gops(1); + init_out("delay-moov-elst-signal-init"); + av_write_frame(ctx, NULL); // Output the moov + close_out(); + memcpy(header, hash, HASH_SIZE); + av_write_frame(ctx, NULL); // Output the first fragment + init_out("delay-moov-elst-signal-second-frag"); + mux_gops(1); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + memcpy(content, hash, HASH_SIZE); + finish(); + + av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0); + av_dict_set(&opts, "fragment_index", "2", 0); + init(1, 1); + signal_init_ts(); + skip_gops(1); + mux_gops(1); // Write the second fragment + init_out("delay-moov-elst-signal-init-discont"); + av_write_frame(ctx, NULL); // Output the moov + close_out(); + check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs"); + init_out("delay-moov-elst-signal-second-frag-discont"); + av_write_frame(ctx, NULL); // Output the second fragment + close_out(); + check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs"); + finish(); + + + // Test VFR content, with sidx atoms (which declare the pts duration + // of a fragment, forcing overriding the start pts of the next one). + // Here, the fragment duration in pts is significantly different from + // the duration in dts. The video stream starts at dts=-10,pts=0, and + // the second fragment starts at dts=155,pts=156. The trun duration sum + // of the first fragment is 165, which also is written as + // baseMediaDecodeTime in the tfdt in the second fragment. The sidx for + // the first fragment says earliest_presentation_time = 0 and + // subsegment_duration = 156, which also matches the sidx in the second + // fragment. For the audio stream, the pts and dts durations also don't + // match - the input stream starts at pts=-2048, but that part is excluded + // by the edit list. + init_out("vfr"); + av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0); + init_fps(1, 1, 3); + mux_frames(gop_size/2); + duration /= 10; + mux_frames(gop_size/2); + mux_gops(1); + finish(); + close_out(); + + // Test VFR content, with cleared duration fields. In these cases, + // the muxer must guess the duration of the last packet of each + // fragment. As long as the framerate doesn't vary (too much) at the + // fragment edge, it works just fine. Additionally, when automatically + // cutting fragments, the muxer already know the timestamps of the next + // packet for one stream (in most cases the video stream), avoiding + // having to use guesses for that one. + init_count_warnings(); + clear_duration = 1; + init_out("vfr-noduration"); + av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0); + init_fps(1, 1, 3); + mux_frames(gop_size/2); + duration /= 10; + mux_frames(gop_size/2); + mux_gops(1); + finish(); + close_out(); + clear_duration = 0; + reset_count_warnings(); + check(num_warnings > 0, "No warnings printed for filled in durations"); + + av_free(md5); + + return check_faults > 0 ? 1 : 0; +} diff --git a/libavformat/tests/noproxy.c b/libavformat/tests/noproxy.c new file mode 100644 index 0000000000..9daee052d9 --- /dev/null +++ b/libavformat/tests/noproxy.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013 Martin Storsjo + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/network.h" + +static void test(const char *pattern, const char *host) +{ + int res = ff_http_match_no_proxy(pattern, host); + printf("The pattern \"%s\" %s the hostname %s\n", + pattern ? pattern : "(null)", res ? "matches" : "does not match", + host); +} + +int main(void) +{ + test(NULL, "domain.com"); + test("example.com domain.com", "domain.com"); + test("example.com other.com", "domain.com"); + test("example.com,domain.com", "domain.com"); + test("example.com,domain.com", "otherdomain.com"); + test("example.com, *.domain.com", "sub.domain.com"); + test("example.com, *.domain.com", "domain.com"); + test("example.com, .domain.com", "domain.com"); + test("*", "domain.com"); + return 0; +} diff --git a/libavformat/tests/rtmpdh.c b/libavformat/tests/rtmpdh.c new file mode 100644 index 0000000000..c25ca91b7e --- /dev/null +++ b/libavformat/tests/rtmpdh.c @@ -0,0 +1,158 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/rtmpdh.c" + +#include + +static int test_random_shared_secret(void) +{ + FF_DH *peer1 = NULL, *peer2 = NULL; + int ret; + uint8_t pubkey1[128], pubkey2[128]; + uint8_t sharedkey1[128], sharedkey2[128]; + + peer1 = ff_dh_init(1024); + peer2 = ff_dh_init(1024); + if (!peer1 || !peer2) { + ret = AVERROR(ENOMEM); + goto fail; + } + if ((ret = ff_dh_generate_public_key(peer1)) < 0) + goto fail; + if ((ret = ff_dh_generate_public_key(peer2)) < 0) + goto fail; + if ((ret = ff_dh_write_public_key(peer1, pubkey1, sizeof(pubkey1))) < 0) + goto fail; + if ((ret = ff_dh_write_public_key(peer2, pubkey2, sizeof(pubkey2))) < 0) + goto fail; + if ((ret = ff_dh_compute_shared_secret_key(peer1, pubkey2, sizeof(pubkey2), + sharedkey1, sizeof(sharedkey1))) < 0) + goto fail; + if ((ret = ff_dh_compute_shared_secret_key(peer2, pubkey1, sizeof(pubkey1), + sharedkey2, sizeof(sharedkey2))) < 0) + goto fail; + if (memcmp(sharedkey1, sharedkey2, sizeof(sharedkey1))) { + printf("Mismatched generated shared key\n"); + ret = AVERROR_INVALIDDATA; + } else { + printf("Generated shared key ok\n"); + } +fail: + ff_dh_free(peer1); + ff_dh_free(peer2); + return ret; +} + +static const char *private_key = + "976C18FCADC255B456564F74F3EEDA59D28AF6B744D743F2357BFD2404797EF896EF1A" + "7C1CBEAAA3AB60AF3192D189CFF3F991C9CBBFD78119FCA2181384B94011943B6D6F28" + "9E1B708E2D1A0C7771169293F03DA27E561F15F16F0AC9BC858C77A80FA98FD088A232" + "19D08BE6F165DE0B02034B18705829FAD0ACB26A5B75EF"; +static const char *public_key = + "F272ECF8362257C5D2C3CC2229CF9C0A03225BC109B1DBC76A68C394F256ACA3EF5F64" + "FC270C26382BF315C19E97A76104A716FC998A651E8610A3AE6CF65D8FAE5D3F32EEA0" + "0B32CB9609B494116A825D7142D17B88E3D20EDD98743DE29CF37A23A9F6A58B960591" + "3157D5965FCB46DDA73A1F08DD897BAE88DFE6FC937CBA"; +static const uint8_t public_key_bin[] = { + 0xf2, 0x72, 0xec, 0xf8, 0x36, 0x22, 0x57, 0xc5, 0xd2, 0xc3, 0xcc, 0x22, + 0x29, 0xcf, 0x9c, 0x0a, 0x03, 0x22, 0x5b, 0xc1, 0x09, 0xb1, 0xdb, 0xc7, + 0x6a, 0x68, 0xc3, 0x94, 0xf2, 0x56, 0xac, 0xa3, 0xef, 0x5f, 0x64, 0xfc, + 0x27, 0x0c, 0x26, 0x38, 0x2b, 0xf3, 0x15, 0xc1, 0x9e, 0x97, 0xa7, 0x61, + 0x04, 0xa7, 0x16, 0xfc, 0x99, 0x8a, 0x65, 0x1e, 0x86, 0x10, 0xa3, 0xae, + 0x6c, 0xf6, 0x5d, 0x8f, 0xae, 0x5d, 0x3f, 0x32, 0xee, 0xa0, 0x0b, 0x32, + 0xcb, 0x96, 0x09, 0xb4, 0x94, 0x11, 0x6a, 0x82, 0x5d, 0x71, 0x42, 0xd1, + 0x7b, 0x88, 0xe3, 0xd2, 0x0e, 0xdd, 0x98, 0x74, 0x3d, 0xe2, 0x9c, 0xf3, + 0x7a, 0x23, 0xa9, 0xf6, 0xa5, 0x8b, 0x96, 0x05, 0x91, 0x31, 0x57, 0xd5, + 0x96, 0x5f, 0xcb, 0x46, 0xdd, 0xa7, 0x3a, 0x1f, 0x08, 0xdd, 0x89, 0x7b, + 0xae, 0x88, 0xdf, 0xe6, 0xfc, 0x93, 0x7c, 0xba +}; +static const uint8_t peer_public_key[] = { + 0x58, 0x66, 0x05, 0x49, 0x94, 0x23, 0x2b, 0x66, 0x52, 0x13, 0xff, 0x46, + 0xf2, 0xb3, 0x79, 0xa9, 0xee, 0xae, 0x1a, 0x13, 0xf0, 0x71, 0x52, 0xfb, + 0x93, 0x4e, 0xee, 0x97, 0x05, 0x73, 0x50, 0x7d, 0xaf, 0x02, 0x07, 0x72, + 0xac, 0xdc, 0xa3, 0x95, 0x78, 0xee, 0x9a, 0x19, 0x71, 0x7e, 0x99, 0x9f, + 0x2a, 0xd4, 0xb3, 0xe2, 0x0c, 0x1d, 0x1a, 0x78, 0x4c, 0xde, 0xf1, 0xad, + 0xb4, 0x60, 0xa8, 0x51, 0xac, 0x71, 0xec, 0x86, 0x70, 0xa2, 0x63, 0x36, + 0x92, 0x7c, 0xe3, 0x87, 0xee, 0xe4, 0xf1, 0x62, 0x24, 0x74, 0xb4, 0x04, + 0xfa, 0x5c, 0xdf, 0xba, 0xfa, 0xa3, 0xc2, 0xbb, 0x62, 0x27, 0xd0, 0xf4, + 0xe4, 0x43, 0xda, 0x8a, 0x88, 0x69, 0x60, 0xe2, 0xdb, 0x75, 0x2a, 0x98, + 0x9d, 0xb5, 0x50, 0xe3, 0x99, 0xda, 0xe0, 0xa6, 0x14, 0xc9, 0x80, 0x12, + 0xf9, 0x3c, 0xac, 0x06, 0x02, 0x7a, 0xde, 0x74 +}; +static const uint8_t shared_secret[] = { + 0xb2, 0xeb, 0xcb, 0x71, 0xf3, 0x61, 0xfb, 0x5b, 0x4e, 0x5c, 0x4c, 0xcf, + 0x5c, 0x08, 0x5f, 0x96, 0x26, 0x77, 0x1d, 0x31, 0xf1, 0xe1, 0xf7, 0x4b, + 0x92, 0xac, 0x82, 0x2a, 0x88, 0xc7, 0x83, 0xe1, 0xc7, 0xf3, 0xd3, 0x1a, + 0x7d, 0xc8, 0x31, 0xe3, 0x97, 0xe4, 0xec, 0x31, 0x0e, 0x8f, 0x73, 0x1a, + 0xe4, 0xf6, 0xd8, 0xc8, 0x94, 0xff, 0xa0, 0x03, 0x84, 0x03, 0x0f, 0xa5, + 0x30, 0x5d, 0x67, 0xe0, 0x7a, 0x3b, 0x5f, 0xed, 0x4c, 0xf5, 0xbc, 0x18, + 0xea, 0xd4, 0x77, 0xa9, 0x07, 0xb3, 0x54, 0x0b, 0x02, 0xd9, 0xc6, 0xb8, + 0x66, 0x5e, 0xec, 0xa4, 0xcd, 0x47, 0xed, 0xc9, 0x38, 0xc6, 0x91, 0x08, + 0xf3, 0x85, 0x9b, 0x69, 0x16, 0x78, 0x0d, 0xb7, 0x74, 0x51, 0xaa, 0x5b, + 0x4d, 0x74, 0xe4, 0x29, 0x2e, 0x9e, 0x8e, 0xf7, 0xe5, 0x42, 0x83, 0xb0, + 0x65, 0xb0, 0xce, 0xc6, 0xb2, 0x8f, 0x5b, 0xb0 +}; + +static int test_ref_data(void) +{ + FF_DH *dh; + int ret = AVERROR(ENOMEM); + uint8_t pubkey_test[128]; + uint8_t sharedkey_test[128]; + + dh = ff_dh_init(1024); + if (!dh) + goto fail; + bn_hex2bn(dh->priv_key, private_key, ret); + if (!ret) + goto fail; + bn_hex2bn(dh->pub_key, public_key, ret); + if (!ret) + goto fail; + if ((ret = ff_dh_write_public_key(dh, pubkey_test, sizeof(pubkey_test))) < 0) + goto fail; + if (memcmp(pubkey_test, public_key_bin, sizeof(pubkey_test))) { + printf("Mismatched generated public key\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } else { + printf("Generated public key ok\n"); + } + if ((ret = ff_dh_compute_shared_secret_key(dh, peer_public_key, sizeof(peer_public_key), + sharedkey_test, sizeof(sharedkey_test))) < 0) + goto fail; + if (memcmp(shared_secret, sharedkey_test, sizeof(sharedkey_test))) { + printf("Mismatched generated shared key\n"); + ret = AVERROR_INVALIDDATA; + } else { + printf("Generated shared key ok\n"); + } +fail: + ff_dh_free(dh); + return ret; +} + +int main(void) +{ + if (test_random_shared_secret() < 0) + return 1; + if (test_ref_data() < 0) + return 1; + return 0; +} diff --git a/libavformat/tests/seek.c b/libavformat/tests/seek.c new file mode 100644 index 0000000000..82da3744db --- /dev/null +++ b/libavformat/tests/seek.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2007 Michael Niedermayer + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/common.h" +#include "libavutil/mathematics.h" + +#include "libavformat/avformat.h" + +static char buffer[20]; + +static const char *ret_str(int v) +{ + switch (v) { + case AVERROR_EOF: return "-EOF"; + case AVERROR(EIO): return "-EIO"; + case AVERROR(ENOMEM): return "-ENOMEM"; + case AVERROR(EINVAL): return "-EINVAL"; + default: + snprintf(buffer, sizeof(buffer), "%2d", v); + return buffer; + } +} + +static void ts_str(char buffer[60], int64_t ts, AVRational base) +{ + double tsval; + if (ts == AV_NOPTS_VALUE) { + strcpy(buffer, " NOPTS "); + return; + } + tsval = ts * av_q2d(base); + snprintf(buffer, 60, "%9f", tsval); +} + +int main(int argc, char **argv) +{ + const char *filename; + AVFormatContext *ic = NULL; + int i, ret, stream_id; + int64_t timestamp; + AVDictionary *format_opts = NULL; + + av_dict_set(&format_opts, "channels", "1", 0); + av_dict_set(&format_opts, "sample_rate", "22050", 0); + + /* initialize libavcodec, and register all codecs and formats */ + av_register_all(); + + if (argc != 2) { + printf("usage: %s input_file\n" + "\n", argv[0]); + return 1; + } + + filename = argv[1]; + + ret = avformat_open_input(&ic, filename, NULL, &format_opts); + av_dict_free(&format_opts); + if (ret < 0) { + fprintf(stderr, "cannot open %s\n", filename); + return 1; + } + + ret = avformat_find_stream_info(ic, NULL); + if (ret < 0) { + fprintf(stderr, "%s: could not find codec parameters\n", filename); + return 1; + } + + for(i=0; ; i++){ + AVPacket pkt = { 0 }; + AVStream *av_uninit(st); + char ts_buf[60]; + + if(ret>=0){ + ret= av_read_frame(ic, &pkt); + if(ret>=0){ + char dts_buf[60]; + st= ic->streams[pkt.stream_index]; + ts_str(dts_buf, pkt.dts, st->time_base); + ts_str(ts_buf, pkt.pts, st->time_base); + printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size); + av_packet_unref(&pkt); + } else + printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace + printf("\n"); + } + + if(i>25) break; + + stream_id= (i>>1)%(ic->nb_streams+1) - 1; + timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE; + if(stream_id>=0){ + st= ic->streams[stream_id]; + timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base); + } + //FIXME fully test the new seek API + if(i&1) ret = avformat_seek_file(ic, stream_id, INT64_MIN, timestamp, timestamp, 0); + else ret = avformat_seek_file(ic, stream_id, timestamp, timestamp, INT64_MAX, 0); + ts_str(ts_buf, timestamp, stream_id < 0 ? AV_TIME_BASE_Q : st->time_base); + printf("ret:%-10s st:%2d flags:%d ts:%s\n", ret_str(ret), stream_id, i&1, ts_buf); + } + + avformat_close_input(&ic); + + return 0; +} diff --git a/libavformat/tests/srtp.c b/libavformat/tests/srtp.c new file mode 100644 index 0000000000..1703193620 --- /dev/null +++ b/libavformat/tests/srtp.c @@ -0,0 +1,167 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "libavformat/rtpdec.h" +#include "libavformat/srtp.h" + +static const char *aes128_80_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; + +static const uint8_t rtp_aes128_80[] = { + // RTP header + 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x62, 0x69, 0x76, 0xca, 0xc5, + // HMAC + 0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99, +}; + +static const uint8_t rtcp_aes128_80[] = { + // RTCP header + 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda, + 0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35, + // RTCP index + 0x80, 0x00, 0x00, 0x03, + // HMAC + 0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde, +}; + +static const char *aes128_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; + +static const uint8_t rtp_aes128_32[] = { + // RTP header + 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x62, 0x69, 0x76, 0xca, 0xc5, + // HMAC + 0xa1, 0xac, 0x1b, 0xb4, +}; + +static const uint8_t rtcp_aes128_32[] = { + // RTCP header + 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b, + 0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34, + // RTCP index + 0x80, 0x00, 0x00, 0x04, + // HMAC + 0x5b, 0xd2, 0xa9, 0x9d, +}; + +static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; + +static const uint8_t rtp_aes128_80_32[] = { + // RTP header + 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x62, 0x69, 0x76, 0xca, 0xc5, + // HMAC + 0xa1, 0xac, 0x1b, 0xb4, +}; + +static const uint8_t rtcp_aes128_80_32[] = { + // RTCP header + 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53, + 0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9, + // RTCP index + 0x80, 0x00, 0x00, 0x05, + // HMAC + 0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10, +}; + +static void print_data(const uint8_t *buf, int len) +{ + int i; + for (i = 0; i < len; i++) + printf("%02x", buf[i]); + printf("\n"); +} + +static int test_decrypt(struct SRTPContext *srtp, const uint8_t *in, int len, + uint8_t *out) +{ + memcpy(out, in, len); + if (!ff_srtp_decrypt(srtp, out, &len)) { + print_data(out, len); + return len; + } else + return -1; +} + +static void test_encrypt(const uint8_t *data, int in_len, const char *suite, + const char *key) +{ + struct SRTPContext enc = { 0 }, dec = { 0 }; + int len; + char buf[RTP_MAX_PACKET_LENGTH]; + ff_srtp_set_crypto(&enc, suite, key); + ff_srtp_set_crypto(&dec, suite, key); + len = ff_srtp_encrypt(&enc, data, in_len, buf, sizeof(buf)); + if (!ff_srtp_decrypt(&dec, buf, &len)) { + if (len == in_len && !memcmp(buf, data, len)) + printf("Decrypted content matches input\n"); + else + printf("Decrypted content doesn't match input\n"); + } else { + printf("Decryption failed\n"); + } + ff_srtp_free(&enc); + ff_srtp_free(&dec); +} + +int main(void) +{ + static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80"; + static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32"; + static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32"; + static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD"; + uint8_t buf[RTP_MAX_PACKET_LENGTH]; + struct SRTPContext srtp = { 0 }; + int len; + ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key); + len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf); + test_encrypt(buf, len, aes128_80_suite, test_key); + test_encrypt(buf, len, aes128_32_suite, test_key); + test_encrypt(buf, len, aes128_80_32_suite, test_key); + test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf); + test_encrypt(buf, len, aes128_80_suite, test_key); + test_encrypt(buf, len, aes128_32_suite, test_key); + test_encrypt(buf, len, aes128_80_32_suite, test_key); + ff_srtp_free(&srtp); + + memset(&srtp, 0, sizeof(srtp)); // Clear the context + ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key); + test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf); + test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf); + ff_srtp_free(&srtp); + + memset(&srtp, 0, sizeof(srtp)); // Clear the context + ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key); + test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf); + test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf); + ff_srtp_free(&srtp); + return 0; +} diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c new file mode 100644 index 0000000000..ec33173e40 --- /dev/null +++ b/libavformat/tests/url.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012 Martin Storsjo + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavformat/url.h" + +static void test(const char *base, const char *rel) +{ + char buf[200], buf2[200]; + ff_make_absolute_url(buf, sizeof(buf), base, rel); + printf("%s\n", buf); + if (base) { + /* Test in-buffer replacement */ + snprintf(buf2, sizeof(buf2), "%s", base); + ff_make_absolute_url(buf2, sizeof(buf2), buf2, rel); + if (strcmp(buf, buf2)) { + printf("In-place handling of %s + %s failed\n", base, rel); + exit(1); + } + } +} + +int main(void) +{ + test(NULL, "baz"); + test("/foo/bar", "baz"); + test("/foo/bar", "../baz"); + test("/foo/bar", "/baz"); + test("http://server/foo/", "baz"); + test("http://server/foo/bar", "baz"); + test("http://server/foo/", "../baz"); + test("http://server/foo/bar/123", "../../baz"); + test("http://server/foo/bar/123", "/baz"); + test("http://server/foo/bar/123", "https://other/url"); + test("http://server/foo/bar?param=value/with/slashes", "/baz"); + test("http://server/foo/bar?param&otherparam", "?someparam"); + test("http://server/foo/bar", "//other/url"); + return 0; +} diff --git a/libavformat/url-test.c b/libavformat/url-test.c deleted file mode 100644 index 503b36e572..0000000000 --- a/libavformat/url-test.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2012 Martin Storsjo - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "url.h" - -static void test(const char *base, const char *rel) -{ - char buf[200], buf2[200]; - ff_make_absolute_url(buf, sizeof(buf), base, rel); - printf("%s\n", buf); - if (base) { - /* Test in-buffer replacement */ - snprintf(buf2, sizeof(buf2), "%s", base); - ff_make_absolute_url(buf2, sizeof(buf2), buf2, rel); - if (strcmp(buf, buf2)) { - printf("In-place handling of %s + %s failed\n", base, rel); - exit(1); - } - } -} - -int main(void) -{ - test(NULL, "baz"); - test("/foo/bar", "baz"); - test("/foo/bar", "../baz"); - test("/foo/bar", "/baz"); - test("http://server/foo/", "baz"); - test("http://server/foo/bar", "baz"); - test("http://server/foo/", "../baz"); - test("http://server/foo/bar/123", "../../baz"); - test("http://server/foo/bar/123", "/baz"); - test("http://server/foo/bar/123", "https://other/url"); - test("http://server/foo/bar?param=value/with/slashes", "/baz"); - test("http://server/foo/bar?param&otherparam", "?someparam"); - test("http://server/foo/bar", "//other/url"); - return 0; -} diff --git a/libavresample/avresample-test.c b/libavresample/avresample-test.c deleted file mode 100644 index 697b4ba799..0000000000 --- a/libavresample/avresample-test.c +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2002 Fabrice Bellard - * Copyright (c) 2012 Justin Ruggles - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "libavutil/avstring.h" -#include "libavutil/common.h" -#include "libavutil/lfg.h" -#include "libavutil/libm.h" -#include "libavutil/log.h" -#include "libavutil/mem.h" -#include "libavutil/opt.h" -#include "libavutil/samplefmt.h" -#include "avresample.h" - -static double dbl_rand(AVLFG *lfg) -{ - return 2.0 * (av_lfg_get(lfg) / (double)UINT_MAX) - 1.0; -} - -#define PUT_FUNC(name, fmt, type, expr) \ -static void put_sample_ ## name(void **data, enum AVSampleFormat sample_fmt,\ - int channels, int sample, int ch, \ - double v_dbl) \ -{ \ - type v = expr; \ - type **out = (type **)data; \ - if (av_sample_fmt_is_planar(sample_fmt)) \ - out[ch][sample] = v; \ - else \ - out[0][sample * channels + ch] = v; \ -} - -PUT_FUNC(u8, AV_SAMPLE_FMT_U8, uint8_t, av_clip_uint8 ( lrint(v_dbl * (1 << 7)) + 128)) -PUT_FUNC(s16, AV_SAMPLE_FMT_S16, int16_t, av_clip_int16 ( lrint(v_dbl * (1 << 15)))) -PUT_FUNC(s32, AV_SAMPLE_FMT_S32, int32_t, av_clipl_int32(llrint(v_dbl * (1U << 31)))) -PUT_FUNC(flt, AV_SAMPLE_FMT_FLT, float, v_dbl) -PUT_FUNC(dbl, AV_SAMPLE_FMT_DBL, double, v_dbl) - -static void put_sample(void **data, enum AVSampleFormat sample_fmt, - int channels, int sample, int ch, double v_dbl) -{ - switch (av_get_packed_sample_fmt(sample_fmt)) { - case AV_SAMPLE_FMT_U8: - put_sample_u8(data, sample_fmt, channels, sample, ch, v_dbl); - break; - case AV_SAMPLE_FMT_S16: - put_sample_s16(data, sample_fmt, channels, sample, ch, v_dbl); - break; - case AV_SAMPLE_FMT_S32: - put_sample_s32(data, sample_fmt, channels, sample, ch, v_dbl); - break; - case AV_SAMPLE_FMT_FLT: - put_sample_flt(data, sample_fmt, channels, sample, ch, v_dbl); - break; - case AV_SAMPLE_FMT_DBL: - put_sample_dbl(data, sample_fmt, channels, sample, ch, v_dbl); - break; - } -} - -static void audiogen(AVLFG *rnd, void **data, enum AVSampleFormat sample_fmt, - int channels, int sample_rate, int nb_samples) -{ - int i, ch, k; - double v, f, a, ampa; - double tabf1[AVRESAMPLE_MAX_CHANNELS]; - double tabf2[AVRESAMPLE_MAX_CHANNELS]; - double taba[AVRESAMPLE_MAX_CHANNELS]; - -#define PUT_SAMPLE put_sample(data, sample_fmt, channels, k, ch, v); - - k = 0; - - /* 1 second of single freq sine at 1000 Hz */ - a = 0; - for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { - v = sin(a) * 0.30; - for (ch = 0; ch < channels; ch++) - PUT_SAMPLE - a += M_PI * 1000.0 * 2.0 / sample_rate; - } - - /* 1 second of varying frequency between 100 and 10000 Hz */ - a = 0; - for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { - v = sin(a) * 0.30; - for (ch = 0; ch < channels; ch++) - PUT_SAMPLE - f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate); - a += M_PI * f * 2.0 / sample_rate; - } - - /* 0.5 second of low amplitude white noise */ - for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { - v = dbl_rand(rnd) * 0.30; - for (ch = 0; ch < channels; ch++) - PUT_SAMPLE - } - - /* 0.5 second of high amplitude white noise */ - for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { - v = dbl_rand(rnd); - for (ch = 0; ch < channels; ch++) - PUT_SAMPLE - } - - /* 1 second of unrelated ramps for each channel */ - for (ch = 0; ch < channels; ch++) { - taba[ch] = 0; - tabf1[ch] = 100 + av_lfg_get(rnd) % 5000; - tabf2[ch] = 100 + av_lfg_get(rnd) % 5000; - } - for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { - for (ch = 0; ch < channels; ch++) { - v = sin(taba[ch]) * 0.30; - PUT_SAMPLE - f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate); - taba[ch] += M_PI * f * 2.0 / sample_rate; - } - } - - /* 2 seconds of 500 Hz with varying volume */ - a = 0; - ampa = 0; - for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) { - for (ch = 0; ch < channels; ch++) { - double amp = (1.0 + sin(ampa)) * 0.15; - if (ch & 1) - amp = 0.30 - amp; - v = sin(a) * amp; - PUT_SAMPLE - a += M_PI * 500.0 * 2.0 / sample_rate; - ampa += M_PI * 2.0 / sample_rate; - } - } -} - -/* formats, rates, and layouts are ordered for priority in testing. - e.g. 'avresample-test 4 2 2' will test all input/output combinations of - S16/FLTP/S16P/FLT, 48000/44100, and stereo/mono */ - -static const enum AVSampleFormat formats[] = { - AV_SAMPLE_FMT_S16, - AV_SAMPLE_FMT_FLTP, - AV_SAMPLE_FMT_S16P, - AV_SAMPLE_FMT_FLT, - AV_SAMPLE_FMT_S32P, - AV_SAMPLE_FMT_S32, - AV_SAMPLE_FMT_U8P, - AV_SAMPLE_FMT_U8, - AV_SAMPLE_FMT_DBLP, - AV_SAMPLE_FMT_DBL, -}; - -static const int rates[] = { - 48000, - 44100, - 16000 -}; - -static const uint64_t layouts[] = { - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_5POINT1, - AV_CH_LAYOUT_7POINT1, -}; - -int main(int argc, char **argv) -{ - AVAudioResampleContext *s; - AVLFG rnd; - int ret = 0; - uint8_t *in_buf = NULL; - uint8_t *out_buf = NULL; - unsigned int in_buf_size; - unsigned int out_buf_size; - uint8_t *in_data[AVRESAMPLE_MAX_CHANNELS] = { 0 }; - uint8_t *out_data[AVRESAMPLE_MAX_CHANNELS] = { 0 }; - int in_linesize; - int out_linesize; - uint64_t in_ch_layout; - int in_channels; - enum AVSampleFormat in_fmt; - int in_rate; - uint64_t out_ch_layout; - int out_channels; - enum AVSampleFormat out_fmt; - int out_rate; - int num_formats, num_rates, num_layouts; - int i, j, k, l, m, n; - - num_formats = 2; - num_rates = 2; - num_layouts = 2; - if (argc > 1) { - if (!av_strncasecmp(argv[1], "-h", 3)) { - av_log(NULL, AV_LOG_INFO, "Usage: avresample-test [ " - "[ []]]\n" - "Default is 2 2 2\n"); - return 0; - } - num_formats = strtol(argv[1], NULL, 0); - num_formats = av_clip(num_formats, 1, FF_ARRAY_ELEMS(formats)); - } - if (argc > 2) { - num_rates = strtol(argv[2], NULL, 0); - num_rates = av_clip(num_rates, 1, FF_ARRAY_ELEMS(rates)); - } - if (argc > 3) { - num_layouts = strtol(argv[3], NULL, 0); - num_layouts = av_clip(num_layouts, 1, FF_ARRAY_ELEMS(layouts)); - } - - av_log_set_level(AV_LOG_DEBUG); - - av_lfg_init(&rnd, 0xC0FFEE); - - in_buf_size = av_samples_get_buffer_size(&in_linesize, 8, 48000 * 6, - AV_SAMPLE_FMT_DBLP, 0); - out_buf_size = in_buf_size; - - in_buf = av_malloc(in_buf_size); - if (!in_buf) - goto end; - out_buf = av_malloc(out_buf_size); - if (!out_buf) - goto end; - - s = avresample_alloc_context(); - if (!s) { - av_log(NULL, AV_LOG_ERROR, "Error allocating AVAudioResampleContext\n"); - ret = 1; - goto end; - } - - for (i = 0; i < num_formats; i++) { - in_fmt = formats[i]; - for (k = 0; k < num_layouts; k++) { - in_ch_layout = layouts[k]; - in_channels = av_get_channel_layout_nb_channels(in_ch_layout); - for (m = 0; m < num_rates; m++) { - in_rate = rates[m]; - - ret = av_samples_fill_arrays(in_data, &in_linesize, in_buf, - in_channels, in_rate * 6, - in_fmt, 0); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "failed in_data fill arrays\n"); - goto end; - } - audiogen(&rnd, (void **)in_data, in_fmt, in_channels, in_rate, in_rate * 6); - - for (j = 0; j < num_formats; j++) { - out_fmt = formats[j]; - for (l = 0; l < num_layouts; l++) { - out_ch_layout = layouts[l]; - out_channels = av_get_channel_layout_nb_channels(out_ch_layout); - for (n = 0; n < num_rates; n++) { - out_rate = rates[n]; - - av_log(NULL, AV_LOG_INFO, "%s to %s, %d to %d channels, %d Hz to %d Hz\n", - av_get_sample_fmt_name(in_fmt), av_get_sample_fmt_name(out_fmt), - in_channels, out_channels, in_rate, out_rate); - - ret = av_samples_fill_arrays(out_data, &out_linesize, - out_buf, out_channels, - out_rate * 6, out_fmt, 0); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "failed out_data fill arrays\n"); - goto end; - } - - av_opt_set_int(s, "in_channel_layout", in_ch_layout, 0); - av_opt_set_int(s, "in_sample_fmt", in_fmt, 0); - av_opt_set_int(s, "in_sample_rate", in_rate, 0); - av_opt_set_int(s, "out_channel_layout", out_ch_layout, 0); - av_opt_set_int(s, "out_sample_fmt", out_fmt, 0); - av_opt_set_int(s, "out_sample_rate", out_rate, 0); - - av_opt_set_int(s, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); - - ret = avresample_open(s); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "Error opening context\n"); - goto end; - } - - ret = avresample_convert(s, out_data, out_linesize, out_rate * 6, - in_data, in_linesize, in_rate * 6); - if (ret < 0) { - char errbuf[256]; - av_strerror(ret, errbuf, sizeof(errbuf)); - av_log(NULL, AV_LOG_ERROR, "%s\n", errbuf); - goto end; - } - av_log(NULL, AV_LOG_INFO, "Converted %d samples to %d samples\n", - in_rate * 6, ret); - if (avresample_get_delay(s) > 0) - av_log(NULL, AV_LOG_INFO, "%d delay samples not converted\n", - avresample_get_delay(s)); - if (avresample_available(s) > 0) - av_log(NULL, AV_LOG_INFO, "%d samples available for output\n", - avresample_available(s)); - av_log(NULL, AV_LOG_INFO, "\n"); - - avresample_close(s); - } - } - } - } - } - } - - ret = 0; - -end: - av_freep(&in_buf); - av_freep(&out_buf); - avresample_free(&s); - return ret; -} diff --git a/libavresample/tests/.gitignore b/libavresample/tests/.gitignore new file mode 100644 index 0000000000..1e15871d54 --- /dev/null +++ b/libavresample/tests/.gitignore @@ -0,0 +1 @@ +/avresample diff --git a/libavresample/tests/avresample.c b/libavresample/tests/avresample.c new file mode 100644 index 0000000000..77599960f8 --- /dev/null +++ b/libavresample/tests/avresample.c @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2002 Fabrice Bellard + * Copyright (c) 2012 Justin Ruggles + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/avstring.h" +#include "libavutil/common.h" +#include "libavutil/lfg.h" +#include "libavutil/libm.h" +#include "libavutil/log.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" +#include "libavutil/samplefmt.h" + +#include "libavresample/avresample.h" + +static double dbl_rand(AVLFG *lfg) +{ + return 2.0 * (av_lfg_get(lfg) / (double)UINT_MAX) - 1.0; +} + +#define PUT_FUNC(name, fmt, type, expr) \ +static void put_sample_ ## name(void **data, enum AVSampleFormat sample_fmt,\ + int channels, int sample, int ch, \ + double v_dbl) \ +{ \ + type v = expr; \ + type **out = (type **)data; \ + if (av_sample_fmt_is_planar(sample_fmt)) \ + out[ch][sample] = v; \ + else \ + out[0][sample * channels + ch] = v; \ +} + +PUT_FUNC(u8, AV_SAMPLE_FMT_U8, uint8_t, av_clip_uint8 ( lrint(v_dbl * (1 << 7)) + 128)) +PUT_FUNC(s16, AV_SAMPLE_FMT_S16, int16_t, av_clip_int16 ( lrint(v_dbl * (1 << 15)))) +PUT_FUNC(s32, AV_SAMPLE_FMT_S32, int32_t, av_clipl_int32(llrint(v_dbl * (1U << 31)))) +PUT_FUNC(flt, AV_SAMPLE_FMT_FLT, float, v_dbl) +PUT_FUNC(dbl, AV_SAMPLE_FMT_DBL, double, v_dbl) + +static void put_sample(void **data, enum AVSampleFormat sample_fmt, + int channels, int sample, int ch, double v_dbl) +{ + switch (av_get_packed_sample_fmt(sample_fmt)) { + case AV_SAMPLE_FMT_U8: + put_sample_u8(data, sample_fmt, channels, sample, ch, v_dbl); + break; + case AV_SAMPLE_FMT_S16: + put_sample_s16(data, sample_fmt, channels, sample, ch, v_dbl); + break; + case AV_SAMPLE_FMT_S32: + put_sample_s32(data, sample_fmt, channels, sample, ch, v_dbl); + break; + case AV_SAMPLE_FMT_FLT: + put_sample_flt(data, sample_fmt, channels, sample, ch, v_dbl); + break; + case AV_SAMPLE_FMT_DBL: + put_sample_dbl(data, sample_fmt, channels, sample, ch, v_dbl); + break; + } +} + +static void audiogen(AVLFG *rnd, void **data, enum AVSampleFormat sample_fmt, + int channels, int sample_rate, int nb_samples) +{ + int i, ch, k; + double v, f, a, ampa; + double tabf1[AVRESAMPLE_MAX_CHANNELS]; + double tabf2[AVRESAMPLE_MAX_CHANNELS]; + double taba[AVRESAMPLE_MAX_CHANNELS]; + +#define PUT_SAMPLE put_sample(data, sample_fmt, channels, k, ch, v); + + k = 0; + + /* 1 second of single freq sine at 1000 Hz */ + a = 0; + for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { + v = sin(a) * 0.30; + for (ch = 0; ch < channels; ch++) + PUT_SAMPLE + a += M_PI * 1000.0 * 2.0 / sample_rate; + } + + /* 1 second of varying frequency between 100 and 10000 Hz */ + a = 0; + for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { + v = sin(a) * 0.30; + for (ch = 0; ch < channels; ch++) + PUT_SAMPLE + f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate); + a += M_PI * f * 2.0 / sample_rate; + } + + /* 0.5 second of low amplitude white noise */ + for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { + v = dbl_rand(rnd) * 0.30; + for (ch = 0; ch < channels; ch++) + PUT_SAMPLE + } + + /* 0.5 second of high amplitude white noise */ + for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { + v = dbl_rand(rnd); + for (ch = 0; ch < channels; ch++) + PUT_SAMPLE + } + + /* 1 second of unrelated ramps for each channel */ + for (ch = 0; ch < channels; ch++) { + taba[ch] = 0; + tabf1[ch] = 100 + av_lfg_get(rnd) % 5000; + tabf2[ch] = 100 + av_lfg_get(rnd) % 5000; + } + for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { + for (ch = 0; ch < channels; ch++) { + v = sin(taba[ch]) * 0.30; + PUT_SAMPLE + f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate); + taba[ch] += M_PI * f * 2.0 / sample_rate; + } + } + + /* 2 seconds of 500 Hz with varying volume */ + a = 0; + ampa = 0; + for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) { + for (ch = 0; ch < channels; ch++) { + double amp = (1.0 + sin(ampa)) * 0.15; + if (ch & 1) + amp = 0.30 - amp; + v = sin(a) * amp; + PUT_SAMPLE + a += M_PI * 500.0 * 2.0 / sample_rate; + ampa += M_PI * 2.0 / sample_rate; + } + } +} + +/* formats, rates, and layouts are ordered for priority in testing. + e.g. 'avresample-test 4 2 2' will test all input/output combinations of + S16/FLTP/S16P/FLT, 48000/44100, and stereo/mono */ + +static const enum AVSampleFormat formats[] = { + AV_SAMPLE_FMT_S16, + AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_S16P, + AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_S32P, + AV_SAMPLE_FMT_S32, + AV_SAMPLE_FMT_U8P, + AV_SAMPLE_FMT_U8, + AV_SAMPLE_FMT_DBLP, + AV_SAMPLE_FMT_DBL, +}; + +static const int rates[] = { + 48000, + 44100, + 16000 +}; + +static const uint64_t layouts[] = { + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_5POINT1, + AV_CH_LAYOUT_7POINT1, +}; + +int main(int argc, char **argv) +{ + AVAudioResampleContext *s; + AVLFG rnd; + int ret = 0; + uint8_t *in_buf = NULL; + uint8_t *out_buf = NULL; + unsigned int in_buf_size; + unsigned int out_buf_size; + uint8_t *in_data[AVRESAMPLE_MAX_CHANNELS] = { 0 }; + uint8_t *out_data[AVRESAMPLE_MAX_CHANNELS] = { 0 }; + int in_linesize; + int out_linesize; + uint64_t in_ch_layout; + int in_channels; + enum AVSampleFormat in_fmt; + int in_rate; + uint64_t out_ch_layout; + int out_channels; + enum AVSampleFormat out_fmt; + int out_rate; + int num_formats, num_rates, num_layouts; + int i, j, k, l, m, n; + + num_formats = 2; + num_rates = 2; + num_layouts = 2; + if (argc > 1) { + if (!av_strncasecmp(argv[1], "-h", 3)) { + av_log(NULL, AV_LOG_INFO, "Usage: avresample-test [ " + "[ []]]\n" + "Default is 2 2 2\n"); + return 0; + } + num_formats = strtol(argv[1], NULL, 0); + num_formats = av_clip(num_formats, 1, FF_ARRAY_ELEMS(formats)); + } + if (argc > 2) { + num_rates = strtol(argv[2], NULL, 0); + num_rates = av_clip(num_rates, 1, FF_ARRAY_ELEMS(rates)); + } + if (argc > 3) { + num_layouts = strtol(argv[3], NULL, 0); + num_layouts = av_clip(num_layouts, 1, FF_ARRAY_ELEMS(layouts)); + } + + av_log_set_level(AV_LOG_DEBUG); + + av_lfg_init(&rnd, 0xC0FFEE); + + in_buf_size = av_samples_get_buffer_size(&in_linesize, 8, 48000 * 6, + AV_SAMPLE_FMT_DBLP, 0); + out_buf_size = in_buf_size; + + in_buf = av_malloc(in_buf_size); + if (!in_buf) + goto end; + out_buf = av_malloc(out_buf_size); + if (!out_buf) + goto end; + + s = avresample_alloc_context(); + if (!s) { + av_log(NULL, AV_LOG_ERROR, "Error allocating AVAudioResampleContext\n"); + ret = 1; + goto end; + } + + for (i = 0; i < num_formats; i++) { + in_fmt = formats[i]; + for (k = 0; k < num_layouts; k++) { + in_ch_layout = layouts[k]; + in_channels = av_get_channel_layout_nb_channels(in_ch_layout); + for (m = 0; m < num_rates; m++) { + in_rate = rates[m]; + + ret = av_samples_fill_arrays(in_data, &in_linesize, in_buf, + in_channels, in_rate * 6, + in_fmt, 0); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "failed in_data fill arrays\n"); + goto end; + } + audiogen(&rnd, (void **)in_data, in_fmt, in_channels, in_rate, in_rate * 6); + + for (j = 0; j < num_formats; j++) { + out_fmt = formats[j]; + for (l = 0; l < num_layouts; l++) { + out_ch_layout = layouts[l]; + out_channels = av_get_channel_layout_nb_channels(out_ch_layout); + for (n = 0; n < num_rates; n++) { + out_rate = rates[n]; + + av_log(NULL, AV_LOG_INFO, "%s to %s, %d to %d channels, %d Hz to %d Hz\n", + av_get_sample_fmt_name(in_fmt), av_get_sample_fmt_name(out_fmt), + in_channels, out_channels, in_rate, out_rate); + + ret = av_samples_fill_arrays(out_data, &out_linesize, + out_buf, out_channels, + out_rate * 6, out_fmt, 0); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "failed out_data fill arrays\n"); + goto end; + } + + av_opt_set_int(s, "in_channel_layout", in_ch_layout, 0); + av_opt_set_int(s, "in_sample_fmt", in_fmt, 0); + av_opt_set_int(s, "in_sample_rate", in_rate, 0); + av_opt_set_int(s, "out_channel_layout", out_ch_layout, 0); + av_opt_set_int(s, "out_sample_fmt", out_fmt, 0); + av_opt_set_int(s, "out_sample_rate", out_rate, 0); + + av_opt_set_int(s, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); + + ret = avresample_open(s); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Error opening context\n"); + goto end; + } + + ret = avresample_convert(s, out_data, out_linesize, out_rate * 6, + in_data, in_linesize, in_rate * 6); + if (ret < 0) { + char errbuf[256]; + av_strerror(ret, errbuf, sizeof(errbuf)); + av_log(NULL, AV_LOG_ERROR, "%s\n", errbuf); + goto end; + } + av_log(NULL, AV_LOG_INFO, "Converted %d samples to %d samples\n", + in_rate * 6, ret); + if (avresample_get_delay(s) > 0) + av_log(NULL, AV_LOG_INFO, "%d delay samples not converted\n", + avresample_get_delay(s)); + if (avresample_available(s) > 0) + av_log(NULL, AV_LOG_INFO, "%d samples available for output\n", + avresample_available(s)); + av_log(NULL, AV_LOG_INFO, "\n"); + + avresample_close(s); + } + } + } + } + } + } + + ret = 0; + +end: + av_freep(&in_buf); + av_freep(&out_buf); + avresample_free(&s); + return ret; +} diff --git a/libavutil/adler32-test.c b/libavutil/adler32-test.c deleted file mode 100644 index ab109f9175..0000000000 --- a/libavutil/adler32-test.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "log.h" -#include "timer.h" -#include "adler32.h" - -#define LEN 7001 - -static volatile int checksum; - -int main(int argc, char **argv) -{ - int i; - char data[LEN]; - - av_log_set_level(AV_LOG_DEBUG); - - for (i = 0; i < LEN; i++) - data[i] = ((i * i) >> 3) + 123 * i; - - if (argc > 1 && !strcmp(argv[1], "-t")) { - for (i = 0; i < 1000; i++) { - START_TIMER; - checksum = av_adler32_update(1, data, LEN); - STOP_TIMER("adler"); - } - } else { - checksum = av_adler32_update(1, data, LEN); - } - - av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum); - return checksum == 0x50e6e508 ? 0 : 1; -} diff --git a/libavutil/aes-test.c b/libavutil/aes-test.c deleted file mode 100644 index afb5ad3685..0000000000 --- a/libavutil/aes-test.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "aes.c" - -#include - -#include "lfg.h" -#include "log.h" - -int main(int argc, char **argv) -{ - int i, j; - AVAES b; - static const uint8_t rkey[2][16] = { - { 0 }, - { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, - 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 } - }; - static const uint8_t rpt[2][16] = { - { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, - 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 }, - { 0 } - }; - static const uint8_t rct[2][16] = { - { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, - 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf }, - { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, - 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 } - }; - uint8_t pt[16], temp[16]; - int err = 0; - - av_log_set_level(AV_LOG_DEBUG); - - for (i = 0; i < 2; i++) { - av_aes_init(&b, rkey[i], 128, 1); - av_aes_crypt(&b, temp, rct[i], 1, NULL, 1); - for (j = 0; j < 16; j++) { - if (rpt[i][j] != temp[j]) { - av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", - j, rpt[i][j], temp[j]); - err = 1; - } - } - } - - if (argc > 1 && !strcmp(argv[1], "-t")) { - AVAES ae, ad; - AVLFG prng; - - av_aes_init(&ae, "PI=3.141592654..", 128, 0); - av_aes_init(&ad, "PI=3.141592654..", 128, 1); - av_lfg_init(&prng, 1); - - for (i = 0; i < 10000; i++) { - for (j = 0; j < 16; j++) - pt[j] = av_lfg_get(&prng); - { - START_TIMER; - av_aes_crypt(&ae, temp, pt, 1, NULL, 0); - if (!(i & (i - 1))) - av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", - temp[0], temp[5], temp[10], temp[15]); - av_aes_crypt(&ad, temp, temp, 1, NULL, 1); - STOP_TIMER("aes"); - } - for (j = 0; j < 16; j++) { - if (pt[j] != temp[j]) { - av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", - i, j, pt[j], temp[j]); - } - } - } - } - return err; -} diff --git a/libavutil/atomic-test.c b/libavutil/atomic-test.c deleted file mode 100644 index c0a89a461e..0000000000 --- a/libavutil/atomic-test.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "atomic.h" - -int main(void) -{ - volatile int val = 1; - int res; - - res = avpriv_atomic_int_add_and_fetch(&val, 1); - assert(res == 2); - avpriv_atomic_int_set(&val, 3); - res = avpriv_atomic_int_get(&val); - assert(res == 3); - - return 0; -} diff --git a/libavutil/avstring-test.c b/libavutil/avstring-test.c deleted file mode 100644 index fc4f0a415e..0000000000 --- a/libavutil/avstring-test.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "common.h" -#include "mem.h" -#include "avstring.h" - -int main(void) -{ - int i; - static const char *strings[] = { - "''", - "", - ":", - "\\", - "'", - " '' :", - " '' '' :", - "foo '' :", - "'foo'", - "foo ", - " ' foo ' ", - "foo\\", - "foo': blah:blah", - "foo\\: blah:blah", - "foo\'", - "'foo : ' :blahblah", - "\\ :blah", - " foo", - " foo ", - " foo \\ ", - "foo ':blah", - " foo bar : blahblah", - "\\f\\o\\o", - "'foo : \\ \\ ' : blahblah", - "'\\fo\\o:': blahblah", - "\\'fo\\o\\:': foo ' :blahblah" - }; - - printf("Testing av_get_token()\n"); - for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) { - const char *p = strings[i]; - char *q; - printf("|%s|", p); - q = av_get_token(&p, ":"); - printf(" -> |%s|", q); - printf(" + |%s|\n", p); - av_free(q); - } - - return 0; -} diff --git a/libavutil/base64-test.c b/libavutil/base64-test.c deleted file mode 100644 index 3ce0518a84..0000000000 --- a/libavutil/base64-test.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "common.h" -#include "base64.h" - -#define MAX_DATA_SIZE 1024 -#define MAX_ENCODED_SIZE 2048 - -static int test_encode_decode(const uint8_t *data, unsigned int data_size, - const char *encoded_ref) -{ - char encoded[MAX_ENCODED_SIZE]; - uint8_t data2[MAX_DATA_SIZE]; - int data2_size, max_data2_size = MAX_DATA_SIZE; - - if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) { - printf("Failed: cannot encode the input data\n"); - return 1; - } - if (encoded_ref && strcmp(encoded, encoded_ref)) { - printf("Failed: encoded string differs from reference\n" - "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref); - return 1; - } - - if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) { - printf("Failed: cannot decode the encoded string\n" - "Encoded:\n%s\n", encoded); - return 1; - } - if (memcmp(data2, data, data_size)) { - printf("Failed: encoded/decoded data differs from original data\n"); - return 1; - } - - printf("Passed!\n"); - return 0; -} - -int main(void) -{ - int i, error_count = 0; - struct test { - const uint8_t *data; - const char *encoded_ref; - } tests[] = { - { "", ""}, - { "1", "MQ=="}, - { "22", "MjI="}, - { "333", "MzMz"}, - { "4444", "NDQ0NA=="}, - { "55555", "NTU1NTU="}, - { "666666", "NjY2NjY2"}, - { "abc:def", "YWJjOmRlZg=="}, - }; - - printf("Encoding/decoding tests\n"); - for (i = 0; i < FF_ARRAY_ELEMS(tests); i++) - error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref); - - if (error_count) - printf("Error Count: %d.\n", error_count); - - return !!error_count; -} diff --git a/libavutil/blowfish-test.c b/libavutil/blowfish-test.c deleted file mode 100644 index 4281ca29bd..0000000000 --- a/libavutil/blowfish-test.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "blowfish.h" - -#define NUM_VARIABLE_KEY_TESTS 34 - -/* plaintext bytes -- left halves */ -static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = { - 0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111, - 0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8, - 0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0, - 0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18, - 0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577, - 0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567, - 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF -}; - -/* plaintext bytes -- right halves */ -static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = { - 0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111, - 0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA, - 0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2, - 0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA, - 0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A, - 0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF, - 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF -}; - -/* key bytes for variable key tests */ -static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }, - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, - { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }, - { 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 }, - { 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E }, - { 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 }, - { 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E }, - { 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 }, - { 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE }, - { 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 }, - { 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE }, - { 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 }, - { 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F }, - { 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 }, - { 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E }, - { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 }, - { 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 }, - { 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F }, - { 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 }, - { 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF }, - { 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 }, - { 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF }, - { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, - { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }, - { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, - { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 } -}; - -/* ciphertext bytes -- left halves */ -static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = { - 0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380, - 0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B, - 0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7, - 0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B, - 0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A, - 0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D, - 0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C -}; - -/* ciphertext bytes -- right halves */ -static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = { - 0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096, - 0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0, - 0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98, - 0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B, - 0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5, - 0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D, - 0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A -}; - -/* plaintext bytes */ -static const uint8_t plaintext[8] = "BLOWFISH"; - -static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH"; - -/* ciphertext bytes */ -static const uint8_t ciphertext[8] = { - 0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03 -}; - -static const uint8_t ciphertext2[16] = { - 0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99, - 0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1, -}; - -#define IV "blowfish" - -static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src, - const uint8_t *ref, int len, uint8_t *iv, int dir, - const char *test) -{ - av_blowfish_crypt(ctx, dst, src, len, iv, dir); - if (memcmp(dst, ref, 8*len)) { - int i; - printf("%s failed\ngot ", test); - for (i = 0; i < 8*len; i++) - printf("%02x ", dst[i]); - printf("\nexpected "); - for (i = 0; i < 8*len; i++) - printf("%02x ", ref[i]); - printf("\n"); - exit(1); - } -} - -int main(void) -{ - AVBlowfish ctx; - uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS]; - uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS]; - uint8_t tmp[16], iv[8]; - int i; - - av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26); - - test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption"); - test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption"); - test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption"); - test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption"); - memcpy(iv, IV, 8); - test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption"); - memcpy(iv, IV, 8); - test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption"); - memcpy(iv, IV, 8); - test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption"); - memcpy(iv, IV, 8); - test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption"); - - memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS); - memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS); - - for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) { - av_blowfish_init(&ctx, variable_key[i], 8); - - av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0); - if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) { - printf("Test encryption failed.\n"); - return 1; - } - - av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1); - if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) { - printf("Test decryption failed.\n"); - return 1; - } - } - printf("Test encryption/decryption success.\n"); - - return 0; -} - diff --git a/libavutil/cpu-test.c b/libavutil/cpu-test.c deleted file mode 100644 index a2c3b38c0d..0000000000 --- a/libavutil/cpu-test.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#if HAVE_UNISTD_H -#include -#elif !HAVE_GETOPT -#include "compat/getopt.c" -#endif - -#include -#include - -#include "avstring.h" -#include "common.h" -#include "cpu.h" - -static const struct { - int flag; - const char *name; -} cpu_flag_tab[] = { -#if ARCH_AARCH64 - { AV_CPU_FLAG_ARMV8, "armv8" }, - { AV_CPU_FLAG_NEON, "neon" }, - { AV_CPU_FLAG_VFP, "vfp" }, -#elif ARCH_ARM - { AV_CPU_FLAG_ARMV5TE, "armv5te" }, - { AV_CPU_FLAG_ARMV6, "armv6" }, - { AV_CPU_FLAG_ARMV6T2, "armv6t2" }, - { AV_CPU_FLAG_VFP, "vfp" }, - { AV_CPU_FLAG_VFP_VM, "vfp_vm" }, - { AV_CPU_FLAG_VFPV3, "vfpv3" }, - { AV_CPU_FLAG_NEON, "neon" }, -#elif ARCH_PPC - { AV_CPU_FLAG_ALTIVEC, "altivec" }, -#elif ARCH_X86 - { AV_CPU_FLAG_MMX, "mmx" }, - { AV_CPU_FLAG_MMXEXT, "mmxext" }, - { AV_CPU_FLAG_SSE, "sse" }, - { AV_CPU_FLAG_SSE2, "sse2" }, - { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" }, - { AV_CPU_FLAG_SSE3, "sse3" }, - { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" }, - { AV_CPU_FLAG_SSSE3, "ssse3" }, - { AV_CPU_FLAG_ATOM, "atom" }, - { AV_CPU_FLAG_SSE4, "sse4.1" }, - { AV_CPU_FLAG_SSE42, "sse4.2" }, - { AV_CPU_FLAG_AVX, "avx" }, - { AV_CPU_FLAG_AVXSLOW, "avxslow" }, - { AV_CPU_FLAG_XOP, "xop" }, - { AV_CPU_FLAG_FMA3, "fma3" }, - { AV_CPU_FLAG_FMA4, "fma4" }, - { AV_CPU_FLAG_3DNOW, "3dnow" }, - { AV_CPU_FLAG_3DNOWEXT, "3dnowext" }, - { AV_CPU_FLAG_CMOV, "cmov" }, - { AV_CPU_FLAG_AVX2, "avx2" }, - { AV_CPU_FLAG_BMI1, "bmi1" }, - { AV_CPU_FLAG_BMI2, "bmi2" }, -#endif - { 0 } -}; - -static void print_cpu_flags(int cpu_flags, const char *type) -{ - int i; - - fprintf(stderr, "cpu_flags(%s) = 0x%08X\n", type, cpu_flags); - fprintf(stderr, "cpu_flags_str(%s) =", type); - for (i = 0; cpu_flag_tab[i].flag; i++) - if (cpu_flags & cpu_flag_tab[i].flag) - fprintf(stderr, " %s", cpu_flag_tab[i].name); - fprintf(stderr, "\n"); -} - - -int main(int argc, char **argv) -{ - int cpu_flags_raw = av_get_cpu_flags(); - int cpu_flags_eff; - int cpu_count = av_cpu_count(); - char threads[5] = "auto"; - - if (cpu_flags_raw < 0) - return 1; - - for (;;) { - int c = getopt(argc, argv, "c:t:"); - if (c == -1) - break; - switch (c) { - case 'c': - { - int cpuflags = av_parse_cpu_flags(optarg); - if (cpuflags < 0) - return 2; - av_set_cpu_flags_mask(cpuflags); - break; - } - case 't': - { - int len = av_strlcpy(threads, optarg, sizeof(threads)); - if (len >= sizeof(threads)) { - fprintf(stderr, "Invalid thread count '%s'\n", optarg); - return 2; - } - } - } - } - - cpu_flags_eff = av_get_cpu_flags(); - - if (cpu_flags_eff < 0) - return 3; - - print_cpu_flags(cpu_flags_raw, "raw"); - print_cpu_flags(cpu_flags_eff, "effective"); - fprintf(stderr, "threads = %s (cpu_count = %d)\n", threads, cpu_count); - - return 0; -} diff --git a/libavutil/crc-test.c b/libavutil/crc-test.c deleted file mode 100644 index ef15fb5669..0000000000 --- a/libavutil/crc-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "crc.h" - -int main(void) -{ - uint8_t buf[1999]; - int i; - static const int p[5][3] = { - { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 }, - { AV_CRC_32_IEEE, 0x04C11DB7, 0xC0F5BAE0 }, - { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 }, - { AV_CRC_16_ANSI, 0x8005, 0x1FBB }, - { AV_CRC_8_ATM, 0x07, 0xE3 } - }; - const AVCRC *ctx; - - for (i = 0; i < sizeof(buf); i++) - buf[i] = i + i * i; - - for (i = 0; i < 5; i++) { - ctx = av_crc_get_table(p[i][0]); - printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf))); - } - return 0; -} diff --git a/libavutil/des-test.c b/libavutil/des-test.c deleted file mode 100644 index a372035a54..0000000000 --- a/libavutil/des-test.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "des.c" - -#include -#include -#include -#include - -#include "time.h" - -static uint64_t rand64(void) -{ - uint64_t r = rand(); - r = (r << 32) | rand(); - return r; -} - -static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; -static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; -static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 }; -static DECLARE_ALIGNED(8, uint8_t, tmp)[8]; -static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8]; -static const uint8_t cbc_key[] = { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, - 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23 -}; - -static int run_test(int cbc, int decrypt) -{ - AVDES d; - int delay = cbc && !decrypt ? 2 : 1; - uint64_t res; - AV_WB64(large_buffer[0], 0x4e6f772069732074ULL); - AV_WB64(large_buffer[1], 0x1234567890abcdefULL); - AV_WB64(tmp, 0x1234567890abcdefULL); - av_des_init(&d, cbc_key, 192, decrypt); - av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt); - res = AV_RB64(large_buffer[9999 + delay]); - if (cbc) { - if (decrypt) - return res == 0xc5cecf63ecec514cULL; - else - return res == 0xcb191f85d1ed8439ULL; - } else { - if (decrypt) - return res == 0x8325397644091a0aULL; - else - return res == 0xdd17e8b8b437d232ULL; - } -} - -int main(void) -{ - AVDES d; - int i; - uint64_t key[3]; - uint64_t data; - uint64_t ct; - uint64_t roundkeys[16]; - srand(av_gettime()); - key[0] = AV_RB64(test_key); - data = AV_RB64(plain); - gen_roundkeys(roundkeys, key[0]); - if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) { - printf("Test 1 failed\n"); - return 1; - } - av_des_init(&d, test_key, 64, 0); - av_des_crypt(&d, tmp, plain, 1, NULL, 0); - if (memcmp(tmp, crypt, sizeof(crypt))) { - printf("Public API decryption failed\n"); - return 1; - } - if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) { - printf("Partial Monte-Carlo test failed\n"); - return 1; - } - for (i = 0; i < 1000; i++) { - key[0] = rand64(); - key[1] = rand64(); - key[2] = rand64(); - data = rand64(); - av_des_init(&d, key, 192, 0); - av_des_crypt(&d, &ct, &data, 1, NULL, 0); - av_des_init(&d, key, 192, 1); - av_des_crypt(&d, &ct, &ct, 1, NULL, 1); - if (ct != data) { - printf("Test 2 failed\n"); - return 1; - } - } -#ifdef GENTABLES - printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n"); - for (i = 0; i < 8; i++) { - int j; - printf(" {"); - for (j = 0; j < 64; j++) { - uint32_t v = S_boxes[i][j >> 1]; - v = j & 1 ? v >> 4 : v & 0xf; - v <<= 28 - 4 * i; - v = shuffle(v, P_shuffle, sizeof(P_shuffle)); - printf((j & 7) == 0 ? "\n " : " "); - printf("0x%08X,", v); - } - printf("\n },\n"); - } - printf("};\n"); -#endif - return 0; -} diff --git a/libavutil/des.c b/libavutil/des.c index 1dbedd92cd..75a5d896fb 100644 --- a/libavutil/des.c +++ b/libavutil/des.c @@ -111,7 +111,7 @@ static const uint8_t S_boxes[8][32] = { #else /** * This table contains the results of applying both the S-box and P-shuffle. - * It can be regenerated by compiling des-test.c with "-DCONFIG_SMALL -DGENTABLES". + * It can be regenerated by compiling tests/des.c with "-DCONFIG_SMALL -DGENTABLES". */ static const uint32_t S_boxes_P_shuffle[8][64] = { { 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, diff --git a/libavutil/eval-test.c b/libavutil/eval-test.c deleted file mode 100644 index 3551f17b20..0000000000 --- a/libavutil/eval-test.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include - -#include "libm.h" -#include "timer.h" -#include "eval.h" - -static const double const_values[] = { - M_PI, - M_E, - 0 -}; - -static const char *const const_names[] = { - "PI", - "E", - 0 -}; - -int main(int argc, char **argv) -{ - int i; - double d; - const char *const *expr; - static const char *const exprs[] = { - "", - "1;2", - "-20", - "-PI", - "+PI", - "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", - "80G/80Gi", - "1k", - "1Gi", - "1gi", - "1GiFoo", - "1k+1k", - "1Gi*3foo", - "foo", - "foo(", - "foo()", - "foo)", - "sin", - "sin(", - "sin()", - "sin)", - "sin 10", - "sin(1,2,3)", - "sin(1 )", - "1", - "1foo", - "bar + PI + E + 100f*2 + foo", - "13k + 12f - foo(1, 2)", - "1gi", - "1Gi", - "st(0, 123)", - "st(1, 123); ld(1)", - "lte(0, 1)", - "lte(1, 1)", - "lte(1, 0)", - "lt(0, 1)", - "lt(1, 1)", - "gt(1, 0)", - "gt(2, 7)", - "gte(122, 122)", - /* compute 1+2+...+N */ - "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)", - /* compute Fib(N) */ - "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)", - "while(0, 10)", - "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", - "isnan(1)", - "isnan(NAN)", - "isnan(INF)", - "isinf(1)", - "isinf(NAN)", - "isinf(INF)", - "floor(NAN)", - "floor(123.123)", - "floor(-123.123)", - "trunc(123.123)", - "trunc(-123.123)", - "ceil(123.123)", - "ceil(-123.123)", - "sqrt(1764)", - "isnan(sqrt(-1))", - "not(1)", - "not(NAN)", - "not(0)", - "6.0206dB", - "-3.0103dB", - NULL - }; - - for (expr = exprs; *expr; expr++) { - printf("Evaluating '%s'\n", *expr); - av_expr_parse_and_eval(&d, *expr, - const_names, const_values, - NULL, NULL, NULL, NULL, NULL, 0, NULL); - if (isnan(d)) - printf("'%s' -> nan\n\n", *expr); - else - printf("'%s' -> %f\n\n", *expr, d); - } - - av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", - const_names, const_values, - NULL, NULL, NULL, NULL, NULL, 0, NULL); - printf("%f == 12.7\n", d); - av_expr_parse_and_eval(&d, "80G/80Gi", - const_names, const_values, - NULL, NULL, NULL, NULL, NULL, 0, NULL); - printf("%f == 0.931322575\n", d); - - if (argc > 1 && !strcmp(argv[1], "-t")) { - for (i = 0; i < 1050; i++) { - START_TIMER; - av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", - const_names, const_values, - NULL, NULL, NULL, NULL, NULL, 0, NULL); - STOP_TIMER("av_expr_parse_and_eval"); - } - } - - return 0; -} diff --git a/libavutil/fifo-test.c b/libavutil/fifo-test.c deleted file mode 100644 index f6615b1034..0000000000 --- a/libavutil/fifo-test.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "fifo.h" - -int main(void) -{ - /* create a FIFO buffer */ - AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int)); - int i, j, n; - - /* fill data */ - for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) - av_fifo_generic_write(fifo, &i, sizeof(int), NULL); - - /* peek at FIFO */ - n = av_fifo_size(fifo) / sizeof(int); - for (i = -n + 1; i < n; i++) { - int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int)); - printf("%d: %d\n", i, *v); - } - printf("\n"); - - /* read data */ - for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) { - av_fifo_generic_read(fifo, &j, sizeof(int), NULL); - printf("%d ", j); - } - printf("\n"); - - av_fifo_free(fifo); - - return 0; -} diff --git a/libavutil/float_dsp-test.c b/libavutil/float_dsp-test.c deleted file mode 100644 index e24018c07d..0000000000 --- a/libavutil/float_dsp-test.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "cpu.h" -#include "internal.h" -#include "lfg.h" -#include "log.h" -#include "random_seed.h" -#include "float_dsp.h" - -#define LEN 240 - -static void fill_float_array(AVLFG *lfg, float *a, int len) -{ - int i; - double bmg[2], stddev = 10.0, mean = 0.0; - - for (i = 0; i < len; i += 2) { - av_bmg_get(lfg, bmg); - a[i] = bmg[0] * stddev + mean; - a[i + 1] = bmg[1] * stddev + mean; - } -} -static int compare_floats(const float *a, const float *b, int len, - float max_diff) -{ - int i; - for (i = 0; i < len; i++) { - if (fabsf(a[i] - b[i]) > max_diff) { - av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n", - i, a[i], b[i], a[i] - b[i]); - return -1; - } - } - return 0; -} - -static void fill_double_array(AVLFG *lfg, double *a, int len) -{ - int i; - double bmg[2], stddev = 10.0, mean = 0.0; - - for (i = 0; i < len; i += 2) { - av_bmg_get(lfg, bmg); - a[i] = bmg[0] * stddev + mean; - a[i + 1] = bmg[1] * stddev + mean; - } -} - -static int compare_doubles(const double *a, const double *b, int len, - double max_diff) -{ - int i; - - for (i = 0; i < len; i++) { - if (fabs(a[i] - b[i]) > max_diff) { - av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n", - i, a[i], b[i], a[i] - b[i]); - return -1; - } - } - return 0; -} - -static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - cdsp->vector_fmul(cdst, v1, v2, LEN); - fdsp->vector_fmul(odst, v1, v2, LEN); - - if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) - av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n"); - - return ret; -} - -#define ARBITRARY_FMAC_SCALAR_CONST 0.005 -static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *src0, float scale) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - memcpy(cdst, v1, LEN * sizeof(*v1)); - memcpy(odst, v1, LEN * sizeof(*v1)); - - cdsp->vector_fmac_scalar(cdst, src0, scale, LEN); - fdsp->vector_fmac_scalar(odst, src0, scale, LEN); - - if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST)) - av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n"); - - return ret; -} - -static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, float scale) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - cdsp->vector_fmul_scalar(cdst, v1, scale, LEN); - fdsp->vector_fmul_scalar(odst, v1, scale, LEN); - - if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) - av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n"); - - return ret; -} - -static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const double *v1, double scale) -{ - LOCAL_ALIGNED(32, double, cdst, [LEN]); - LOCAL_ALIGNED(32, double, odst, [LEN]); - int ret; - - cdsp->vector_dmul_scalar(cdst, v1, scale, LEN); - fdsp->vector_dmul_scalar(odst, v1, scale, LEN); - - if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON)) - av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n"); - - return ret; -} - -#define ARBITRARY_FMUL_WINDOW_CONST 0.008 -static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2, const float *v3) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2); - fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2); - - if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST)) - av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n"); - - return ret; -} - -#define ARBITRARY_FMUL_ADD_CONST 0.005 -static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2, const float *v3) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN); - fdsp->vector_fmul_add(odst, v1, v2, v3, LEN); - - if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST)) - av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n"); - - return ret; -} - -static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2) -{ - LOCAL_ALIGNED(32, float, cdst, [LEN]); - LOCAL_ALIGNED(32, float, odst, [LEN]); - int ret; - - cdsp->vector_fmul_reverse(cdst, v1, v2, LEN); - fdsp->vector_fmul_reverse(odst, v1, v2, LEN); - - if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) - av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n"); - - return ret; -} - -static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2) -{ - LOCAL_ALIGNED(32, float, cv1, [LEN]); - LOCAL_ALIGNED(32, float, cv2, [LEN]); - LOCAL_ALIGNED(32, float, ov1, [LEN]); - LOCAL_ALIGNED(32, float, ov2, [LEN]); - int ret; - - memcpy(cv1, v1, LEN * sizeof(*v1)); - memcpy(cv2, v2, LEN * sizeof(*v2)); - memcpy(ov1, v1, LEN * sizeof(*v1)); - memcpy(ov2, v2, LEN * sizeof(*v2)); - - cdsp->butterflies_float(cv1, cv2, LEN); - fdsp->butterflies_float(ov1, ov2, LEN); - - if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) || - (ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON))) - av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n"); - - return ret; -} - -#define ARBITRARY_SCALARPRODUCT_CONST 0.2 -static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, - const float *v1, const float *v2) -{ - float cprod, oprod; - int ret; - - cprod = cdsp->scalarproduct_float(v1, v2, LEN); - oprod = fdsp->scalarproduct_float(v1, v2, LEN); - - if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST)) - av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n"); - - return ret; -} - -int main(int argc, char **argv) -{ - int ret = 0; - uint32_t seed; - AVFloatDSPContext fdsp, cdsp; - AVLFG lfg; - - LOCAL_ALIGNED(32, float, src0, [LEN]); - LOCAL_ALIGNED(32, float, src1, [LEN]); - LOCAL_ALIGNED(32, float, src2, [LEN]); - LOCAL_ALIGNED(32, double, dbl_src0, [LEN]); - LOCAL_ALIGNED(32, double, dbl_src1, [LEN]); - - if (argc > 2 && !strcmp(argv[1], "-s")) - seed = strtoul(argv[2], NULL, 10); - else - seed = av_get_random_seed(); - - av_log(NULL, AV_LOG_INFO, "float_dsp-test: random seed %u\n", seed); - - av_lfg_init(&lfg, seed); - - fill_float_array(&lfg, src0, LEN); - fill_float_array(&lfg, src1, LEN); - fill_float_array(&lfg, src2, LEN); - - fill_double_array(&lfg, dbl_src0, LEN); - fill_double_array(&lfg, dbl_src1, LEN); - - avpriv_float_dsp_init(&fdsp, 1); - av_set_cpu_flags_mask(0); - avpriv_float_dsp_init(&cdsp, 1); - - if (test_vector_fmul(&fdsp, &cdsp, src0, src1)) - ret -= 1 << 0; - if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0])) - ret -= 1 << 1; - if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0])) - ret -= 1 << 2; - if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2)) - ret -= 1 << 3; - if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2)) - ret -= 1 << 4; - if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1)) - ret -= 1 << 5; - if (test_butterflies_float(&fdsp, &cdsp, src0, src1)) - ret -= 1 << 6; - if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1)) - ret -= 1 << 7; - if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0])) - ret -= 1 << 8; - - return ret; -} diff --git a/libavutil/hmac-test.c b/libavutil/hmac-test.c deleted file mode 100644 index f97c8a6ab3..0000000000 --- a/libavutil/hmac-test.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hmac.c" - -#include -#include - -static void test(AVHMAC *hmac, const uint8_t *key, int keylen, - const uint8_t *data, int datalen) -{ - uint8_t buf[MAX_HASHLEN]; - int out, i; - // Some of the test vectors are strings, where sizeof() includes the - // trailing null byte - remove that. - if (!key[keylen - 1]) - keylen--; - if (!data[datalen - 1]) - datalen--; - out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf)); - for (i = 0; i < out; i++) - printf("%02x", buf[i]); - printf("\n"); -} - -int main(void) -{ - uint8_t key1[20], key3[131], data3[50]; - enum AVHMACType i = AV_HMAC_SHA224; - static const uint8_t key2[] = "Jefe"; - static const uint8_t data1[] = "Hi There"; - static const uint8_t data2[] = "what do ya want for nothing?"; - static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First"; - static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; - static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger " - "than block-size data. The key needs to be hashed before being used" - " by the HMAC algorithm."; - AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5); - if (!hmac) - return 1; - memset(key1, 0x0b, sizeof(key1)); - memset(key3, 0xaa, sizeof(key3)); - memset(data3, 0xdd, sizeof(data3)); - // RFC 2202 test vectors - test(hmac, key1, 16, data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 16, data3, sizeof(data3)); - test(hmac, key3, 80, data4, sizeof(data4)); - test(hmac, key3, 80, data5, sizeof(data5)); - av_hmac_free(hmac); - - /* SHA-1 */ - hmac = av_hmac_alloc(AV_HMAC_SHA1); - if (!hmac) - return 1; - // RFC 2202 test vectors - test(hmac, key1, sizeof(key1), data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 20, data3, sizeof(data3)); - test(hmac, key3, 80, data4, sizeof(data4)); - test(hmac, key3, 80, data5, sizeof(data5)); - av_hmac_free(hmac); - - /* SHA-2 */ - while (i <= AV_HMAC_SHA256) { - hmac = av_hmac_alloc(i); - // RFC 4231 test vectors - test(hmac, key1, sizeof(key1), data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 20, data3, sizeof(data3)); - test(hmac, key3, sizeof(key3), data4, sizeof(data4)); - test(hmac, key3, sizeof(key3), data6, sizeof(data6)); - av_hmac_free(hmac); - i++; - } - return 0; -} diff --git a/libavutil/lfg-test.c b/libavutil/lfg-test.c deleted file mode 100644 index 92b4259a3c..0000000000 --- a/libavutil/lfg-test.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "log.h" -#include "timer.h" -#include "lfg.h" - -int main(void) -{ - int x = 0; - int i, j; - AVLFG state; - - av_lfg_init(&state, 0xdeadbeef); - for (j = 0; j < 10000; j++) { - START_TIMER - for (i = 0; i < 624; i++) - x += av_lfg_get(&state); - STOP_TIMER("624 calls of av_lfg_get"); - } - av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x); - - /* BMG usage example */ - { - double mean = 1000; - double stddev = 53; - - av_lfg_init(&state, 42); - - for (i = 0; i < 1000; i += 2) { - double bmg_out[2]; - av_bmg_get(&state, bmg_out); - av_log(NULL, AV_LOG_INFO, - "%f\n%f\n", - bmg_out[0] * stddev + mean, - bmg_out[1] * stddev + mean); - } - } - - return 0; -} diff --git a/libavutil/lls-test.c b/libavutil/lls-test.c deleted file mode 100644 index f9814b3863..0000000000 --- a/libavutil/lls-test.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "internal.h" -#include "lfg.h" -#include "lls.h" - -int main(void) -{ - LLSModel m; - int i, order; - AVLFG lfg; - - av_lfg_init(&lfg, 1); - avpriv_init_lls(&m, 3); - - for (i = 0; i < 100; i++) { - LOCAL_ALIGNED(32, double, var, [4]); - double eval; - - var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2; - var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; - var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; - var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; - m.update_lls(&m, var); - avpriv_solve_lls(&m, 0.001, 0); - for (order = 0; order < 3; order++) { - eval = m.evaluate_lls(&m, var + 1, order); - printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n", - var[0], order, eval, sqrt(m.variance[order] / (i + 1)), - m.coeff[order][0], m.coeff[order][1], - m.coeff[order][2]); - } - } - return 0; -} diff --git a/libavutil/md5-test.c b/libavutil/md5-test.c deleted file mode 100644 index 8d5dd1e104..0000000000 --- a/libavutil/md5-test.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "md5.h" - -static void print_md5(uint8_t *md5) -{ - int i; - for (i = 0; i < 16; i++) - printf("%02x", md5[i]); - printf("\n"); -} - -int main(void) -{ - uint8_t md5val[16]; - int i; - uint8_t in[1000]; - - for (i = 0; i < 1000; i++) - in[i] = i * i; - av_md5_sum(md5val, in, 1000); - print_md5(md5val); - av_md5_sum(md5val, in, 63); - print_md5(md5val); - av_md5_sum(md5val, in, 64); - print_md5(md5val); - av_md5_sum(md5val, in, 65); - print_md5(md5val); - for (i = 0; i < 1000; i++) - in[i] = i % 127; - av_md5_sum(md5val, in, 999); - print_md5(md5val); - - return 0; -} diff --git a/libavutil/opt-test.c b/libavutil/opt-test.c deleted file mode 100644 index 6262b77e5b..0000000000 --- a/libavutil/opt-test.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "common.h" -#include "error.h" -#include "log.h" -#include "mem.h" -#include "rational.h" -#include "opt.h" - -typedef struct TestContext { - const AVClass *class; - int num; - int toggle; - char *string; - int flags; - AVRational rational; -} TestContext; - -#define OFFSET(x) offsetof(TestContext, x) - -#define TEST_FLAG_COOL 01 -#define TEST_FLAG_LAME 02 -#define TEST_FLAG_MU 04 - -static const AVOption test_options[] = { - { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 }, - { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 }, - { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 }, - { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX }, - { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"}, - { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"}, - { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"}, - { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"}, - { NULL }, -}; - -static const char *test_get_name(void *ctx) -{ - return "test"; -} - -static const AVClass test_class = { - "TestContext", - test_get_name, - test_options -}; - -int main(void) -{ - int i; - TestContext test_ctx = { .class = &test_class }; - static const char *options[] = { - "", - ":", - "=", - "foo=:", - ":=foo", - "=foo", - "foo=", - "foo", - "foo=val", - "foo==val", - "toggle=:", - "string=:", - "toggle=1 : foo", - "toggle=100", - "toggle==1", - "flags=+mu-lame : num=42: toggle=0", - "num=42 : string=blahblah", - "rational=0 : rational=1/2 : rational=1/-1", - "rational=-1/0", - }; - - printf("\nTesting av_set_options_string()\n"); - - av_opt_set_defaults(&test_ctx); - test_ctx.string = av_strdup("default"); - if (!test_ctx.string) - return AVERROR(ENOMEM); - - av_log_set_level(AV_LOG_DEBUG); - - for (i = 0; i < FF_ARRAY_ELEMS(options); i++) { - av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]); - if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0) - av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]); - printf("\n"); - } - - return 0; -} diff --git a/libavutil/parseutils-test.c b/libavutil/parseutils-test.c deleted file mode 100644 index 149861f1d5..0000000000 --- a/libavutil/parseutils-test.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "common.h" -#include "log.h" -#include "rational.h" -#include "parseutils.h" - -int main(void) -{ - int i; - uint8_t rgba[4]; - static const char *const rates[] = { - "-inf", - "inf", - "nan", - "123/0", - "-123 / 0", - "", - "/", - " 123 / 321", - "foo/foo", - "foo/1", - "1/foo", - "0/0", - "/0", - "1/", - "1", - "0", - "-123/123", - "-foo", - "123.23", - ".23", - "-.23", - "-0.234", - "-0.0000001", - " 21332.2324 ", - " -21332.2324 ", - }; - static const char *const color_names[] = { - "foo", - "red", - "Red ", - "RED", - "Violet", - "Yellow", - "Red", - "0x000000", - "0x0000000", - "0xff000000", - "0x3e34ff", - "0x3e34ffaa", - "0xffXXee", - "0xfoobar", - "0xffffeeeeeeee", - "#ff0000", - "#ffXX00", - "ff0000", - "ffXX00", - "red@foo", - "random@10", - "0xff0000@1.0", - "red@", - "red@0xfff", - "red@0xf", - "red@2", - "red@0.1", - "red@-1", - "red@0.5", - "red@1.0", - "red@256", - "red@10foo", - "red@-1.0", - "red@-0.0", - }; - - printf("Testing av_parse_video_rate()\n"); - - for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { - int ret; - AVRational q = { 0, 0 }; - ret = av_parse_video_rate(&q, rates[i]); - printf("'%s' -> %d/%d %s\n", - rates[i], q.num, q.den, ret ? "ERROR" : "OK"); - } - - printf("\nTesting av_parse_color()\n"); - - av_log_set_level(AV_LOG_DEBUG); - - for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { - if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) - printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", - color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); - } - - return 0; -} diff --git a/libavutil/sha-test.c b/libavutil/sha-test.c deleted file mode 100644 index 5f62a98ea3..0000000000 --- a/libavutil/sha-test.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "sha.c" - -#include - -int main(void) -{ - int i, j, k; - AVSHA ctx; - unsigned char digest[32]; - static const int lengths[3] = { 160, 224, 256 }; - - for (j = 0; j < 3; j++) { - printf("Testing SHA-%d\n", lengths[j]); - for (k = 0; k < 3; k++) { - av_sha_init(&ctx, lengths[j]); - if (k == 0) - av_sha_update(&ctx, "abc", 3); - else if (k == 1) - av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56); - else - for (i = 0; i < 1000*1000; i++) - av_sha_update(&ctx, "a", 1); - av_sha_final(&ctx, digest); - for (i = 0; i < lengths[j] >> 3; i++) - printf("%02X", digest[i]); - putchar('\n'); - } - switch (j) { - case 0: - //test vectors (from FIPS PUB 180-1) - printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n" - "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n" - "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n"); - break; - case 1: - //test vectors (from FIPS PUB 180-2 Appendix A) - printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n" - "75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n" - "20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n"); - break; - case 2: - //test vectors (from FIPS PUB 180-2) - printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n" - "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n" - "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n"); - break; - } - } - - return 0; -} diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore new file mode 100644 index 0000000000..c4d1d065fb --- /dev/null +++ b/libavutil/tests/.gitignore @@ -0,0 +1,21 @@ +/adler32 +/aes +/atomic +/avstring +/base64 +/blowfish +/cpu +/crc +/des +/eval +/fifo +/float_dsp +/hmac +/lfg +/lls +/md5 +/opt +/parseutils +/sha +/tree +/xtea diff --git a/libavutil/tests/adler32.c b/libavutil/tests/adler32.c new file mode 100644 index 0000000000..323690056c --- /dev/null +++ b/libavutil/tests/adler32.c @@ -0,0 +1,51 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/log.h" +#include "libavutil/timer.h" +#include "libavutil/adler32.h" + +#define LEN 7001 + +static volatile int checksum; + +int main(int argc, char **argv) +{ + int i; + char data[LEN]; + + av_log_set_level(AV_LOG_DEBUG); + + for (i = 0; i < LEN; i++) + data[i] = ((i * i) >> 3) + 123 * i; + + if (argc > 1 && !strcmp(argv[1], "-t")) { + for (i = 0; i < 1000; i++) { + START_TIMER; + checksum = av_adler32_update(1, data, LEN); + STOP_TIMER("adler"); + } + } else { + checksum = av_adler32_update(1, data, LEN); + } + + av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum); + return checksum == 0x50e6e508 ? 0 : 1; +} diff --git a/libavutil/tests/aes.c b/libavutil/tests/aes.c new file mode 100644 index 0000000000..49ca553e0a --- /dev/null +++ b/libavutil/tests/aes.c @@ -0,0 +1,92 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/aes.c" + +#include + +#include "libavutil/lfg.h" +#include "libavutil/log.h" + +int main(int argc, char **argv) +{ + int i, j; + AVAES b; + static const uint8_t rkey[2][16] = { + { 0 }, + { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, + 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 } + }; + static const uint8_t rpt[2][16] = { + { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, + 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 }, + { 0 } + }; + static const uint8_t rct[2][16] = { + { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, + 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf }, + { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, + 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 } + }; + uint8_t pt[16], temp[16]; + int err = 0; + + av_log_set_level(AV_LOG_DEBUG); + + for (i = 0; i < 2; i++) { + av_aes_init(&b, rkey[i], 128, 1); + av_aes_crypt(&b, temp, rct[i], 1, NULL, 1); + for (j = 0; j < 16; j++) { + if (rpt[i][j] != temp[j]) { + av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", + j, rpt[i][j], temp[j]); + err = 1; + } + } + } + + if (argc > 1 && !strcmp(argv[1], "-t")) { + AVAES ae, ad; + AVLFG prng; + + av_aes_init(&ae, "PI=3.141592654..", 128, 0); + av_aes_init(&ad, "PI=3.141592654..", 128, 1); + av_lfg_init(&prng, 1); + + for (i = 0; i < 10000; i++) { + for (j = 0; j < 16; j++) + pt[j] = av_lfg_get(&prng); + { + START_TIMER; + av_aes_crypt(&ae, temp, pt, 1, NULL, 0); + if (!(i & (i - 1))) + av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", + temp[0], temp[5], temp[10], temp[15]); + av_aes_crypt(&ad, temp, temp, 1, NULL, 1); + STOP_TIMER("aes"); + } + for (j = 0; j < 16; j++) { + if (pt[j] != temp[j]) { + av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", + i, j, pt[j], temp[j]); + } + } + } + } + return err; +} diff --git a/libavutil/tests/atomic.c b/libavutil/tests/atomic.c new file mode 100644 index 0000000000..70636f42fb --- /dev/null +++ b/libavutil/tests/atomic.c @@ -0,0 +1,35 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/atomic.h" + +int main(void) +{ + volatile int val = 1; + int res; + + res = avpriv_atomic_int_add_and_fetch(&val, 1); + assert(res == 2); + avpriv_atomic_int_set(&val, 3); + res = avpriv_atomic_int_get(&val); + assert(res == 3); + + return 0; +} diff --git a/libavutil/tests/avstring.c b/libavutil/tests/avstring.c new file mode 100644 index 0000000000..2e5ee2d44a --- /dev/null +++ b/libavutil/tests/avstring.c @@ -0,0 +1,69 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/common.h" +#include "libavutil/mem.h" +#include "libavutil/avstring.h" + +int main(void) +{ + int i; + static const char *strings[] = { + "''", + "", + ":", + "\\", + "'", + " '' :", + " '' '' :", + "foo '' :", + "'foo'", + "foo ", + " ' foo ' ", + "foo\\", + "foo': blah:blah", + "foo\\: blah:blah", + "foo\'", + "'foo : ' :blahblah", + "\\ :blah", + " foo", + " foo ", + " foo \\ ", + "foo ':blah", + " foo bar : blahblah", + "\\f\\o\\o", + "'foo : \\ \\ ' : blahblah", + "'\\fo\\o:': blahblah", + "\\'fo\\o\\:': foo ' :blahblah" + }; + + printf("Testing av_get_token()\n"); + for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) { + const char *p = strings[i]; + char *q; + printf("|%s|", p); + q = av_get_token(&p, ":"); + printf(" -> |%s|", q); + printf(" + |%s|\n", p); + av_free(q); + } + + return 0; +} diff --git a/libavutil/tests/base64.c b/libavutil/tests/base64.c new file mode 100644 index 0000000000..16ea399788 --- /dev/null +++ b/libavutil/tests/base64.c @@ -0,0 +1,84 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/common.h" +#include "libavutil/base64.h" + +#define MAX_DATA_SIZE 1024 +#define MAX_ENCODED_SIZE 2048 + +static int test_encode_decode(const uint8_t *data, unsigned int data_size, + const char *encoded_ref) +{ + char encoded[MAX_ENCODED_SIZE]; + uint8_t data2[MAX_DATA_SIZE]; + int data2_size, max_data2_size = MAX_DATA_SIZE; + + if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) { + printf("Failed: cannot encode the input data\n"); + return 1; + } + if (encoded_ref && strcmp(encoded, encoded_ref)) { + printf("Failed: encoded string differs from reference\n" + "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref); + return 1; + } + + if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) { + printf("Failed: cannot decode the encoded string\n" + "Encoded:\n%s\n", encoded); + return 1; + } + if (memcmp(data2, data, data_size)) { + printf("Failed: encoded/decoded data differs from original data\n"); + return 1; + } + + printf("Passed!\n"); + return 0; +} + +int main(void) +{ + int i, error_count = 0; + struct test { + const uint8_t *data; + const char *encoded_ref; + } tests[] = { + { "", ""}, + { "1", "MQ=="}, + { "22", "MjI="}, + { "333", "MzMz"}, + { "4444", "NDQ0NA=="}, + { "55555", "NTU1NTU="}, + { "666666", "NjY2NjY2"}, + { "abc:def", "YWJjOmRlZg=="}, + }; + + printf("Encoding/decoding tests\n"); + for (i = 0; i < FF_ARRAY_ELEMS(tests); i++) + error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref); + + if (error_count) + printf("Error Count: %d.\n", error_count); + + return !!error_count; +} diff --git a/libavutil/tests/blowfish.c b/libavutil/tests/blowfish.c new file mode 100644 index 0000000000..acaab70aeb --- /dev/null +++ b/libavutil/tests/blowfish.c @@ -0,0 +1,190 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/blowfish.h" + +#define NUM_VARIABLE_KEY_TESTS 34 + +/* plaintext bytes -- left halves */ +static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = { + 0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111, + 0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8, + 0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0, + 0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18, + 0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577, + 0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567, + 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF +}; + +/* plaintext bytes -- right halves */ +static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = { + 0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111, + 0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA, + 0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2, + 0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA, + 0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A, + 0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF, + 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF +}; + +/* key bytes for variable key tests */ +static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, + { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }, + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, + { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }, + { 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 }, + { 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E }, + { 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 }, + { 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E }, + { 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 }, + { 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE }, + { 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 }, + { 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE }, + { 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 }, + { 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F }, + { 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 }, + { 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E }, + { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 }, + { 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 }, + { 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F }, + { 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 }, + { 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF }, + { 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 }, + { 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, + { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }, + { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, + { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 } +}; + +/* ciphertext bytes -- left halves */ +static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = { + 0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380, + 0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B, + 0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7, + 0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B, + 0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A, + 0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D, + 0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C +}; + +/* ciphertext bytes -- right halves */ +static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = { + 0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096, + 0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0, + 0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98, + 0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B, + 0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5, + 0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D, + 0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A +}; + +/* plaintext bytes */ +static const uint8_t plaintext[8] = "BLOWFISH"; + +static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH"; + +/* ciphertext bytes */ +static const uint8_t ciphertext[8] = { + 0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03 +}; + +static const uint8_t ciphertext2[16] = { + 0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99, + 0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1, +}; + +#define IV "blowfish" + +static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src, + const uint8_t *ref, int len, uint8_t *iv, int dir, + const char *test) +{ + av_blowfish_crypt(ctx, dst, src, len, iv, dir); + if (memcmp(dst, ref, 8*len)) { + int i; + printf("%s failed\ngot ", test); + for (i = 0; i < 8*len; i++) + printf("%02x ", dst[i]); + printf("\nexpected "); + for (i = 0; i < 8*len; i++) + printf("%02x ", ref[i]); + printf("\n"); + exit(1); + } +} + +int main(void) +{ + AVBlowfish ctx; + uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS]; + uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS]; + uint8_t tmp[16], iv[8]; + int i; + + av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26); + + test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption"); + test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption"); + test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption"); + test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption"); + memcpy(iv, IV, 8); + test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption"); + memcpy(iv, IV, 8); + test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption"); + memcpy(iv, IV, 8); + test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption"); + memcpy(iv, IV, 8); + test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption"); + + memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS); + memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS); + + for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) { + av_blowfish_init(&ctx, variable_key[i], 8); + + av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0); + if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) { + printf("Test encryption failed.\n"); + return 1; + } + + av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1); + if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) { + printf("Test decryption failed.\n"); + return 1; + } + } + printf("Test encryption/decryption success.\n"); + + return 0; +} + diff --git a/libavutil/tests/cpu.c b/libavutil/tests/cpu.c new file mode 100644 index 0000000000..176b7eb030 --- /dev/null +++ b/libavutil/tests/cpu.c @@ -0,0 +1,136 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#if HAVE_UNISTD_H +#include +#elif !HAVE_GETOPT +#include "compat/getopt.c" +#endif + +#include +#include + +#include "libavutil/avstring.h" +#include "libavutil/common.h" +#include "libavutil/cpu.h" + +static const struct { + int flag; + const char *name; +} cpu_flag_tab[] = { +#if ARCH_AARCH64 + { AV_CPU_FLAG_ARMV8, "armv8" }, + { AV_CPU_FLAG_NEON, "neon" }, + { AV_CPU_FLAG_VFP, "vfp" }, +#elif ARCH_ARM + { AV_CPU_FLAG_ARMV5TE, "armv5te" }, + { AV_CPU_FLAG_ARMV6, "armv6" }, + { AV_CPU_FLAG_ARMV6T2, "armv6t2" }, + { AV_CPU_FLAG_VFP, "vfp" }, + { AV_CPU_FLAG_VFP_VM, "vfp_vm" }, + { AV_CPU_FLAG_VFPV3, "vfpv3" }, + { AV_CPU_FLAG_NEON, "neon" }, +#elif ARCH_PPC + { AV_CPU_FLAG_ALTIVEC, "altivec" }, +#elif ARCH_X86 + { AV_CPU_FLAG_MMX, "mmx" }, + { AV_CPU_FLAG_MMXEXT, "mmxext" }, + { AV_CPU_FLAG_SSE, "sse" }, + { AV_CPU_FLAG_SSE2, "sse2" }, + { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" }, + { AV_CPU_FLAG_SSE3, "sse3" }, + { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" }, + { AV_CPU_FLAG_SSSE3, "ssse3" }, + { AV_CPU_FLAG_ATOM, "atom" }, + { AV_CPU_FLAG_SSE4, "sse4.1" }, + { AV_CPU_FLAG_SSE42, "sse4.2" }, + { AV_CPU_FLAG_AVX, "avx" }, + { AV_CPU_FLAG_AVXSLOW, "avxslow" }, + { AV_CPU_FLAG_XOP, "xop" }, + { AV_CPU_FLAG_FMA3, "fma3" }, + { AV_CPU_FLAG_FMA4, "fma4" }, + { AV_CPU_FLAG_3DNOW, "3dnow" }, + { AV_CPU_FLAG_3DNOWEXT, "3dnowext" }, + { AV_CPU_FLAG_CMOV, "cmov" }, + { AV_CPU_FLAG_AVX2, "avx2" }, + { AV_CPU_FLAG_BMI1, "bmi1" }, + { AV_CPU_FLAG_BMI2, "bmi2" }, +#endif + { 0 } +}; + +static void print_cpu_flags(int cpu_flags, const char *type) +{ + int i; + + fprintf(stderr, "cpu_flags(%s) = 0x%08X\n", type, cpu_flags); + fprintf(stderr, "cpu_flags_str(%s) =", type); + for (i = 0; cpu_flag_tab[i].flag; i++) + if (cpu_flags & cpu_flag_tab[i].flag) + fprintf(stderr, " %s", cpu_flag_tab[i].name); + fprintf(stderr, "\n"); +} + + +int main(int argc, char **argv) +{ + int cpu_flags_raw = av_get_cpu_flags(); + int cpu_flags_eff; + int cpu_count = av_cpu_count(); + char threads[5] = "auto"; + + if (cpu_flags_raw < 0) + return 1; + + for (;;) { + int c = getopt(argc, argv, "c:t:"); + if (c == -1) + break; + switch (c) { + case 'c': + { + int cpuflags = av_parse_cpu_flags(optarg); + if (cpuflags < 0) + return 2; + av_set_cpu_flags_mask(cpuflags); + break; + } + case 't': + { + int len = av_strlcpy(threads, optarg, sizeof(threads)); + if (len >= sizeof(threads)) { + fprintf(stderr, "Invalid thread count '%s'\n", optarg); + return 2; + } + } + } + } + + cpu_flags_eff = av_get_cpu_flags(); + + if (cpu_flags_eff < 0) + return 3; + + print_cpu_flags(cpu_flags_raw, "raw"); + print_cpu_flags(cpu_flags_eff, "effective"); + fprintf(stderr, "threads = %s (cpu_count = %d)\n", threads, cpu_count); + + return 0; +} diff --git a/libavutil/tests/crc.c b/libavutil/tests/crc.c new file mode 100644 index 0000000000..c2c609fba8 --- /dev/null +++ b/libavutil/tests/crc.c @@ -0,0 +1,45 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/crc.h" + +int main(void) +{ + uint8_t buf[1999]; + int i; + static const int p[5][3] = { + { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 }, + { AV_CRC_32_IEEE, 0x04C11DB7, 0xC0F5BAE0 }, + { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 }, + { AV_CRC_16_ANSI, 0x8005, 0x1FBB }, + { AV_CRC_8_ATM, 0x07, 0xE3 } + }; + const AVCRC *ctx; + + for (i = 0; i < sizeof(buf); i++) + buf[i] = i + i * i; + + for (i = 0; i < 5; i++) { + ctx = av_crc_get_table(p[i][0]); + printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf))); + } + return 0; +} diff --git a/libavutil/tests/des.c b/libavutil/tests/des.c new file mode 100644 index 0000000000..1e7a2fa50a --- /dev/null +++ b/libavutil/tests/des.c @@ -0,0 +1,128 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/des.c" + +#include +#include +#include +#include + +#include "libavutil/time.h" + +static uint64_t rand64(void) +{ + uint64_t r = rand(); + r = (r << 32) | rand(); + return r; +} + +static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; +static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; +static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 }; +static DECLARE_ALIGNED(8, uint8_t, tmp)[8]; +static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8]; +static const uint8_t cbc_key[] = { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, + 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23 +}; + +static int run_test(int cbc, int decrypt) +{ + AVDES d; + int delay = cbc && !decrypt ? 2 : 1; + uint64_t res; + AV_WB64(large_buffer[0], 0x4e6f772069732074ULL); + AV_WB64(large_buffer[1], 0x1234567890abcdefULL); + AV_WB64(tmp, 0x1234567890abcdefULL); + av_des_init(&d, cbc_key, 192, decrypt); + av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt); + res = AV_RB64(large_buffer[9999 + delay]); + if (cbc) { + if (decrypt) + return res == 0xc5cecf63ecec514cULL; + else + return res == 0xcb191f85d1ed8439ULL; + } else { + if (decrypt) + return res == 0x8325397644091a0aULL; + else + return res == 0xdd17e8b8b437d232ULL; + } +} + +int main(void) +{ + AVDES d; + int i; + uint64_t key[3]; + uint64_t data; + uint64_t ct; + uint64_t roundkeys[16]; + srand(av_gettime()); + key[0] = AV_RB64(test_key); + data = AV_RB64(plain); + gen_roundkeys(roundkeys, key[0]); + if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) { + printf("Test 1 failed\n"); + return 1; + } + av_des_init(&d, test_key, 64, 0); + av_des_crypt(&d, tmp, plain, 1, NULL, 0); + if (memcmp(tmp, crypt, sizeof(crypt))) { + printf("Public API decryption failed\n"); + return 1; + } + if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) { + printf("Partial Monte-Carlo test failed\n"); + return 1; + } + for (i = 0; i < 1000; i++) { + key[0] = rand64(); + key[1] = rand64(); + key[2] = rand64(); + data = rand64(); + av_des_init(&d, key, 192, 0); + av_des_crypt(&d, &ct, &data, 1, NULL, 0); + av_des_init(&d, key, 192, 1); + av_des_crypt(&d, &ct, &ct, 1, NULL, 1); + if (ct != data) { + printf("Test 2 failed\n"); + return 1; + } + } +#ifdef GENTABLES + printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n"); + for (i = 0; i < 8; i++) { + int j; + printf(" {"); + for (j = 0; j < 64; j++) { + uint32_t v = S_boxes[i][j >> 1]; + v = j & 1 ? v >> 4 : v & 0xf; + v <<= 28 - 4 * i; + v = shuffle(v, P_shuffle, sizeof(P_shuffle)); + printf((j & 7) == 0 ? "\n " : " "); + printf("0x%08X,", v); + } + printf("\n },\n"); + } + printf("};\n"); +#endif + return 0; +} diff --git a/libavutil/tests/eval.c b/libavutil/tests/eval.c new file mode 100644 index 0000000000..818c59ccdb --- /dev/null +++ b/libavutil/tests/eval.c @@ -0,0 +1,145 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "libavutil/libm.h" +#include "libavutil/timer.h" +#include "libavutil/eval.h" + +static const double const_values[] = { + M_PI, + M_E, + 0 +}; + +static const char *const const_names[] = { + "PI", + "E", + 0 +}; + +int main(int argc, char **argv) +{ + int i; + double d; + const char *const *expr; + static const char *const exprs[] = { + "", + "1;2", + "-20", + "-PI", + "+PI", + "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", + "80G/80Gi", + "1k", + "1Gi", + "1gi", + "1GiFoo", + "1k+1k", + "1Gi*3foo", + "foo", + "foo(", + "foo()", + "foo)", + "sin", + "sin(", + "sin()", + "sin)", + "sin 10", + "sin(1,2,3)", + "sin(1 )", + "1", + "1foo", + "bar + PI + E + 100f*2 + foo", + "13k + 12f - foo(1, 2)", + "1gi", + "1Gi", + "st(0, 123)", + "st(1, 123); ld(1)", + "lte(0, 1)", + "lte(1, 1)", + "lte(1, 0)", + "lt(0, 1)", + "lt(1, 1)", + "gt(1, 0)", + "gt(2, 7)", + "gte(122, 122)", + /* compute 1+2+...+N */ + "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)", + /* compute Fib(N) */ + "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)", + "while(0, 10)", + "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", + "isnan(1)", + "isnan(NAN)", + "isnan(INF)", + "isinf(1)", + "isinf(NAN)", + "isinf(INF)", + "floor(NAN)", + "floor(123.123)", + "floor(-123.123)", + "trunc(123.123)", + "trunc(-123.123)", + "ceil(123.123)", + "ceil(-123.123)", + "sqrt(1764)", + "isnan(sqrt(-1))", + "not(1)", + "not(NAN)", + "not(0)", + "6.0206dB", + "-3.0103dB", + NULL + }; + + for (expr = exprs; *expr; expr++) { + printf("Evaluating '%s'\n", *expr); + av_expr_parse_and_eval(&d, *expr, + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); + if (isnan(d)) + printf("'%s' -> nan\n\n", *expr); + else + printf("'%s' -> %f\n\n", *expr, d); + } + + av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); + printf("%f == 12.7\n", d); + av_expr_parse_and_eval(&d, "80G/80Gi", + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); + printf("%f == 0.931322575\n", d); + + if (argc > 1 && !strcmp(argv[1], "-t")) { + for (i = 0; i < 1050; i++) { + START_TIMER; + av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); + STOP_TIMER("av_expr_parse_and_eval"); + } + } + + return 0; +} diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c new file mode 100644 index 0000000000..4c4b37a501 --- /dev/null +++ b/libavutil/tests/fifo.c @@ -0,0 +1,51 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/fifo.h" + +int main(void) +{ + /* create a FIFO buffer */ + AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int)); + int i, j, n; + + /* fill data */ + for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) + av_fifo_generic_write(fifo, &i, sizeof(int), NULL); + + /* peek at FIFO */ + n = av_fifo_size(fifo) / sizeof(int); + for (i = -n + 1; i < n; i++) { + int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int)); + printf("%d: %d\n", i, *v); + } + printf("\n"); + + /* read data */ + for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) { + av_fifo_generic_read(fifo, &j, sizeof(int), NULL); + printf("%d ", j); + } + printf("\n"); + + av_fifo_free(fifo); + + return 0; +} diff --git a/libavutil/tests/float_dsp.c b/libavutil/tests/float_dsp.c new file mode 100644 index 0000000000..ab6bf6a569 --- /dev/null +++ b/libavutil/tests/float_dsp.c @@ -0,0 +1,296 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/cpu.h" +#include "libavutil/internal.h" +#include "libavutil/lfg.h" +#include "libavutil/log.h" +#include "libavutil/random_seed.h" +#include "libavutil/float_dsp.h" + +#define LEN 240 + +static void fill_float_array(AVLFG *lfg, float *a, int len) +{ + int i; + double bmg[2], stddev = 10.0, mean = 0.0; + + for (i = 0; i < len; i += 2) { + av_bmg_get(lfg, bmg); + a[i] = bmg[0] * stddev + mean; + a[i + 1] = bmg[1] * stddev + mean; + } +} +static int compare_floats(const float *a, const float *b, int len, + float max_diff) +{ + int i; + for (i = 0; i < len; i++) { + if (fabsf(a[i] - b[i]) > max_diff) { + av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n", + i, a[i], b[i], a[i] - b[i]); + return -1; + } + } + return 0; +} + +static void fill_double_array(AVLFG *lfg, double *a, int len) +{ + int i; + double bmg[2], stddev = 10.0, mean = 0.0; + + for (i = 0; i < len; i += 2) { + av_bmg_get(lfg, bmg); + a[i] = bmg[0] * stddev + mean; + a[i + 1] = bmg[1] * stddev + mean; + } +} + +static int compare_doubles(const double *a, const double *b, int len, + double max_diff) +{ + int i; + + for (i = 0; i < len; i++) { + if (fabs(a[i] - b[i]) > max_diff) { + av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n", + i, a[i], b[i], a[i] - b[i]); + return -1; + } + } + return 0; +} + +static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + cdsp->vector_fmul(cdst, v1, v2, LEN); + fdsp->vector_fmul(odst, v1, v2, LEN); + + if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) + av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n"); + + return ret; +} + +#define ARBITRARY_FMAC_SCALAR_CONST 0.005 +static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *src0, float scale) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + memcpy(cdst, v1, LEN * sizeof(*v1)); + memcpy(odst, v1, LEN * sizeof(*v1)); + + cdsp->vector_fmac_scalar(cdst, src0, scale, LEN); + fdsp->vector_fmac_scalar(odst, src0, scale, LEN); + + if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST)) + av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n"); + + return ret; +} + +static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, float scale) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + cdsp->vector_fmul_scalar(cdst, v1, scale, LEN); + fdsp->vector_fmul_scalar(odst, v1, scale, LEN); + + if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) + av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n"); + + return ret; +} + +static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const double *v1, double scale) +{ + LOCAL_ALIGNED(32, double, cdst, [LEN]); + LOCAL_ALIGNED(32, double, odst, [LEN]); + int ret; + + cdsp->vector_dmul_scalar(cdst, v1, scale, LEN); + fdsp->vector_dmul_scalar(odst, v1, scale, LEN); + + if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON)) + av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n"); + + return ret; +} + +#define ARBITRARY_FMUL_WINDOW_CONST 0.008 +static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2, const float *v3) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2); + fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2); + + if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST)) + av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n"); + + return ret; +} + +#define ARBITRARY_FMUL_ADD_CONST 0.005 +static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2, const float *v3) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN); + fdsp->vector_fmul_add(odst, v1, v2, v3, LEN); + + if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST)) + av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n"); + + return ret; +} + +static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2) +{ + LOCAL_ALIGNED(32, float, cdst, [LEN]); + LOCAL_ALIGNED(32, float, odst, [LEN]); + int ret; + + cdsp->vector_fmul_reverse(cdst, v1, v2, LEN); + fdsp->vector_fmul_reverse(odst, v1, v2, LEN); + + if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) + av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n"); + + return ret; +} + +static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2) +{ + LOCAL_ALIGNED(32, float, cv1, [LEN]); + LOCAL_ALIGNED(32, float, cv2, [LEN]); + LOCAL_ALIGNED(32, float, ov1, [LEN]); + LOCAL_ALIGNED(32, float, ov2, [LEN]); + int ret; + + memcpy(cv1, v1, LEN * sizeof(*v1)); + memcpy(cv2, v2, LEN * sizeof(*v2)); + memcpy(ov1, v1, LEN * sizeof(*v1)); + memcpy(ov2, v2, LEN * sizeof(*v2)); + + cdsp->butterflies_float(cv1, cv2, LEN); + fdsp->butterflies_float(ov1, ov2, LEN); + + if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) || + (ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON))) + av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n"); + + return ret; +} + +#define ARBITRARY_SCALARPRODUCT_CONST 0.2 +static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, + const float *v1, const float *v2) +{ + float cprod, oprod; + int ret; + + cprod = cdsp->scalarproduct_float(v1, v2, LEN); + oprod = fdsp->scalarproduct_float(v1, v2, LEN); + + if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST)) + av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n"); + + return ret; +} + +int main(int argc, char **argv) +{ + int ret = 0; + uint32_t seed; + AVFloatDSPContext fdsp, cdsp; + AVLFG lfg; + + LOCAL_ALIGNED(32, float, src0, [LEN]); + LOCAL_ALIGNED(32, float, src1, [LEN]); + LOCAL_ALIGNED(32, float, src2, [LEN]); + LOCAL_ALIGNED(32, double, dbl_src0, [LEN]); + LOCAL_ALIGNED(32, double, dbl_src1, [LEN]); + + if (argc > 2 && !strcmp(argv[1], "-s")) + seed = strtoul(argv[2], NULL, 10); + else + seed = av_get_random_seed(); + + av_log(NULL, AV_LOG_INFO, "float_dsp-test: random seed %u\n", seed); + + av_lfg_init(&lfg, seed); + + fill_float_array(&lfg, src0, LEN); + fill_float_array(&lfg, src1, LEN); + fill_float_array(&lfg, src2, LEN); + + fill_double_array(&lfg, dbl_src0, LEN); + fill_double_array(&lfg, dbl_src1, LEN); + + avpriv_float_dsp_init(&fdsp, 1); + av_set_cpu_flags_mask(0); + avpriv_float_dsp_init(&cdsp, 1); + + if (test_vector_fmul(&fdsp, &cdsp, src0, src1)) + ret -= 1 << 0; + if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0])) + ret -= 1 << 1; + if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0])) + ret -= 1 << 2; + if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2)) + ret -= 1 << 3; + if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2)) + ret -= 1 << 4; + if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1)) + ret -= 1 << 5; + if (test_butterflies_float(&fdsp, &cdsp, src0, src1)) + ret -= 1 << 6; + if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1)) + ret -= 1 << 7; + if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0])) + ret -= 1 << 8; + + return ret; +} diff --git a/libavutil/tests/hmac.c b/libavutil/tests/hmac.c new file mode 100644 index 0000000000..600240fe97 --- /dev/null +++ b/libavutil/tests/hmac.c @@ -0,0 +1,92 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/hmac.c" + +#include +#include + +static void test(AVHMAC *hmac, const uint8_t *key, int keylen, + const uint8_t *data, int datalen) +{ + uint8_t buf[MAX_HASHLEN]; + int out, i; + // Some of the test vectors are strings, where sizeof() includes the + // trailing null byte - remove that. + if (!key[keylen - 1]) + keylen--; + if (!data[datalen - 1]) + datalen--; + out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf)); + for (i = 0; i < out; i++) + printf("%02x", buf[i]); + printf("\n"); +} + +int main(void) +{ + uint8_t key1[20], key3[131], data3[50]; + enum AVHMACType i = AV_HMAC_SHA224; + static const uint8_t key2[] = "Jefe"; + static const uint8_t data1[] = "Hi There"; + static const uint8_t data2[] = "what do ya want for nothing?"; + static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First"; + static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; + static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger " + "than block-size data. The key needs to be hashed before being used" + " by the HMAC algorithm."; + AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5); + if (!hmac) + return 1; + memset(key1, 0x0b, sizeof(key1)); + memset(key3, 0xaa, sizeof(key3)); + memset(data3, 0xdd, sizeof(data3)); + // RFC 2202 test vectors + test(hmac, key1, 16, data1, sizeof(data1)); + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); + test(hmac, key3, 16, data3, sizeof(data3)); + test(hmac, key3, 80, data4, sizeof(data4)); + test(hmac, key3, 80, data5, sizeof(data5)); + av_hmac_free(hmac); + + /* SHA-1 */ + hmac = av_hmac_alloc(AV_HMAC_SHA1); + if (!hmac) + return 1; + // RFC 2202 test vectors + test(hmac, key1, sizeof(key1), data1, sizeof(data1)); + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); + test(hmac, key3, 20, data3, sizeof(data3)); + test(hmac, key3, 80, data4, sizeof(data4)); + test(hmac, key3, 80, data5, sizeof(data5)); + av_hmac_free(hmac); + + /* SHA-2 */ + while (i <= AV_HMAC_SHA256) { + hmac = av_hmac_alloc(i); + // RFC 4231 test vectors + test(hmac, key1, sizeof(key1), data1, sizeof(data1)); + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); + test(hmac, key3, 20, data3, sizeof(data3)); + test(hmac, key3, sizeof(key3), data4, sizeof(data4)); + test(hmac, key3, sizeof(key3), data6, sizeof(data6)); + av_hmac_free(hmac); + i++; + } + return 0; +} diff --git a/libavutil/tests/lfg.c b/libavutil/tests/lfg.c new file mode 100644 index 0000000000..9a0c47c4de --- /dev/null +++ b/libavutil/tests/lfg.c @@ -0,0 +1,56 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/log.h" +#include "libavutil/timer.h" +#include "libavutil/lfg.h" + +int main(void) +{ + int x = 0; + int i, j; + AVLFG state; + + av_lfg_init(&state, 0xdeadbeef); + for (j = 0; j < 10000; j++) { + START_TIMER + for (i = 0; i < 624; i++) + x += av_lfg_get(&state); + STOP_TIMER("624 calls of av_lfg_get"); + } + av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x); + + /* BMG usage example */ + { + double mean = 1000; + double stddev = 53; + + av_lfg_init(&state, 42); + + for (i = 0; i < 1000; i += 2) { + double bmg_out[2]; + av_bmg_get(&state, bmg_out); + av_log(NULL, AV_LOG_INFO, + "%f\n%f\n", + bmg_out[0] * stddev + mean, + bmg_out[1] * stddev + mean); + } + } + + return 0; +} diff --git a/libavutil/tests/lls.c b/libavutil/tests/lls.c new file mode 100644 index 0000000000..7866b38998 --- /dev/null +++ b/libavutil/tests/lls.c @@ -0,0 +1,54 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/internal.h" +#include "libavutil/lfg.h" +#include "libavutil/lls.h" + +int main(void) +{ + LLSModel m; + int i, order; + AVLFG lfg; + + av_lfg_init(&lfg, 1); + avpriv_init_lls(&m, 3); + + for (i = 0; i < 100; i++) { + LOCAL_ALIGNED(32, double, var, [4]); + double eval; + + var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2; + var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; + var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; + var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; + m.update_lls(&m, var); + avpriv_solve_lls(&m, 0.001, 0); + for (order = 0; order < 3; order++) { + eval = m.evaluate_lls(&m, var + 1, order); + printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n", + var[0], order, eval, sqrt(m.variance[order] / (i + 1)), + m.coeff[order][0], m.coeff[order][1], + m.coeff[order][2]); + } + } + return 0; +} diff --git a/libavutil/tests/md5.c b/libavutil/tests/md5.c new file mode 100644 index 0000000000..9fb7006dd8 --- /dev/null +++ b/libavutil/tests/md5.c @@ -0,0 +1,54 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/md5.h" + +static void print_md5(uint8_t *md5) +{ + int i; + for (i = 0; i < 16; i++) + printf("%02x", md5[i]); + printf("\n"); +} + +int main(void) +{ + uint8_t md5val[16]; + int i; + uint8_t in[1000]; + + for (i = 0; i < 1000; i++) + in[i] = i * i; + av_md5_sum(md5val, in, 1000); + print_md5(md5val); + av_md5_sum(md5val, in, 63); + print_md5(md5val); + av_md5_sum(md5val, in, 64); + print_md5(md5val); + av_md5_sum(md5val, in, 65); + print_md5(md5val); + for (i = 0; i < 1000; i++) + in[i] = i % 127; + av_md5_sum(md5val, in, 999); + print_md5(md5val); + + return 0; +} diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c new file mode 100644 index 0000000000..350ce3d820 --- /dev/null +++ b/libavutil/tests/opt.c @@ -0,0 +1,110 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/common.h" +#include "libavutil/error.h" +#include "libavutil/log.h" +#include "libavutil/mem.h" +#include "libavutil/rational.h" +#include "libavutil/opt.h" + +typedef struct TestContext { + const AVClass *class; + int num; + int toggle; + char *string; + int flags; + AVRational rational; +} TestContext; + +#define OFFSET(x) offsetof(TestContext, x) + +#define TEST_FLAG_COOL 01 +#define TEST_FLAG_LAME 02 +#define TEST_FLAG_MU 04 + +static const AVOption test_options[] = { + { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 }, + { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 }, + { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 }, + { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX }, + { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"}, + { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"}, + { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"}, + { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"}, + { NULL }, +}; + +static const char *test_get_name(void *ctx) +{ + return "test"; +} + +static const AVClass test_class = { + "TestContext", + test_get_name, + test_options +}; + +int main(void) +{ + int i; + TestContext test_ctx = { .class = &test_class }; + static const char *options[] = { + "", + ":", + "=", + "foo=:", + ":=foo", + "=foo", + "foo=", + "foo", + "foo=val", + "foo==val", + "toggle=:", + "string=:", + "toggle=1 : foo", + "toggle=100", + "toggle==1", + "flags=+mu-lame : num=42: toggle=0", + "num=42 : string=blahblah", + "rational=0 : rational=1/2 : rational=1/-1", + "rational=-1/0", + }; + + printf("\nTesting av_set_options_string()\n"); + + av_opt_set_defaults(&test_ctx); + test_ctx.string = av_strdup("default"); + if (!test_ctx.string) + return AVERROR(ENOMEM); + + av_log_set_level(AV_LOG_DEBUG); + + for (i = 0; i < FF_ARRAY_ELEMS(options); i++) { + av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]); + if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0) + av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]); + printf("\n"); + } + + return 0; +} diff --git a/libavutil/tests/parseutils.c b/libavutil/tests/parseutils.c new file mode 100644 index 0000000000..805c01ff5a --- /dev/null +++ b/libavutil/tests/parseutils.c @@ -0,0 +1,116 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "libavutil/common.h" +#include "libavutil/log.h" +#include "libavutil/rational.h" +#include "libavutil/parseutils.h" + +int main(void) +{ + int i; + uint8_t rgba[4]; + static const char *const rates[] = { + "-inf", + "inf", + "nan", + "123/0", + "-123 / 0", + "", + "/", + " 123 / 321", + "foo/foo", + "foo/1", + "1/foo", + "0/0", + "/0", + "1/", + "1", + "0", + "-123/123", + "-foo", + "123.23", + ".23", + "-.23", + "-0.234", + "-0.0000001", + " 21332.2324 ", + " -21332.2324 ", + }; + static const char *const color_names[] = { + "foo", + "red", + "Red ", + "RED", + "Violet", + "Yellow", + "Red", + "0x000000", + "0x0000000", + "0xff000000", + "0x3e34ff", + "0x3e34ffaa", + "0xffXXee", + "0xfoobar", + "0xffffeeeeeeee", + "#ff0000", + "#ffXX00", + "ff0000", + "ffXX00", + "red@foo", + "random@10", + "0xff0000@1.0", + "red@", + "red@0xfff", + "red@0xf", + "red@2", + "red@0.1", + "red@-1", + "red@0.5", + "red@1.0", + "red@256", + "red@10foo", + "red@-1.0", + "red@-0.0", + }; + + printf("Testing av_parse_video_rate()\n"); + + for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { + int ret; + AVRational q = { 0, 0 }; + ret = av_parse_video_rate(&q, rates[i]); + printf("'%s' -> %d/%d %s\n", + rates[i], q.num, q.den, ret ? "ERROR" : "OK"); + } + + printf("\nTesting av_parse_color()\n"); + + av_log_set_level(AV_LOG_DEBUG); + + for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { + if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) + printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", + color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); + } + + return 0; +} diff --git a/libavutil/tests/sha.c b/libavutil/tests/sha.c new file mode 100644 index 0000000000..0f1d514b44 --- /dev/null +++ b/libavutil/tests/sha.c @@ -0,0 +1,69 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/sha.c" + +#include + +int main(void) +{ + int i, j, k; + AVSHA ctx; + unsigned char digest[32]; + static const int lengths[3] = { 160, 224, 256 }; + + for (j = 0; j < 3; j++) { + printf("Testing SHA-%d\n", lengths[j]); + for (k = 0; k < 3; k++) { + av_sha_init(&ctx, lengths[j]); + if (k == 0) + av_sha_update(&ctx, "abc", 3); + else if (k == 1) + av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56); + else + for (i = 0; i < 1000*1000; i++) + av_sha_update(&ctx, "a", 1); + av_sha_final(&ctx, digest); + for (i = 0; i < lengths[j] >> 3; i++) + printf("%02X", digest[i]); + putchar('\n'); + } + switch (j) { + case 0: + //test vectors (from FIPS PUB 180-1) + printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n" + "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n" + "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n"); + break; + case 1: + //test vectors (from FIPS PUB 180-2 Appendix A) + printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n" + "75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n" + "20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n"); + break; + case 2: + //test vectors (from FIPS PUB 180-2) + printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n" + "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n" + "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n"); + break; + } + } + + return 0; +} diff --git a/libavutil/tests/tree.c b/libavutil/tests/tree.c new file mode 100644 index 0000000000..fb19b27896 --- /dev/null +++ b/libavutil/tests/tree.c @@ -0,0 +1,110 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/tree.c" + +#include + +#include "libavutil/common.h" +#include "libavutil/lfg.h" +#include "libavutil/log.h" + +static int check(AVTreeNode *t) +{ + if (t) { + int left = check(t->child[0]); + int right = check(t->child[1]); + + if (left > 999 || right > 999) + return 1000; + if (right - left != t->state) + return 1000; + if (t->state > 1 || t->state < -1) + return 1000; + return FFMAX(left, right) + 1; + } + return 0; +} + +static void print(AVTreeNode *t, int depth) +{ + int i; + for (i = 0; i < depth * 4; i++) + av_log(NULL, AV_LOG_ERROR, " "); + if (t) { + av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem); + print(t->child[0], depth + 1); + print(t->child[1], depth + 1); + } else + av_log(NULL, AV_LOG_ERROR, "NULL\n"); +} + +static int cmp(void *a, const void *b) +{ + return (uint8_t *) a - (const uint8_t *) b; +} + +int main(void) +{ + int i; + AVTreeNode *root = NULL, *node = NULL; + AVLFG prng; + + av_lfg_init(&prng, 1); + + for (i = 0; i < 10000; i++) { + AVTreeNode *node2 = NULL; + intptr_t j = av_lfg_get(&prng) % 86294; + void *ret, *jj = (void *)(j + 1); + + while (ret = av_tree_find(root, jj, cmp, NULL)) { + j = av_lfg_get(&prng) % 86294; + jj = (void *)(j + 1); + } + + if (check(root) > 999) { + av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); + print(root, 0); + return 1; + } + + if (!node) + node = av_tree_node_alloc(); + if (!node) { + av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); + return 1; + } + av_tree_insert(&root, jj, cmp, &node); + + while (ret = av_tree_find(root, jj, cmp, NULL)) { + j = av_lfg_get(&prng) % 86294; + jj = (void *)(j + 1); + } + + ret = av_tree_insert(&root, jj, cmp, &node2); + if (ret != jj) + av_tree_destroy(node2); + ret = av_tree_find(root, jj, cmp, NULL); + if (ret) + av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); + } + + av_tree_destroy(root); + + return 0; +} diff --git a/libavutil/tests/xtea.c b/libavutil/tests/xtea.c new file mode 100644 index 0000000000..326f2714a9 --- /dev/null +++ b/libavutil/tests/xtea.c @@ -0,0 +1,120 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/intreadwrite.h" +#include "libavutil/xtea.h" + +#define XTEA_NUM_TESTS 6 + +static const uint8_t xtea_test_key[XTEA_NUM_TESTS][16] = { + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } +}; + +static const uint8_t xtea_test_pt[XTEA_NUM_TESTS][8] = { + { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 }, + { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, + { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f }, + { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 }, + { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, + { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 } +}; + +static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = { + { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 }, + { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 }, + { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, + { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 }, + { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d }, + { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 } +}; + +static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, + const uint8_t *ref, int len, uint8_t *iv, int dir, + const char *test, + void (*crypt)(AVXTEA *, uint8_t *, const uint8_t *, int, uint8_t *, int)) +{ + crypt(ctx, dst, src, len, iv, dir); + if (memcmp(dst, ref, 8*len)) { + int i; + printf("%s failed\ngot ", test); + for (i = 0; i < 8*len; i++) + printf("%02x ", dst[i]); + printf("\nexpected "); + for (i = 0; i < 8*len; i++) + printf("%02x ", ref[i]); + printf("\n"); + exit(1); + } +} + +int main(void) +{ + AVXTEA ctx; + uint8_t buf[16], iv[8]; + int i, j; + static const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld"; + uint8_t ct[32]; + uint8_t pl[32]; + + for (i = 0; i < XTEA_NUM_TESTS; i++) { + av_xtea_init(&ctx, xtea_test_key[i]); + + test_xtea(&ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption", av_xtea_crypt); + test_xtea(&ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption", av_xtea_crypt); + + for (j = 0; j < 4; j++) + AV_WL32(&buf[4*j], AV_RB32(&xtea_test_key[i][4*j])); + av_xtea_le_init(&ctx, buf); + for (j = 0; j < 2; j++) { + AV_WL32(&ct[4*j], AV_RB32(&xtea_test_ct[i][4*j])); + AV_WL32(&pl[4*j], AV_RB32(&xtea_test_pt[i][4*j])); + } + test_xtea(&ctx, buf, pl, ct, 1, NULL, 0, "encryption", av_xtea_le_crypt); + test_xtea(&ctx, buf, ct, pl, 1, NULL, 1, "decryption", av_xtea_le_crypt); + + /* encrypt */ + memcpy(iv, "HALLO123", 8); + av_xtea_crypt(&ctx, ct, src, 4, iv, 0); + + /* decrypt into pl */ + memcpy(iv, "HALLO123", 8); + test_xtea(&ctx, pl, ct, src, 4, iv, 1, "CBC decryption", av_xtea_crypt); + + memcpy(iv, "HALLO123", 8); + test_xtea(&ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption", av_xtea_crypt); + } + printf("Test encryption/decryption success.\n"); + + return 0; +} diff --git a/libavutil/tree-test.c b/libavutil/tree-test.c deleted file mode 100644 index f93e53409d..0000000000 --- a/libavutil/tree-test.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "tree.c" - -#include - -#include "common.h" -#include "lfg.h" -#include "log.h" - -static int check(AVTreeNode *t) -{ - if (t) { - int left = check(t->child[0]); - int right = check(t->child[1]); - - if (left > 999 || right > 999) - return 1000; - if (right - left != t->state) - return 1000; - if (t->state > 1 || t->state < -1) - return 1000; - return FFMAX(left, right) + 1; - } - return 0; -} - -static void print(AVTreeNode *t, int depth) -{ - int i; - for (i = 0; i < depth * 4; i++) - av_log(NULL, AV_LOG_ERROR, " "); - if (t) { - av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem); - print(t->child[0], depth + 1); - print(t->child[1], depth + 1); - } else - av_log(NULL, AV_LOG_ERROR, "NULL\n"); -} - -static int cmp(void *a, const void *b) -{ - return (uint8_t *) a - (const uint8_t *) b; -} - -int main(void) -{ - int i; - AVTreeNode *root = NULL, *node = NULL; - AVLFG prng; - - av_lfg_init(&prng, 1); - - for (i = 0; i < 10000; i++) { - AVTreeNode *node2 = NULL; - intptr_t j = av_lfg_get(&prng) % 86294; - void *ret, *jj = (void *)(j + 1); - - while (ret = av_tree_find(root, jj, cmp, NULL)) { - j = av_lfg_get(&prng) % 86294; - jj = (void *)(j + 1); - } - - if (check(root) > 999) { - av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); - print(root, 0); - return 1; - } - - if (!node) - node = av_tree_node_alloc(); - if (!node) { - av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); - return 1; - } - av_tree_insert(&root, jj, cmp, &node); - - while (ret = av_tree_find(root, jj, cmp, NULL)) { - j = av_lfg_get(&prng) % 86294; - jj = (void *)(j + 1); - } - - ret = av_tree_insert(&root, jj, cmp, &node2); - if (ret != jj) - av_tree_destroy(node2); - ret = av_tree_find(root, jj, cmp, NULL); - if (ret) - av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); - } - - av_tree_destroy(root); - - return 0; -} diff --git a/libavutil/xtea-test.c b/libavutil/xtea-test.c deleted file mode 100644 index 98445760eb..0000000000 --- a/libavutil/xtea-test.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "intreadwrite.h" -#include "xtea.h" - -#define XTEA_NUM_TESTS 6 - -static const uint8_t xtea_test_key[XTEA_NUM_TESTS][16] = { - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } -}; - -static const uint8_t xtea_test_pt[XTEA_NUM_TESTS][8] = { - { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 }, - { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, - { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f }, - { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 }, - { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, - { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 } -}; - -static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = { - { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 }, - { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 }, - { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }, - { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 }, - { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d }, - { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 } -}; - -static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, - const uint8_t *ref, int len, uint8_t *iv, int dir, - const char *test, - void (*crypt)(AVXTEA *, uint8_t *, const uint8_t *, int, uint8_t *, int)) -{ - crypt(ctx, dst, src, len, iv, dir); - if (memcmp(dst, ref, 8*len)) { - int i; - printf("%s failed\ngot ", test); - for (i = 0; i < 8*len; i++) - printf("%02x ", dst[i]); - printf("\nexpected "); - for (i = 0; i < 8*len; i++) - printf("%02x ", ref[i]); - printf("\n"); - exit(1); - } -} - -int main(void) -{ - AVXTEA ctx; - uint8_t buf[16], iv[8]; - int i, j; - static const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld"; - uint8_t ct[32]; - uint8_t pl[32]; - - for (i = 0; i < XTEA_NUM_TESTS; i++) { - av_xtea_init(&ctx, xtea_test_key[i]); - - test_xtea(&ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption", av_xtea_crypt); - test_xtea(&ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption", av_xtea_crypt); - - for (j = 0; j < 4; j++) - AV_WL32(&buf[4*j], AV_RB32(&xtea_test_key[i][4*j])); - av_xtea_le_init(&ctx, buf); - for (j = 0; j < 2; j++) { - AV_WL32(&ct[4*j], AV_RB32(&xtea_test_ct[i][4*j])); - AV_WL32(&pl[4*j], AV_RB32(&xtea_test_pt[i][4*j])); - } - test_xtea(&ctx, buf, pl, ct, 1, NULL, 0, "encryption", av_xtea_le_crypt); - test_xtea(&ctx, buf, ct, pl, 1, NULL, 1, "decryption", av_xtea_le_crypt); - - /* encrypt */ - memcpy(iv, "HALLO123", 8); - av_xtea_crypt(&ctx, ct, src, 4, iv, 0); - - /* decrypt into pl */ - memcpy(iv, "HALLO123", 8); - test_xtea(&ctx, pl, ct, src, 4, iv, 1, "CBC decryption", av_xtea_crypt); - - memcpy(iv, "HALLO123", 8); - test_xtea(&ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption", av_xtea_crypt); - } - printf("Test encryption/decryption success.\n"); - - return 0; -} diff --git a/library.mak b/library.mak index c980c3dbe3..712b7e1c6e 100644 --- a/library.mak +++ b/library.mak @@ -44,11 +44,12 @@ $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver $(DEP_LIBS) $(SLIB_EXTRA_CMD) clean:: - $(RM) $(addprefix $(SUBDIR),*-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \ - $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) + $(RM) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \ + $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) $(CLEANSUFFIXES:%=$(SUBDIR)tests/%) distclean:: clean - $(RM) $(DISTCLEANSUFFIXES:%=$(SUBDIR)%) $(DISTCLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) + $(RM) $(DISTCLEANSUFFIXES:%=$(SUBDIR)%) $(DISTCLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) \ + $(DISTCLEANSUFFIXES:%=$(SUBDIR)tests/%) install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME) $(Q)mkdir -p "$(SHLIBDIR)" diff --git a/libswscale/colorspace-test.c b/libswscale/colorspace-test.c deleted file mode 100644 index fbf595d4c1..0000000000 --- a/libswscale/colorspace-test.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2002 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include /* for memset() */ -#include -#include - -#include "swscale.h" -#include "rgb2rgb.h" -#include "libavutil/mem.h" - -#define SIZE 1000 -#define srcByte 0x55 -#define dstByte 0xBB - -#define FUNC(s, d, n) { s, d, #n, n } - -int main(void) -{ - int i, funcNum; - uint8_t *srcBuffer = av_malloc(SIZE); - uint8_t *dstBuffer = av_malloc(SIZE); - int failedNum = 0; - int passedNum = 0; - - if (!srcBuffer || !dstBuffer) - return -1; - - av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); - sws_rgb2rgb_init(); - - for (funcNum = 0; ; funcNum++) { - struct func_info_s { - int src_bpp; - int dst_bpp; - const char *name; - void (*func)(const uint8_t *src, uint8_t *dst, int src_size); - } func_info[] = { - FUNC(2, 2, rgb15to16), - FUNC(2, 3, rgb15to24), - FUNC(2, 4, rgb15to32), - FUNC(2, 3, rgb16to24), - FUNC(2, 4, rgb16to32), - FUNC(3, 2, rgb24to15), - FUNC(3, 2, rgb24to16), - FUNC(3, 4, rgb24to32), - FUNC(4, 2, rgb32to15), - FUNC(4, 2, rgb32to16), - FUNC(4, 3, rgb32to24), - FUNC(2, 2, rgb16to15), - FUNC(2, 2, rgb15tobgr15), - FUNC(2, 2, rgb15tobgr16), - FUNC(2, 3, rgb15tobgr24), - FUNC(2, 4, rgb15tobgr32), - FUNC(2, 2, rgb16tobgr15), - FUNC(2, 2, rgb16tobgr16), - FUNC(2, 3, rgb16tobgr24), - FUNC(2, 4, rgb16tobgr32), - FUNC(3, 2, rgb24tobgr15), - FUNC(3, 2, rgb24tobgr16), - FUNC(3, 3, rgb24tobgr24), - FUNC(3, 4, rgb24tobgr32), - FUNC(4, 2, rgb32tobgr15), - FUNC(4, 2, rgb32tobgr16), - FUNC(4, 3, rgb32tobgr24), - FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */ - FUNC(0, 0, NULL) - }; - int width; - int failed = 0; - int srcBpp = 0; - int dstBpp = 0; - - if (!func_info[funcNum].func) - break; - - av_log(NULL, AV_LOG_INFO, "."); - memset(srcBuffer, srcByte, SIZE); - - for (width = 63; width > 0; width--) { - int dstOffset; - for (dstOffset = 128; dstOffset < 196; dstOffset += 4) { - int srcOffset; - memset(dstBuffer, dstByte, SIZE); - - for (srcOffset = 128; srcOffset < 196; srcOffset += 4) { - uint8_t *src = srcBuffer + srcOffset; - uint8_t *dst = dstBuffer + dstOffset; - const char *name = NULL; - - // don't fill the screen with shit ... - if (failed) - break; - - srcBpp = func_info[funcNum].src_bpp; - dstBpp = func_info[funcNum].dst_bpp; - name = func_info[funcNum].name; - - func_info[funcNum].func(src, dst, width * srcBpp); - - if (!srcBpp) - break; - - for (i = 0; i < SIZE; i++) { - if (srcBuffer[i] != srcByte) { - av_log(NULL, AV_LOG_INFO, - "src damaged at %d w:%d src:%d dst:%d %s\n", - i, width, srcOffset, dstOffset, name); - failed = 1; - break; - } - } - for (i = 0; i < dstOffset; i++) { - if (dstBuffer[i] != dstByte) { - av_log(NULL, AV_LOG_INFO, - "dst damaged at %d w:%d src:%d dst:%d %s\n", - i, width, srcOffset, dstOffset, name); - failed = 1; - break; - } - } - for (i = dstOffset + width * dstBpp; i < SIZE; i++) { - if (dstBuffer[i] != dstByte) { - av_log(NULL, AV_LOG_INFO, - "dst damaged at %d w:%d src:%d dst:%d %s\n", - i, width, srcOffset, dstOffset, name); - failed = 1; - break; - } - } - } - } - } - if (failed) - failedNum++; - else if (srcBpp) - passedNum++; - } - - av_log(NULL, AV_LOG_INFO, - "\n%d converters passed, %d converters randomly overwrote memory\n", - passedNum, failedNum); - return failedNum; -} diff --git a/libswscale/swscale-test.c b/libswscale/swscale-test.c deleted file mode 100644 index 8063519be1..0000000000 --- a/libswscale/swscale-test.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (C) 2003 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include - -#undef HAVE_AV_CONFIG_H -#include "libavutil/imgutils.h" -#include "libavutil/mem.h" -#include "libavutil/avutil.h" -#include "libavutil/crc.h" -#include "libavutil/pixdesc.h" -#include "libavutil/lfg.h" -#include "swscale.h" - -/* HACK Duplicated from swscale_internal.h. - * Should be removed when a cleaner pixel format system exists. */ -#define isGray(x) \ - ((x) == AV_PIX_FMT_GRAY8 || \ - (x) == AV_PIX_FMT_YA8 || \ - (x) == AV_PIX_FMT_GRAY16BE || \ - (x) == AV_PIX_FMT_GRAY16LE || \ - (x) == AV_PIX_FMT_YA16BE || \ - (x) == AV_PIX_FMT_YA16LE) -#define hasChroma(x) \ - (!(isGray(x) || \ - (x) == AV_PIX_FMT_MONOBLACK || \ - (x) == AV_PIX_FMT_MONOWHITE)) -#define isALPHA(x) \ - ((x) == AV_PIX_FMT_BGR32 || \ - (x) == AV_PIX_FMT_BGR32_1 || \ - (x) == AV_PIX_FMT_RGB32 || \ - (x) == AV_PIX_FMT_RGB32_1 || \ - (x) == AV_PIX_FMT_YUVA420P) - -static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, - int stride2, int w, int h) -{ - int x, y; - uint64_t ssd = 0; - - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - int d = src1[x + y * stride1] - src2[x + y * stride2]; - ssd += d * d; - } - } - return ssd; -} - -struct Results { - uint64_t ssdY; - uint64_t ssdU; - uint64_t ssdV; - uint64_t ssdA; - uint32_t crc; -}; - -// test by ref -> src -> dst -> out & compare out against ref -// ref & out are YV12 -static int doTest(uint8_t *ref[4], int refStride[4], int w, int h, - enum AVPixelFormat srcFormat, enum AVPixelFormat dstFormat, - int srcW, int srcH, int dstW, int dstH, int flags, - struct Results *r) -{ - const AVPixFmtDescriptor *desc_yuva420p = av_pix_fmt_desc_get(AV_PIX_FMT_YUVA420P); - const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat); - const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat); - static enum AVPixelFormat cur_srcFormat; - static int cur_srcW, cur_srcH; - static uint8_t *src[4]; - static int srcStride[4]; - uint8_t *dst[4] = { 0 }; - uint8_t *out[4] = { 0 }; - int dstStride[4]; - int i; - uint64_t ssdY, ssdU = 0, ssdV = 0, ssdA = 0; - struct SwsContext *dstContext = NULL, *outContext = NULL; - uint32_t crc = 0; - int res = 0; - - if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) { - struct SwsContext *srcContext = NULL; - int p; - - for (p = 0; p < 4; p++) - av_freep(&src[p]); - - av_image_fill_linesizes(srcStride, srcFormat, srcW); - for (p = 0; p < 4; p++) { - if (srcStride[p]) - src[p] = av_mallocz(srcStride[p] * srcH + 16); - if (srcStride[p] && !src[p]) { - perror("Malloc"); - res = -1; - goto end; - } - } - srcContext = sws_getContext(w, h, AV_PIX_FMT_YUVA420P, srcW, srcH, - srcFormat, SWS_BILINEAR, NULL, NULL, NULL); - if (!srcContext) { - fprintf(stderr, "Failed to get %s ---> %s\n", - desc_yuva420p->name, - desc_src->name); - res = -1; - goto end; - } - sws_scale(srcContext, ref, refStride, 0, h, src, srcStride); - sws_freeContext(srcContext); - - cur_srcFormat = srcFormat; - cur_srcW = srcW; - cur_srcH = srcH; - } - - av_image_fill_linesizes(dstStride, dstFormat, dstW); - for (i = 0; i < 4; i++) { - /* Image buffers passed into libswscale can be allocated any way you - * prefer, as long as they're aligned enough for the architecture, and - * they're freed appropriately (such as using av_free for buffers - * allocated with av_malloc). */ - /* An extra 16 bytes is being allocated because some scalers may write - * out of bounds. */ - if (dstStride[i]) - dst[i] = av_mallocz(dstStride[i] * dstH + 16); - if (dstStride[i] && !dst[i]) { - perror("Malloc"); - res = -1; - - goto end; - } - } - - dstContext = sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, - flags, NULL, NULL, NULL); - if (!dstContext) { - fprintf(stderr, "Failed to get %s ---> %s\n", - desc_src->name, desc_dst->name); - res = -1; - goto end; - } - - printf(" %s %dx%d -> %s %3dx%3d flags=%2d", - desc_src->name, srcW, srcH, - desc_dst->name, dstW, dstH, - flags); - fflush(stdout); - - sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); - - for (i = 0; i < 4 && dstStride[i]; i++) - crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], - dstStride[i] * dstH); - - if (r && crc == r->crc) { - ssdY = r->ssdY; - ssdU = r->ssdU; - ssdV = r->ssdV; - ssdA = r->ssdA; - } else { - for (i = 0; i < 4; i++) { - if (refStride[i]) - out[i] = av_mallocz(refStride[i] * h); - if (refStride[i] && !out[i]) { - perror("Malloc"); - res = -1; - goto end; - } - } - outContext = sws_getContext(dstW, dstH, dstFormat, w, h, - AV_PIX_FMT_YUVA420P, SWS_BILINEAR, - NULL, NULL, NULL); - if (!outContext) { - fprintf(stderr, "Failed to get %s ---> %s\n", - desc_dst->name, - desc_yuva420p->name); - res = -1; - goto end; - } - sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); - - ssdY = getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); - if (hasChroma(srcFormat) && hasChroma(dstFormat)) { - //FIXME check that output is really gray - ssdU = getSSD(ref[1], out[1], refStride[1], refStride[1], - (w + 1) >> 1, (h + 1) >> 1); - ssdV = getSSD(ref[2], out[2], refStride[2], refStride[2], - (w + 1) >> 1, (h + 1) >> 1); - } - if (isALPHA(srcFormat) && isALPHA(dstFormat)) - ssdA = getSSD(ref[3], out[3], refStride[3], refStride[3], w, h); - - ssdY /= w * h; - ssdU /= w * h / 4; - ssdV /= w * h / 4; - ssdA /= w * h; - - sws_freeContext(outContext); - - for (i = 0; i < 4; i++) - if (refStride[i]) - av_free(out[i]); - } - - printf(" CRC=%08x SSD=%5"PRId64 ",%5"PRId64 ",%5"PRId64 ",%5"PRId64 "\n", - crc, ssdY, ssdU, ssdV, ssdA); - -end: - sws_freeContext(dstContext); - - for (i = 0; i < 4; i++) - if (dstStride[i]) - av_free(dst[i]); - - return res; -} - -static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h, - enum AVPixelFormat srcFormat_in, - enum AVPixelFormat dstFormat_in) -{ - const int flags[] = { SWS_FAST_BILINEAR, SWS_BILINEAR, SWS_BICUBIC, - SWS_X, SWS_POINT, SWS_AREA, 0 }; - const int srcW = w; - const int srcH = h; - const int dstW[] = { srcW - srcW / 3, srcW, srcW + srcW / 3, 0 }; - const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 }; - enum AVPixelFormat srcFormat, dstFormat; - const AVPixFmtDescriptor *desc_src, *desc_dst; - - for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0; - srcFormat < AV_PIX_FMT_NB; srcFormat++) { - if (!sws_isSupportedInput(srcFormat) || - !sws_isSupportedOutput(srcFormat)) - continue; - - desc_src = av_pix_fmt_desc_get(srcFormat); - - for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0; - dstFormat < AV_PIX_FMT_NB; dstFormat++) { - int i, j, k; - int res = 0; - - if (!sws_isSupportedInput(dstFormat) || - !sws_isSupportedOutput(dstFormat)) - continue; - - desc_dst = av_pix_fmt_desc_get(dstFormat); - - printf("%s -> %s\n", desc_src->name, desc_dst->name); - fflush(stdout); - - for (k = 0; flags[k] && !res; k++) - for (i = 0; dstW[i] && !res; i++) - for (j = 0; dstH[j] && !res; j++) - res = doTest(ref, refStride, w, h, - srcFormat, dstFormat, - srcW, srcH, dstW[i], dstH[j], flags[k], - NULL); - if (dstFormat_in != AV_PIX_FMT_NONE) - break; - } - if (srcFormat_in != AV_PIX_FMT_NONE) - break; - } -} - -static int fileTest(uint8_t *ref[4], int refStride[4], int w, int h, FILE *fp, - enum AVPixelFormat srcFormat_in, - enum AVPixelFormat dstFormat_in) -{ - char buf[256]; - - while (fgets(buf, sizeof(buf), fp)) { - struct Results r; - enum AVPixelFormat srcFormat; - char srcStr[12]; - int srcW, srcH; - enum AVPixelFormat dstFormat; - char dstStr[12]; - int dstW, dstH; - int flags; - int ret; - - ret = sscanf(buf, - " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x" - " SSD=%"PRId64 ", %"PRId64 ", %"PRId64 ", %"PRId64 "\n", - srcStr, &srcW, &srcH, dstStr, &dstW, &dstH, - &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA); - if (ret != 12) { - srcStr[0] = dstStr[0] = 0; - ret = sscanf(buf, "%12s -> %12s\n", srcStr, dstStr); - } - - srcFormat = av_get_pix_fmt(srcStr); - dstFormat = av_get_pix_fmt(dstStr); - - if (srcFormat == AV_PIX_FMT_NONE || dstFormat == AV_PIX_FMT_NONE) { - fprintf(stderr, "malformed input file\n"); - return -1; - } - if ((srcFormat_in != AV_PIX_FMT_NONE && srcFormat_in != srcFormat) || - (dstFormat_in != AV_PIX_FMT_NONE && dstFormat_in != dstFormat)) - continue; - if (ret != 12) { - printf("%s", buf); - continue; - } - - doTest(ref, refStride, w, h, - srcFormat, dstFormat, - srcW, srcH, dstW, dstH, flags, - &r); - } - - return 0; -} - -#define W 96 -#define H 96 - -int main(int argc, char **argv) -{ - enum AVPixelFormat srcFormat = AV_PIX_FMT_NONE; - enum AVPixelFormat dstFormat = AV_PIX_FMT_NONE; - uint8_t *rgb_data = av_malloc(W * H * 4); - uint8_t *rgb_src[4] = { rgb_data, NULL, NULL, NULL }; - int rgb_stride[4] = { 4 * W, 0, 0, 0 }; - uint8_t *data = av_malloc(4 * W * H); - uint8_t *src[4] = { data, data + W * H, data + W * H * 2, data + W * H * 3 }; - int stride[4] = { W, W, W, W }; - int x, y; - struct SwsContext *sws; - AVLFG rand; - int res = -1; - int i; - - if (!rgb_data || !data) - return -1; - - sws = sws_getContext(W / 12, H / 12, AV_PIX_FMT_RGB32, W, H, - AV_PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); - - av_lfg_init(&rand, 1); - - for (y = 0; y < H; y++) - for (x = 0; x < W * 4; x++) - rgb_data[ x + y * 4 * W] = av_lfg_get(&rand); - sws_scale(sws, rgb_src, rgb_stride, 0, H, src, stride); - sws_freeContext(sws); - av_free(rgb_data); - - for (i = 1; i < argc; i += 2) { - if (argv[i][0] != '-' || i + 1 == argc) - goto bad_option; - if (!strcmp(argv[i], "-ref")) { - FILE *fp = fopen(argv[i + 1], "r"); - if (!fp) { - fprintf(stderr, "could not open '%s'\n", argv[i + 1]); - goto error; - } - res = fileTest(src, stride, W, H, fp, srcFormat, dstFormat); - fclose(fp); - goto end; - } else if (!strcmp(argv[i], "-src")) { - srcFormat = av_get_pix_fmt(argv[i + 1]); - if (srcFormat == AV_PIX_FMT_NONE) { - fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); - return -1; - } - } else if (!strcmp(argv[i], "-dst")) { - dstFormat = av_get_pix_fmt(argv[i + 1]); - if (dstFormat == AV_PIX_FMT_NONE) { - fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); - return -1; - } - } else { -bad_option: - fprintf(stderr, "bad option or argument missing (%s)\n", argv[i]); - goto error; - } - } - - selfTest(src, stride, W, H, srcFormat, dstFormat); -end: - res = 0; -error: - av_free(data); - - return res; -} diff --git a/libswscale/tests/.gitignore b/libswscale/tests/.gitignore new file mode 100644 index 0000000000..0ac3691ecd --- /dev/null +++ b/libswscale/tests/.gitignore @@ -0,0 +1,2 @@ +/colorspace +/swscale diff --git a/libswscale/tests/colorspace.c b/libswscale/tests/colorspace.c new file mode 100644 index 0000000000..962b11a857 --- /dev/null +++ b/libswscale/tests/colorspace.c @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2002 Michael Niedermayer + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include /* for memset() */ +#include +#include + +#include "libavutil/mem.h" + +#include "libswscale/rgb2rgb.h" +#include "libswscale/swscale.h" + +#define SIZE 1000 +#define srcByte 0x55 +#define dstByte 0xBB + +#define FUNC(s, d, n) { s, d, #n, n } + +int main(void) +{ + int i, funcNum; + uint8_t *srcBuffer = av_malloc(SIZE); + uint8_t *dstBuffer = av_malloc(SIZE); + int failedNum = 0; + int passedNum = 0; + + if (!srcBuffer || !dstBuffer) + return -1; + + av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); + sws_rgb2rgb_init(); + + for (funcNum = 0; ; funcNum++) { + struct func_info_s { + int src_bpp; + int dst_bpp; + const char *name; + void (*func)(const uint8_t *src, uint8_t *dst, int src_size); + } func_info[] = { + FUNC(2, 2, rgb15to16), + FUNC(2, 3, rgb15to24), + FUNC(2, 4, rgb15to32), + FUNC(2, 3, rgb16to24), + FUNC(2, 4, rgb16to32), + FUNC(3, 2, rgb24to15), + FUNC(3, 2, rgb24to16), + FUNC(3, 4, rgb24to32), + FUNC(4, 2, rgb32to15), + FUNC(4, 2, rgb32to16), + FUNC(4, 3, rgb32to24), + FUNC(2, 2, rgb16to15), + FUNC(2, 2, rgb15tobgr15), + FUNC(2, 2, rgb15tobgr16), + FUNC(2, 3, rgb15tobgr24), + FUNC(2, 4, rgb15tobgr32), + FUNC(2, 2, rgb16tobgr15), + FUNC(2, 2, rgb16tobgr16), + FUNC(2, 3, rgb16tobgr24), + FUNC(2, 4, rgb16tobgr32), + FUNC(3, 2, rgb24tobgr15), + FUNC(3, 2, rgb24tobgr16), + FUNC(3, 3, rgb24tobgr24), + FUNC(3, 4, rgb24tobgr32), + FUNC(4, 2, rgb32tobgr15), + FUNC(4, 2, rgb32tobgr16), + FUNC(4, 3, rgb32tobgr24), + FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */ + FUNC(0, 0, NULL) + }; + int width; + int failed = 0; + int srcBpp = 0; + int dstBpp = 0; + + if (!func_info[funcNum].func) + break; + + av_log(NULL, AV_LOG_INFO, "."); + memset(srcBuffer, srcByte, SIZE); + + for (width = 63; width > 0; width--) { + int dstOffset; + for (dstOffset = 128; dstOffset < 196; dstOffset += 4) { + int srcOffset; + memset(dstBuffer, dstByte, SIZE); + + for (srcOffset = 128; srcOffset < 196; srcOffset += 4) { + uint8_t *src = srcBuffer + srcOffset; + uint8_t *dst = dstBuffer + dstOffset; + const char *name = NULL; + + // don't fill the screen with shit ... + if (failed) + break; + + srcBpp = func_info[funcNum].src_bpp; + dstBpp = func_info[funcNum].dst_bpp; + name = func_info[funcNum].name; + + func_info[funcNum].func(src, dst, width * srcBpp); + + if (!srcBpp) + break; + + for (i = 0; i < SIZE; i++) { + if (srcBuffer[i] != srcByte) { + av_log(NULL, AV_LOG_INFO, + "src damaged at %d w:%d src:%d dst:%d %s\n", + i, width, srcOffset, dstOffset, name); + failed = 1; + break; + } + } + for (i = 0; i < dstOffset; i++) { + if (dstBuffer[i] != dstByte) { + av_log(NULL, AV_LOG_INFO, + "dst damaged at %d w:%d src:%d dst:%d %s\n", + i, width, srcOffset, dstOffset, name); + failed = 1; + break; + } + } + for (i = dstOffset + width * dstBpp; i < SIZE; i++) { + if (dstBuffer[i] != dstByte) { + av_log(NULL, AV_LOG_INFO, + "dst damaged at %d w:%d src:%d dst:%d %s\n", + i, width, srcOffset, dstOffset, name); + failed = 1; + break; + } + } + } + } + } + if (failed) + failedNum++; + else if (srcBpp) + passedNum++; + } + + av_log(NULL, AV_LOG_INFO, + "\n%d converters passed, %d converters randomly overwrote memory\n", + passedNum, failedNum); + return failedNum; +} diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c new file mode 100644 index 0000000000..309ef812c7 --- /dev/null +++ b/libswscale/tests/swscale.c @@ -0,0 +1,412 @@ +/* + * Copyright (C) 2003 Michael Niedermayer + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include + +#undef HAVE_AV_CONFIG_H +#include "libavutil/imgutils.h" +#include "libavutil/mem.h" +#include "libavutil/avutil.h" +#include "libavutil/crc.h" +#include "libavutil/pixdesc.h" +#include "libavutil/lfg.h" + +#include "libswscale/swscale.h" + +/* HACK Duplicated from swscale_internal.h. + * Should be removed when a cleaner pixel format system exists. */ +#define isGray(x) \ + ((x) == AV_PIX_FMT_GRAY8 || \ + (x) == AV_PIX_FMT_YA8 || \ + (x) == AV_PIX_FMT_GRAY16BE || \ + (x) == AV_PIX_FMT_GRAY16LE || \ + (x) == AV_PIX_FMT_YA16BE || \ + (x) == AV_PIX_FMT_YA16LE) +#define hasChroma(x) \ + (!(isGray(x) || \ + (x) == AV_PIX_FMT_MONOBLACK || \ + (x) == AV_PIX_FMT_MONOWHITE)) +#define isALPHA(x) \ + ((x) == AV_PIX_FMT_BGR32 || \ + (x) == AV_PIX_FMT_BGR32_1 || \ + (x) == AV_PIX_FMT_RGB32 || \ + (x) == AV_PIX_FMT_RGB32_1 || \ + (x) == AV_PIX_FMT_YUVA420P) + +static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, + int stride2, int w, int h) +{ + int x, y; + uint64_t ssd = 0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + int d = src1[x + y * stride1] - src2[x + y * stride2]; + ssd += d * d; + } + } + return ssd; +} + +struct Results { + uint64_t ssdY; + uint64_t ssdU; + uint64_t ssdV; + uint64_t ssdA; + uint32_t crc; +}; + +// test by ref -> src -> dst -> out & compare out against ref +// ref & out are YV12 +static int doTest(uint8_t *ref[4], int refStride[4], int w, int h, + enum AVPixelFormat srcFormat, enum AVPixelFormat dstFormat, + int srcW, int srcH, int dstW, int dstH, int flags, + struct Results *r) +{ + const AVPixFmtDescriptor *desc_yuva420p = av_pix_fmt_desc_get(AV_PIX_FMT_YUVA420P); + const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat); + const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat); + static enum AVPixelFormat cur_srcFormat; + static int cur_srcW, cur_srcH; + static uint8_t *src[4]; + static int srcStride[4]; + uint8_t *dst[4] = { 0 }; + uint8_t *out[4] = { 0 }; + int dstStride[4]; + int i; + uint64_t ssdY, ssdU = 0, ssdV = 0, ssdA = 0; + struct SwsContext *dstContext = NULL, *outContext = NULL; + uint32_t crc = 0; + int res = 0; + + if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) { + struct SwsContext *srcContext = NULL; + int p; + + for (p = 0; p < 4; p++) + av_freep(&src[p]); + + av_image_fill_linesizes(srcStride, srcFormat, srcW); + for (p = 0; p < 4; p++) { + if (srcStride[p]) + src[p] = av_mallocz(srcStride[p] * srcH + 16); + if (srcStride[p] && !src[p]) { + perror("Malloc"); + res = -1; + goto end; + } + } + srcContext = sws_getContext(w, h, AV_PIX_FMT_YUVA420P, srcW, srcH, + srcFormat, SWS_BILINEAR, NULL, NULL, NULL); + if (!srcContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + desc_yuva420p->name, + desc_src->name); + res = -1; + goto end; + } + sws_scale(srcContext, ref, refStride, 0, h, src, srcStride); + sws_freeContext(srcContext); + + cur_srcFormat = srcFormat; + cur_srcW = srcW; + cur_srcH = srcH; + } + + av_image_fill_linesizes(dstStride, dstFormat, dstW); + for (i = 0; i < 4; i++) { + /* Image buffers passed into libswscale can be allocated any way you + * prefer, as long as they're aligned enough for the architecture, and + * they're freed appropriately (such as using av_free for buffers + * allocated with av_malloc). */ + /* An extra 16 bytes is being allocated because some scalers may write + * out of bounds. */ + if (dstStride[i]) + dst[i] = av_mallocz(dstStride[i] * dstH + 16); + if (dstStride[i] && !dst[i]) { + perror("Malloc"); + res = -1; + + goto end; + } + } + + dstContext = sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, + flags, NULL, NULL, NULL); + if (!dstContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + desc_src->name, desc_dst->name); + res = -1; + goto end; + } + + printf(" %s %dx%d -> %s %3dx%3d flags=%2d", + desc_src->name, srcW, srcH, + desc_dst->name, dstW, dstH, + flags); + fflush(stdout); + + sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); + + for (i = 0; i < 4 && dstStride[i]; i++) + crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], + dstStride[i] * dstH); + + if (r && crc == r->crc) { + ssdY = r->ssdY; + ssdU = r->ssdU; + ssdV = r->ssdV; + ssdA = r->ssdA; + } else { + for (i = 0; i < 4; i++) { + if (refStride[i]) + out[i] = av_mallocz(refStride[i] * h); + if (refStride[i] && !out[i]) { + perror("Malloc"); + res = -1; + goto end; + } + } + outContext = sws_getContext(dstW, dstH, dstFormat, w, h, + AV_PIX_FMT_YUVA420P, SWS_BILINEAR, + NULL, NULL, NULL); + if (!outContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + desc_dst->name, + desc_yuva420p->name); + res = -1; + goto end; + } + sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); + + ssdY = getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); + if (hasChroma(srcFormat) && hasChroma(dstFormat)) { + //FIXME check that output is really gray + ssdU = getSSD(ref[1], out[1], refStride[1], refStride[1], + (w + 1) >> 1, (h + 1) >> 1); + ssdV = getSSD(ref[2], out[2], refStride[2], refStride[2], + (w + 1) >> 1, (h + 1) >> 1); + } + if (isALPHA(srcFormat) && isALPHA(dstFormat)) + ssdA = getSSD(ref[3], out[3], refStride[3], refStride[3], w, h); + + ssdY /= w * h; + ssdU /= w * h / 4; + ssdV /= w * h / 4; + ssdA /= w * h; + + sws_freeContext(outContext); + + for (i = 0; i < 4; i++) + if (refStride[i]) + av_free(out[i]); + } + + printf(" CRC=%08x SSD=%5"PRId64 ",%5"PRId64 ",%5"PRId64 ",%5"PRId64 "\n", + crc, ssdY, ssdU, ssdV, ssdA); + +end: + sws_freeContext(dstContext); + + for (i = 0; i < 4; i++) + if (dstStride[i]) + av_free(dst[i]); + + return res; +} + +static void selfTest(uint8_t *ref[4], int refStride[4], int w, int h, + enum AVPixelFormat srcFormat_in, + enum AVPixelFormat dstFormat_in) +{ + const int flags[] = { SWS_FAST_BILINEAR, SWS_BILINEAR, SWS_BICUBIC, + SWS_X, SWS_POINT, SWS_AREA, 0 }; + const int srcW = w; + const int srcH = h; + const int dstW[] = { srcW - srcW / 3, srcW, srcW + srcW / 3, 0 }; + const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 }; + enum AVPixelFormat srcFormat, dstFormat; + const AVPixFmtDescriptor *desc_src, *desc_dst; + + for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0; + srcFormat < AV_PIX_FMT_NB; srcFormat++) { + if (!sws_isSupportedInput(srcFormat) || + !sws_isSupportedOutput(srcFormat)) + continue; + + desc_src = av_pix_fmt_desc_get(srcFormat); + + for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0; + dstFormat < AV_PIX_FMT_NB; dstFormat++) { + int i, j, k; + int res = 0; + + if (!sws_isSupportedInput(dstFormat) || + !sws_isSupportedOutput(dstFormat)) + continue; + + desc_dst = av_pix_fmt_desc_get(dstFormat); + + printf("%s -> %s\n", desc_src->name, desc_dst->name); + fflush(stdout); + + for (k = 0; flags[k] && !res; k++) + for (i = 0; dstW[i] && !res; i++) + for (j = 0; dstH[j] && !res; j++) + res = doTest(ref, refStride, w, h, + srcFormat, dstFormat, + srcW, srcH, dstW[i], dstH[j], flags[k], + NULL); + if (dstFormat_in != AV_PIX_FMT_NONE) + break; + } + if (srcFormat_in != AV_PIX_FMT_NONE) + break; + } +} + +static int fileTest(uint8_t *ref[4], int refStride[4], int w, int h, FILE *fp, + enum AVPixelFormat srcFormat_in, + enum AVPixelFormat dstFormat_in) +{ + char buf[256]; + + while (fgets(buf, sizeof(buf), fp)) { + struct Results r; + enum AVPixelFormat srcFormat; + char srcStr[12]; + int srcW, srcH; + enum AVPixelFormat dstFormat; + char dstStr[12]; + int dstW, dstH; + int flags; + int ret; + + ret = sscanf(buf, + " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x" + " SSD=%"PRId64 ", %"PRId64 ", %"PRId64 ", %"PRId64 "\n", + srcStr, &srcW, &srcH, dstStr, &dstW, &dstH, + &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA); + if (ret != 12) { + srcStr[0] = dstStr[0] = 0; + ret = sscanf(buf, "%12s -> %12s\n", srcStr, dstStr); + } + + srcFormat = av_get_pix_fmt(srcStr); + dstFormat = av_get_pix_fmt(dstStr); + + if (srcFormat == AV_PIX_FMT_NONE || dstFormat == AV_PIX_FMT_NONE) { + fprintf(stderr, "malformed input file\n"); + return -1; + } + if ((srcFormat_in != AV_PIX_FMT_NONE && srcFormat_in != srcFormat) || + (dstFormat_in != AV_PIX_FMT_NONE && dstFormat_in != dstFormat)) + continue; + if (ret != 12) { + printf("%s", buf); + continue; + } + + doTest(ref, refStride, w, h, + srcFormat, dstFormat, + srcW, srcH, dstW, dstH, flags, + &r); + } + + return 0; +} + +#define W 96 +#define H 96 + +int main(int argc, char **argv) +{ + enum AVPixelFormat srcFormat = AV_PIX_FMT_NONE; + enum AVPixelFormat dstFormat = AV_PIX_FMT_NONE; + uint8_t *rgb_data = av_malloc(W * H * 4); + uint8_t *rgb_src[4] = { rgb_data, NULL, NULL, NULL }; + int rgb_stride[4] = { 4 * W, 0, 0, 0 }; + uint8_t *data = av_malloc(4 * W * H); + uint8_t *src[4] = { data, data + W * H, data + W * H * 2, data + W * H * 3 }; + int stride[4] = { W, W, W, W }; + int x, y; + struct SwsContext *sws; + AVLFG rand; + int res = -1; + int i; + + if (!rgb_data || !data) + return -1; + + sws = sws_getContext(W / 12, H / 12, AV_PIX_FMT_RGB32, W, H, + AV_PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); + + av_lfg_init(&rand, 1); + + for (y = 0; y < H; y++) + for (x = 0; x < W * 4; x++) + rgb_data[ x + y * 4 * W] = av_lfg_get(&rand); + sws_scale(sws, rgb_src, rgb_stride, 0, H, src, stride); + sws_freeContext(sws); + av_free(rgb_data); + + for (i = 1; i < argc; i += 2) { + if (argv[i][0] != '-' || i + 1 == argc) + goto bad_option; + if (!strcmp(argv[i], "-ref")) { + FILE *fp = fopen(argv[i + 1], "r"); + if (!fp) { + fprintf(stderr, "could not open '%s'\n", argv[i + 1]); + goto error; + } + res = fileTest(src, stride, W, H, fp, srcFormat, dstFormat); + fclose(fp); + goto end; + } else if (!strcmp(argv[i], "-src")) { + srcFormat = av_get_pix_fmt(argv[i + 1]); + if (srcFormat == AV_PIX_FMT_NONE) { + fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); + return -1; + } + } else if (!strcmp(argv[i], "-dst")) { + dstFormat = av_get_pix_fmt(argv[i + 1]); + if (dstFormat == AV_PIX_FMT_NONE) { + fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); + return -1; + } + } else { +bad_option: + fprintf(stderr, "bad option or argument missing (%s)\n", argv[i]); + goto error; + } + } + + selfTest(src, stride, W, H, srcFormat, dstFormat); +end: + res = 0; +error: + av_free(data); + + return res; +} diff --git a/tests/fate-run.sh b/tests/fate-run.sh index 9edfa9aeb6..d11ca3c1f7 100755 --- a/tests/fate-run.sh +++ b/tests/fate-run.sh @@ -167,7 +167,7 @@ pixfmts(){ filter=${test#filter-pixfmts-} filter_args=$1 - showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test" + showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts" exclude_fmts=${outfile}${filter}_exclude_fmts out_fmts=${outfile}${filter}_out_fmts diff --git a/tests/fate/fft.mak b/tests/fate/fft.mak index 6349e5ac75..3360a07e66 100644 --- a/tests/fate/fft.mak +++ b/tests/fate/fft.mak @@ -23,8 +23,8 @@ fate-rdft-float: $(FATE_RDFT-yes) FATE_FFT_ALL = $(FATE_DCT-yes) $(FATE_FFT-yes) $(FATE_MDCT-yes) $(FATE_RDFT-yes) -$(FATE_FFT_ALL): libavcodec/fft-test$(EXESUF) -$(FATE_FFT_ALL): CMD = run libavcodec/fft-test $(CPUFLAGS:%=-c%) $(ARGS) +$(FATE_FFT_ALL): libavcodec/tests/fft$(EXESUF) +$(FATE_FFT_ALL): CMD = run libavcodec/tests/fft $(CPUFLAGS:%=-c%) $(ARGS) define DEF_FFT_FIXED FATE_FFT_FIXED-$(CONFIG_FFT) += fate-fft-fixed-$(1) fate-ifft-fixed-$(1) @@ -43,8 +43,8 @@ fate-mdct-fixed: $(FATE_MDCT_FIXED-yes) FATE_FFT_FIXED_ALL = $(FATE_FFT_FIXED-yes) $(FATE_MDCT_FIXED-yes) -$(FATE_FFT_FIXED_ALL): libavcodec/fft-fixed-test$(EXESUF) -$(FATE_FFT_FIXED_ALL): CMD = run libavcodec/fft-fixed-test $(CPUFLAGS:%=-c%) $(ARGS) +$(FATE_FFT_FIXED_ALL): libavcodec/tests/fft-fixed$(EXESUF) +$(FATE_FFT_FIXED_ALL): CMD = run libavcodec/tests/fft-fixed $(CPUFLAGS:%=-c%) $(ARGS) $(FATE_FFT_ALL) $(FATE_FFT_FIXED_ALL): REF = /dev/null diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 42fb063547..d9315480e4 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -160,7 +160,7 @@ fate-filter-pixfmts-scale: CMD = pixfmts "200:100" FATE_FILTER_PIXFMTS += fate-filter-pixfmts-vflip fate-filter-pixfmts-vflip: CMD = pixfmts -$(FATE_FILTER_PIXFMTS): libavfilter/filtfmts-test$(EXESUF) +$(FATE_FILTER_PIXFMTS): libavfilter/tests/filtfmts$(EXESUF) FATE_FILTER_VSYNTH-$(CONFIG_FORMAT_FILTER) += $(FATE_FILTER_PIXFMTS) diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index 138a1b2dcf..d656acefb7 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -1,21 +1,21 @@ FATE_LIBAVCODEC-$(CONFIG_GOLOMB) += fate-golomb -fate-golomb: libavcodec/golomb-test$(EXESUF) -fate-golomb: CMD = run libavcodec/golomb-test +fate-golomb: libavcodec/tests/golomb$(EXESUF) +fate-golomb: CMD = run libavcodec/tests/golomb fate-golomb: REF = /dev/null FATE_LIBAVCODEC-$(CONFIG_IDCTDSP) += fate-idct8x8 -fate-idct8x8: libavcodec/dct-test$(EXESUF) -fate-idct8x8: CMD = run libavcodec/dct-test -i +fate-idct8x8: libavcodec/tests/dct$(EXESUF) +fate-idct8x8: CMD = run libavcodec/tests/dct -i fate-idct8x8: CMP = null fate-idct8x8: REF = /dev/null FATE_LIBAVCODEC-$(CONFIG_IIRFILTER) += fate-iirfilter -fate-iirfilter: libavcodec/iirfilter-test$(EXESUF) -fate-iirfilter: CMD = run libavcodec/iirfilter-test +fate-iirfilter: libavcodec/tests/iirfilter$(EXESUF) +fate-iirfilter: CMD = run libavcodec/tests/iirfilter FATE_LIBAVCODEC-$(CONFIG_RANGECODER) += fate-rangecoder -fate-rangecoder: libavcodec/rangecoder-test$(EXESUF) -fate-rangecoder: CMD = run libavcodec/rangecoder-test +fate-rangecoder: libavcodec/tests/rangecoder$(EXESUF) +fate-rangecoder: CMD = run libavcodec/tests/rangecoder fate-rangecoder: CMP = null fate-rangecoder: REF = /dev/null diff --git a/tests/fate/libavdevice.mak b/tests/fate/libavdevice.mak index b30ae99779..e983327a50 100644 --- a/tests/fate/libavdevice.mak +++ b/tests/fate/libavdevice.mak @@ -1,6 +1,6 @@ FATE_LIBAVDEVICE-$(CONFIG_JACK_INDEV) += fate-timefilter -fate-timefilter: libavdevice/timefilter-test$(EXESUF) -fate-timefilter: CMD = run libavdevice/timefilter-test +fate-timefilter: libavdevice/tests/timefilter$(EXESUF) +fate-timefilter: CMD = run libavdevice/tests/timefilter FATE-$(CONFIG_AVDEVICE) += $(FATE_LIBAVDEVICE-yes) fate-libavdevice: $(FATE_LIBAVDEVICE-yes) diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak index e98e0eee1e..30f0e03cb8 100644 --- a/tests/fate/libavformat.mak +++ b/tests/fate/libavformat.mak @@ -1,22 +1,22 @@ FATE_LIBAVFORMAT-$(CONFIG_NETWORK) += fate-noproxy -fate-noproxy: libavformat/noproxy-test$(EXESUF) -fate-noproxy: CMD = run libavformat/noproxy-test +fate-noproxy: libavformat/tests/noproxy$(EXESUF) +fate-noproxy: CMD = run libavformat/tests/noproxy FATE_LIBAVFORMAT-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += fate-rtmpdh -fate-rtmpdh: libavformat/rtmpdh-test$(EXESUF) -fate-rtmpdh: CMD = run libavformat/rtmpdh-test +fate-rtmpdh: libavformat/tests/rtmpdh$(EXESUF) +fate-rtmpdh: CMD = run libavformat/tests/rtmpdh FATE_LIBAVFORMAT-$(CONFIG_SRTP) += fate-srtp -fate-srtp: libavformat/srtp-test$(EXESUF) -fate-srtp: CMD = run libavformat/srtp-test +fate-srtp: libavformat/tests/srtp$(EXESUF) +fate-srtp: CMD = run libavformat/tests/srtp FATE_LIBAVFORMAT-yes += fate-url -fate-url: libavformat/url-test$(EXESUF) -fate-url: CMD = run libavformat/url-test +fate-url: libavformat/tests/url$(EXESUF) +fate-url: CMD = run libavformat/tests/url FATE_LIBAVFORMAT-$(CONFIG_MOV_MUXER) += fate-movenc -fate-movenc: libavformat/movenc-test$(EXESUF) -fate-movenc: CMD = run libavformat/movenc-test +fate-movenc: libavformat/tests/movenc$(EXESUF) +fate-movenc: CMD = run libavformat/tests/movenc FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT-yes) fate-libavformat: $(FATE_LIBAVFORMAT) diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 7f3329b1d5..69e4042a8b 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -1,82 +1,82 @@ FATE_LIBAVUTIL += fate-adler32 -fate-adler32: libavutil/adler32-test$(EXESUF) -fate-adler32: CMD = run libavutil/adler32-test +fate-adler32: libavutil/tests/adler32$(EXESUF) +fate-adler32: CMD = run libavutil/tests/adler32 fate-adler32: REF = /dev/null FATE_LIBAVUTIL += fate-aes -fate-aes: libavutil/aes-test$(EXESUF) -fate-aes: CMD = run libavutil/aes-test +fate-aes: libavutil/tests/aes$(EXESUF) +fate-aes: CMD = run libavutil/tests/aes fate-aes: REF = /dev/null FATE_LIBAVUTIL += fate-atomic -fate-atomic: libavutil/atomic-test$(EXESUF) -fate-atomic: CMD = run libavutil/atomic-test +fate-atomic: libavutil/tests/atomic$(EXESUF) +fate-atomic: CMD = run libavutil/tests/atomic fate-atomic: REF = /dev/null FATE_LIBAVUTIL += fate-avstring -fate-avstring: libavutil/avstring-test$(EXESUF) -fate-avstring: CMD = run libavutil/avstring-test +fate-avstring: libavutil/tests/avstring$(EXESUF) +fate-avstring: CMD = run libavutil/tests/avstring FATE_LIBAVUTIL += fate-base64 -fate-base64: libavutil/base64-test$(EXESUF) -fate-base64: CMD = run libavutil/base64-test +fate-base64: libavutil/tests/base64$(EXESUF) +fate-base64: CMD = run libavutil/tests/base64 FATE_LIBAVUTIL += fate-blowfish -fate-blowfish: libavutil/blowfish-test$(EXESUF) -fate-blowfish: CMD = run libavutil/blowfish-test +fate-blowfish: libavutil/tests/blowfish$(EXESUF) +fate-blowfish: CMD = run libavutil/tests/blowfish FATE_LIBAVUTIL += fate-cpu -fate-cpu: libavutil/cpu-test$(EXESUF) -fate-cpu: CMD = run libavutil/cpu-test $(CPUFLAGS:%=-c%) $(THREADS:%=-t%) +fate-cpu: libavutil/tests/cpu$(EXESUF) +fate-cpu: CMD = run libavutil/tests/cpu $(CPUFLAGS:%=-c%) $(THREADS:%=-t%) fate-cpu: REF = /dev/null FATE_LIBAVUTIL += fate-crc -fate-crc: libavutil/crc-test$(EXESUF) -fate-crc: CMD = run libavutil/crc-test +fate-crc: libavutil/tests/crc$(EXESUF) +fate-crc: CMD = run libavutil/tests/crc FATE_LIBAVUTIL += fate-des -fate-des: libavutil/des-test$(EXESUF) -fate-des: CMD = run libavutil/des-test +fate-des: libavutil/tests/des$(EXESUF) +fate-des: CMD = run libavutil/tests/des fate-des: REF = /dev/null FATE_LIBAVUTIL += fate-eval -fate-eval: libavutil/eval-test$(EXESUF) -fate-eval: CMD = run libavutil/eval-test +fate-eval: libavutil/tests/eval$(EXESUF) +fate-eval: CMD = run libavutil/tests/eval FATE_LIBAVUTIL += fate-fifo -fate-fifo: libavutil/fifo-test$(EXESUF) -fate-fifo: CMD = run libavutil/fifo-test +fate-fifo: libavutil/tests/fifo$(EXESUF) +fate-fifo: CMD = run libavutil/tests/fifo FATE_LIBAVUTIL += fate-float-dsp -fate-float-dsp: libavutil/float_dsp-test$(EXESUF) -fate-float-dsp: CMD = run libavutil/float_dsp-test +fate-float-dsp: libavutil/tests/float_dsp$(EXESUF) +fate-float-dsp: CMD = run libavutil/tests/float_dsp fate-float-dsp: CMP = null fate-float-dsp: REF = /dev/null FATE_LIBAVUTIL += fate-hmac -fate-hmac: libavutil/hmac-test$(EXESUF) -fate-hmac: CMD = run libavutil/hmac-test +fate-hmac: libavutil/tests/hmac$(EXESUF) +fate-hmac: CMD = run libavutil/tests/hmac FATE_LIBAVUTIL += fate-md5 -fate-md5: libavutil/md5-test$(EXESUF) -fate-md5: CMD = run libavutil/md5-test +fate-md5: libavutil/tests/md5$(EXESUF) +fate-md5: CMD = run libavutil/tests/md5 FATE_LIBAVUTIL += fate-parseutils -fate-parseutils: libavutil/parseutils-test$(EXESUF) -fate-parseutils: CMD = run libavutil/parseutils-test +fate-parseutils: libavutil/tests/parseutils$(EXESUF) +fate-parseutils: CMD = run libavutil/tests/parseutils FATE_LIBAVUTIL += fate-sha -fate-sha: libavutil/sha-test$(EXESUF) -fate-sha: CMD = run libavutil/sha-test +fate-sha: libavutil/tests/sha$(EXESUF) +fate-sha: CMD = run libavutil/tests/sha FATE_LIBAVUTIL += fate-tree -fate-tree: libavutil/tree-test$(EXESUF) -fate-tree: CMD = run libavutil/tree-test +fate-tree: libavutil/tests/tree$(EXESUF) +fate-tree: CMD = run libavutil/tests/tree fate-tree: REF = /dev/null FATE_LIBAVUTIL += fate-xtea -fate-xtea: libavutil/xtea-test$(EXESUF) -fate-xtea: CMD = run libavutil/xtea-test +fate-xtea: libavutil/tests/xtea$(EXESUF) +fate-xtea: CMD = run libavutil/tests/xtea FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL) fate-libavutil: $(FATE_LIBAVUTIL) diff --git a/tests/fate/seek.mak b/tests/fate/seek.mak index 88555f7e55..60adab2085 100644 --- a/tests/fate/seek.mak +++ b/tests/fate/seek.mak @@ -218,8 +218,8 @@ fate-seek-lavf-yuv4mpeg: SRC = lavf/lavf.y4m FATE_SEEK += $(FATE_SEEK_LAVF-yes:%=fate-seek-lavf-%) -$(FATE_SEEK): libavformat/seek-test$(EXESUF) -$(FATE_SEEK): CMD = run libavformat/seek-test$(EXESUF) $(TARGET_PATH)/tests/data/$(SRC) +$(FATE_SEEK): libavformat/tests/seek$(EXESUF) +$(FATE_SEEK): CMD = run libavformat/tests/seek$(EXESUF) $(TARGET_PATH)/tests/data/$(SRC) $(FATE_SEEK): fate-seek-%: fate-% fate-seek-%: REF = $(SRC_PATH)/tests/ref/seek/$(@:fate-seek-%=%) -- cgit v1.2.3