国标录像支持多端同时播放
This commit is contained in:
@@ -110,26 +110,26 @@ public class PlayController {
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
|
||||
resultHolder.put(key, uuid, result);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
cmder.streamByeCmd(deviceId, channelId, (event) -> {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
if (streamInfo == null) {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("点播未找到");
|
||||
resultHolder.invokeAllResult(msg);
|
||||
storager.stopPlay(deviceId, channelId);
|
||||
}else {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
//Response response = event.getResponse();
|
||||
msg.setData(String.format("success"));
|
||||
resultHolder.invokeAllResult(msg);
|
||||
}
|
||||
mediaServerService.closeRTPServer(device, channelId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
if (streamInfo == null) {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("点播未找到");
|
||||
resultHolder.invokeAllResult(msg);
|
||||
storager.stopPlay(deviceId, channelId);
|
||||
return result;
|
||||
}
|
||||
cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream(), (event) -> {
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
//Response response = event.getResponse();
|
||||
msg.setData(String.format("success"));
|
||||
resultHolder.invokeAllResult(msg);
|
||||
mediaServerService.closeRTPServer(device, channelId, streamInfo.getStream());
|
||||
});
|
||||
|
||||
if (deviceId != null || channelId != null) {
|
||||
@@ -329,7 +329,7 @@ public class PlayController {
|
||||
jsonObject.put("deviceId", transaction.getDeviceId());
|
||||
jsonObject.put("channelId", transaction.getChannelId());
|
||||
jsonObject.put("ssrc", transaction.getSsrc());
|
||||
jsonObject.put("streamId", transaction.getStreamId());
|
||||
jsonObject.put("streamId", transaction.getStream());
|
||||
objects.add(jsonObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public class DownloadController {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId);
|
||||
if (streamInfo != null) {
|
||||
// 停止之前的下载
|
||||
cmder.streamByeCmd(deviceId, channelId);
|
||||
cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream());
|
||||
}
|
||||
|
||||
MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
@@ -114,7 +114,7 @@ public class DownloadController {
|
||||
|
||||
cmder.downloadStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, (MediaServerItem mediaServerItem, JSONObject response) -> {
|
||||
logger.info("收到订阅消息: " + response.toJSONString());
|
||||
playService.onPublishHandlerForDownload(mediaServerItem, response, deviceId, channelId, uuid.toString());
|
||||
playService.onPublishHandlerForDownload(mediaServerItem, response, deviceId, channelId, uuid);
|
||||
}, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
@@ -130,11 +130,12 @@ public class DownloadController {
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "deviceId", value = "设备ID", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
|
||||
})
|
||||
@GetMapping("/stop/{deviceId}/{channelId}")
|
||||
public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
@GetMapping("/stop/{deviceId}/{channelId}/{stream}")
|
||||
public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
|
||||
cmder.streamByeCmd(deviceId, channelId);
|
||||
cmder.streamByeCmd(deviceId, channelId, stream);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备历史媒体下载停止 API调用,deviceId/channelId:%s_%s", deviceId, channelId));
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -75,52 +76,8 @@ public class PlaybackController {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
}
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
|
||||
return result;
|
||||
}
|
||||
MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true);
|
||||
|
||||
// 超时处理
|
||||
result.onTimeout(()->{
|
||||
logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId);
|
||||
if (streamInfo != null) {
|
||||
// 停止之前的回放
|
||||
cmder.streamByeCmd(deviceId, channelId);
|
||||
}
|
||||
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId, uuid, result);
|
||||
|
||||
if (newMediaServerItem == null) {
|
||||
logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout");
|
||||
resultHolder.invokeResult(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
cmder.playbackStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, (MediaServerItem mediaServerItem, JSONObject response) -> {
|
||||
logger.info("收到订阅消息: " + response.toJSONString());
|
||||
playService.onPublishHandlerForPlayBack(mediaServerItem, response, deviceId, channelId, uuid.toString());
|
||||
}, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, msg->{
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
|
||||
@@ -131,24 +88,31 @@ public class PlaybackController {
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "deviceId", value = "设备ID", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
|
||||
})
|
||||
@GetMapping("/stop/{deviceId}/{channelId}")
|
||||
public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
@GetMapping("/stop/{deviceId}/{channelId}/{stream}")
|
||||
public ResponseEntity<String> playStop(
|
||||
@PathVariable String deviceId,
|
||||
@PathVariable String channelId,
|
||||
@PathVariable String stream) {
|
||||
|
||||
cmder.streamByeCmd(deviceId, channelId);
|
||||
cmder.streamByeCmd(deviceId, channelId, stream);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备录像回放停止 API调用,deviceId/channelId:%s/%s", deviceId, channelId));
|
||||
}
|
||||
if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId) || StringUtils.isEmpty(stream)) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (deviceId != null && channelId != null) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
json.put("channelId", channelId);
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
return new ResponseEntity<>(json.toString(), HttpStatus.OK);
|
||||
} else {
|
||||
logger.warn("设备录像回放停止API调用失败!");
|
||||
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user