kindring 2 lat temu
rodzic
commit
ecd0a34b80

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java

@@ -532,6 +532,7 @@ public class SIPCommander implements ISIPCommander {
         content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
                 : udpSipProvider.getNewCallId();
+        logger.info("下发audio invite 为{}",content.toString());
         // todo 订阅audio推流流变化
         Request request = headerProvider.createPlaybackInviteRequest(device,null, content.toString(), null, SipUtils.getNewFromTag(), null, callIdHeader, ssrcInfo.getSsrc());
         transmitRequest(device.getTransport(), request, (e)->{

+ 14 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java

@@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.genersoft.iot.vmp.conf.DynamicTask;
 import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.gb28181.GBEventSubscribe;
+import com.genersoft.iot.vmp.gb28181.GB_Event;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
@@ -68,6 +70,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
     @Autowired
     private IStreamProxyService streamProxyService;
 
+    @Autowired
+    private GBEventSubscribe GBHookSubscribe;
     @Autowired
     private IRedisCatchStorage redisCatchStorage;
 
@@ -847,6 +851,16 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
             String addressStr = sdp.getOrigin().getAddress();
             logger.info("设备{}请求语音流,地址:{}:{},ssrc:{}", username, addressStr, port, ssrc);
             // todo 向zlm服务器申请语音推流转发通道
+            JSONObject subscribeKey = new JSONObject();
+            subscribeKey.put("deviceId", username);
+            subscribeKey.put("addr", addressStr);
+            subscribeKey.put("port", port);
+            subscribeKey.put("ssrc", ssrc);
+
+            GBEventSubscribe.Event subscribe = GBHookSubscribe.sendNotify(GB_Event.HOOK_BROADCAST_INVITE,subscribeKey);
+            if (subscribe != null ) {
+                subscribe.response(0, subscribeKey);
+            }
         } else {
             logger.warn("来自无效设备/平台的请求");
             responseAck(serverTransaction, Response.BAD_REQUEST);

+ 2 - 8
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java

@@ -54,7 +54,6 @@ public class BroadcastResponseMessageHandler extends SIPRequestProcessorParent i
 
             logger.info("[sip received] broadcast response from {}",device.getDeviceId());
             // invite 信息完成
-            String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST_INVITE + device.getDeviceId();
 
             ServerTransaction serverTransaction = getServerTransaction(evt);
             // 回复200 OK
@@ -62,17 +61,12 @@ public class BroadcastResponseMessageHandler extends SIPRequestProcessorParent i
             // 此处是对本平台发出Broadcast指令的应答
             JSONObject json = new JSONObject();
             XmlUtil.node2Json(rootElement, json);
+            logger.info("[handForDevice] json值为: {}",json.toJSONString());
             if (logger.isDebugEnabled()) {
                 logger.debug(json.toJSONString());
             }
 //            HookSubscribeForKey broadcastForInviteHook = GBHookSubscribeFactory.on_broadcast_invite(deviceId);
-            JSONObject subscribeKey = new JSONObject();
-            subscribeKey.put("deviceId", device.getDeviceId());
-//            subscribeKey.put("json", json.toJSONString());
-            GBEventSubscribe.Event subscribe = GBHookSubscribe.sendNotify(GB_Event.HOOK_BROADCAST_INVITE,subscribeKey);
-            if (subscribe != null ) {
-                subscribe.response(0, json);
-            }
+
         } catch (ParseException | SipException | InvalidArgumentException e) {
             logger.error("[命令发送失败] 国标级联 语音喊话: {}", e.getMessage());
         }

+ 15 - 4
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java

@@ -283,7 +283,7 @@ public class ZLMRTPServerFactory {
      * @param ssrc
      * @return
      */
-    public Map<String, Object> createStartSendRtpStreamAudioData(MediaServerItem serverItem,String streamId,String recv_stream_id,String ssrc){
+    public Map<String, Object> createStartSendRtpStreamAudioData(MediaServerItem serverItem,String streamId,String recv_stream_id,String ssrc,String dst_url,int dst_port){
         String sendRtpPortRange = serverItem.getSendRtpPortRange();
         if (ObjectUtils.isEmpty(sendRtpPortRange)) {
             return null;
@@ -299,7 +299,7 @@ public class ZLMRTPServerFactory {
             logger.error("没有可用的端口");
             return null;
         }
-
+        // startSendRtp CHECK_ARGS("vhost", "app", "stream", "ssrc", "dst_url", "dst_port", "is_udp");
         Map<String, Object> param = new HashMap<>();
         param.put("enable_tcp", 1);
         param.put("vhost", "__defaultVhost__");
@@ -309,9 +309,20 @@ public class ZLMRTPServerFactory {
         param.put("only_audio", 1);
         param.put("ssrc", ssrc);
         param.put("app", "broadcast");
-        param.put("stream", streamId);
-        param.put("recv_stream_id", recv_stream_id);
 
+
+        param.put("recv_stream_id",recv_stream_id );
+        param.put("stream", recv_stream_id);
+
+        param.put("from_mp4", 0);
+        param.put("is_udp", 0);
+        param.put("dst_url", dst_url);
+        param.put("dst_port", dst_port);
+
+//        param.put("stream", streamId);
+//        param.put("recv_stream_id", recv_stream_id);
+
+        logger.info("send json: {}",param.toString());
 //        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(param));
         return param;
     }

+ 1 - 1
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java

@@ -59,7 +59,7 @@ public interface IMediaServerService {
 //    SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId,boolean ssrcCheck, boolean isPlayback);
 //    SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId, String presetSsrc, boolean ssrcCheck, boolean isPlayback, Integer port);
 //    SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId, String ssrc, boolean ssrcCheck, boolean isPlayback);
-    SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId,String audioStreamId);
+    SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId,String audioStreamId,String addr,String port,String ssrc);
 
     void closeSendRtpServer(MediaServerItem mediaServerItem, String streamId);
 

+ 6 - 4
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java

@@ -174,7 +174,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
 
 
     @Override
-    public SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId,String audioStreamId) {
+    public SSRCInfo startSendRtpServer(MediaServerItem mediaServerItem, String streamId,String audioStreamId,
+                                       String addr,String port,String _ssrc) {
         if (mediaServerItem == null || mediaServerItem.getId() == null) {
             return null;
         }
@@ -194,8 +195,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
             }
             int rtpServerPort;
             // 创建
-            Map<String, Object> rtpParam = zlmrtpServerFactory.createStartSendRtpStreamAudioData(mediaServerItem, streamId,audioStreamId,ssrc );
-            JSONObject result = zlmrtpServerFactory.startSendRtpPassive(mediaServerItem,rtpParam);
+            Map<String, Object> rtpParam = zlmrtpServerFactory.createStartSendRtpStreamAudioData(mediaServerItem, streamId,audioStreamId,ssrc,addr, Integer.parseInt(port));
+//            JSONObject result = zlmrtpServerFactory.startSendRtpPassive(mediaServerItem,rtpParam);
+            JSONObject result = zlmrtpServerFactory.startSendRtpStream(mediaServerItem,rtpParam);
             logger.info("zlm start send {}",result.toJSONString());
             RedisUtil.set(key, mediaServerItem);
             rtpServerPort = (int) result.get("local_port");
@@ -609,7 +611,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
         if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
             param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
         }
-
+        param.put("rtc.externIP",mediaServerItem.getIp());
         JSONObject responseJSON = zlmresTfulUtils.setServerConfig(mediaServerItem, param);
 
         if (responseJSON != null && responseJSON.getInteger("code") == 0) {

+ 35 - 25
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java

@@ -427,7 +427,7 @@ public class PlayServiceImpl implements IPlayService {
 
 
         // 检查无法连接zlm的情况
-        if (streamInfo != null) {
+        if (streamInfo != null && false) {
             GBHookSubscribe.removeSubscribe(broadcastForInviteHook);
             String streamId = streamInfo.getStream();
             if (streamId == null){
@@ -480,26 +480,50 @@ public class PlayServiceImpl implements IPlayService {
                 streamInfo = null;
             }
         }
-        SSRCInfo ssrcInfo;
         if(streamInfo == null){
-            String streamId = null;
-            if (mediaServerItem.isRtpEnable()) {
-                streamId = String.format("broadcast_%s", device.getDeviceId());
-            }
+
+
+
+            // rtp语音通道创建完成,开始发送broadcast
+            broadcastEventHandle(device,
+                (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 推流通道
-            logger.info("[语音广播] 尝试创建rtp语音推流通道");
-            ssrcInfo = mediaServerService.startSendRtpServer(mediaServerItem, streamId, audioStreamId);
-            logger.info(JSONObject.toJSONString(ssrcInfo));
+
 
             // 注册subScript事件
             GBHookSubscribe.addSubscribe(broadcastForInviteHook,(int code,JSONObject json)->{
-                logger.info("[语音广播] 接收到设备invite信息___订阅事件触发");
+                logger.info("[语音广播] 接收到设备invite信息___订阅事件触发 JSONDATA: {}",json.toJSONString());
+                String streamId = null;
+                SSRCInfo ssrcInfo;
+                if (mediaServerItem.isRtpEnable()) {
+                    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));
+
+
                 resultHolder.invokeAllResult(msg);
                 WVPResult wvpResult = new WVPResult();
                 wvpResult.setCode(ErrorCode.SUCCESS.getCode());
                 wvpResult.setMsg("okokokokooo");
                 wvpResult.setData(ssrcInfo);
-                logger.debug(json.toJSONString());
+
                 msg.setData(wvpResult);
                 resultHolder.invokeAllResult(msg);
                 // TODO: 2023/3/7 开始下发invite信息给设备
@@ -518,20 +542,6 @@ public class PlayServiceImpl implements IPlayService {
 //                    errorEvent.response(eventResult);
                 }
             });
-
-            // rtp语音通道创建完成,开始发送broadcast
-            broadcastEventHandle(device,
-                (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);
-                    }
-                }
-            );
         }
 
 

+ 4 - 4
src/main/resources/application.yml

@@ -93,7 +93,7 @@ sip:
     # [必须修改] 本机的IP, 必须是网卡上的IP,用于sip下协议栈监听ip,如果监听所有设置为0.0.0.0
     monitor-ip: 0.0.0.0
     # [必须修改] 本机的IP
-    ip: 192.168.1.26
+    ip: kindring.cn
     # [可选] 28181服务监听的端口
     port: 29000
     # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007)
@@ -123,13 +123,13 @@ media:
     # [必须修改] zlm服务器唯一id,用于触发hook时区别是哪台服务器,general.mediaServerId
     id: your_server_id
     # [必须修改] zlm服务器的内网IP
-    ip: 192.168.1.203
+    ip: szgpay.ticp.net
     # [可选] 返回流地址时的ip,置空使用 media.ip
-    stream-ip: 192.168.1.203
+    stream-ip: szgpay.ticp.net
     #stream-ip: 192.168.1.203
     #stream-ip: 113.88.194.58
     # [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip
-    sdp-ip: 192.168.1.203
+    sdp-ip: szgpay.ticp.net
     #sdp-ip: 192.168.1.203
     #sdp-ip: 113.88.194.58
     # [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip

+ 16 - 6
web_src/config/index.js

@@ -3,7 +3,7 @@
 // see http://vuejs-templates.github.io/webpack for documentation.
 
 const path = require('path')
-
+const baseUrl = "https://192.168.31.174:29001"
 module.exports = {
   dev: {
 
@@ -12,27 +12,37 @@ module.exports = {
     assetsPublicPath: '/',
     proxyTable: {
       '/debug': {
-        target: 'https://192.168.1.26:29001',
+        target: baseUrl,
         changeOrigin: true,
         secure: false,
         pathRewrite: {
           '^/debug': ''
         },headers: {
-          Referer: 'https://192.168.1.26:29001'
+          Referer: baseUrl
+        }
+      },
+      '/zlmServer': {
+        target: "https://szgpay.ticp.net:29010",
+        changeOrigin: true,
+        secure: false,
+        pathRewrite: {
+          '^/zlmServer': ''
+        },headers: {
+          Referer: baseUrl
         }
       },
       '/aiLib':{
-        target: 'https://192.168.1.26:29001',
+        target: baseUrl,
         secure: false,
         changeOrigin: true,
       },
       '/mFile':{
-        target: 'https://192.168.1.26:29001',
+        target: baseUrl,
         secure: false,
         changeOrigin: true,
       },
       '/static/snap': {
-        target: 'https://192.168.1.26:29001',
+        target: baseUrl,
         secure: false,
         changeOrigin: true,
         // pathRewrite: {

+ 1 - 0
web_src/package.json

@@ -12,6 +12,7 @@
   "dependencies": {
     "axios": "^0.24.0",
     "core-js": "^2.6.5",
+    "crypto-js": "^4.1.1",
     "echarts": "^4.9.0",
     "element-ui": "^2.15.6",
     "fingerprintjs2": "^2.1.2",

+ 8 - 4
web_src/src/components/common/microphone.vue

@@ -9,6 +9,7 @@
 <script>
 import handle from "@/until/handle";
 import ZLMRTCClient from "@/assets/ZLMRTCClient";
+import CryptoJS from "crypto-js"
 export default {
   name: "microphone.vue",
   props:{
@@ -61,17 +62,20 @@ export default {
         this.isQueryAllowAudio = true
         let hookProtocol = this.hookProtocol;
         let hookHost = this.hookHost;
+        let pushKey = "3e80d1762a324d5b0ff636e0bd16f1e3";
+        pushKey = CryptoJS.MD5(pushKey);
         if(!hookProtocol){
-          hookProtocol = "https"
+          hookProtocol = "http"
         }
         if(!hookHost){
-          hookHost = "192.168.1.203:29010"
+          hookHost = "szgpay.ticp.net:29010"
         }
         let app = "broadcast";
-        let stream = `audio_${this.deviceId}`
-        let zlmSdpUrl = `${this.hookProtocol}://${this.hookHost}/index/api/webrtc?app=${app}&stream=${stream}&type=push`;
+        let stream = `audio${this.deviceId}`
+        let zlmSdpUrl = `/zlmServer/index/api/webrtc?app=${app}&stream=${stream}&type=push&sign=${pushKey}`;
         let player = new ZLMRTCClient.Endpoint(
           {
+
             // element: document.getElementById('video'),// video 标签
             debug: true,// 是否打印日志
             zlmsdpUrl:zlmSdpUrl,//流地址