aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-05-11 19:10:10 +0100
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-05-11 19:13:03 +0100
commit96d616052b3d39678e477fa10610ca688f46fff9 (patch)
tree8bd31d06318bc786ea8f1d84f92090c9c860bc11 /libavcodec
parent27506aceda8115f82f89691a4441d62a8cf24a6e (diff)
parentd12b5b2f135aade4099f4b26b0fe678656158c13 (diff)
downloadffmpeg-96d616052b3d39678e477fa10610ca688f46fff9.tar.gz
Merge commit 'd12b5b2f135aade4099f4b26b0fe678656158c13'
* commit 'd12b5b2f135aade4099f4b26b0fe678656158c13': build: Split test programs off into separate files Some conversions done by: James Almer <jamrial@gmail.com> Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile2
-rw-r--r--libavcodec/avfft-test.c52
-rw-r--r--libavcodec/avfft.c34
-rw-r--r--libavcodec/cabac-test.c165
-rw-r--r--libavcodec/cabac.c147
-rw-r--r--libavcodec/iirfilter-test.c52
-rw-r--r--libavcodec/iirfilter.c32
-rw-r--r--libavcodec/imgconvert-test.c50
-rw-r--r--libavcodec/imgconvert.c28
-rw-r--r--libavcodec/jpeg2000dwt-test.c141
-rw-r--r--libavcodec/jpeg2000dwt.c122
-rw-r--r--libavcodec/mathops-test.c41
-rw-r--r--libavcodec/mathops.c26
-rw-r--r--libavcodec/options-test.c189
-rw-r--r--libavcodec/rangecoder-test.c64
-rw-r--r--libavcodec/rangecoder.c45
-rw-r--r--libavcodec/snowenc-test.c147
-rw-r--r--libavcodec/snowenc.c129
-rw-r--r--libavcodec/utils-test.c37
-rw-r--r--libavcodec/utils.c20
20 files changed, 939 insertions, 584 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8c9c23ab8b..98e9a073ef 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -996,9 +996,9 @@ TESTPROGS = imgconvert \
mathops \
options \
utils \
- avfft \
TESTPROGS-$(CONFIG_CABAC) += cabac
+TESTPROGS-$(CONFIG_DCT) += avfft
TESTPROGS-$(CONFIG_FFT) += fft fft-fixed fft-fixed32
TESTPROGS-$(CONFIG_GOLOMB) += golomb
TESTPROGS-$(CONFIG_IDCTDSP) += dct
diff --git a/libavcodec/avfft-test.c b/libavcodec/avfft-test.c
new file mode 100644
index 0000000000..83949f4fb5
--- /dev/null
+++ b/libavcodec/avfft-test.c
@@ -0,0 +1,52 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "avfft.h"
+
+int main(int argc, char **argv)
+{
+ int i;
+#define LEN 1024
+ FFTSample *ref = av_malloc_array(LEN, sizeof(*ref));
+ FFTSample *data = av_malloc_array(LEN, sizeof(*data));
+ RDFTContext *rdft_context = av_rdft_init(10, DFT_R2C);
+ RDFTContext *irdft_context = av_rdft_init(10, IDFT_C2R);
+
+ if (!ref || !data || !rdft_context || !irdft_context)
+ return 2;
+ for (i=0; i<LEN; i++) {
+ ref[i] = data[i] = i*456 + 123 + i*i;
+ }
+ av_rdft_calc(rdft_context, data);
+ av_rdft_calc(irdft_context, data);
+
+ for (i=0; i<LEN; i++) {
+ if (fabs(ref[i] - data[i]/LEN*2) > 1) {
+ fprintf(stderr, "Failed at %d (%f %f)\n", i, ref[i], data[i]/LEN*2);
+ return 1;
+ }
+ }
+
+ av_rdft_end(rdft_context);
+ av_rdft_end(irdft_context);
+ av_free(data);
+ av_free(ref);
+
+ return 0;
+}
diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index 675d2b906b..2200f37708 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -142,38 +142,4 @@ av_cold void av_dct_end(DCTContext *s)
}
}
-#ifdef TEST
-int main(int argc, char **argv)
-{
- int i;
-#define LEN 1024
- FFTSample *ref = av_malloc_array(LEN, sizeof(*ref));
- FFTSample *data = av_malloc_array(LEN, sizeof(*data));
- RDFTContext *rdft_context = av_rdft_init(10, DFT_R2C);
- RDFTContext *irdft_context = av_rdft_init(10, IDFT_C2R);
-
- if (!ref || !data || !rdft_context || !irdft_context)
- return 2;
- for (i=0; i<LEN; i++) {
- ref[i] = data[i] = i*456 + 123 + i*i;
- }
- av_rdft_calc(rdft_context, data);
- av_rdft_calc(irdft_context, data);
-
- for (i=0; i<LEN; i++) {
- if (fabs(ref[i] - data[i]/LEN*2) > 1) {
- fprintf(stderr, "Failed at %d (%f %f)\n", i, ref[i], data[i]/LEN*2);
- return 1;
- }
- }
-
- av_rdft_end(rdft_context);
- av_rdft_end(irdft_context);
- av_free(data);
- av_free(ref);
-
- return 0;
-}
-#endif
-
#endif /* CONFIG_DCT */
diff --git a/libavcodec/cabac-test.c b/libavcodec/cabac-test.c
new file mode 100644
index 0000000000..47f31e997c
--- /dev/null
+++ b/libavcodec/cabac-test.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cabac.c"
+
+#define SIZE 10240
+
+#include "libavutil/lfg.h"
+#include "avcodec.h"
+
+static inline void put_cabac_bit(CABACContext *c, int b){
+ put_bits(&c->pb, 1, b);
+ for(;c->outstanding_count; c->outstanding_count--){
+ put_bits(&c->pb, 1, 1-b);
+ }
+}
+
+static inline void renorm_cabac_encoder(CABACContext *c){
+ while(c->range < 0x100){
+ //FIXME optimize
+ if(c->low<0x100){
+ put_cabac_bit(c, 0);
+ }else if(c->low<0x200){
+ c->outstanding_count++;
+ c->low -= 0x100;
+ }else{
+ put_cabac_bit(c, 1);
+ c->low -= 0x200;
+ }
+
+ c->range+= c->range;
+ c->low += c->low;
+ }
+}
+
+static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
+ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
+
+ if(bit == ((*state)&1)){
+ c->range -= RangeLPS;
+ *state = ff_h264_mlps_state[128 + *state];
+ }else{
+ c->low += c->range - RangeLPS;
+ c->range = RangeLPS;
+ *state= ff_h264_mlps_state[127 - *state];
+ }
+
+ renorm_cabac_encoder(c);
+}
+
+/**
+ * @param bit 0 -> write zero bit, !=0 write one bit
+ */
+static void put_cabac_bypass(CABACContext *c, int bit){
+ c->low += c->low;
+
+ if(bit){
+ c->low += c->range;
+ }
+//FIXME optimize
+ if(c->low<0x200){
+ put_cabac_bit(c, 0);
+ }else if(c->low<0x400){
+ c->outstanding_count++;
+ c->low -= 0x200;
+ }else{
+ put_cabac_bit(c, 1);
+ c->low -= 0x400;
+ }
+}
+
+/**
+ *
+ * @return the number of bytes written
+ */
+static int put_cabac_terminate(CABACContext *c, int bit){
+ c->range -= 2;
+
+ if(!bit){
+ renorm_cabac_encoder(c);
+ }else{
+ c->low += c->range;
+ c->range= 2;
+
+ renorm_cabac_encoder(c);
+
+ av_assert0(c->low <= 0x1FF);
+ put_cabac_bit(c, c->low>>9);
+ put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
+
+ flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
+ }
+
+ return (put_bits_count(&c->pb)+7)>>3;
+}
+
+int main(void){
+ CABACContext c;
+ uint8_t b[9*SIZE];
+ uint8_t r[9*SIZE];
+ int i, ret = 0;
+ uint8_t state[10]= {0};
+ AVLFG prng;
+
+ av_lfg_init(&prng, 1);
+ ff_init_cabac_encoder(&c, b, SIZE);
+
+ for(i=0; i<SIZE; i++){
+ if(2*i<SIZE) r[i] = av_lfg_get(&prng) % 7;
+ else r[i] = (i>>8)&1;
+ }
+
+ for(i=0; i<SIZE; i++){
+ put_cabac_bypass(&c, r[i]&1);
+ }
+
+ for(i=0; i<SIZE; i++){
+ put_cabac(&c, state, r[i]&1);
+ }
+
+ i= put_cabac_terminate(&c, 1);
+ b[i++] = av_lfg_get(&prng);
+ b[i ] = av_lfg_get(&prng);
+
+ ff_init_cabac_decoder(&c, b, SIZE);
+
+ memset(state, 0, sizeof(state));
+
+ for(i=0; i<SIZE; i++){
+ if( (r[i]&1) != get_cabac_bypass(&c) ) {
+ av_log(NULL, AV_LOG_ERROR, "CABAC bypass failure at %d\n", i);
+ ret = 1;
+ }
+ }
+
+ for(i=0; i<SIZE; i++){
+ if( (r[i]&1) != get_cabac_noinline(&c, state) ) {
+ av_log(NULL, AV_LOG_ERROR, "CABAC failure at %d\n", i);
+ ret = 1;
+ }
+ }
+ if(!get_cabac_terminate(&c)) {
+ av_log(NULL, AV_LOG_ERROR, "where's the Terminator?\n");
+ ret = 1;
+ }
+
+ return ret;
+}
diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index 1a877dd2b5..a718d51ddb 100644
--- a/libavcodec/cabac.c
+++ b/libavcodec/cabac.c
@@ -200,150 +200,3 @@ int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
return AVERROR_INVALIDDATA;
return 0;
}
-
-#ifdef TEST
-#define SIZE 10240
-
-#include "libavutil/lfg.h"
-#include "avcodec.h"
-
-static inline void put_cabac_bit(CABACContext *c, int b){
- put_bits(&c->pb, 1, b);
- for(;c->outstanding_count; c->outstanding_count--){
- put_bits(&c->pb, 1, 1-b);
- }
-}
-
-static inline void renorm_cabac_encoder(CABACContext *c){
- while(c->range < 0x100){
- //FIXME optimize
- if(c->low<0x100){
- put_cabac_bit(c, 0);
- }else if(c->low<0x200){
- c->outstanding_count++;
- c->low -= 0x100;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x200;
- }
-
- c->range+= c->range;
- c->low += c->low;
- }
-}
-
-static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
-
- if(bit == ((*state)&1)){
- c->range -= RangeLPS;
- *state = ff_h264_mlps_state[128 + *state];
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- *state= ff_h264_mlps_state[127 - *state];
- }
-
- renorm_cabac_encoder(c);
-}
-
-/**
- * @param bit 0 -> write zero bit, !=0 write one bit
- */
-static void put_cabac_bypass(CABACContext *c, int bit){
- c->low += c->low;
-
- if(bit){
- c->low += c->range;
- }
-//FIXME optimize
- if(c->low<0x200){
- put_cabac_bit(c, 0);
- }else if(c->low<0x400){
- c->outstanding_count++;
- c->low -= 0x200;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x400;
- }
-}
-
-/**
- *
- * @return the number of bytes written
- */
-static int put_cabac_terminate(CABACContext *c, int bit){
- c->range -= 2;
-
- if(!bit){
- renorm_cabac_encoder(c);
- }else{
- c->low += c->range;
- c->range= 2;
-
- renorm_cabac_encoder(c);
-
- av_assert0(c->low <= 0x1FF);
- put_cabac_bit(c, c->low>>9);
- put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
-
- flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
- }
-
- return (put_bits_count(&c->pb)+7)>>3;
-}
-
-int main(void){
- CABACContext c;
- uint8_t b[9*SIZE];
- uint8_t r[9*SIZE];
- int i, ret = 0;
- uint8_t state[10]= {0};
- AVLFG prng;
-
- av_lfg_init(&prng, 1);
- ff_init_cabac_encoder(&c, b, SIZE);
-
- for(i=0; i<SIZE; i++){
- if(2*i<SIZE) r[i] = av_lfg_get(&prng) % 7;
- else r[i] = (i>>8)&1;
- }
-
- for(i=0; i<SIZE; i++){
- put_cabac_bypass(&c, r[i]&1);
- }
-
- for(i=0; i<SIZE; i++){
- put_cabac(&c, state, r[i]&1);
- }
-
- i= put_cabac_terminate(&c, 1);
- b[i++] = av_lfg_get(&prng);
- b[i ] = av_lfg_get(&prng);
-
- ff_init_cabac_decoder(&c, b, SIZE);
-
- memset(state, 0, sizeof(state));
-
- for(i=0; i<SIZE; i++){
- if( (r[i]&1) != get_cabac_bypass(&c) ) {
- av_log(NULL, AV_LOG_ERROR, "CABAC bypass failure at %d\n", i);
- ret = 1;
- }
- }
-
- for(i=0; i<SIZE; i++){
- if( (r[i]&1) != get_cabac_noinline(&c, state) ) {
- av_log(NULL, AV_LOG_ERROR, "CABAC failure at %d\n", i);
- ret = 1;
- }
- }
- if(!get_cabac_terminate(&c)) {
- av_log(NULL, AV_LOG_ERROR, "where's the Terminator?\n");
- ret = 1;
- }
-
- return ret;
-}
-
-#endif /* TEST */
diff --git a/libavcodec/iirfilter-test.c b/libavcodec/iirfilter-test.c
new file mode 100644
index 0000000000..0138097380
--- /dev/null
+++ b/libavcodec/iirfilter-test.c
@@ -0,0 +1,52 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <math.h>
+#include <stdint.h>
+#include <stdio.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_coeffsp(&fcoeffs);
+ ff_iir_filter_free_statep(&fstate);
+ return 0;
+}
diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index 474f52fde7..a8c9b9b826 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -323,35 +323,3 @@ void ff_iir_filter_init(FFIIRFilterContext *f) {
if (HAVE_MIPSFPU)
ff_iir_filter_init_mips(f);
}
-
-#ifdef TEST
-#include <stdio.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_coeffsp(&fcoeffs);
- ff_iir_filter_free_statep(&fstate);
- return 0;
-}
-#endif /* TEST */
diff --git a/libavcodec/imgconvert-test.c b/libavcodec/imgconvert-test.c
new file mode 100644
index 0000000000..96004d79c2
--- /dev/null
+++ b/libavcodec/imgconvert-test.c
@@ -0,0 +1,50 @@
+/*
+ * Misc image conversion routines
+ * Copyright (c) 2001, 2002, 2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "imgconvert.c"
+
+#if FF_API_AVPICTURE
+FF_DISABLE_DEPRECATION_WARNINGS
+int main(void){
+ int i;
+ int err=0;
+ int skip = 0;
+
+ for (i=0; i<AV_PIX_FMT_NB*2; i++) {
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
+ if(!desc || !desc->name) {
+ skip ++;
+ continue;
+ }
+ if (skip) {
+ av_log(NULL, AV_LOG_INFO, "%3d unused pixel format values\n", skip);
+ skip = 0;
+ }
+ av_log(NULL, AV_LOG_INFO, "pix fmt %s yuv_plan:%d avg_bpp:%d\n", desc->name, is_yuv_planar(desc), av_get_padded_bits_per_pixel(desc));
+ if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
+ av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
+ err = 1;
+ }
+ }
+ return err;
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif /* FF_API_AVPICTURE */
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 0035dc6e1c..46fa7809bd 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -231,33 +231,5 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
return 0;
}
-
-#ifdef TEST
-
-int main(void){
- int i;
- int err=0;
- int skip = 0;
-
- for (i=0; i<AV_PIX_FMT_NB*2; i++) {
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
- if(!desc || !desc->name) {
- skip ++;
- continue;
- }
- if (skip) {
- av_log(NULL, AV_LOG_INFO, "%3d unused pixel format values\n", skip);
- skip = 0;
- }
- av_log(NULL, AV_LOG_INFO, "pix fmt %s yuv_plan:%d avg_bpp:%d\n", desc->name, is_yuv_planar(desc), av_get_padded_bits_per_pixel(desc));
- if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
- av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
- err = 1;
- }
- }
- return err;
-}
-
-#endif
FF_ENABLE_DEPRECATION_WARNINGS
#endif /* FF_API_AVPICTURE */
diff --git a/libavcodec/jpeg2000dwt-test.c b/libavcodec/jpeg2000dwt-test.c
new file mode 100644
index 0000000000..30f1ce1ef7
--- /dev/null
+++ b/libavcodec/jpeg2000dwt-test.c
@@ -0,0 +1,141 @@
+/*
+ * Discrete wavelet transform
+ * Copyright (c) 2007 Kamil Nowosad
+ * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "jpeg2000dwt.c"
+
+#include "libavutil/lfg.h"
+
+#define MAX_W 256
+
+static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, int type, int max_diff) {
+ int ret, j;
+ DWTContext s1={{{0}}}, *s= &s1;
+ int64_t err2 = 0;
+
+ ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, type);
+ if (ret < 0) {
+ fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
+ return 1;
+ }
+ ret = ff_dwt_encode(s, array);
+ if (ret < 0) {
+ fprintf(stderr, "ff_dwt_encode failed\n");
+ return 1;
+ }
+ ret = ff_dwt_decode(s, array);
+ if (ret < 0) {
+ fprintf(stderr, "ff_dwt_encode failed\n");
+ return 1;
+ }
+ for (j = 0; j<MAX_W * MAX_W; j++) {
+ if (FFABS(array[j] - ref[j]) > max_diff) {
+ fprintf(stderr, "missmatch at %d (%d != %d) decomp:%d border %d %d %d %d\n",
+ j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
+ return 2;
+ }
+ err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
+ array[j] = ref[j];
+ }
+ ff_dwt_destroy(s);
+
+ printf("%s, decomp:%2d border %3d %3d %3d %3d milli-err2:%9"PRId64"\n",
+ type == FF_DWT53 ? "5/3i" : "9/7i",
+ decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
+ 1000*err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
+
+ return 0;
+}
+
+static int test_dwtf(float *array, float *ref, int border[2][2], int decomp_levels, float max_diff) {
+ int ret, j;
+ DWTContext s1={{{0}}}, *s= &s1;
+ double err2 = 0;
+
+ ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, FF_DWT97);
+ if (ret < 0) {
+ fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
+ return 1;
+ }
+ ret = ff_dwt_encode(s, array);
+ if (ret < 0) {
+ fprintf(stderr, "ff_dwt_encode failed\n");
+ return 1;
+ }
+ ret = ff_dwt_decode(s, array);
+ if (ret < 0) {
+ fprintf(stderr, "ff_dwt_encode failed\n");
+ return 1;
+ }
+ for (j = 0; j<MAX_W * MAX_W; j++) {
+ if (FFABS(array[j] - ref[j]) > max_diff) {
+ fprintf(stderr, "missmatch at %d (%f != %f) decomp:%d border %d %d %d %d\n",
+ j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
+ return 2;
+ }
+ err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
+ array[j] = ref[j];
+ }
+ ff_dwt_destroy(s);
+
+ printf("9/7f, decomp:%2d border %3d %3d %3d %3d err2:%20.3f\n",
+ decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
+ err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
+
+ return 0;
+}
+
+static int array[MAX_W * MAX_W];
+static int ref [MAX_W * MAX_W];
+static float arrayf[MAX_W * MAX_W];
+static float reff [MAX_W * MAX_W];
+
+int main(void) {
+ AVLFG prng;
+ int i,j;
+ int border[2][2];
+ int ret, decomp_levels;
+
+ av_lfg_init(&prng, 1);
+
+ for (i = 0; i<MAX_W * MAX_W; i++)
+ arrayf[i] = reff[i] = array[i] = ref[i] = av_lfg_get(&prng) % 2048;
+
+ for (i = 0; i < 100; i++) {
+ for (j=0; j<4; j++)
+ border[j>>1][j&1] = av_lfg_get(&prng) % MAX_W;
+ if (border[0][0] >= border[0][1] || border[1][0] >= border[1][1])
+ continue;
+ decomp_levels = av_lfg_get(&prng) % FF_DWT_MAX_DECLVLS;
+
+ ret = test_dwt(array, ref, border, decomp_levels, FF_DWT53, 0);
+ if (ret)
+ return ret;
+ ret = test_dwt(array, ref, border, decomp_levels, FF_DWT97_INT, FFMIN(7+5*decomp_levels, 15+3*decomp_levels));
+ if (ret)
+ return ret;
+ ret = test_dwtf(arrayf, reff, border, decomp_levels, 0.05);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/libavcodec/jpeg2000dwt.c b/libavcodec/jpeg2000dwt.c
index a46c93a9b2..188cc261a4 100644
--- a/libavcodec/jpeg2000dwt.c
+++ b/libavcodec/jpeg2000dwt.c
@@ -622,125 +622,3 @@ void ff_dwt_destroy(DWTContext *s)
av_freep(&s->f_linebuf);
av_freep(&s->i_linebuf);
}
-
-#ifdef TEST
-
-#include "libavutil/lfg.h"
-
-#define MAX_W 256
-
-static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, int type, int max_diff) {
- int ret, j;
- DWTContext s1={{{0}}}, *s= &s1;
- int64_t err2 = 0;
-
- ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, type);
- if (ret < 0) {
- fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
- return 1;
- }
- ret = ff_dwt_encode(s, array);
- if (ret < 0) {
- fprintf(stderr, "ff_dwt_encode failed\n");
- return 1;
- }
- ret = ff_dwt_decode(s, array);
- if (ret < 0) {
- fprintf(stderr, "ff_dwt_encode failed\n");
- return 1;
- }
- for (j = 0; j<MAX_W * MAX_W; j++) {
- if (FFABS(array[j] - ref[j]) > max_diff) {
- fprintf(stderr, "missmatch at %d (%d != %d) decomp:%d border %d %d %d %d\n",
- j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
- return 2;
- }
- err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
- array[j] = ref[j];
- }
- ff_dwt_destroy(s);
-
- printf("%s, decomp:%2d border %3d %3d %3d %3d milli-err2:%9"PRId64"\n",
- type == FF_DWT53 ? "5/3i" : "9/7i",
- decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
- 1000*err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
-
- return 0;
-}
-
-static int test_dwtf(float *array, float *ref, int border[2][2], int decomp_levels, float max_diff) {
- int ret, j;
- DWTContext s1={{{0}}}, *s= &s1;
- double err2 = 0;
-
- ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, FF_DWT97);
- if (ret < 0) {
- fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
- return 1;
- }
- ret = ff_dwt_encode(s, array);
- if (ret < 0) {
- fprintf(stderr, "ff_dwt_encode failed\n");
- return 1;
- }
- ret = ff_dwt_decode(s, array);
- if (ret < 0) {
- fprintf(stderr, "ff_dwt_encode failed\n");
- return 1;
- }
- for (j = 0; j<MAX_W * MAX_W; j++) {
- if (FFABS(array[j] - ref[j]) > max_diff) {
- fprintf(stderr, "missmatch at %d (%f != %f) decomp:%d border %d %d %d %d\n",
- j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
- return 2;
- }
- err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
- array[j] = ref[j];
- }
- ff_dwt_destroy(s);
-
- printf("9/7f, decomp:%2d border %3d %3d %3d %3d err2:%20.3f\n",
- decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
- err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
-
- return 0;
-}
-
-static int array[MAX_W * MAX_W];
-static int ref [MAX_W * MAX_W];
-static float arrayf[MAX_W * MAX_W];
-static float reff [MAX_W * MAX_W];
-
-int main(void) {
- AVLFG prng;
- int i,j;
- int border[2][2];
- int ret, decomp_levels;
-
- av_lfg_init(&prng, 1);
-
- for (i = 0; i<MAX_W * MAX_W; i++)
- arrayf[i] = reff[i] = array[i] = ref[i] = av_lfg_get(&prng) % 2048;
-
- for (i = 0; i < 100; i++) {
- for (j=0; j<4; j++)
- border[j>>1][j&1] = av_lfg_get(&prng) % MAX_W;
- if (border[0][0] >= border[0][1] || border[1][0] >= border[1][1])
- continue;
- decomp_levels = av_lfg_get(&prng) % FF_DWT_MAX_DECLVLS;
-
- ret = test_dwt(array, ref, border, decomp_levels, FF_DWT53, 0);
- if (ret)
- return ret;
- ret = test_dwt(array, ref, border, decomp_levels, FF_DWT97_INT, FFMIN(7+5*decomp_levels, 15+3*decomp_levels));
- if (ret)
- return ret;
- ret = test_dwtf(arrayf, reff, border, decomp_levels, 0.05);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-#endif
diff --git a/libavcodec/mathops-test.c b/libavcodec/mathops-test.c
new file mode 100644
index 0000000000..d47f1442df
--- /dev/null
+++ b/libavcodec/mathops-test.c
@@ -0,0 +1,41 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "mathops.h"
+
+#include <stdlib.h>
+
+int main(void)
+{
+ unsigned u;
+
+ for(u=0; u<65536; u++) {
+ unsigned s = u*u;
+ unsigned root = ff_sqrt(s);
+ unsigned root_m1 = ff_sqrt(s-1);
+ if (s && root != u) {
+ fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
+ return 1;
+ }
+ if (u && root_m1 != u - 1) {
+ fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/libavcodec/mathops.c b/libavcodec/mathops.c
deleted file mode 100644
index 31c8e69e61..0000000000
--- a/libavcodec/mathops.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "mathops.h"
-
-#ifdef TEST
-
-#include <stdlib.h>
-
-int main(void)
-{
- unsigned u;
-
- for(u=0; u<65536; u++) {
- unsigned s = u*u;
- unsigned root = ff_sqrt(s);
- unsigned root_m1 = ff_sqrt(s-1);
- if (s && root != u) {
- fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
- return 1;
- }
- if (u && root_m1 != u - 1) {
- fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
- return 1;
- }
- }
- return 0;
-}
-#endif /* TEST */
diff --git a/libavcodec/options-test.c b/libavcodec/options-test.c
new file mode 100644
index 0000000000..2a085795d0
--- /dev/null
+++ b/libavcodec/options-test.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "options.c"
+
+static int dummy_init(AVCodecContext *ctx)
+{
+ //TODO: this code should set every possible pointer that could be set by codec and is not an option;
+ ctx->extradata_size = 8;
+ ctx->extradata = av_malloc(ctx->extradata_size);
+ return 0;
+}
+
+static int dummy_close(AVCodecContext *ctx)
+{
+ av_freep(&ctx->extradata);
+ ctx->extradata_size = 0;
+ return 0;
+}
+
+static int dummy_encode(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
+{
+ return AVERROR(ENOSYS);
+}
+
+typedef struct Dummy12Context {
+ AVClass *av_class;
+ int num;
+ char* str;
+} Dummy12Context;
+
+typedef struct Dummy3Context {
+ void *fake_av_class;
+ int num;
+ char* str;
+} Dummy3Context;
+
+#define OFFSET(x) offsetof(Dummy12Context, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption dummy_options[] = {
+ { "str", "set str", OFFSET(str), AV_OPT_TYPE_STRING, { .str = "i'm src default value" }, 0, 0, VE},
+ { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 1500100900 }, 0, INT_MAX, VE},
+ { NULL },
+};
+
+static const AVClass dummy_v1_class = {
+ .class_name = "dummy_v1_class",
+ .item_name = av_default_item_name,
+ .option = dummy_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVClass dummy_v2_class = {
+ .class_name = "dummy_v2_class",
+ .item_name = av_default_item_name,
+ .option = dummy_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+/* codec with options */
+static AVCodec dummy_v1_encoder = {
+ .name = "dummy_v1_codec",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_NONE - 1,
+ .encode2 = dummy_encode,
+ .init = dummy_init,
+ .close = dummy_close,
+ .priv_class = &dummy_v1_class,
+ .priv_data_size = sizeof(Dummy12Context),
+};
+
+/* codec with options, different class */
+static AVCodec dummy_v2_encoder = {
+ .name = "dummy_v2_codec",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_NONE - 2,
+ .encode2 = dummy_encode,
+ .init = dummy_init,
+ .close = dummy_close,
+ .priv_class = &dummy_v2_class,
+ .priv_data_size = sizeof(Dummy12Context),
+};
+
+/* codec with priv data, but no class */
+static AVCodec dummy_v3_encoder = {
+ .name = "dummy_v3_codec",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_NONE - 3,
+ .encode2 = dummy_encode,
+ .init = dummy_init,
+ .close = dummy_close,
+ .priv_data_size = sizeof(Dummy3Context),
+};
+
+/* codec without priv data */
+static AVCodec dummy_v4_encoder = {
+ .name = "dummy_v4_codec",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_NONE - 4,
+ .encode2 = dummy_encode,
+ .init = dummy_init,
+ .close = dummy_close,
+};
+
+static void test_copy_print_codec(const AVCodecContext *ctx)
+{
+ printf("%-14s: %dx%d prv: %s",
+ ctx->codec ? ctx->codec->name : "NULL",
+ ctx->width, ctx->height,
+ ctx->priv_data ? "set" : "null");
+ if (ctx->codec && ctx->codec->priv_class && ctx->codec->priv_data_size) {
+ int64_t i64;
+ char *str = NULL;
+ av_opt_get_int(ctx->priv_data, "num", 0, &i64);
+ av_opt_get(ctx->priv_data, "str", 0, (uint8_t**)&str);
+ printf(" opts: %"PRId64" %s", i64, str);
+ av_free(str);
+ }
+ printf("\n");
+}
+
+static void test_copy(const AVCodec *c1, const AVCodec *c2)
+{
+ AVCodecContext *ctx1, *ctx2;
+ printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
+ ctx1 = avcodec_alloc_context3(c1);
+ ctx2 = avcodec_alloc_context3(c2);
+ ctx1->width = ctx1->height = 128;
+ if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
+ av_opt_set(ctx2->priv_data, "num", "667", 0);
+ av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
+ }
+ avcodec_copy_context(ctx2, ctx1);
+ test_copy_print_codec(ctx1);
+ test_copy_print_codec(ctx2);
+ if (ctx1->codec) {
+ printf("opened:\n");
+ avcodec_open2(ctx1, ctx1->codec, NULL);
+ if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
+ av_opt_set(ctx2->priv_data, "num", "667", 0);
+ av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
+ }
+ avcodec_copy_context(ctx2, ctx1);
+ test_copy_print_codec(ctx1);
+ test_copy_print_codec(ctx2);
+ avcodec_close(ctx1);
+ }
+ avcodec_free_context(&ctx1);
+ avcodec_free_context(&ctx2);
+}
+
+int main(void)
+{
+ AVCodec *dummy_codec[] = {
+ &dummy_v1_encoder,
+ &dummy_v2_encoder,
+ &dummy_v3_encoder,
+ &dummy_v4_encoder,
+ NULL,
+ };
+ int i, j;
+
+ for (i = 0; dummy_codec[i]; i++)
+ avcodec_register(dummy_codec[i]);
+
+ printf("testing avcodec_copy_context()\n");
+ for (i = 0; i < FF_ARRAY_ELEMS(dummy_codec); i++)
+ for (j = 0; j < FF_ARRAY_ELEMS(dummy_codec); j++)
+ test_copy(dummy_codec[i], dummy_codec[j]);
+ return 0;
+}
diff --git a/libavcodec/rangecoder-test.c b/libavcodec/rangecoder-test.c
new file mode 100644
index 0000000000..2892949033
--- /dev/null
+++ b/libavcodec/rangecoder-test.c
@@ -0,0 +1,64 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#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, (1LL << 32) / 20, 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/rangecoder.c b/libavcodec/rangecoder.c
index 31bbaa5881..9c6ef75b69 100644
--- a/libavcodec/rangecoder.c
+++ b/libavcodec/rangecoder.c
@@ -114,48 +114,3 @@ int ff_rac_terminate(RangeCoder *c)
return c->bytestream - c->bytestream_start;
}
-
-#ifdef TEST
-#define SIZE 10240
-
-#include "libavutil/lfg.h"
-#include "libavutil/log.h"
-
-static uint8_t b[9 * SIZE];
-static uint8_t r[9 * SIZE];
-
-int main(void)
-{
- RangeCoder c;
- 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, (1LL << 32) / 20, 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;
-}
-#endif /* TEST */
diff --git a/libavcodec/snowenc-test.c b/libavcodec/snowenc-test.c
new file mode 100644
index 0000000000..e1ed86f5c7
--- /dev/null
+++ b/libavcodec/snowenc-test.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "snowenc.c"
+
+#undef malloc
+#undef free
+#undef printf
+
+#include "libavutil/lfg.h"
+#include "libavutil/mathematics.h"
+
+int main(void){
+#define width 256
+#define height 256
+ int buffer[2][width*height];
+ SnowContext s;
+ int i;
+ AVLFG prng;
+ s.spatial_decomposition_count=6;
+ s.spatial_decomposition_type=1;
+
+ s.temp_dwt_buffer = av_mallocz_array(width, sizeof(DWTELEM));
+ s.temp_idwt_buffer = av_mallocz_array(width, sizeof(IDWTELEM));
+
+ if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
+ fprintf(stderr, "Failed to allocate memory\n");
+ return 1;
+ }
+
+ av_lfg_init(&prng, 1);
+
+ printf("testing 5/3 DWT\n");
+ for(i=0; i<width*height; i++)
+ buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
+
+ ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+
+ for(i=0; i<width*height; i++)
+ if(buffer[0][i]!= buffer[1][i]) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
+
+ printf("testing 9/7 DWT\n");
+ s.spatial_decomposition_type=0;
+ for(i=0; i<width*height; i++)
+ buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
+
+ ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+
+ for(i=0; i<width*height; i++)
+ if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
+
+ {
+ int level, orientation, x, y;
+ int64_t errors[8][4];
+ int64_t g=0;
+
+ memset(errors, 0, sizeof(errors));
+ s.spatial_decomposition_count=3;
+ s.spatial_decomposition_type=0;
+ for(level=0; level<s.spatial_decomposition_count; level++){
+ for(orientation=level ? 1 : 0; orientation<4; orientation++){
+ int w= width >> (s.spatial_decomposition_count-level);
+ int h= height >> (s.spatial_decomposition_count-level);
+ int stride= width << (s.spatial_decomposition_count-level);
+ DWTELEM *buf= buffer[0];
+ int64_t error=0;
+
+ if(orientation&1) buf+=w;
+ if(orientation>1) buf+=stride>>1;
+
+ memset(buffer[0], 0, sizeof(int)*width*height);
+ buf[w/2 + h/2*stride]= 256*256;
+ ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int64_t d= buffer[0][x + y*width];
+ error += d*d;
+ if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
+ }
+ if(FFABS(height/2-y)<9 && level==2) printf("\n");
+ }
+ error= (int)(sqrt(error)+0.5);
+ errors[level][orientation]= error;
+ if(g) g=av_gcd(g, error);
+ else g= error;
+ }
+ }
+ printf("static int const visual_weight[][4]={\n");
+ for(level=0; level<s.spatial_decomposition_count; level++){
+ printf(" {");
+ for(orientation=0; orientation<4; orientation++){
+ printf("%8"PRId64",", errors[level][orientation]/g);
+ }
+ printf("},\n");
+ }
+ printf("};\n");
+ {
+ int level=2;
+ int w= width >> (s.spatial_decomposition_count-level);
+ //int h= height >> (s.spatial_decomposition_count-level);
+ int stride= width << (s.spatial_decomposition_count-level);
+ DWTELEM *buf= buffer[0];
+ int64_t error=0;
+
+ buf+=w;
+ buf+=stride>>1;
+
+ memset(buffer[0], 0, sizeof(int)*width*height);
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int tab[4]={0,2,3,1};
+ buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
+ }
+ }
+ ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ int64_t d= buffer[0][x + y*width];
+ error += d*d;
+ if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
+ }
+ if(FFABS(height/2-y)<9) printf("\n");
+ }
+ }
+
+ }
+ return 0;
+}
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index b1d177d3b8..00aef572ae 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1955,132 +1955,3 @@ AVCodec ff_snow_encoder = {
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_INIT_CLEANUP,
};
-
-
-#ifdef TEST
-#undef malloc
-#undef free
-#undef printf
-
-#include "libavutil/lfg.h"
-#include "libavutil/mathematics.h"
-
-int main(void){
-#define width 256
-#define height 256
- int buffer[2][width*height];
- SnowContext s;
- int i;
- AVLFG prng;
- s.spatial_decomposition_count=6;
- s.spatial_decomposition_type=1;
-
- s.temp_dwt_buffer = av_mallocz_array(width, sizeof(DWTELEM));
- s.temp_idwt_buffer = av_mallocz_array(width, sizeof(IDWTELEM));
-
- if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
- fprintf(stderr, "Failed to allocate memory\n");
- return 1;
- }
-
- av_lfg_init(&prng, 1);
-
- printf("testing 5/3 DWT\n");
- for(i=0; i<width*height; i++)
- buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
-
- ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-
- for(i=0; i<width*height; i++)
- if(buffer[0][i]!= buffer[1][i]) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
-
- printf("testing 9/7 DWT\n");
- s.spatial_decomposition_type=0;
- for(i=0; i<width*height; i++)
- buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
-
- ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
-
- for(i=0; i<width*height; i++)
- if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
-
- {
- int level, orientation, x, y;
- int64_t errors[8][4];
- int64_t g=0;
-
- memset(errors, 0, sizeof(errors));
- s.spatial_decomposition_count=3;
- s.spatial_decomposition_type=0;
- for(level=0; level<s.spatial_decomposition_count; level++){
- for(orientation=level ? 1 : 0; orientation<4; orientation++){
- int w= width >> (s.spatial_decomposition_count-level);
- int h= height >> (s.spatial_decomposition_count-level);
- int stride= width << (s.spatial_decomposition_count-level);
- DWTELEM *buf= buffer[0];
- int64_t error=0;
-
- if(orientation&1) buf+=w;
- if(orientation>1) buf+=stride>>1;
-
- memset(buffer[0], 0, sizeof(int)*width*height);
- buf[w/2 + h/2*stride]= 256*256;
- ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int64_t d= buffer[0][x + y*width];
- error += d*d;
- if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
- }
- if(FFABS(height/2-y)<9 && level==2) printf("\n");
- }
- error= (int)(sqrt(error)+0.5);
- errors[level][orientation]= error;
- if(g) g=av_gcd(g, error);
- else g= error;
- }
- }
- printf("static int const visual_weight[][4]={\n");
- for(level=0; level<s.spatial_decomposition_count; level++){
- printf(" {");
- for(orientation=0; orientation<4; orientation++){
- printf("%8"PRId64",", errors[level][orientation]/g);
- }
- printf("},\n");
- }
- printf("};\n");
- {
- int level=2;
- int w= width >> (s.spatial_decomposition_count-level);
- //int h= height >> (s.spatial_decomposition_count-level);
- int stride= width << (s.spatial_decomposition_count-level);
- DWTELEM *buf= buffer[0];
- int64_t error=0;
-
- buf+=w;
- buf+=stride>>1;
-
- memset(buffer[0], 0, sizeof(int)*width*height);
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int tab[4]={0,2,3,1};
- buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
- }
- }
- ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
- for(y=0; y<height; y++){
- for(x=0; x<width; x++){
- int64_t d= buffer[0][x + y*width];
- error += d*d;
- if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
- }
- if(FFABS(height/2-y)<9) printf("\n");
- }
- }
-
- }
- return 0;
-}
-#endif /* TEST */
diff --git a/libavcodec/utils-test.c b/libavcodec/utils-test.c
new file mode 100644
index 0000000000..7b3b718bd1
--- /dev/null
+++ b/libavcodec/utils-test.c
@@ -0,0 +1,37 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+
+int main(void){
+ AVCodec *codec = NULL;
+ int ret = 0;
+ avcodec_register_all();
+
+ while (codec = av_codec_next(codec)) {
+ if (av_codec_is_encoder(codec)) {
+ if (codec->type == AVMEDIA_TYPE_AUDIO) {
+ if (!codec->sample_fmts) {
+ av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
+ ret = 1;
+ }
+ }
+ }
+ }
+ return ret;
+}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index e6609ef9b2..8652b17ee7 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -4172,23 +4172,3 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
return 0;
}
-
-#ifdef TEST
-int main(void){
- AVCodec *codec = NULL;
- int ret = 0;
- avcodec_register_all();
-
- while (codec = av_codec_next(codec)) {
- if (av_codec_is_encoder(codec)) {
- if (codec->type == AVMEDIA_TYPE_AUDIO) {
- if (!codec->sample_fmts) {
- av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
- ret = 1;
- }
- }
- }
- }
- return ret;
-}
-#endif /* TEST */