1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

WebRTC: Support config the bitrate of transcoding AAC to Opus. v5.0.167, v6.0.60 (#3515)

---------

Co-authored-by: john <hondaxiao@tencent.com>
This commit is contained in:
chundonglinlin 2023-07-18 11:09:50 +08:00 committed by GitHub
parent a1c7b9f2ba
commit 3fa4f66648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 5 deletions

View file

@ -2669,7 +2669,8 @@ srs_error_t SrsConfig::check_normal_config()
if (m != "enabled" && m != "nack" && m != "twcc" && m != "nack_no_copy"
&& m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check"
&& m != "dtls_role" && m != "dtls_version" && m != "drop_for_pt" && m != "rtc_to_rtmp"
&& m != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe") {
&& m != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe" && m != "opus_bitrate"
&& m != "aac_bitrate") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -4641,6 +4642,74 @@ bool SrsConfig::get_rtc_twcc_enabled(string vhost)
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
int SrsConfig::get_rtc_opus_bitrate(string vhost)
{
static int DEFAULT = 48000;
string opus_bitrate = srs_getenv("srs.vhost.rtc.opus_bitrate"); // SRS_VHOST_RTC_OPUS_BITRATE
if (!opus_bitrate.empty()) {
int v = ::atoi(opus_bitrate.c_str());
if (v < 8000 || v > 320000) {
srs_warn("Reset opus btirate %d to %d", v, DEFAULT);
v = DEFAULT;
}
return v;
}
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("opus_bitrate");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
int v = ::atoi(conf->arg0().c_str());
if (v < 8000 || v > 320000) {
srs_warn("Reset opus btirate %d to %d", v, DEFAULT);
return DEFAULT;
}
return v;
}
int SrsConfig::get_rtc_aac_bitrate(string vhost)
{
static int DEFAULT = 48000;
string aac_bitrate = srs_getenv("srs.vhost.rtc.aac_bitrate"); // SRS_VHOST_RTC_AAC_BITRATE
if (!aac_bitrate.empty()) {
int v = ::atoi(aac_bitrate.c_str());
if (v < 8000 || v > 320000) {
srs_warn("Reset aac btirate %d to %d", v, DEFAULT);
v = DEFAULT;
}
return v;
}
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("aac_bitrate");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
int v = ::atoi(conf->arg0().c_str());
if (v < 8000 || v > 320000) {
srs_warn("Reset aac btirate %d to %d", v, DEFAULT);
return DEFAULT;
}
return v;
}
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);