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 77 @Value("${media.seniorSdp}")
78 78 private boolean seniorSdp;
79 79  
  80 + @Value("${media.autoApplyPlay}")
  81 + private boolean autoApplyPlay;
  82 +
80 83 @Autowired
81 84 private ZLMHttpHookSubscribe subscribe;
82 85  
... ... @@ -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 193 public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) {
191 194 StringBuilder builder = new StringBuilder("A50F01");
192 195 String strTmp;
... ... @@ -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 222 @Override
220 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 290 @Override
288 291 public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
289 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 299 String streamId = null;
293 300 if (rtpEnable) {
294 301 streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
... ... @@ -326,13 +333,14 @@ public class SIPCommander implements ISIPCommander {
326 333  
327 334 if (seniorSdp) {
328 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 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 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 342 content.append("a=recvonly\r\n");
  343 + content.append("a=rtpmap:96 PS/90000\r\n");
336 344 content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
337 345 content.append("a=rtpmap:126 H264/90000\r\n");
338 346 content.append("a=rtpmap:125 H264S/90000\r\n");
... ... @@ -341,7 +349,6 @@ public class SIPCommander implements ISIPCommander {
341 349 content.append("a=fmtp:99 profile-level-id=3\r\n");
342 350 content.append("a=rtpmap:98 H264/90000\r\n");
343 351 content.append("a=rtpmap:97 MPEG4/90000\r\n");
344   - content.append("a=rtpmap:96 PS/90000\r\n");
345 352 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
346 353 content.append("a=setup:passive\r\n");
347 354 content.append("a=connection:new\r\n");
... ... @@ -380,9 +387,6 @@ public class SIPCommander implements ISIPCommander {
380 387  
381 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 390 Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
387 391  
388 392 ClientTransaction transaction = transmitRequest(device, request, errorEvent);
... ... @@ -408,8 +412,16 @@ public class SIPCommander implements ISIPCommander {
408 412 , SipSubscribe.Event errorEvent) {
409 413 try {
410 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 426 JSONObject subscribeKey = new JSONObject();
415 427 subscribeKey.put("app", "rtp");
... ... @@ -417,7 +429,6 @@ public class SIPCommander implements ISIPCommander {
417 429  
418 430 subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
419 431  
420   - //
421 432 StringBuffer content = new StringBuffer(200);
422 433 content.append("v=0\r\n");
423 434 content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
... ... @@ -437,13 +448,14 @@ public class SIPCommander implements ISIPCommander {
437 448  
438 449 if (seniorSdp) {
439 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 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 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 457 content.append("a=recvonly\r\n");
  458 + content.append("a=rtpmap:96 PS/90000\r\n");
447 459 content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
448 460 content.append("a=rtpmap:126 H264/90000\r\n");
449 461 content.append("a=rtpmap:125 H264S/90000\r\n");
... ... @@ -452,7 +464,6 @@ public class SIPCommander implements ISIPCommander {
452 464 content.append("a=fmtp:99 profile-level-id=3\r\n");
453 465 content.append("a=rtpmap:98 H264/90000\r\n");
454 466 content.append("a=rtpmap:97 MPEG4/90000\r\n");
455   - content.append("a=rtpmap:96 PS/90000\r\n");
456 467 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
457 468 content.append("a=setup:passive\r\n");
458 469 content.append("a=connection:new\r\n");
... ... @@ -521,9 +532,6 @@ public class SIPCommander implements ISIPCommander {
521 532 if (dialog == null) {
522 533 return;
523 534 }
524   -
525   -
526   -
527 535 Request byeRequest = dialog.createRequest(Request.BYE);
528 536 SipURI byeURI = (SipURI) byeRequest.getRequestURI();
529 537 String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();
... ...