From 71ed6e5dc51df06eaa90637992731a7e75eabcd7 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 11 Oct 2021 22:14:45 +0800 Subject: [PATCH] RTC: Refine config, aac to rtmp_to_rtc, bframe to keep_bframe. v4.0.174 --- trunk/conf/clion.conf | 2 +- trunk/conf/docker.conf | 2 +- trunk/conf/full.conf | 21 +++++------- trunk/conf/https.rtc.conf | 2 +- trunk/conf/regression-test.conf | 4 +-- trunk/conf/rtc.conf | 2 +- trunk/conf/rtc2rtmp.conf | 2 +- trunk/conf/rtmp2rtc.conf | 2 +- trunk/conf/srs.conf | 2 +- trunk/conf/srt2rtc.conf | 2 +- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_config.cpp | 44 +++++++++++++++++++----- trunk/src/app/srs_app_config.hpp | 4 +-- trunk/src/app/srs_app_rtc_source.cpp | 50 +++++++++++++++++++--------- trunk/src/app/srs_app_rtc_source.hpp | 4 +-- trunk/src/core/srs_core_version4.hpp | 2 +- 16 files changed, 94 insertions(+), 52 deletions(-) diff --git a/trunk/conf/clion.conf b/trunk/conf/clion.conf index cceabe17e..600966060 100644 --- a/trunk/conf/clion.conf +++ b/trunk/conf/clion.conf @@ -33,7 +33,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac transcode; + rtmp_to_rtc on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp on; } diff --git a/trunk/conf/docker.conf b/trunk/conf/docker.conf index 61175100e..58a200442 100644 --- a/trunk/conf/docker.conf +++ b/trunk/conf/docker.conf @@ -31,7 +31,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac discard; + rtmp_to_rtc off; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp off; } diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 234b3edfc..c3f092855 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -459,19 +459,16 @@ vhost rtc.vhost.srs.com { # default: 0 drop_for_pt 0; ############################################################### - # For transmuxing RTMP to RTC, the strategy for bframe. - # keep Keep bframe, which may make browser with playing problems. - # discard Discard bframe, maybe cause browser with little problems. - # default: discard - bframe discard; - # For transmuxing RTMP to RTC, the strategy for aac audio. - # transcode Transcode aac to opus. - # discard Discard aac audio packet. - # default: discard - aac discard; + # Whether enable transmuxing RTMP to RTC. + # If enabled, transcode aac to opus. + # default: off + rtmp_to_rtc off; + # Whether keep B-frame, which is normal feature in live streaming, + # but usually disabled in RTC. + # default: off + keep_bframe off; ############################################################### - # For transmuxing RTC to RTMP. - # Whether trans-mux RTC to RTMP streaming. + # Whether enable transmuxing RTC to RTMP. # Default: off rtc_to_rtmp off; # The PLI interval in seconds, for RTC to RTMP. diff --git a/trunk/conf/https.rtc.conf b/trunk/conf/https.rtc.conf index ea9bc8d82..5ceb9048d 100644 --- a/trunk/conf/https.rtc.conf +++ b/trunk/conf/https.rtc.conf @@ -44,7 +44,7 @@ rtc_server { vhost __defaultVhost__ { rtc { enabled on; - bframe discard; + keep_bframe off; } } diff --git a/trunk/conf/regression-test.conf b/trunk/conf/regression-test.conf index 0fb6ee2ff..c17dc21b2 100644 --- a/trunk/conf/regression-test.conf +++ b/trunk/conf/regression-test.conf @@ -27,8 +27,8 @@ rtc_server { vhost __defaultVhost__ { rtc { enabled on; - bframe discard; - aac transcode; + rtmp_to_rtc on; + keep_bframe off; rtc_to_rtmp on; } play { diff --git a/trunk/conf/rtc.conf b/trunk/conf/rtc.conf index adcfc2b57..b7269cbdd 100644 --- a/trunk/conf/rtc.conf +++ b/trunk/conf/rtc.conf @@ -30,7 +30,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac discard; + rtmp_to_rtc off; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp off; } diff --git a/trunk/conf/rtc2rtmp.conf b/trunk/conf/rtc2rtmp.conf index 08707b5ab..66f3c8cfa 100644 --- a/trunk/conf/rtc2rtmp.conf +++ b/trunk/conf/rtc2rtmp.conf @@ -28,7 +28,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac transcode; + rtmp_to_rtc on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp on; } diff --git a/trunk/conf/rtmp2rtc.conf b/trunk/conf/rtmp2rtc.conf index 08707b5ab..66f3c8cfa 100644 --- a/trunk/conf/rtmp2rtc.conf +++ b/trunk/conf/rtmp2rtc.conf @@ -28,7 +28,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac transcode; + rtmp_to_rtc on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp on; } diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index 8dba3c6cf..d7af0b9f4 100644 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -32,7 +32,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac discard; + rtmp_to_rtc off; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp off; } diff --git a/trunk/conf/srt2rtc.conf b/trunk/conf/srt2rtc.conf index 31d2243e3..18e3ad404 100644 --- a/trunk/conf/srt2rtc.conf +++ b/trunk/conf/srt2rtc.conf @@ -41,7 +41,7 @@ vhost __defaultVhost__ { rtc { enabled on; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc - aac discard; + rtmp_to_rtc off; # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp rtc_to_rtmp off; } diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index f2cd9a014..5f3f07b4e 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-10-11, RTC: Refine config, aac to rtmp_to_rtc, bframe to keep_bframe. v4.0.174 * v4.0, 2021-10-10, For [#1641](https://github.com/ossrs/srs/issues/1641), Support RTMP publish and play regression test. v4.0.173 * v4.0, 2021-10-10, RTC: Change rtc.aac to discard by default. v4.0.172 * v4.0, 2021-10-10, Fix [#2304](https://github.com/ossrs/srs/issues/2304) Remove Push RTSP feature. v4.0.171 diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 9130cc68c..75045d170 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -521,6 +521,32 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root) srs_freep(conf); continue; } + + // SRS3.0, change the forward. + // SRS1/2: + // vhost { rtc { aac; } } + // SRS3+: + // vhost { rtc { rtmp_to_rtc; } } + if (n == "rtc") { + SrsConfDirective* aac = conf->get("aac"); + if (aac) { + string v = aac->arg0() == "transcode" ? "on" : "off"; + conf->get_or_create("rtmp_to_rtc")->set_arg0(v); + conf->remove(aac); srs_freep(aac); + srs_warn("transform: vhost.rtc.aac to vhost.rtc.rtmp_to_rtc %s", v.c_str()); + } + + SrsConfDirective* bframe = conf->get("bframe"); + if (bframe) { + string v = bframe->arg0() == "keep" ? "on" : "off"; + conf->get_or_create("keep_bframe")->set_arg0(v); + conf->remove(bframe); srs_freep(bframe); + srs_warn("transform: vhost.rtc.bframe to vhost.rtc.keep_bframe %s", v.c_str()); + } + + ++it; + continue; + } ++it; } @@ -2782,7 +2808,7 @@ 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 != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str()); } } @@ -3641,9 +3667,9 @@ bool SrsConfig::get_rtc_enabled(string vhost) return SRS_CONF_PERFER_FALSE(conf->arg0()); } -bool SrsConfig::get_rtc_bframe_discard(string vhost) +bool SrsConfig::get_rtc_keep_bframe(string vhost) { - static bool DEFAULT = true; + static bool DEFAULT = false; SrsConfDirective* conf = get_rtc(vhost); @@ -3651,17 +3677,17 @@ bool SrsConfig::get_rtc_bframe_discard(string vhost) return DEFAULT; } - conf = conf->get("bframe"); + conf = conf->get("keep_bframe"); if (!conf || conf->arg0().empty()) { return DEFAULT; } - return conf->arg0() != "keep"; + return SRS_CONF_PERFER_FALSE(conf->arg0()); } -bool SrsConfig::get_rtc_aac_discard(string vhost) +bool SrsConfig::get_rtc_from_rtmp(string vhost) { - static bool DEFAULT = true; + static bool DEFAULT = false; SrsConfDirective* conf = get_rtc(vhost); @@ -3669,12 +3695,12 @@ bool SrsConfig::get_rtc_aac_discard(string vhost) return DEFAULT; } - conf = conf->get("aac"); + conf = conf->get("rtmp_to_rtc"); if (!conf || conf->arg0().empty()) { return DEFAULT; } - return conf->arg0() == "discard"; + return SRS_CONF_PERFER_FALSE(conf->arg0()); } srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index e6854c165..a59962325 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -481,8 +481,8 @@ private: public: SrsConfDirective* get_rtc(std::string vhost); bool get_rtc_enabled(std::string vhost); - bool get_rtc_bframe_discard(std::string vhost); - bool get_rtc_aac_discard(std::string vhost); + bool get_rtc_keep_bframe(std::string vhost); + bool get_rtc_from_rtmp(std::string vhost); srs_utime_t get_rtc_stun_timeout(std::string vhost); bool get_rtc_stun_strict_check(std::string vhost); std::string get_rtc_dtls_role(std::string vhost); diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index d53534940..a07e61d10 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -707,8 +707,8 @@ SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source) source_ = source; format = new SrsRtmpFormat(); codec_ = new SrsAudioTranscoder(); - discard_aac = false; - discard_bframe = false; + rtmp_to_rtc = false; + keep_bframe = false; merge_nalus = false; meta = new SrsMetaCache(); audio_sequence = 0; @@ -743,22 +743,24 @@ srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r) srs_error_t err = srs_success; req = r; + rtmp_to_rtc = _srs_config->get_rtc_from_rtmp(req->vhost); - if ((err = format->initialize()) != srs_success) { - return srs_error_wrap(err, "format initialize"); + if (rtmp_to_rtc) { + if ((err = format->initialize()) != srs_success) { + return srs_error_wrap(err, "format initialize"); + } + + int bitrate = 48000; // The output bitrate in bps. + if ((err = codec_->initialize(SrsAudioCodecIdAAC, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, + bitrate)) != srs_success) { + return srs_error_wrap(err, "init codec"); + } } - int bitrate = 48000; // The output bitrate in bps. - if ((err = codec_->initialize(SrsAudioCodecIdAAC, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) { - return srs_error_wrap(err, "init codec"); - } - - // TODO: FIXME: Support reload. - discard_aac = _srs_config->get_rtc_aac_discard(req->vhost); - discard_bframe = _srs_config->get_rtc_bframe_discard(req->vhost); + keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost); merge_nalus = _srs_config->get_rtc_server_merge_nalus(); - srs_trace("RTC bridge from RTMP, discard_aac=%d, discard_bframe=%d, merge_nalus=%d", - discard_aac, discard_bframe, merge_nalus); + srs_trace("RTC bridge from RTMP, rtmp2rtc=%d, keep_bframe=%d, merge_nalus=%d", + rtmp_to_rtc, keep_bframe, merge_nalus); return err; } @@ -767,6 +769,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish() { srs_error_t err = srs_success; + if (!rtmp_to_rtc) { + return err; + } + // TODO: FIXME: Should sync with bridger? if ((err = source_->on_publish()) != srs_success) { return srs_error_wrap(err, "source publish"); @@ -781,6 +787,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish() void SrsRtcFromRtmpBridger::on_unpublish() { + if (!rtmp_to_rtc) { + return; + } + // Reset the metadata cache, to make VLC happy when disable/enable stream. // @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448 meta->update_previous_vsh(); @@ -795,6 +805,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg) { srs_error_t err = srs_success; + if (!rtmp_to_rtc) { + return err; + } + // TODO: FIXME: Support parsing OPUS for RTC. if ((err = format->on_audio(msg)) != srs_success) { return srs_error_wrap(err, "format consume audio"); @@ -813,7 +827,7 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg) } // When drop aac audio packet, never transcode. - if (discard_aac && acodec == SrsAudioCodecIdAAC) { + if (acodec != SrsAudioCodecIdAAC) { return err; } @@ -905,6 +919,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg) { srs_error_t err = srs_success; + if (!rtmp_to_rtc) { + return err; + } + // cache the sequence header if h264 bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size); if (is_sequence_header && (err = meta->update_vsh(msg)) != srs_success) { @@ -993,7 +1011,7 @@ srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* f // Because RTC does not support B-frame, so we will drop them. // TODO: Drop B-frame in better way, which not cause picture corruption. - if (discard_bframe) { + if (!keep_bframe) { if ((err = sample->parse_bframe()) != srs_success) { return srs_error_wrap(err, "parse bframe"); } diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index cfe694a41..d49e6f230 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -254,9 +254,9 @@ private: // The metadata cache. SrsMetaCache* meta; private: - bool discard_aac; + bool rtmp_to_rtc; SrsAudioTranscoder* codec_; - bool discard_bframe; + bool keep_bframe; bool merge_nalus; uint16_t audio_sequence; uint16_t video_sequence; diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 5e936953a..cd876d483 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 173 +#define VERSION_REVISION 174 #endif