Commit 155838ce2eca9dbdde3ca0b2a5d4e72ab603e54d

Authored by 648540858
1 parent f4e5e039

优化子码流切换逻辑,去除主子多开逻辑。优化单端口模式ssrc变化导致的无法移出点播缓存 #895

Showing 20 changed files with 165 additions and 624 deletions
src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java
@@ -29,7 +29,7 @@ public class InviteInfo { @@ -29,7 +29,7 @@ public class InviteInfo {
29 private StreamInfo streamInfo; 29 private StreamInfo streamInfo;
30 30
31 31
32 - public static InviteInfo getinviteInfo(String deviceId, String channelId, String stream, SSRCInfo ssrcInfo, 32 + public static InviteInfo getInviteInfo(String deviceId, String channelId, String stream, SSRCInfo ssrcInfo,
33 String receiveIp, Integer receivePort, String streamMode, 33 String receiveIp, Integer receivePort, String streamMode,
34 InviteSessionType type, InviteSessionStatus status) { 34 InviteSessionType type, InviteSessionStatus status) {
35 InviteInfo inviteInfo = new InviteInfo(); 35 InviteInfo inviteInfo = new InviteInfo();
@@ -138,25 +138,6 @@ public class InviteInfo { @@ -138,25 +138,6 @@ public class InviteInfo {
138 this.subStream = subStream; 138 this.subStream = subStream;
139 } 139 }
140 140
141 - public static InviteInfo getInviteInfo(String deviceId, String channelId,Boolean isSubStream, String stream, SSRCInfo ssrcInfo,  
142 - String receiveIp, Integer receivePort, String streamMode,  
143 - InviteSessionType type, InviteSessionStatus status) {  
144 - InviteInfo inviteInfo = new InviteInfo();  
145 - inviteInfo.setDeviceId(deviceId);  
146 - inviteInfo.setChannelId(channelId);  
147 - inviteInfo.setStream(stream);  
148 - inviteInfo.setSsrcInfo(ssrcInfo);  
149 - inviteInfo.setReceiveIp(receiveIp);  
150 - inviteInfo.setReceivePort(receivePort);  
151 - inviteInfo.setStreamMode(streamMode);  
152 - inviteInfo.setType(type);  
153 - inviteInfo.setStatus(status);  
154 - if(isSubStream != null){  
155 - inviteInfo.setSubStream(isSubStream);  
156 - }  
157 - return inviteInfo;  
158 - }  
159 - /*=========================设备主子码流逻辑END====================*/  
160 141
161 142
162 143
src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java
@@ -542,17 +542,5 @@ public class StreamInfo implements Serializable, Cloneable{ @@ -542,17 +542,5 @@ public class StreamInfo implements Serializable, Cloneable{
542 this.subStream = subStream; 542 this.subStream = subStream;
543 } 543 }
544 544
545 - public static String getPlayStream(String deviceId,String channelId,boolean isSubStream){  
546 - String streamId;  
547 - if(isSubStream){  
548 - streamId = String.format("%s_%s_%s","sub",deviceId, channelId);  
549 - }else {  
550 - streamId = String.format("%s_%s_%s","main", deviceId, channelId);  
551 - }  
552 - return streamId;  
553 - }  
554 -  
555 - /*=========================设备主子码流逻辑END====================*/  
556 -  
557 545
558 } 546 }
src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
@@ -45,7 +45,6 @@ public class DynamicTask { @@ -45,7 +45,6 @@ public class DynamicTask {
45 * @return 45 * @return
46 */ 46 */
47 public void startCron(String key, Runnable task, int cycleForCatalog) { 47 public void startCron(String key, Runnable task, int cycleForCatalog) {
48 - System.out.println(cycleForCatalog);  
49 ScheduledFuture<?> future = futureMap.get(key); 48 ScheduledFuture<?> future = futureMap.get(key);
50 if (future != null) { 49 if (future != null) {
51 if (future.isCancelled()) { 50 if (future.isCancelled()) {
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
@@ -156,29 +156,5 @@ public class DeferredResultHolder { @@ -156,29 +156,5 @@ public class DeferredResultHolder {
156 } 156 }
157 } 157 }
158 158
159 - /*============================设备主子码流逻辑START========================*/  
160 - public static String getPlayKey(String deviceId,String channelId,boolean deviceSwitchSubStream,boolean isSubStream){  
161 - String key = null;  
162 - if(deviceSwitchSubStream){  
163 - key = CALLBACK_CMD_PLAY + isSubStream + deviceId + channelId;  
164 - }else {  
165 - key = CALLBACK_CMD_PLAY +deviceId + channelId;  
166 - }  
167 - return key;  
168 - }  
169 -  
170 - public static String getSnapKey(String deviceId,String channelId,boolean deviceSwitchSubStream,boolean isSubStream){  
171 - String key = null;  
172 - if(deviceSwitchSubStream){  
173 - key = CALLBACK_CMD_SNAP + isSubStream + deviceId + channelId;  
174 - }else {  
175 - key = CALLBACK_CMD_SNAP +deviceId + channelId;  
176 - }  
177 - return key;  
178 - }  
179 -  
180 -  
181 - /*============================设备主子码流逻辑END========================*/  
182 -  
183 159
184 } 160 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
@@ -98,7 +98,7 @@ public interface ISIPCommander { @@ -98,7 +98,7 @@ public interface ISIPCommander {
98 * @param device 视频设备 98 * @param device 视频设备
99 * @param channelId 预览通道 99 * @param channelId 预览通道
100 */ 100 */
101 - void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,boolean isSubStream, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; 101 + void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
102 102
103 /** 103 /**
104 * 请求回放视频流 104 * 请求回放视频流
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -268,7 +268,7 @@ public class SIPCommander implements ISIPCommander { @@ -268,7 +268,7 @@ public class SIPCommander implements ISIPCommander {
268 * @param errorEvent sip错误订阅 268 * @param errorEvent sip错误订阅
269 */ 269 */
270 @Override 270 @Override
271 - public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,boolean isSubStream, 271 + public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
272 ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { 272 ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
273 String stream = ssrcInfo.getStream(); 273 String stream = ssrcInfo.getStream();
274 274
@@ -345,13 +345,13 @@ public class SIPCommander implements ISIPCommander { @@ -345,13 +345,13 @@ public class SIPCommander implements ISIPCommander {
345 345
346 if( device.isSwitchPrimarySubStream() ){ 346 if( device.isSwitchPrimarySubStream() ){
347 if("TP-LINK".equals(device.getManufacturer())){ 347 if("TP-LINK".equals(device.getManufacturer())){
348 - if (isSubStream){ 348 + if (device.isSwitchPrimarySubStream()){
349 content.append("a=streamMode:sub\r\n"); 349 content.append("a=streamMode:sub\r\n");
350 }else { 350 }else {
351 content.append("a=streamMode:main\r\n"); 351 content.append("a=streamMode:main\r\n");
352 } 352 }
353 }else { 353 }else {
354 - if (isSubStream){ 354 + if (device.isSwitchPrimarySubStream()){
355 content.append("a=streamprofile:1\r\n"); 355 content.append("a=streamprofile:1\r\n");
356 }else { 356 }else {
357 content.append("a=streamprofile:0\r\n"); 357 content.append("a=streamprofile:0\r\n");
@@ -374,11 +374,8 @@ public class SIPCommander implements ISIPCommander { @@ -374,11 +374,8 @@ public class SIPCommander implements ISIPCommander {
374 // 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值 374 // 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值
375 ResponseEvent responseEvent = (ResponseEvent) e.event; 375 ResponseEvent responseEvent = (ResponseEvent) e.event;
376 SIPResponse response = (SIPResponse) responseEvent.getResponse(); 376 SIPResponse response = (SIPResponse) responseEvent.getResponse();
377 - if(device.isSwitchPrimarySubStream()){  
378 - streamSession.put(device.getDeviceId(), channelId, "switch-play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response, InviteSessionType.PLAY);  
379 - }else {  
380 - streamSession.put(device.getDeviceId(), channelId, "play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response, InviteSessionType.PLAY);  
381 - } 377 + streamSession.put(device.getDeviceId(), channelId, "play", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response,
  378 + InviteSessionType.PLAY);
382 okEvent.response(e); 379 okEvent.response(e);
383 }); 380 });
384 } 381 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
@@ -142,13 +142,8 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In @@ -142,13 +142,8 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
142 // 可能是设备主动停止 142 // 可能是设备主动停止
143 Device device = storager.queryVideoDeviceByChannelId(platformGbId); 143 Device device = storager.queryVideoDeviceByChannelId(platformGbId);
144 if (device != null) { 144 if (device != null) {
145 - SsrcTransaction ssrcTransactionForPlay = null;  
146 - if (device.isSwitchPrimarySubStream() ) {  
147 - ssrcTransactionForPlay = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, "switch-play", null);  
148 - } else {  
149 - storager.stopPlay(device.getDeviceId(), channelId);  
150 - ssrcTransactionForPlay = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);  
151 - } 145 + storager.stopPlay(device.getDeviceId(), channelId);
  146 + SsrcTransaction ssrcTransactionForPlay = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
152 if (ssrcTransactionForPlay != null){ 147 if (ssrcTransactionForPlay != null){
153 if (ssrcTransactionForPlay.getCallId().equals(callIdHeader.getCallId())){ 148 if (ssrcTransactionForPlay.getCallId().equals(callIdHeader.getCallId())){
154 // 释放ssrc 149 // 释放ssrc
@@ -158,16 +153,8 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In @@ -158,16 +153,8 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
158 } 153 }
159 streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream()); 154 streamSession.remove(device.getDeviceId(), channelId, ssrcTransactionForPlay.getStream());
160 } 155 }
161 - InviteInfo inviteInfo = null;  
162 - if (device.isSwitchPrimarySubStream() ) {  
163 - String streamType = ssrcTransactionForPlay.getStream().split("_")[0];  
164 - boolean isSubStream = "sub".equals(streamType);  
165 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream);  
166 - inviteStreamService.removeInviteInfo(inviteInfo.getType(),inviteInfo.getDeviceId(),inviteInfo.getChannelId(),isSubStream,inviteInfo.getStream());  
167 - }else {  
168 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);  
169 - inviteStreamService.removeInviteInfo(inviteInfo);  
170 - } 156 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
  157 + inviteStreamService.removeInviteInfo(inviteInfo);
171 if (inviteInfo != null) { 158 if (inviteInfo != null) {
172 if (inviteInfo.getStreamInfo() != null) { 159 if (inviteInfo.getStreamInfo() != null) {
173 mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStream()); 160 mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServerId(), inviteInfo.getStream());
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -490,7 +490,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -490,7 +490,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
490 } 490 }
491 sendRtpItem.setStreamId(streamId); 491 sendRtpItem.setStreamId(streamId);
492 redisCatchStorage.updateSendRTPSever(sendRtpItem); 492 redisCatchStorage.updateSendRTPSever(sendRtpItem);
493 - playService.play(mediaServerItem, device.getDeviceId(), channelId,false, ((code, msg, data) -> { 493 + playService.play(mediaServerItem, device.getDeviceId(), channelId, ((code, msg, data) -> {
494 if (code == InviteErrorCode.SUCCESS.getCode()){ 494 if (code == InviteErrorCode.SUCCESS.getCode()){
495 hookEvent.run(code, msg, data); 495 hookEvent.run(code, msg, data);
496 }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){ 496 }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
@@ -252,7 +252,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @@ -252,7 +252,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
252 } 252 }
253 253
254 private void executeSave(){ 254 private void executeSave(){
255 - System.out.println("定时存储数据");  
256 executeSaveForUpdate(); 255 executeSaveForUpdate();
257 executeSaveForDelete(); 256 executeSaveForDelete();
258 executeSaveForOnline(); 257 executeSaveForOnline();
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
@@ -250,7 +250,6 @@ public class SipUtils { @@ -250,7 +250,6 @@ public class SipUtils {
250 if (ObjectUtils.isEmpty(timeStr)){ 250 if (ObjectUtils.isEmpty(timeStr)){
251 return null; 251 return null;
252 } 252 }
253 - System.out.println(timeStr);  
254 LocalDateTime localDateTime; 253 LocalDateTime localDateTime;
255 try { 254 try {
256 localDateTime = LocalDateTime.parse(timeStr); 255 localDateTime = LocalDateTime.parse(timeStr);
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -343,19 +343,10 @@ public class ZLMHttpHookListener { @@ -343,19 +343,10 @@ public class ZLMHttpHookListener {
343 } 343 }
344 344
345 if ("rtp".equals(param.getApp()) && !param.isRegist()) { 345 if ("rtp".equals(param.getApp()) && !param.isRegist()) {
346 - if(param.getStream().split("_").length == 3){  
347 - boolean isSubStream = "sub".equals(param.getStream().split("_")[0]);  
348 - InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream(), isSubStream);  
349 - if(inviteInfo != null && (inviteInfo.getType() == InviteSessionType.PLAY )){  
350 - inviteStreamService.removeInviteInfo(inviteInfo.getType(),inviteInfo.getDeviceId(),  
351 - inviteInfo.getChannelId(),inviteInfo.isSubStream(),inviteInfo.getStream());  
352 - }  
353 - }else {  
354 - InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());  
355 - if (inviteInfo != null && (inviteInfo.getType() == InviteSessionType.PLAY || inviteInfo.getType() == InviteSessionType.PLAYBACK)) {  
356 - inviteStreamService.removeInviteInfo(inviteInfo);  
357 - storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());  
358 - } 346 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
  347 + if (inviteInfo != null && (inviteInfo.getType() == InviteSessionType.PLAY || inviteInfo.getType() == InviteSessionType.PLAYBACK)) {
  348 + inviteStreamService.removeInviteInfo(inviteInfo);
  349 + storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
359 } 350 }
360 } else { 351 } else {
361 if (!"rtp".equals(param.getApp())) { 352 if (!"rtp".equals(param.getApp())) {
@@ -483,15 +474,8 @@ public class ZLMHttpHookListener { @@ -483,15 +474,8 @@ public class ZLMHttpHookListener {
483 Device device = deviceService.getDevice(inviteInfo.getDeviceId()); 474 Device device = deviceService.getDevice(inviteInfo.getDeviceId());
484 if (device != null) { 475 if (device != null) {
485 try { 476 try {
486 - InviteInfo info = null;  
487 - if(device.isSwitchPrimarySubStream()){  
488 - boolean isSubStream = "sub".equals(param.getStream().split("_")[0]);  
489 - info = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(),isSubStream, inviteInfo.getStream());  
490 - }else {  
491 - info = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());  
492 -  
493 - }  
494 - 477 + InviteInfo info = inviteStreamService.getInviteInfo(inviteInfo.getType(),
  478 + inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());
495 if (info != null) { 479 if (info != null) {
496 cmder.streamByeCmd(device, inviteInfo.getChannelId(), 480 cmder.streamByeCmd(device, inviteInfo.getChannelId(),
497 inviteInfo.getStream(), null); 481 inviteInfo.getStream(), null);
@@ -502,15 +486,9 @@ public class ZLMHttpHookListener { @@ -502,15 +486,9 @@ public class ZLMHttpHookListener {
502 } 486 }
503 } 487 }
504 488
505 - if(device.isSwitchPrimarySubStream()){  
506 - boolean isSubStream = "sub".equals(param.getStream().split("_")[0]);  
507 - inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),  
508 - inviteInfo.getChannelId(),isSubStream, inviteInfo.getStream());  
509 - }else {  
510 - inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),  
511 - inviteInfo.getChannelId(), inviteInfo.getStream());  
512 - storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());  
513 - } 489 + inviteStreamService.removeInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),
  490 + inviteInfo.getChannelId(), inviteInfo.getStream());
  491 + storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
514 return ret; 492 return ret;
515 } 493 }
516 } else { 494 } else {
@@ -563,26 +541,12 @@ public class ZLMHttpHookListener { @@ -563,26 +541,12 @@ public class ZLMHttpHookListener {
563 541
564 if ("rtp".equals(param.getApp())) { 542 if ("rtp".equals(param.getApp())) {
565 String[] s = param.getStream().split("_"); 543 String[] s = param.getStream().split("_");
566 - if (!mediaInfo.isRtpEnable() ) { 544 + if (!mediaInfo.isRtpEnable() || s.length != 2) {
567 defaultResult.setResult(HookResult.SUCCESS()); 545 defaultResult.setResult(HookResult.SUCCESS());
568 return defaultResult; 546 return defaultResult;
569 - }else if(s.length != 2 && s.length != 3 ){  
570 - defaultResult.setResult(HookResult.SUCCESS());  
571 - return defaultResult;  
572 - }  
573 - String deviceId = null;  
574 - String channelId = null;  
575 - boolean isSubStream = false;  
576 - if (s[0].length() < 20) {  
577 - if ("sub".equals(s[0])) {  
578 - isSubStream = true;  
579 - }  
580 - deviceId = s[1];  
581 - channelId = s[2];  
582 - } else {  
583 - deviceId = s[0];  
584 - channelId = s[1];  
585 } 547 }
  548 + String deviceId = s[0];
  549 + String channelId = s[1];
586 Device device = redisCatchStorage.getDevice(deviceId); 550 Device device = redisCatchStorage.getDevice(deviceId);
587 if (device == null) { 551 if (device == null) {
588 defaultResult.setResult(new HookResult(ErrorCode.ERROR404.getCode(), ErrorCode.ERROR404.getMsg())); 552 defaultResult.setResult(new HookResult(ErrorCode.ERROR404.getCode(), ErrorCode.ERROR404.getMsg()));
@@ -596,7 +560,7 @@ public class ZLMHttpHookListener { @@ -596,7 +560,7 @@ public class ZLMHttpHookListener {
596 logger.info("[ZLM HOOK] 流未找到, 发起自动点播:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); 560 logger.info("[ZLM HOOK] 流未找到, 发起自动点播:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
597 561
598 RequestMessage msg = new RequestMessage(); 562 RequestMessage msg = new RequestMessage();
599 - String key = DeferredResultHolder.getPlayKey(deviceId, channelId, device.isSwitchPrimarySubStream(), isSubStream); 563 + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
600 boolean exist = resultHolder.exist(key, null); 564 boolean exist = resultHolder.exist(key, null);
601 msg.setKey(key); 565 msg.setKey(key);
602 String uuid = UUID.randomUUID().toString(); 566 String uuid = UUID.randomUUID().toString();
@@ -614,7 +578,7 @@ public class ZLMHttpHookListener { @@ -614,7 +578,7 @@ public class ZLMHttpHookListener {
614 resultHolder.put(key, uuid, result); 578 resultHolder.put(key, uuid, result);
615 579
616 if (!exist) { 580 if (!exist) {
617 - playService.play(mediaInfo, deviceId, channelId,isSubStream, (code, message, data) -> { 581 + playService.play(mediaInfo, deviceId, channelId, (code, message, data) -> {
618 msg.setData(new HookResult(code, message)); 582 msg.setData(new HookResult(code, message));
619 resultHolder.invokeResult(msg); 583 resultHolder.invokeResult(msg);
620 }); 584 });
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
@@ -270,11 +270,6 @@ public class ZLMRESTfulUtils { @@ -270,11 +270,6 @@ public class ZLMRESTfulUtils {
270 } 270 }
271 271
272 public JSONObject openRtpServer(MediaServerItem mediaServerItem, Map<String, Object> param){ 272 public JSONObject openRtpServer(MediaServerItem mediaServerItem, Map<String, Object> param){
273 - System.out.println("==============openRtpServer=================");  
274 - for (String s : param.keySet()) {  
275 - System.out.println(s + "-->" + param.get(s));  
276 - }  
277 - System.out.println("===============================");  
278 return sendPost(mediaServerItem, "openRtpServer",param, null); 273 return sendPost(mediaServerItem, "openRtpServer",param, null);
279 } 274 }
280 275
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -227,7 +227,6 @@ public class ZLMRTPServerFactory { @@ -227,7 +227,6 @@ public class ZLMRTPServerFactory {
227 int localPort = 0; 227 int localPort = 0;
228 if (userSetting.getGbSendStreamStrict()) { 228 if (userSetting.getGbSendStreamStrict()) {
229 if (userSetting.getGbSendStreamStrict()) { 229 if (userSetting.getGbSendStreamStrict()) {
230 - System.out.println("createSendRtpItem1");  
231 localPort = keepPort(serverItem, ssrc, localPort); 230 localPort = keepPort(serverItem, ssrc, localPort);
232 if (localPort == 0) { 231 if (localPort == 0) {
233 return null; 232 return null;
@@ -264,7 +263,6 @@ public class ZLMRTPServerFactory { @@ -264,7 +263,6 @@ public class ZLMRTPServerFactory {
264 // 默认为随机端口 263 // 默认为随机端口
265 int localPort = 0; 264 int localPort = 0;
266 if (userSetting.getGbSendStreamStrict()) { 265 if (userSetting.getGbSendStreamStrict()) {
267 - System.out.println("createSendRtpItem2");  
268 localPort = keepPort(serverItem, ssrc, localPort); 266 localPort = keepPort(serverItem, ssrc, localPort);
269 if (localPort == 0) { 267 if (localPort == 0) {
270 return null; 268 return null;
@@ -294,9 +292,7 @@ public class ZLMRTPServerFactory { @@ -294,9 +292,7 @@ public class ZLMRTPServerFactory {
294 param.put("port", localPort); 292 param.put("port", localPort);
295 param.put("enable_tcp", 1); 293 param.put("enable_tcp", 1);
296 param.put("stream_id", ssrc); 294 param.put("stream_id", ssrc);
297 - System.out.println("用于收流");  
298 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); 295 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param);
299 - System.out.println(jsonObject);  
300 if (jsonObject.getInteger("code") == 0) { 296 if (jsonObject.getInteger("code") == 0) {
301 localPort = jsonObject.getInteger("port"); 297 localPort = jsonObject.getInteger("port");
302 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); 298 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java
@@ -4,8 +4,6 @@ import com.genersoft.iot.vmp.common.InviteInfo; @@ -4,8 +4,6 @@ import com.genersoft.iot.vmp.common.InviteInfo;
4 import com.genersoft.iot.vmp.common.InviteSessionType; 4 import com.genersoft.iot.vmp.common.InviteSessionType;
5 import com.genersoft.iot.vmp.service.bean.ErrorCallback; 5 import com.genersoft.iot.vmp.service.bean.ErrorCallback;
6 6
7 -import java.util.List;  
8 -  
9 /** 7 /**
10 * 记录国标点播的状态,包括实时预览,下载,录像回放 8 * 记录国标点播的状态,包括实时预览,下载,录像回放
11 */ 9 */
@@ -16,6 +14,8 @@ public interface IInviteStreamService { @@ -16,6 +14,8 @@ public interface IInviteStreamService {
16 */ 14 */
17 void updateInviteInfo(InviteInfo inviteInfo); 15 void updateInviteInfo(InviteInfo inviteInfo);
18 16
  17 + InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream);
  18 +
19 /** 19 /**
20 * 获取点播的状态信息 20 * 获取点播的状态信息
21 */ 21 */
@@ -74,48 +74,5 @@ public interface IInviteStreamService { @@ -74,48 +74,5 @@ public interface IInviteStreamService {
74 int getStreamInfoCount(String mediaServerId); 74 int getStreamInfoCount(String mediaServerId);
75 75
76 76
77 - /*======================设备主子码流逻辑START=========================*/  
78 - /**  
79 - * 获取点播的状态信息  
80 - */  
81 - InviteInfo getInviteInfoByDeviceAndChannel(InviteSessionType type,  
82 - String deviceId,  
83 - String channelId,boolean isSubStream);  
84 -  
85 - void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId,boolean isSubStream);  
86 -  
87 - InviteInfo getInviteInfo(InviteSessionType type,  
88 - String deviceId,  
89 - String channelId,  
90 - boolean isSubStream,  
91 - String stream);  
92 -  
93 - void removeInviteInfo(InviteSessionType type,  
94 - String deviceId,  
95 - String channelId,  
96 - boolean isSubStream,  
97 - String stream);  
98 -  
99 - void once(InviteSessionType type, String deviceId, String channelId,boolean isSubStream, String stream, ErrorCallback<Object> callback);  
100 -  
101 - void call(InviteSessionType type, String deviceId, String channelId,boolean isSubStream, String stream, int code, String msg, Object data);  
102 -  
103 - void updateInviteInfoSub(InviteInfo inviteInfo);  
104 -  
105 - /**  
106 - * 获取点播的状态信息  
107 - */  
108 - InviteInfo getInviteInfoByStream(InviteSessionType type, String stream,boolean isSubStream);  
109 -  
110 - /**  
111 - * 获取点播的状态信息  
112 - */  
113 - List<Object> getInviteInfos(InviteSessionType type,  
114 - String deviceId,  
115 - String channelId,  
116 - String stream);  
117 - /*======================设备主子码流逻辑END=========================*/  
118 -  
119 -  
120 77
121 } 78 }
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
@@ -16,9 +16,9 @@ import java.text.ParseException; @@ -16,9 +16,9 @@ import java.text.ParseException;
16 */ 16 */
17 public interface IPlayService { 17 public interface IPlayService {
18 18
19 - void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,boolean isSubStream, 19 + void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
20 ErrorCallback<Object> callback); 20 ErrorCallback<Object> callback);
21 - SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId,boolean isSubStream, ErrorCallback<Object> callback); 21 + SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback);
22 22
23 MediaServerItem getNewMediaServerItem(Device device); 23 MediaServerItem getNewMediaServerItem(Device device);
24 24
@@ -43,5 +43,5 @@ public interface IPlayService { @@ -43,5 +43,5 @@ public interface IPlayService {
43 43
44 void resumeRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException; 44 void resumeRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException;
45 45
46 - void getSnap(String deviceId, String channelId, String fileName,boolean isSubStream, ErrorCallback errorCallback); 46 + void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback);
47 } 47 }
src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
@@ -85,6 +85,24 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @@ -85,6 +85,24 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
85 } 85 }
86 86
87 @Override 87 @Override
  88 + public InviteInfo updateInviteInfoForStream(InviteInfo inviteInfo, String stream) {
  89 +
  90 + InviteInfo inviteInfoInDb = getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());
  91 + if (inviteInfoInDb == null) {
  92 + return null;
  93 + }
  94 + removeInviteInfo(inviteInfoInDb);
  95 + String key = VideoManagerConstants.INVITE_PREFIX +
  96 + "_" + inviteInfo.getType() +
  97 + "_" + inviteInfo.getDeviceId() +
  98 + "_" + inviteInfo.getChannelId() +
  99 + "_" + stream;
  100 + inviteInfoInDb.setStream(stream);
  101 + redisTemplate.opsForValue().set(key, inviteInfoInDb);
  102 + return inviteInfoInDb;
  103 + }
  104 +
  105 + @Override
88 public InviteInfo getInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream) { 106 public InviteInfo getInviteInfo(InviteSessionType type, String deviceId, String channelId, String stream) {
89 String key = VideoManagerConstants.INVITE_PREFIX + 107 String key = VideoManagerConstants.INVITE_PREFIX +
90 "_" + (type != null ? type : "*") + 108 "_" + (type != null ? type : "*") +
@@ -152,19 +170,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @@ -152,19 +170,6 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
152 170
153 } 171 }
154 172
155 - @Override  
156 - public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) {  
157 - String key = buildKey(type, deviceId, channelId, stream);  
158 - List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);  
159 - if (callbacks == null) {  
160 - return;  
161 - }  
162 - for (ErrorCallback<Object> callback : callbacks) {  
163 - callback.run(code, msg, data);  
164 - }  
165 - inviteErrorCallbackMap.remove(key);  
166 - }  
167 -  
168 private String buildKey(InviteSessionType type, String deviceId, String channelId, String stream) { 173 private String buildKey(InviteSessionType type, String deviceId, String channelId, String stream) {
169 String key = type + "_" + deviceId + "_" + channelId; 174 String key = type + "_" + deviceId + "_" + channelId;
170 // 如果ssrc未null那么可以实现一个通道只能一次操作,ssrc不为null则可以支持一个通道多次invite 175 // 如果ssrc未null那么可以实现一个通道只能一次操作,ssrc不为null则可以支持一个通道多次invite
@@ -199,69 +204,9 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @@ -199,69 +204,9 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
199 return count; 204 return count;
200 } 205 }
201 206
202 - /*======================设备主子码流逻辑START=========================*/  
203 -  
204 - @Override  
205 - public InviteInfo getInviteInfoByDeviceAndChannel(InviteSessionType type, String deviceId, String channelId, boolean isSubStream) {  
206 - return getInviteInfo(type, deviceId, channelId,isSubStream, null);  
207 - }  
208 -  
209 - @Override  
210 - public void removeInviteInfoByDeviceAndChannel(InviteSessionType inviteSessionType, String deviceId, String channelId, boolean isSubStream) {  
211 - removeInviteInfo(inviteSessionType, deviceId, channelId,isSubStream, null);  
212 - }  
213 -  
214 - @Override  
215 - public InviteInfo getInviteInfo(InviteSessionType type, String deviceId, String channelId,boolean isSubStream, String stream) {  
216 - String key = VideoManagerConstants.INVITE_PREFIX +  
217 - "_" + (type != null ? type : "*") +  
218 - "_" + (isSubStream ? "sub" : "main") +  
219 - "_" + (deviceId != null ? deviceId : "*") +  
220 - "_" + (channelId != null ? channelId : "*") +  
221 - "_" + (stream != null ? stream : "*");  
222 - List<Object> scanResult = RedisUtil.scan(redisTemplate, key);  
223 - if (scanResult.size() != 1) {  
224 - return null;  
225 - }  
226 - return (InviteInfo) redisTemplate.opsForValue().get(scanResult.get(0));  
227 - }  
228 -  
229 @Override 207 @Override
230 - public void removeInviteInfo(InviteSessionType type, String deviceId, String channelId, boolean isSubStream, String stream) {  
231 - String scanKey = VideoManagerConstants.INVITE_PREFIX +  
232 - "_" + (type != null ? type : "*") +  
233 - "_" + (isSubStream ? "sub" : "main") +  
234 - "_" + (deviceId != null ? deviceId : "*") +  
235 - "_" + (channelId != null ? channelId : "*") +  
236 - "_" + (stream != null ? stream : "*");  
237 - List<Object> scanResult = RedisUtil.scan(redisTemplate, scanKey);  
238 - if (scanResult.size() > 0) {  
239 - for (Object keyObj : scanResult) {  
240 - String key = (String) keyObj;  
241 - InviteInfo inviteInfo = (InviteInfo) redisTemplate.opsForValue().get(key);  
242 - if (inviteInfo == null) {  
243 - continue;  
244 - }  
245 - redisTemplate.delete(key);  
246 - inviteErrorCallbackMap.remove(buildKey(type, deviceId, channelId, inviteInfo.getStream()));  
247 - }  
248 - }  
249 - }  
250 -  
251 - @Override  
252 - public void once(InviteSessionType type, String deviceId, String channelId, boolean isSubStream, String stream, ErrorCallback<Object> callback) {  
253 - String key = buildSubStreamKey(type, deviceId, channelId,isSubStream, stream);  
254 - List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);  
255 - if (callbacks == null) {  
256 - callbacks = new CopyOnWriteArrayList<>();  
257 - inviteErrorCallbackMap.put(key, callbacks);  
258 - }  
259 - callbacks.add(callback);  
260 - }  
261 -  
262 - @Override  
263 - public void call(InviteSessionType type, String deviceId, String channelId, boolean isSubStream, String stream, int code, String msg, Object data) {  
264 - String key = buildSubStreamKey(type, deviceId, channelId,isSubStream, stream); 208 + public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) {
  209 + String key = buildSubStreamKey(type, deviceId, channelId, stream);
265 List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); 210 List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
266 if (callbacks == null) { 211 if (callbacks == null) {
267 return; 212 return;
@@ -273,89 +218,12 @@ public class InviteStreamServiceImpl implements IInviteStreamService { @@ -273,89 +218,12 @@ public class InviteStreamServiceImpl implements IInviteStreamService {
273 } 218 }
274 219
275 220
276 - private String buildSubStreamKey(InviteSessionType type, String deviceId, String channelId, boolean isSubStream, String stream) {  
277 - String key = type + "_" + (isSubStream ? "sub":"main") + "_" + deviceId + "_" + channelId; 221 + private String buildSubStreamKey(InviteSessionType type, String deviceId, String channelId, String stream) {
  222 + String key = type + "_" + "_" + deviceId + "_" + channelId;
278 // 如果ssrc为null那么可以实现一个通道只能一次操作,ssrc不为null则可以支持一个通道多次invite 223 // 如果ssrc为null那么可以实现一个通道只能一次操作,ssrc不为null则可以支持一个通道多次invite
279 if (stream != null) { 224 if (stream != null) {
280 key += ("_" + stream); 225 key += ("_" + stream);
281 } 226 }
282 return key; 227 return key;
283 } 228 }
284 - @Override  
285 - public void updateInviteInfoSub(InviteInfo inviteInfo) {  
286 - if (inviteInfo == null || (inviteInfo.getDeviceId() == null || inviteInfo.getChannelId() == null)) {  
287 - logger.warn("[更新Invite信息],参数不全: {}", JSON.toJSON(inviteInfo));  
288 - return;  
289 - }  
290 - InviteInfo inviteInfoForUpdate = null;  
291 -  
292 - if (InviteSessionStatus.ready == inviteInfo.getStatus()) {  
293 - if (inviteInfo.getDeviceId() == null  
294 - || inviteInfo.getChannelId() == null  
295 - || inviteInfo.getType() == null  
296 - || inviteInfo.getStream() == null  
297 - ) {  
298 - return;  
299 - }  
300 - inviteInfoForUpdate = inviteInfo;  
301 - } else {  
302 - InviteInfo inviteInfoInRedis = getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId(),  
303 - inviteInfo.getChannelId(),inviteInfo.isSubStream(), inviteInfo.getStream());  
304 - if (inviteInfoInRedis == null) {  
305 - logger.warn("[更新Invite信息],未从缓存中读取到Invite信息: deviceId: {}, channel: {}, stream: {}",  
306 - inviteInfo.getDeviceId(), inviteInfo.getChannelId(), inviteInfo.getStream());  
307 - return;  
308 - }  
309 - if (inviteInfo.getStreamInfo() != null) {  
310 - inviteInfoInRedis.setStreamInfo(inviteInfo.getStreamInfo());  
311 - }  
312 - if (inviteInfo.getSsrcInfo() != null) {  
313 - inviteInfoInRedis.setSsrcInfo(inviteInfo.getSsrcInfo());  
314 - }  
315 - if (inviteInfo.getStreamMode() != null) {  
316 - inviteInfoInRedis.setStreamMode(inviteInfo.getStreamMode());  
317 - }  
318 - if (inviteInfo.getReceiveIp() != null) {  
319 - inviteInfoInRedis.setReceiveIp(inviteInfo.getReceiveIp());  
320 - }  
321 - if (inviteInfo.getReceivePort() != null) {  
322 - inviteInfoInRedis.setReceivePort(inviteInfo.getReceivePort());  
323 - }  
324 - if (inviteInfo.getStatus() != null) {  
325 - inviteInfoInRedis.setStatus(inviteInfo.getStatus());  
326 - }  
327 -  
328 - inviteInfoForUpdate = inviteInfoInRedis;  
329 -  
330 - }  
331 - String key = VideoManagerConstants.INVITE_PREFIX +  
332 - "_" + inviteInfoForUpdate.getType() +  
333 - "_" + (inviteInfoForUpdate.isSubStream() ? "sub":"main") +  
334 - "_" + inviteInfoForUpdate.getDeviceId() +  
335 - "_" + inviteInfoForUpdate.getChannelId() +  
336 - "_" + inviteInfoForUpdate.getStream();  
337 - redisTemplate.opsForValue().set(key, inviteInfoForUpdate);  
338 - }  
339 -  
340 - @Override  
341 - public InviteInfo getInviteInfoByStream(InviteSessionType type, String stream, boolean isSubStream) {  
342 - return getInviteInfo(type, null, null,isSubStream, stream);  
343 - }  
344 -  
345 - @Override  
346 - public List<Object> getInviteInfos(InviteSessionType type, String deviceId, String channelId, String stream) {  
347 - String key = VideoManagerConstants.INVITE_PREFIX +  
348 - "_" + (type != null ? type : "*") +  
349 - "_" + (deviceId != null ? deviceId : "*") +  
350 - "_" + (channelId != null ? channelId : "*") +  
351 - "_" + (stream != null ? stream : "*");  
352 - List<Object> scanResult = RedisUtil.scan(redisTemplate, key);  
353 - return scanResult;  
354 - }  
355 -  
356 - /*======================设备主子码流逻辑END=========================*/  
357 -  
358 -  
359 -  
360 -  
361 } 229 }
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -116,43 +116,27 @@ public class PlayServiceImpl implements IPlayService { @@ -116,43 +116,27 @@ public class PlayServiceImpl implements IPlayService {
116 116
117 117
118 @Override 118 @Override
119 - public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId,boolean isSubStream, ErrorCallback<Object> callback) { 119 + public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback) {
120 if (mediaServerItem == null) { 120 if (mediaServerItem == null) {
121 throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm"); 121 throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm");
122 } 122 }
123 123
124 Device device = redisCatchStorage.getDevice(deviceId); 124 Device device = redisCatchStorage.getDevice(deviceId);
125 - InviteInfo inviteInfo;  
126 - if(device.isSwitchPrimarySubStream()){  
127 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
128 - }else {  
129 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);  
130 - } 125 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
131 if (inviteInfo != null ) { 126 if (inviteInfo != null ) {
132 if (inviteInfo.getStreamInfo() == null) { 127 if (inviteInfo.getStreamInfo() == null) {
133 // 点播发起了但是尚未成功, 仅注册回调等待结果即可 128 // 点播发起了但是尚未成功, 仅注册回调等待结果即可
134 - if(device.isSwitchPrimarySubStream()){  
135 - inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId,isSubStream, null, callback);  
136 - }else {  
137 - inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId, null, callback);  
138 - } 129 + inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId, null, callback);
139 return inviteInfo.getSsrcInfo(); 130 return inviteInfo.getSsrcInfo();
140 }else { 131 }else {
141 StreamInfo streamInfo = inviteInfo.getStreamInfo(); 132 StreamInfo streamInfo = inviteInfo.getStreamInfo();
142 String streamId = streamInfo.getStream(); 133 String streamId = streamInfo.getStream();
143 if (streamId == null) { 134 if (streamId == null) {
144 callback.run(InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(), "点播失败, redis缓存streamId等于null", null); 135 callback.run(InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(), "点播失败, redis缓存streamId等于null", null);
145 - if(device.isSwitchPrimarySubStream()){  
146 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
147 - InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(),  
148 - "点播失败, redis缓存streamId等于null",  
149 - null);  
150 - }else {  
151 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
152 - InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(),  
153 - "点播失败, redis缓存streamId等于null",  
154 - null);  
155 - } 136 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  137 + InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(),
  138 + "点播失败, redis缓存streamId等于null",
  139 + null);
156 return inviteInfo.getSsrcInfo(); 140 return inviteInfo.getSsrcInfo();
157 } 141 }
158 String mediaServerId = streamInfo.getMediaServerId(); 142 String mediaServerId = streamInfo.getMediaServerId();
@@ -161,64 +145,38 @@ public class PlayServiceImpl implements IPlayService { @@ -161,64 +145,38 @@ public class PlayServiceImpl implements IPlayService {
161 Boolean ready = zlmrtpServerFactory.isStreamReady(mediaInfo, "rtp", streamId); 145 Boolean ready = zlmrtpServerFactory.isStreamReady(mediaInfo, "rtp", streamId);
162 if (ready != null && ready) { 146 if (ready != null && ready) {
163 callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); 147 callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
164 - if(device.isSwitchPrimarySubStream()){  
165 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
166 - InviteErrorCode.SUCCESS.getCode(),  
167 - InviteErrorCode.SUCCESS.getMsg(),  
168 - streamInfo);  
169 - }else {  
170 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
171 - InviteErrorCode.SUCCESS.getCode(),  
172 - InviteErrorCode.SUCCESS.getMsg(),  
173 - streamInfo);  
174 - } 148 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  149 + InviteErrorCode.SUCCESS.getCode(),
  150 + InviteErrorCode.SUCCESS.getMsg(),
  151 + streamInfo);
175 return inviteInfo.getSsrcInfo(); 152 return inviteInfo.getSsrcInfo();
176 }else { 153 }else {
177 // 点播发起了但是尚未成功, 仅注册回调等待结果即可 154 // 点播发起了但是尚未成功, 仅注册回调等待结果即可
178 - if(device.isSwitchPrimarySubStream()) {  
179 - inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId, null, callback);  
180 - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());  
181 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);  
182 - }else {  
183 - inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId,isSubStream, null, callback);  
184 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
185 - } 155 + inviteStreamService.once(InviteSessionType.PLAY, deviceId, channelId, null, callback);
  156 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
  157 + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
186 } 158 }
187 } 159 }
188 } 160 }
189 161
190 - String streamId = null;  
191 - if (mediaServerItem.isRtpEnable()) {  
192 - if(device.isSwitchPrimarySubStream()){  
193 - streamId = StreamInfo.getPlayStream(deviceId, channelId, isSubStream);  
194 - }else {  
195 - streamId = String.format("%s_%s", device.getDeviceId(), channelId);  
196 - }  
197 - } 162 + String streamId = String.format("%s_%s", device.getDeviceId(), channelId);
198 SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam()); 163 SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam());
199 if (ssrcInfo == null) { 164 if (ssrcInfo == null) {
200 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null); 165 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null);
201 - if(device.isSwitchPrimarySubStream()){  
202 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
203 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(),  
204 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(),  
205 - null);  
206 - }else {  
207 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
208 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(),  
209 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(),  
210 - null);  
211 - } 166 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  167 + InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(),
  168 + InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(),
  169 + null);
212 return null; 170 return null;
213 } 171 }
214 // TODO 记录点播的状态 172 // TODO 记录点播的状态
215 - play(mediaServerItem, ssrcInfo, device, channelId,isSubStream, callback); 173 + play(mediaServerItem, ssrcInfo, device, channelId, callback);
216 return ssrcInfo; 174 return ssrcInfo;
217 } 175 }
218 176
219 177
220 @Override 178 @Override
221 - public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,boolean isSubStream, 179 + public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
222 ErrorCallback<Object> callback) { 180 ErrorCallback<Object> callback) {
223 181
224 if (mediaServerItem == null || ssrcInfo == null) { 182 if (mediaServerItem == null || ssrcInfo == null) {
@@ -227,11 +185,9 @@ public class PlayServiceImpl implements IPlayService { @@ -227,11 +185,9 @@ public class PlayServiceImpl implements IPlayService {
227 null); 185 null);
228 return; 186 return;
229 } 187 }
230 - if( device.isSwitchPrimarySubStream() ){  
231 - logger.info("[点播开始] deviceId: {}, channelId: {},码流类型:{},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId,isSubStream ? "辅码流" : "主码流", ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());  
232 - }else {  
233 - logger.info("[点播开始] deviceId: {}, channelId: {},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());  
234 - } 188 + logger.info("[点播开始] deviceId: {}, channelId: {},码流类型:{},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}",
  189 + device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "辅码流" : "主码流", ssrcInfo.getPort(),
  190 + device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
235 //端口获取失败的ssrcInfo 没有必要发送点播指令 191 //端口获取失败的ssrcInfo 没有必要发送点播指令
236 if (ssrcInfo.getPort() <= 0) { 192 if (ssrcInfo.getPort() <= 0) {
237 logger.info("[点播端口分配异常],deviceId={},channelId={},ssrcInfo={}", device.getDeviceId(), channelId, ssrcInfo); 193 logger.info("[点播端口分配异常],deviceId={},channelId={},ssrcInfo={}", device.getDeviceId(), channelId, ssrcInfo);
@@ -240,50 +196,27 @@ public class PlayServiceImpl implements IPlayService { @@ -240,50 +196,27 @@ public class PlayServiceImpl implements IPlayService {
240 streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); 196 streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
241 197
242 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "点播端口分配异常", null); 198 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "点播端口分配异常", null);
243 - if(device.isSwitchPrimarySubStream()){  
244 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
245 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "点播端口分配异常", null);  
246 - }else {  
247 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
248 - InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "点播端口分配异常", null);  
249 - } 199 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  200 + InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "点播端口分配异常", null);
250 return; 201 return;
251 } 202 }
252 203
253 // 初始化redis中的invite消息状态 204 // 初始化redis中的invite消息状态
254 - InviteInfo inviteInfo;  
255 -  
256 - if(device.isSwitchPrimarySubStream()){  
257 - // 初始化redis中的invite消息状态  
258 - inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channelId,isSubStream, ssrcInfo.getStream(), ssrcInfo,  
259 - mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAY,  
260 - InviteSessionStatus.ready);  
261 - inviteStreamService.updateInviteInfoSub(inviteInfo);  
262 - }else {  
263 - // 初始化redis中的invite消息状态  
264 - inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,  
265 - mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAY,  
266 - InviteSessionStatus.ready);  
267 - inviteStreamService.updateInviteInfo(inviteInfo);  
268 - } 205 + InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
  206 + mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAY,
  207 + InviteSessionStatus.ready);
  208 + inviteInfo.setSubStream(device.isSwitchPrimarySubStream());
  209 + inviteStreamService.updateInviteInfo(inviteInfo);
269 // 超时处理 210 // 超时处理
270 String timeOutTaskKey = UUID.randomUUID().toString(); 211 String timeOutTaskKey = UUID.randomUUID().toString();
271 dynamicTask.startDelay(timeOutTaskKey, () -> { 212 dynamicTask.startDelay(timeOutTaskKey, () -> {
272 // 执行超时任务时查询是否已经成功,成功了则不执行超时任务,防止超时任务取消失败的情况 213 // 执行超时任务时查询是否已经成功,成功了则不执行超时任务,防止超时任务取消失败的情况
273 - InviteInfo inviteInfoForTimeOut;  
274 - if(device.isSwitchPrimarySubStream()){  
275 - // 初始化redis中的invite消息状态  
276 - inviteInfoForTimeOut = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream);  
277 - }else {  
278 - // 初始化redis中的invite消息状态  
279 - inviteInfoForTimeOut = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);  
280 - } 214 + InviteInfo inviteInfoForTimeOut = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
281 if (inviteInfoForTimeOut == null || inviteInfoForTimeOut.getStreamInfo() == null) { 215 if (inviteInfoForTimeOut == null || inviteInfoForTimeOut.getStreamInfo() == null) {
282 - if( device.isSwitchPrimarySubStream()){  
283 - logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {},码流类型:{},端口:{}, SSRC: {}", device.getDeviceId(), channelId,isSubStream ? "辅码流" : "主码流", ssrcInfo.getPort(), ssrcInfo.getSsrc());  
284 - }else {  
285 - logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {},端口:{}, SSRC: {}", device.getDeviceId(), channelId, ssrcInfo.getPort(), ssrcInfo.getSsrc());  
286 - } 216 + logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {},码流类型:{},端口:{}, SSRC: {}",
  217 + device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "辅码流" : "主码流",
  218 + ssrcInfo.getPort(), ssrcInfo.getSsrc());
  219 +
287 // 点播超时回复BYE 同时释放ssrc以及此次点播的资源 220 // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
288 // InviteInfo inviteInfoForTimeout = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.play, device.getDeviceId(), channelId); 221 // InviteInfo inviteInfoForTimeout = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.play, device.getDeviceId(), channelId);
289 // if (inviteInfoForTimeout == null) { 222 // if (inviteInfoForTimeout == null) {
@@ -295,16 +228,10 @@ public class PlayServiceImpl implements IPlayService { @@ -295,16 +228,10 @@ public class PlayServiceImpl implements IPlayService {
295 // // TODO 发送cancel 228 // // TODO 发送cancel
296 // } 229 // }
297 callback.run(InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getMsg(), null); 230 callback.run(InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getMsg(), null);
298 - if( device.isSwitchPrimarySubStream()){  
299 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
300 - InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getMsg(), null);  
301 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream); 231 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  232 + InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getMsg(), null);
  233 + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
302 234
303 - }else {  
304 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
305 - InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getMsg(), null);  
306 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);  
307 - }  
308 try { 235 try {
309 cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null); 236 cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null);
310 } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) { 237 } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
@@ -322,42 +249,26 @@ public class PlayServiceImpl implements IPlayService { @@ -322,42 +249,26 @@ public class PlayServiceImpl implements IPlayService {
322 }, userSetting.getPlayTimeout()); 249 }, userSetting.getPlayTimeout());
323 250
324 try { 251 try {
325 - cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId,isSubStream, (mediaServerItemInuse, hookParam ) -> { 252 + cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (mediaServerItemInuse, hookParam ) -> {
326 logger.info("收到订阅消息: " + hookParam); 253 logger.info("收到订阅消息: " + hookParam);
327 dynamicTask.stop(timeOutTaskKey); 254 dynamicTask.stop(timeOutTaskKey);
328 // hook响应 255 // hook响应
329 - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, hookParam, device.getDeviceId(), channelId,isSubStream); 256 + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, hookParam, device.getDeviceId(), channelId);
330 if (streamInfo == null){ 257 if (streamInfo == null){
331 callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), 258 callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
332 InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); 259 InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
333 - if( device.isSwitchPrimarySubStream()){  
334 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
335 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),  
336 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);  
337 - }else {  
338 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
339 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),  
340 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);  
341 - } 260 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  261 + InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
  262 + InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
342 return; 263 return;
343 } 264 }
344 callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); 265 callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
345 - if( device.isSwitchPrimarySubStream()){  
346 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
347 - InviteErrorCode.SUCCESS.getCode(),  
348 - InviteErrorCode.SUCCESS.getMsg(),  
349 - streamInfo);  
350 - }else {  
351 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
352 - InviteErrorCode.SUCCESS.getCode(),  
353 - InviteErrorCode.SUCCESS.getMsg(),  
354 - streamInfo);  
355 - }  
356 - if( device.isSwitchPrimarySubStream() ){  
357 - logger.info("[点播成功] deviceId: {}, channelId: {},码流类型:{}", device.getDeviceId(), channelId,isSubStream ? "辅码流" : "主码流");  
358 - }else {  
359 - logger.info("[点播成功] deviceId: {}, channelId: {}", device.getDeviceId(), channelId);  
360 - } 266 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  267 + InviteErrorCode.SUCCESS.getCode(),
  268 + InviteErrorCode.SUCCESS.getMsg(),
  269 + streamInfo);
  270 + logger.info("[点播成功] deviceId: {}, channelId: {},码流类型:{}", device.getDeviceId(),
  271 + device.isSwitchPrimarySubStream() ? "辅码流" : "主码流");
361 String streamUrl; 272 String streamUrl;
362 if (mediaServerItemInuse.getRtspPort() != 0) { 273 if (mediaServerItemInuse.getRtspPort() != 0) {
363 streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", ssrcInfo.getStream()); 274 streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", ssrcInfo.getStream());
@@ -413,15 +324,9 @@ public class PlayServiceImpl implements IPlayService { @@ -413,15 +324,9 @@ public class PlayServiceImpl implements IPlayService {
413 324
414 callback.run(InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(), 325 callback.run(InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
415 InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null); 326 InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
416 - if(device.isSwitchPrimarySubStream()){  
417 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
418 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),  
419 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);  
420 - }else {  
421 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
422 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),  
423 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);  
424 - } 327 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  328 + InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),
  329 + InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);
425 } 330 }
426 } 331 }
427 return; 332 return;
@@ -438,39 +343,26 @@ public class PlayServiceImpl implements IPlayService { @@ -438,39 +343,26 @@ public class PlayServiceImpl implements IPlayService {
438 subscribe.removeSubscribe(hookSubscribe); 343 subscribe.removeSubscribe(hookSubscribe);
439 String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); 344 String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase();
440 hookSubscribe.getContent().put("stream", stream); 345 hookSubscribe.getContent().put("stream", stream);
441 - inviteInfo.setStream(stream); 346 + inviteStreamService.updateInviteInfoForStream(inviteInfo, stream);
442 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { 347 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> {
443 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); 348 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam);
444 dynamicTask.stop(timeOutTaskKey); 349 dynamicTask.stop(timeOutTaskKey);
445 // hook响应 350 // hook响应
446 - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, hookParam, device.getDeviceId(), channelId,isSubStream); 351 + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, hookParam, device.getDeviceId(), channelId);
447 if (streamInfo == null){ 352 if (streamInfo == null){
448 callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), 353 callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
449 InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); 354 InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
450 - if( device.isSwitchPrimarySubStream()){  
451 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
452 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),  
453 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);  
454 - }else {  
455 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
456 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),  
457 - InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);  
458 - } 355 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  356 + InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(),
  357 + InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null);
459 return; 358 return;
460 } 359 }
461 callback.run(InviteErrorCode.SUCCESS.getCode(), 360 callback.run(InviteErrorCode.SUCCESS.getCode(),
462 InviteErrorCode.SUCCESS.getMsg(), streamInfo); 361 InviteErrorCode.SUCCESS.getMsg(), streamInfo);
463 - if( device.isSwitchPrimarySubStream()){  
464 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
465 - InviteErrorCode.SUCCESS.getCode(),  
466 - InviteErrorCode.SUCCESS.getMsg(),  
467 - streamInfo);  
468 - }else {  
469 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
470 - InviteErrorCode.SUCCESS.getCode(),  
471 - InviteErrorCode.SUCCESS.getMsg(),  
472 - streamInfo);  
473 - } 362 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  363 + InviteErrorCode.SUCCESS.getCode(),
  364 + InviteErrorCode.SUCCESS.getMsg(),
  365 + streamInfo);
474 }); 366 });
475 return; 367 return;
476 } 368 }
@@ -493,17 +385,14 @@ public class PlayServiceImpl implements IPlayService { @@ -493,17 +385,14 @@ public class PlayServiceImpl implements IPlayService {
493 385
494 callback.run(InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(), 386 callback.run(InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),
495 "下级自定义了ssrc,重新设置收流信息失败", null); 387 "下级自定义了ssrc,重新设置收流信息失败", null);
496 - if( device.isSwitchPrimarySubStream()){  
497 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
498 - InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),  
499 - "下级自定义了ssrc,重新设置收流信息失败", null);  
500 - }else {  
501 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
502 - InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),  
503 - "下级自定义了ssrc,重新设置收流信息失败", null);  
504 - } 388 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  389 + InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),
  390 + "下级自定义了ssrc,重新设置收流信息失败", null);
505 391
506 }else { 392 }else {
  393 + if (ssrcInfo.getStream()!= null && !ssrcInfo.getStream().equals(inviteInfo.getStream())) {
  394 + inviteStreamService.removeInviteInfo(inviteInfo);
  395 + }
507 ssrcInfo.setSsrc(ssrcInResponse); 396 ssrcInfo.setSsrc(ssrcInResponse);
508 inviteInfo.setSsrcInfo(ssrcInfo); 397 inviteInfo.setSsrcInfo(ssrcInfo);
509 inviteInfo.setStream(ssrcInfo.getStream()); 398 inviteInfo.setStream(ssrcInfo.getStream());
@@ -512,11 +401,7 @@ public class PlayServiceImpl implements IPlayService { @@ -512,11 +401,7 @@ public class PlayServiceImpl implements IPlayService {
512 logger.info("[点播消息] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正"); 401 logger.info("[点播消息] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正");
513 } 402 }
514 } 403 }
515 - if(device.isSwitchPrimarySubStream()){  
516 - inviteStreamService.updateInviteInfoSub(inviteInfo);  
517 - }else {  
518 - inviteStreamService.updateInviteInfo(inviteInfo);  
519 - } 404 + inviteStreamService.updateInviteInfo(inviteInfo);
520 }, (event) -> { 405 }, (event) -> {
521 dynamicTask.stop(timeOutTaskKey); 406 dynamicTask.stop(timeOutTaskKey);
522 mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream()); 407 mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
@@ -527,19 +412,11 @@ public class PlayServiceImpl implements IPlayService { @@ -527,19 +412,11 @@ public class PlayServiceImpl implements IPlayService {
527 412
528 callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_ERROR.getCode(), 413 callback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_ERROR.getCode(),
529 String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null); 414 String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null);
530 - if( device.isSwitchPrimarySubStream()){  
531 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
532 - InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),  
533 - String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null);  
534 -  
535 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream);  
536 - }else {  
537 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
538 - InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),  
539 - String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null); 415 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  416 + InviteErrorCode.ERROR_FOR_RESET_SSRC.getCode(),
  417 + String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null);
540 418
541 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);  
542 - } 419 + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
543 }); 420 });
544 } catch (InvalidArgumentException | SipException | ParseException e) { 421 } catch (InvalidArgumentException | SipException | ParseException e) {
545 422
@@ -553,52 +430,30 @@ public class PlayServiceImpl implements IPlayService { @@ -553,52 +430,30 @@ public class PlayServiceImpl implements IPlayService {
553 430
554 callback.run(InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getCode(), 431 callback.run(InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getCode(),
555 InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getMsg(), null); 432 InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getMsg(), null);
556 - if( device.isSwitchPrimarySubStream()){  
557 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream, null,  
558 - InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getCode(),  
559 - InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getMsg(), null);  
560 -  
561 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId,isSubStream);  
562 - }else {  
563 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
564 - InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getCode(),  
565 - InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getMsg(), null); 433 + inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
  434 + InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getCode(),
  435 + InviteErrorCode.ERROR_FOR_SIP_SENDING_FAILED.getMsg(), null);
566 436
567 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);  
568 - } 437 + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, device.getDeviceId(), channelId);
569 } 438 }
570 } 439 }
571 440
572 - private StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, HookParam hookParam, String deviceId, String channelId, boolean isSubStream) { 441 + private StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, HookParam hookParam, String deviceId, String channelId) {
573 StreamInfo streamInfo = null; 442 StreamInfo streamInfo = null;
574 Device device = redisCatchStorage.getDevice(deviceId); 443 Device device = redisCatchStorage.getDevice(deviceId);
575 OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam; 444 OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam;
576 - if( device.isSwitchPrimarySubStream() ){  
577 - streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId,isSubStream);  
578 - }else {  
579 - streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId);  
580 - } 445 + streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId);
581 if (streamInfo != null) { 446 if (streamInfo != null) {
582 - InviteInfo inviteInfo;  
583 - if(device.isSwitchPrimarySubStream()){  
584 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
585 - }else {  
586 - DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);  
587 - if (deviceChannel != null) {  
588 - deviceChannel.setStreamId(streamInfo.getStream());  
589 - storager.startPlay(deviceId, channelId, streamInfo.getStream());  
590 - }  
591 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); 447 + DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
  448 + if (deviceChannel != null) {
  449 + deviceChannel.setStreamId(streamInfo.getStream());
  450 + storager.startPlay(deviceId, channelId, streamInfo.getStream());
592 } 451 }
  452 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
593 if (inviteInfo != null) { 453 if (inviteInfo != null) {
594 inviteInfo.setStatus(InviteSessionStatus.ok); 454 inviteInfo.setStatus(InviteSessionStatus.ok);
595 inviteInfo.setStreamInfo(streamInfo); 455 inviteInfo.setStreamInfo(streamInfo);
596 - if(device.isSwitchPrimarySubStream()){  
597 - inviteStreamService.updateInviteInfoSub(inviteInfo);  
598 - }else {  
599 - inviteStreamService.updateInviteInfo(inviteInfo);  
600 - }  
601 - 456 + inviteStreamService.updateInviteInfo(inviteInfo);
602 } 457 }
603 } 458 }
604 return streamInfo; 459 return streamInfo;
@@ -693,7 +548,7 @@ public class PlayServiceImpl implements IPlayService { @@ -693,7 +548,7 @@ public class PlayServiceImpl implements IPlayService {
693 device.getDeviceId(), channelId, startTime, endTime, ssrcInfo.getPort(), device.getStreamMode(), 548 device.getDeviceId(), channelId, startTime, endTime, ssrcInfo.getPort(), device.getStreamMode(),
694 ssrcInfo.getSsrc(), device.isSsrcCheck()); 549 ssrcInfo.getSsrc(), device.isSsrcCheck());
695 // 初始化redis中的invite消息状态 550 // 初始化redis中的invite消息状态
696 - InviteInfo inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo, 551 + InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
697 mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAYBACK, 552 mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAYBACK,
698 InviteSessionStatus.ready); 553 InviteSessionStatus.ready);
699 inviteStreamService.updateInviteInfo(inviteInfo); 554 inviteStreamService.updateInviteInfo(inviteInfo);
@@ -805,7 +660,7 @@ public class PlayServiceImpl implements IPlayService { @@ -805,7 +660,7 @@ public class PlayServiceImpl implements IPlayService {
805 subscribe.removeSubscribe(hookSubscribe); 660 subscribe.removeSubscribe(hookSubscribe);
806 String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); 661 String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase();
807 hookSubscribe.getContent().put("stream", stream); 662 hookSubscribe.getContent().put("stream", stream);
808 - inviteInfo.setStream(stream); 663 + inviteStreamService.updateInviteInfoForStream(inviteInfo, stream);
809 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { 664 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> {
810 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); 665 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam);
811 dynamicTask.stop(playBackTimeOutTaskKey); 666 dynamicTask.stop(playBackTimeOutTaskKey);
@@ -834,6 +689,10 @@ public class PlayServiceImpl implements IPlayService { @@ -834,6 +689,10 @@ public class PlayServiceImpl implements IPlayService {
834 "下级自定义了ssrc,重新设置收流信息失败", null); 689 "下级自定义了ssrc,重新设置收流信息失败", null);
835 690
836 }else { 691 }else {
  692 + if (ssrcInfo.getStream()!= null && !ssrcInfo.getStream().equals(inviteInfo.getStream())) {
  693 + inviteStreamService.removeInviteInfo(inviteInfo);
  694 + }
  695 +
837 ssrcInfo.setSsrc(ssrcInResponse); 696 ssrcInfo.setSsrc(ssrcInResponse);
838 inviteInfo.setSsrcInfo(ssrcInfo); 697 inviteInfo.setSsrcInfo(ssrcInfo);
839 inviteInfo.setStream(ssrcInfo.getStream()); 698 inviteInfo.setStream(ssrcInfo.getStream());
@@ -892,7 +751,7 @@ public class PlayServiceImpl implements IPlayService { @@ -892,7 +751,7 @@ public class PlayServiceImpl implements IPlayService {
892 } 751 }
893 logger.info("[录像下载] deviceId: {}, channelId: {}, 下载速度:{}, 收流端口:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, downloadSpeed, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); 752 logger.info("[录像下载] deviceId: {}, channelId: {}, 下载速度:{}, 收流端口:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, downloadSpeed, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
894 // 初始化redis中的invite消息状态 753 // 初始化redis中的invite消息状态
895 - InviteInfo inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo, 754 + InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
896 mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.DOWNLOAD, 755 mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.DOWNLOAD,
897 InviteSessionStatus.ready); 756 InviteSessionStatus.ready);
898 inviteStreamService.updateInviteInfo(inviteInfo); 757 inviteStreamService.updateInviteInfo(inviteInfo);
@@ -998,7 +857,9 @@ public class PlayServiceImpl implements IPlayService { @@ -998,7 +857,9 @@ public class PlayServiceImpl implements IPlayService {
998 // 添加订阅 857 // 添加订阅
999 HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); 858 HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
1000 subscribe.removeSubscribe(hookSubscribe); 859 subscribe.removeSubscribe(hookSubscribe);
1001 - hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase()); 860 + String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase();
  861 + hookSubscribe.getContent().put("stream", stream);
  862 + inviteStreamService.updateInviteInfoForStream(inviteInfo, stream);
1002 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { 863 subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> {
1003 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); 864 logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam);
1004 dynamicTask.stop(downLoadTimeOutTaskKey); 865 dynamicTask.stop(downLoadTimeOutTaskKey);
@@ -1026,6 +887,9 @@ public class PlayServiceImpl implements IPlayService { @@ -1026,6 +887,9 @@ public class PlayServiceImpl implements IPlayService {
1026 "下级自定义了ssrc,重新设置收流信息失败", null); 887 "下级自定义了ssrc,重新设置收流信息失败", null);
1027 888
1028 }else { 889 }else {
  890 + if (ssrcInfo.getStream()!= null && !ssrcInfo.getStream().equals(inviteInfo.getStream())) {
  891 + inviteStreamService.removeInviteInfo(inviteInfo);
  892 + }
1029 ssrcInfo.setSsrc(ssrcInResponse); 893 ssrcInfo.setSsrc(ssrcInResponse);
1030 inviteInfo.setSsrcInfo(ssrcInfo); 894 inviteInfo.setSsrcInfo(ssrcInfo);
1031 inviteInfo.setStream(ssrcInfo.getStream()); 895 inviteInfo.setStream(ssrcInfo.getStream());
@@ -1034,6 +898,7 @@ public class PlayServiceImpl implements IPlayService { @@ -1034,6 +898,7 @@ public class PlayServiceImpl implements IPlayService {
1034 logger.info("[录像下载] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正"); 898 logger.info("[录像下载] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正");
1035 } 899 }
1036 } 900 }
  901 + inviteStreamService.updateInviteInfo(inviteInfo);
1037 }); 902 });
1038 } catch (InvalidArgumentException | SipException | ParseException e) { 903 } catch (InvalidArgumentException | SipException | ParseException e) {
1039 logger.error("[命令发送失败] 录像下载: {}", e.getMessage()); 904 logger.error("[命令发送失败] 录像下载: {}", e.getMessage());
@@ -1255,18 +1120,13 @@ public class PlayServiceImpl implements IPlayService { @@ -1255,18 +1120,13 @@ public class PlayServiceImpl implements IPlayService {
1255 } 1120 }
1256 1121
1257 @Override 1122 @Override
1258 - public void getSnap(String deviceId, String channelId, String fileName,boolean isSubStream, ErrorCallback errorCallback) { 1123 + public void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback) {
1259 Device device = deviceService.getDevice(deviceId); 1124 Device device = deviceService.getDevice(deviceId);
1260 if (device == null) { 1125 if (device == null) {
1261 errorCallback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), null); 1126 errorCallback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), null);
1262 return; 1127 return;
1263 } 1128 }
1264 - InviteInfo inviteInfo;  
1265 - if(device.isSwitchPrimarySubStream()){  
1266 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
1267 - }else {  
1268 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);  
1269 - } 1129 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
1270 if (inviteInfo != null) { 1130 if (inviteInfo != null) {
1271 if (inviteInfo.getStreamInfo() != null) { 1131 if (inviteInfo.getStreamInfo() != null) {
1272 // 已存在线直接截图 1132 // 已存在线直接截图
@@ -1292,11 +1152,11 @@ public class PlayServiceImpl implements IPlayService { @@ -1292,11 +1152,11 @@ public class PlayServiceImpl implements IPlayService {
1292 } 1152 }
1293 1153
1294 MediaServerItem newMediaServerItem = getNewMediaServerItem(device); 1154 MediaServerItem newMediaServerItem = getNewMediaServerItem(device);
1295 - play(newMediaServerItem, deviceId, channelId,isSubStream, (code, msg, data)->{ 1155 + play(newMediaServerItem, deviceId, channelId, (code, msg, data)->{
1296 if (code == InviteErrorCode.SUCCESS.getCode()) { 1156 if (code == InviteErrorCode.SUCCESS.getCode()) {
1297 InviteInfo inviteInfoForPlay = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); 1157 InviteInfo inviteInfoForPlay = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
1298 if (inviteInfoForPlay != null && inviteInfoForPlay.getStreamInfo() != null) { 1158 if (inviteInfoForPlay != null && inviteInfoForPlay.getStreamInfo() != null) {
1299 - getSnap(deviceId, channelId, fileName,isSubStream, errorCallback); 1159 + getSnap(deviceId, channelId, fileName, errorCallback);
1300 }else { 1160 }else {
1301 errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null); 1161 errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null);
1302 } 1162 }
@@ -1306,17 +1166,4 @@ public class PlayServiceImpl implements IPlayService { @@ -1306,17 +1166,4 @@ public class PlayServiceImpl implements IPlayService {
1306 }); 1166 });
1307 } 1167 }
1308 1168
1309 -  
1310 - /*======================设备主子码流逻辑START=========================*/  
1311 - public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, OnStreamChangedHookParam hookParam, String deviceId, String channelId,boolean isSubStream) {  
1312 - String streamId = hookParam.getStream();  
1313 - List<OnStreamChangedHookParam.MediaTrack> tracks = hookParam.getTracks();  
1314 - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", streamId, tracks, null);  
1315 - streamInfo.setDeviceID(deviceId);  
1316 - streamInfo.setChannelId(channelId);  
1317 - streamInfo.setSubStream(isSubStream);  
1318 - return streamInfo;  
1319 - }  
1320 - /*======================设备主子码流逻辑END=========================*/  
1321 -  
1322 } 1169 }
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
@@ -70,7 +70,6 @@ public class UserServiceImpl implements IUserService { @@ -70,7 +70,6 @@ public class UserServiceImpl implements IUserService {
70 continue; 70 continue;
71 } 71 }
72 String checkStr = callId == null? user.getPushKey():(callId + "_" + user.getPushKey()) ; 72 String checkStr = callId == null? user.getPushKey():(callId + "_" + user.getPushKey()) ;
73 - System.out.println(checkStr);  
74 String checkSign = DigestUtils.md5DigestAsHex(checkStr.getBytes()); 73 String checkSign = DigestUtils.md5DigestAsHex(checkStr.getBytes());
75 if (checkSign.equals(sign)) { 74 if (checkSign.equals(sign)) {
76 return true; 75 return true;
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -88,17 +88,16 @@ public class PlayController { @@ -88,17 +88,16 @@ public class PlayController {
88 @Operation(summary = "开始点播") 88 @Operation(summary = "开始点播")
89 @Parameter(name = "deviceId", description = "设备国标编号", required = true) 89 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
90 @Parameter(name = "channelId", description = "通道国标编号", required = true) 90 @Parameter(name = "channelId", description = "通道国标编号", required = true)
91 - @Parameter(name = "isSubStream", description = "是否子码流(true-子码流,false-主码流),默认为false", required = true)  
92 @GetMapping("/start/{deviceId}/{channelId}") 91 @GetMapping("/start/{deviceId}/{channelId}")
93 public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId, 92 public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId,
94 - @PathVariable String channelId,boolean isSubStream) { 93 + @PathVariable String channelId) {
95 94
96 // 获取可用的zlm 95 // 获取可用的zlm
97 Device device = storager.queryVideoDevice(deviceId); 96 Device device = storager.queryVideoDevice(deviceId);
98 MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); 97 MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
99 98
100 RequestMessage requestMessage = new RequestMessage(); 99 RequestMessage requestMessage = new RequestMessage();
101 - String key = DeferredResultHolder.getPlayKey(deviceId,channelId,device.isSwitchPrimarySubStream(),isSubStream); 100 + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
102 requestMessage.setKey(key); 101 requestMessage.setKey(key);
103 String uuid = UUID.randomUUID().toString(); 102 String uuid = UUID.randomUUID().toString();
104 requestMessage.setId(uuid); 103 requestMessage.setId(uuid);
@@ -117,7 +116,7 @@ public class PlayController { @@ -117,7 +116,7 @@ public class PlayController {
117 // 录像查询以channelId作为deviceId查询 116 // 录像查询以channelId作为deviceId查询
118 resultHolder.put(key, uuid, result); 117 resultHolder.put(key, uuid, result);
119 118
120 - playService.play(newMediaServerItem, deviceId, channelId,isSubStream, (code, msg, data) -> { 119 + playService.play(newMediaServerItem, deviceId, channelId, (code, msg, data) -> {
121 WVPResult<StreamContent> wvpResult = new WVPResult<>(); 120 WVPResult<StreamContent> wvpResult = new WVPResult<>();
122 if (code == InviteErrorCode.SUCCESS.getCode()) { 121 if (code == InviteErrorCode.SUCCESS.getCode()) {
123 wvpResult.setCode(ErrorCode.SUCCESS.getCode()); 122 wvpResult.setCode(ErrorCode.SUCCESS.getCode());
@@ -158,12 +157,7 @@ public class PlayController { @@ -158,12 +157,7 @@ public class PlayController {
158 throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在"); 157 throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在");
159 } 158 }
160 159
161 - InviteInfo inviteInfo =null;  
162 - if(device.isSwitchPrimarySubStream()){  
163 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
164 - }else {  
165 - inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);  
166 - } 160 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
167 if (inviteInfo == null) { 161 if (inviteInfo == null) {
168 throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到"); 162 throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到");
169 } 163 }
@@ -176,12 +170,8 @@ public class PlayController { @@ -176,12 +170,8 @@ public class PlayController {
176 throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); 170 throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
177 } 171 }
178 } 172 }
179 - if(device.isSwitchPrimarySubStream()){  
180 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);  
181 - }else {  
182 - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);  
183 - storager.stopPlay(deviceId, channelId);  
184 - } 173 + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
  174 + storager.stopPlay(deviceId, channelId);
185 175
186 JSONObject json = new JSONObject(); 176 JSONObject json = new JSONObject();
187 json.put("deviceId", deviceId); 177 json.put("deviceId", deviceId);
@@ -360,9 +350,8 @@ public class PlayController { @@ -360,9 +350,8 @@ public class PlayController {
360 logger.debug("获取截图: {}/{}", deviceId, channelId); 350 logger.debug("获取截图: {}/{}", deviceId, channelId);
361 } 351 }
362 352
363 - Device device = storager.queryVideoDevice(deviceId);  
364 DeferredResult<String> result = new DeferredResult<>(3 * 1000L); 353 DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
365 - String key = DeferredResultHolder.getSnapKey(deviceId,channelId,device.isSwitchPrimarySubStream(),isSubStream); 354 + String key = DeferredResultHolder.CALLBACK_CMD_SNAP + deviceId;
366 String uuid = UUID.randomUUID().toString(); 355 String uuid = UUID.randomUUID().toString();
367 resultHolder.put(key, uuid, result); 356 resultHolder.put(key, uuid, result);
368 357
@@ -371,7 +360,7 @@ public class PlayController { @@ -371,7 +360,7 @@ public class PlayController {
371 message.setId(uuid); 360 message.setId(uuid);
372 361
373 String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + "jpg"; 362 String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + "jpg";
374 - playService.getSnap(deviceId, channelId, fileName,isSubStream, (code, msg, data) -> { 363 + playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
375 if (code == InviteErrorCode.SUCCESS.getCode()) { 364 if (code == InviteErrorCode.SUCCESS.getCode()) {
376 message.setData(data); 365 message.setData(data);
377 }else { 366 }else {
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
@@ -122,7 +122,7 @@ public class ApiStreamController { @@ -122,7 +122,7 @@ public class ApiStreamController {
122 MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); 122 MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
123 123
124 124
125 - playService.play(newMediaServerItem, serial, code,false, (errorCode, msg, data) -> { 125 + playService.play(newMediaServerItem, serial, code, (errorCode, msg, data) -> {
126 if (errorCode == InviteErrorCode.SUCCESS.getCode()) { 126 if (errorCode == InviteErrorCode.SUCCESS.getCode()) {
127 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code); 127 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code);
128 if (inviteInfo != null && inviteInfo.getStreamInfo() != null) { 128 if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {