去除ssrc作为流ID传递,ssrc只作为sdp消息使用。动态端口的情况下支持固定流地址,同时支持未点播时直接播放流地址,代码自动发起点播

This commit is contained in:
panlinlin
2020-12-19 21:52:20 +08:00
parent 0188ffd19f
commit b0080159d9
17 changed files with 117 additions and 127 deletions

View File

@@ -80,7 +80,7 @@ public class PlayController {
playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
});
} else {
String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase();
String streamId = streamInfo.getStreamId();
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
if (rtpInfo.getBoolean("exist")) {
RequestMessage msg = new RequestMessage();
@@ -99,21 +99,21 @@ public class PlayController {
return result;
}
@PostMapping("/play/{ssrc}/stop")
public ResponseEntity<String> playStop(@PathVariable String ssrc) {
@PostMapping("/play/{streamId}/stop")
public ResponseEntity<String> playStop(@PathVariable String streamId) {
cmder.streamByeCmd(ssrc);
StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc);
cmder.streamByeCmd(streamId);
StreamInfo streamInfo = storager.queryPlayByStreamId(streamId);
if (streamInfo == null)
return new ResponseEntity<String>("ssrc not found", HttpStatus.OK);
return new ResponseEntity<String>("streamId not found", HttpStatus.OK);
storager.stopPlay(streamInfo);
if (logger.isDebugEnabled()) {
logger.debug(String.format("设备预览停止API调用ssrc%s", ssrc));
logger.debug(String.format("设备预览停止API调用streamId%s", streamId));
}
if (ssrc != null) {
if (streamId != null) {
JSONObject json = new JSONObject();
json.put("ssrc", ssrc);
json.put("streamId", streamId);
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
} else {
logger.warn("设备预览停止API调用失败");
@@ -123,17 +123,16 @@ public class PlayController {
/**
* 将不是h264的视频通过ffmpeg 转码为h264 + aac
* @param ssrc
* @param streamId 流ID
* @return
*/
@PostMapping("/play/{ssrc}/convert")
public ResponseEntity<String> playConvert(@PathVariable String ssrc) {
StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc);
@PostMapping("/play/{streamId}/convert")
public ResponseEntity<String> playConvert(@PathVariable String streamId) {
StreamInfo streamInfo = storager.queryPlayByStreamId(streamId);
if (streamInfo == null) {
logger.warn("视频转码API调用失败, 视频流已经停止!");
return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK);
}
String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
if (!rtpInfo.getBoolean("exist")) {
logger.warn("视频转码API调用失败, 视频流已停止推流!");

View File

@@ -72,7 +72,7 @@ public class PlaybackController {
StreamInfo streamInfo = storager.queryPlaybackByDevice(deviceId, channelId);
if (streamInfo != null) {
// 停止之前的回放
cmder.streamByeCmd(streamInfo.getSsrc());
cmder.streamByeCmd(streamInfo.getStreamId());
}
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid, result);
cmder.playbackStreamCmd(device, channelId, startTime, endTime, (JSONObject response) -> {

View File

@@ -61,9 +61,7 @@ public class PlayServiceImpl implements IPlayService {
public StreamInfo onPublishHandler(JSONObject resonse, String deviceId, String channelId, String uuid) {
String streamId = resonse.getString("id");
String ssrc = new DecimalFormat("0000000000").format(Integer.parseInt(streamId, 16));
StreamInfo streamInfo = new StreamInfo();
streamInfo.setSsrc(ssrc);
streamInfo.setStreamId(streamId);
streamInfo.setDeviceID(deviceId);
streamInfo.setCahnnelId(channelId);