Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor gb28181, supporting SIP server enable, multiplex, API interface #1679

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 62 additions & 37 deletions trunk/conf/push.gb28181.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ daemon off;
pid ./objs/srs28181.pid;
srs_log_file ./objs/srs28181.log;
srs_log_tank console;

http_api {
enabled on;
listen 1985;
}

stream_caster {
enabled on;
caster gb28181;

#rtmp输出地址,可以参数化
#[stream] 代表客户端sip设备编号
#[timestamp] 时间戳
output rtmp://127.0.0.1/live/[stream];
#sip监听udp端口
listen 15060;
#转发流到rtmp服务器地址与端口
output 127.0.0.1:1935;
Copy link
Member

@winlinvip winlinvip Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要改成rtmp地址,这样用户可以指定app。' translates to:
'Need to change to rtmp address so that users can specify the app.

TRANS_BY_GPT3

Copy link
Member

@winlinvip winlinvip Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[stream] is the video channel encoding ID.

TRANS_BY_GPT3


#服务器主机号,可以域名或ip地址
#也就是设备端将媒体发送的地址,如果是服务器是内外网
#需要写外网地址
host 192.168.1.27;
#接收设备端rtp流的多路复用端口
listen 9000;

#服务器端编号
#设备端配置编号需要与该值一致,否则无法注册
serial 34020000002000000001;
#rtp接收监听端口范围,最小值
rtp_port_min 58200;
#rtp接收监听端口范围,最大值
rtp_port_max 58300;

#服务器端域
realm 3402000000;
#是否等待关键帧之后,再转发,
#off:不需等待,直接转发
#on:等第一个关键帧后,再转发
wait_keyframe off;

#rtp包空闲等待时间,如果指定时间没有收到任何包
#rtp监听连接自动停止,发送BYE命令
rtp_idle_timeout 30;

#是否转发音频流
#目前只支持aac格式,所以需要设备支持aac格式
Expand All @@ -41,32 +48,50 @@ stream_caster {
#因为flash,只支持11025 22050 44100
audio_enable on;

#服务端发送ack后,接收回应的超时时间,单位为秒
#如果指定时间没有回应,认为失败
ack_timeout 30;
#服务器主机号,可以域名或ip地址
#也就是设备端将媒体发送的地址,如果是服务器是内外网
#需要写外网地址,
#调用api创建stream session时返回ip地址也是host
host 192.168.1.27;
Copy link
Member

@winlinvip winlinvip Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place needs support for a more comprehensive way of obtaining IP, refer to #307 (comment).

TRANS_BY_GPT3


#设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
#认为设备离线
keepalive_timeout 30;
sip {
#是否启用srs内部sip信令
#为on信令走srs, off 只转发ps流
enabled on;

#sip监听udp端口
listen 15060;

#服务器端编号
#设备端配置编号需要与该值一致,否则无法注册
serial 34020000002000000001;

#是否等待关键帧之后,再转发,
#off:不需等待,直接转发
#on:等第一个关键帧后,再转发
wait_keyframe off;
#服务器端域
realm 3402000000;

#日志打印是否打印sip信息
#off:不打印
#on:打印接收或发送sip命令信息
print_sip_message off;

#rtp包空闲等待时间,如果指定时间没有收到任何包
#rtp监听连接自动停止,发送BYE命令
rtp_idle_timeout 30;
#服务端发送ack后,接收回应的超时时间,单位为秒
#如果指定时间没有回应,认为失败
ack_timeout 30;

#rtp接收监听端口范围,最小值
rtp_port_min 58200;
#rtp接收监听端口范围,最大值
rtp_port_max 58300;
#设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
#认为设备离线
keepalive_timeout 30;

#日志打印是否打印sip信息
#off:不打印
#on:打印接收或发送sip命令信息
print_sip_message off;
Copy link
Member

@winlinvip winlinvip Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to log-level, srs_info level log, enable info log.

TRANS_BY_GPT3


#注册之后是否自动给设备端发送invite
#on: 是 off 不是,需要通过api控制
auto_play on;

#设备将流发送的端口,是否固定
#on 发送流到多路复用端口 如9000
#off 自动从rtp_mix_port - rtp_max_port 之间的值中
#选一个可以用的端口
invite_port_fixed on;
}
}
vhost __defaultVhost__ {
}
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
"srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call"
"srs_app_caster_flv" "srs_app_process" "srs_app_ng_exec"
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
"srs_app_coworkers" "srs_app_hybrid" "srs_app_gb28181")
"srs_app_coworkers" "srs_app_hybrid" "srs_app_gb28181" "srs_app_gb28181_sip")
DEFINES=""
# add each modules for app
for SRS_MODULE in ${SRS_MODULES[*]}; do
Expand Down
144 changes: 137 additions & 7 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,10 @@ srs_error_t SrsConfig::global_to_json(SrsJsonObject* obj)
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "print_sip_message") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "invite_port_fixed") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "auto_play") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
}

}
Expand Down Expand Up @@ -3672,12 +3676,24 @@ srs_error_t SrsConfig::check_normal_config()
string n = conf->name;
if (n != "enabled" && n != "caster" && n != "output"
&& n != "listen" && n != "rtp_port_min" && n != "rtp_port_max"
&& n != "rtp_idle_timeout" && n != "ack_timeout" && n != "keepalive_timeout"
&& n != "host" && n != "serial" && n != "realm"
&& n != "rtp_idle_timeout" && n != "sip"
&& n != "audio_enable" && n != "wait_keyframe"
&& n != "print_sip_message") {
&& n != "host") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal stream_caster.%s", n.c_str());
}

if (n == "sip") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "listen"
&& m != "ack_timeout" && m != "keepalive_timeout"
&& m != "host" && m != "serial" && m != "realm"
&& m != "print_sip_message" && m != "auto_play"
&& m != "invite_port_fixed") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal stream_caster.%s", m.c_str());
}
}
}
}
}

Expand Down Expand Up @@ -4207,15 +4223,15 @@ int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* conf)
return ::atoi(conf->arg0().c_str());
}

int SrsConfig::get_stream_caster_gb28181_rtp_ide_timeout(SrsConfDirective* conf)
int SrsConfig::get_stream_caster_gb28181_rtp_idle_timeout(SrsConfDirective* conf)
Copy link
Member

@winlinvip winlinvip Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use srs_utime_t uniformly, which is defined in time, and there are also related macro definitions for converting time. Please make sure to change it together in other places.

TRANS_BY_GPT3

{
static int DEFAULT = 30;

if (!conf) {
return DEFAULT;
}

conf = conf->get("rtp_ide_timeout");
conf = conf->get("rtp_idle_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
Expand All @@ -4230,6 +4246,11 @@ int SrsConfig::get_stream_caster_gb28181_ack_timeout(SrsConfDirective* conf)
if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

conf = conf->get("ack_timeout");
if (!conf || conf->arg0().empty()) {
Expand All @@ -4246,6 +4267,11 @@ int SrsConfig::get_stream_caster_gb28181_keepalive_timeout(SrsConfDirective* con
if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

conf = conf->get("keepalive_timeout");
if (!conf || conf->arg0().empty()) {
Expand All @@ -4257,12 +4283,12 @@ int SrsConfig::get_stream_caster_gb28181_keepalive_timeout(SrsConfDirective* con

string SrsConfig::get_stream_caster_gb28181_host(SrsConfDirective* conf)
{
static string DEFAULT = "127.0.0.1";
static string DEFAULT = "";

if (!conf) {
return DEFAULT;
}

conf = conf->get("host");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
Expand All @@ -4278,6 +4304,11 @@ string SrsConfig::get_stream_caster_gb28181_serial(SrsConfDirective* conf)
if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

conf = conf->get("serial");
if (!conf || conf->arg0().empty()) {
Expand All @@ -4294,6 +4325,11 @@ string SrsConfig::get_stream_caster_gb28181_realm(SrsConfDirective* conf)
if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

conf = conf->get("realm");
if (!conf || conf->arg0().empty()) {
Expand Down Expand Up @@ -4326,6 +4362,11 @@ bool SrsConfig::get_stream_caster_gb28181_print_sip_message(SrsConfDirective* co
if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

conf = conf->get("print_sip_message");
if (!conf || conf->arg0().empty()) {
Expand All @@ -4351,6 +4392,95 @@ bool SrsConfig::get_stream_caster_gb28181_wait_keyframe(SrsConfDirective* conf)
return SRS_CONF_PERFER_FALSE(conf->arg0());
}

bool SrsConfig::get_stream_caster_gb28181_sip_enable(SrsConfDirective* conf)
{
static bool DEFAULT = false;

if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

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

return SRS_CONF_PERFER_FALSE(conf->arg0());

}

bool SrsConfig::get_stream_caster_gb28181_sip_auto_play(SrsConfDirective* conf)
{
static bool DEFAULT = false;

if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

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

return SRS_CONF_PERFER_FALSE(conf->arg0());

}

int SrsConfig::get_stream_caster_gb28181_sip_listen(SrsConfDirective* conf)
{
static int DEFAULT = 0;

if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

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

return ::atoi(conf->arg0().c_str());

}

bool SrsConfig::get_stream_caster_gb28181_sip_invite_port_fixed(SrsConfDirective* conf)
{
static bool DEFAULT = true;

if (!conf) {
return DEFAULT;
}

conf = conf->get("sip");
if (!conf) {
return DEFAULT;
}

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

return SRS_CONF_PERFER_FALSE(conf->arg0());

}


SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);
Expand Down
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class SrsConfig
// Get the max udp port for rtp of stream caster rtsp.
virtual int get_stream_caster_rtp_port_max(SrsConfDirective* conf);

virtual int get_stream_caster_gb28181_rtp_ide_timeout(SrsConfDirective* conf);
virtual int get_stream_caster_gb28181_rtp_idle_timeout(SrsConfDirective* conf);
virtual int get_stream_caster_gb28181_ack_timeout(SrsConfDirective* conf);
virtual int get_stream_caster_gb28181_keepalive_timeout(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_audio_enable(SrsConfDirective* conf);
Expand All @@ -495,6 +495,11 @@ class SrsConfig
virtual std::string get_stream_caster_gb28181_realm(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_print_sip_message(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_wait_keyframe(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_sip_enable(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_sip_auto_play(SrsConfDirective* conf);
virtual int get_stream_caster_gb28181_sip_listen(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_sip_invite_port_fixed(SrsConfDirective* conf);


// vhost specified section
public:
Expand Down
Loading