From a9e09b2c0a99efddfcc16f5e413e2d73aa0e1732 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 9 Nov 2017 17:10:07 +0100 Subject: add support for specifying sample format (#317) API: ausrc and auplay - add config items for ausrc/auplay format: ausrc_format s16|float auplay_format s16|float - audio.c: convert audio samples to/from signed 16-bit Modules: alsa add test for sample format FLOAT rst: add support for FLOAT sample format audiounit: add support for FLOAT sample format coreaudio: check for signed 16-bit audio format oss: check for signed 16-bit sample format winwave: check for S16LE pulse: add support for FLOAT sample format sndio: check for S16 format gst1: check sample format aufile: check sample format aubridge: check sample format gst: check sample format opensles: check for S16 sample format jack: check sample format alsa: remove usage of local config test: change samples to void pointer test: change sample type to void pointer --- test/call.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- test/main.c | 1 + test/mock/mock_auplay.c | 5 ++-- test/mock/mock_ausrc.c | 5 ++-- test/play.c | 2 +- test/test.h | 3 ++- 6 files changed, 77 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/call.c b/test/call.c index 0cd0394..b86ce6a 100644 --- a/test/call.c +++ b/test/call.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include "test.h" @@ -721,7 +722,7 @@ int test_call_video(void) #endif -static void mock_sample_handler(const int16_t *sampv, size_t sampc, void *arg) +static void mock_sample_handler(const void *sampv, size_t sampc, void *arg) { struct fixture *fix = arg; bool got_aulevel; @@ -819,3 +820,68 @@ int test_call_progress(void) return err; } + + +static void float_sample_handler(const void *sampv, size_t sampc, void *arg) +{ + struct fixture *fix = arg; + (void)sampv; + (void)sampc; + + if (sampc && fix->a.n_established && fix->b.n_established) + re_cancel(); +} + + +int test_call_format_float(void) +{ + struct fixture fix, *f = &fix; + struct ausrc *ausrc = NULL; + struct auplay *auplay = NULL; + int err = 0; + + fixture_init(f); + + conf_config()->audio.src_fmt = AUFMT_FLOAT; + conf_config()->audio.play_fmt = AUFMT_FLOAT; + + err = mock_ausrc_register(&ausrc); + TEST_ERR(err); + err = mock_auplay_register(&auplay, float_sample_handler, f); + TEST_ERR(err); + + f->estab_action = ACTION_NOTHING; + + f->behaviour = BEHAVIOUR_ANSWER; + + /* Make a call from A to B */ + err = ua_connect(f->a.ua, 0, NULL, f->buri, NULL, VIDMODE_OFF); + TEST_ERR(err); + + /* run main-loop with timeout, wait for events */ + err = re_main_timeout(5000); + TEST_ERR(err); + TEST_ERR(fix.err); + + ASSERT_EQ(0, fix.a.n_incoming); + ASSERT_EQ(1, fix.a.n_established); + ASSERT_EQ(0, fix.a.n_closed); + ASSERT_EQ(0, fix.a.close_scode); + + ASSERT_EQ(1, fix.b.n_incoming); + ASSERT_EQ(1, fix.b.n_established); + ASSERT_EQ(0, fix.b.n_closed); + + out: + conf_config()->audio.src_fmt = AUFMT_S16LE; + conf_config()->audio.play_fmt = AUFMT_S16LE; + + fixture_close(f); + mem_deref(auplay); + mem_deref(ausrc); + + if (fix.err) + return fix.err; + + return err; +} diff --git a/test/main.c b/test/main.c index 497d347..e917f2d 100644 --- a/test/main.c +++ b/test/main.c @@ -35,6 +35,7 @@ static const struct test tests[] = { TEST(test_call_dtmf), TEST(test_call_aulevel), TEST(test_call_progress), + TEST(test_call_format_float), #ifdef USE_VIDEO TEST(test_call_video), TEST(test_video), diff --git a/test/mock/mock_auplay.c b/test/mock/mock_auplay.c index 9857d9f..2a4ffcc 100644 --- a/test/mock/mock_auplay.c +++ b/test/mock/mock_auplay.c @@ -4,6 +4,7 @@ * Copyright (C) 2010 - 2016 Creytiv.com */ #include +#include #include #include "../test.h" @@ -13,7 +14,7 @@ struct auplay_st { struct tmr tmr; struct auplay_prm prm; - int16_t *sampv; + void *sampv; size_t sampc; auplay_write_h *wh; void *arg; @@ -72,7 +73,7 @@ static int mock_auplay_alloc(struct auplay_st **stp, const struct auplay *ap, st->sampc = prm->srate * prm->ch * prm->ptime / 1000; - st->sampv = mem_zalloc(2 * st->sampc, NULL); + st->sampv = mem_zalloc(aufmt_sample_size(prm->fmt) * st->sampc, NULL); if (!st->sampv) { err = ENOMEM; goto out; diff --git a/test/mock/mock_ausrc.c b/test/mock/mock_ausrc.c index 39512f1..070cbfc 100644 --- a/test/mock/mock_ausrc.c +++ b/test/mock/mock_ausrc.c @@ -4,6 +4,7 @@ * Copyright (C) 2010 - 2016 Creytiv.com */ #include +#include #include #include "../test.h" @@ -13,7 +14,7 @@ struct ausrc_st { struct tmr tmr; struct ausrc_prm prm; - int16_t *sampv; + void *sampv; size_t sampc; ausrc_read_h *rh; void *arg; @@ -65,7 +66,7 @@ static int mock_ausrc_alloc(struct ausrc_st **stp, const struct ausrc *as, st->sampc = prm->srate * prm->ch * prm->ptime / 1000; - st->sampv = mem_zalloc(2 * st->sampc, NULL); + st->sampv = mem_zalloc(aufmt_sample_size(prm->fmt) * st->sampc, NULL); if (!st->sampv) { err = ENOMEM; goto out; diff --git a/test/play.c b/test/play.c index 9e8c09c..82c8813 100644 --- a/test/play.c +++ b/test/play.c @@ -39,7 +39,7 @@ static struct mbuf *generate_tone(void) } -static void sample_handler(const int16_t *sampv, size_t sampc, void *arg) +static void sample_handler(const void *sampv, size_t sampc, void *arg) { struct test *test = arg; size_t bytec = sampc * 2; diff --git a/test/test.h b/test/test.h index 572e179..f276a8d 100644 --- a/test/test.h +++ b/test/test.h @@ -143,7 +143,7 @@ int mock_ausrc_register(struct ausrc **ausrcp); struct auplay; -typedef void (mock_sample_h)(const int16_t *sampv, size_t sampc, void *arg); +typedef void (mock_sample_h)(const void *sampv, size_t sampc, void *arg); int mock_auplay_register(struct auplay **auplayp, mock_sample_h *sampleh, void *arg); @@ -206,6 +206,7 @@ int test_call_dtmf(void); int test_call_video(void); int test_call_aulevel(void); int test_call_progress(void); +int test_call_format_float(void); #ifdef USE_VIDEO int test_video(void); -- cgit v1.2.3