Skip to content

Commit e11b93d

Browse files
chundonglinlinxiaozhihong
authored andcommitted
WebRTC: Support config the bitrate of transcoding AAC to Opus. v5.0.167, v6.0.60 (#3515)
--------- Co-authored-by: john <[email protected]>
1 parent 497ea2b commit e11b93d

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

trunk/conf/full.conf

+10
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ vhost rtc.vhost.srs.com {
546546
# Overwrite by env SRS_VHOST_RTC_KEEP_BFRAME for all vhosts.
547547
# default: off
548548
keep_bframe off;
549+
# The transcode audio bitrate, for RTMP to RTC.
550+
# Overwrite by env SRS_VHOST_RTC_OPUS_BITRATE for all vhosts.
551+
# [8000, 320000]
552+
# default: 48000
553+
opus_bitrate 48000;
549554
###############################################################
550555
# Whether enable transmuxing RTC to RTMP.
551556
# Overwrite by env SRS_VHOST_RTC_RTC_TO_RTMP for all vhosts.
@@ -556,6 +561,11 @@ vhost rtc.vhost.srs.com {
556561
# Overwrite by env SRS_VHOST_RTC_PLI_FOR_RTMP for all vhosts.
557562
# Default: 6.0
558563
pli_for_rtmp 6.0;
564+
# The transcode audio bitrate, for RTC to RTMP.
565+
# Overwrite by env SRS_VHOST_RTC_AAC_BITRATE for all vhosts.
566+
# [8000, 320000]
567+
# default: 48000
568+
aac_bitrate 48000;
559569
}
560570
###############################################################
561571
# For transmuxing RTMP to RTC, it will impact the default values if RTC is on.

trunk/doc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The changelog for SRS.
88

99
## SRS 5.0 Changelog
1010

11+
* v5.0, 2023-07-18, Merge [#3515](https://github.com/ossrs/srs/pull/3515): WebRTC: Support config the bitrate of transcoding AAC to Opus. v5.0.167 (#3515)
1112
* v5.0, 2023-07-09, Merge [#3615](https://github.com/ossrs/srs/pull/3615): Compile: Fix typo for 3rdparty. v5.0.166 (#3615)
1213
* v5.0, 2023-07-09, Fix issue of srs-player failing to play HTTP-FLV. v5.0.165
1314
* v5.0, 2023-07-01, Merge [#3595](https://github.com/ossrs/srs/pull/3595): WHIP: Improve WHIP deletion by token verification. v5.0.164 (#3595)

trunk/src/app/srs_app_config.cpp

+70-1
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,8 @@ srs_error_t SrsConfig::check_normal_config()
26692669
if (m != "enabled" && m != "nack" && m != "twcc" && m != "nack_no_copy"
26702670
&& m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check"
26712671
&& m != "dtls_role" && m != "dtls_version" && m != "drop_for_pt" && m != "rtc_to_rtmp"
2672-
&& m != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe") {
2672+
&& m != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe" && m != "opus_bitrate"
2673+
&& m != "aac_bitrate") {
26732674
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
26742675
}
26752676
}
@@ -4641,6 +4642,74 @@ bool SrsConfig::get_rtc_twcc_enabled(string vhost)
46414642
return SRS_CONF_PERFER_TRUE(conf->arg0());
46424643
}
46434644

4645+
int SrsConfig::get_rtc_opus_bitrate(string vhost)
4646+
{
4647+
static int DEFAULT = 48000;
4648+
4649+
string opus_bitrate = srs_getenv("srs.vhost.rtc.opus_bitrate"); // SRS_VHOST_RTC_OPUS_BITRATE
4650+
if (!opus_bitrate.empty()) {
4651+
int v = ::atoi(opus_bitrate.c_str());
4652+
if (v < 8000 || v > 320000) {
4653+
srs_warn("Reset opus btirate %d to %d", v, DEFAULT);
4654+
v = DEFAULT;
4655+
}
4656+
4657+
return v;
4658+
}
4659+
4660+
SrsConfDirective* conf = get_rtc(vhost);
4661+
if (!conf) {
4662+
return DEFAULT;
4663+
}
4664+
4665+
conf = conf->get("opus_bitrate");
4666+
if (!conf || conf->arg0().empty()) {
4667+
return DEFAULT;
4668+
}
4669+
4670+
int v = ::atoi(conf->arg0().c_str());
4671+
if (v < 8000 || v > 320000) {
4672+
srs_warn("Reset opus btirate %d to %d", v, DEFAULT);
4673+
return DEFAULT;
4674+
}
4675+
4676+
return v;
4677+
}
4678+
4679+
int SrsConfig::get_rtc_aac_bitrate(string vhost)
4680+
{
4681+
static int DEFAULT = 48000;
4682+
4683+
string aac_bitrate = srs_getenv("srs.vhost.rtc.aac_bitrate"); // SRS_VHOST_RTC_AAC_BITRATE
4684+
if (!aac_bitrate.empty()) {
4685+
int v = ::atoi(aac_bitrate.c_str());
4686+
if (v < 8000 || v > 320000) {
4687+
srs_warn("Reset aac btirate %d to %d", v, DEFAULT);
4688+
v = DEFAULT;
4689+
}
4690+
4691+
return v;
4692+
}
4693+
4694+
SrsConfDirective* conf = get_rtc(vhost);
4695+
if (!conf) {
4696+
return DEFAULT;
4697+
}
4698+
4699+
conf = conf->get("aac_bitrate");
4700+
if (!conf || conf->arg0().empty()) {
4701+
return DEFAULT;
4702+
}
4703+
4704+
int v = ::atoi(conf->arg0().c_str());
4705+
if (v < 8000 || v > 320000) {
4706+
srs_warn("Reset aac btirate %d to %d", v, DEFAULT);
4707+
return DEFAULT;
4708+
}
4709+
4710+
return v;
4711+
}
4712+
46444713
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
46454714
{
46464715
srs_assert(root);

trunk/src/app/srs_app_config.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ class SrsConfig
531531
bool get_rtc_nack_enabled(std::string vhost);
532532
bool get_rtc_nack_no_copy(std::string vhost);
533533
bool get_rtc_twcc_enabled(std::string vhost);
534+
int get_rtc_opus_bitrate(std::string vhost);
535+
int get_rtc_aac_bitrate(std::string vhost);
534536

535537
// vhost specified section
536538
public:

trunk/src/app/srs_app_rtc_source.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ srs_error_t SrsRtcFromRtmpBridge::init_codec(SrsAudioCodecId codec)
895895
codec_ = new SrsAudioTranscoder();
896896

897897
// Initialize the codec according to the codec in stream.
898-
int bitrate = 48000; // The output bitrate in bps.
898+
int bitrate = _srs_config->get_rtc_opus_bitrate(req->vhost);// The output bitrate in bps.
899899
if ((err = codec_->initialize(codec, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) {
900900
return srs_error_wrap(err, "init codec=%d", codec);
901901
}
@@ -1352,7 +1352,7 @@ srs_error_t SrsRtmpFromRtcBridge::initialize(SrsRequest* r)
13521352
SrsAudioCodecId to = SrsAudioCodecIdAAC; // The output audio codec.
13531353
int channels = 2; // The output audio channels.
13541354
int sample_rate = 48000; // The output audio sample rate in HZ.
1355-
int bitrate = 48000; // The output audio bitrate in bps.
1355+
int bitrate = _srs_config->get_rtc_aac_bitrate(r->vhost); // The output audio bitrate in bps.
13561356
if ((err = codec_->initialize(from, to, channels, sample_rate, bitrate)) != srs_success) {
13571357
return srs_error_wrap(err, "bridge initialize");
13581358
}

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 166
12+
#define VERSION_REVISION 167
1313

1414
#endif

0 commit comments

Comments
 (0)