Skip to content

Commit c5bea4f

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

11 files changed

+1846
-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
@@ -280,7 +280,8 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc
280280
"srs_app_coworkers" "srs_app_hybrid")
281281
if [[ $SRS_RTC == YES ]]; then
282282
MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp"
283-
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
283+
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api"
284+
"srs_app_rtc_to_rtmp")
284285
fi
285286
if [[ $SRS_FFMPEG_FIT == YES ]]; then
286287
MODULE_FILES+=("srs_app_rtc_codec")

trunk/src/app/srs_app_config.cpp

+244-1
Original file line numberDiff line numberDiff line change
@@ -3651,7 +3651,8 @@ 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" && n != "rtp_cache" && n != "rtp_msg_cache") {
3654+
&& n != "ip_family" && n != "rtp_cache" && n != "rtp_msg_cache"
3655+
&& n != "to_rtmp") {
36553656
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str());
36563657
}
36573658
}
@@ -5078,6 +5079,248 @@ std::string SrsConfig::get_rtc_server_black_hole_addr()
50785079
return conf->arg0();
50795080
}
50805081

5082+
int SrsConfig::get_rtc_server_rtmp_opus_payload_type()
5083+
{
5084+
static int DEFAULT = 0;
5085+
5086+
SrsConfDirective* conf = root->get("rtc_server");
5087+
if (!conf) {
5088+
return DEFAULT;
5089+
}
5090+
5091+
conf = conf->get("to_rtmp");
5092+
if (!conf) {
5093+
return DEFAULT;
5094+
}
5095+
5096+
conf = conf->get("opus_payload_type");
5097+
if (!conf) {
5098+
return DEFAULT;
5099+
}
5100+
5101+
return ::atoi(conf->arg0().c_str());
5102+
}
5103+
5104+
bool SrsConfig::get_rtc_server_rtmp_enabled()
5105+
{
5106+
static bool DEFAULT = false;
5107+
5108+
SrsConfDirective* conf = root->get("rtc_server");
5109+
if (!conf) {
5110+
return DEFAULT;
5111+
}
5112+
5113+
conf = conf->get("to_rtmp");
5114+
if (!conf) {
5115+
return DEFAULT;
5116+
}
5117+
5118+
conf = conf->get("enabled");
5119+
if (!conf || conf->arg0().empty()) {
5120+
return DEFAULT;
5121+
}
5122+
5123+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5124+
}
5125+
5126+
std::string SrsConfig::get_rtc_server_rtmp_output()
5127+
{
5128+
static std::string DEFAULT = "";
5129+
5130+
SrsConfDirective* conf = root->get("rtc_server");
5131+
if (!conf) {
5132+
return DEFAULT;
5133+
}
5134+
5135+
conf = conf->get("to_rtmp");
5136+
if (!conf) {
5137+
return DEFAULT;
5138+
}
5139+
5140+
conf = conf->get("output");
5141+
if (!conf) {
5142+
return DEFAULT;
5143+
}
5144+
5145+
return conf->arg0().c_str();
5146+
}
5147+
5148+
bool SrsConfig::get_rtc_server_rtmp_source_copy()
5149+
{
5150+
static bool DEFAULT = false;
5151+
5152+
SrsConfDirective* conf = root->get("rtc_server");
5153+
if (!conf) {
5154+
return DEFAULT;
5155+
}
5156+
5157+
conf = conf->get("to_rtmp");
5158+
if (!conf) {
5159+
return DEFAULT;
5160+
}
5161+
5162+
conf = conf->get("source_copy");
5163+
if (!conf || conf->arg0().empty()) {
5164+
return DEFAULT;
5165+
}
5166+
5167+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5168+
}
5169+
5170+
std::string SrsConfig::get_rtc_server_rtmp_audio_format()
5171+
{
5172+
static std::string DEFAULT = "rtp";
5173+
5174+
SrsConfDirective* conf = root->get("rtc_server");
5175+
if (!conf) {
5176+
return DEFAULT;
5177+
}
5178+
5179+
conf = conf->get("to_rtmp");
5180+
if (!conf) {
5181+
return DEFAULT;
5182+
}
5183+
5184+
conf = conf->get("audio_format");
5185+
if (!conf || conf->arg0().empty()) {
5186+
return DEFAULT;
5187+
}
5188+
5189+
return conf->arg0().c_str();
5190+
}
5191+
5192+
std::string SrsConfig::get_rtc_server_rtmp_record_path()
5193+
{
5194+
static std::string DEFAULT = "record";
5195+
5196+
SrsConfDirective* conf = root->get("rtc_server");
5197+
if (!conf) {
5198+
return DEFAULT;
5199+
}
5200+
5201+
conf = conf->get("to_rtmp");
5202+
if (!conf) {
5203+
return DEFAULT;
5204+
}
5205+
5206+
conf = conf->get("record_path");
5207+
if (!conf) {
5208+
return DEFAULT;
5209+
}
5210+
5211+
return conf->arg0().c_str();
5212+
}
5213+
5214+
int SrsConfig::get_rtc_server_rtmp_keyframe_interval_print()
5215+
{
5216+
static int DEFAULT = 10;
5217+
5218+
SrsConfDirective* conf = root->get("rtc_server");
5219+
if (!conf) {
5220+
return DEFAULT;
5221+
}
5222+
5223+
conf = conf->get("to_rtmp");
5224+
if (!conf) {
5225+
return DEFAULT;
5226+
}
5227+
5228+
conf = conf->get("keyframe_interval_print");
5229+
if (!conf) {
5230+
return DEFAULT;
5231+
}
5232+
5233+
return ::atoi(conf->arg0().c_str());
5234+
}
5235+
5236+
int SrsConfig::get_rtc_server_rtmp_req_keyframe()
5237+
{
5238+
static int DEFAULT = 0;
5239+
5240+
SrsConfDirective* conf = root->get("rtc_server");
5241+
if (!conf) {
5242+
return DEFAULT;
5243+
}
5244+
5245+
conf = conf->get("to_rtmp");
5246+
if (!conf) {
5247+
return DEFAULT;
5248+
}
5249+
5250+
conf = conf->get("req_keyframe");
5251+
if (!conf) {
5252+
return DEFAULT;
5253+
}
5254+
5255+
return ::atoi(conf->arg0().c_str());
5256+
}
5257+
5258+
bool SrsConfig::get_rtc_server_rtmp_record_video()
5259+
{
5260+
static bool DEFAULT = false;
5261+
5262+
SrsConfDirective* conf = root->get("rtc_server");
5263+
if (!conf) {
5264+
return DEFAULT;
5265+
}
5266+
5267+
conf = conf->get("to_rtmp");
5268+
if (!conf) {
5269+
return DEFAULT;
5270+
}
5271+
5272+
conf = conf->get("record_video");
5273+
if (!conf || conf->arg0().empty()) {
5274+
return DEFAULT;
5275+
}
5276+
5277+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5278+
}
5279+
5280+
bool SrsConfig::get_rtc_server_rtmp_record_audio()
5281+
{
5282+
static bool DEFAULT = false;
5283+
5284+
SrsConfDirective* conf = root->get("rtc_server");
5285+
if (!conf) {
5286+
return DEFAULT;
5287+
}
5288+
5289+
conf = conf->get("to_rtmp");
5290+
if (!conf) {
5291+
return DEFAULT;
5292+
}
5293+
5294+
conf = conf->get("record_audio");
5295+
if (!conf || conf->arg0().empty()) {
5296+
return DEFAULT;
5297+
}
5298+
5299+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5300+
}
5301+
5302+
bool SrsConfig::get_rtc_server_rtmp_audio_enabled()
5303+
{
5304+
static bool DEFAULT = false;
5305+
5306+
SrsConfDirective* conf = root->get("rtc_server");
5307+
if (!conf) {
5308+
return DEFAULT;
5309+
}
5310+
5311+
conf = conf->get("to_rtmp");
5312+
if (!conf) {
5313+
return DEFAULT;
5314+
}
5315+
5316+
conf = conf->get("audio_enabled");
5317+
if (!conf || conf->arg0().empty()) {
5318+
return DEFAULT;
5319+
}
5320+
5321+
return SRS_CONF_PERFER_FALSE(conf->arg0());
5322+
}
5323+
50815324
SrsConfDirective* SrsConfig::get_rtc(string vhost)
50825325
{
50835326
SrsConfDirective* conf = get_vhost(vhost);

trunk/src/app/srs_app_config.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,19 @@ class SrsConfig
549549
public:
550550
virtual bool get_rtc_server_black_hole();
551551
virtual std::string get_rtc_server_black_hole_addr();
552+
553+
virtual int get_rtc_server_rtmp_opus_payload_type();
554+
virtual bool get_rtc_server_rtmp_enabled();
555+
virtual std::string get_rtc_server_rtmp_output();
556+
virtual bool get_rtc_server_rtmp_source_copy();
557+
virtual std::string get_rtc_server_rtmp_audio_format();
558+
virtual std::string get_rtc_server_rtmp_record_path();
559+
virtual int get_rtc_server_rtmp_keyframe_interval_print();
560+
virtual int get_rtc_server_rtmp_req_keyframe();
561+
virtual bool get_rtc_server_rtmp_record_video();
562+
virtual bool get_rtc_server_rtmp_record_audio();
563+
virtual bool get_rtc_server_rtmp_audio_enabled();
564+
552565
private:
553566
virtual int get_rtc_server_reuseport2();
554567

0 commit comments

Comments
 (0)