修复并发点播时可能出现的rtpServer开启但是还未收到流的情况,编码类型136,137,138默认开启音频通道

pull/608/head
648540858 2022-09-07 16:18:35 +08:00
parent e7bdcc1f8d
commit ec0ec5eb54
11 changed files with 85 additions and 33 deletions

View File

@ -356,7 +356,7 @@ public class SIPCommander implements ISIPCommander {
// String streamMode = device.getStreamMode().toUpperCase(); // String streamMode = device.getStreamMode().toUpperCase();
logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort()); logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
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.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{ subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{
if (event != null) { if (event != null) {
event.response(mediaServerItemInUse, json); event.response(mediaServerItemInUse, json);
@ -524,7 +524,7 @@ public class SIPCommander implements ISIPCommander {
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
: udpSipProvider.getNewCallId(); : udpSipProvider.getNewCallId();
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtmp", mediaServerItem.getId()); HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
// 添加订阅 // 添加订阅
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{ subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{
if (hookEvent != null) { if (hookEvent != null) {

View File

@ -16,9 +16,7 @@ import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlayService; import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.IStreamProxyService; import com.genersoft.iot.vmp.service.IStreamProxyService;
@ -90,6 +88,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
@Autowired @Autowired
private IMediaServerService mediaServerService; private IMediaServerService mediaServerService;
@Autowired
private ZlmHttpHookSubscribe zlmHttpHookSubscribe;
@Autowired @Autowired
private SIPProcessorObserver sipProcessorObserver; private SIPProcessorObserver sipProcessorObserver;
@ -400,9 +401,16 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
if (playTransaction != null) { if (playTransaction != null) {
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, "rtp", playTransaction.getStream()); Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, "rtp", playTransaction.getStream());
if (!streamReady) { if (!streamReady) {
boolean hasRtpServer = mediaServerService.checkRtpServer(mediaServerItem, "rtp", playTransaction.getStream());
if (hasRtpServer) {
logger.info("[上级点播]已经开启rtpServer但是尚未收到流开启监听流的到来");
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", playTransaction.getStream(), true, "rtsp", mediaServerItem.getId());
zlmHttpHookSubscribe.addSubscribe(hookSubscribe, hookEvent);
}else {
playTransaction = null; playTransaction = null;
} }
} }
}
if (playTransaction == null) { if (playTransaction == null) {
String streamId = null; String streamId = null;
if (mediaServerItem.isRtpEnable()) { if (mediaServerItem.isRtpEnable()) {
@ -564,7 +572,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
} else if ("push".equals(gbStream.getStreamType())) { } else if ("push".equals(gbStream.getStreamType())) {
if (!platform.isStartOfflinePush()) { if (!platform.isStartOfflinePush()) {
// 平台设置中关闭了拉起离线的推流则直接回复 // 平台设置中关闭了拉起离线的推流则直接回复
responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel unavailable"); responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing");
return; return;
} }
// 发送redis消息以使设备上线 // 发送redis消息以使设备上线

View File

@ -203,6 +203,12 @@ public class XmlUtil {
return null; return null;
} }
deviceChannel.setChannelId(channelId); deviceChannel.setChannelId(channelId);
int channelTypeCode = Integer.parseInt(channelId.substring(10, 13));
if (channelTypeCode == 136 || channelTypeCode == 137 || channelTypeCode == 138) {
deviceChannel.setHasAudio(true);
}else {
deviceChannel.setHasAudio(false);
}
if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) { if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) {
// 除了ADD和update情况下需要识别全部内容 // 除了ADD和update情况下需要识别全部内容
return deviceChannel; return deviceChannel;
@ -396,7 +402,6 @@ public class XmlUtil {
} else { } else {
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType"))); deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
} }
deviceChannel.setHasAudio(true); // 默认含有音频播放时再检查是否有音频及是否AAC
return deviceChannel; return deviceChannel;
} }
} }

View File

@ -96,6 +96,10 @@ public class ZLMRTPServerFactory {
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");
if (result == 0) {
// 此时说明rtpServer已经创建但是流还没有推上来
}
return result; return result;
} }
}else if(rtpInfo.getInteger("code") == -2){ }else if(rtpInfo.getInteger("code") == -2){

View File

@ -83,4 +83,6 @@ public interface IMediaServerService {
MediaServerItem getDefaultMediaServer(); MediaServerItem getDefaultMediaServer();
void updateMediaServerKeepalive(String mediaServerId, JSONObject data); void updateMediaServerKeepalive(String mediaServerId, JSONObject data);
boolean checkRtpServer(MediaServerItem mediaServerItem, String rtp, String stream);
} }

View File

@ -147,9 +147,11 @@ public class MediaServerServiceImpl implements IMediaServerService {
if (streamId == null) { if (streamId == null) {
streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
} }
int rtpServerPort = mediaServerItem.getRtpProxyPort(); int rtpServerPort;
if (mediaServerItem.isRtpEnable()) { if (mediaServerItem.isRtpEnable()) {
rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port);
} else {
rtpServerPort = mediaServerItem.getRtpProxyPort();
} }
RedisUtil.set(key, mediaServerItem); RedisUtil.set(key, mediaServerItem);
return new SSRCInfo(rtpServerPort, ssrc, streamId); return new SSRCInfo(rtpServerPort, ssrc, streamId);
@ -681,4 +683,13 @@ public class MediaServerServiceImpl implements IMediaServerService {
} }
} }
} }
@Override
public boolean checkRtpServer(MediaServerItem mediaServerItem, String app, String stream) {
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, stream);
if(rtpInfo.getInteger("code") == 0){
return rtpInfo.getBoolean("exist");
}
return false;
}
} }

View File

@ -164,7 +164,18 @@ public class PlayServiceImpl implements IPlayService {
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId); JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
if(rtpInfo.getInteger("code") == 0){ if(rtpInfo.getInteger("code") == 0){
if (rtpInfo.getBoolean("exist")) { if (rtpInfo.getBoolean("exist")) {
int localPort = rtpInfo.getInteger("local_port");
if (localPort == 0) {
logger.warn("[点播]点播时发现rtpServerC存在但是尚未开始推流");
// 此时说明rtpServer已经创建但是流还没有推上来
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(ErrorCode.ERROR100.getCode());
wvpResult.setMsg("点播已经在进行中,请稍候重试");
msg.setData(wvpResult);
resultHolder.invokeAllResult(msg);
return playResult;
}else {
WVPResult wvpResult = new WVPResult(); WVPResult wvpResult = new WVPResult();
wvpResult.setCode(ErrorCode.SUCCESS.getCode()); wvpResult.setCode(ErrorCode.SUCCESS.getCode());
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg()); wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
@ -175,6 +186,8 @@ public class PlayServiceImpl implements IPlayService {
if (hookEvent != null) { if (hookEvent != null) {
hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo))); hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo)));
} }
}
}else { }else {
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
@ -187,7 +200,6 @@ public class PlayServiceImpl implements IPlayService {
streamInfo = null; streamInfo = null;
} }
} }
if (streamInfo == null) { if (streamInfo == null) {
String streamId = null; String streamId = null;

View File

@ -143,15 +143,12 @@ public interface DeviceChannelMapper {
@Update(value = {"UPDATE device_channel SET status=0 WHERE deviceId=#{deviceId}"}) @Update(value = {"UPDATE device_channel SET status=0 WHERE deviceId=#{deviceId}"})
void offlineByDeviceId(String deviceId); void offlineByDeviceId(String deviceId);
@Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void online(String deviceId, String channelId);
@Insert("<script> " + @Insert("<script> " +
"insert into device_channel " + "insert into device_channel " +
"(channelId, deviceId, name, manufacture, model, owner, civilCode, block, subCount, " + "(channelId, deviceId, name, manufacture, model, owner, civilCode, block, subCount, " +
" address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " + " address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " +
" ipAddress, port, password, PTZType, status, streamId, longitude, latitude, longitudeGcj02, latitudeGcj02, " + " ipAddress, port, password, PTZType, status, streamId, longitude, latitude, longitudeGcj02, latitudeGcj02, " +
" longitudeWgs84, latitudeWgs84, createTime, updateTime, businessGroupId, gpsTime) " + " longitudeWgs84, latitudeWgs84, hasAudio, createTime, updateTime, businessGroupId, gpsTime) " +
"values " + "values " +
"<foreach collection='addChannels' index='index' item='item' separator=','> " + "<foreach collection='addChannels' index='index' item='item' separator=','> " +
"('${item.channelId}', '${item.deviceId}', '${item.name}', '${item.manufacture}', '${item.model}', " + "('${item.channelId}', '${item.deviceId}', '${item.name}', '${item.manufacture}', '${item.model}', " +
@ -160,7 +157,7 @@ public interface DeviceChannelMapper {
"'${item.certNum}', ${item.certifiable}, ${item.errCode}, '${item.secrecy}', " + "'${item.certNum}', ${item.certifiable}, ${item.errCode}, '${item.secrecy}', " +
"'${item.ipAddress}', ${item.port}, '${item.password}', ${item.PTZType}, ${item.status}, " + "'${item.ipAddress}', ${item.port}, '${item.password}', ${item.PTZType}, ${item.status}, " +
"'${item.streamId}', ${item.longitude}, ${item.latitude},${item.longitudeGcj02}, " + "'${item.streamId}', ${item.longitude}, ${item.latitude},${item.longitudeGcj02}, " +
"${item.latitudeGcj02},${item.longitudeWgs84}, ${item.latitudeWgs84},'${item.createTime}', '${item.updateTime}', " + "${item.latitudeGcj02},${item.longitudeWgs84}, ${item.latitudeWgs84}, ${item.hasAudio},'${item.createTime}', '${item.updateTime}', " +
"'${item.businessGroupId}', '${item.gpsTime}') " + "'${item.businessGroupId}', '${item.gpsTime}') " +
"</foreach> " + "</foreach> " +
"ON DUPLICATE KEY UPDATE " + "ON DUPLICATE KEY UPDATE " +
@ -193,11 +190,15 @@ public interface DeviceChannelMapper {
"latitudeGcj02=VALUES(latitudeGcj02), " + "latitudeGcj02=VALUES(latitudeGcj02), " +
"longitudeWgs84=VALUES(longitudeWgs84), " + "longitudeWgs84=VALUES(longitudeWgs84), " +
"latitudeWgs84=VALUES(latitudeWgs84), " + "latitudeWgs84=VALUES(latitudeWgs84), " +
"hasAudio=VALUES(hasAudio), " +
"businessGroupId=VALUES(businessGroupId), " + "businessGroupId=VALUES(businessGroupId), " +
"gpsTime=VALUES(gpsTime)" + "gpsTime=VALUES(gpsTime)" +
"</script>") "</script>")
int batchAdd(List<DeviceChannel> addChannels); int batchAdd(List<DeviceChannel> addChannels);
@Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void online(String deviceId, String channelId);
@Update({"<script>" + @Update({"<script>" +
"<foreach collection='updateChannels' item='item' separator=';'>" + "<foreach collection='updateChannels' item='item' separator=';'>" +
" UPDATE" + " UPDATE" +
@ -341,4 +342,7 @@ public interface DeviceChannelMapper {
" left join platform_catalog pc on pgc.catalogId = pc.id and pgc.platformId = pc.platformId" + " left join platform_catalog pc on pgc.catalogId = pc.id and pgc.platformId = pc.platformId" +
" where pgc.platformId=#{serverGBId}") " where pgc.platformId=#{serverGBId}")
List<DeviceChannel> queryChannelWithCatalog(String serverGBId); List<DeviceChannel> queryChannelWithCatalog(String serverGBId);
@Select("select * from device_channel where deviceId = #{deviceId}")
List<DeviceChannel> queryAllChannels(String deviceId);
} }

View File

@ -111,11 +111,11 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
if (CollectionUtils.isEmpty(deviceChannelList)) { if (CollectionUtils.isEmpty(deviceChannelList)) {
return false; return false;
} }
List<DeviceChannel> allChannelInPlay = deviceChannelMapper.getAllChannelInPlay(); List<DeviceChannel> allChannels = deviceChannelMapper.queryAllChannels(deviceId);
Map<String,DeviceChannel> allChannelMapInPlay = new ConcurrentHashMap<>(); Map<String,DeviceChannel> allChannelMap = new ConcurrentHashMap<>();
if (allChannelInPlay.size() > 0) { if (allChannels.size() > 0) {
for (DeviceChannel deviceChannel : allChannelInPlay) { for (DeviceChannel deviceChannel : allChannels) {
allChannelMapInPlay.put(deviceChannel.getChannelId(), deviceChannel); allChannelMap.put(deviceChannel.getChannelId(), deviceChannel);
} }
} }
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
@ -123,15 +123,17 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
List<DeviceChannel> channels = new ArrayList<>(); List<DeviceChannel> channels = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
Map<String, Integer> subContMap = new HashMap<>(); Map<String, Integer> subContMap = new HashMap<>();
if (deviceChannelList.size() > 1) { if (deviceChannelList.size() > 0) {
// 数据去重 // 数据去重
Set<String> gbIdSet = new HashSet<>(); Set<String> gbIdSet = new HashSet<>();
for (DeviceChannel deviceChannel : deviceChannelList) { for (DeviceChannel deviceChannel : deviceChannelList) {
if (!gbIdSet.contains(deviceChannel.getChannelId())) { if (!gbIdSet.contains(deviceChannel.getChannelId())) {
gbIdSet.add(deviceChannel.getChannelId()); gbIdSet.add(deviceChannel.getChannelId());
if (allChannelMapInPlay.containsKey(deviceChannel.getChannelId())) { if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
deviceChannel.setStreamId(allChannelMapInPlay.get(deviceChannel.getChannelId()).getStreamId()); deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
} }
channels.add(deviceChannel); channels.add(deviceChannel);
if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
if (subContMap.get(deviceChannel.getParentId()) == null) { if (subContMap.get(deviceChannel.getParentId()) == null) {
@ -153,8 +155,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
} }
} }
}else {
channels = deviceChannelList;
} }
if (stringBuilder.length() > 0) { if (stringBuilder.length() > 0) {
logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder);

View File

@ -43,6 +43,7 @@ public class UserController {
private IRoleService roleService; private IRoleService roleService;
@GetMapping("/login") @GetMapping("/login")
@PostMapping("/login")
@Operation(summary = "登录") @Operation(summary = "登录")
@Parameter(name = "username", description = "用户名", required = true) @Parameter(name = "username", description = "用户名", required = true)
@Parameter(name = "password", description = "密码32位md5加密", required = true) @Parameter(name = "password", description = "密码32位md5加密", required = true)

View File

@ -98,6 +98,11 @@
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />
</root> </root>
<logger name="wvp" level="debug" additivity="true">
<appender-ref ref="RollingFileError"/>
<appender-ref ref="RollingFile"/>
</logger>
<logger name="GB28181_SIP" level="debug" additivity="true"> <logger name="GB28181_SIP" level="debug" additivity="true">
<appender-ref ref="RollingFileError"/> <appender-ref ref="RollingFileError"/>
<appender-ref ref="sipRollingFile"/> <appender-ref ref="sipRollingFile"/>