Skip to content

Commit

Permalink
Bridger: Support RTC2RTMP bridger and shared FastTimer. 4.0.95
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed May 1, 2021
1 parent c770e6d commit 3d22597
Show file tree
Hide file tree
Showing 12 changed files with 700 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Other important wiki:

## V4 changes

* v5.0, 2021-04-20, Support RTC2RTMP bridger and shared FastTimer. 4.0.95
* v5.0, 2021-04-20, Refine transcoder to support aac2opus and opus2aac. 4.0.94
* v4.0, 2021-05-01, Timer: Extract and apply shared FastTimer. 4.0.93
* v4.0, 2021-04-29, RTC: Support AV1 for Chrome M90. 4.0.91
Expand Down
9 changes: 9 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ vhost rtc.vhost.srs.com {
# discard Discard aac audio packet.
# default: transcode
aac transcode;
###############################################################
# For transmuxing RTC to RTMP.
# Whether trans-mux RTC to RTMP streaming.
# Default: off
rtc_to_rtmp off;
# The PLI interval in seconds, for RTC to RTMP.
# Note the available range is [0.5, 30]
# Default: 6.0
pli_for_rtmp 6.0;
}
###############################################################
# For transmuxing RTMP to RTC, it will impact the default values if RTC is on.
Expand Down
43 changes: 42 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,8 @@ srs_error_t SrsConfig::check_normal_config()
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check"
&& m != "dtls_role" && m != "dtls_version" && m != "drop_for_pt") {
&& m != "dtls_role" && m != "dtls_version" && m != "drop_for_pt" && m != "rtc_to_rtmp"
&& m != "pli_for_rtmp") {
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 @@ -5226,6 +5227,46 @@ int SrsConfig::get_rtc_drop_for_pt(string vhost)
return ::atoi(conf->arg0().c_str());
}

bool SrsConfig::get_rtc_to_rtmp(string vhost)
{
static bool DEFAULT = false;

SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}

conf = conf->get("rtc_to_rtmp");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return SRS_CONF_PERFER_FALSE(conf->arg0());
}

srs_utime_t SrsConfig::get_rtc_pli_for_rtmp(string vhost)
{
static srs_utime_t DEFAULT = 6 * SRS_UTIME_SECONDS;

SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}

conf = conf->get("pli_for_rtmp");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

srs_utime_t v = (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
if (v < 500 * SRS_UTIME_MILLISECONDS || v > 30 * SRS_UTIME_SECONDS) {
srs_warn("Reset pli %dms to %dms", srsu2msi(v), srsu2msi(DEFAULT));
return DEFAULT;
}

return v;
}

bool SrsConfig::get_rtc_nack_enabled(string vhost)
{
static bool DEFAULT = true;
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ class SrsConfig
std::string get_rtc_dtls_role(std::string vhost);
std::string get_rtc_dtls_version(std::string vhost);
int get_rtc_drop_for_pt(std::string vhost);
bool get_rtc_to_rtmp(std::string vhost);
srs_utime_t get_rtc_pli_for_rtmp(std::string vhost);
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);
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ srs_error_t SrsUdpMuxListener::listen()

srs_freep(trd);
trd = new SrsSTCoroutine("udp", this, cid);

//change stack size to 256K, fix crash when call some 3rd-part api.
((SrsSTCoroutine*)trd)->set_stack_size(1 << 18);

if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "start thread");
}
Expand Down
22 changes: 22 additions & 0 deletions trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,28 @@ srs_error_t SrsRtcPublishStream::initialize(SrsRequest* r, SrsRtcStreamDescripti
}
source->set_publish_stream(this);

// Bridge to rtmp
bool rtc_to_rtmp = _srs_config->get_rtc_to_rtmp(req->vhost);
if (rtc_to_rtmp) {
SrsSource *rtmp = NULL;
if ((err = _srs_sources->fetch_or_create(r, _srs_hybrid->srs()->instance(), &rtmp)) != srs_success) {
return srs_error_wrap(err, "create source");
}

// TODO: FIMXE: Check it in SrsRtcConnection::add_publisher?
if (!rtmp->can_publish(false)) {
return srs_error_new(ERROR_SYSTEM_STREAM_BUSY, "rtmp stream %s busy", r->get_stream_url().c_str());
}

SrsRtmpFromRtcBridger *bridger = new SrsRtmpFromRtcBridger(rtmp);
if ((err = bridger->initialize(r)) != srs_success) {
srs_freep(bridger);
return srs_error_wrap(err, "create bridger");
}

source->set_bridger(bridger);
}

return err;
}

Expand Down
Loading

0 comments on commit 3d22597

Please sign in to comment.