From 2ac332501a5c4abafa4c6bc3095c20c71cf86094 Mon Sep 17 00:00:00 2001 From: chundonglinlin Date: Sat, 15 Apr 2023 20:29:48 +0800 Subject: [PATCH 1/3] WebRTC: Support config the bitrate of transcoding AAC to Opus.(#3448) --- trunk/conf/full.conf | 10 ++++++++ trunk/src/app/srs_app_config.cpp | 38 ++++++++++++++++++++++++++++ trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_rtc_source.cpp | 4 +-- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 352f039203..d1a498ddc6 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -550,6 +550,11 @@ vhost rtc.vhost.srs.com { # Overwrite by env SRS_VHOST_RTC_KEEP_BFRAME for all vhosts. # default: off keep_bframe off; + # The transcode audio bitrate, for RTMP to RTC. + # Overwrite by env SRS_VHOST_RTC_AUDIO_BITRATE for all vhosts. + # [8000, 192000] + # default: 48000 + opus_bitrate 48000; ############################################################### # Whether enable transmuxing RTC to RTMP. # Overwrite by env SRS_VHOST_RTC_RTC_TO_RTMP for all vhosts. @@ -560,6 +565,11 @@ vhost rtc.vhost.srs.com { # Overwrite by env SRS_VHOST_RTC_PLI_FOR_RTMP for all vhosts. # Default: 6.0 pli_for_rtmp 6.0; + # The transcode audio bitrate, for RTC to RTMP. + # Overwrite by env SRS_VHOST_RTC_AUDIO_BITRATE for all vhosts. + # [8000, 192000] + # default: 48000 + aac_bitrate 48000; } ############################################################### # For transmuxing RTMP to RTC, it will impact the default values if RTC is on. diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 5fb625667c..c1d560e9c8 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -4641,6 +4641,44 @@ bool SrsConfig::get_rtc_twcc_enabled(string vhost) return SRS_CONF_PERFER_TRUE(conf->arg0()); } +int SrsConfig::get_rtc_opus_bitrate(string vhost) +{ + SRS_OVERWRITE_BY_ENV_INT("srs.vhost.rtc.opus_bitrate"); // SRS_VHOST_RTC_OPUS_BITRATE + + static int DEFAULT = 48000; + + SrsConfDirective* conf = get_rtc(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("opus_bitrate"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return ::atoi(conf->arg0().c_str()); +} + +int SrsConfig::get_rtc_aac_bitrate(string vhost) +{ + SRS_OVERWRITE_BY_ENV_INT("srs.vhost.rtc.aac_bitrate"); // SRS_VHOST_RTC_AAC_BITRATE + + static int DEFAULT = 48000; + + SrsConfDirective* conf = get_rtc(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("aac_bitrate"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return ::atoi(conf->arg0().c_str()); +} + SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost) { srs_assert(root); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 469c459254..9bb16de301 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -531,6 +531,8 @@ class SrsConfig bool get_rtc_nack_enabled(std::string vhost); bool get_rtc_nack_no_copy(std::string vhost); bool get_rtc_twcc_enabled(std::string vhost); + int get_rtc_opus_bitrate(std::string vhost); + int get_rtc_aac_bitrate(std::string vhost); // vhost specified section public: diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index db0c2b02fa..17921ac357 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -877,7 +877,7 @@ srs_error_t SrsRtcRtpBuilder::init_codec(SrsAudioCodecId codec) codec_ = new SrsAudioTranscoder(); // Initialize the codec according to the codec in stream. - int bitrate = 48000; // The output bitrate in bps. + int bitrate = _srs_config->get_rtc_opus_bitrate(req->vhost);// The output bitrate in bps. if ((err = codec_->initialize(codec, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) { return srs_error_wrap(err, "init codec=%d", codec); } @@ -1334,7 +1334,7 @@ srs_error_t SrsRtcFrameBuilder::initialize(SrsRequest* r) SrsAudioCodecId to = SrsAudioCodecIdAAC; // The output audio codec. int channels = 2; // The output audio channels. int sample_rate = 48000; // The output audio sample rate in HZ. - int bitrate = 48000; // The output audio bitrate in bps. + int bitrate = _srs_config->get_rtc_aac_bitrate(r->vhost); // The output audio bitrate in bps. if ((err = codec_->initialize(from, to, channels, sample_rate, bitrate)) != srs_success) { return srs_error_wrap(err, "bridge initialize"); } From 89a1d7d7e5d063f9261670202795048de7eb14e5 Mon Sep 17 00:00:00 2001 From: chundonglinlin Date: Thu, 27 Apr 2023 21:25:46 +0800 Subject: [PATCH 2/3] Config: clamp audio bitrate ranges from 8000 to 320000. --- trunk/conf/full.conf | 8 +++--- trunk/src/app/srs_app_config.cpp | 45 +++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index d1a498ddc6..b8a472ee4f 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -551,8 +551,8 @@ vhost rtc.vhost.srs.com { # default: off keep_bframe off; # The transcode audio bitrate, for RTMP to RTC. - # Overwrite by env SRS_VHOST_RTC_AUDIO_BITRATE for all vhosts. - # [8000, 192000] + # Overwrite by env SRS_VHOST_RTC_OPUS_BITRATE for all vhosts. + # [8000, 320000] # default: 48000 opus_bitrate 48000; ############################################################### @@ -566,8 +566,8 @@ vhost rtc.vhost.srs.com { # Default: 6.0 pli_for_rtmp 6.0; # The transcode audio bitrate, for RTC to RTMP. - # Overwrite by env SRS_VHOST_RTC_AUDIO_BITRATE for all vhosts. - # [8000, 192000] + # Overwrite by env SRS_VHOST_RTC_AAC_BITRATE for all vhosts. + # [8000, 320000] # default: 48000 aac_bitrate 48000; } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index c1d560e9c8..74093a7481 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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()); } } @@ -4643,10 +4644,19 @@ bool SrsConfig::get_rtc_twcc_enabled(string vhost) int SrsConfig::get_rtc_opus_bitrate(string vhost) { - SRS_OVERWRITE_BY_ENV_INT("srs.vhost.rtc.opus_bitrate"); // SRS_VHOST_RTC_OPUS_BITRATE - 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; @@ -4657,15 +4667,30 @@ int SrsConfig::get_rtc_opus_bitrate(string vhost) return DEFAULT; } - return ::atoi(conf->arg0().c_str()); + 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) { - SRS_OVERWRITE_BY_ENV_INT("srs.vhost.rtc.aac_bitrate"); // SRS_VHOST_RTC_AAC_BITRATE - 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; @@ -4676,7 +4701,13 @@ int SrsConfig::get_rtc_aac_bitrate(string vhost) return DEFAULT; } - return ::atoi(conf->arg0().c_str()); + 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) From 6b9436a6dd6a8ee4c668e81744571e435ae2cd6a Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Jul 2023 10:31:39 +0800 Subject: [PATCH 3/3] Update release to v5.0.167, v6.0.60 --- trunk/doc/CHANGELOG.md | 2 ++ trunk/src/core/srs_core_version5.hpp | 2 +- trunk/src/core/srs_core_version6.hpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 075ad5259e..c6789929a1 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 6.0 Changelog +* v6.0, 2023-07-18, Merge [#3515](https://github.com/ossrs/srs/pull/3515): WebRTC: Support config the bitrate of transcoding AAC to Opus. v6.0.60 (#3515) * v6.0, 2023-07-09, Merge [#3615](https://github.com/ossrs/srs/pull/3615): Compile: Fix typo for 3rdparty. v6.0.59 (#3615) * v6.0, 2023-07-01, Merge [#3595](https://github.com/ossrs/srs/pull/3595): WHIP: Improve WHIP deletion by token verification. v6.0.58 (#3595) * v6.0, 2023-07-01, Merge [#3605](https://github.com/ossrs/srs/pull/3605): BugFix: Resolve the problem of srs_error_t memory leak. v6.0.57 (#3605) @@ -73,6 +74,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* 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) * v5.0, 2023-07-09, Merge [#3615](https://github.com/ossrs/srs/pull/3615): Compile: Fix typo for 3rdparty. v5.0.166 (#3615) * 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) * v5.0, 2023-07-01, Merge [#3605](https://github.com/ossrs/srs/pull/3605): BugFix: Resolve the problem of srs_error_t memory leak. v5.0.163 (#3605) diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp index 8270f06325..d3e358921b 100644 --- a/trunk/src/core/srs_core_version5.hpp +++ b/trunk/src/core/srs_core_version5.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 0 -#define VERSION_REVISION 166 +#define VERSION_REVISION 167 #endif diff --git a/trunk/src/core/srs_core_version6.hpp b/trunk/src/core/srs_core_version6.hpp index 3099473372..07b71e9325 100644 --- a/trunk/src/core/srs_core_version6.hpp +++ b/trunk/src/core/srs_core_version6.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 6 #define VERSION_MINOR 0 -#define VERSION_REVISION 59 +#define VERSION_REVISION 60 #endif