添加对海康平台录像回放的兼容,修复录像信息发送失败, 级联平台支持开启rtcp保活
This commit is contained in:
@@ -531,6 +531,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrex));
|
||||
param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrex));
|
||||
param.put("hook.on_server_keepalive",String.format("%s/on_server_keepalive", hookPrex));
|
||||
param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrex));
|
||||
if (mediaServerItem.getRecordAssistPort() > 0) {
|
||||
param.put("hook.on_record_mp4",String.format("http://127.0.0.1:%s/api/record/on_record_mp4", mediaServerItem.getRecordAssistPort()));
|
||||
}else {
|
||||
|
||||
@@ -73,7 +73,6 @@ public class MediaServiceImpl implements IMediaService {
|
||||
}else {
|
||||
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return streamInfo;
|
||||
|
||||
@@ -291,7 +291,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
logger.info("[点播消息] 收到invite 200, 发现下级自定义了ssrc: {}", ssrcInResponse );
|
||||
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
|
||||
logger.info("[SIP 消息] SSRC修正 {}->{}", ssrc, ssrcInResponse);
|
||||
logger.info("[点播消息] SSRC修正 {}->{}", ssrc, ssrcInResponse);
|
||||
|
||||
if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) {
|
||||
// ssrc 不可用
|
||||
@@ -441,37 +441,92 @@ public class PlayServiceImpl implements IPlayService {
|
||||
resultHolder.exist(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid);
|
||||
}, userSetting.getPlayTimeout());
|
||||
|
||||
SipSubscribe.Event errorEvent = event -> {
|
||||
dynamicTask.stop(playBackTimeOutTaskKey);
|
||||
requestMessage.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)));
|
||||
playBackResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
playBackResult.setMsg(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
playBackResult.setData(requestMessage);
|
||||
playBackResult.setEvent(event);
|
||||
playBackCallback.call(playBackResult);
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
||||
};
|
||||
|
||||
InviteStreamCallback hookEvent = (InviteStreamInfo inviteStreamInfo) -> {
|
||||
logger.info("收到回放订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
|
||||
dynamicTask.stop(playBackTimeOutTaskKey);
|
||||
StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
|
||||
if (streamInfo == null) {
|
||||
logger.warn("设备回放API调用失败!");
|
||||
playBackResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
playBackResult.setMsg("设备回放API调用失败!");
|
||||
playBackCallback.call(playBackResult);
|
||||
return;
|
||||
}
|
||||
redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
|
||||
WVPResult<StreamInfo> success = WVPResult.success(streamInfo);
|
||||
requestMessage.setData(success);
|
||||
playBackResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
playBackResult.setData(requestMessage);
|
||||
playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
|
||||
playBackResult.setResponse(inviteStreamInfo.getResponse());
|
||||
playBackCallback.call(playBackResult);
|
||||
};
|
||||
|
||||
cmder.playbackStreamCmd(mediaServerItem, ssrcInfo, device, channelId, startTime, endTime, infoCallBack,
|
||||
(InviteStreamInfo inviteStreamInfo) -> {
|
||||
logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
|
||||
dynamicTask.stop(playBackTimeOutTaskKey);
|
||||
StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
|
||||
if (streamInfo == null) {
|
||||
logger.warn("设备回放API调用失败!");
|
||||
playBackResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
playBackResult.setMsg("设备回放API调用失败!");
|
||||
playBackCallback.call(playBackResult);
|
||||
return;
|
||||
hookEvent, eventResult -> {
|
||||
if (eventResult.type == SipSubscribe.EventResultType.response) {
|
||||
ResponseEvent responseEvent = (ResponseEvent)eventResult.event;
|
||||
String contentString = new String(responseEvent.getResponse().getRawContent());
|
||||
// 获取ssrc
|
||||
int ssrcIndex = contentString.indexOf("y=");
|
||||
// 检查是否有y字段
|
||||
if (ssrcIndex >= 0) {
|
||||
//ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段 TODO 后续对不规范的非10位ssrc兼容
|
||||
String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
|
||||
// 查询到ssrc不一致且开启了ssrc校验则需要针对处理
|
||||
if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
|
||||
return;
|
||||
}
|
||||
logger.info("[回放消息] 收到invite 200, 发现下级自定义了ssrc: {}", ssrcInResponse );
|
||||
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
|
||||
logger.info("[回放消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
|
||||
|
||||
if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) {
|
||||
// ssrc 不可用
|
||||
// 释放ssrc
|
||||
mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
||||
eventResult.msg = "下级自定义了ssrc,但是此ssrc不可用";
|
||||
eventResult.statusCode = 400;
|
||||
errorEvent.response(eventResult);
|
||||
return;
|
||||
}
|
||||
|
||||
// 单端口模式streamId也有变化,需要重新设置监听
|
||||
if (!mediaServerItem.isRtpEnable()) {
|
||||
// 添加订阅
|
||||
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
|
||||
subscribe.removeSubscribe(hookSubscribe);
|
||||
hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase());
|
||||
subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response)->{
|
||||
logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + response.toJSONString());
|
||||
dynamicTask.stop(playBackTimeOutTaskKey);
|
||||
// hook响应
|
||||
onPublishHandlerForPlay(mediaServerItemInUse, response, device.getDeviceId(), channelId, uuid);
|
||||
hookEvent.call(new InviteStreamInfo(mediaServerItem, null, eventResult.callId, "rtp", ssrcInfo.getStream()));
|
||||
});
|
||||
}
|
||||
// 关闭rtp server
|
||||
mediaServerService.closeRTPServer(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
||||
// 重新开启ssrc server
|
||||
mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), true, ssrcInfo.getPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
|
||||
WVPResult<StreamInfo> success = WVPResult.success(streamInfo);
|
||||
requestMessage.setData(success);
|
||||
playBackResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
playBackResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
playBackResult.setData(requestMessage);
|
||||
playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
|
||||
playBackResult.setResponse(inviteStreamInfo.getResponse());
|
||||
playBackCallback.call(playBackResult);
|
||||
}, event -> {
|
||||
dynamicTask.stop(playBackTimeOutTaskKey);
|
||||
requestMessage.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)));
|
||||
playBackResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
playBackResult.setMsg(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
playBackResult.setData(requestMessage);
|
||||
playBackResult.setEvent(event);
|
||||
playBackCallback.call(playBackResult);
|
||||
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
||||
});
|
||||
|
||||
}, errorEvent);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user