Support gb28181 sip over udp, ps steam over rtp

pull/1653/head
xialixin 5 years ago
parent d6e11706ec
commit cbe9c1dabc

@ -0,0 +1,71 @@
# push gb28281 stream to SRS.
listen 1935;
max_connections 1000;
daemon off;
pid ./objs/srs28181.pid
srs_log_tank console;
stream_caster {
enabled on;
caster gb28181;
#rtmp输出地址可以参数化
#[stream] 代表客户端sip设备编号
#[timestamp] 时间戳
output rtmp://127.0.0.1/live/[stream];
#sip监听udp端口
listen 15060;
#服务器主机号可以域名或ip地址
#也就是设备端将媒体发送的地址,如果是服务器是内外网
#需要写外网地址
host 192.168.1.27;
#服务器端编号
#设备端配置编号需要与该值一致,否则无法注册
serial 34020000002020000001;
#服务器端域
realm 3402000000;
#是否转发音频流
#目前只支持aac格式所以需要设备支持aac格式
#on:转发音频
#off:不转发音频,只有视频
#*注意*!!!:flv 只支持11025 22050 44100 三种
#如果设备端没有三种中任何一个,转发时为自动选择一种格式
#同时也会将adts的头封装在flv aac raw数据中
#这样的话播放器为自动通过adts头自动选择采样频率
#像ffplay, vlc都可以但是flash是没有声音
#因为flash,只支持11025 22050 44100
audio_enable on;
#服务端发送ack后接收回应的超时时间单位为秒
#如果指定时间没有回应,认为失败
ack_timeout 30;
#设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
#认为设备离线
keepalive_timeout 30;
#是否等待关键帧之后,再转发,
#off:不需等待,直接转发
#on:等第一个关键帧后,再转发
wait_keyframe off;
#日志打印是否打印sip信息
#off:不打印
#on:打印接收或发送sip命令信息
print_sip_message off;
#rtp包空闲等待时间如果指定时间没有收到任何包
#rtp监听连接自动停止发送BYE命令
rtp_idle_timeout 30;
#rtp接收监听端口范围最小值
rtp_port_min 58200;
#rtp接收监听端口范围最大值
rtp_port_max 58300;
}
vhost __defaultVhost__ {
}

4
trunk/configure vendored

@ -213,7 +213,7 @@ MODULE_DEPENDS=("CORE" "KERNEL")
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot})
MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
"srs_rtmp_handshake" "srs_protocol_utility" "srs_rtmp_msg_array" "srs_protocol_stream"
"srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json"
"srs_raw_avc" "srs_rtsp_stack" "srs_sip_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json"
"srs_protocol_format")
PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
PROTOCOL_OBJS="${MODULE_OBJS[@]}"
@ -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_coworkers" "srs_app_hybrid" "srs_app_gb28181")
DEFINES=""
# add each modules for app
for SRS_MODULE in ${SRS_MODULES[*]}; do

@ -275,6 +275,11 @@ bool srs_stream_caster_is_flv(string caster)
return caster == "flv";
}
bool srs_stream_caster_is_gb28181(string caster)
{
return caster == "gb28181";
}
bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req)
{
static bool DEFAULT = true;
@ -2137,7 +2142,26 @@ srs_error_t SrsConfig::global_to_json(SrsJsonObject* obj)
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
} else if (sdir->name == "rtp_port_max") {
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
} else if (sdir->name == "rtp_idle_timeout") {
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
} else if (sdir->name == "ack_timeout") {
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
} else if (sdir->name == "keepalive_timeout") {
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
} else if (sdir->name == "audio_enable") {
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
} else if (sdir->name == "host") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "serial") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "realm") {
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
} else if (sdir->name == "wait_keyframe") {
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());
}
}
obj->set(dir->name, sobj);
} else {
@ -3647,7 +3671,11 @@ srs_error_t SrsConfig::check_normal_config()
SrsConfDirective* conf = stream_caster->at(i);
string n = conf->name;
if (n != "enabled" && n != "caster" && n != "output"
&& n != "listen" && n != "rtp_port_min" && n != "rtp_port_max") {
&& 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 != "audio_enable" && n != "wait_keyframe"
&& n != "print_sip_message") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal stream_caster.%s", n.c_str());
}
}
@ -4179,6 +4207,150 @@ 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)
{
static int DEFAULT = 30;
if (!conf) {
return DEFAULT;
}
conf = conf->get("rtp_ide_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_stream_caster_gb28181_ack_timeout(SrsConfDirective* conf)
{
static int DEFAULT = 30;
if (!conf) {
return DEFAULT;
}
conf = conf->get("ack_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_stream_caster_gb28181_keepalive_timeout(SrsConfDirective* conf)
{
static int DEFAULT = 30;
if (!conf) {
return DEFAULT;
}
conf = conf->get("keepalive_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
}
string SrsConfig::get_stream_caster_gb28181_host(SrsConfDirective* conf)
{
static string DEFAULT = "127.0.0.1";
if (!conf) {
return DEFAULT;
}
conf = conf->get("host");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_stream_caster_gb28181_serial(SrsConfDirective* conf)
{
static string DEFAULT = "";
if (!conf) {
return DEFAULT;
}
conf = conf->get("serial");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_stream_caster_gb28181_realm(SrsConfDirective* conf)
{
static string DEFAULT = "";
if (!conf) {
return DEFAULT;
}
conf = conf->get("realm");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
bool SrsConfig::get_stream_caster_gb28181_audio_enable(SrsConfDirective* conf)
{
static bool DEFAULT = true;
if (!conf) {
return DEFAULT;
}
conf = conf->get("audio_enable");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_stream_caster_gb28181_print_sip_message(SrsConfDirective* conf)
{
static bool DEFAULT = false;
if (!conf) {
return DEFAULT;
}
conf = conf->get("print_sip_message");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_stream_caster_gb28181_wait_keyframe(SrsConfDirective* conf)
{
static bool DEFAULT = false;
if (!conf) {
return DEFAULT;
}
conf = conf->get("wait_keyframe");
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);

@ -119,6 +119,7 @@ extern bool srs_config_dvr_is_plan_session(std::string plan);
extern bool srs_stream_caster_is_udp(std::string caster);
extern bool srs_stream_caster_is_rtsp(std::string caster);
extern bool srs_stream_caster_is_flv(std::string caster);
extern bool srs_stream_caster_is_gb28181(std::string caster);
// Whether the dvr_apply active the stream specified by req.
extern bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req);
@ -484,6 +485,17 @@ public:
virtual int get_stream_caster_rtp_port_min(SrsConfDirective* conf);
// 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_ack_timeout(SrsConfDirective* conf);
virtual int get_stream_caster_gb28181_keepalive_timeout(SrsConfDirective* conf);
virtual bool get_stream_caster_gb28181_audio_enable(SrsConfDirective* conf);
virtual std::string get_stream_caster_gb28181_host(SrsConfDirective* conf);
virtual std::string get_stream_caster_gb28181_serial(SrsConfDirective* conf);
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);
// vhost specified section
public:
// Get the vhost directive by vhost name.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,330 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2013-2020 Winlin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_APP_GB28181_HPP
#define SRS_APP_GB28181_HPP
#include <srs_core.hpp>
#include <arpa/inet.h>
#include <string>
#include <vector>
#include <map>
#include <srs_app_st.hpp>
#include <srs_app_thread.hpp>
#include <srs_app_listener.hpp>
#include <srs_rtsp_stack.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_app_log.hpp>
#include <srs_kernel_file.hpp>
class SrsStSocket;
class SrsRtpConn;
class SrsRtspConn;
class SrsRtspStack;
class SrsRtspCaster;
class SrsConfDirective;
class SrsRtpPacket;
class SrsRequest;
class SrsStSocket;
class SrsRtmpClient;
class SrsRawH264Stream;
class SrsRawAacStream;
struct SrsRawAacStreamCodec;
class SrsSharedPtrMessage;
class SrsAudioFrame;
class SrsSimpleStream;
class SrsPithyPrint;
class SrsSimpleRtmpClient;
class SrsSipStack;
class SrsGb28181Caster;
class SrsRtspJitter;
class SrsRtspAudioCache;
class SrsSipRequest;
class SrsGb28181Conn;
class SrsGb28281ClientInfo;
/* gb28181 program stream struct define
*/
struct SrsPsPacketStartCode
{
uint8_t start_code[3];
uint8_t stream_id[1];
};
struct SrsPsPacketHeader
{
SrsPsPacketStartCode start;// 4
uint8_t info[9];
uint8_t stuffing_length;
};
struct SrsPsPacketBBHeader
{
SrsPsPacketStartCode start;
uint16_t length;
};
struct SrsPsePacket
{
SrsPsPacketStartCode start;
uint16_t length;
uint8_t info[2];
uint8_t stuffing_length;
};
struct SrsPsMapPacket
{
SrsPsPacketStartCode start;
uint16_t length;
};
class SrsPsRtpPacket: public SrsRtpPacket
{
public:
SrsPsRtpPacket();
virtual ~SrsPsRtpPacket();
public:
virtual srs_error_t decode(SrsBuffer* stream);
};
// A rtp connection which transport a stream.
class SrsPsRtpConn: public ISrsUdpHandler
{
private:
SrsPithyPrint* pprint;
SrsUdpListener* listener;
SrsGb28181Conn* gb28181;
SrsPsRtpPacket* cache;
std::map<uint32_t, SrsSimpleStream*> cache_payload;
std::string session_id;
int _port;
uint32_t pre_timestamp;
SrsFileWriter ps_fw;
SrsFileWriter video_fw;
SrsFileWriter audio_fw;
bool first_keyframe_flag;
bool wait_first_keyframe;
bool audio_enable;
public:
SrsPsRtpConn(SrsGb28181Conn* r, int p, std::string sid, bool a, bool k);
virtual ~SrsPsRtpConn();
private:
int64_t parse_ps_timestamp(const uint8_t* p);
private:
bool can_send_ps_av_packet();
void dispose();
public:
virtual int port();
virtual srs_error_t listen();
// Interface ISrsUdpHandler
public:
virtual srs_error_t on_udp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf);
virtual srs_error_t on_ps_stream(char* ps_data, int ps_size, uint32_t timestamp);
};
class SrsGb28281ClientInfo {
public:
SrsGb28281ClientInfo();
virtual ~SrsGb28281ClientInfo();
public:
sockaddr* sock_from;
int sock_fromlen;
srs_netfd_t stfd;
SrsSipRequest *req;
};
enum Srs28181CtrlStatusType{
Srs28181Unkonw = 0,
Srs28181RegisterOk = 1,
Srs28181AliveOk = 2,
Srs28181InviteOk = 3,
Srs28181Trying = 4,
Srs28181Bye = 5,
};
class SrsGb28181Conn : public ISrsCoroutineHandler, public ISrsConnection
{
private:
std::string output_template;
SrsPithyPrint* pprint;
public:
Srs28181CtrlStatusType register_status;
Srs28181CtrlStatusType alive_status;
Srs28181CtrlStatusType invite_status;
srs_utime_t register_time;
srs_utime_t alive_time;
srs_utime_t invite_time;
srs_utime_t recv_rtp_time;
std::string rtmp_url;
int reg_expires;
private:
std::string session_id;
// video stream.
int video_id;
std::string video_codec;
SrsPsRtpConn* video_rtp;
// audio stream.
int audio_id;
std::string audio_codec;
int audio_sample_rate;
int audio_channel;
SrsPsRtpConn* audio_rtp;
public:
SrsGb28281ClientInfo* info;
private:
SrsStSocket* skt;
SrsSipStack* sip;
SrsGb28181Caster* caster;
SrsCoroutine* trd;
private:
SrsSipRequest* req;
SrsSimpleRtmpClient* sdk;
SrsRtspJitter* vjitter;
SrsRtspJitter* ajitter;
private:
SrsRawH264Stream* avc;
std::string h264_sps;
std::string h264_pps;
bool h264_sps_changed;
bool h264_pps_changed;
bool h264_sps_pps_sent;
private:
SrsRawAacStream* aac;
std::string aac_specific_config;
public:
SrsGb28181Conn(SrsGb28181Caster* c, std::string id);
virtual ~SrsGb28181Conn();
public:
virtual srs_error_t serve();
virtual std::string remote_ip();
virtual void set_request_info(SrsSipRequest *req);
virtual std::string get_session_id();
private:
virtual srs_error_t do_cycle();
// internal methods
public:
virtual srs_error_t start_rtp_listen(int port);
virtual srs_error_t stop_rtp_listen();
// Interface ISrsOneCycleThreadHandler
public:
virtual srs_error_t cycle();
public:
virtual srs_error_t on_rtp_video(SrsSimpleStream* stream, int64_t dts, int keyframe);
virtual srs_error_t on_rtp_audio(SrsSimpleStream* stream, int64_t dts);
private:
virtual srs_error_t write_h264_sps_pps(uint32_t dts, uint32_t pts);
virtual srs_error_t write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts, uint32_t pts);
virtual srs_error_t write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts);
virtual srs_error_t rtmp_write_packet(char type, uint32_t timestamp, char* data, int size);
private:
// Connect to RTMP server.
virtual srs_error_t connect();
// Close the connection to RTMP server.
virtual void close();
};
class SrsGb28181Config
{
public:
std::string sip_host;
std::string sip_port;
std::string sip_serial;
std::string sip_realm;
int sip_ack_timeout;
int sip_keepalive_timeout;
int rtp_idle_timeout;
bool audio_enable;
std::string output;
int rtp_port_min;
int rtp_port_max;
int listen_port;
bool print_sip_message;
bool wait_keyframe;
public:
SrsGb28181Config(SrsConfDirective* c);
virtual ~SrsGb28181Config();
};
//gb28181 conn manager
class SrsGb28181Caster : public ISrsUdpHandler
{
private:
SrsGb28181Config *config;
// The key: port, value: whether used.
std::map<int, bool> used_ports;
SrsSipStack *sip;
srs_netfd_t lfd;
private:
std::map<std::string, SrsGb28181Conn*> clients;
SrsCoroutineManager* manager;
public:
SrsGb28181Caster(SrsConfDirective* c);
virtual ~SrsGb28181Caster();
private:
srs_error_t fetch_or_create(SrsSipRequest* r, SrsGb28181Conn** gb28181);
virtual SrsGb28181Conn* fetch(const SrsSipRequest* r);
virtual void destroy();
public:
// Alloc a rtp port from local ports pool.
// @param pport output the rtp port.
virtual srs_error_t alloc_port(int* pport);
// Free the alloced rtp port.
virtual void free_port(int lpmin, int lpmax);
virtual srs_error_t initialize();
virtual void set_stfd(srs_netfd_t fd);
virtual SrsGb28181Config GetGb28181Config();
// Interface ISrsUdpHandler
public:
virtual srs_error_t on_udp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf);
private:
virtual srs_error_t on_udp_bytes(std::string host, int port, char* buf, int nb_buf, sockaddr* from, int fromlen);
// internal methods.
public:
virtual srs_error_t send_message(sockaddr* f, int l, std::stringstream& ss);
virtual srs_error_t send_bye(SrsSipRequest *req, sockaddr *f, int l);
virtual srs_error_t send_ack(SrsSipRequest *req, sockaddr *f, int l);
virtual srs_error_t send_invite(SrsSipRequest *req, sockaddr *f, int l, int port);
virtual srs_error_t send_status(SrsSipRequest *req, sockaddr *f, int l);
virtual void remove(SrsGb28181Conn* conn);
};
#endif

@ -59,6 +59,13 @@ srs_error_t ISrsUdpHandler::on_stfd_change(srs_netfd_t /*fd*/)
return srs_success;
}
void ISrsUdpHandler::set_stfd(srs_netfd_t /*fd*/)
{
}
ISrsTcpHandler::ISrsTcpHandler()
{
}
@ -105,6 +112,8 @@ srs_error_t SrsUdpListener::listen()
return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port);
}
handler->set_stfd(lfd);
srs_freep(trd);
trd = new SrsSTCoroutine("udp", this);
if ((err = trd->start()) != srs_success) {
@ -206,4 +215,3 @@ srs_error_t SrsTcpListener::cycle()
return err;
}

@ -43,6 +43,8 @@ public:
// When fd changed, for instance, reload the listen port,
// notify the handler and user can do something.
virtual srs_error_t on_stfd_change(srs_netfd_t fd);
virtual void set_stfd(srs_netfd_t fd);
public:
// When udp listener got a udp packet, notice server to process it.
// @param type, the client type, used to create concrete connection,

@ -51,6 +51,7 @@ using namespace std;
#include <srs_kernel_consts.hpp>
#include <srs_app_thread.hpp>
#include <srs_app_coworkers.hpp>
#include <srs_app_gb28181.hpp>
// system interval in srs_utime_t,
// all resolution times should be times togother,
@ -108,6 +109,8 @@ std::string srs_listener_type2string(SrsListenerType type)
return "RTSP";
case SrsListenerFlv:
return "HTTP-FLV";
case SrsListenerGb28181:
return "GB28181-SIP over UDP";
default:
return "UNKONWN";
}
@ -298,7 +301,7 @@ srs_error_t SrsUdpStreamListener::listen(string i, int p)
// the caller already ensure the type is ok,
// we just assert here for unknown stream caster.
srs_assert(type == SrsListenerMpegTsOverUdp);
srs_assert(type == SrsListenerMpegTsOverUdp || type == SrsListenerGb28181);
ip = i;
port = p;
@ -336,6 +339,22 @@ SrsUdpCasterListener::~SrsUdpCasterListener()
srs_freep(caster);
}
SrsGb28181Listener::SrsGb28181Listener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c) : SrsUdpStreamListener(svr, t, NULL)
{
// the caller already ensure the type is ok,
// we just assert here for unknown stream caster.
srs_assert(type == SrsListenerGb28181);
if (type == SrsListenerGb28181) {
caster = new SrsGb28181Caster(c);
}
}
SrsGb28181Listener::~SrsGb28181Listener()
{
srs_freep(caster);
}
SrsSignalManager* SrsSignalManager::instance = NULL;
SrsSignalManager::SrsSignalManager(SrsServer* s)
@ -1093,6 +1112,8 @@ srs_error_t SrsServer::listen_stream_caster()
listener = new SrsRtspListener(this, SrsListenerRtsp, stream_caster);
} else if (srs_stream_caster_is_flv(caster)) {
listener = new SrsHttpFlvListener(this, SrsListenerFlv, stream_caster);
} else if (srs_stream_caster_is_gb28181(caster)) {
listener = new SrsGb28181Listener(this, SrsListenerGb28181, stream_caster);
} else {
return srs_error_new(ERROR_STREAM_CASTER_ENGINE, "invalid caster %s", caster.c_str());
}

@ -69,6 +69,8 @@ enum SrsListenerType
SrsListenerRtsp = 4,
// TCP stream, FLV stream over HTTP.
SrsListenerFlv = 5,
// UDP stream, gb28181 stream
SrsListenerGb28181 = 6,
};
// A common tcp listener, for RTMP/HTTP server.
@ -156,6 +158,14 @@ public:
virtual ~SrsUdpCasterListener();
};
// A UDP sip listener, for sip server.
class SrsGb28181Listener : public SrsUdpStreamListener
{
public:
SrsGb28181Listener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c);
virtual ~SrsGb28181Listener();
};
// Convert signal to io,
// @see: st-1.9/docs/notes.html
class SrsSignalManager : public ISrsCoroutineHandler

@ -0,0 +1,553 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2013-2020 Winlin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_sip_stack.hpp>
#if !defined(SRS_EXPORT_LIBRTMP)
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <map>
using namespace std;
#include <srs_protocol_io.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_codec.hpp>
#include <srs_rtsp_stack.hpp>
#define SIP_MAX_HEADER_LEN 2049
unsigned int srs_sip_random(int min,int max)
{
srand(int(time(0)));
return rand() % (max - min + 1) + min;
}
std::string srs_sip_get_form_to_uri(std::string msg)
{
//<sip:34020000002000000001@3402000000>;tag=536961166
//sip:34020000002000000001@3402000000
size_t pos = msg.find("<");
if (pos == string::npos) {
return msg;
}
msg = msg.substr(pos+1);
size_t pos2 = msg.find(">");
if (pos2 == string::npos) {
return msg;
}
msg = msg.substr(0, pos2-1);
return msg;
}
std::string srs_sip_get_param(std::string msg, std::string param)
{
std::vector<std::string> vec_params = srs_string_split(msg, ";");
size_t min_pos = string::npos;
for (vector<string>::iterator it = vec_params.begin(); it != vec_params.end(); ++it) {
string value = *it;
size_t pos = value.find(param);
if (pos == string::npos) {
continue;
}
std::vector<std::string> v_pram = srs_string_split(value, "=");
if (v_pram.size() > 0) {
return v_pram.at(1);
}
}
return "";
}
SrsSipRequest::SrsSipRequest()
{
seq = 0;
content_length = 0;
sdp = NULL;
transport = NULL;
method = "";
uri = "";;
version = "";;
seq = 0;
content_type = "";
content_length = 0;
call_id = "";
from = "";
to = "";
via = "";
from_tag = "";
to_tag = "";
contact = "";
user_agent = "";
branch = "";
status = "";
expires = 3600;
max_forwards = 70;
cmdtype = SrsSipCmdRequest;
host = "127.0.0.1";;
host_port = 5060;
serial = "";;
realm = "";;
sip_auth_id = "";
sip_auth_pwd = "";
sip_username = "";
peer_ip = "";
peer_port = 0;
}
SrsSipRequest::~SrsSipRequest()
{
srs_freep(sdp);
srs_freep(transport);
}
bool SrsSipRequest::is_register()
{
return method == SRS_SIP_METHOD_REGISTER;
}
bool SrsSipRequest::is_invite()
{
return method == SRS_SIP_METHOD_INVITE;
}
bool SrsSipRequest::is_ack()
{
return method == SRS_SIP_METHOD_ACK;
}
bool SrsSipRequest::is_message()
{
return method == SRS_SIP_METHOD_MESSAGE;
}
bool SrsSipRequest::is_bye()
{
return method == SRS_SIP_METHOD_BYE;
}
std::string SrsSipRequest::get_cmdtype_str()
{
switch(cmdtype) {
case SrsSipCmdRequest:
return "request";
case SrsSipCmdRespone:
return "respone";
}
return "";
}
void SrsSipRequest::copy(SrsSipRequest* src)
{
if (!src){
return;
}
method = src->method;
uri = src->uri;
version = src->version;
seq = src->seq;
content_type = src->content_type;
content_length = src->content_length;
call_id = src->call_id;
from = src->from;
to = src->to;
via = src->via;
from_tag = src->from_tag;
to_tag = src->to_tag;
contact = src->contact;
user_agent = src->user_agent;
branch = src->branch;
status = src->status;
expires = src->expires;
max_forwards = src->max_forwards;
cmdtype = src->cmdtype;
host = src->host;
host_port = src->host_port;
serial = src->serial;
realm = src->realm;
sip_auth_id = src->sip_auth_id;
sip_auth_pwd = src->sip_auth_pwd;
sip_username = src->sip_username;
peer_ip = src->peer_ip;
peer_port = src->peer_port;
}
SrsSipStack::SrsSipStack()
{
buf = new SrsSimpleStream();
}
SrsSipStack::~SrsSipStack()
{
srs_freep(buf);
}
srs_error_t SrsSipStack::parse_request(SrsSipRequest** preq, const char* recv_msg, int nb_len)
{
srs_error_t err = srs_success;
SrsSipRequest* req = new SrsSipRequest();
if ((err = do_parse_request(req, recv_msg)) != srs_success) {
srs_freep(req);
return srs_error_wrap(err, "recv message");
}
*preq = req;
return err;
}
srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_msg)
{
srs_error_t err = srs_success;
std::vector<std::string> header_body = srs_string_split(recv_msg, SRS_RTSP_CRLFCRLF);
std::string header = header_body.at(0);
std::string body = "";
if (header_body.size() > 1){
body = header_body.at(1);
}
//srs_trace("sip: header=%s\n", header.c_str());
//srs_trace("sip: body=%s\n", body.c_str());
// parse one by one.
char* start = (char*)header.c_str();
char* end = start + header.size();
char* p = start;
char* newline_start = start;
std::string firstline = "";
while (p < end) {
if (p[0] == '\r' && p[1] == '\n'){
p +=2;
int linelen = (int)(p - newline_start);
std::string oneline(newline_start, linelen);
newline_start = p;
if (firstline == ""){
firstline = oneline;
//srs_trace("=== first line=%s", firstline.c_str());
}else{
size_t pos = oneline.find(":");
if (pos != string::npos){
if (pos != 0) {
//ex: CSeq: 100 MESSAGE header is 'CSeq:',content is '100 MESSAGE'
std::string head = oneline.substr(0, pos+1);
std::string content = oneline.substr(pos+1, oneline.length()-pos-1);
content = srs_string_replace(content, "\r\n", "");
content = srs_string_trim_start(content, " ");
char *phead = (char*)head.c_str();
if (!strcasecmp(phead, "call-id:")) {
std::vector<std::string> vec_callid = srs_string_split(content, " ");
req->call_id = vec_callid.at(0);
}
else if (!strcasecmp(phead, "contact:")) {
req->contact = content;
}
else if (!strcasecmp(phead, "content-encoding:")) {
srs_trace("sip: message head %s content=%s", phead, content.c_str());
}
else if (!strcasecmp(phead, "content-length:")) {
srs_trace("sip: message head %s content=%s", phead, content.c_str());
}
else if (!strcasecmp(phead, "content-type:")) {
srs_trace("sip: message head %s content=%s", phead, content.c_str());
}
else if (!strcasecmp(phead, "cseq:")) {
std::vector<std::string> vec_seq = srs_string_split(content, " ");
req->seq = strtoul(vec_seq.at(0).c_str(), NULL, 10);
req->method = vec_seq.at(1);
}
else if (!strcasecmp(phead, "from:")) {
content = srs_string_replace(content, "sip:", "");
req->from = srs_sip_get_form_to_uri(content.c_str());
if (srs_string_contains(content, "tag")) {
req->from_tag = srs_sip_get_param(content.c_str(), "tag");
}
}
else if (!strcasecmp(phead, "to:")) {
content = srs_string_replace(content, "sip:", "");
req->to = srs_sip_get_form_to_uri(content.c_str());
if (srs_string_contains(content, "tag")) {
req->to_tag = srs_sip_get_param(content.c_str(), "tag");
}
}
else if (!strcasecmp(phead, "via:")) {
req->via = content;
req->branch = srs_sip_get_param(content.c_str(), "branch");
}
else if (!strcasecmp(phead, "expires:")){
req->expires = strtoul(content.c_str(), NULL, 10);
}
else if (!strcasecmp(phead, "user-agent:")){
req->user_agent = content;
}
else {
srs_trace("sip: unkonw message head %s content=%s", phead, content.c_str());
}
}
}
//srs_trace("====new line=%s", oneline.c_str());
}
}else{
p++;
}
}
std::vector<std::string> method_uri_ver = srs_string_split(firstline, " ");
//respone first line text:SIP/2.0 200 OK
if (!strcasecmp(method_uri_ver.at(0).c_str(), "sip/2.0")) {
req->cmdtype = SrsSipCmdRespone;
//req->method= vec_seq.at(1);
req->status = method_uri_ver.at(1);
req->version = method_uri_ver.at(0);
req->uri = req->from;
vector<string> str = srs_string_split(req->to, "@");
req->sip_auth_id = srs_string_replace(str.at(0), "sip:", "");
}else {//request first line text :MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
req->cmdtype = SrsSipCmdRequest;
req->method= method_uri_ver.at(0);
req->uri = method_uri_ver.at(1);
req->version = method_uri_ver.at(2);
vector<string> str = srs_string_split(req->from, "@");
req->sip_auth_id = srs_string_replace(str.at(0), "sip:", "");
}
req->sip_username = req->sip_auth_id;
//srs_trace("sip: method=%s uri=%s version=%s cmdtype=%s",
// req->method.c_str(), req->uri.c_str(), req->version.c_str(), req->get_cmdtype_str().c_str());
// srs_trace("via=%s", req->via.c_str());
// srs_trace("via_branch=%s", req->branch.c_str());
//srs_trace("cseq=%d", req->seq);
// srs_trace("contact=%s", req->contact.c_str());
//srs_trace("from=%s", req->from.c_str());
//srs_trace("to=%s", req->to.c_str());
//srs_trace("callid=%s", req->call_id.c_str());
// srs_trace("status=%s", req->status.c_str());
// srs_trace("from_tag=%s", req->from_tag.c_str());
// srs_trace("to_tag=%s", req->to_tag.c_str());
//srs_trace("sip_auth_id=%s", req->sip_auth_id.c_str());
return err;
}
srs_error_t SrsSipStack::resp_keepalive(std::stringstream& ss, SrsSipRequest *req){
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
<< "Via: " << SRS_SIP_VERSION << "/UDP " << req->host << ":" << req->host_port << ";branch=" << req->branch << SRS_RTSP_CRLF
<< "From: <sip:" << req->from.c_str() << ">;tag=" << req->from_tag << SRS_RTSP_CRLF
<< "To: <sip:"<< req->to.c_str() << ">\r\n"
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
<< "CSeq: " << req->seq << " " << req->method << SRS_RTSP_CRLF
<< "Contact: "<< req->contact << SRS_RTSP_CRLF
<< "Max-Forwards: 70" << SRS_RTSP_CRLF
<< "User-Agent: "<< SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
<< "Content-Length: 0" << SRS_RTSP_CRLFCRLF;
return srs_success;
}
srs_error_t SrsSipStack::resp_ack(std::stringstream& ss, SrsSipRequest *req){
ss << "ACK " << "sip:" << req->sip_auth_id << "@" << req->realm << " "<< SRS_SIP_VERSION << SRS_RTSP_CRLF
<< "Via: " << SRS_SIP_VERSION << "/UDP " << req->host << ":" << req->host_port << ";branch=" << req->branch << SRS_RTSP_CRLF
<< "From: <sip:" << req->serial << "@" << req->host + ":" << req->host_port << ">;tag=" << req->from_tag << SRS_RTSP_CRLF
<< "To: <sip:"<< req->sip_auth_id << "@" << req->realm << ">\r\n"
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
<< "CSeq: " << req->seq << " " << req->method << SRS_RTSP_CRLF
<< "Max-Forwards: 70" << SRS_RTSP_CRLF
<< "User-Agent: "<< SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
<< "Content-Length: 0" << SRS_RTSP_CRLFCRLF;
return srs_success;
}
srs_error_t SrsSipStack::resp_status(stringstream& ss, SrsSipRequest *req)
{
srs_error_t err = srs_success;
if (req->method == "REGISTER"){
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
<< "Via: " << req->via << SRS_RTSP_CRLF
<< "From: <sip:"<< req->from << ">" << SRS_RTSP_CRLF
<< "To: <sip:"<< req->to << ">" << SRS_RTSP_CRLF
<< "CSeq: "<< req->seq << " " << req->method << SRS_RTSP_CRLF
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
<< "Contact: " << req->contact << SRS_RTSP_CRLF
<< "User-Agent: " << SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
<< "Content-Length: 0" << SRS_RTSP_CRLFCRLF;
}else{
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
<< "Via: " << req->via << SRS_RTSP_CRLF
<< "From: <sip:"<< req->from << ">" << SRS_RTSP_CRLF
<< "To: <sip:"<< req->to << ">" << SRS_RTSP_CRLF
<< "CSeq: "<< req->seq << " " << req->method << SRS_RTSP_CRLF
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
<< "User-Agent: " << SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
<< "Content-Length: 0" << SRS_RTSP_CRLFCRLF;
}
return err;
}
srs_error_t SrsSipStack::req_invite(stringstream& ss, SrsSipRequest *req, int port)
{
/*
INVITE sip:34020000001320000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.22:15060;rport;branch=z9hG4bK369961166
From: <sip:34020000002000000001@3402000000>;tag=536961166
To: <sip:34020000001320000001@3402000000>
Call-ID: 929961057
CSeq: 3 INVITE
Content-Type: APPLICATION/SDP
Contact: <sip:34020000002000000001@192.168.1.22:15060>
Max-Forwards: 70
User-Agent: XXXXXXX XXXXXXX
Subject: 34020000001320000001:0200000001,34020000002020000001:0
Content-Length: 247
v=0
o=34020000002000000001 0 0 IN IP4 192.168.1.23
s=Play
c=IN IP4 192.168.1.23
t=0 0
m=video 30000 RTP/AVP 96 97 98 99
a=recvonly
a=rtpmap:96 PS/90000
a=rtpmap:97 MPEG4/90000
a=rtpmap:98 H264/90000
a=rtpmap:99 H265/90000
y=0200000001
*/
srs_error_t err = srs_success;
int ssrc = srs_sip_random(10000, 99999);
std::stringstream sdp;
sdp << "v=0" << SRS_RTSP_CRLF
<< "o=" << req->sip_auth_id << " 0 0 IN IP4 " << req->host << SRS_RTSP_CRLF
<< "s=Play" << SRS_RTSP_CRLF
<< "c=IN IP4 " << req->host << SRS_RTSP_CRLF
<< "t=0 0" << SRS_RTSP_CRLF
<< "m=video " << port <<" RTP/AVP 96 97 98 99" << SRS_RTSP_CRLF
<< "a=recvonly" << SRS_RTSP_CRLF
<< "a=rtpmap:96 PS/90000" << SRS_RTSP_CRLF
<< "a=rtpmap:97 MPEG4/90000" << SRS_RTSP_CRLF
<< "a=rtpmap:98 H264/90000" << SRS_RTSP_CRLF
<< "a=rtpmap:99 H265/90000" << SRS_RTSP_CRLF
<< "y=00181" << ssrc << SRS_RTSP_CRLF;
//<< "a=streamMode:MAIN\r\n"
//<< "a=filesize:0\r\n"
int rand = srs_sip_random(1000, 9999);
std::stringstream from, to, uri;
//"INVITE sip:34020000001320000001@3402000000 SIP/2.0\r\n
uri << "sip:" << req->sip_auth_id << "@" << req->realm;
//From: <sip:34020000002000000001@%s:%s>;tag=500485%d\r\n
from << req->serial << "@" << req->host << ":" << req->host_port;
to << req->sip_auth_id << "@" << req->realm;
req->from = from.str();
req->to = to.str();
req->uri = uri.str();
ss << "INVITE " << req->uri << " " << SRS_SIP_VERSION << SRS_RTSP_CRLF
<< "Via: " << SRS_SIP_VERSION << "/UDP "<< req->host << ":" << req->host_port << ";rport;branch=z9hG4bK3420" << rand << SRS_RTSP_CRLF
<< "From: <sip:" << req->from << ">;tag=51235" << rand << SRS_RTSP_CRLF
<< "To: <sip:" << req->to << ">" << SRS_RTSP_CRLF
<< "Call-ID: 20000" << rand <<SRS_RTSP_CRLF
<< "CSeq: 20 INVITE" << SRS_RTSP_CRLF
<< "Content-Type: Application/SDP" << SRS_RTSP_CRLF
<< "Contact: <sip:" << req->to << ">" << SRS_RTSP_CRLF
<< "Max-Forwards: 70" << " \r\n"
<< "User-Agent: " << SRS_SIP_USER_AGENT <<SRS_RTSP_CRLF
<< "Subject: "<< req->sip_auth_id << ":00181" << ssrc << "," << req->serial << ":0" << SRS_RTSP_CRLF
<< "Content-Length: " << sdp.str().length() << SRS_RTSP_CRLFCRLF
<< sdp.str();
return err;
}
srs_error_t SrsSipStack::req_bye(std::stringstream& ss, SrsSipRequest *req)
{
srs_error_t err = srs_success;
std::stringstream from, to, uri;
uri << "sip:" << req->sip_auth_id << "@" << req->realm;
from << req->serial << "@" << req->host << ":" << req->host_port;
to << req->sip_auth_id << "@" << req->realm;
req->from = from.str();
req->to = to.str();
req->uri = uri.str();
int rand = srs_sip_random(1000, 9999);
ss << "BYE " << req->uri << " "<< SRS_SIP_VERSION << SRS_RTSP_CRLF
<< "Via: "<< SRS_SIP_VERSION << "/UDP "<< req->host << ":" << req->host_port << ";branch=z9hG4bK3420" << rand << SRS_RTSP_CRLF
<< "From: <sip:" << req->from << ">;tag=51235" << rand << SRS_RTSP_CRLF
<< "To: <sip:" << req->to << ">" << SRS_RTSP_CRLF
<< "Call-ID: 20000" << rand << SRS_RTSP_CRLF
<< "CSeq: 21 BYE" << SRS_RTSP_CRLF
<< "Max-Forwards: 70" << SRS_RTSP_CRLF
<< "User-Agent: " << SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
<< "Content-Length: 0" << SRS_RTSP_CRLFCRLF;
return err;
}
#endif

@ -0,0 +1,143 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2013-2020 Winlin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_PROTOCOL_SIP_HPP
#define SRS_PROTOCOL_SIP_HPP
#include <srs_core.hpp>
#if !defined(SRS_EXPORT_LIBRTMP)
#include <string>
#include <sstream>
#include <srs_kernel_consts.hpp>
#include <srs_rtsp_stack.hpp>
class SrsBuffer;
class SrsSimpleStream;
class SrsAudioFrame;
// SIP methods
#define SRS_SIP_METHOD_REGISTER "REGISTER"
#define SRS_SIP_METHOD_MESSAGE "MESSAGE"
#define SRS_SIP_METHOD_INVITE "INVITE"
#define SRS_SIP_METHOD_ACK "ACK"
#define SRS_SIP_METHOD_BYE "BYE"
// SIP-Version
#define SRS_SIP_VERSION "SIP/2.0"
#define SRS_SIP_USER_AGENT RTMP_SIG_SRS_SERVER
enum SrsSipCmdType{
SrsSipCmdRequest=0,
SrsSipCmdRespone=1
};
class SrsSipRequest
{
public:
//sip header member
std::string method;
std::string uri;
std::string version;
std::string status;
std::string via;
std::string from;
std::string to;
std::string from_tag;
std::string to_tag;
std::string branch;
std::string call_id;
long seq;
std::string contact;
std::string user_agent;
std::string content_type;
long content_length;
long expires;
int max_forwards;
public:
std::string serial;
std::string realm;
std::string sip_auth_id;
std::string sip_auth_pwd;
std::string sip_username;
std::string peer_ip;
int peer_port;
std::string host;
int host_port;
SrsSipCmdType cmdtype;
public:
SrsRtspSdp* sdp;
SrsRtspTransport* transport;
public:
SrsSipRequest();
virtual ~SrsSipRequest();
public:
virtual bool is_register();
virtual bool is_invite();
virtual bool is_message();
virtual bool is_ack();
virtual bool is_bye();
virtual void copy(SrsSipRequest* src);
public:
virtual std::string get_cmdtype_str();
};
// The gb28181 sip protocol stack.
class SrsSipStack
{
private:
// The cached bytes buffer.
SrsSimpleStream* buf;
public:
SrsSipStack();
virtual ~SrsSipStack();
public:
virtual srs_error_t parse_request(SrsSipRequest** preq, const char *recv_msg, int nb_buf);
protected:
virtual srs_error_t do_parse_request(SrsSipRequest* req, const char *recv_msg);
public:
virtual srs_error_t resp_status(std::stringstream& ss, SrsSipRequest *req);
virtual srs_error_t resp_keepalive(std::stringstream& ss, SrsSipRequest *req);
virtual srs_error_t resp_ack(std::stringstream& ss, SrsSipRequest *req);
virtual srs_error_t req_invite(std::stringstream& ss, SrsSipRequest *req, int port);
virtual srs_error_t req_bye(std::stringstream& ss, SrsSipRequest *req);
};
#endif
#endif

@ -397,6 +397,11 @@ int srs_recvfrom(srs_netfd_t stfd, void *buf, int len, struct sockaddr *from, in
return st_recvfrom((st_netfd_t)stfd, buf, len, from, fromlen, (st_utime_t)timeout);
}
int srs_sendto(srs_netfd_t stfd, void *msg, int len, struct sockaddr *to, int tolen, srs_utime_t timeout)
{
return st_sendto((st_netfd_t)stfd, (const void*)msg, len, (const struct sockaddr *)to, tolen, (st_utime_t)timeout);
}
srs_netfd_t srs_accept(srs_netfd_t stfd, struct sockaddr *addr, int *addrlen, srs_utime_t timeout)
{
return (srs_netfd_t)st_accept((st_netfd_t)stfd, addr, addrlen, (st_utime_t)timeout);

@ -88,6 +88,7 @@ extern srs_netfd_t srs_netfd_open_socket(int osfd);
extern srs_netfd_t srs_netfd_open(int osfd);
extern int srs_recvfrom(srs_netfd_t stfd, void *buf, int len, struct sockaddr *from, int *fromlen, srs_utime_t timeout);
extern int srs_sendto(srs_netfd_t stfd, void *msg, int len, struct sockaddr *to, int tolen, srs_utime_t timeout);
extern srs_netfd_t srs_accept(srs_netfd_t stfd, struct sockaddr *addr, int *addrlen, srs_utime_t timeout);

Loading…
Cancel
Save