From ddfce1fcdd5a9addfe3a5a29bfaa621bb127e336 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 21 May 2021 12:00:35 -0400 Subject: [PATCH] TT#111150 add unit test for resampler Change-Id: Ib9b78f1200c0f4f5feae549f840059b9481d10b6 --- t/.gitignore | 1 + t/Makefile | 6 ++++-- t/test-resample.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 t/test-resample.c diff --git a/t/.gitignore b/t/.gitignore index 1c0fcbfc1..a3a4be8e6 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -66,3 +66,4 @@ spandsp_logging.h aead-aes-crypt tcp_listener.c test-kernel-module +test-resample diff --git a/t/Makefile b/t/Makefile index 6144294aa..f410f0c0e 100644 --- a/t/Makefile +++ b/t/Makefile @@ -64,7 +64,7 @@ DAEMONSRCS= crypto.c ssrc.c aux.c rtp.c HASHSRCS= ifeq ($(with_transcoding),yes) -SRCS+= test-transcode.c test-dtmf-detect.c test-payload-tracker.c +SRCS+= test-transcode.c test-dtmf-detect.c test-payload-tracker.c test-resample.c SRCS+= spandsp_recv_fax_pcm.c spandsp_recv_fax_t38.c spandsp_send_fax_pcm.c \ spandsp_send_fax_t38.c ifeq ($(with_amr_tests),yes) @@ -89,7 +89,7 @@ include ../lib/common.Makefile TESTS= test-bitstr aes-crypt aead-aes-crypt test-const_str_hash.strhash ifeq ($(with_transcoding),yes) -TESTS+= test-transcode test-dtmf-detect test-payload-tracker +TESTS+= test-transcode test-dtmf-detect test-payload-tracker test-resample ifeq ($(with_amr_tests),yes) TESTS+= test-amr-decode test-amr-encode endif @@ -182,6 +182,8 @@ test-transcode: test-transcode.o $(COMMONOBJS) codeclib.o resample.o codec.o ssr streambuf.o cookie_cache.o udp_listener.o homer.o load.o cdr.o dtmf.o timerthread.o \ media_player.o jitter_buffer.o dtmflib.o t38.o tcp_listener.o +test-resample: test-resample.o $(COMMONOBJS) codeclib.o resample.o dtmflib.o + test-payload-tracker: test-payload-tracker.o $(COMMONOBJS) ssrc.o aux.o auxlib.o rtp.o crypto.o codeclib.o \ resample.o dtmflib.o diff --git a/t/test-resample.c b/t/test-resample.c new file mode 100644 index 000000000..216963b67 --- /dev/null +++ b/t/test-resample.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include "resample.h" +#include "codeclib.h" + +void test_1(int in_samples, int in_format, int in_rate, int in_channels, + int out_format, int out_rate, int out_channels, + int out_exp_samples) +{ + printf("testing %i %i %i %i %i %i %i %i\n", in_samples, in_format, in_rate, in_channels, + out_format, out_rate, out_channels, + out_exp_samples); + + AVFrame *in_f = av_frame_alloc(); + in_f->nb_samples = in_samples; + in_f->format = in_format; + in_f->sample_rate = in_rate; + in_f->channel_layout = av_get_default_channel_layout(in_channels); + int ret = av_frame_get_buffer(in_f, 0); + assert(ret == 0); + memset(in_f->extended_data[0], 0, in_f->nb_samples * av_get_bytes_per_sample(in_f->format)); + + resample_t resampler; + ZERO(resampler); + format_t out_fmt = { + .channels = out_channels, + .clockrate = out_rate, + .format = out_format, + }; + AVFrame *out_f = resample_frame(&resampler, in_f, &out_fmt); + assert(out_f != NULL); + + printf("received samples %i\n", out_f->nb_samples); + assert(out_f->nb_samples == out_exp_samples); + + av_frame_free(&in_f); + av_frame_free(&out_f); + resample_shutdown(&resampler); +} + +int main(void) { + codeclib_init(0); + + test_1(320, AV_SAMPLE_FMT_S16, 16000, 1, AV_SAMPLE_FMT_S16, 8000, 1, 144); + test_1(160, AV_SAMPLE_FMT_S16, 8000, 1, AV_SAMPLE_FMT_S16, 16000, 1, 288); + + return 0; +} + +int get_local_log_level(unsigned int u) { + return 7; +}