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 {
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;
}

View file

@ -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;
}

View file

@ -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.

View file

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

View file

@ -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 {

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -522,6 +522,32 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
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)

View file

@ -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);

View file

@ -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");
}

View file

@ -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;

View file

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