background
28181 protocol called the GB / T28181 "security video surveillance network system information transmission, switching, control technology requirements", was proposed by the Ministry of Public Security Technology Information Bureau, the National Security Alarm System Standardization Technical Committee (SAC / TC100) centralized, Ministry of Public Security a number of units jointly drafted a national standard (hereinafter referred to as 28181).
28181 protocol in the country safe city, transport, roads and other monitoring is widely used, if want a unified large monitoring platform, supports 28181 protocol access is essential. Today, many customers are want to expand on the basis of 28181 platform previously used on.
Explanation
LiveGBS GB28181 GB28181 streaming media server is responsible for the device / platform pushed into ES PS circulation flow and distribution.
Meanwhile, LiveGBS provide external HTTP API interface through the interface can learn streaming forwarding operation status information services, forwarding session information, server configuration and version information;
LiveGBS GB28181 streaming server provides the following functionality:
1. accepting and processing requests GB28181 Streaming access server (if permission verification plug flow is called authentication server interface);
2. Streaming GB28181 accept and process equipment;
3. Real streaming media, PS (TS) switch ES;
4. push ES EasyDSS flow stream media server;
5. GB28181 access server to accept and process the request disconnection plug flow;
6. External providing server acquires the status information, control http API interfaces;
LiveGBS live streaming detailed flow
An access server sends an Invite request to
the access server sends an Invite request to the streaming server, a streaming service request return message body carries the SDP message body,
which describes the content of the media server receives the media stream IP, port, media format;
Invite request code show as below:
const options = {
serialServer: serialServer,
serialDevice: code,
method: common.SIP_INVITE,
contentType: common.CONTENT_NONE,
content: sdp,
host: hostip,
port: hostport,
rtpovertcp: (parseInt(rtpovertcp)===0?'UDP':'TCP')
};
console.log('inviteMediaServer......sendRequest' + JSON.stringify(options));
uas.sendRequest(options);
2 Invite streaming service request processing and receiving ACK response
streaming service accepts Invite request, and processes the request in a callback function, js code is as follows:
uas.on('invite', async ctx => {
const request = ctx.request;
const content = JSON.parse(request.content);
const status = 200;
const serial = sip.parseUri(request.uri).user;
const host = config.server.serverHost;
let ssid = serial.substring(16,20);// PrefixInteger(sessionid,4);
let sirialid = serial.substring(3,8);
const ssrc = "0"+sirialid+ssid;
console.log("ssrc = "+ssrc);
let sdp = '';
//如果已存在
let bHas = this.session_.has(serial);
console.log(bHas);
if (bHas) {
console.log('this.session_ has exist serial: '+serial);
sdp = '';
}
else{
let port = config.server.udpPort;//流媒体接收TCP端口
let transport = 'RTP/AVP';
let a = "a=recvonly\r\n";
if(content.rtpovertcp === 'TCP' )
{
port = config.server.tcpPort;//流媒体接收TCP端口
transport = 'TCP/RTP/AVP';
a = "a=recvonly\r\na=setup:passive\r\n";
}
sdp = "v=0\r\n" +
`o=${serial} 0 0 IN IP4 ${host}\r\n` +
"s=Play\r\n" +
`c=IN IP4 ${host}\r\n` +
"t=0 0\r\n" +
`m=video ${port} ${transport} 96 98 97\r\n` +
"a=rtpmap:96 PS/90000\r\n" +
"a=rtpmap:98 H264/90000\r\n" +
"a=rtpmap:97 MPEG4/90000\r\n" +
`${a}`+
//`a=connection:new\r\n` +
`y=${ssrc}\r\n`;
// A new channel is coming, delete the old
rtpserver.deleteChannels(parseInt(ssrc));
// Create a new stram,and add to redis
this.registerStream(parseInt(ssrc),uuidv4(),true);
}
let response = sip.makeResponse(request, status, common.messages[status]);
uas.sendAckEx(response, sdp);
});
Codes indicated above, we provide in the SDP message body transmission of two streams, the UDP and TCP, respectively, controlled by Invite request brought "rtpovertcp" parameter, because it is TCP transmission mode without packet loss in GB28181 push the public network server equipment flow scenarios can be widely used, however, for most of the market to support national standard devices do not support plug-flow mode tcp, udp is still the mainstream of plug flow mode, however, it has been tested and udp plug flow mode relatively poor public network applications it is desirable to further improve or optimize.
3 the access server receives ACK response and begins to push the device an Invite message stream
callback function js ack response processing code is as follows:
uas.once('ack', async ctx => {
const request = ctx.request;
const callId = request.headers['call-id'];
if (request.content.length > 0 )
{
const serial = serialDevice;//sip.parseUri(request.headers.from.uri).user;
let response ;
if(!this.session_.has(callId))
{
response = await this.inviteDevice(serial, code, callId, request.content);
//Invite Device is complete
if(response != undefined)
{
if(response.content)
{
const transform = require('sdp');
const res = transform.parse(response.content);
console.log(res.media[0].protocol);
if((res.media[0].protocol === 'RTP/AVP'&&parseInt(rtpovertcp)===0) ||
(res.media[0].protocol === 'TCP/RTP/AVP'&&parseInt(rtpovertcp)===1) ){
if (response.status === 200 )
{
//send ack to stream server
this.ackMediaServer(response.status,request,request.content);
this.session_.set(callId, response);
}
}
else{
response.status = 700;
}
}
console.log('inviteMediaServer ack is coming.......response='+JSON.stringify(response));
}
resolve(response);
}
else{
console.log('inviteMediaServer this.session_.has: '+callId);
}
}
});
As shown in the code, after the completion of the request InviteDevice, we did a special treatment in the process returned Response, i.e.: if the TCP stream Discovery pull the pull flow returns its response plug flow model is still 'RTP / AVP' of UDP mode, we believe that the device does not support TCP mode, returning to the top 700, it does not support streaming media transmission.
4 Invite apparatus 200 returns a normal response to the streaming media server and transmitting
the code reflected at point 3.
5 streaming media service that accepts flow request success response
uas.on('ack', async ctx => {
const request = ctx.request;
if (request.content.length === 0) {
return;
}
const serial = sip.parseUri(request.headers.from.uri).user;
this.session_.set(serial, request);
const ssrc = serialTossrc(serial);
// resole a new stram,and refresh to redis
const info = JSON.parse(await redis.get(`stream:${parseInt(ssrc)}`));
this.registerStream(parseInt(ssrc),info.uuId,false);
});
At this point, pull the whole flow process has been completed.
For more information
Download: https://www.liveqing.com/docs/download/LiveGBS.html