|
@@ -31,6 +31,7 @@ import com.genersoft.iot.vmp.vmanager.bean.DeferredResultEx;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
|
+import gov.nist.javax.sip.message.SIPRequest;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
@@ -353,22 +354,47 @@ public class PlayController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取webrtc推流地址
|
|
|
+ * 开始语音广播,获取设备invite,音频编码协商 步骤1
|
|
|
* @param deviceId
|
|
|
* @param channelId
|
|
|
* @return
|
|
|
*/
|
|
|
- @Operation(summary = "获取webrtc推流地址")
|
|
|
+ @Operation(summary = "开始语音广播")
|
|
|
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
|
|
@Parameter(name = "channelId", description = "设备国标编号", required = true)
|
|
|
- @GetMapping("/getWebRtcAddr")
|
|
|
- public WVPResult getWebRtcAddr(@RequestParam String deviceId,
|
|
|
- @RequestParam("channelId") String channelId) {
|
|
|
+ @Parameter(name = "waitTime", description = "设备国标编号", required = false)
|
|
|
+ @GetMapping("/startBroadcast")
|
|
|
+ public DeferredResult<WVPResult<String>> getWebRtcAddr(@RequestParam String deviceId,
|
|
|
+ @RequestParam("channelId") String channelId,
|
|
|
+ @RequestParam(value = "waitTime",
|
|
|
+ required = false,
|
|
|
+ defaultValue = "5000") int waitTimeStr ) {
|
|
|
+
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
|
|
+ msg.setKey(key);
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ msg.setId(uuid);
|
|
|
+ DeferredResult<WVPResult<String>> result = new DeferredResult<>(10*1000l);
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ resultHolder.put(key, uuid, result);
|
|
|
+
|
|
|
+ String app = "audio";
|
|
|
+ String stream = "rtc_" + deviceId + "_" + channelId;
|
|
|
+ String type = "push";
|
|
|
+// if(waitTimeStr.isEmpty() || waitTimeStr==""){
|
|
|
+// waitTimeStr = "5000";
|
|
|
+// }
|
|
|
+ int waitTime = waitTimeStr;
|
|
|
|
|
|
//首先判断设备是否正在对讲
|
|
|
if (redisCatchStorage.isBroadcastItem(deviceId)) {
|
|
|
// 设备正在进行语音对讲
|
|
|
- return WVPResult.fail(ErrorCode.ERROR_Device_Busy);
|
|
|
+ wvpResult.setCode(ErrorCode.ERROR_Device_Busy.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.ERROR_Device_Busy.getMsg());
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
Device device = storager.queryVideoDevice(deviceId);
|
|
@@ -376,26 +402,56 @@ public class PlayController {
|
|
|
|
|
|
if (mediaServerItem == null) {
|
|
|
logger.error("流媒体未找到");
|
|
|
- return WVPResult.fail(ErrorCode.ERR_MEDIA);
|
|
|
+ wvpResult.setCode(ErrorCode.ERR_MEDIA.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.ERR_MEDIA.getMsg());
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ return result;
|
|
|
}
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>(16);
|
|
|
- String app = "audio";
|
|
|
- String stream = "rtc_" + deviceId + "_" + channelId;
|
|
|
- String type = "push";
|
|
|
+ Map<String, Object> resultData = new HashMap<>(16);
|
|
|
LoginUser userInfo = SecurityUtils.getUserInfo();
|
|
|
String sign = Md5Utils.hash(userService.getUserByUsername(userInfo.getUsername()).getPushKey()); //获取推流鉴权密钥
|
|
|
//示例 https://192.168.126.111:9443/index/api/webrtc?app=live&stream=test&type=play&sign=...
|
|
|
String webRtcPushUrl = String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=%s&sign=%s", mediaServerItem.getIp(), mediaServerItem.getHttpSSlPort(), app, stream, type,sign);
|
|
|
- // 获取id
|
|
|
- result.put("mediaId",mediaServerItem.getId());
|
|
|
- result.put("app",app);
|
|
|
- result.put("stream",stream);
|
|
|
- result.put("type",type);
|
|
|
- result.put("sign",sign);
|
|
|
- result.put("webRtcPushUrl", webRtcPushUrl);
|
|
|
- logger.info("获取webrtc推流地址:{}",webRtcPushUrl);
|
|
|
- return WVPResult.success(result);
|
|
|
+ // 下发broadcast给设备
|
|
|
+ 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);
|
|
|
+ // todo 存储invite信息和request信息至redis中
|
|
|
+ // 获取id
|
|
|
+ resultData.put("mediaId",mediaServerItem.getId());
|
|
|
+ resultData.put("app",app);
|
|
|
+ resultData.put("stream",stream);
|
|
|
+ resultData.put("type",type);
|
|
|
+ resultData.put("sign",sign);
|
|
|
+ resultData.put("webRtcPushUrl", webRtcPushUrl);
|
|
|
+ logger.info("获取webrtc推流地址:{}",webRtcPushUrl);
|
|
|
+ wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
+ wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
|
|
+ wvpResult.setData(resultData);
|
|
|
+ }
|
|
|
+ logger.warn("结束");
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ logger.warn("结束2");
|
|
|
+// return result;
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "获取所有的ssrc")
|