|
@@ -364,133 +364,24 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void openBroadcast(MediaServerItem mediaServerItem,String deviceId,String audioStreamId,ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
|
|
|
+ public void openBroadcast(MediaServerItem mediaServerItem,
|
|
|
+ String deviceId,
|
|
|
+ String audioStreamId,
|
|
|
+ HookSubscribeForKey broadcastForInviteHook,
|
|
|
+ NodeCallBack nodeCallBack,
|
|
|
Runnable timeoutCallback){
|
|
|
logger.warn("[语音广播] 开语音广播");
|
|
|
// PlayResult playResult = new PlayResult();
|
|
|
- RequestMessage msg = new RequestMessage();
|
|
|
- String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
|
|
- // 使用invite 来进行延迟
|
|
|
- msg.setKey(key);
|
|
|
- String uuid = UUID.randomUUID().toString();
|
|
|
- msg.setId(uuid);
|
|
|
-// playResult.setUuid(uuid);
|
|
|
- DeferredResult<WVPResult<String>> result = new DeferredResult<>(13*1000l);
|
|
|
-// playResult.setResult(result);
|
|
|
- resultHolder.put(key, uuid, result);
|
|
|
- // 检查zlm
|
|
|
- if (mediaServerItem == null) {
|
|
|
- logger.warn("[语音广播] 无法连接至ZLM服务器");
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg("无法连接至流媒体服务器");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- // 此段为录像查询...
|
|
|
Device device = redisCatchStorage.getDevice(deviceId);
|
|
|
-// StreamInfo streamInfo = redisCatchStorage.queryRecordByDevice(deviceId);
|
|
|
-// playResult.setDevice(device);
|
|
|
-
|
|
|
-
|
|
|
- HookSubscribeForKey broadcastForInviteHook = GBHookSubscribeFactory.on_broadcast_invite(deviceId);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 检查无法连接zlm的情况
|
|
|
-// if (streamInfo != null && false) {
|
|
|
-// GBHookSubscribe.removeSubscribe(broadcastForInviteHook);
|
|
|
-// String streamId = streamInfo.getStream();
|
|
|
-// if (streamId == null){
|
|
|
-// logger.warn("[语音广播] zlm 缓存的 streamId等于null");
|
|
|
-// WVPResult wvpResult = new WVPResult();
|
|
|
-// wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
-// wvpResult.setMsg("zlm 缓存的 streamId等于null");
|
|
|
-// msg.setData(wvpResult);
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// return ;
|
|
|
-// }
|
|
|
-// String mediaServerId = streamInfo.getMediaServerId();
|
|
|
-// MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
|
|
-// JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
|
|
-// if(rtpInfo.getInteger("code") == 0){
|
|
|
-// if (rtpInfo.getBoolean("exist")) {
|
|
|
-// int localPort = rtpInfo.getInteger("local_port");
|
|
|
-// if (localPort == 0) {
|
|
|
-// logger.warn("[语音广播],点播时发现rtpServerC存在,但是尚未开始推流");
|
|
|
-// // 此时说明rtpServer已经创建但是流还没有推上来
|
|
|
-// WVPResult wvpResult = new WVPResult();
|
|
|
-// wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
-// wvpResult.setMsg("语音广播已经开始");
|
|
|
-// msg.setData(wvpResult);
|
|
|
-//
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// return ;
|
|
|
-// }else{
|
|
|
-// // 语音点播已经开始,返回推流信息给前端
|
|
|
-// WVPResult wvpResult = new WVPResult();
|
|
|
-// wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
-// wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
|
|
-// wvpResult.setData(streamInfo);
|
|
|
-// msg.setData(wvpResult);
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// if (hookEvent != null) {
|
|
|
-// hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo)));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// logger.warn("[语音广播] 停止语音广播推流转发端口");
|
|
|
-// redisCatchStorage.stopBroadcast(streamInfo);
|
|
|
-// storager.stopBroadcast(streamInfo.getDeviceID());
|
|
|
-// streamInfo = null;
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// logger.warn("[语音广播] 无法连接至zlm服务器");
|
|
|
-// redisCatchStorage.stopPlay(streamInfo);
|
|
|
-// storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
|
|
-// streamInfo = null;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- result.onTimeout(()->{
|
|
|
- logger.warn("[广播超时] 与设备交互broadcast流程超时,未收到设备invite信息");
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg("[广播超时] 与设备交互broadcast流程超时,未收到设备invite信息");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- // 超时移除
|
|
|
- GBHookSubscribe.removeSubscribe(broadcastForInviteHook);
|
|
|
- });
|
|
|
-
|
|
|
- result.onCompletion(()->{
|
|
|
- // 通道结束
|
|
|
- logger.info("[语音广播] broadcast流程结束....");
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- // rtp语音通道创建完成,开始发送broadcast
|
|
|
- broadcastEventHandle(
|
|
|
- device,
|
|
|
- audioStreamId,
|
|
|
- (int code,String tipMsg)->{
|
|
|
- if(code == 1){
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg(tipMsg);
|
|
|
- msg.setData(wvpResult);
|
|
|
- // 回复之前所有的点播请求
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- // 开始创建 rtp/tcp 推流通道
|
|
|
-
|
|
|
|
|
|
+ // rtp语音通道创建完成,开始发送broadcast,
|
|
|
+ try {
|
|
|
+ cmder.audioBroadcastCmd(device, audioStreamId);
|
|
|
+ }catch (InvalidArgumentException | SipException | ParseException e) {
|
|
|
+ logger.error("[命令发送失败] 发送broadcast中 errorMsg: {}", e.getMessage());
|
|
|
+ nodeCallBack.run(1,"[命令发送失败] 无法发送broadcast消息");
|
|
|
+ }
|
|
|
// 注册subScript事件
|
|
|
GBHookSubscribe.addInviteSubscribe(broadcastForInviteHook,(int code, JSONObject json, SIPRequest request)->{
|
|
|
logger.info("[语音广播] 接收到设备invite信息___订阅事件触发 JSONDATA: {}",json.toJSONString());
|
|
@@ -502,46 +393,23 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
streamId = String.format("broadcast_%s", device.getDeviceId());
|
|
|
}
|
|
|
logger.info("[语音广播] 尝试创建rtp语音推流通道");
|
|
|
-// ssrcInfo = mediaServerService.startSendRtpServer(mediaServerItem, streamId, audioStreamId,
|
|
|
-// json.getString("addr"),
|
|
|
-// json.getString("port"),
|
|
|
-// json.getString("ssrc")
|
|
|
-// );
|
|
|
-// logger.info(JSONObject.toJSONString(ssrcInfo));
|
|
|
-// TimeDescriptionImpl timeDescription = (TimeDescriptionImpl) (sdp.getTimeDescriptions(false).get(0));
|
|
|
-// TimeField startTimeFiled = (TimeField) timeDescription.getTime();
|
|
|
-// startTime = startTimeFiled.getStartTime();
|
|
|
-// stopTime = startTimeFiled.getStopTime();
|
|
|
-//
|
|
|
-// start = Instant.ofEpochSecond(startTime);
|
|
|
-// end = Instant.ofEpochSecond(stopTime);
|
|
|
|
|
|
// TODO: 2023/3/7 开始下发invite信息给设备
|
|
|
try {
|
|
|
-// String sdpContent = cmder.createBroadcastInviteSdp(mediaServerItem, ssrcInfo);
|
|
|
-// String _ssrc = ssrcInfo.getSsrc();
|
|
|
-
|
|
|
-
|
|
|
- cmder.sendBoradcastInviteCmd(request,mediaServerItem, ssrcInfo, device, null, null,
|
|
|
- null,
|
|
|
- (_event) -> {
|
|
|
- },
|
|
|
- (_errorEvent) -> {
|
|
|
-
|
|
|
- });
|
|
|
+ // 向流媒体服务器申请创建 rtpServer 服务端口
|
|
|
ssrcInfo = mediaServerService.startSendRtpServer(mediaServerItem, streamId, audioStreamId,
|
|
|
json.getString("addr"),
|
|
|
json.getString("port"),
|
|
|
ssrcStr
|
|
|
);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
- wvpResult.setMsg("okokokokooo");
|
|
|
- wvpResult.setData(ssrcInfo);
|
|
|
+ // 回复invite 200 信息至设备
|
|
|
+ cmder.sendBoradcastInviteCmd(request,mediaServerItem, ssrcInfo, device, null, null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null);
|
|
|
+ //
|
|
|
+ nodeCallBack.run(0,"ok");
|
|
|
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
}catch(InvalidArgumentException | SipException | ParseException e){
|
|
|
logger.error("[下发audio拉流invite失败]",e);
|
|
|
// SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new CmdSendFailEvent(null));
|
|
@@ -549,26 +417,9 @@ public class PlayServiceImpl implements IPlayService {
|
|
|
// errorEvent.response(eventResult);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
- public void broadcastEventHandle(
|
|
|
- Device device,
|
|
|
- String webrtcStreamId,
|
|
|
- NodeCallBack nodeCallBack){
|
|
|
- logger.info("[语音广播] 开始broadcast交互");
|
|
|
- try {
|
|
|
- cmder.audioBroadcastCmd(device,webrtcStreamId);
|
|
|
- nodeCallBack.run(0,"ok");
|
|
|
- } catch (InvalidArgumentException | SipException | ParseException e) {
|
|
|
- logger.error("[命令发送失败] 发送broadcast中 errorMsg: {}", e.getMessage());
|
|
|
- nodeCallBack.run(1,"[命令发送失败] 无法发送broadcast消息");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId) {
|
|
|
StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId);
|