|
@@ -6,6 +6,8 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
|
|
import com.genersoft.iot.vmp.conf.UserSetting;
|
|
|
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
|
|
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
|
|
+import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
|
|
+import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
|
|
import com.genersoft.iot.vmp.gb28181.GBEventSubscribe;
|
|
|
import com.genersoft.iot.vmp.gb28181.GBHookSubscribeFactory;
|
|
|
import com.genersoft.iot.vmp.gb28181.HookSubscribeForKey;
|
|
@@ -17,11 +19,14 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
|
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
|
|
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
|
|
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
|
|
+import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
|
|
import com.genersoft.iot.vmp.service.IMediaServerService;
|
|
|
import com.genersoft.iot.vmp.service.IMediaService;
|
|
|
import com.genersoft.iot.vmp.service.IPlayService;
|
|
|
+import com.genersoft.iot.vmp.service.IUserService;
|
|
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
|
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
|
|
+import com.genersoft.iot.vmp.utils.Md5Utils;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.DeferredResultEx;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
|
@@ -39,7 +44,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.sip.InvalidArgumentException;
|
|
|
import javax.sip.SipException;
|
|
|
import java.text.ParseException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
@Tag(name = "国标设备点播")
|
|
@@ -83,6 +90,9 @@ public class PlayController {
|
|
|
@Autowired
|
|
|
private GBEventSubscribe GBHookSubscribe;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
@Operation(summary = "开始点播")
|
|
|
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
|
|
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
|
@@ -255,15 +265,17 @@ 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("/broadcast")
|
|
|
// @PostMapping("/broadcast/{deviceId}")
|
|
|
public DeferredResult<WVPResult<String>> broadcastApi(
|
|
|
HttpServletRequest request,
|
|
|
- @RequestParam String deviceId,@RequestParam String stream) {
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("语音广播API调用");
|
|
|
- }
|
|
|
+ @RequestParam String deviceId,
|
|
|
+ @RequestParam String app,
|
|
|
+ @RequestParam String stream) {
|
|
|
+ logger.info("[语音广播] 开始语音广播交互流程");
|
|
|
+
|
|
|
// 添加计时器,待事件结束则自动触发超时回复
|
|
|
RequestMessage msg = new RequestMessage();
|
|
|
String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
|
@@ -275,6 +287,17 @@ public class PlayController {
|
|
|
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信息");
|
|
@@ -327,6 +350,52 @@ public class PlayController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取webrtc推流地址
|
|
|
+ * @param deviceId
|
|
|
+ * @param channelId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Operation(summary = "获取webrtc推流地址")
|
|
|
+ @Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
|
|
+ @Parameter(name = "channelId", description = "设备国标编号", required = true)
|
|
|
+ @GetMapping("/getWebRtcAddr")
|
|
|
+ public WVPResult getWebRtcAddr(@RequestParam String deviceId,
|
|
|
+ @RequestParam("channelId") String channelId) {
|
|
|
+
|
|
|
+ //首先判断设备是否正在对讲
|
|
|
+ if (redisCatchStorage.isBroadcastItem(deviceId)) {
|
|
|
+ // 设备正在进行语音对讲
|
|
|
+ return WVPResult.fail(ErrorCode.ERROR_Device_Busy);
|
|
|
+ }
|
|
|
+
|
|
|
+ Device device = storager.queryVideoDevice(deviceId);
|
|
|
+ MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device);
|
|
|
+
|
|
|
+ if (mediaServerItem == null) {
|
|
|
+ logger.error("流媒体未找到");
|
|
|
+ return WVPResult.fail(ErrorCode.ERR_MEDIA);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>(16);
|
|
|
+ String app = "audio";
|
|
|
+ String stream = "rtc_" + deviceId + "_" + channelId;
|
|
|
+ String type = "push";
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "获取所有的ssrc")
|
|
|
@GetMapping("/ssrc")
|
|
|
public JSONObject getSSRC() {
|