TT#111150 add unit test for resampler

Change-Id: Ib9b78f1200c0f4f5feae549f840059b9481d10b6
rfuchs/1283
Richard Fuchs 5 years ago
parent 9b296db449
commit ddfce1fcdd

1
t/.gitignore vendored

@ -66,3 +66,4 @@ spandsp_logging.h
aead-aes-crypt
tcp_listener.c
test-kernel-module
test-resample

@ -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

@ -0,0 +1,53 @@
#include <libavutil/frame.h>
#include <libavutil/opt.h>
#include <assert.h>
#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;
}
Loading…
Cancel
Save