修复bug以及日志按照,错误/sip/数据库 分割

pull/698/head
648540858 2022-08-26 18:03:09 +08:00
parent 938064199b
commit 9f680a2e9e
25 changed files with 187 additions and 113 deletions

View File

@ -31,6 +31,8 @@ public class StreamInfo {
private String rtsp; private String rtsp;
private String rtsps; private String rtsps;
private String rtc; private String rtc;
private String rtcs;
private String mediaServerId; private String mediaServerId;
private Object tracks; private Object tracks;
private String startTime; private String startTime;
@ -302,4 +304,12 @@ public class StreamInfo {
public void setIp(String ip) { public void setIp(String ip) {
this.ip = ip; this.ip = ip;
} }
public String getRtcs() {
return rtcs;
}
public void setRtcs(String rtcs) {
this.rtcs = rtcs;
}
} }

View File

@ -1,6 +1,8 @@
package com.genersoft.iot.vmp.conf.security; package com.genersoft.iot.vmp.conf.security;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import org.apache.poi.hssf.eventmodel.ERFListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
@ -28,8 +30,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi
response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified"); response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified");
response.setHeader("Content-type", "application/json;charset=UTF-8"); response.setHeader("Content-type", "application/json;charset=UTF-8");
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("code", "-1"); jsonObject.put("code", ErrorCode.ERROR401.getCode());
jsonObject.put("msg", "请登录后重新请求"); jsonObject.put("msg", ErrorCode.ERROR401.getMsg());
String logUri = "api/user/login"; String logUri = "api/user/login";
if (request.getRequestURI().contains(logUri)){ if (request.getRequestURI().contains(logUri)){
jsonObject.put("msg", e.getMessage()); jsonObject.put("msg", e.getMessage());

View File

@ -0,0 +1,24 @@
package com.genersoft.iot.vmp.conf.security;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import java.util.Collections;
public class UrlTokenHandler extends SpringBootServletInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.setSessionTrackingModes(
Collections.singleton(SessionTrackingMode.COOKIE)
);
SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
}
}

View File

@ -2,8 +2,10 @@ package com.genersoft.iot.vmp.gb28181;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.ISIPProcessorObserver;
import com.genersoft.iot.vmp.utils.DateUtil;
import gov.nist.javax.sip.SipProviderImpl; import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl; import gov.nist.javax.sip.SipStackImpl;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,6 +15,7 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.sip.*; import javax.sip.*;
import java.text.DateFormat;
import java.util.Properties; import java.util.Properties;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@ -52,7 +55,9 @@ public class SipLayer{
* gov.nist.javax.sip.SipStackImpl * gov.nist.javax.sip.SipStackImpl
* gov/nist/javax/sip/SipStackImpl.class * gov/nist/javax/sip/SipStackImpl.class
*/ */
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true"); if (logger.isDebugEnabled()) {
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
}
// 接收所有notify请求即使没有订阅 // 接收所有notify请求即使没有订阅
properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true"); properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true");
// 为_NULL _对话框传递_终止的_事件 // 为_NULL _对话框传递_终止的_事件
@ -67,9 +72,10 @@ public class SipLayer{
* 0; public static final int TRACE_MESSAGES = 16; public static final int * 0; public static final int TRACE_MESSAGES = 16; public static final int
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32; * TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32;
*/ */
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0"); if (logger.isDebugEnabled()) {
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log"); properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log"); }
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "INFO");
sipStack = (SipStackImpl) sipFactory.createSipStack(properties); sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
return sipStack; return sipStack;

View File

@ -71,7 +71,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
@Override @Override
@Async @Async
public void processRequest(RequestEvent requestEvent) { public void processRequest(RequestEvent requestEvent) {
logger.debug("\n收到请求\n{}", requestEvent.getRequest());
String method = requestEvent.getRequest().getMethod(); String method = requestEvent.getRequest().getMethod();
ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method); ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);
if (sipRequestProcessor == null) { if (sipRequestProcessor == null) {
@ -90,7 +89,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
@Async @Async
public void processResponse(ResponseEvent responseEvent) { public void processResponse(ResponseEvent responseEvent) {
Response response = responseEvent.getResponse(); Response response = responseEvent.getResponse();
logger.debug("\n收到响应\n{}", responseEvent.getResponse());
int status = response.getStatusCode(); int status = response.getStatusCode();
if (((status >= 200) && (status < 300)) || status == Response.UNAUTHORIZED) { // Success! if (((status >= 200) && (status < 300)) || status == Response.UNAUTHORIZED) { // Success!

View File

@ -640,7 +640,7 @@ public class SIPCommander implements ISIPCommander {
hookEvent.call(new InviteStreamInfo(mediaServerItem, json, callIdHeader.getCallId(), "rtp", ssrcInfo.getStream())); hookEvent.call(new InviteStreamInfo(mediaServerItem, json, callIdHeader.getCallId(), "rtp", ssrcInfo.getStream()));
subscribe.removeSubscribe(hookSubscribe); subscribe.removeSubscribe(hookSubscribe);
hookSubscribe.getContent().put("regist", false); hookSubscribe.getContent().put("regist", false);
hookSubscribe.getContent().put("schema", "rtmp"); hookSubscribe.getContent().put("schema", "rtsp");
// 添加流注销的订阅注销了后向设备发送bye // 添加流注销的订阅注销了后向设备发送bye
subscribe.addSubscribe(hookSubscribe, subscribe.addSubscribe(hookSubscribe,
(MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd)->{ (MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd)->{

View File

@ -410,6 +410,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
streamId = String.format("%s_%s", device.getDeviceId(), channelId); streamId = String.format("%s_%s", device.getDeviceId(), channelId);
} }
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false); SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false);
logger.info(JSONObject.toJSONString(ssrcInfo));
sendRtpItem.setStreamId(ssrcInfo.getStream()); sendRtpItem.setStreamId(ssrcInfo.getStream());
// 写入redis 超时时回复 // 写入redis 超时时回复
redisCatchStorage.updateSendRTPSever(sendRtpItem); redisCatchStorage.updateSendRTPSever(sendRtpItem);

View File

@ -180,7 +180,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException { private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException {
System.out.println(evt.getRequest().toString());
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
String deviceId = XmlUtil.getText(rootElement, "DeviceID"); String deviceId = XmlUtil.getText(rootElement, "DeviceID");
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);

View File

@ -164,7 +164,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
} }
} }
if (channelId.equals(sipConfig.getId())) { if ("7".equals(deviceAlarm.getAlarmMethod()) ) {
// 发送给平台的报警信息。 发送redis通知 // 发送给平台的报警信息。 发送redis通知
AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage(); AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage();
alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod())); alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod()));

View File

@ -7,12 +7,10 @@ import java.util.Map;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.service.*; import com.genersoft.iot.vmp.service.*;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@ -49,6 +47,9 @@ public class ZLMHttpHookListener {
@Autowired @Autowired
private SIPCommander cmder; private SIPCommander cmder;
@Autowired
private SIPCommanderFroPlatform commanderFroPlatform;
@Autowired @Autowired
private IPlayService playService; private IPlayService playService;
@ -237,7 +238,7 @@ public class ZLMHttpHookListener {
// 鉴权通过 // 鉴权通过
redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo); redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
// 通知assist新的callId // 通知assist新的callId
if (mediaInfo != null) { if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) {
assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null);
} }
}else { }else {
@ -427,7 +428,7 @@ public class ZLMHttpHookListener {
}else { }else {
redisCatchStorage.removeStreamAuthorityInfo(app, stream); redisCatchStorage.removeStreamAuthorityInfo(app, stream);
} }
if ("rtmp".equals(schema)){ if ("rtsp".equals(schema)){
logger.info("on_stream_changed注册->{}, app->{}, stream->{}", regist, app, stream); logger.info("on_stream_changed注册->{}, app->{}, stream->{}", regist, app, stream);
if (regist) { if (regist) {
mediaServerService.addCount(mediaServerId); mediaServerService.addCount(mediaServerId);
@ -523,17 +524,21 @@ public class ZLMHttpHookListener {
if ("rtp".equals(app)){ if ("rtp".equals(app)){
ret.put("close", true); ret.put("close", true);
StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId); StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId);
SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, null, streamId);
if (streamInfoForPlayCatch != null) { if (streamInfoForPlayCatch != null) {
// 如果在给上级推流,也不停止。 // 收到无人观看说明流也没有在往上级推送
if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) { if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
ret.put("close", false); List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByChnnelId(streamInfoForPlayCatch.getChannelId());
} else { if (sendRtpItems.size() > 0) {
cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId(), for (SendRtpItem sendRtpItem : sendRtpItems) {
streamInfoForPlayCatch.getStream(), null); ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(sendRtpItem.getPlatformId());
redisCatchStorage.stopPlay(streamInfoForPlayCatch); commanderFroPlatform.streamByeCmd(parentPlatform, sendRtpItem.getCallId());
storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId()); }
}
} }
cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId(),
streamInfoForPlayCatch.getStream(), null);
redisCatchStorage.stopPlay(streamInfoForPlayCatch);
storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
}else{ }else{
StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null, streamId, null); StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null, streamId, null);
if (streamInfoForPlayBackCatch != null) { if (streamInfoForPlayBackCatch != null) {

View File

@ -92,6 +92,7 @@ public class ZLMRTPServerFactory {
int result = -1; int result = -1;
// 查询此rtp server 是否已经存在 // 查询此rtp server 是否已经存在
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId); JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
logger.info(JSONObject.toJSONString(rtpInfo));
if(rtpInfo.getInteger("code") == 0){ if(rtpInfo.getInteger("code") == 0){
if (rtpInfo.getBoolean("exist")) { if (rtpInfo.getBoolean("exist")) {
result = rtpInfo.getInteger("local_port"); result = rtpInfo.getInteger("local_port");
@ -113,7 +114,7 @@ public class ZLMRTPServerFactory {
} }
param.put("ssrc", ssrc); param.put("ssrc", ssrc);
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
logger.info(JSONObject.toJSONString(openRtpServerResultJson));
if (openRtpServerResultJson != null) { if (openRtpServerResultJson != null) {
if (openRtpServerResultJson.getInteger("code") == 0) { if (openRtpServerResultJson.getInteger("code") == 0) {
result= openRtpServerResultJson.getInteger("port"); result= openRtpServerResultJson.getInteger("port");
@ -270,7 +271,7 @@ public class ZLMRTPServerFactory {
* *
*/ */
public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) { public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) {
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtmp", streamId); JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtsp", streamId);
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")); return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
} }
@ -290,7 +291,7 @@ public class ZLMRTPServerFactory {
* @return * @return
*/ */
public int totalReaderCount(MediaServerItem mediaServerItem, String app, String streamId) { public int totalReaderCount(MediaServerItem mediaServerItem, String app, String streamId) {
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId); JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtsp", streamId);
if (mediaInfo == null) { if (mediaInfo == null) {
return 0; return 0;
} }

View File

@ -417,7 +417,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
if (RedisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置 if (RedisUtil.zScore(key, serverItem.getId()) == null) { // 不存在则设置默认值 已存在则重置
RedisUtil.zAdd(key, serverItem.getId(), 0L); RedisUtil.zAdd(key, serverItem.getId(), 0L);
// 查询服务流数量 // 查询服务流数量
zlmresTfulUtils.getMediaList(serverItem, null, null, "rtmp",(mediaList ->{ zlmresTfulUtils.getMediaList(serverItem, null, null, "rtsp",(mediaList ->{
Integer code = mediaList.getInteger("code"); Integer code = mediaList.getInteger("code");
if (code == 0) { if (code == 0) {
JSONArray data = mediaList.getJSONArray("data"); JSONArray data = mediaList.getJSONArray("data");

View File

@ -112,6 +112,7 @@ public class MediaServiceImpl implements IMediaService {
streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
streamInfoResult.setRtc(String.format("http://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpPort(), app, stream, ObjectUtils.isEmpty(callId)?"":"&callId=" + callId));
if (mediaInfo.getHttpSSlPort() != 0) { if (mediaInfo.getHttpSSlPort() != 0) {
streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
@ -122,7 +123,7 @@ public class MediaServiceImpl implements IMediaService {
streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, ObjectUtils.isEmpty(callId)?"":"&callId=" + callId)); streamInfoResult.setRtcs(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, ObjectUtils.isEmpty(callId)?"":"&callId=" + callId));
} }
streamInfoResult.setTracks(tracks); streamInfoResult.setTracks(tracks);

View File

@ -195,6 +195,7 @@ public class PlayServiceImpl implements IPlayService {
streamId = String.format("%s_%s", device.getDeviceId(), channelId); streamId = String.format("%s_%s", device.getDeviceId(), channelId);
} }
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false); SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, device.isSsrcCheck(), false);
logger.info(JSONObject.toJSONString(ssrcInfo));
play(mediaServerItem, ssrcInfo, device, channelId, (mediaServerItemInUse, response)->{ play(mediaServerItem, ssrcInfo, device, channelId, (mediaServerItemInUse, response)->{
if (hookEvent != null) { if (hookEvent != null) {
hookEvent.response(mediaServerItem, response); hookEvent.response(mediaServerItem, response);
@ -306,7 +307,7 @@ public class PlayServiceImpl implements IPlayService {
// 单端口模式streamId也有变化需要重新设置监听 // 单端口模式streamId也有变化需要重新设置监听
if (!mediaServerItem.isRtpEnable()) { if (!mediaServerItem.isRtpEnable()) {
// 添加订阅 // 添加订阅
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", stream, true, "rtmp", mediaServerItem.getId()); HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", stream, true, "rtsp", mediaServerItem.getId());
subscribe.removeSubscribe(hookSubscribe); subscribe.removeSubscribe(hookSubscribe);
hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase()); hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response)->{ subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response)->{

View File

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.service.IPlatformChannelService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -12,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener; import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.util.List;
@Component @Component
@ -37,8 +42,6 @@ public class RedisAlarmMsgListener implements MessageListener {
return; return;
} }
String gbId = alarmChannelMessage.getGbId(); String gbId = alarmChannelMessage.getGbId();
Device device = storage.queryVideoDevice(gbId);
ParentPlatform platform = storage.queryParentPlatByServerGBId(gbId);
DeviceAlarm deviceAlarm = new DeviceAlarm(); DeviceAlarm deviceAlarm = new DeviceAlarm();
deviceAlarm.setCreateTime(DateUtil.getNow()); deviceAlarm.setCreateTime(DateUtil.getNow());
@ -46,18 +49,29 @@ public class RedisAlarmMsgListener implements MessageListener {
deviceAlarm.setAlarmDescription(alarmChannelMessage.getAlarmDescription()); deviceAlarm.setAlarmDescription(alarmChannelMessage.getAlarmDescription());
deviceAlarm.setAlarmMethod("" + alarmChannelMessage.getAlarmSn()); deviceAlarm.setAlarmMethod("" + alarmChannelMessage.getAlarmSn());
deviceAlarm.setAlarmPriority("1"); deviceAlarm.setAlarmPriority("1");
deviceAlarm.setAlarmTime(DateUtil.getNow()); deviceAlarm.setAlarmTime(DateUtil.getNowForISO8601());
deviceAlarm.setAlarmType("1"); deviceAlarm.setAlarmType("1");
deviceAlarm.setLongitude(0); deviceAlarm.setLongitude(0);
deviceAlarm.setLatitude(0); deviceAlarm.setLatitude(0);
if (ObjectUtils.isEmpty(gbId)) {
if (device != null && platform == null) { // 发送给所有的上级
commander.sendAlarmMessage(device, deviceAlarm); List<ParentPlatform> parentPlatforms = storage.queryEnableParentPlatformList(true);
}else if (device == null && platform != null){ if (parentPlatforms.size() > 0) {
commanderForPlatform.sendAlarmMessage(platform, deviceAlarm); for (ParentPlatform parentPlatform : parentPlatforms) {
commanderForPlatform.sendAlarmMessage(parentPlatform, deviceAlarm);
}
}
}else { }else {
logger.warn("无法确定" + gbId + "是平台还是设备"); Device device = storage.queryVideoDevice(gbId);
ParentPlatform platform = storage.queryParentPlatByServerGBId(gbId);
if (device != null && platform == null) {
commander.sendAlarmMessage(device, deviceAlarm);
}else if (device == null && platform != null){
commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
}else {
logger.warn("无法确定" + gbId + "是平台还是设备");
}
} }
} }
} }

View File

@ -271,7 +271,7 @@ public class RedisGbPlayMsgListener implements MessageListener {
}, userSetting.getPlatformPlayTimeout()); }, userSetting.getPlatformPlayTimeout());
// 添加订阅 // 添加订阅
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(content.getApp(), content.getStream(), true, "rtmp", mediaServerItem.getId()); HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(content.getApp(), content.getStream(), true, "rtsp", mediaServerItem.getId());
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{ subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{
dynamicTask.stop(taskKey); dynamicTask.stop(taskKey);

View File

@ -301,7 +301,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
if (jsonObject == null) { if (jsonObject == null) {
return false; return false;
} }
System.out.println(jsonObject);
if (jsonObject.getInteger("code") == 0) { if (jsonObject.getInteger("code") == 0) {
result = true; result = true;
streamProxy.setEnable(true); streamProxy.setEnable(true);
@ -427,7 +426,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
if(data != null && data.size() > 0) { if(data != null && data.size() > 0) {
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
JSONObject streamJSONObj = data.getJSONObject(i); JSONObject streamJSONObj = data.getJSONObject(i);
if ("rtmp".equals(streamJSONObj.getString("schema"))) { if ("rtsp".equals(streamJSONObj.getString("schema"))) {
StreamInfo streamInfo = new StreamInfo(); StreamInfo streamInfo = new StreamInfo();
String app = streamJSONObj.getString("app"); String app = streamJSONObj.getString("app");
String stream = streamJSONObj.getString("stream"); String stream = streamJSONObj.getString("stream");

View File

@ -237,4 +237,6 @@ public interface IRedisCatchStorage {
* redis * redis
*/ */
void sendStreamPushRequestedMsgForStatus(); void sendStreamPushRequestedMsgForStatus();
List<SendRtpItem> querySendRTPServerByChnnelId(String channelId);
} }

View File

@ -379,6 +379,24 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
} }
} }
@Override
public List<SendRtpItem> querySendRTPServerByChnnelId(String channelId) {
if (channelId == null) {
return null;
}
String platformGbId = "*";
String callId = "*";
String streamId = "*";
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
List<Object> scan = RedisUtil.scan(key);
List<SendRtpItem> result = new ArrayList<>();
for (Object o : scan) {
result.add((SendRtpItem) RedisUtil.get((String) o));
}
return result;
}
@Override @Override
public List<SendRtpItem> querySendRTPServer(String platformGbId) { public List<SendRtpItem> querySendRTPServer(String platformGbId) {
if (platformGbId == null) { if (platformGbId == null) {

View File

@ -82,4 +82,9 @@ public class DateUtil {
return false; return false;
} }
} }
public static String getNowForISO8601() {
LocalDateTime nowDateTime = LocalDateTime.now();
return formatterISO8601.format(nowDateTime);
}
} }

View File

@ -197,7 +197,7 @@ public class PlatformController {
@Operation(summary = "保存上级平台信息") @Operation(summary = "保存上级平台信息")
@PostMapping("/save") @PostMapping("/save")
@ResponseBody @ResponseBody
public String savePlatform(@RequestBody ParentPlatform parentPlatform) { public void savePlatform(@RequestBody ParentPlatform parentPlatform) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("保存上级平台信息API调用"); logger.debug("保存上级平台信息API调用");
@ -247,7 +247,6 @@ public class PlatformController {
// 停止订阅相关的定时任务 // 停止订阅相关的定时任务
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId()); subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
} }
return null;
} else { } else {
throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败"); throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
} }

View File

@ -5,6 +5,7 @@ import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadSheet;
import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.SecurityUtils; import com.genersoft.iot.vmp.conf.security.SecurityUtils;
import com.genersoft.iot.vmp.conf.security.dto.LoginUser; import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.GbStream;
@ -17,6 +18,7 @@ import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.service.IStreamPushService; import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler; import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler;
import com.genersoft.iot.vmp.vmanager.bean.BatchGBStreamParam; import com.genersoft.iot.vmp.vmanager.bean.BatchGBStreamParam;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -95,11 +97,9 @@ public class StreamPushController {
@PostMapping(value = "/save_to_gb") @PostMapping(value = "/save_to_gb")
@ResponseBody @ResponseBody
@Operation(summary = "将推流添加到国标") @Operation(summary = "将推流添加到国标")
public Object saveToGB(@RequestBody GbStream stream){ public void saveToGB(@RequestBody GbStream stream){
if (streamPushService.saveToGB(stream)){ if (!streamPushService.saveToGB(stream)){
return "success"; throw new ControllerException(ErrorCode.ERROR100);
}else {
return "fail";
} }
} }
@ -107,11 +107,9 @@ public class StreamPushController {
@DeleteMapping(value = "/remove_form_gb") @DeleteMapping(value = "/remove_form_gb")
@ResponseBody @ResponseBody
@Operation(summary = "将推流移出到国标") @Operation(summary = "将推流移出到国标")
public Object removeFormGB(@RequestBody GbStream stream){ public void removeFormGB(@RequestBody GbStream stream){
if (streamPushService.removeFromGB(stream)){ if (!streamPushService.removeFromGB(stream)){
return "success"; throw new ControllerException(ErrorCode.ERROR100);
}else {
return "fail";
} }
} }
@ -121,25 +119,21 @@ public class StreamPushController {
@Operation(summary = "中止一个推流") @Operation(summary = "中止一个推流")
@Parameter(name = "app", description = "应用名", required = true) @Parameter(name = "app", description = "应用名", required = true)
@Parameter(name = "stream", description = "流id", required = true) @Parameter(name = "stream", description = "流id", required = true)
public Object stop(String app, String streamId){ public void stop(String app, String streamId){
if (streamPushService.stop(app, streamId)){ if (!streamPushService.stop(app, streamId)){
return "success"; throw new ControllerException(ErrorCode.ERROR100);
}else {
return "fail";
} }
} }
@DeleteMapping(value = "/batchStop") @DeleteMapping(value = "/batchStop")
@ResponseBody @ResponseBody
@Operation(summary = "中止多个推流") @Operation(summary = "中止多个推流")
public Object batchStop(@RequestBody BatchGBStreamParam batchGBStreamParam){ public void batchStop(@RequestBody BatchGBStreamParam batchGBStreamParam){
if (batchGBStreamParam.getGbStreams().size() == 0) { if (batchGBStreamParam.getGbStreams().size() == 0) {
return "fail"; throw new ControllerException(ErrorCode.ERROR100);
} }
if (streamPushService.batchStop(batchGBStreamParam.getGbStreams())){ if (!streamPushService.batchStop(batchGBStreamParam.getGbStreams())){
return "success"; throw new ControllerException(ErrorCode.ERROR100);
}else {
return "fail";
} }
} }
@ -249,7 +243,7 @@ public class StreamPushController {
@Parameter(name = "app", description = "应用名", required = true) @Parameter(name = "app", description = "应用名", required = true)
@Parameter(name = "stream", description = "流id", required = true) @Parameter(name = "stream", description = "流id", required = true)
@Parameter(name = "mediaServerId", description = "媒体服务器id") @Parameter(name = "mediaServerId", description = "媒体服务器id")
public WVPResult<StreamInfo> getPlayUrl(@RequestParam String app,@RequestParam String stream, public StreamInfo getPlayUrl(@RequestParam String app,@RequestParam String stream,
@RequestParam(required = false) String mediaServerId){ @RequestParam(required = false) String mediaServerId){
boolean authority = false; boolean authority = false;
// 是否登陆用户, 登陆用户返回完整信息 // 是否登陆用户, 登陆用户返回完整信息
@ -257,52 +251,38 @@ public class StreamPushController {
if (userInfo!= null) { if (userInfo!= null) {
authority = true; authority = true;
} }
WVPResult<StreamInfo> result = new WVPResult<>();
StreamPushItem push = streamPushService.getPush(app, stream); StreamPushItem push = streamPushService.getPush(app, stream);
if (push != null && !push.isSelf()) { if (push != null && !push.isSelf()) {
result.setCode(-1); throw new ControllerException(ErrorCode.ERROR100.getCode(), "来自其他平台的推流信息");
result.setMsg("来自其他平台的推流信息");
return result;
} }
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority); StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
if (streamInfo != null){ if (streamInfo == null){
result.setCode(0); throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取播放地址失败");
result.setMsg("success");
result.setData(streamInfo);
}else {
result.setCode(-1);
result.setMsg("获取播放地址失败");
} }
return streamInfo;
return result;
} }
/** /**
* *
* @param stream * @param stream
* @return * @return
*/ */
@PostMapping(value = "/add") @PostMapping(value = "/add")
@ResponseBody @ResponseBody
@Operation(summary = "停止视频回放") @Operation(summary = "添加推流信息")
public WVPResult<StreamInfo> add(@RequestBody StreamPushItem stream){ public void add(@RequestBody StreamPushItem stream){
if (ObjectUtils.isEmpty(stream.getGbId())) { if (ObjectUtils.isEmpty(stream.getGbId())) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "国标ID不可为空");
return new WVPResult<>(400, "国标ID不可为空", null);
} }
if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) { if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) {
return new WVPResult<>(400, "app或stream不可为空", null); throw new ControllerException(ErrorCode.ERROR400.getCode(), "app或stream不可为空");
} }
stream.setStatus(false); stream.setStatus(false);
stream.setPushIng(false); stream.setPushIng(false);
stream.setAliveSecond(0L); stream.setAliveSecond(0L);
stream.setTotalReaderCount("0"); stream.setTotalReaderCount("0");
boolean result = streamPushService.add(stream); if (!streamPushService.add(stream)) {
throw new ControllerException(ErrorCode.ERROR100);
if (result) {
return new WVPResult<>(0, "success", null);
}else {
return new WVPResult<>(-1, "fail", null);
} }
} }
} }

View File

@ -77,25 +77,35 @@
</encoder> </encoder>
</appender> </appender>
<!-- 生成 SIP日志追加 -->
<appender name="sipRollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--历史日志文件输出的文件名 -->
<FileNamePattern>${LOG_HOME}/sip-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>30</MaxHistory>
<maxFileSize>50MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
</encoder>
</appender>
<!-- 日志输出级别 --> <!-- 日志输出级别 -->
<root level="INFO"> <root level="INFO">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />
<appender-ref ref="RollingFile" />
<appender-ref ref="RollingFileError" />
</root> </root>
<!-- <logger name="com.genersoft.iot.vmp.storager.dao" level="INFO">--> <logger name="GB28181_SIP" level="debug" additivity="true">
<!-- <appender-ref ref="STDOUT"/>--> <appender-ref ref="RollingFileError"/>
<!-- </logger>--> <appender-ref ref="sipRollingFile"/>
<!-- <logger name="com.genersoft.iot.vmp.gb28181" level="INFO">--> </logger>
<!-- <appender-ref ref="STDOUT"/>-->
<!-- </logger>-->
<!--记录druid-sql的记录--> <!--记录druid-sql的记录-->
<logger name="druid.sql.Statement" level="debug" additivity="true"> <logger name="com.genersoft.iot.vmp.storager.dao" level="info" additivity="true">
<!--AppenderRef ref="Console"/--> <!--AppenderRef ref="Console"/-->
<!-- <appender-ref ref="RollingFile"/>-->
<appender-ref ref="RollingFileError"/> <appender-ref ref="RollingFileError"/>
<appender-ref ref="druidSqlRollingFile"/> <appender-ref ref="druidSqlRollingFile"/>
</logger> </logger>

View File

@ -371,7 +371,7 @@ export default {
if (tab.name === "codec") { if (tab.name === "codec") {
this.$axios({ this.$axios({
method: 'get', method: 'get',
url: '/zlm/' +this.mediaServerId+ '/index/api/getMediaInfo?vhost=__defaultVhost__&schema=rtmp&app='+ this.app +'&stream='+ this.streamId url: '/zlm/' +this.mediaServerId+ '/index/api/getMediaInfo?vhost=__defaultVhost__&schema=rtsp&app='+ this.app +'&stream='+ this.streamId
}).then(function (res) { }).then(function (res) {
that.tracksLoading = false; that.tracksLoading = false;
if (res.data.code == 0 && res.data.tracks) { if (res.data.code == 0 && res.data.tracks) {

View File

@ -268,30 +268,29 @@ export default {
} }
}, },
saveForm: function (){ saveForm: function (){
var that = this; this.$axios({
that.$axios({
method: 'post', method: 'post',
url: this.saveUrl, url: this.saveUrl,
data: that.platform data: this.platform
}).then(function (res) { }).then((res) =>{
if (res.data.code === 0) { if (res.data.code === 0) {
that.$message({ this.$message({
showClose: true, showClose: true,
message: "保存成功", message: "保存成功",
type: "success", type: "success",
}); });
that.showDialog = false; this.showDialog = false;
if (that.listChangeCallback != null) { if (this.listChangeCallback != null) {
that.listChangeCallback(); this.listChangeCallback();
} }
}else { }else {
that.$message({ this.$message({
showClose: true, showClose: true,
message: res.data.msg, message: res.data.msg,
type: "error", type: "error",
}); });
} }
}).catch(function (error) { }).catch((error)=> {
console.log(error); console.log(error);
}); });
}, },