修正录像回放错误

This commit is contained in:
Lawrence 2021-01-11 09:16:16 +08:00
parent 6ce6b95b56
commit b1f4810025

View File

@ -77,6 +77,9 @@ public class SIPCommander implements ISIPCommander {
@Value("${media.seniorSdp}") @Value("${media.seniorSdp}")
private boolean seniorSdp; private boolean seniorSdp;
@Value("${media.autoApplyPlay}")
private boolean autoApplyPlay;
@Autowired @Autowired
private ZLMHttpHookSubscribe subscribe; private ZLMHttpHookSubscribe subscribe;
@ -287,8 +290,12 @@ public class SIPCommander implements ISIPCommander {
@Override @Override
public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) { public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
try { try {
String ssrc = "";
String ssrc = streamSession.createPlaySsrc(); if (rtpEnable) {
ssrc = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
}else {
ssrc = streamSession.createPlaySsrc();
}
String streamId = null; String streamId = null;
if (rtpEnable) { if (rtpEnable) {
streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId); streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
@ -326,13 +333,14 @@ public class SIPCommander implements ISIPCommander {
if (seniorSdp) { if (seniorSdp) {
if("TCP-PASSIVE".equals(streamMode)) { if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) { }else if ("TCP-ACTIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) { }else if("UDP".equals(streamMode)) {
content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
} }
content.append("a=recvonly\r\n"); content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
content.append("a=fmtp:126 profile-level-id=42e01e\r\n"); content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
content.append("a=rtpmap:126 H264/90000\r\n"); content.append("a=rtpmap:126 H264/90000\r\n");
content.append("a=rtpmap:125 H264S/90000\r\n"); content.append("a=rtpmap:125 H264S/90000\r\n");
@ -341,7 +349,6 @@ public class SIPCommander implements ISIPCommander {
content.append("a=fmtp:99 profile-level-id=3\r\n"); content.append("a=fmtp:99 profile-level-id=3\r\n");
content.append("a=rtpmap:98 H264/90000\r\n"); content.append("a=rtpmap:98 H264/90000\r\n");
content.append("a=rtpmap:97 MPEG4/90000\r\n"); content.append("a=rtpmap:97 MPEG4/90000\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
content.append("a=setup:passive\r\n"); content.append("a=setup:passive\r\n");
content.append("a=connection:new\r\n"); content.append("a=connection:new\r\n");
@ -380,9 +387,6 @@ public class SIPCommander implements ISIPCommander {
content.append("y="+ssrc+"\r\n");//ssrc content.append("y="+ssrc+"\r\n");//ssrc
// String fromTag = UUID.randomUUID().toString();
// Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, fromTag, null, ssrc);
Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc); Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
ClientTransaction transaction = transmitRequest(device, request, errorEvent); ClientTransaction transaction = transmitRequest(device, request, errorEvent);
@ -408,8 +412,16 @@ public class SIPCommander implements ISIPCommander {
, SipSubscribe.Event errorEvent) { , SipSubscribe.Event errorEvent) {
try { try {
MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
String ssrc = streamSession.createPlayBackSsrc(); String ssrc = null;
String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); String streamId = null;
if (rtpEnable) {
ssrc = String.format("gb_playback_%s_%s", device.getDeviceId(), channelId);
streamId = ssrc;
}else {
ssrc = streamSession.createPlayBackSsrc();
streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
}
// 添加订阅 // 添加订阅
JSONObject subscribeKey = new JSONObject(); JSONObject subscribeKey = new JSONObject();
subscribeKey.put("app", "rtp"); subscribeKey.put("app", "rtp");
@ -417,7 +429,6 @@ public class SIPCommander implements ISIPCommander {
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event); subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
//
StringBuffer content = new StringBuffer(200); StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n"); content.append("v=0\r\n");
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
@ -437,13 +448,14 @@ public class SIPCommander implements ISIPCommander {
if (seniorSdp) { if (seniorSdp) {
if("TCP-PASSIVE".equals(streamMode)) { if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) { }else if ("TCP-ACTIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) { }else if("UDP".equals(streamMode)) {
content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
} }
content.append("a=recvonly\r\n"); content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
content.append("a=fmtp:126 profile-level-id=42e01e\r\n"); content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
content.append("a=rtpmap:126 H264/90000\r\n"); content.append("a=rtpmap:126 H264/90000\r\n");
content.append("a=rtpmap:125 H264S/90000\r\n"); content.append("a=rtpmap:125 H264S/90000\r\n");
@ -452,7 +464,6 @@ public class SIPCommander implements ISIPCommander {
content.append("a=fmtp:99 profile-level-id=3\r\n"); content.append("a=fmtp:99 profile-level-id=3\r\n");
content.append("a=rtpmap:98 H264/90000\r\n"); content.append("a=rtpmap:98 H264/90000\r\n");
content.append("a=rtpmap:97 MPEG4/90000\r\n"); content.append("a=rtpmap:97 MPEG4/90000\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式 if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
content.append("a=setup:passive\r\n"); content.append("a=setup:passive\r\n");
content.append("a=connection:new\r\n"); content.append("a=connection:new\r\n");
@ -521,9 +532,6 @@ public class SIPCommander implements ISIPCommander {
if (dialog == null) { if (dialog == null) {
return; return;
} }
Request byeRequest = dialog.createRequest(Request.BYE); Request byeRequest = dialog.createRequest(Request.BYE);
SipURI byeURI = (SipURI) byeRequest.getRequestURI(); SipURI byeURI = (SipURI) byeRequest.getRequestURI();
String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString(); String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();