summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-05 15:57:37 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-05 15:57:37 +0100
commit51111f4747355c0f15e62c5626a47d94fc92ccba (patch)
tree15ac77dfe1a4e20b1e02f97c1aed64fe7ce9c192
parent4b4920f542554755b3fc7af5fddbfef801bd8d2e (diff)
audio: add function to set encoder bitrate
- auenc API updated with bitrate in bits/s - new command to set encoder bitrate: /aubitrate 128000
-rw-r--r--include/baresip.h2
-rw-r--r--modules/menu/menu.c22
-rw-r--r--modules/opus/encode.c4
-rw-r--r--src/audio.c42
4 files changed, 70 insertions, 0 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 746a95e..6887c5c 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -826,6 +826,7 @@ const struct vidisp *vidisp_find(const struct list *vidispl, const char *name);
/** Audio Codec parameters */
struct auenc_param {
uint32_t ptime; /**< Packet time in [ms] */
+ uint32_t bitrate;/**< Wanted bitrate in [bit/s] */
};
struct auenc_state;
@@ -986,6 +987,7 @@ void audio_encoder_cycle(struct audio *audio);
int audio_level_get(const struct audio *au, double *level);
int audio_debug(struct re_printf *pf, const struct audio *a);
struct stream *audio_strm(const struct audio *a);
+int audio_set_bitrate(struct audio *au, uint32_t bitrate);
/*
diff --git a/modules/menu/menu.c b/modules/menu/menu.c
index c7f1646..0ea87b7 100644
--- a/modules/menu/menu.c
+++ b/modules/menu/menu.c
@@ -774,6 +774,27 @@ static int set_current_call(struct re_printf *pf, void *arg)
}
+static int set_audio_bitrate(struct re_printf *pf, void *arg)
+{
+ struct cmd_arg *carg = arg;
+ struct call *call;
+ uint32_t bitrate = atoi(carg->prm);
+ int err;
+
+ call = ua_call(uag_cur());
+ if (call) {
+ err = re_hprintf(pf, "setting audio bitrate: %u bps\n",
+ bitrate);
+ audio_set_bitrate(call_audio(call), bitrate);
+ }
+ else {
+ err = re_hprintf(pf, "call not found\n");
+ }
+
+ return err;
+}
+
+
static const struct cmd callcmdv[] = {
{"reinvite", 'I', 0, "Send re-INVITE", call_reinvite },
{"resume", 'X', 0, "Call resume", cmd_call_resume },
@@ -784,6 +805,7 @@ static const struct cmd callcmdv[] = {
{"hold", 'x', 0, "Call hold", cmd_call_hold },
{"", 'H', 0, "Hold previous call", hold_prev_call },
{"", 'L', 0, "Resume previous call",hold_prev_call },
+{"aubitrate", 0, CMD_PRM, "Set audio bitrate", set_audio_bitrate },
#ifdef USE_VIDEO
{"video_cycle", 'E', 0, "Cycle video encoder", call_videoenc_cycle },
diff --git a/modules/opus/encode.c b/modules/opus/encode.c
index 7ee1ca2..6723ac8 100644
--- a/modules/opus/encode.c
+++ b/modules/opus/encode.c
@@ -134,6 +134,10 @@ int opus_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
fch = prm.stereo ? OPUS_AUTO : 1;
vbr = prm.cbr ? 0 : 1;
+ /* override local bitrate */
+ if (param && param->bitrate)
+ prm.bitrate = param->bitrate;
+
(void)opus_encoder_ctl(aes->enc,
OPUS_SET_MAX_BANDWIDTH(srate2bw(prm.srate)));
(void)opus_encoder_ctl(aes->enc, OPUS_SET_BITRATE(prm.bitrate));
diff --git a/src/audio.c b/src/audio.c
index f0d6720..cc6e41f 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -1602,6 +1602,7 @@ int audio_encoder_set(struct audio *a, const struct aucodec *ac,
struct auenc_param prm;
prm.ptime = tx->ptime;
+ prm.bitrate = 0; /* auto */
err = ac->encupdh(&tx->enc, ac, &prm, params);
if (err) {
@@ -2079,3 +2080,44 @@ int audio_print_rtpstat(struct re_printf *pf, const struct audio *a)
return err;
}
+
+
+int audio_set_bitrate(struct audio *au, uint32_t bitrate)
+{
+ struct autx *tx;
+ const struct aucodec *ac;
+ int err;
+
+ if (!au)
+ return EINVAL;
+
+ tx = &au->tx;
+
+ ac = tx->ac;
+
+ info("audio: set bitrate for encoder '%s' to %u bits/s\n",
+ ac ? ac->name : "?",
+ bitrate);
+
+ if (ac) {
+
+ if (ac->encupdh) {
+ struct auenc_param prm;
+
+ prm.ptime = tx->ptime;
+ prm.bitrate = bitrate;
+
+ err = ac->encupdh(&tx->enc, ac, &prm, NULL);
+ if (err) {
+ warning("audio: encupdh error: %m\n", err);
+ return err;
+ }
+ }
+
+ }
+ else {
+ info("audio: set_bitrate: no audio encoder\n");
+ }
+
+ return 0;
+}