summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/baresip.h20
-rw-r--r--mk/modules.mk5
-rw-r--r--modules/amr/amr.c22
-rw-r--r--modules/auloop/auloop.c6
-rw-r--r--modules/bv32/bv32.c22
-rw-r--r--modules/codec2/codec2.c10
-rw-r--r--modules/g711/g711.c40
-rw-r--r--modules/g722/g722.c11
-rw-r--r--modules/g7221/decode.c3
-rw-r--r--modules/g7221/encode.c2
-rw-r--r--modules/g7221/g7221.h5
-rw-r--r--modules/g726/g726.c11
-rw-r--r--modules/gsm/gsm.c11
-rw-r--r--modules/l16/l16.c33
-rw-r--r--modules/mpa/decode.c8
-rw-r--r--modules/mpa/encode.c6
-rw-r--r--modules/mpa/mpa.h7
-rw-r--r--modules/opus/decode.c76
-rw-r--r--modules/opus/encode.c49
-rw-r--r--modules/opus/opus.c2
-rw-r--r--modules/opus/opus.h13
-rw-r--r--src/audio.c35
-rw-r--r--test/mock/mock_aucodec.c12
23 files changed, 241 insertions, 168 deletions
diff --git a/include/baresip.h b/include/baresip.h
index ee2cdbf..1e7e862 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -839,21 +839,17 @@ struct aucodec;
typedef int (auenc_update_h)(struct auenc_state **aesp,
const struct aucodec *ac,
struct auenc_param *prm, const char *fmtp);
-typedef int (auenc_encode_h)(struct auenc_state *aes, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc);
-typedef int (auenc_encode_fmt_h)(struct auenc_state *aes,
- uint8_t *buf, size_t *len,
- int fmt, const void *sampv, size_t sampc);
+typedef int (auenc_encode_h)(struct auenc_state *aes,
+ uint8_t *buf, size_t *len,
+ int fmt, const void *sampv, size_t sampc);
typedef int (audec_update_h)(struct audec_state **adsp,
const struct aucodec *ac, const char *fmtp);
-typedef int (audec_decode_h)(struct audec_state *ads, int16_t *sampv,
- size_t *sampc, const uint8_t *buf, size_t len);
-typedef int (audec_decode_fmt_h)(struct audec_state *ads,
- int fmt, void *sampv, size_t *sampc,
- const uint8_t *buf, size_t len);
+typedef int (audec_decode_h)(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
+ const uint8_t *buf, size_t len);
typedef int (audec_plc_h)(struct audec_state *ads,
- int16_t *sampv, size_t *sampc);
+ int fmt, void *sampv, size_t *sampc);
struct aucodec {
struct le le;
@@ -870,8 +866,6 @@ struct aucodec {
audec_plc_h *plch;
sdp_fmtp_enc_h *fmtp_ench;
sdp_fmtp_cmp_h *fmtp_cmph;
- auenc_encode_fmt_h *encfmth;
- audec_decode_fmt_h *decfmth;
};
void aucodec_register(struct list *aucodecl, struct aucodec *ac);
diff --git a/mk/modules.mk b/mk/modules.mk
index 6d6ba6e..a8256a1 100644
--- a/mk/modules.mk
+++ b/mk/modules.mk
@@ -171,11 +171,6 @@ USE_MPA := $(shell [ -f $(SYSROOT)/include/twolame.h ] || \
[ -f $(SYSROOT_ALT)/include/twolame.h ] && echo "yes")
endif
endif
-USE_SPEEX := $(shell [ -f $(SYSROOT)/include/speex.h ] || \
- [ -f $(SYSROOT)/include/speex/speex.h ] || \
- [ -f $(SYSROOT)/local/include/speex.h ] || \
- [ -f $(SYSROOT)/local/include/speex/speex.h ] || \
- [ -f $(SYSROOT_ALT)/include/speex/speex.h ] && echo "yes")
USE_SPEEX_AEC := $(shell [ -f $(SYSROOT)/include/speex/speex_echo.h ] || \
[ -f $(SYSROOT)/local/include/speex/speex_echo.h ] || \
[ -f $(SYSROOT_ALT)/include/speex/speex_echo.h ] && echo "yes")
diff --git a/modules/amr/amr.c b/modules/amr/amr.c
index 885a318..58343a1 100644
--- a/modules/amr/amr.c
+++ b/modules/amr/amr.c
@@ -16,6 +16,7 @@
#include <dec_if.h>
#endif
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include "amr.h"
@@ -205,7 +206,7 @@ static int decode_update(struct audec_state **adsp,
#ifdef AMR_WB
static int encode_wb(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
int n;
@@ -215,6 +216,9 @@ static int encode_wb(struct auenc_state *st, uint8_t *buf, size_t *len,
if (*len < NB_SERIAL_MAX)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
/* CMR value 15 indicates that no mode request is present */
buf[0] = 15 << 4;
@@ -228,7 +232,8 @@ static int encode_wb(struct auenc_state *st, uint8_t *buf, size_t *len,
}
-static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc,
+static int decode_wb(struct audec_state *st,
+ int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
if (*sampc < L_FRAME16k)
@@ -236,6 +241,9 @@ static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc,
if (len > NB_SERIAL_MAX)
return EINVAL;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
IF2D_IF_decode(st->dec, &buf[1], sampv, 0);
*sampc = L_FRAME16k;
@@ -247,7 +255,7 @@ static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc,
#ifdef AMR_NB
static int encode_nb(struct auenc_state *st, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc)
+ size_t *len, int fmt, const void *sampv, size_t sampc)
{
int r;
@@ -256,6 +264,9 @@ static int encode_nb(struct auenc_state *st, uint8_t *buf,
if (*len < NB_SERIAL_MAX)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
/* CMR value 15 indicates that no mode request is present */
buf[0] = 15 << 4;
@@ -269,7 +280,7 @@ static int encode_nb(struct auenc_state *st, uint8_t *buf,
}
-static int decode_nb(struct audec_state *st, int16_t *sampv,
+static int decode_nb(struct audec_state *st, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
if (!st || !sampv || !sampc || !buf)
@@ -281,6 +292,9 @@ static int decode_nb(struct audec_state *st, int16_t *sampv,
if (*sampc < L_FRAME16k)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
Decoder_Interface_Decode(st->dec, &buf[1], sampv, 0);
*sampc = FRAMESIZE_NB;
diff --git a/modules/auloop/auloop.c b/modules/auloop/auloop.c
index 347f130..c1da518 100644
--- a/modules/auloop/auloop.c
+++ b/modules/auloop/auloop.c
@@ -120,12 +120,14 @@ static int codec_read(struct audio_loop *al, int16_t *sampv, size_t sampc)
aubuf_read_samp(al->ab, al->sampv, al->sampc);
- err = al->ac->ench(al->enc, x, &xlen, al->sampv, al->sampc);
+ err = al->ac->ench(al->enc, x, &xlen,
+ AUFMT_S16LE, al->sampv, al->sampc);
if (err)
goto out;
if (al->ac->dech) {
- err = al->ac->dech(al->dec, sampv, &sampc, x, xlen);
+ err = al->ac->dech(al->dec, AUFMT_S16LE, sampv, &sampc,
+ x, xlen);
if (err)
goto out;
}
diff --git a/modules/bv32/bv32.c b/modules/bv32/bv32.c
index d3dd45c..a23241e 100644
--- a/modules/bv32/bv32.c
+++ b/modules/bv32/bv32.c
@@ -4,6 +4,7 @@
* Copyright (C) 2010 Creytiv.com
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include <bv32/bv32.h>
#include <bv32/bitpack.h>
@@ -100,17 +101,21 @@ static int decode_update(struct audec_state **adsp,
static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
size_t i, nframe;
+ short *p = (short *)sampv;
nframe = sampc / NSAMP;
if (*len < nframe * CODED_OCTETS)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
for (i=0; i<nframe; i++) {
- BV32_Encode(&st->bsc, &st->cs, (short *)&sampv[i*NSAMP]);
+ BV32_Encode(&st->bsc, &st->cs, &p[i*NSAMP]);
BV32_BitPack((void *)&buf[i*CODED_OCTETS], &st->bsc);
}
@@ -120,19 +125,23 @@ static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
}
-static int decode(struct audec_state *st, int16_t *sampv,
+static int decode(struct audec_state *st, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
size_t i, nframe;
+ short *p = sampv;
nframe = len / CODED_OCTETS;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
if (*sampc < NSAMP*nframe)
return ENOMEM;
for (i=0; i<nframe; i++) {
BV32_BitUnPack((void *)&buf[i*CODED_OCTETS], &st->bsd);
- BV32_Decode(&st->bsd, &st->ds, (short *)&sampv[i*NSAMP]);
+ BV32_Decode(&st->bsd, &st->ds, &p[i*NSAMP]);
}
*sampc = NSAMP * nframe;
@@ -141,8 +150,11 @@ static int decode(struct audec_state *st, int16_t *sampv,
}
-static int plc(struct audec_state *st, int16_t *sampv, size_t *sampc)
+static int plc(struct audec_state *st, int fmt, void *sampv, size_t *sampc)
{
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
BV32_PLC(&st->ds, sampv);
*sampc = NSAMP;
diff --git a/modules/codec2/codec2.c b/modules/codec2/codec2.c
index b6911dc..44e8e43 100644
--- a/modules/codec2/codec2.c
+++ b/modules/codec2/codec2.c
@@ -123,7 +123,7 @@ static int decode_update(struct audec_state **adsp,
static int encode(struct auenc_state *aes, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc)
+ size_t *len, int fmt, const void *sampv, size_t sampc)
{
if (!buf || !len || !sampv)
return EINVAL;
@@ -133,6 +133,9 @@ static int encode(struct auenc_state *aes, uint8_t *buf,
if (sampc != (size_t)codec2_samples_per_frame(aes->c2))
return EPROTO;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
codec2_encode(aes->c2, buf, (short *)sampv);
*len = codec2_bits_per_frame(aes->c2)/8;
@@ -141,7 +144,7 @@ static int encode(struct auenc_state *aes, uint8_t *buf,
}
-static int decode(struct audec_state *ads, int16_t *sampv,
+static int decode(struct audec_state *ads, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
if (!sampv || !sampc || !buf)
@@ -152,6 +155,9 @@ static int decode(struct audec_state *ads, int16_t *sampv,
if (len < (size_t)codec2_bits_per_frame(ads->c2)/8)
return EPROTO;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
codec2_decode(ads->c2, sampv, buf);
*sampc = codec2_samples_per_frame(ads->c2);
diff --git a/modules/g711/g711.c b/modules/g711/g711.c
index d264153..e72f117 100644
--- a/modules/g711/g711.c
+++ b/modules/g711/g711.c
@@ -17,8 +17,10 @@
static int pcmu_encode(struct auenc_state *aes, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc)
+ size_t *len, int fmt, const void *sampv, size_t sampc)
{
+ const int16_t *p = sampv;
+
(void)aes;
if (!buf || !len || !sampv)
@@ -27,18 +29,23 @@ static int pcmu_encode(struct auenc_state *aes, uint8_t *buf,
if (*len < sampc)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*len = sampc;
while (sampc--)
- *buf++ = g711_pcm2ulaw(*sampv++);
+ *buf++ = g711_pcm2ulaw(*p++);
return 0;
}
-static int pcmu_decode(struct audec_state *ads, int16_t *sampv,
+static int pcmu_decode(struct audec_state *ads, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
+ int16_t *p = sampv;
+
(void)ads;
if (!sampv || !sampc || !buf)
@@ -47,18 +54,23 @@ static int pcmu_decode(struct audec_state *ads, int16_t *sampv,
if (*sampc < len)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = len;
while (len--)
- *sampv++ = g711_ulaw2pcm(*buf++);
+ *p++ = g711_ulaw2pcm(*buf++);
return 0;
}
static int pcma_encode(struct auenc_state *aes, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc)
+ size_t *len, int fmt, const void *sampv, size_t sampc)
{
+ const int16_t *p = sampv;
+
(void)aes;
if (!buf || !len || !sampv)
@@ -67,18 +79,23 @@ static int pcma_encode(struct auenc_state *aes, uint8_t *buf,
if (*len < sampc)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*len = sampc;
while (sampc--)
- *buf++ = g711_pcm2alaw(*sampv++);
+ *buf++ = g711_pcm2alaw(*p++);
return 0;
}
-static int pcma_decode(struct audec_state *ads, int16_t *sampv,
+static int pcma_decode(struct audec_state *ads, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
+ int16_t *p = sampv;
+
(void)ads;
if (!sampv || !sampc || !buf)
@@ -87,10 +104,13 @@ static int pcma_decode(struct audec_state *ads, int16_t *sampv,
if (*sampc < len)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = len;
while (len--)
- *sampv++ = g711_alaw2pcm(*buf++);
+ *p++ = g711_alaw2pcm(*buf++);
return 0;
}
@@ -98,12 +118,12 @@ static int pcma_decode(struct audec_state *ads, int16_t *sampv,
static struct aucodec pcmu = {
LE_INIT, "0", "PCMU", 8000, 8000, 1, NULL,
- NULL, pcmu_encode, NULL, pcmu_decode, NULL, NULL, NULL, NULL, NULL
+ NULL, pcmu_encode, NULL, pcmu_decode, NULL, NULL, NULL
};
static struct aucodec pcma = {
LE_INIT, "8", "PCMA", 8000, 8000, 1, NULL,
- NULL, pcma_encode, NULL, pcma_decode, NULL, NULL, NULL, NULL, NULL
+ NULL, pcma_encode, NULL, pcma_decode, NULL, NULL, NULL
};
diff --git a/modules/g722/g722.c b/modules/g722/g722.c
index 16d1f98..dd2a943 100644
--- a/modules/g722/g722.c
+++ b/modules/g722/g722.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <re.h>
+#include <rem_au.h>
#include <baresip.h>
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES 1
#include <spandsp.h>
@@ -125,10 +126,13 @@ static int decode_update(struct audec_state **adsp,
static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
int n;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
n = g722_encode(&st->enc, buf, sampv, (int)sampc);
if (n <= 0) {
return EPROTO;
@@ -143,7 +147,7 @@ static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
}
-static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
+static int decode(struct audec_state *st, int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
int n;
@@ -151,6 +155,9 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
if (!st || !sampv || !buf)
return EINVAL;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
n = g722_decode(&st->dec, sampv, buf, (int)len);
if (n < 0)
return EPROTO;
diff --git a/modules/g7221/decode.c b/modules/g7221/decode.c
index 0f7155f..298a8ae 100644
--- a/modules/g7221/decode.c
+++ b/modules/g7221/decode.c
@@ -48,7 +48,8 @@ int g7221_decode_update(struct audec_state **adsp, const struct aucodec *ac,
}
-int g7221_decode(struct audec_state *ads, int16_t *sampv, size_t *sampc,
+int g7221_decode(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
size_t framec;
diff --git a/modules/g7221/encode.c b/modules/g7221/encode.c
index 8345f5f..8dec82f 100644
--- a/modules/g7221/encode.c
+++ b/modules/g7221/encode.c
@@ -50,7 +50,7 @@ int g7221_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
int g7221_encode(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
size_t framec;
diff --git a/modules/g7221/g7221.h b/modules/g7221/g7221.h
index 635fc01..2c16d4c 100644
--- a/modules/g7221/g7221.h
+++ b/modules/g7221/g7221.h
@@ -13,13 +13,14 @@ struct g7221_aucodec {
int g7221_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
struct auenc_param *prm, const char *fmtp);
int g7221_encode(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc);
+ int fmt, const void *sampv, size_t sampc);
/* Decode */
int g7221_decode_update(struct audec_state **adsp, const struct aucodec *ac,
const char *fmtp);
-int g7221_decode(struct audec_state *ads, int16_t *sampv, size_t *sampc,
+int g7221_decode(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len);
diff --git a/modules/g726/g726.c b/modules/g726/g726.c
index fd4e462..8334b84 100644
--- a/modules/g726/g726.c
+++ b/modules/g726/g726.c
@@ -5,6 +5,7 @@
*/
#include <re.h>
+#include <rem_au.h>
#include <baresip.h>
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES 1
#include <spandsp.h>
@@ -119,11 +120,14 @@ static int decode_update(struct audec_state **adsp,
static int encode(struct auenc_state *st, uint8_t *buf,
- size_t *len, const int16_t *sampv, size_t sampc)
+ size_t *len, int fmt, const void *sampv, size_t sampc)
{
if (!buf || !len || !sampv)
return EINVAL;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
if (*len < MAX_PACKET)
return ENOMEM;
@@ -133,12 +137,15 @@ static int encode(struct auenc_state *st, uint8_t *buf,
}
-static int decode(struct audec_state *st, int16_t *sampv,
+static int decode(struct audec_state *st, int fmt, void *sampv,
size_t *sampc, const uint8_t *buf, size_t len)
{
if (!sampv || !sampc || !buf)
return EINVAL;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = g726_decode(&st->st, sampv, buf, (int)len);
return 0;
diff --git a/modules/gsm/gsm.c b/modules/gsm/gsm.c
index be225d8..da7fba7 100644
--- a/modules/gsm/gsm.c
+++ b/modules/gsm/gsm.c
@@ -5,6 +5,7 @@
*/
#include <gsm.h> /* please report if you have problems finding this file */
#include <re.h>
+#include <rem_au.h>
#include <baresip.h>
@@ -113,13 +114,16 @@ static int decode_update(struct audec_state **adsp,
static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
if (sampc != FRAME_SIZE)
return EPROTO;
if (*len < sizeof(gsm_frame))
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
gsm_encode(st->enc, (gsm_signal *)sampv, buf);
*len = sizeof(gsm_frame);
@@ -128,7 +132,7 @@ static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
}
-static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
+static int decode(struct audec_state *st, int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
int ret;
@@ -138,6 +142,9 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
if (len < sizeof(gsm_frame))
return EBADMSG;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
ret = gsm_decode(st->dec, (gsm_byte *)buf, (gsm_signal *)sampv);
if (ret)
return EPROTO;
diff --git a/modules/l16/l16.c b/modules/l16/l16.c
index ce131a0..3f324c9 100644
--- a/modules/l16/l16.c
+++ b/modules/l16/l16.c
@@ -4,6 +4,7 @@
* Copyright (C) 2010 - 2015 Creytiv.com
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
@@ -18,9 +19,10 @@ enum {NR_CODECS = 8};
static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
int16_t *p = (void *)buf;
+ const int16_t *sampv16 = sampv;
(void)st;
if (!buf || !len || !sampv)
@@ -29,19 +31,23 @@ static int encode(struct auenc_state *st, uint8_t *buf, size_t *len,
if (*len < sampc*2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*len = sampc*2;
while (sampc--)
- *p++ = htons(*sampv++);
+ *p++ = htons(*sampv16++);
return 0;
}
-static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
+static int decode(struct audec_state *st, int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
int16_t *p = (void *)buf;
+ int16_t *sampv16 = sampv;
(void)st;
if (!buf || !len || !sampv)
@@ -50,11 +56,14 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
if (*sampc < len/2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = len/2;
len /= 2;
while (len--)
- *sampv++ = ntohs(*p++);
+ *sampv16++ = ntohs(*p++);
return 0;
}
@@ -62,14 +71,14 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc,
/* See RFC 3551 */
static struct aucodec l16v[NR_CODECS] = {
-{LE_INIT, "10", "L16", 44100, 44100, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 32000, 32000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 16000, 16000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 8000, 8000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, "11", "L16", 44100, 44100, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 32000, 32000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 16000, 16000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
-{LE_INIT, 0, "L16", 8000, 8000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0},
+{LE_INIT, "10", "L16", 44100, 44100, 2, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 32000, 32000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 16000, 16000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 8000, 8000, 2, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, "11", "L16", 44100, 44100, 1, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 32000, 32000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 16000, 16000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
+{LE_INIT, 0, "L16", 8000, 8000, 1, 0, 0, encode, 0, decode, 0, 0, 0},
};
diff --git a/modules/mpa/decode.c b/modules/mpa/decode.c
index 4e2a720..b7aaf41 100644
--- a/modules/mpa/decode.c
+++ b/modules/mpa/decode.c
@@ -5,6 +5,7 @@
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include <mpg123.h>
#include <speex/speex_resampler.h>
@@ -110,7 +111,8 @@ int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac,
}
-int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
+int mpa_decode_frm(struct audec_state *ads,
+ int fmt, void *sampv_void, size_t *sampc,
const uint8_t *buf, size_t len)
{
int result, channels, encoding, i;
@@ -118,6 +120,7 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
size_t n;
spx_uint32_t intermediate_len;
spx_uint32_t out_len;
+ int16_t *sampv = sampv_void;
#ifdef DEBUG
debug("MPA dec start %d %ld\n",len, *sampc);
@@ -132,6 +135,9 @@ int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
return EPROTO;
}
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
n = 0;
result = mpg123_decode(ads->dec, buf+4, len-4,
(unsigned char*)ads->intermediate_buffer,
diff --git a/modules/mpa/encode.c b/modules/mpa/encode.c
index d13bc0a..8c8968a 100644
--- a/modules/mpa/encode.c
+++ b/modules/mpa/encode.c
@@ -5,6 +5,7 @@
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include <twolame.h>
#include <string.h>
@@ -136,7 +137,7 @@ out:
int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
int n;
spx_uint32_t intermediate_len,in_len;
@@ -144,6 +145,9 @@ int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
if (!aes || !buf || !len || !sampv)
return EINVAL;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
if (aes->resampler) {
in_len = (uint32_t)sampc/2;
intermediate_len = sizeof(aes->intermediate_buffer)
diff --git a/modules/mpa/mpa.h b/modules/mpa/mpa.h
index 0db2528..170cc3c 100644
--- a/modules/mpa/mpa.h
+++ b/modules/mpa/mpa.h
@@ -24,14 +24,15 @@ struct mpa_param {
int mpa_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
struct auenc_param *prm, const char *fmtp);
int mpa_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc);
+ int fmt, const void *sampv, size_t sampc);
/* Decode */
int mpa_decode_update(struct audec_state **adsp, const struct aucodec *ac,
const char *fmtp);
-int mpa_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
- const uint8_t *buf, size_t len);
+int mpa_decode_frm(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
+ const uint8_t *buf, size_t len);
/* SDP */
void mpa_decode_fmtp(struct mpa_param *prm, const char *fmtp);
diff --git a/modules/opus/decode.c b/modules/opus/decode.c
index a09f2ff..a4b8721 100644
--- a/modules/opus/decode.c
+++ b/modules/opus/decode.c
@@ -64,7 +64,8 @@ int opus_decode_update(struct audec_state **adsp, const struct aucodec *ac,
}
-int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
+int opus_decode_frm(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len)
{
int n;
@@ -72,11 +73,29 @@ int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
if (!ads || !sampv || !sampc || !buf)
return EINVAL;
- n = opus_decode(ads->dec, buf, (opus_int32)len,
- sampv, (int)(*sampc/ads->ch), 0);
- if (n < 0) {
- warning("opus: decode error: %s\n", opus_strerror(n));
- return EPROTO;
+ switch (fmt) {
+
+ case AUFMT_S16LE:
+ n = opus_decode(ads->dec, buf, (opus_int32)len,
+ sampv, (int)(*sampc/ads->ch), 0);
+ if (n < 0) {
+ warning("opus: decode error: %s\n", opus_strerror(n));
+ return EPROTO;
+ }
+ break;
+
+ case AUFMT_FLOAT:
+ n = opus_decode_float(ads->dec, buf, (opus_int32)len,
+ sampv, (int)(*sampc/ads->ch), 0);
+ if (n < 0) {
+ warning("opus: float decode error: %s\n",
+ opus_strerror(n));
+ return EPROTO;
+ }
+ break;
+
+ default:
+ return ENOTSUP;
}
*sampc = n * ads->ch;
@@ -85,40 +104,33 @@ int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
}
-int opus_decode_format_frm(struct audec_state *ads,
- int fmt, void *sampv, size_t *sampc,
- const uint8_t *buf, size_t len)
+int opus_decode_pkloss(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc)
{
int n;
- if (!ads || !sampv || !sampc || !buf)
+ if (!ads || !sampv || !sampc)
return EINVAL;
- if (fmt != AUFMT_FLOAT)
- return ENOTSUP;
- n = opus_decode_float(ads->dec, buf, (opus_int32)len,
- sampv, (int)(*sampc/ads->ch), 0);
- if (n < 0) {
- warning("opus: decode error: %s\n", opus_strerror(n));
- return EPROTO;
- }
+ switch (fmt) {
- *sampc = n * ads->ch;
-
- return 0;
-}
+ case AUFMT_S16LE:
+ n = opus_decode(ads->dec, NULL, 0,
+ sampv, (int)(*sampc/ads->ch), 0);
+ if (n < 0)
+ return EPROTO;
+ break;
+ case AUFMT_FLOAT:
+ n = opus_decode_float(ads->dec, NULL, 0,
+ sampv, (int)(*sampc/ads->ch), 0);
+ if (n < 0)
+ return EPROTO;
+ break;
-int opus_decode_pkloss(struct audec_state *ads, int16_t *sampv, size_t *sampc)
-{
- int n;
-
- if (!ads || !sampv || !sampc)
- return EINVAL;
-
- n = opus_decode(ads->dec, NULL, 0, sampv, (int)(*sampc/ads->ch), 0);
- if (n < 0)
- return EPROTO;
+ default:
+ return ENOTSUP;
+ }
*sampc = n * ads->ch;
diff --git a/modules/opus/encode.c b/modules/opus/encode.c
index 7450d92..7baf4f8 100644
--- a/modules/opus/encode.c
+++ b/modules/opus/encode.c
@@ -172,42 +172,37 @@ int opus_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
int opus_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv, size_t sampc)
{
opus_int32 n;
if (!aes || !buf || !len || !sampv)
return EINVAL;
- n = opus_encode(aes->enc, sampv, (int)(sampc/aes->ch),
- buf, (opus_int32)(*len));
- if (n < 0) {
- warning("opus: encode error: %s\n", opus_strerror((int)n));
- return EPROTO;
- }
-
- *len = n;
-
- return 0;
-}
+ switch (fmt) {
+ case AUFMT_S16LE:
+ n = opus_encode(aes->enc, sampv, (int)(sampc/aes->ch),
+ buf, (opus_int32)(*len));
+ if (n < 0) {
+ warning("opus: encode error: %s\n",
+ opus_strerror((int)n));
+ return EPROTO;
+ }
+ break;
+
+ case AUFMT_FLOAT:
+ n = opus_encode_float(aes->enc, sampv, (int)(sampc/aes->ch),
+ buf, (opus_int32)(*len));
+ if (n < 0) {
+ warning("opus: float encode error: %s\n",
+ opus_strerror((int)n));
+ return EPROTO;
+ }
+ break;
-int opus_encode_format_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- int fmt, const void *sampv, size_t sampc)
-{
- opus_int32 n;
-
- if (!aes || !buf || !len || !sampv)
- return EINVAL;
-
- if (fmt != AUFMT_FLOAT)
+ default:
return ENOTSUP;
-
- n = opus_encode_float(aes->enc, sampv, (int)(sampc/aes->ch),
- buf, (opus_int32)(*len));
- if (n < 0) {
- warning("opus: encode error: %s\n", opus_strerror((int)n));
- return EPROTO;
}
*len = n;
diff --git a/modules/opus/opus.c b/modules/opus/opus.c
index 8346680..7acccec 100644
--- a/modules/opus/opus.c
+++ b/modules/opus/opus.c
@@ -69,8 +69,6 @@ static struct aucodec opus = {
.decupdh = opus_decode_update,
.dech = opus_decode_frm,
.plch = opus_decode_pkloss,
- .encfmth = opus_encode_format_frm,
- .decfmth = opus_decode_format_frm,
};
diff --git a/modules/opus/opus.h b/modules/opus/opus.h
index 9e79bd5..70fa0e3 100644
--- a/modules/opus/opus.h
+++ b/modules/opus/opus.h
@@ -19,20 +19,17 @@ struct opus_param {
int opus_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
struct auenc_param *prm, const char *fmtp);
int opus_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc);
-int opus_encode_format_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
- int fmt, const void *sampv, size_t sampc);
+ int fmt, const void *sampv, size_t sampc);
/* Decode */
int opus_decode_update(struct audec_state **adsp, const struct aucodec *ac,
const char *fmtp);
-int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
+int opus_decode_frm(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
const uint8_t *buf, size_t len);
-int opus_decode_format_frm(struct audec_state *ads,
- int fmt, void *sampv, size_t *sampc,
- const uint8_t *buf, size_t len);
-int opus_decode_pkloss(struct audec_state *st, int16_t *sampv, size_t *sampc);
+int opus_decode_pkloss(struct audec_state *st,
+ int fmt, void *sampv, size_t *sampc);
/* SDP */
diff --git a/src/audio.c b/src/audio.c
index b5ce913..dd5369f 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -450,19 +450,8 @@ static void encode_rtp_send(struct audio *a, struct autx *tx,
len = mbuf_get_space(tx->mb);
- if (tx->enc_fmt == AUFMT_S16LE) {
- err = tx->ac->ench(tx->enc, mbuf_buf(tx->mb), &len,
- sampv, sampc);
- }
- else if (tx->ac->encfmth) {
- err = tx->ac->encfmth(tx->enc, mbuf_buf(tx->mb), &len,
- tx->enc_fmt, sampv, sampc);
- }
- else {
- warning("audio: sample format not supported by encoder (%s)\n",
- aufmt_name(tx->enc_fmt));
- return;
- }
+ err = tx->ac->ench(tx->enc, mbuf_buf(tx->mb), &len,
+ tx->enc_fmt, sampv, sampc);
if ((err & 0xffff0000) == 0x00010000) {
/* MPA needs some special treatment here */
@@ -766,27 +755,15 @@ static int aurx_stream_decode(struct aurx *rx, struct mbuf *mb)
if (mbuf_get_left(mb)) {
- if (rx->dec_fmt == AUFMT_S16LE) {
- err = rx->ac->dech(rx->dec, rx->sampv, &sampc,
- mbuf_buf(mb), mbuf_get_left(mb));
+ err = rx->ac->dech(rx->dec,
+ rx->dec_fmt, rx->sampv, &sampc,
+ mbuf_buf(mb), mbuf_get_left(mb));
- }
- else if (rx->ac->decfmth) {
- err = rx->ac->decfmth(rx->dec,
- rx->dec_fmt, rx->sampv, &sampc,
- mbuf_buf(mb), mbuf_get_left(mb));
- }
- else {
- warning("audio: sample format not supported"
- " by decoder (%s)\n",
- aufmt_name(rx->dec_fmt));
- return ENOTSUP;
- }
}
else if (rx->ac->plch && rx->dec_fmt == AUFMT_S16LE) {
sampc = rx->ac->srate * rx->ac->ch * rx->ptime / 1000;
- err = rx->ac->plch(rx->dec, rx->sampv, &sampc);
+ err = rx->ac->plch(rx->dec, rx->dec_fmt, rx->sampv, &sampc);
}
else {
/* no PLC in the codec, might be done in filters below */
diff --git a/test/mock/mock_aucodec.c b/test/mock/mock_aucodec.c
index fd91721..8115a36 100644
--- a/test/mock/mock_aucodec.c
+++ b/test/mock/mock_aucodec.c
@@ -16,9 +16,10 @@
static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv_void, size_t sampc)
{
int16_t *p = (void *)buf;
+ const int16_t *sampv = sampv_void;
(void)st;
if (!buf || !len || !sampv)
@@ -27,6 +28,9 @@ static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
if (*len < sampc*2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*len = 2 + sampc*2;
*p++ = L16_HEADER;
@@ -39,10 +43,11 @@ static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
static int mock_l16_decode(struct audec_state *st,
- int16_t *sampv, size_t *sampc,
+ int fmt, void *sampv_void, size_t *sampc,
const uint8_t *buf, size_t len)
{
int16_t *p = (void *)buf;
+ int16_t *sampv = sampv_void;
uint16_t hdr;
(void)st;
@@ -55,6 +60,9 @@ static int mock_l16_decode(struct audec_state *st,
if (*sampc < len/2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = (len - 2)/2;
hdr = *p++;