[FFmpeg-devel] [PATCH] checkasm: add alacdsp tests
James Almer
jamrial at gmail.com
Sun Oct 4 20:45:01 CEST 2015
Signed-off-by: James Almer <jamrial at gmail.com>
---
tests/checkasm/Makefile | 1 +
tests/checkasm/alacdsp.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++
tests/checkasm/checkasm.c | 3 ++
tests/checkasm/checkasm.h | 1 +
4 files changed, 120 insertions(+)
create mode 100644 tests/checkasm/alacdsp.c
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index f30e9c4..bf0dc9f 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -1,4 +1,5 @@
# libavcodec tests
+AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o
AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
AVCODECOBJS-$(CONFIG_FLACDSP) += flacdsp.o
AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
diff --git a/tests/checkasm/alacdsp.c b/tests/checkasm/alacdsp.c
new file mode 100644
index 0000000..ac86f68
--- /dev/null
+++ b/tests/checkasm/alacdsp.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015 James Almer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 <string.h>
+#include "checkasm.h"
+#include "libavcodec/alacdsp.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+
+#define BUF_SIZE 1024
+#define MAX_CHANNELS 2
+
+#define randomize_buffers() \
+ do { \
+ int i; \
+ for (i = 0; i < BUF_SIZE * MAX_CHANNELS; i += 4) { \
+ uint32_t r = rnd() & 0x7FFFFF; \
+ AV_WN32A(ref_buf + i, r); \
+ AV_WN32A(new_buf + i, r); \
+ } \
+ } while (0)
+
+static void check_decorrelate_stereo(void)
+{
+ LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
+ LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
+ uint8_t *ref[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
+ uint8_t *new[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
+ ALACDSPContext c;
+
+ ff_alacdsp_init(&c);
+ if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) {
+ int shift = rnd() & 0x1F;
+ int weight = rnd() & 0xFF;
+ declare_func(void, int32_t **buf, int len, int shift, int weight);
+
+ randomize_buffers();
+ call_ref((int32_t **)ref, BUF_SIZE / sizeof(int32_t), shift, weight);
+ call_new((int32_t **)new, BUF_SIZE / sizeof(int32_t), shift, weight);
+ if (memcmp(*ref, *new, BUF_SIZE * MAX_CHANNELS))
+ fail();
+ bench_new((int32_t **)new, BUF_SIZE / sizeof(int32_t), shift, weight);
+ }
+
+ report("decorrelate_stereo");
+}
+
+#undef randomize_buffers
+#define randomize_buffers() \
+ do { \
+ int i, j; \
+ for (i = 0; i < BUF_SIZE; i += 4) { \
+ for (j = 0; j < ch; j++) { \
+ uint32_t r = rnd() & 0x7FFFFF; \
+ AV_WN32A(ref[j] + i, r); \
+ AV_WN32A(new[j] + i, r); \
+ r = rnd() & 0xFF; \
+ AV_WN32A(ref_ebb[j] + i, r); \
+ AV_WN32A(new_ebb[j] + i, r); \
+ } \
+ } \
+ } while (0)
+
+static void check_append_extra_bits(void)
+{
+ LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]);
+ LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]);
+ uint8_t *ref[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
+ uint8_t *new[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
+ uint8_t *ref_ebb[] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] };
+ uint8_t *new_ebb[] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] };
+ ALACDSPContext c;
+ static const char * const channels[2] = { "mono", "stereo" };
+ int ch;
+
+ ff_alacdsp_init(&c);
+ for (ch = 1; ch <= 2; ch++) {
+ if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) {
+ declare_func(void, int32_t **buf, int32_t **ebb, int ebits, int ch, int len);
+
+ randomize_buffers();
+ call_ref((int32_t **)ref, (int32_t **)ref_ebb, 8, ch, BUF_SIZE / sizeof(int32_t));
+ call_new((int32_t **)new, (int32_t **)new_ebb, 8, ch, BUF_SIZE / sizeof(int32_t));
+ if (memcmp(*ref, *new, BUF_SIZE * ch))
+ fail();
+ bench_new((int32_t **)new, (int32_t **)new_ebb, 8, ch, BUF_SIZE / sizeof(int32_t));
+ }
+ }
+
+ report("append_extra_bits");
+}
+
+void checkasm_check_alacdsp(void)
+{
+ check_decorrelate_stereo();
+ check_append_extra_bits();
+}
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 264473a..bba2dbc 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -58,6 +58,9 @@ static const struct {
void (*func)(void);
} tests[] = {
#if CONFIG_AVCODEC
+ #if CONFIG_ALAC_DECODER
+ { "alacdsp", checkasm_check_alacdsp },
+ #endif
#if CONFIG_BSWAPDSP
{ "bswapdsp", checkasm_check_bswapdsp },
#endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 5bac20f..1775a25 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -29,6 +29,7 @@
#include "libavutil/lfg.h"
#include "libavutil/timer.h"
+void checkasm_check_alacdsp(void);
void checkasm_check_bswapdsp(void);
void checkasm_check_flacdsp(void);
void checkasm_check_h264pred(void);
--
2.5.2
More information about the ffmpeg-devel
mailing list