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

RTC: Refine config, aac to rtmp_to_rtc, bframe to keep_bframe. v4.0.174

This commit is contained in:
winlin 2021-10-11 22:14:45 +08:00
parent fe9e43b6d4
commit 71ed6e5dc5
16 changed files with 94 additions and 52 deletions

View file

@ -33,7 +33,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp on; rtc_to_rtmp on;
} }

View file

@ -31,7 +31,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp off; rtc_to_rtmp off;
} }

View file

@ -459,19 +459,16 @@ vhost rtc.vhost.srs.com {
# default: 0 # default: 0
drop_for_pt 0; drop_for_pt 0;
############################################################### ###############################################################
# For transmuxing RTMP to RTC, the strategy for bframe. # Whether enable transmuxing RTMP to RTC.
# keep Keep bframe, which may make browser with playing problems. # If enabled, transcode aac to opus.
# discard Discard bframe, maybe cause browser with little problems. # default: off
# default: discard rtmp_to_rtc off;
bframe discard; # Whether keep B-frame, which is normal feature in live streaming,
# For transmuxing RTMP to RTC, the strategy for aac audio. # but usually disabled in RTC.
# transcode Transcode aac to opus. # default: off
# discard Discard aac audio packet. keep_bframe off;
# default: discard
aac discard;
############################################################### ###############################################################
# For transmuxing RTC to RTMP. # Whether enable transmuxing RTC to RTMP.
# Whether trans-mux RTC to RTMP streaming.
# Default: off # Default: off
rtc_to_rtmp off; rtc_to_rtmp off;
# The PLI interval in seconds, for RTC to RTMP. # The PLI interval in seconds, for RTC to RTMP.

View file

@ -44,7 +44,7 @@ rtc_server {
vhost __defaultVhost__ { vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
bframe discard; keep_bframe off;
} }
} }

View file

@ -27,8 +27,8 @@ rtc_server {
vhost __defaultVhost__ { vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
bframe discard; rtmp_to_rtc on;
aac transcode; keep_bframe off;
rtc_to_rtmp on; rtc_to_rtmp on;
} }
play { play {

View file

@ -30,7 +30,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp off; rtc_to_rtmp off;
} }

View file

@ -28,7 +28,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp on; rtc_to_rtmp on;
} }

View file

@ -28,7 +28,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp on; rtc_to_rtmp on;
} }

View file

@ -32,7 +32,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp off; rtc_to_rtmp off;
} }

View file

@ -41,7 +41,7 @@ vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
# @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc # @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 # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
rtc_to_rtmp off; rtc_to_rtmp off;
} }

View file

@ -8,6 +8,7 @@ The changelog for SRS.
## SRS 4.0 Changelog ## 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, 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, 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 * v4.0, 2021-10-10, Fix [#2304](https://github.com/ossrs/srs/issues/2304) Remove Push RTSP feature. v4.0.171

View file

@ -522,6 +522,32 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
continue; 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; ++it;
} }
} }
@ -2782,7 +2808,7 @@ srs_error_t SrsConfig::check_normal_config()
if (m != "enabled" && m != "nack" && m != "twcc" && m != "nack_no_copy" if (m != "enabled" && m != "nack" && m != "twcc" && m != "nack_no_copy"
&& m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check" && 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 != "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()); 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()); 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); SrsConfDirective* conf = get_rtc(vhost);
@ -3651,17 +3677,17 @@ bool SrsConfig::get_rtc_bframe_discard(string vhost)
return DEFAULT; return DEFAULT;
} }
conf = conf->get("bframe"); conf = conf->get("keep_bframe");
if (!conf || conf->arg0().empty()) { if (!conf || conf->arg0().empty()) {
return DEFAULT; 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); SrsConfDirective* conf = get_rtc(vhost);
@ -3669,12 +3695,12 @@ bool SrsConfig::get_rtc_aac_discard(string vhost)
return DEFAULT; return DEFAULT;
} }
conf = conf->get("aac"); conf = conf->get("rtmp_to_rtc");
if (!conf || conf->arg0().empty()) { if (!conf || conf->arg0().empty()) {
return DEFAULT; return DEFAULT;
} }
return conf->arg0() == "discard"; return SRS_CONF_PERFER_FALSE(conf->arg0());
} }
srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost) srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost)

View file

@ -481,8 +481,8 @@ private:
public: public:
SrsConfDirective* get_rtc(std::string vhost); SrsConfDirective* get_rtc(std::string vhost);
bool get_rtc_enabled(std::string vhost); bool get_rtc_enabled(std::string vhost);
bool get_rtc_bframe_discard(std::string vhost); bool get_rtc_keep_bframe(std::string vhost);
bool get_rtc_aac_discard(std::string vhost); bool get_rtc_from_rtmp(std::string vhost);
srs_utime_t get_rtc_stun_timeout(std::string vhost); srs_utime_t get_rtc_stun_timeout(std::string vhost);
bool get_rtc_stun_strict_check(std::string vhost); bool get_rtc_stun_strict_check(std::string vhost);
std::string get_rtc_dtls_role(std::string vhost); std::string get_rtc_dtls_role(std::string vhost);

View file

@ -707,8 +707,8 @@ SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source)
source_ = source; source_ = source;
format = new SrsRtmpFormat(); format = new SrsRtmpFormat();
codec_ = new SrsAudioTranscoder(); codec_ = new SrsAudioTranscoder();
discard_aac = false; rtmp_to_rtc = false;
discard_bframe = false; keep_bframe = false;
merge_nalus = false; merge_nalus = false;
meta = new SrsMetaCache(); meta = new SrsMetaCache();
audio_sequence = 0; audio_sequence = 0;
@ -743,22 +743,24 @@ srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r)
srs_error_t err = srs_success; srs_error_t err = srs_success;
req = r; req = r;
rtmp_to_rtc = _srs_config->get_rtc_from_rtmp(req->vhost);
if ((err = format->initialize()) != srs_success) { if (rtmp_to_rtc) {
return srs_error_wrap(err, "format initialize"); 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. keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost);
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);
merge_nalus = _srs_config->get_rtc_server_merge_nalus(); merge_nalus = _srs_config->get_rtc_server_merge_nalus();
srs_trace("RTC bridge from RTMP, discard_aac=%d, discard_bframe=%d, merge_nalus=%d", srs_trace("RTC bridge from RTMP, rtmp2rtc=%d, keep_bframe=%d, merge_nalus=%d",
discard_aac, discard_bframe, merge_nalus); rtmp_to_rtc, keep_bframe, merge_nalus);
return err; return err;
} }
@ -767,6 +769,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// TODO: FIXME: Should sync with bridger? // TODO: FIXME: Should sync with bridger?
if ((err = source_->on_publish()) != srs_success) { if ((err = source_->on_publish()) != srs_success) {
return srs_error_wrap(err, "source publish"); return srs_error_wrap(err, "source publish");
@ -781,6 +787,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish()
void SrsRtcFromRtmpBridger::on_unpublish() void SrsRtcFromRtmpBridger::on_unpublish()
{ {
if (!rtmp_to_rtc) {
return;
}
// Reset the metadata cache, to make VLC happy when disable/enable stream. // Reset the metadata cache, to make VLC happy when disable/enable stream.
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448 // @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
meta->update_previous_vsh(); meta->update_previous_vsh();
@ -795,6 +805,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// TODO: FIXME: Support parsing OPUS for RTC. // TODO: FIXME: Support parsing OPUS for RTC.
if ((err = format->on_audio(msg)) != srs_success) { if ((err = format->on_audio(msg)) != srs_success) {
return srs_error_wrap(err, "format consume audio"); 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. // When drop aac audio packet, never transcode.
if (discard_aac && acodec == SrsAudioCodecIdAAC) { if (acodec != SrsAudioCodecIdAAC) {
return err; return err;
} }
@ -905,6 +919,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// cache the sequence header if h264 // cache the sequence header if h264
bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size); bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size);
if (is_sequence_header && (err = meta->update_vsh(msg)) != srs_success) { 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. // Because RTC does not support B-frame, so we will drop them.
// TODO: Drop B-frame in better way, which not cause picture corruption. // 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) { if ((err = sample->parse_bframe()) != srs_success) {
return srs_error_wrap(err, "parse bframe"); return srs_error_wrap(err, "parse bframe");
} }

View file

@ -254,9 +254,9 @@ private:
// The metadata cache. // The metadata cache.
SrsMetaCache* meta; SrsMetaCache* meta;
private: private:
bool discard_aac; bool rtmp_to_rtc;
SrsAudioTranscoder* codec_; SrsAudioTranscoder* codec_;
bool discard_bframe; bool keep_bframe;
bool merge_nalus; bool merge_nalus;
uint16_t audio_sequence; uint16_t audio_sequence;
uint16_t video_sequence; uint16_t video_sequence;

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 4 #define VERSION_MAJOR 4
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 173 #define VERSION_REVISION 174
#endif #endif