mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix gb28181 api error code
This commit is contained in:
parent
7950bc586e
commit
33b91cd6f2
5 changed files with 151 additions and 99 deletions
|
@ -312,7 +312,12 @@ srs_error_t SrsGb28181PsRtpProcessor::on_udp_packet(const sockaddr* from, const
|
||||||
channel.set_channel_id(tmp_id);
|
channel.set_channel_id(tmp_id);
|
||||||
channel.set_port_mode(RTP_PORT_MODE_FIXED);
|
channel.set_port_mode(RTP_PORT_MODE_FIXED);
|
||||||
channel.set_ssrc(pkt.ssrc);
|
channel.set_ssrc(pkt.ssrc);
|
||||||
_srs_gb28181->create_stream_channel(&channel);
|
|
||||||
|
srs_error_t err2 = srs_success;
|
||||||
|
if ((err2 = _srs_gb28181->create_stream_channel(&channel)) != srs_success){
|
||||||
|
srs_warn("gb28181: RtpProcessor create stream channel error %s", srs_error_desc(err2).c_str());
|
||||||
|
srs_error_reset(err2);
|
||||||
|
};
|
||||||
|
|
||||||
muxer = _srs_gb28181->fetch_rtmpmuxer(tmp_id);
|
muxer = _srs_gb28181->fetch_rtmpmuxer(tmp_id);
|
||||||
}
|
}
|
||||||
|
@ -1547,8 +1552,9 @@ void SrsGb28181Manger::stop_rtp_listen(std::string id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//api
|
//api
|
||||||
uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channel)
|
srs_error_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channel)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
srs_assert(channel);
|
srs_assert(channel);
|
||||||
|
|
||||||
std::string id = channel->get_channel_id();
|
std::string id = channel->get_channel_id();
|
||||||
|
@ -1559,15 +1565,14 @@ uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channe
|
||||||
SrsGb28181StreamChannel s = muxer->get_channel();
|
SrsGb28181StreamChannel s = muxer->get_channel();
|
||||||
channel->copy(&s);
|
channel->copy(&s);
|
||||||
//return ERROR_GB28181_SESSION_IS_EXIST;
|
//return ERROR_GB28181_SESSION_IS_EXIST;
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
//create on rtmp muxer, gb28181 stream to rtmp
|
//create on rtmp muxer, gb28181 stream to rtmp
|
||||||
srs_error_t err = srs_success;
|
|
||||||
if ((err = fetch_or_create_rtmpmuxer(id, &muxer)) != srs_success){
|
if ((err = fetch_or_create_rtmpmuxer(id, &muxer)) != srs_success){
|
||||||
srs_warn("gb28181: create rtmp muxer error, %s", srs_error_desc(err).c_str());
|
srs_warn("gb28181: create rtmp muxer error, %s", srs_error_desc(err).c_str());
|
||||||
srs_freep(err);
|
return err;
|
||||||
return ERROR_GB28181_CREATER_RTMPMUXER_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Start RTP listening port, receive gb28181 stream,
|
//Start RTP listening port, receive gb28181 stream,
|
||||||
|
@ -1584,21 +1589,19 @@ uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channe
|
||||||
if (port_mode == RTP_PORT_MODE_RANDOM){
|
if (port_mode == RTP_PORT_MODE_RANDOM){
|
||||||
alloc_port(&rtp_port);
|
alloc_port(&rtp_port);
|
||||||
if (rtp_port <= 0){
|
if (rtp_port <= 0){
|
||||||
return ERROR_GB28181_RTP_PORT_FULL;
|
return srs_error_new(ERROR_GB28181_RTP_PORT_FULL, "gb28181: rtp port full");
|
||||||
}
|
}
|
||||||
srs_error_t err = srs_success;
|
|
||||||
if ((err = start_ps_rtp_listen(id, rtp_port)) != srs_success){
|
if ((err = start_ps_rtp_listen(id, rtp_port)) != srs_success){
|
||||||
srs_warn("gb28181: start ps rtp listen error, %s", srs_error_desc(err).c_str());
|
|
||||||
srs_freep(err);
|
|
||||||
free_port(rtp_port, rtp_port + 1);
|
free_port(rtp_port, rtp_port + 1);
|
||||||
return ERROR_GB28181_CREATER_RTMPMUXER_FAILED;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(port_mode == RTP_PORT_MODE_FIXED) {
|
else if(port_mode == RTP_PORT_MODE_FIXED) {
|
||||||
rtp_port = config->rtp_mux_port;
|
rtp_port = config->rtp_mux_port;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return ERROR_GB28181_PORT_MODE_INVALID;
|
return srs_error_new(ERROR_GB28181_PORT_MODE_INVALID, "gb28181: port mode invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ssrc = channel->get_ssrc();
|
uint32_t ssrc = channel->get_ssrc();
|
||||||
|
@ -1673,11 +1676,13 @@ uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channe
|
||||||
|
|
||||||
muxer->copy_channel(channel);
|
muxer->copy_channel(channel);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::delete_stream_channel(std::string id)
|
srs_error_t SrsGb28181Manger::delete_stream_channel(std::string id)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
//notify the device to stop streaming
|
//notify the device to stop streaming
|
||||||
//if an internal sip service controlled channel
|
//if an internal sip service controlled channel
|
||||||
notify_sip_bye(id, id);
|
notify_sip_bye(id, id);
|
||||||
|
@ -1686,19 +1691,21 @@ uint32_t SrsGb28181Manger::delete_stream_channel(std::string id)
|
||||||
if (muxer){
|
if (muxer){
|
||||||
stop_rtp_listen(id);
|
stop_rtp_listen(id);
|
||||||
muxer->stop();
|
muxer->stop();
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}else {
|
}else {
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "stream channel is not exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::query_stream_channel(std::string id, SrsJsonArray* arr)
|
srs_error_t SrsGb28181Manger::query_stream_channel(std::string id, SrsJsonArray* arr)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if (!id.empty()){
|
if (!id.empty()){
|
||||||
SrsGb28181RtmpMuxer *muxer = fetch_rtmpmuxer(id);
|
SrsGb28181RtmpMuxer *muxer = fetch_rtmpmuxer(id);
|
||||||
if (!muxer){
|
if (!muxer){
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "stream channel not exists");
|
||||||
}
|
}
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsJsonObject* obj = SrsJsonAny::object();
|
||||||
arr->append(obj);
|
arr->append(obj);
|
||||||
|
@ -1713,13 +1720,15 @@ uint32_t SrsGb28181Manger::query_stream_channel(std::string id, SrsJsonArray* ar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::notify_sip_invite(std::string id, std::string ip, int port, uint32_t ssrc, std::string chid)
|
srs_error_t SrsGb28181Manger::notify_sip_invite(std::string id, std::string ip, int port, uint32_t ssrc, std::string chid)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
//if RTMP Muxer does not exist, you need to create
|
//if RTMP Muxer does not exist, you need to create
|
||||||
|
@ -1732,9 +1741,9 @@ uint32_t SrsGb28181Manger::notify_sip_invite(std::string id, std::string ip, int
|
||||||
//channel not exist
|
//channel not exist
|
||||||
SrsGb28181StreamChannel channel;
|
SrsGb28181StreamChannel channel;
|
||||||
channel.set_channel_id(key);
|
channel.set_channel_id(key);
|
||||||
int code = create_stream_channel(&channel);
|
err = create_stream_channel(&channel);
|
||||||
if (code != ERROR_SUCCESS){
|
if (err != srs_success){
|
||||||
return code;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = channel.get_ip();
|
ip = channel.get_ip();
|
||||||
|
@ -1754,10 +1763,10 @@ uint32_t SrsGb28181Manger::notify_sip_invite(std::string id, std::string ip, int
|
||||||
return sip_service->send_invite(&req, ip, port, ssrc, chid);
|
return sip_service->send_invite(&req, ip, port, ssrc, chid);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::notify_sip_bye(std::string id, std::string chid)
|
srs_error_t SrsGb28181Manger::notify_sip_bye(std::string id, std::string chid)
|
||||||
{
|
{
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSipRequest req;
|
SrsSipRequest req;
|
||||||
|
@ -1765,10 +1774,10 @@ uint32_t SrsGb28181Manger::notify_sip_bye(std::string id, std::string chid)
|
||||||
return sip_service->send_bye(&req, chid);
|
return sip_service->send_bye(&req, chid);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::notify_sip_raw_data(std::string id, std::string data)
|
srs_error_t SrsGb28181Manger::notify_sip_raw_data(std::string id, std::string data)
|
||||||
{
|
{
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSipRequest req;
|
SrsSipRequest req;
|
||||||
|
@ -1777,21 +1786,19 @@ uint32_t SrsGb28181Manger::notify_sip_raw_data(std::string id, std::string data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::notify_sip_unregister(std::string id)
|
srs_error_t SrsGb28181Manger::notify_sip_unregister(std::string id)
|
||||||
{
|
{
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_stream_channel(id);
|
|
||||||
sip_service->remove_session(id);
|
sip_service->remove_session(id);
|
||||||
return ERROR_SUCCESS;
|
return delete_stream_channel(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::notify_sip_query_catalog(std::string id)
|
srs_error_t SrsGb28181Manger::notify_sip_query_catalog(std::string id)
|
||||||
{
|
{
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSipRequest req;
|
SrsSipRequest req;
|
||||||
|
@ -1799,10 +1806,10 @@ uint32_t SrsGb28181Manger::notify_sip_query_catalog(std::string id)
|
||||||
return sip_service->send_query_catalog(&req);
|
return sip_service->send_query_catalog(&req);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsGb28181Manger::query_sip_session(std::string id, SrsJsonArray* arr)
|
srs_error_t SrsGb28181Manger::query_sip_session(std::string id, SrsJsonArray* arr)
|
||||||
{
|
{
|
||||||
if (!sip_service){
|
if (!sip_service){
|
||||||
return ERROR_GB28181_SIP_NOT_RUN;
|
return srs_error_new(ERROR_GB28181_SIP_NOT_RUN, "sip not run");
|
||||||
}
|
}
|
||||||
|
|
||||||
return sip_service->query_sip_session(id, arr);
|
return sip_service->query_sip_session(id, arr);
|
||||||
|
|
|
@ -413,16 +413,16 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//stream channel api
|
//stream channel api
|
||||||
uint32_t create_stream_channel(SrsGb28181StreamChannel *channel);
|
srs_error_t create_stream_channel(SrsGb28181StreamChannel *channel);
|
||||||
uint32_t delete_stream_channel(std::string id);
|
srs_error_t delete_stream_channel(std::string id);
|
||||||
uint32_t query_stream_channel(std::string id, SrsJsonArray* arr);
|
srs_error_t query_stream_channel(std::string id, SrsJsonArray* arr);
|
||||||
//sip api
|
//sip api
|
||||||
uint32_t notify_sip_invite(std::string id, std::string ip, int port, uint32_t ssrc, std::string chid);
|
srs_error_t notify_sip_invite(std::string id, std::string ip, int port, uint32_t ssrc, std::string chid);
|
||||||
uint32_t notify_sip_bye(std::string id, std::string chid);
|
srs_error_t notify_sip_bye(std::string id, std::string chid);
|
||||||
uint32_t notify_sip_raw_data(std::string id, std::string data);
|
srs_error_t notify_sip_raw_data(std::string id, std::string data);
|
||||||
uint32_t notify_sip_unregister(std::string id);
|
srs_error_t notify_sip_unregister(std::string id);
|
||||||
uint32_t notify_sip_query_catalog(std::string id);
|
srs_error_t notify_sip_query_catalog(std::string id);
|
||||||
uint32_t query_sip_session(std::string id, SrsJsonArray* arr);
|
srs_error_t query_sip_session(std::string id, SrsJsonArray* arr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
|
@ -201,20 +201,25 @@ srs_error_t SrsGb28181SipSession::do_cycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
//create stream channel, ready for recv device av stream
|
//create stream channel, ready for recv device av stream
|
||||||
int code = _srs_gb28181->create_stream_channel(&ch);
|
srs_error_t err = _srs_gb28181->create_stream_channel(&ch);
|
||||||
|
|
||||||
if (code == ERROR_SUCCESS){
|
if ((err = _srs_gb28181->create_stream_channel(&ch)) == srs_success){
|
||||||
SrsSipRequest req;
|
SrsSipRequest req;
|
||||||
req.sip_auth_id = _session_id;
|
req.sip_auth_id = _session_id;
|
||||||
|
|
||||||
//send invite to device, req push av stream
|
//send invite to device, req push av stream
|
||||||
code = servcie->send_invite(&req, ch.get_ip(),
|
err = servcie->send_invite(&req, ch.get_ip(),
|
||||||
ch.get_rtp_port(), ch.get_ssrc(), chid);
|
ch.get_rtp_port(), ch.get_ssrc(), chid);
|
||||||
|
|
||||||
//the same device can't be sent too fast. the device can't handle it
|
|
||||||
srs_usleep(1*SRS_UTIME_SECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success){
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
//the same device can't be sent too fast. the device can't handle it
|
||||||
|
srs_usleep(1*SRS_UTIME_SECONDS);
|
||||||
|
|
||||||
srs_trace("gb28181: %s clients device=%s send invite code=%d",
|
srs_trace("gb28181: %s clients device=%s send invite code=%d",
|
||||||
_session_id.c_str(), chid.c_str(), code);
|
_session_id.c_str(), chid.c_str(), code);
|
||||||
}//end for (it)
|
}//end for (it)
|
||||||
|
@ -238,9 +243,14 @@ srs_error_t SrsGb28181SipSession::do_cycle()
|
||||||
query_duration >= config->sip_query_catalog_interval) {
|
query_duration >= config->sip_query_catalog_interval) {
|
||||||
SrsSipRequest req;
|
SrsSipRequest req;
|
||||||
req.sip_auth_id = _session_id;
|
req.sip_auth_id = _session_id;
|
||||||
servcie->send_query_catalog(&req);
|
|
||||||
_query_catalog_time = srs_get_system_time();
|
_query_catalog_time = srs_get_system_time();
|
||||||
|
|
||||||
|
srs_error_t err = servcie->send_query_catalog(&req);
|
||||||
|
if (err != srs_success){
|
||||||
|
srs_trace("gb28181: sip query catalog error %s",srs_error_desc(err).c_str());
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
//print device status
|
//print device status
|
||||||
srs_trace("gb28181: sip session=%s peer(%s, %d) status(%s,%s) duration(%u,%u)",
|
srs_trace("gb28181: sip session=%s peer(%s, %d) status(%s,%s) duration(%u,%u)",
|
||||||
_session_id.c_str(), _peer_ip.c_str(), _peer_port,
|
_session_id.c_str(), _peer_ip.c_str(), _peer_port,
|
||||||
|
@ -621,26 +631,28 @@ int SrsGb28181SipService::send_status(SrsSipRequest *req, sockaddr *f, int l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port, uint32_t ssrc, std::string chid)
|
srs_error_t SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port, uint32_t ssrc, std::string chid)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
srs_assert(req);
|
srs_assert(req);
|
||||||
|
|
||||||
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
||||||
|
|
||||||
if (!sip_session){
|
if (!sip_session){
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "sip session not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
//if you are inviting or succeed in invite,
|
//if you are inviting or succeed in invite,
|
||||||
//you cannot invite again. you need to 'bye' and try again
|
//you cannot invite again. you need to 'bye' and try again
|
||||||
SrsGb28181Device *device = sip_session->get_device_info(chid);
|
SrsGb28181Device *device = sip_session->get_device_info(chid);
|
||||||
if (!device || device->device_status != "ON"){
|
if (!device || device->device_status != "ON"){
|
||||||
return ERROR_GB28181_SIP_CH_OFFLINE;
|
return srs_error_new(ERROR_GB28181_SIP_CH_OFFLINE, "sip device channel offline");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device->invite_status == SrsGb28181SipSessionTrying ||
|
if (device->invite_status == SrsGb28181SipSessionTrying ||
|
||||||
device->invite_status == SrsGb28181SipSessionInviteOk){
|
device->invite_status == SrsGb28181SipSessionInviteOk){
|
||||||
return ERROR_GB28181_SIP_IS_INVITING;
|
return srs_error_new(ERROR_GB28181_SIP_IS_INVITING, "sip device channel inviting");
|
||||||
}
|
}
|
||||||
|
|
||||||
req->host = config->host;
|
req->host = config->host;
|
||||||
|
@ -656,7 +668,7 @@ int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port,
|
||||||
|
|
||||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||||
{
|
{
|
||||||
return ERROR_GB28181_SIP_INVITE_FAILED;
|
return srs_error_new(ERROR_GB28181_SIP_INVITE_FAILED, "sip device invite failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
//prame branch, from_tag, to_tag, call_id,
|
//prame branch, from_tag, to_tag, call_id,
|
||||||
|
@ -668,27 +680,25 @@ int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port,
|
||||||
//call_id map sip_session
|
//call_id map sip_session
|
||||||
sip_session_map_by_callid(sip_session, req->call_id);
|
sip_session_map_by_callid(sip_session, req->call_id);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGb28181SipService::send_bye(SrsSipRequest *req, std::string chid)
|
srs_error_t SrsGb28181SipService::send_bye(SrsSipRequest *req, std::string chid)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
srs_assert(req);
|
srs_assert(req);
|
||||||
|
|
||||||
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
||||||
|
|
||||||
if (!sip_session){
|
if (!sip_session){
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "sip session not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGb28181Device *device = sip_session->get_device_info(chid);
|
SrsGb28181Device *device = sip_session->get_device_info(chid);
|
||||||
if (!device){
|
if (!device){
|
||||||
return ERROR_GB28181_SIP_CH_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SIP_CH_NOTEXIST, "sip device channel not exist");
|
||||||
}
|
}
|
||||||
// if (status == SrsGb28181SipSessionTrying ||
|
|
||||||
// status == SrsGb28181SipSessionInviteOk){
|
|
||||||
// return ERROR_GB28181_SIP_IS_INVITING;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//prame branch, from_tag, to_tag, call_id,
|
//prame branch, from_tag, to_tag, call_id,
|
||||||
//The parameter of 'bye' must be the same as 'invite'
|
//The parameter of 'bye' must be the same as 'invite'
|
||||||
|
@ -709,20 +719,22 @@ int SrsGb28181SipService::send_bye(SrsSipRequest *req, std::string chid)
|
||||||
sockaddr addr = sip_session->sockaddr_from();
|
sockaddr addr = sip_session->sockaddr_from();
|
||||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||||
{
|
{
|
||||||
return ERROR_GB28181_SIP_BYE_FAILED;
|
return srs_error_new(ERROR_GB28181_SIP_BYE_FAILED, "sip bye failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGb28181SipService::send_sip_raw_data(SrsSipRequest *req, std::string data)
|
srs_error_t SrsGb28181SipService::send_sip_raw_data(SrsSipRequest *req, std::string data)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
srs_assert(req);
|
srs_assert(req);
|
||||||
|
|
||||||
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
SrsGb28181SipSession *sip_session = fetch(req->sip_auth_id);
|
||||||
|
|
||||||
if (!sip_session){
|
if (!sip_session){
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "sip session no exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -731,13 +743,13 @@ int SrsGb28181SipService::send_sip_raw_data(SrsSipRequest *req, std::string dat
|
||||||
sockaddr addr = sip_session->sockaddr_from();
|
sockaddr addr = sip_session->sockaddr_from();
|
||||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||||
{
|
{
|
||||||
return ERROR_GB28181_SIP_RAW_DATA_FAILED;
|
return srs_error_new(ERROR_GB28181_SIP_RAW_DATA_FAILED, "sip raw data failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGb28181SipService::send_query_catalog(SrsSipRequest *req)
|
srs_error_t SrsGb28181SipService::send_query_catalog(SrsSipRequest *req)
|
||||||
{
|
{
|
||||||
req->host = config->host;
|
req->host = config->host;
|
||||||
req->host_port = config->sip_port;
|
req->host_port = config->sip_port;
|
||||||
|
@ -752,12 +764,14 @@ int SrsGb28181SipService::send_query_catalog(SrsSipRequest *req)
|
||||||
return send_sip_raw_data(req, ss.str());
|
return send_sip_raw_data(req, ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGb28181SipService::query_sip_session(std::string sid, SrsJsonArray* arr)
|
srs_error_t SrsGb28181SipService::query_sip_session(std::string sid, SrsJsonArray* arr)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if (!sid.empty()){
|
if (!sid.empty()){
|
||||||
SrsGb28181SipSession* sess = fetch(sid);
|
SrsGb28181SipSession* sess = fetch(sid);
|
||||||
if (!sess){
|
if (!sess){
|
||||||
return ERROR_GB28181_SESSION_IS_NOTEXIST;
|
return srs_error_new(ERROR_GB28181_SESSION_IS_NOTEXIST, "sip session not exist");
|
||||||
}
|
}
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsJsonObject* obj = SrsJsonAny::object();
|
||||||
arr->append(obj);
|
arr->append(obj);
|
||||||
|
@ -772,7 +786,7 @@ int SrsGb28181SipService::query_sip_session(std::string sid, SrsJsonArray* arr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsGb28181SipService::fetch_or_create_sip_session(SrsSipRequest *req, SrsGb28181SipSession** sip_session)
|
srs_error_t SrsGb28181SipService::fetch_or_create_sip_session(SrsSipRequest *req, SrsGb28181SipSession** sip_session)
|
||||||
|
|
|
@ -172,9 +172,9 @@ public:
|
||||||
int send_ack(SrsSipRequest *req, sockaddr *f, int l);
|
int send_ack(SrsSipRequest *req, sockaddr *f, int l);
|
||||||
int send_status(SrsSipRequest *req, sockaddr *f, int l);
|
int send_status(SrsSipRequest *req, sockaddr *f, int l);
|
||||||
|
|
||||||
int send_invite(SrsSipRequest *req, std::string ip, int port, uint32_t ssrc, std::string chid);
|
srs_error_t send_invite(SrsSipRequest *req, std::string ip, int port, uint32_t ssrc, std::string chid);
|
||||||
int send_bye(SrsSipRequest *req, std::string chid);
|
srs_error_t send_bye(SrsSipRequest *req, std::string chid);
|
||||||
int send_query_catalog(SrsSipRequest *req);
|
srs_error_t send_query_catalog(SrsSipRequest *req);
|
||||||
|
|
||||||
// The SIP command is transmitted through HTTP API,
|
// The SIP command is transmitted through HTTP API,
|
||||||
// and the body content is transmitted to the device,
|
// and the body content is transmitted to the device,
|
||||||
|
@ -190,8 +190,8 @@ public:
|
||||||
// Content-Length: 0
|
// Content-Length: 0
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
int send_sip_raw_data(SrsSipRequest *req, std::string data);
|
srs_error_t send_sip_raw_data(SrsSipRequest *req, std::string data);
|
||||||
int query_sip_session(std::string sid, SrsJsonArray* arr);
|
srs_error_t query_sip_session(std::string sid, SrsJsonArray* arr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
srs_error_t fetch_or_create_sip_session(SrsSipRequest *req, SrsGb28181SipSession** sess);
|
srs_error_t fetch_or_create_sip_session(SrsSipRequest *req, SrsGb28181SipSession** sess);
|
||||||
|
|
|
@ -1670,6 +1670,8 @@ SrsGoApiGb28181::~SrsGoApiGb28181()
|
||||||
|
|
||||||
srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsJsonObject* obj = SrsJsonAny::object();
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
SrsAutoFree(SrsJsonObject, obj);
|
||||||
|
|
||||||
|
@ -1696,9 +1698,9 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
channel.set_app(app);
|
channel.set_app(app);
|
||||||
channel.set_stream(stream);
|
channel.set_stream(stream);
|
||||||
channel.set_port_mode(port_mode);
|
channel.set_port_mode(port_mode);
|
||||||
|
|
||||||
uint32_t code = _srs_gb28181->create_stream_channel(&channel);
|
if ((err =_srs_gb28181->create_stream_channel(&channel)) != srs_success) {
|
||||||
if (code != ERROR_SUCCESS) {
|
int code = srs_error_code(err); srs_error_reset(err);
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1718,15 +1720,20 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t code = _srs_gb28181->delete_stream_channel(id);
|
err =_srs_gb28181->delete_stream_channel(id);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "query_channel") {
|
else if(action == "query_channel") {
|
||||||
SrsJsonArray* arr = SrsJsonAny::array();
|
SrsJsonArray* arr = SrsJsonAny::array();
|
||||||
data->set("channels", arr);
|
data->set("channels", arr);
|
||||||
|
|
||||||
uint32_t code = _srs_gb28181->query_stream_channel(id, arr);
|
if ((err = _srs_gb28181->query_stream_channel(id, arr)) != srs_success) {
|
||||||
if (code != ERROR_SUCCESS) {
|
int code = srs_error_code(err); srs_error_reset(err);
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1745,9 +1752,12 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
int _port = strtoul(rtp_port.c_str(), NULL, 10);
|
int _port = strtoul(rtp_port.c_str(), NULL, 10);
|
||||||
uint32_t _ssrc = (uint32_t)(strtoul(ssrc.c_str(), NULL, 10));
|
uint32_t _ssrc = (uint32_t)(strtoul(ssrc.c_str(), NULL, 10));
|
||||||
|
|
||||||
|
err = _srs_gb28181->notify_sip_invite(id, ip, _port, _ssrc, chid);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
int code = _srs_gb28181->notify_sip_invite(id, ip, _port, _ssrc, chid);
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "sip_bye"){
|
else if(action == "sip_bye"){
|
||||||
|
@ -1756,7 +1766,12 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = _srs_gb28181->notify_sip_bye(id, chid);
|
err = _srs_gb28181->notify_sip_bye(id, chid);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "sip_raw_data"){
|
else if(action == "sip_raw_data"){
|
||||||
|
@ -1766,7 +1781,13 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
|
|
||||||
std::string body;
|
std::string body;
|
||||||
r->body_read_all(body);
|
r->body_read_all(body);
|
||||||
int code = _srs_gb28181->notify_sip_raw_data(id, body);
|
|
||||||
|
err = _srs_gb28181->notify_sip_raw_data(id, body);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "sip_unregister"){
|
else if(action == "sip_unregister"){
|
||||||
|
@ -1774,7 +1795,12 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = _srs_gb28181->notify_sip_unregister(id);
|
err = _srs_gb28181->notify_sip_unregister(id);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "sip_query_catalog"){
|
else if(action == "sip_query_catalog"){
|
||||||
|
@ -1782,15 +1808,20 @@ srs_error_t SrsGoApiGb28181::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
return srs_api_response_code(w, r, ERROR_GB28181_VALUE_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = _srs_gb28181->notify_sip_query_catalog(id);
|
err = _srs_gb28181->notify_sip_query_catalog(id);
|
||||||
|
int code = srs_error_code(err);
|
||||||
|
if (err != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
else if(action == "sip_query_session"){
|
else if(action == "sip_query_session"){
|
||||||
SrsJsonArray* arr = SrsJsonAny::array();
|
SrsJsonArray* arr = SrsJsonAny::array();
|
||||||
data->set("sessions", arr);
|
data->set("sessions", arr);
|
||||||
|
|
||||||
uint32_t code = _srs_gb28181->query_sip_session(id, arr);
|
if ((err = _srs_gb28181->query_sip_session(id, arr)) != srs_success) {
|
||||||
if (code != ERROR_SUCCESS) {
|
int code = srs_error_code(err); srs_error_reset(err);
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue