summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-04-25 20:14:08 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-04-25 20:14:08 +0200
commit9900cc5fee1cb5e1292915b43bf4d59870893be3 (patch)
treed7defbda95f4e177aff48d0b3c099f96eb09b76b
parent8cb1afe6778fc5dedbdb867555dd3d75647dfb2e (diff)
test: added a mock audio-codec
-rw-r--r--test/call.c13
-rw-r--r--test/mock/mock_aucodec.c91
-rw-r--r--test/srcs.mk1
-rw-r--r--test/test.h7
4 files changed, 101 insertions, 11 deletions
diff --git a/test/call.c b/test/call.c
index e3cfa8d..f3881c6 100644
--- a/test/call.c
+++ b/test/call.c
@@ -62,7 +62,7 @@ struct fixture {
f->magic = MAGIC; \
f->exp_estab = 1; \
f->exp_closed = 1; \
- aucodec_register(baresip_aucodecl(), &dummy_pcma); \
+ mock_aucodec_register(); \
\
err = ua_alloc(&f->a.ua, \
"A <sip:a:xxx@127.0.0.1>;regint=0" prm); \
@@ -92,7 +92,7 @@ struct fixture {
mem_deref(f->b.ua); \
mem_deref(f->a.ua); \
\
- aucodec_unregister(&dummy_pcma); \
+ mock_aucodec_unregister(); \
\
uag_event_unregister(event_handler); \
\
@@ -106,15 +106,6 @@ struct fixture {
} while (0)
-static struct aucodec dummy_pcma = {
- .pt = "8",
- .name = "PCMA",
- .srate = 8000,
- .crate = 8000,
- .ch = 1,
-};
-
-
static void event_handler(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg)
{
diff --git a/test/mock/mock_aucodec.c b/test/mock/mock_aucodec.c
new file mode 100644
index 0000000..c923665
--- /dev/null
+++ b/test/mock/mock_aucodec.c
@@ -0,0 +1,91 @@
+/**
+ * @file mock/mock_aucodec.c Mock audio codec
+ *
+ * Copyright (C) 2010 - 2016 Creytiv.com
+ */
+
+#include <string.h>
+#include <re.h>
+#include <rem.h>
+#include <baresip.h>
+#include "../test.h"
+
+
+/* A dummy protocol header */
+#define L16_HEADER 0x1616
+
+
+static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
+ const int16_t *sampv, size_t sampc)
+{
+ int16_t *p = (void *)buf;
+ (void)st;
+
+ if (!buf || !len || !sampv)
+ return EINVAL;
+
+ if (*len < sampc*2)
+ return ENOMEM;
+
+ *len = 2 + sampc*2;
+
+ *p++ = L16_HEADER;
+
+ while (sampc--)
+ *p++ = htons(*sampv++);
+
+ return 0;
+}
+
+
+static int mock_l16_decode(struct audec_state *st,
+ int16_t *sampv, size_t *sampc,
+ const uint8_t *buf, size_t len)
+{
+ int16_t *p = (void *)buf;
+ uint16_t hdr;
+ (void)st;
+
+ if (!buf || !len || !sampv)
+ return EINVAL;
+
+ if (*sampc < len/2)
+ return ENOMEM;
+
+ *sampc = (len - 2)/2;
+
+ hdr = *p++;
+ if (L16_HEADER != hdr) {
+ warning("mock_aucodec: invalid L16 header"
+ " 0x%04x (len=%zu)\n", hdr, len);
+ return EPROTO;
+ }
+
+ len /= 2;
+ while (len--)
+ *sampv++ = ntohs(*p++);
+
+ return 0;
+}
+
+
+static struct aucodec ac_dummy = {
+ .name = "FOO16",
+ .srate = 8000,
+ .crate = 8000,
+ .ch = 1,
+ .ench = mock_l16_encode,
+ .dech = mock_l16_decode,
+};
+
+
+void mock_aucodec_register(void)
+{
+ aucodec_register(baresip_aucodecl(), &ac_dummy);
+}
+
+
+void mock_aucodec_unregister(void)
+{
+ aucodec_unregister(&ac_dummy);
+}
diff --git a/test/srcs.mk b/test/srcs.mk
index 91d4d3d..3c481ac 100644
--- a/test/srcs.mk
+++ b/test/srcs.mk
@@ -36,6 +36,7 @@ ifneq ($(USE_TLS),)
TEST_SRCS += mock/cert.c
endif
+TEST_SRCS += mock/mock_aucodec.c
TEST_SRCS += mock/mock_auplay.c
TEST_SRCS += mock/mock_ausrc.c
ifneq ($(USE_VIDEO),)
diff --git a/test/test.h b/test/test.h
index b7ef3e0..3a19ec1 100644
--- a/test/test.h
+++ b/test/test.h
@@ -122,6 +122,13 @@ int dns_server_add_srv(struct dns_server *srv, const char *name,
const char *target);
/*
+ * Mock Audio-codec
+ */
+
+void mock_aucodec_register(void);
+void mock_aucodec_unregister(void);
+
+/*
* Mock Audio-source
*/