From 52dd8320a51be645a3155ba4babee968f4f4cc8a Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 8 Dec 2022 12:54:25 -0500 Subject: [PATCH] MT#56008 support different Opus "applications" Also change the default Opus application to "VoIP" Change-Id: Ied52380989f0abf4ee54246cf657edc4ca50232f --- lib/codeclib.c | 16 +++++- t/auto-daemon-tests.pl | 128 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 130 insertions(+), 14 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index 8514ff086..eaec31fce 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -1857,12 +1857,24 @@ struct libopus_encoder_options { int vbr_constraint; int fec; int pl; + int application; }; static void libopus_set_enc_opts(str *key, str *val, void *p) { struct libopus_encoder_options *opts = p; if (!str_cmp(key, "complexity") || !str_cmp(key, "compression_level")) opts->complexity = str_to_i(val, -1); + else if (!str_cmp(key, "application")) { + if (!str_cmp(val, "VOIP") || !str_cmp(val, "VoIP") || !str_cmp(val, "voip")) + opts->application = OPUS_APPLICATION_VOIP; + else if (!str_cmp(val, "audio")) + opts->application = OPUS_APPLICATION_AUDIO; + else if (!str_cmp(val, "low-delay") || !str_cmp(val, "low delay") || !str_cmp(val, "lowdelay")) + opts->application = OPUS_APPLICATION_RESTRICTED_LOWDELAY; + else + ilog(LOG_WARN | LOG_FLAG_LIMIT, "Unknown Opus application: '" STR_FORMAT "'", + STR_FMT(val)); + } else if (!str_cmp(key, "vbr")) { // aligned with ffmpeg vbr=0/1/2 option opts->vbr = str_to_i(val, -1); @@ -1902,12 +1914,12 @@ static const char *libopus_encoder_init(encoder_t *enc, const str *extra_opts) { return "invalid clock rate"; } - struct libopus_encoder_options opts = { .vbr = 1, .complexity = 10, }; + struct libopus_encoder_options opts = { .vbr = 1, .complexity = 10, .application = OPUS_APPLICATION_VOIP }; codeclib_key_value_parse(extra_opts, true, libopus_set_enc_opts, &opts); int err; enc->u.opus = opus_encoder_create(enc->requested_format.clockrate, enc->requested_format.channels, - OPUS_APPLICATION_AUDIO, &err); + opts.application, &err); if (!enc->u.opus) { ilog(LOG_ERR, "Error from libopus: %s", opus_strerror(err)); return "failed to alloc codec context"; diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl index 8f9037ea8..6f6e2b70f 100755 --- a/t/auto-daemon-tests.pl +++ b/t/auto-daemon-tests.pl @@ -1231,6 +1231,57 @@ a=sendrecv a=rtcp:PORT SDP +snd($sock_a, $port_b, rtp(8, 1000, 3000, 0x1234, $pcma_1)); +($ssrc) = rcv($sock_b, $port_a, rtpm(96, 1000, 3000, -1, "\x0c\x87\xfc\xe4\x56\x3b\x03\xec\x1f\xa8\xa2\x3f\xda\xc0\xca\x15\xec\x3e\xd6\x05\x1d\xc1\xf3\x38\x93\x63\xe5\x28\x64\xbf\x21\x34\x71\x69\xd6\xe3\x22\x5a\x2c\x7c\xbc\x8b\x59\x6e\x40")); +snd($sock_a, $port_b, rtp(8, 1001, 3160, 0x1234, $pcma_1)); +rcv($sock_b, $port_a, rtpm(96, 1001, 3960, $ssrc, "\x0c\x88\x00\xde\x27\xd1\x44\xf8\x72\xc6\x43\x79\x7e\xd4\xa4\xfe\x15\xd8\x09\x2f\x9b\x25\xef\x75\x7c\x5e\x8e\xd0\x4a\x6f\x3a\xb6\x7b\x93\x6a\x95\xd6\x9b\x8b\x1b\xcb\x69\x40")); + + + +($sock_a, $sock_b) = new_call([qw(198.51.100.16 6032)], [qw(198.51.100.16 6034)]); + +($port_a) = offer('opus encoder control, application audio', + { codec => { transcode => ['opus/48000/2////application=audio'] } }, < { transcode => ['PCMA'], set => ['opus/48000/2////application=audio'] } }, <