|
@@ -276,95 +276,6 @@ public class PlayController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "语音广播命令")
|
|
|
- @Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
|
|
- @Parameter(name = "app", description = "推流app", required = true)
|
|
|
- @Parameter(name = "stream", description = "音频推流编号", required = true)
|
|
|
- @GetMapping("/broadcastOld")
|
|
|
-// @PostMapping("/broadcast/{deviceId}")
|
|
|
- public DeferredResult<WVPResult<String>> broadcastApi(
|
|
|
- HttpServletRequest request,
|
|
|
- @RequestParam String deviceId,
|
|
|
- @RequestParam String app,
|
|
|
- @RequestParam String stream) {
|
|
|
- logger.info("[语音广播] 开始语音广播交互流程");
|
|
|
-
|
|
|
- // 添加计时器,待事件结束则自动触发超时回复
|
|
|
- RequestMessage msg = new RequestMessage();
|
|
|
- String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
|
|
- boolean exist = resultHolder.exist(key, null);
|
|
|
- msg.setKey(key);
|
|
|
- String uuid = UUID.randomUUID().toString();
|
|
|
- msg.setId(uuid);
|
|
|
- DeferredResult<WVPResult<String>> result = new DeferredResult<>(13*1000l);
|
|
|
- DeferredResultEx<WVPResult<String>> deferredResultEx = new DeferredResultEx<>(result);
|
|
|
- HookSubscribeForKey broadcastForInviteHook = GBHookSubscribeFactory.on_broadcast_invite(deviceId);
|
|
|
-
|
|
|
- // 判断流是否存在
|
|
|
- StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
|
|
- if (streamAuthorityInfo == null) {
|
|
|
- logger.error("webrtc推流未找到");
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERR_NOTFOUND_STREAM.getCode());
|
|
|
- wvpResult.setMsg("[广播失败] 无法获取webrtc流信息");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- });
|
|
|
- resultHolder.put(key, uuid, result);
|
|
|
- Device device = storager.queryVideoDevice(deviceId);
|
|
|
- MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
|
|
- logger.info("[语言广播] 分配的流媒体服务器为 {}",newMediaServerItem.getId());
|
|
|
- if (newMediaServerItem == null) {
|
|
|
- logger.warn("[语音广播] 无法连接至ZLM服务器");
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg("无法连接至流媒体服务器");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }else{
|
|
|
- playService.openBroadcast(
|
|
|
- newMediaServerItem,
|
|
|
- deviceId,
|
|
|
- app,
|
|
|
- stream,
|
|
|
- broadcastForInviteHook,
|
|
|
- (int code,String tipMsg)->{
|
|
|
- if(code == 1){
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg(tipMsg);
|
|
|
- msg.setData(wvpResult);
|
|
|
- // 回复之前所有的点播请求
|
|
|
- logger.info("语音广播失败,取消invite等待");
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- } else if (code == 0) {
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
- wvpResult.setMsg("okokokokooo");
|
|
|
-// wvpResult.setData(ssrcInfo);
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }
|
|
|
- }, null);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 开始语音广播
|
|
|
* @param deviceId
|
|
@@ -380,7 +291,8 @@ public class PlayController {
|
|
|
@RequestParam("channelId") String channelId,
|
|
|
@RequestParam(value = "waitTime",
|
|
|
required = false,
|
|
|
- defaultValue = "5000") int waitTimeStr ) {
|
|
|
+ defaultValue = "5000") int waitTimeStr )
|
|
|
+ {
|
|
|
|
|
|
WVPResult wvpResult = new WVPResult();
|
|
|
|
|
@@ -499,112 +411,111 @@ public class PlayController {
|
|
|
@RequestParam(value = "stream") String stream
|
|
|
){
|
|
|
logger.info("[语音对讲] web端已经开启推流");
|
|
|
- RequestMessage msg = new RequestMessage();
|
|
|
- // 返回invite信息给设备
|
|
|
- String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST_INVITE + deviceId;
|
|
|
- msg.setKey(key);
|
|
|
- String uuid = UUID.randomUUID().toString();
|
|
|
- msg.setId(uuid);
|
|
|
- DeferredResult<WVPResult<String>> result = new DeferredResult<>(10*1000l);
|
|
|
- WVPResult wvpResult = new WVPResult();
|
|
|
- Map<String, Object> resultData = new HashMap<>(16);
|
|
|
- resultHolder.put(key, uuid, result);
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ // 返回invite信息给设备
|
|
|
+ String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST_INVITE + deviceId;
|
|
|
+ msg.setKey(key);
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ msg.setId(uuid);
|
|
|
+ DeferredResult<WVPResult<String>> result = new DeferredResult<>((long) waitTime + 1000L);
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ Map<String, Object> resultData = new HashMap<>(16);
|
|
|
+ resultHolder.put(key, uuid, result);
|
|
|
|
|
|
- // 检查设备是否存在
|
|
|
- Device device = storager.queryVideoDevice(deviceId);
|
|
|
- if (device == null){
|
|
|
- // 无法找到设备
|
|
|
- wvpResult.setCode(ErrorCode.ERROR404.getCode());
|
|
|
- wvpResult.setMsg("无法找到设备");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }
|
|
|
+ // 检查设备是否存在
|
|
|
+ Device device = storager.queryVideoDevice(deviceId);
|
|
|
+ if (device == null) {
|
|
|
+ // 无法找到设备
|
|
|
+ wvpResult.setCode(ErrorCode.ERROR404.getCode());
|
|
|
+ wvpResult.setMsg("无法找到设备");
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }
|
|
|
|
|
|
- // 获取对应的媒体服务
|
|
|
- MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device);
|
|
|
- logger.info("[语言广播] 分配的流媒体服务器为 {}",mediaServerItem.getId());
|
|
|
- if (mediaServerItem == null) {
|
|
|
- logger.warn("[语音广播] 无法连接至ZLM服务器");
|
|
|
- wvpResult.setCode(ErrorCode.ERR_NOTFOUND_STREAM.getCode());
|
|
|
- wvpResult.setMsg("无法连接至流媒体服务器");
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }else{
|
|
|
- playService.openBroadcast(
|
|
|
- mediaServerItem,
|
|
|
- device,
|
|
|
- waitTime,
|
|
|
- (int code, JSONObject json, SIPRequest request)->{
|
|
|
- // 0 ok,1 超时,2 异常
|
|
|
- // invite sdp , message data
|
|
|
- // request , null
|
|
|
- if(code == 1){
|
|
|
- logger.warn("invite超时");
|
|
|
- wvpResult.setCode(ErrorCode.ERR_TIMEOUT.getCode());
|
|
|
- wvpResult.setMsg(ErrorCode.ERR_TIMEOUT.getMsg());
|
|
|
- } else if (code == 2) {
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg((String) json.get("msg"));
|
|
|
- } else if (code == 0) {
|
|
|
- logger.info("收到设备invite信息: {}",json);
|
|
|
-
|
|
|
- BroadcastItem broadcastItem = new BroadcastItem();
|
|
|
- broadcastItem.setMediaId(mediaServerItem.getId());
|
|
|
- broadcastItem.setDeviceId(deviceId);
|
|
|
- broadcastItem.setApp(app);
|
|
|
- broadcastItem.setStream(stream);
|
|
|
- broadcastItem.setRecv_stream("recv_"+stream);
|
|
|
- broadcastItem.setIpcIp((String) json.get("addr"));
|
|
|
- broadcastItem.setIpcAudioPort((Integer) json.get("port"));
|
|
|
- broadcastItem.setSsrc((String) json.get("ssrc"));
|
|
|
- broadcastItem.setRequest(request);
|
|
|
- broadcastItem.setAudioFormats((Vector) json.get("audioFormats"));
|
|
|
- // 获取id
|
|
|
- playService.broadcast(
|
|
|
- mediaServerItem,
|
|
|
- device,
|
|
|
- broadcastItem,
|
|
|
- waitTime,
|
|
|
- (int _code, JSONObject _json, SIPRequest _request)->{
|
|
|
- // todo 处理并返回语音广播请求,应该有一个ack
|
|
|
- if(_code == 1){
|
|
|
- logger.warn("等待设备ack超时");
|
|
|
- wvpResult.setCode(ErrorCode.ERR_TIMEOUT.getCode());
|
|
|
- wvpResult.setMsg(ErrorCode.ERR_TIMEOUT.getMsg());
|
|
|
- } else if (_code == 2) {
|
|
|
- wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
- wvpResult.setMsg((String) _json.get("msg"));
|
|
|
- } else if (_code == 0) {
|
|
|
- logger.info("回复 invite 200 成功: {}",_json);
|
|
|
-
|
|
|
- // 获取id
|
|
|
- resultData.put("mediaId",mediaServerItem.getId());
|
|
|
- wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
- wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
|
|
- wvpResult.setData(resultData);
|
|
|
- }
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
- }
|
|
|
- );
|
|
|
- //存储invite信息和request信息至redis中
|
|
|
- gbStore.addBroadcastStore(
|
|
|
- "broadcast_"+deviceId,
|
|
|
- broadcastItem
|
|
|
- );
|
|
|
-
|
|
|
- }
|
|
|
- msg.setData(wvpResult);
|
|
|
- resultHolder.invokeAllResult(msg);
|
|
|
+ // 获取对应的媒体服务
|
|
|
+ MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device);
|
|
|
+ logger.info("[语言广播] 分配的流媒体服务器为 {}", mediaServerItem.getId());
|
|
|
+ if (mediaServerItem == null) {
|
|
|
+ logger.warn("[语音广播] 无法连接至ZLM服务器");
|
|
|
+ wvpResult.setCode(ErrorCode.ERR_NOTFOUND_STREAM.getCode());
|
|
|
+ wvpResult.setMsg("无法连接至流媒体服务器");
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ } else {
|
|
|
+ playService.openBroadcast(
|
|
|
+ mediaServerItem,
|
|
|
+ device,
|
|
|
+ waitTime,
|
|
|
+ (int code, JSONObject json, SIPRequest request) -> {
|
|
|
+ // 0 ok,1 超时,2 异常
|
|
|
+ // invite sdp , message data
|
|
|
+ // request , null
|
|
|
+ if (code == 1) {
|
|
|
+ logger.warn("invite超时");
|
|
|
+ wvpResult.setCode(ErrorCode.ERR_TIMEOUT.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.ERR_TIMEOUT.getMsg());
|
|
|
+ } else if (code == 2) {
|
|
|
+ wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
+ wvpResult.setMsg((String) json.get("msg"));
|
|
|
+ } else if (code == 0) {
|
|
|
+ logger.info("收到设备invite信息: {}", json);
|
|
|
+
|
|
|
+ BroadcastItem broadcastItem = new BroadcastItem();
|
|
|
+ broadcastItem.setMediaId(mediaServerItem.getId());
|
|
|
+ broadcastItem.setDeviceId(deviceId);
|
|
|
+ broadcastItem.setApp(app);
|
|
|
+ broadcastItem.setStream(stream);
|
|
|
+ broadcastItem.setRecv_stream("recv_" + stream);
|
|
|
+ broadcastItem.setIpcIp((String) json.get("addr"));
|
|
|
+ broadcastItem.setIpcAudioPort((Integer) json.get("port"));
|
|
|
+ broadcastItem.setSsrc((String) json.get("ssrc"));
|
|
|
+ broadcastItem.setRequest(request);
|
|
|
+ broadcastItem.setAudioFormats((Vector) json.get("audioFormats"));
|
|
|
+ // 获取id
|
|
|
+ playService.broadcast(
|
|
|
+ mediaServerItem,
|
|
|
+ device,
|
|
|
+ broadcastItem,
|
|
|
+ waitTime,
|
|
|
+ (int _code, JSONObject _json, SIPRequest _request) -> {
|
|
|
+ // todo 处理并返回语音广播请求,应该有一个ack
|
|
|
+ if (_code == 1) {
|
|
|
+ logger.warn("等待设备ack超时");
|
|
|
+ wvpResult.setCode(ErrorCode.ERR_TIMEOUT.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.ERR_TIMEOUT.getMsg());
|
|
|
+ } else if (_code == 2) {
|
|
|
+ wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
|
|
+ wvpResult.setMsg((String) _json.get("msg"));
|
|
|
+ } else if (_code == 0) {
|
|
|
+ logger.info("回复 invite 200 成功: {}", _json);
|
|
|
+
|
|
|
+ // 获取id
|
|
|
+ resultData.put("mediaId", mediaServerItem.getId());
|
|
|
+ wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
|
|
+ wvpResult.setData(resultData);
|
|
|
+ }
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ //存储invite信息和request信息至redis中
|
|
|
+ gbStore.addBroadcastStore(
|
|
|
+ "broadcast_" + deviceId,
|
|
|
+ broadcastItem
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
// return result;
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- }
|
|
|
- // 获取zlm推流端口
|
|
|
- // todo 回复 invite 200 给设备
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
- return result;
|
|
|
+ }
|
|
|
+ // 获取zlm推流端口
|
|
|
+ // todo 回复 invite 200 给设备
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "停止语音广播")
|
|
@@ -612,8 +523,7 @@ public class PlayController {
|
|
|
@Parameter(name = "channelId", description = "设备通道编号", required = true)
|
|
|
@GetMapping("/stopBroadcast")
|
|
|
public WVPResult stopBroadcast(@RequestParam("deviceId") String deviceId,@RequestParam("channelId") String channelId){
|
|
|
-//
|
|
|
-//
|
|
|
+
|
|
|
WVPResult wvpResult = new WVPResult();
|
|
|
// Device device = storager.queryVideoDevice(deviceId);
|
|
|
// 停止音频流,给设备发送bye
|