Commit fb69312642e211c19855aeee096735a7a6270fcc

Authored by Lawrence
1 parent 42450af8

修正录像回放错误

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -77,6 +77,9 @@ public class SIPCommander implements ISIPCommander { @@ -77,6 +77,9 @@ public class SIPCommander implements ISIPCommander {
77 @Value("${media.seniorSdp}") 77 @Value("${media.seniorSdp}")
78 private boolean seniorSdp; 78 private boolean seniorSdp;
79 79
  80 + @Value("${media.autoApplyPlay}")
  81 + private boolean autoApplyPlay;
  82 +
80 @Autowired 83 @Autowired
81 private ZLMHttpHookSubscribe subscribe; 84 private ZLMHttpHookSubscribe subscribe;
82 85
@@ -182,11 +185,11 @@ public class SIPCommander implements ISIPCommander { @@ -182,11 +185,11 @@ public class SIPCommander implements ISIPCommander {
182 /** 185 /**
183 * 云台指令码计算 186 * 云台指令码计算
184 * 187 *
185 - * @param cmdCode 指令码  
186 - * @param parameter1 数据1  
187 - * @param parameter2 数据2  
188 - * @param combineCode2 组合码2  
189 - */ 188 + * @param cmdCode 指令码
  189 + * @param parameter1 数据1
  190 + * @param parameter2 数据2
  191 + * @param combineCode2 组合码2
  192 + */
190 public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) { 193 public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) {
191 StringBuilder builder = new StringBuilder("A50F01"); 194 StringBuilder builder = new StringBuilder("A50F01");
192 String strTmp; 195 String strTmp;
@@ -208,13 +211,13 @@ public class SIPCommander implements ISIPCommander { @@ -208,13 +211,13 @@ public class SIPCommander implements ISIPCommander {
208 /** 211 /**
209 * 云台控制,支持方向与缩放控制 212 * 云台控制,支持方向与缩放控制
210 * 213 *
211 - * @param device 控制设备  
212 - * @param channelId 预览通道  
213 - * @param leftRight 镜头左移右移 0:停止 1:左移 2:右移  
214 - * @param upDown 镜头上移下移 0:停止 1:上移 2:下移  
215 - * @param inOut 镜头放大缩小 0:停止 1:缩小 2:放大  
216 - * @param moveSpeed 镜头移动速度  
217 - * @param zoomSpeed 镜头缩放速度 214 + * @param device 控制设备
  215 + * @param channelId 预览通道
  216 + * @param leftRight 镜头左移右移 0:停止 1:左移 2:右移
  217 + * @param upDown 镜头上移下移 0:停止 1:上移 2:下移
  218 + * @param inOut 镜头放大缩小 0:停止 1:缩小 2:放大
  219 + * @param moveSpeed 镜头移动速度
  220 + * @param zoomSpeed 镜头缩放速度
218 */ 221 */
219 @Override 222 @Override
220 public boolean ptzCmd(Device device, String channelId, int leftRight, int upDown, int inOut, int moveSpeed, 223 public boolean ptzCmd(Device device, String channelId, int leftRight, int upDown, int inOut, int moveSpeed,
@@ -287,8 +290,12 @@ public class SIPCommander implements ISIPCommander { @@ -287,8 +290,12 @@ public class SIPCommander implements ISIPCommander {
287 @Override 290 @Override
288 public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) { 291 public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
289 try { 292 try {
290 -  
291 - String ssrc = streamSession.createPlaySsrc(); 293 + String ssrc = "";
  294 + if (rtpEnable) {
  295 + ssrc = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
  296 + }else {
  297 + ssrc = streamSession.createPlaySsrc();
  298 + }
292 String streamId = null; 299 String streamId = null;
293 if (rtpEnable) { 300 if (rtpEnable) {
294 streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId); 301 streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
@@ -326,13 +333,14 @@ public class SIPCommander implements ISIPCommander { @@ -326,13 +333,14 @@ public class SIPCommander implements ISIPCommander {
326 333
327 if (seniorSdp) { 334 if (seniorSdp) {
328 if("TCP-PASSIVE".equals(streamMode)) { 335 if("TCP-PASSIVE".equals(streamMode)) {
329 - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); 336 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
330 }else if ("TCP-ACTIVE".equals(streamMode)) { 337 }else if ("TCP-ACTIVE".equals(streamMode)) {
331 - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); 338 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
332 }else if("UDP".equals(streamMode)) { 339 }else if("UDP".equals(streamMode)) {
333 - content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n"); 340 + content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
334 } 341 }
335 content.append("a=recvonly\r\n"); 342 content.append("a=recvonly\r\n");
  343 + content.append("a=rtpmap:96 PS/90000\r\n");
336 content.append("a=fmtp:126 profile-level-id=42e01e\r\n"); 344 content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
337 content.append("a=rtpmap:126 H264/90000\r\n"); 345 content.append("a=rtpmap:126 H264/90000\r\n");
338 content.append("a=rtpmap:125 H264S/90000\r\n"); 346 content.append("a=rtpmap:125 H264S/90000\r\n");
@@ -341,7 +349,6 @@ public class SIPCommander implements ISIPCommander { @@ -341,7 +349,6 @@ public class SIPCommander implements ISIPCommander {
341 content.append("a=fmtp:99 profile-level-id=3\r\n"); 349 content.append("a=fmtp:99 profile-level-id=3\r\n");
342 content.append("a=rtpmap:98 H264/90000\r\n"); 350 content.append("a=rtpmap:98 H264/90000\r\n");
343 content.append("a=rtpmap:97 MPEG4/90000\r\n"); 351 content.append("a=rtpmap:97 MPEG4/90000\r\n");
344 - content.append("a=rtpmap:96 PS/90000\r\n");  
345 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式 352 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
346 content.append("a=setup:passive\r\n"); 353 content.append("a=setup:passive\r\n");
347 content.append("a=connection:new\r\n"); 354 content.append("a=connection:new\r\n");
@@ -380,9 +387,6 @@ public class SIPCommander implements ISIPCommander { @@ -380,9 +387,6 @@ public class SIPCommander implements ISIPCommander {
380 387
381 content.append("y="+ssrc+"\r\n");//ssrc 388 content.append("y="+ssrc+"\r\n");//ssrc
382 389
383 -// String fromTag = UUID.randomUUID().toString();  
384 -// Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, fromTag, null, ssrc);  
385 -  
386 Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc); 390 Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
387 391
388 ClientTransaction transaction = transmitRequest(device, request, errorEvent); 392 ClientTransaction transaction = transmitRequest(device, request, errorEvent);
@@ -408,8 +412,16 @@ public class SIPCommander implements ISIPCommander { @@ -408,8 +412,16 @@ public class SIPCommander implements ISIPCommander {
408 , SipSubscribe.Event errorEvent) { 412 , SipSubscribe.Event errorEvent) {
409 try { 413 try {
410 MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); 414 MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
411 - String ssrc = streamSession.createPlayBackSsrc();  
412 - String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); 415 + String ssrc = null;
  416 + String streamId = null;
  417 + if (rtpEnable) {
  418 + ssrc = String.format("gb_playback_%s_%s", device.getDeviceId(), channelId);
  419 + streamId = ssrc;
  420 + }else {
  421 + ssrc = streamSession.createPlayBackSsrc();
  422 + streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
  423 + }
  424 +
413 // 添加订阅 425 // 添加订阅
414 JSONObject subscribeKey = new JSONObject(); 426 JSONObject subscribeKey = new JSONObject();
415 subscribeKey.put("app", "rtp"); 427 subscribeKey.put("app", "rtp");
@@ -417,7 +429,6 @@ public class SIPCommander implements ISIPCommander { @@ -417,7 +429,6 @@ public class SIPCommander implements ISIPCommander {
417 429
418 subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event); 430 subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
419 431
420 - //  
421 StringBuffer content = new StringBuffer(200); 432 StringBuffer content = new StringBuffer(200);
422 content.append("v=0\r\n"); 433 content.append("v=0\r\n");
423 content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); 434 content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
@@ -437,13 +448,14 @@ public class SIPCommander implements ISIPCommander { @@ -437,13 +448,14 @@ public class SIPCommander implements ISIPCommander {
437 448
438 if (seniorSdp) { 449 if (seniorSdp) {
439 if("TCP-PASSIVE".equals(streamMode)) { 450 if("TCP-PASSIVE".equals(streamMode)) {
440 - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); 451 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
441 }else if ("TCP-ACTIVE".equals(streamMode)) { 452 }else if ("TCP-ACTIVE".equals(streamMode)) {
442 - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); 453 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
443 }else if("UDP".equals(streamMode)) { 454 }else if("UDP".equals(streamMode)) {
444 - content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n"); 455 + content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
445 } 456 }
446 content.append("a=recvonly\r\n"); 457 content.append("a=recvonly\r\n");
  458 + content.append("a=rtpmap:96 PS/90000\r\n");
447 content.append("a=fmtp:126 profile-level-id=42e01e\r\n"); 459 content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
448 content.append("a=rtpmap:126 H264/90000\r\n"); 460 content.append("a=rtpmap:126 H264/90000\r\n");
449 content.append("a=rtpmap:125 H264S/90000\r\n"); 461 content.append("a=rtpmap:125 H264S/90000\r\n");
@@ -452,7 +464,6 @@ public class SIPCommander implements ISIPCommander { @@ -452,7 +464,6 @@ public class SIPCommander implements ISIPCommander {
452 content.append("a=fmtp:99 profile-level-id=3\r\n"); 464 content.append("a=fmtp:99 profile-level-id=3\r\n");
453 content.append("a=rtpmap:98 H264/90000\r\n"); 465 content.append("a=rtpmap:98 H264/90000\r\n");
454 content.append("a=rtpmap:97 MPEG4/90000\r\n"); 466 content.append("a=rtpmap:97 MPEG4/90000\r\n");
455 - content.append("a=rtpmap:96 PS/90000\r\n");  
456 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式 467 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
457 content.append("a=setup:passive\r\n"); 468 content.append("a=setup:passive\r\n");
458 content.append("a=connection:new\r\n"); 469 content.append("a=connection:new\r\n");
@@ -521,9 +532,6 @@ public class SIPCommander implements ISIPCommander { @@ -521,9 +532,6 @@ public class SIPCommander implements ISIPCommander {
521 if (dialog == null) { 532 if (dialog == null) {
522 return; 533 return;
523 } 534 }
524 -  
525 -  
526 -  
527 Request byeRequest = dialog.createRequest(Request.BYE); 535 Request byeRequest = dialog.createRequest(Request.BYE);
528 SipURI byeURI = (SipURI) byeRequest.getRequestURI(); 536 SipURI byeURI = (SipURI) byeRequest.getRequestURI();
529 String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString(); 537 String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();