summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2016-11-02 20:16:02 +0100
committerGitHub <noreply@github.com>2016-11-02 20:16:02 +0100
commit11efdf755eea58b4809b320506f41e063ae3d62b (patch)
treedd074ccbc44f79e2e8a5ef0ad9a6a094afeaf069 /modules
parent6b296ddf9301401f4900813a970152fff9ac8169 (diff)
Opus mirror (#166)
* opus: mirroring of incoming parameters * opus: added 'opus_mirror' boolean config * opus: mirror only incoming SDP
Diffstat (limited to 'modules')
-rw-r--r--modules/opus/encode.c7
-rw-r--r--modules/opus/opus.c40
-rw-r--r--modules/opus/opus.h3
3 files changed, 47 insertions, 3 deletions
diff --git a/modules/opus/encode.c b/modules/opus/encode.c
index aea944f..f7937c5 100644
--- a/modules/opus/encode.c
+++ b/modules/opus/encode.c
@@ -79,6 +79,13 @@ int opus_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
if (!aesp || !ac || !ac->ch)
return EINVAL;
+ debug("opus: encoder fmtp (%s)\n", fmtp);
+
+ /* Save the incoming OPUS parameters from SDP offer */
+ if (str_isset(fmtp)) {
+ opus_mirror_params(fmtp);
+ }
+
aes = *aesp;
if (!aes) {
diff --git a/modules/opus/opus.c b/modules/opus/opus.c
index 10d9f46..d1e9c24 100644
--- a/modules/opus/opus.c
+++ b/modules/opus/opus.c
@@ -35,25 +35,59 @@
*/
+static bool opus_mirror;
+static char fmtp[256] = "stereo=1;sprop-stereo=1";
+static char fmtp_mirror[256];
+
+
+static int opus_fmtp_enc(struct mbuf *mb, const struct sdp_format *fmt,
+ bool offer, void *arg)
+{
+ bool mirror;
+
+ (void)arg;
+ (void)offer;
+
+ if (!mb || !fmt)
+ return 0;
+
+ mirror = !offer && str_isset(fmtp_mirror);
+
+ return mbuf_printf(mb, "a=fmtp:%s %s\r\n",
+ fmt->id, mirror ? fmtp_mirror : fmtp);
+}
+
+
static struct aucodec opus = {
.name = "opus",
.srate = 48000,
.crate = 48000,
.ch = 2,
- .fmtp = "stereo=1;sprop-stereo=1",
+ .fmtp = NULL,
.encupdh = opus_encode_update,
.ench = opus_encode_frm,
.decupdh = opus_decode_update,
.dech = opus_decode_frm,
.plch = opus_decode_pkloss,
+ .fmtp_ench = opus_fmtp_enc,
};
+void opus_mirror_params(const char *x)
+{
+ if (!opus_mirror)
+ return;
+
+ info("opus: mirror parameters: \"%s\"\n", x);
+
+ str_ncpy(fmtp_mirror, x, sizeof(fmtp_mirror));
+}
+
+
static int module_init(void)
{
struct conf *conf = conf_cur();
uint32_t value;
- static char fmtp[256] = "stereo=1;sprop-stereo=1";
char *p = fmtp + str_len(fmtp);
bool b;
int n = 0;
@@ -98,7 +132,7 @@ static int module_init(void)
p += n;
}
- opus.fmtp = fmtp;
+ (void)conf_get_bool(conf, "opus_mirror", &opus_mirror);
debug("opus: fmtp=\"%s\"\n", fmtp);
diff --git a/modules/opus/opus.h b/modules/opus/opus.h
index 2bed161..d521652 100644
--- a/modules/opus/opus.h
+++ b/modules/opus/opus.h
@@ -32,3 +32,6 @@ int opus_decode_pkloss(struct audec_state *st, int16_t *sampv, size_t *sampc);
/* SDP */
void opus_decode_fmtp(struct opus_param *prm, const char *fmtp);
+
+
+void opus_mirror_params(const char *fmtp);