From 2601150f036e17604ee0431144a7ab921b7f8206 Mon Sep 17 00:00:00 2001
From: 648540858 <18010473990@163.com>
Date: 星期四, 02 九月 2021 15:47:42 +0800
Subject: [PATCH] 更新readme
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java | 210 +++++++++++++++++++++++++++++++++++++---------------
1 files changed, 150 insertions(+), 60 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
index a7b3d94..fcc1487 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
@@ -1,29 +1,24 @@
package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
import javax.sdp.*;
-import javax.sip.InvalidArgumentException;
-import javax.sip.RequestEvent;
-import javax.sip.SipException;
-import javax.sip.SipFactory;
+import javax.sip.*;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.header.*;
import javax.sip.message.Request;
import javax.sip.message.Response;
-import com.genersoft.iot.vmp.conf.MediaServerConfig;
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
+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.gb28181.transmit.request.SIPRequestAbstractProcessor;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.service.IMediaServerService;
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.service.IPlayService;
+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;
import org.slf4j.Logger;
@@ -53,6 +48,8 @@
private IPlayService playService;
private ZLMRTPServerFactory zlmrtpServerFactory;
+
+ private IMediaServerService mediaServerService;
public ZLMRTPServerFactory getZlmrtpServerFactory() {
return zlmrtpServerFactory;
@@ -89,16 +86,39 @@
}
// 鏌ヨ璇锋眰鏂规槸鍚︿笂绾у钩鍙�
- ParentPlatform platform = storager.queryParentPlatById(requesterId);
+ ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId);
if (platform != null) {
// 鏌ヨ骞冲彴涓嬫槸鍚︽湁璇ラ�氶亾
DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId);
- if (channel == null) {
+ GbStream gbStream = storager.queryStreamInParentPlatform(requesterId, channelId);
+ MediaServerItem mediaServerItem = 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){
+ String mediaServerId = gbStream.getMediaServerId();
+ mediaServerItem = mediaServerService.getOne(mediaServerId);
+ if (mediaServerItem == null) {
+ logger.info("[ app={}, stream={} ]zlm鎵句笉鍒帮紝杩斿洖410",gbStream.getApp(), gbStream.getStream());
+ responseAck(evt, Response.GONE, "media server not found");
+ return;
+ }
+ Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, 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");
responseAck(evt, Response.NOT_FOUND); // 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪
return;
- }else {
- responseAck(evt, Response.CALL_IS_BEING_FORWARDED); // 閫氶亾瀛樺湪锛屽彂181锛屽懠鍙浆鎺ヤ腑
}
// 瑙f瀽sdp娑堟伅, 浣跨敤jainsip 鑷甫鐨剆dp瑙f瀽鏂瑰紡
String contentString = new String(request.getRawContent());
@@ -118,8 +138,8 @@
//boolean recvonly = false;
boolean mediaTransmissionTCP = false;
Boolean tcpActive = null;
- for (int i = 0; i < mediaDescriptions.size(); i++) {
- MediaDescription mediaDescription = (MediaDescription)mediaDescriptions.get(i);
+ for (Object description : mediaDescriptions) {
+ MediaDescription mediaDescription = (MediaDescription) description;
Media media = mediaDescription.getMedia();
Vector mediaFormats = media.getMediaFormats(false);
@@ -135,7 +155,7 @@
mediaTransmissionTCP = true;
if ("active".equals(setup)) {
tcpActive = true;
- }else if ("passive".equals(setup)) {
+ } else if ("passive".equals(setup)) {
tcpActive = false;
}
}
@@ -153,38 +173,105 @@
String addressStr = sdp.getOrigin().getAddress();
//String sessionName = sdp.getSessionName().getValue();
logger.info("[涓婄骇鐐规挱]鐢ㄦ埛锛歿}锛� 鍦板潃锛歿}:{}锛� ssrc锛歿}", username, addressStr, port, ssrc);
+ Device device = null;
+ // 閫氳繃 channel 鍜� gbStream 鏄惁涓簄ull 鍊煎垽鏂潵婧愭槸鐩存挱娴佸悎閫傚浗鏍�
+ if (channel != null) {
+ device = storager.queryVideoDeviceByPlatformIdAndChannelId(requesterId, channelId);
+ if (device == null) {
+ logger.warn("鐐规挱骞冲彴{}鐨勯�氶亾{}鏃舵湭鎵惧埌璁惧淇℃伅", requesterId, channel);
+ responseAck(evt, Response.SERVER_INTERNAL_ERROR);
+ return;
+ }
+ mediaServerItem = playService.getNewMediaServerItem(device);
+ if (mediaServerItem == null) {
+ logger.warn("鏈壘鍒板彲鐢ㄧ殑zlm");
+ responseAck(evt, Response.BUSY_HERE);
+ return;
+ }
+ SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
+ device.getDeviceId(), channelId,
+ mediaTransmissionTCP);
+ if (tcpActive != null) {
+ sendRtpItem.setTcpActive(tcpActive);
+ }
+ if (sendRtpItem == null) {
+ logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
+ responseAck(evt, Response.BUSY_HERE);
+ return;
+ }
- Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(requesterId, channelId);
- if (device == null) {
- logger.warn("鐐规挱骞冲彴{}鐨勯�氶亾{}鏃舵湭鎵惧埌璁惧淇℃伅", requesterId, channel);
- responseAck(evt, Response.SERVER_INTERNAL_ERROR);
- return;
- }
- SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(addressStr, port, ssrc, requesterId, device.getDeviceId(), channelId,
- mediaTransmissionTCP);
- if (tcpActive != null) {
- sendRtpItem.setTcpActive(tcpActive);
- }
- if (sendRtpItem == null) {
- logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
- responseAck(evt, Response.BUSY_HERE);
- return;
- }
+ // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ // 閫氱煡涓嬬骇鎺ㄦ祦锛�
+ PlayResult playResult = playService.play(mediaServerItem,device.getDeviceId(), channelId, (mediaServerItemInUSe, responseJSON)->{
+ // 鏀跺埌鎺ㄦ祦锛� 鍥炲200OK, 绛夊緟ack
+ // if (sendRtpItem == null) return;
+ sendRtpItem.setStatus(1);
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ // TODO 娣诲姞瀵箃cp鐨勬敮鎸�
- // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
- redisCatchStorage.updateSendRTPSever(sendRtpItem);
- // 閫氱煡涓嬬骇鎺ㄦ祦锛�
- PlayResult playResult = playService.play(device.getDeviceId(), channelId, (responseJSON)->{
- // 鏀跺埌鎺ㄦ祦锛� 鍥炲200OK, 绛夊緟ack
+ StringBuffer content = new StringBuffer(200);
+ content.append("v=0\r\n");
+ content.append("o="+"00000"+" 0 0 IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n");
+ content.append("s=Play\r\n");
+ content.append("c=IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\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();
+ }
+ } ,((event) -> {
+ // 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
+ Response response = null;
+ try {
+ response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
+ ServerTransaction serverTransaction = getServerTransaction(evt);
+ serverTransaction.sendResponse(response);
+ if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
+ } catch (ParseException | SipException | InvalidArgumentException e) {
+ e.printStackTrace();
+ }
+ }));
+ if (logger.isDebugEnabled()) {
+ logger.debug(playResult.getResult().toString());
+ }
+
+ }else if (gbStream != null) {
+ SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
+ gbStream.getApp(), gbStream.getStream(), channelId,
+ mediaTransmissionTCP);
+
+ if (tcpActive != null) {
+ sendRtpItem.setTcpActive(tcpActive);
+ }
+ if (sendRtpItem == null) {
+ logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
+ responseAck(evt, Response.BUSY_HERE);
+ return;
+ }
+
+ // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+
sendRtpItem.setStatus(1);
redisCatchStorage.updateSendRTPSever(sendRtpItem);
// TODO 娣诲姞瀵箃cp鐨勬敮鎸�
- 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("o="+"00000"+" 0 0 IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
content.append("s=Play\r\n");
- content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
+ content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\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");
@@ -201,19 +288,8 @@
} catch (ParseException e) {
e.printStackTrace();
}
- },(event -> {
- // 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
- Response response = null;
- try {
- response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
- getServerTransaction(evt).sendResponse(response);
- } catch (ParseException | SipException | InvalidArgumentException e) {
- e.printStackTrace();
- }
- }));
- if (logger.isDebugEnabled()) {
- logger.debug(playResult.getResult().toString());
}
+
} else {
// 闈炰笂绾у钩鍙拌姹傦紝鏌ヨ鏄惁璁惧璇锋眰锛堥�氬父涓烘帴鏀惰闊冲箍鎾殑璁惧锛�
Device device = storager.queryVideoDevice(requesterId);
@@ -275,11 +351,6 @@
String username = sdp.getOrigin().getUsername();
String addressStr = sdp.getOrigin().getAddress();
logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}", username, addressStr, port, ssrc);
-
-
-
-
-
} else {
logger.warn("鏉ヨ嚜鏃犳晥璁惧/骞冲彴鐨勮姹�");
@@ -298,6 +369,7 @@
}
}
+
/***
* 鍥炲鐘舵�佺爜
* 100 trying
@@ -311,7 +383,17 @@
*/
private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
- getServerTransaction(evt).sendResponse(response);
+ ServerTransaction serverTransaction = getServerTransaction(evt);
+ serverTransaction.sendResponse(response);
+ if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
+ }
+
+ private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
+ response.setReasonPhrase(msg);
+ ServerTransaction serverTransaction = getServerTransaction(evt);
+ serverTransaction.sendResponse(response);
+ if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
}
/**
@@ -381,4 +463,12 @@
public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
this.redisCatchStorage = redisCatchStorage;
}
+
+ public IMediaServerService getMediaServerService() {
+ return mediaServerService;
+ }
+
+ public void setMediaServerService(IMediaServerService mediaServerService) {
+ this.mediaServerService = mediaServerService;
+ }
}
--
Gitblit v1.8.0