| | |
| | | import javax.sip.message.Request;
|
| | | import javax.sip.message.Response;
|
| | |
|
| | | import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
| | | import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.*;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
| | |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
|
| | | import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
| | | import com.genersoft.iot.vmp.service.IPlayService;
|
| | | import gov.nist.javax.sip.address.AddressImpl;
|
| | | import gov.nist.javax.sip.address.SipUri;
|
| | |
| | | }
|
| | |
|
| | | // 查询请求方是否上级平台
|
| | | ParentPlatform platform = storager.queryParentPlatById(requesterId);
|
| | | ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId);
|
| | | if (platform != null) {
|
| | | // 查询平台下是否有该通道
|
| | | DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId);
|
| | | GbStream gbStream = storager.queryStreamInParentPlatform(requesterId, channelId);
|
| | | // 不是通道可能是直播流
|
| | | if (channel != null || gbStream != null ) {
|
| | | if (channel != null && gbStream == null ) {
|
| | | if (channel.getStatus() == 0) {
|
| | | logger.info("通道离线,返回400");
|
| | | responseAck(evt, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline");
|
| | | return;
|
| | | }
|
| | | responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中
|
| | | }else if(channel == null && gbStream != null){
|
| | | Boolean streamReady = zlmrtpServerFactory.isStreamReady(gbStream.getApp(), gbStream.getStream());
|
| | | if (!streamReady) {
|
| | | logger.info("[ app={}, stream={} ]通道离线,返回400",gbStream.getApp(), gbStream.getStream());
|
| | | responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline");
|
| | | return;
|
| | | }
|
| | | responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 通道存在,发181,呼叫转接中
|
| | | }else {
|
| | | logger.info("通道不存在,返回404");
|
| | |
| | | // 通知下级推流,
|
| | | PlayResult playResult = playService.play(device.getDeviceId(), channelId, (responseJSON)->{
|
| | | // 收到推流, 回复200OK, 等待ack
|
| | | if (sendRtpItem == null) return;
|
| | | // if (sendRtpItem == null) return;
|
| | | sendRtpItem.setStatus(1);
|
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
| | | // TODO 添加对tcp的支持
|
| | | MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
| | | ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
| | |
| | | // 写入redis, 超时时回复
|
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
| | |
|
| | | // 检测直播流是否在线
|
| | | Boolean streamReady = zlmrtpServerFactory.isStreamReady(gbStream.getApp(), gbStream.getStream());
|
| | | if (streamReady) {
|
| | | sendRtpItem.setStatus(1);
|
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
| | | // TODO 添加对tcp的支持
|
| | | MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
| | | content.append("s=Play\r\n");
|
| | | content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | | content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
|
| | | content.append("a=sendonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("y="+ ssrc + "\r\n");
|
| | | content.append("f=\r\n");
|
| | | sendRtpItem.setStatus(1);
|
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
| | | // TODO 添加对tcp的支持
|
| | | ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
| | | content.append("s=Play\r\n");
|
| | | content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | | content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
|
| | | content.append("a=sendonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("y="+ ssrc + "\r\n");
|
| | | content.append("f=\r\n");
|
| | |
|
| | | try {
|
| | | responseAck(evt, content.toString());
|
| | | } catch (SipException e) {
|
| | | e.printStackTrace();
|
| | | } catch (InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | try {
|
| | | responseAck(evt, content.toString());
|
| | | } catch (SipException e) {
|
| | | e.printStackTrace();
|
| | | } catch (InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | getServerTransaction(evt).sendResponse(response);
|
| | | }
|
| | |
|
| | | private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
| | | response.setReasonPhrase(msg);
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 回复带sdp的200
|
| | | * @param evt
|