整合 closeStream 方法
This commit is contained in:
parent
0420227ccc
commit
67b90c7341
@ -71,8 +71,47 @@ public class PlayService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int openRtpServer(DeferredResult<JsonResponse<String>> result, String streamId, int streamMode) {
|
||||||
|
GetRtpInfoResp rtpInfo = zlmMediaService.getRtpInfo(streamId);
|
||||||
|
if (rtpInfo.getExist()) {
|
||||||
|
result.setResult(JsonResponse.error(MessageFormat.format("流 {0} 已存在", streamId)));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenRtpServer openRtpServer = new OpenRtpServer();
|
||||||
|
openRtpServer.setPort(0);
|
||||||
|
openRtpServer.setStreamId(streamId);
|
||||||
|
openRtpServer.setTcpMode(streamMode);
|
||||||
|
OpenRtpServerResp openRtpServerResp = zlmMediaService.openRtpServer(openRtpServer);
|
||||||
|
log.info("openRtpServerResp => {}", openRtpServerResp);
|
||||||
|
if (!openRtpServerResp.getCode().equals(ResponseStatus.Success)) {
|
||||||
|
result.setResult(JsonResponse.error(openRtpServerResp.getCode().getMsg()));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return openRtpServerResp.getPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private JsonResponse<Void> closeStream(String streamId, MediaSdpHelper.Action action, DockingDevice device, String channelId) {
|
||||||
|
zlmMediaService.closeRtpServer(new CloseRtpServer(streamId));
|
||||||
|
String key = CacheUtil.getKey(action.getAction(), device.getDeviceId(), channelId);
|
||||||
|
SipTransactionInfo transactionInfo = JsonUtils.parse(RedisUtil.StringOps.get(key), SipTransactionInfo.class);
|
||||||
|
if (transactionInfo == null) {
|
||||||
|
return JsonResponse.error("未找到连接信息");
|
||||||
|
}
|
||||||
|
Request request = SipRequestBuilder.createByeRequest(device, channelId, transactionInfo);
|
||||||
|
String senderIp = device.getLocalIp();
|
||||||
|
sender.send(senderIp, request);
|
||||||
|
|
||||||
|
String ssrc = transactionInfo.getSsrc();
|
||||||
|
ssrcService.releaseSsrc(zlmMediaConfig.getId(), ssrc);
|
||||||
|
RedisUtil.KeyOps.delete(key);
|
||||||
|
return JsonResponse.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时视频点播
|
* 实时视频点播
|
||||||
|
*
|
||||||
* @param deviceId 设备id
|
* @param deviceId 设备id
|
||||||
* @param channelId 通道id
|
* @param channelId 通道id
|
||||||
*/
|
*/
|
||||||
@ -91,26 +130,14 @@ public class PlayService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetRtpInfoResp rtpInfo = zlmMediaService.getRtpInfo(streamId);
|
|
||||||
if(rtpInfo.getExist()){
|
|
||||||
result.setResult(JsonResponse.error(MessageFormat.format("流 {0} 已存在", streamId)));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int streamMode = device.getStreamMode() == null || device.getStreamMode().equalsIgnoreCase(ListeningPoint.UDP) ? 0 : 1;
|
int streamMode = device.getStreamMode() == null || device.getStreamMode().equalsIgnoreCase(ListeningPoint.UDP) ? 0 : 1;
|
||||||
OpenRtpServer openRtpServer = new OpenRtpServer();
|
String ip = zlmMediaConfig.getIp();
|
||||||
openRtpServer.setPort(0);
|
int port = openRtpServer(result, streamId, streamMode);
|
||||||
openRtpServer.setStreamId(streamId);
|
|
||||||
openRtpServer.setTcpMode(streamMode);
|
if (result.hasResult()) {
|
||||||
OpenRtpServerResp openRtpServerResp = zlmMediaService.openRtpServer(openRtpServer);
|
|
||||||
log.info("openRtpServerResp => {}", openRtpServerResp);
|
|
||||||
if(!openRtpServerResp.getCode().equals(ResponseStatus.Success)){
|
|
||||||
result.setResult(JsonResponse.error(openRtpServerResp.getCode().getMsg()));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ip = zlmMediaConfig.getIp();
|
|
||||||
int port = openRtpServerResp.getPort();
|
|
||||||
String ssrc = ssrcService.getPlaySsrc();
|
String ssrc = ssrcService.getPlaySsrc();
|
||||||
GB28181Description description = MediaSdpHelper.play(deviceId, channelId, Connection.IP4, ip, port, ssrc, StreamMode.of(device.getStreamMode()));
|
GB28181Description description = MediaSdpHelper.play(deviceId, channelId, Connection.IP4, ip, port, ssrc, StreamMode.of(device.getStreamMode()));
|
||||||
|
|
||||||
@ -123,6 +150,7 @@ public class PlayService {
|
|||||||
subscribe.getInviteSubscribe().addPublisher(subscribeKey);
|
subscribe.getInviteSubscribe().addPublisher(subscribeKey);
|
||||||
Flow.Subscriber<SIPResponse> subscriber = new Flow.Subscriber<>() {
|
Flow.Subscriber<SIPResponse> subscriber = new Flow.Subscriber<>() {
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Flow.Subscription subscription) {
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
this.subscription = subscription;
|
this.subscription = subscription;
|
||||||
@ -179,20 +207,7 @@ public class PlayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String streamId = MediaSdpHelper.getStreamId(deviceId, channelId);
|
String streamId = MediaSdpHelper.getStreamId(deviceId, channelId);
|
||||||
String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY.getAction(), deviceId, channelId);
|
return closeStream(streamId, MediaSdpHelper.Action.PLAY, device, channelId);
|
||||||
zlmMediaService.closeRtpServer(new CloseRtpServer(streamId));
|
|
||||||
SipTransactionInfo transactionInfo = JsonUtils.parse(RedisUtil.StringOps.get(key), SipTransactionInfo.class);
|
|
||||||
if(transactionInfo == null){
|
|
||||||
return JsonResponse.error("未找到连接信息");
|
|
||||||
}
|
|
||||||
Request request = SipRequestBuilder.createByeRequest(device, channelId, transactionInfo);
|
|
||||||
String senderIp = device.getLocalIp();
|
|
||||||
sender.send(senderIp, request);
|
|
||||||
|
|
||||||
String ssrc = transactionInfo.getSsrc();
|
|
||||||
ssrcService.releaseSsrc(zlmMediaConfig.getId(),ssrc);
|
|
||||||
RedisUtil.KeyOps.delete(key);
|
|
||||||
return JsonResponse.success(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@ -212,26 +227,14 @@ public class PlayService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetRtpInfoResp rtpInfo = zlmMediaService.getRtpInfo(streamId);
|
|
||||||
if(rtpInfo.getExist()){
|
|
||||||
result.setResult(JsonResponse.error(MessageFormat.format("流 {0} 已存在", streamId)));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int streamMode = device.getStreamMode() == null || device.getStreamMode().equalsIgnoreCase(ListeningPoint.UDP) ? 0 : 1;
|
int streamMode = device.getStreamMode() == null || device.getStreamMode().equalsIgnoreCase(ListeningPoint.UDP) ? 0 : 1;
|
||||||
OpenRtpServer openRtpServer = new OpenRtpServer();
|
String ip = zlmMediaConfig.getIp();
|
||||||
openRtpServer.setPort(0);
|
int port = openRtpServer(result, streamId, streamMode);
|
||||||
openRtpServer.setStreamId(streamId);
|
|
||||||
openRtpServer.setTcpMode(streamMode);
|
if (result.hasResult()) {
|
||||||
OpenRtpServerResp openRtpServerResp = zlmMediaService.openRtpServer(openRtpServer);
|
|
||||||
log.info("openRtpServerResp => {}", openRtpServerResp);
|
|
||||||
if(!openRtpServerResp.getCode().equals(ResponseStatus.Success)){
|
|
||||||
result.setResult(JsonResponse.error(openRtpServerResp.getCode().getMsg()));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ip = zlmMediaConfig.getIp();
|
|
||||||
int port = openRtpServerResp.getPort();
|
|
||||||
String ssrc = ssrcService.getPlaySsrc();
|
String ssrc = ssrcService.getPlaySsrc();
|
||||||
GB28181Description description = MediaSdpHelper.playback(deviceId, channelId, Connection.IP4, ip, port, ssrc, StreamMode.of(device.getStreamMode()), startTime, endTime);
|
GB28181Description description = MediaSdpHelper.playback(deviceId, channelId, Connection.IP4, ip, port, ssrc, StreamMode.of(device.getStreamMode()), startTime, endTime);
|
||||||
|
|
||||||
@ -245,6 +248,7 @@ public class PlayService {
|
|||||||
subscribe.getInviteSubscribe().addPublisher(subscribeKey);
|
subscribe.getInviteSubscribe().addPublisher(subscribeKey);
|
||||||
Flow.Subscriber<SIPResponse> subscriber = new Flow.Subscriber<>() {
|
Flow.Subscriber<SIPResponse> subscriber = new Flow.Subscriber<>() {
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Flow.Subscription subscription) {
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
this.subscription = subscription;
|
this.subscription = subscription;
|
||||||
@ -303,20 +307,7 @@ public class PlayService {
|
|||||||
long start = startTime.toInstant().getEpochSecond();
|
long start = startTime.toInstant().getEpochSecond();
|
||||||
long end = endTime.toInstant().getEpochSecond();
|
long end = endTime.toInstant().getEpochSecond();
|
||||||
String streamId = MediaSdpHelper.getStreamId(deviceId, channelId, String.valueOf(start), String.valueOf(end));
|
String streamId = MediaSdpHelper.getStreamId(deviceId, channelId, String.valueOf(start), String.valueOf(end));
|
||||||
String key = CacheUtil.getKey(MediaSdpHelper.Action.PLAY_BACK.getAction(), deviceId, channelId);
|
return closeStream(streamId, MediaSdpHelper.Action.PLAY_BACK, device, channelId);
|
||||||
zlmMediaService.closeRtpServer(new CloseRtpServer(streamId));
|
|
||||||
SipTransactionInfo transactionInfo = JsonUtils.parse(RedisUtil.StringOps.get(key), SipTransactionInfo.class);
|
|
||||||
if(transactionInfo == null){
|
|
||||||
return JsonResponse.error("未找到连接信息");
|
|
||||||
}
|
|
||||||
Request request = SipRequestBuilder.createByeRequest(device, channelId, transactionInfo);
|
|
||||||
String senderIp = device.getLocalIp();
|
|
||||||
sender.send(senderIp, request);
|
|
||||||
|
|
||||||
String ssrc = transactionInfo.getSsrc();
|
|
||||||
ssrcService.releaseSsrc(zlmMediaConfig.getId(),ssrc);
|
|
||||||
RedisUtil.KeyOps.delete(key);
|
|
||||||
return JsonResponse.success(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user