| | |
| | | import com.genersoft.iot.vmp.service.*;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
| | | import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | }
|
| | | }else if ("broadcast".equals(param.getApp())){
|
| | | // 语音对讲推流 stream需要满足格式deviceId_channelId
|
| | | if (param.isRegist() && param.getStream().indexOf("_") > 0) {
|
| | | if (param.getStream().indexOf("_") > 0) {
|
| | | String[] streamArray = param.getStream().split("_");
|
| | | if (streamArray.length == 2) {
|
| | | String deviceId = streamArray[0];
|
| | | String channelId = streamArray[1];
|
| | | Device device = deviceService.getDevice(deviceId);
|
| | | if (device != null) {
|
| | | DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
|
| | | if (deviceChannel != null) {
|
| | | if (param.isRegist()) {
|
| | | if (audioBroadcastManager.exit(deviceId, channelId)) {
|
| | | // 直接推流
|
| | | SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, null, param.getStream(), null);
|
| | | if (sendRtpItem == null) {
|
| | | // TODO 可能数据错误,重新开启语音通道
|
| | | }else {
|
| | | String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
| | | MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
| | | logger.info("rtp/{}开始向上级推流, 目标={}:{},SSRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
| | | Map<String, Object> sendParam = new HashMap<>(12);
|
| | | sendParam.put("vhost","__defaultVhost__");
|
| | | sendParam.put("app",sendRtpItem.getApp());
|
| | | sendParam.put("stream",sendRtpItem.getStreamId());
|
| | | sendParam.put("ssrc", sendRtpItem.getSsrc());
|
| | | sendParam.put("src_port", sendRtpItem.getLocalPort());
|
| | | sendParam.put("pt", sendRtpItem.getPt());
|
| | | sendParam.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
|
| | | sendParam.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
|
| | |
|
| | | JSONObject jsonObject;
|
| | | if (sendRtpItem.isTcpActive()) {
|
| | | jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, sendParam);
|
| | | } else {
|
| | | sendParam.put("is_udp", is_Udp);
|
| | | sendParam.put("dst_url", sendRtpItem.getIp());
|
| | | sendParam.put("dst_port", sendRtpItem.getPort());
|
| | | jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, sendParam);
|
| | | }
|
| | | if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
| | | logger.info("[语音对讲] 自动推流成功, device: {}, channel: {}", deviceId, channelId);
|
| | | }else {
|
| | | logger.info("[语音对讲] 推流失败, 结果: {}", jsonObject);
|
| | | }
|
| | |
|
| | | }
|
| | | }else {
|
| | | // 开启语音对讲通道
|
| | | try {
|
| | | playService.audioBroadcastCmd(device, channelId, 60, (msg)->{
|
| | | logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId);
|
| | | });
|
| | | } catch (InvalidArgumentException | ParseException | SipException e) {
|
| | | logger.error("[命令发送失败] 语音对讲: {}", e.getMessage());
|
| | | }
|
| | | playService.stopAudioBroadcast(deviceId, channelId);
|
| | | }
|
| | |
|
| | | // 开启语音对讲通道
|
| | | try {
|
| | | playService.audioBroadcastCmd(device, channelId, 60, (msg)->{
|
| | | logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId);
|
| | | });
|
| | | } catch (InvalidArgumentException | ParseException | SipException e) {
|
| | | logger.error("[命令发送失败] 语音对讲: {}", e.getMessage());
|
| | | }
|
| | | }else {
|
| | | logger.info("[语音对讲] 未找到通道:{}", channelId);
|
| | | // 流注销
|
| | | playService.stopAudioBroadcast(deviceId, channelId);
|
| | | }
|
| | | }else{
|
| | | } else{
|
| | | logger.info("[语音对讲] 未找到设备:{}", deviceId);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }else if ("talk".equals(param.getApp())){
|
| | | // 语音对讲推流 stream需要满足格式deviceId_channelId
|
| | | if (param.isRegist() && param.getStream().indexOf("_") > 0) {
|
| | |
| | | }
|
| | | StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
|
| | | param.getApp(), param.getStream(), param.getTracks(), callId);
|
| | | param.setStreamInfo(streamInfoByAppAndStream);
|
| | | param.setStreamInfo(new StreamContent(streamInfoByAppAndStream));
|
| | | redisCatchStorage.addStream(mediaServerItem, type, param.getApp(), param.getStream(), param);
|
| | | if (param.getOriginType() == OriginType.RTSP_PUSH.ordinal()
|
| | | || param.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|
| | |
| | | }
|
| | | GbStream gbStream = storager.getGbStream(param.getApp(), param.getStream());
|
| | | if (gbStream != null) {
|
| | | // eventPublisher.catalogEventPublishForStream(null, gbStream, CatalogEvent.OFF);
|
| | | // eventPublisher.catalogEventPublishForStream(null, gbStream, CatalogEvent.OFF);
|
| | | }
|
| | | zlmMediaListManager.removeMedia(param.getApp(), param.getStream());
|
| | | }
|
| | |
| | | logger.info("[ZLM HOOK]流无人观看:{]->{}->{}/{}" + param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
| | | JSONObject ret = new JSONObject();
|
| | | ret.put("code", 0);
|
| | | // 录像下载
|
| | | // 国标类型的流
|
| | | if ("rtp".equals(param.getApp())){
|
| | | ret.put("close", userSetting.getStreamOnDemand());
|
| | | // 国标流, 点播/录像回放/录像下载
|
| | |
| | | @ResponseBody
|
| | | @PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
|
| | | public JSONObject onStreamNotFound(@RequestBody OnStreamNotFoundHookParam param){
|
| | | logger.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}" + param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
| | | logger.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
| | | taskExecutor.execute(()->{
|
| | | MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
|
| | | if (userSetting.isAutoApplyPlay() && mediaInfo != null) {
|
| | |
| | | @PostMapping(value = "/on_send_rtp_stopped", produces = "application/json;charset=UTF-8")
|
| | | public JSONObject onSendRtpStopped(HttpServletRequest request, @RequestBody OnSendRtpStoppedHookParam param){
|
| | |
|
| | | logger.info("[ZLM HOOK] 发送rtp被动关闭:{}->{}/{}", param.getMediaServerId(), param.getApp(), param.getStream());
|
| | | logger.info("[ZLM HOOK] rtp发送关闭:{}->{}/{}", param.getMediaServerId(), param.getApp(), param.getStream());
|
| | |
|
| | | JSONObject ret = new JSONObject();
|
| | | ret.put("code", 0);
|