Skip to content

Commit ae95246

Browse files
xialixin@kanzhun.comwinlinvip
authored andcommitted
For #2200, Support tansmux RTC to RTMP
1 parent d4aead5 commit ae95246

11 files changed

+1845
-5
lines changed

trunk/conf/rtc_to_rtmp.conf

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
listen 1935;
3+
max_connections 1000;
4+
srs_log_file ./objs/srs.log;
5+
srs_log_tank console;
6+
daemon off;
7+
8+
http_server {
9+
enabled on;
10+
listen 8080;
11+
dir ./research/players;
12+
13+
https {
14+
enabled off;
15+
listen 443;
16+
key ./conf/server.key;
17+
cert ./conf/server.crt;
18+
}
19+
20+
}
21+
22+
http_api {
23+
enabled on;
24+
listen 1985;
25+
https {
26+
enabled off;
27+
listen 443;
28+
key ./conf/server.key;
29+
cert ./conf/server.crt;
30+
}
31+
}
32+
stats {
33+
network 0;
34+
}
35+
rtc_server {
36+
enabled on;
37+
# Listen at udp://8000
38+
listen 8000;
39+
#
40+
# The $CANDIDATE means fetch from env, if not configed, use * as default.
41+
#
42+
# The * means retrieving server IP automatically, from all network interfaces,
43+
# @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
44+
candidate $CANDIDATE;
45+
46+
to_rtmp {
47+
enabled on;
48+
output rtmp://127.0.0.1:1935/[app]/[stream];
49+
audio_enabled off;
50+
audio_foramt rtp;
51+
req_keyframe 0;
52+
keyframe_interval_print 10;
53+
}
54+
}
55+
56+
vhost __defaultVhost__ {
57+
rtc {
58+
enabled on;
59+
bframe discard;
60+
}
61+
62+
http_remux {
63+
enabled on;
64+
mount [vhost]/[app]/[stream].flv;
65+
}
66+
67+
tcp_nodelay on
68+
min_latency on;
69+
70+
play {
71+
gop_cache off;
72+
queue_length 10;
73+
mw_latency 100;
74+
}
75+
}
76+

trunk/configure

+2-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc
279279
"srs_app_coworkers" "srs_app_hybrid")
280280
if [[ $SRS_RTC == YES ]]; then
281281
MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp"
282-
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
282+
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api"
283+
"srs_app_rtc_to_rtmp")
283284
fi
284285
if [[ $SRS_FFMPEG_FIT == YES ]]; then
285286
MODULE_FILES+=("srs_app_rtc_codec")

trunk/src/app/srs_app_config.cpp

+243-1
Original file line numberDiff line numberDiff line change
@@ -3651,7 +3651,7 @@ srs_error_t SrsConfig::check_normal_config()
36513651
string n = conf->at(i)->name;
36523652
if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa"
36533653
&& n != "encrypt" && n != "reuseport" && n != "merge_nalus" && n != "perf_stat" && n != "black_hole"
3654-
&& n != "ip_family") {
3654+
&& n != "ip_family" && n != "to_rtmp") {
36553655
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str());
36563656
}
36573657
}
@@ -4946,6 +4946,248 @@ std::string SrsConfig::get_rtc_server_black_hole_addr()
49464946
return conf->arg0();
49474947
}
49484948

4949+
int SrsConfig::get_rtc_server_rtmp_opus_payload_type()
4950+
{
4951+
static int DEFAULT = 0;
4952+
4953+
SrsConfDirective* conf = root->get("rtc_server");
4954+
if (!conf) {
4955+
return DEFAULT;
4956+
}
4957+
4958+
conf = conf->get("to_rtmp");
4959+
if (!conf) {
4960+
return DEFAULT;
4961+
}
4962+
4963+
conf = conf->get("opus_payload_type");
4964+
if (!conf) {
4965+
return DEFAULT;
4966+
}
4967+
4968+
return ::atoi(conf->arg0().c_str());
4969+
}
4970+
4971+
bool SrsConfig::get_rtc_server_rtmp_enabled()
4972+
{
4973+
static bool DEFAULT = false;
4974+
4975+
SrsConfDirective* conf = root->get("rtc_server");
4976+
if (!conf) {
4977+
return DEFAULT;
4978+
}
4979+
4980+
conf = conf->get("to_rtmp");
4981+
if (!conf) {
4982+
return DEFAULT;
4983+
}
4984+
4985+
conf = conf->get("enabled");
4986+
if (!conf || conf->arg0().empty()) {
4987+
return DEFAULT;
4988+
}
4989+
4990+
return SRS_CONF_PERFER_FALSE(conf->arg0());
4991+
}
4992+
4993+
std::string SrsConfig::get_rtc_server_rtmp_output()
4994+
{
4995+
static std::string DEFAULT = "";
4996+
4997+
SrsConfDirective* conf = root->get("rtc_server");
4998+
if (!conf) {
4999+
return DEFAULT;
5000+
}
5001+
5002+
conf = conf->get("to_rtmp");
5003+
if (!conf) {
5004+
return DEFAULT;
5005+
}
5006+
5007+
conf = conf->get("output");
5008+
if (!conf) {
5009+
return DEFAULT;
5010+
}
5011+
5012+
return conf->arg0().c_str();
5013+
}
5014+
5015+
bool SrsConfig::get_rtc_server_rtmp_source_copy()
5016+
{
5017+
static bool DEFAULT = false;
5018+
5019+
SrsConfDirective* conf = root->get("rtc_server");
5020+
if (!conf) {
5021+
return DEFAULT;
5022+
}
5023+
5024+
conf = conf->get("to_rtmp");
5025+
if (!conf) {
5026+
return DEFAULT;
5027+
}
5028+
5029+
conf = conf->get("source_copy");
5030+
if (!conf || conf->arg0().empty()) {
5031+
return DEFAULT;
5032+
}
5033+
5034+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5035+
}
5036+
5037+
std::string SrsConfig::get_rtc_server_rtmp_audio_format()
5038+
{
5039+
static std::string DEFAULT = "rtp";
5040+
5041+
SrsConfDirective* conf = root->get("rtc_server");
5042+
if (!conf) {
5043+
return DEFAULT;
5044+
}
5045+
5046+
conf = conf->get("to_rtmp");
5047+
if (!conf) {
5048+
return DEFAULT;
5049+
}
5050+
5051+
conf = conf->get("audio_format");
5052+
if (!conf || conf->arg0().empty()) {
5053+
return DEFAULT;
5054+
}
5055+
5056+
return conf->arg0().c_str();
5057+
}
5058+
5059+
std::string SrsConfig::get_rtc_server_rtmp_record_path()
5060+
{
5061+
static std::string DEFAULT = "record";
5062+
5063+
SrsConfDirective* conf = root->get("rtc_server");
5064+
if (!conf) {
5065+
return DEFAULT;
5066+
}
5067+
5068+
conf = conf->get("to_rtmp");
5069+
if (!conf) {
5070+
return DEFAULT;
5071+
}
5072+
5073+
conf = conf->get("record_path");
5074+
if (!conf) {
5075+
return DEFAULT;
5076+
}
5077+
5078+
return conf->arg0().c_str();
5079+
}
5080+
5081+
int SrsConfig::get_rtc_server_rtmp_keyframe_interval_print()
5082+
{
5083+
static int DEFAULT = 10;
5084+
5085+
SrsConfDirective* conf = root->get("rtc_server");
5086+
if (!conf) {
5087+
return DEFAULT;
5088+
}
5089+
5090+
conf = conf->get("to_rtmp");
5091+
if (!conf) {
5092+
return DEFAULT;
5093+
}
5094+
5095+
conf = conf->get("keyframe_interval_print");
5096+
if (!conf) {
5097+
return DEFAULT;
5098+
}
5099+
5100+
return ::atoi(conf->arg0().c_str());
5101+
}
5102+
5103+
int SrsConfig::get_rtc_server_rtmp_req_keyframe()
5104+
{
5105+
static int DEFAULT = 0;
5106+
5107+
SrsConfDirective* conf = root->get("rtc_server");
5108+
if (!conf) {
5109+
return DEFAULT;
5110+
}
5111+
5112+
conf = conf->get("to_rtmp");
5113+
if (!conf) {
5114+
return DEFAULT;
5115+
}
5116+
5117+
conf = conf->get("req_keyframe");
5118+
if (!conf) {
5119+
return DEFAULT;
5120+
}
5121+
5122+
return ::atoi(conf->arg0().c_str());
5123+
}
5124+
5125+
bool SrsConfig::get_rtc_server_rtmp_record_video()
5126+
{
5127+
static bool DEFAULT = false;
5128+
5129+
SrsConfDirective* conf = root->get("rtc_server");
5130+
if (!conf) {
5131+
return DEFAULT;
5132+
}
5133+
5134+
conf = conf->get("to_rtmp");
5135+
if (!conf) {
5136+
return DEFAULT;
5137+
}
5138+
5139+
conf = conf->get("record_video");
5140+
if (!conf || conf->arg0().empty()) {
5141+
return DEFAULT;
5142+
}
5143+
5144+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5145+
}
5146+
5147+
bool SrsConfig::get_rtc_server_rtmp_record_audio()
5148+
{
5149+
static bool DEFAULT = false;
5150+
5151+
SrsConfDirective* conf = root->get("rtc_server");
5152+
if (!conf) {
5153+
return DEFAULT;
5154+
}
5155+
5156+
conf = conf->get("to_rtmp");
5157+
if (!conf) {
5158+
return DEFAULT;
5159+
}
5160+
5161+
conf = conf->get("record_audio");
5162+
if (!conf || conf->arg0().empty()) {
5163+
return DEFAULT;
5164+
}
5165+
5166+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5167+
}
5168+
5169+
bool SrsConfig::get_rtc_server_rtmp_audio_enabled()
5170+
{
5171+
static bool DEFAULT = false;
5172+
5173+
SrsConfDirective* conf = root->get("rtc_server");
5174+
if (!conf) {
5175+
return DEFAULT;
5176+
}
5177+
5178+
conf = conf->get("to_rtmp");
5179+
if (!conf) {
5180+
return DEFAULT;
5181+
}
5182+
5183+
conf = conf->get("audio_enabled");
5184+
if (!conf || conf->arg0().empty()) {
5185+
return DEFAULT;
5186+
}
5187+
5188+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5189+
}
5190+
49495191
SrsConfDirective* SrsConfig::get_rtc(string vhost)
49505192
{
49515193
SrsConfDirective* conf = get_vhost(vhost);

trunk/src/app/srs_app_config.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,19 @@ class SrsConfig
536536
virtual bool get_rtc_server_perf_stat();
537537
virtual bool get_rtc_server_black_hole();
538538
virtual std::string get_rtc_server_black_hole_addr();
539+
540+
virtual int get_rtc_server_rtmp_opus_payload_type();
541+
virtual bool get_rtc_server_rtmp_enabled();
542+
virtual std::string get_rtc_server_rtmp_output();
543+
virtual bool get_rtc_server_rtmp_source_copy();
544+
virtual std::string get_rtc_server_rtmp_audio_format();
545+
virtual std::string get_rtc_server_rtmp_record_path();
546+
virtual int get_rtc_server_rtmp_keyframe_interval_print();
547+
virtual int get_rtc_server_rtmp_req_keyframe();
548+
virtual bool get_rtc_server_rtmp_record_video();
549+
virtual bool get_rtc_server_rtmp_record_audio();
550+
virtual bool get_rtc_server_rtmp_audio_enabled();
551+
539552
private:
540553
virtual int get_rtc_server_reuseport2();
541554

0 commit comments

Comments
 (0)