Skip to content

Commit

Permalink
RTC: Refine config, aac to rtmp_to_rtc, bframe to keep_bframe. v4.0.174
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 11, 2021
1 parent fe9e43b commit 71ed6e5
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 51 deletions.
2 changes: 1 addition & 1 deletion trunk/conf/clion.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/docker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 9 additions & 12 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/https.rtc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rtc_server {
vhost __defaultVhost__ {
rtc {
enabled on;
bframe discard;
keep_bframe off;
}
}

4 changes: 2 additions & 2 deletions trunk/conf/regression-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/rtc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/rtc2rtmp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/rtmp2rtc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/srs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/srt2rtc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 35 additions & 9 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -3641,40 +3667,40 @@ 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);

if (!conf) {
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);

if (!conf) {
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)
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ class SrsConfig
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);
Expand Down
48 changes: 33 additions & 15 deletions trunk/src/app/srs_app_rtc_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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");
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtc_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ class SrsRtcFromRtmpBridger : public ISrsLiveSourceBridger
// 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;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 173
#define VERSION_REVISION 174

#endif

0 comments on commit 71ed6e5

Please sign in to comment.