Selaa lähdekoodia

暂存抓包测试
1. 配置文件修改,broad抓包测试

kindring 2 vuotta sitten
vanhempi
sitoutus
d2a2d19b68

+ 12 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java

@@ -94,6 +94,18 @@ public class Device {
 	@Schema(description = "心跳时间")
 	private String keepaliveTime;
 
+	/**
+	 * 心跳间隔
+	 */
+	@Schema(description = "心跳间隔")
+	private int keepaliveIntervalTime;
+	public int getKeepaliveIntervalTime() {
+		return keepaliveIntervalTime;
+	}
+	public void setKeepaliveIntervalTime(int keepaliveIntervalTime) {
+		this.keepaliveIntervalTime = keepaliveIntervalTime;
+	}
+
 	/**
 	 * 通道个数
 	 */

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

@@ -518,24 +518,27 @@ public class SIPCommander implements ISIPCommander {
                                        SipSubscribe.Event errorEvent)throws
             InvalidArgumentException, SipException, ParseException{
         logger.info("{} 语音对讲拉语音流的ZLM为: {} [{}:{}]", ssrcInfo.getStream(), mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
+        int testPort = 31234;
         StringBuffer content = new StringBuffer(200);
         content.append("v=0\r\n");
         content.append("o=" + device.getDeviceId() + " 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
         content.append("s=Play\r\n");
         content.append("u=" + device.getDeviceId() + ":0\r\n");
         content.append("c=IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
-        content.append("t=" + DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime) + " "
-                + DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) + "\r\n");
+//        content.append("t=" + DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime) + " "
+//                + DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) + "\r\n");
 
         // 使用send only 发送audio拉流地址
-        content.append("m=audio " + ssrcInfo.getPort() + " TCP/RTP/AVP 8 16 24\r\n");
+        content.append("m=audio " + ssrcInfo.getPort() + " TCP/RTP/AVP 8\r\n");
+
+//        content.append("m=audio " + testPort + " TCP/RTP/AVP 8 16 24\r\n");
         content.append("a=sendonly\r\n");
         content.append("a=rtpmao:8 PCMA/8000\r\n");
-        content.append("a=rtpmao:16 PCMU/8000\r\n");
-        content.append("a=rtpmao:24 OPUS/8000\r\n");
+//        content.append("a=rtpmao:16 PCMU/8000\r\n");
+//        content.append("a=rtpmao:24 OPUS/8000\r\n");
         content.append("a=setup:passive\r\n");
         content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
-        content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
+        content.append("y=v/////a/1/8/1\r\n");//ssrc
         CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
                 : udpSipProvider.getNewCallId();
         logger.info("下发audio invite 为{}",content.toString());

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java

@@ -52,6 +52,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
             // 未注册的设备不做处理
             return;
         }
+
         try {
             // 判断RPort是否改变,改变则说明路由nat信息变化,修改设备信息
             // 获取到通信地址等信息

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

@@ -303,9 +303,9 @@ public class ZLMRTPServerFactory {
         Map<String, Object> param = new HashMap<>();
         param.put("vhost", "__defaultVhost__");
         // 推流端口设置0则使用随机端口
-//        param.put("port", 0);
+        param.put("src_port", 31234);
         param.put("only_audio", 1);
-        param.put("ssrc", "123145");
+        param.put("ssrc", ssrc);
         param.put("app", "rtc");
 
 
@@ -318,12 +318,13 @@ public class ZLMRTPServerFactory {
         param.put("dst_port", dst_port);
         param.put("use_ps", 0);
         param.put("pt", 8);
+        param.put("close_delay_ms", 15000);
 
 //        param.put("stream", streamId);
 //        param.put("recv_stream_id", recv_stream_id);
 
-        logger.info("[你好] send json: ");
-        logger.info("[你好] send json: {}",param.toString());
+//        logger.info("[你好] send json: ");
+//        logger.info("[你好] send json: {}",param.toString());
         logger.info("send json: {}",param.toString());
 //        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(param));
         return param;

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

@@ -196,8 +196,8 @@ public class MediaServerServiceImpl implements IMediaServerService {
             int rtpServerPort;
             // 创建
             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);
+            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");

+ 62 - 45
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service.impl;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.ParseException;
+import java.time.Instant;
 import java.util.*;
 
 import javax.sip.InvalidArgumentException;
@@ -21,6 +22,8 @@ import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.service.bean.*;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import gov.nist.javax.sdp.TimeDescriptionImpl;
+import gov.nist.javax.sdp.fields.TimeField;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -380,7 +383,7 @@ public class PlayServiceImpl implements IPlayService {
 
     public PlayResult openBroadcast(MediaServerItem mediaServerItem,String deviceId,String audioStreamId,ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
                               Runnable timeoutCallback){
-
+        logger.warn("[语音广播] 开语音广播");
         PlayResult playResult = new PlayResult();
         RequestMessage msg = new RequestMessage();
         String key  = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
@@ -407,7 +410,8 @@ public class PlayServiceImpl implements IPlayService {
         // 此段为录像查询...
         Device device = redisCatchStorage.getDevice(deviceId);
         StreamInfo streamInfo = redisCatchStorage.queryRecordByDevice(deviceId);
-        playResult.setDevice(device);
+//        playResult.setDevice(device);
+
         result.onCompletion(()->{
             // 通道结束
             logger.info("[语音广播] broadcast流程结束....");
@@ -483,46 +487,68 @@ public class PlayServiceImpl implements IPlayService {
                 streamInfo = null;
             }
         }
-        if(streamInfo == null){
 
 
 
-            // rtp语音通道创建完成,开始发送broadcast
-            broadcastEventHandle(
-                    device,
-                    audioStreamId,
-                (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语音通道创建完成,开始发送broadcast
+        broadcastEventHandle(
+                device,
+                audioStreamId,
+            (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 推流通道
+        // 开始创建 rtp/tcp 推流通道
 
 
-            // 注册subScript事件
-            GBHookSubscribe.addSubscribe(broadcastForInviteHook,(int code,JSONObject json)->{
-                logger.info("[语音广播] 接收到设备invite信息___订阅事件触发 JSONDATA: {}",json.toJSONString());
-                String streamId = null;
-                SSRCInfo ssrcInfo;
-                if (mediaServerItem.isRtpEnable()) {
-                    streamId = String.format("broadcast_%s", device.getDeviceId());
-                }
-                logger.info("[语音广播] 尝试创建rtp语音推流通道");
+        // 注册subScript事件
+        GBHookSubscribe.addSubscribe(broadcastForInviteHook,(int code,JSONObject json)->{
+            logger.info("[语音广播] 接收到设备invite信息___订阅事件触发 JSONDATA: {}",json.toJSONString());
+            String streamId = null;
+            String ssrcStr = json.getString("ssrc");
+            ssrcStr = ssrcStr.replaceAll("\\s*|\r|\n|\t","");
+            SSRCInfo ssrcInfo = new SSRCInfo(31234,ssrcStr,audioStreamId);
+            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));
+//                TimeDescriptionImpl timeDescription = (TimeDescriptionImpl) (sdp.getTimeDescriptions(false).get(0));
+//                TimeField startTimeFiled = (TimeField) timeDescription.getTime();
+//                startTime = startTimeFiled.getStartTime();
+//                stopTime = startTimeFiled.getStopTime();
+//
+//                start = Instant.ofEpochSecond(startTime);
+//                end = Instant.ofEpochSecond(stopTime);
+
+            // TODO: 2023/3/7 开始下发invite信息给设备
+            try {
+                cmder.sendBoradcastInviteCmd(mediaServerItem, ssrcInfo, device, null, null,
+                null,
+                (_event) -> {
+                },
+                (_errorEvent) -> {
+
+                });
                 ssrcInfo = mediaServerService.startSendRtpServer(mediaServerItem, streamId, audioStreamId,
                         json.getString("addr"),
                         json.getString("port"),
-                        json.getString("ssrc")
+                        ssrcStr
                 );
-                logger.info(JSONObject.toJSONString(ssrcInfo));
-
-
                 resultHolder.invokeAllResult(msg);
                 WVPResult wvpResult = new WVPResult();
                 wvpResult.setCode(ErrorCode.SUCCESS.getCode());
@@ -531,23 +557,14 @@ public class PlayServiceImpl implements IPlayService {
 
                 msg.setData(wvpResult);
                 resultHolder.invokeAllResult(msg);
-                // TODO: 2023/3/7 开始下发invite信息给设备
-                try {
-                    cmder.sendBoradcastInviteCmd(mediaServerItem, ssrcInfo, device, null, null,
-                            null,
-                            (_event) -> {
-                            },
-                            (_errorEvent) -> {
-
-                            });
-                }catch(InvalidArgumentException | SipException | ParseException e){
-                    logger.error("[下发audio拉流invite失败]",e);
+            }catch(InvalidArgumentException | SipException | ParseException e){
+                logger.error("[下发audio拉流invite失败]",e);
 //                    SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(new CmdSendFailEvent(null));
 //                    eventResult.msg = "命令发送失败";
 //                    errorEvent.response(eventResult);
-                }
-            });
-        }
+            }
+        });
+
 
 
         return playResult;

+ 13 - 9
src/main/resources/application.yml

@@ -13,13 +13,13 @@ spring:
     # REDIS数据库配置
     redis:
         # [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1
-        host: hofuniot.cn
+        host: kindring.cn
         # [必须修改] 端口号
-        port: 4196
+        port: 7654
         # [可选] 数据库 DB
         database: 6
         # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
-        password: hfyswj100
+        password: hfyredis28181
         # [可选] 超时时间
         timeout: 10000
         # [可选] 一个pool最多可分配多少个jedis实例
@@ -32,9 +32,13 @@ spring:
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
         driver-class-name: com.mysql.cj.jdbc.Driver
-        url: jdbc:mysql://hofuniot.cn:3306/wvp?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true
-        username: gpsuser
-        password: tianhui2013
+#        url: jdbc:mysql://kindring.cn:6543/wvp?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true
+        url: jdbc:mysql://kindring.cn:6543/gb_db?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true
+
+        #        username: gpsuser
+#        password: tianhui2013
+        username: hfygb
+        password: hfygb28181
         druid:
             initialSize: 10                       # 连接池初始化连接数
             maxActive: 200                        # 连接池最大连接数
@@ -123,13 +127,13 @@ media:
     # [必须修改] zlm服务器唯一id,用于触发hook时区别是哪台服务器,general.mediaServerId
     id: your_server_id
     # [必须修改] zlm服务器的内网IP
-    ip: szgpay.ticp.net
+    ip: 119.91.250.126
     # [可选] 返回流地址时的ip,置空使用 media.ip
-    stream-ip: szgpay.ticp.net
+    stream-ip: kindring.cn
     #stream-ip: 192.168.1.203
     #stream-ip: 113.88.194.58
     # [可选] wvp在国标信令中使用的ip,此ip为摄像机可以访问到的ip, 置空使用 media.ip
-    sdp-ip: szgpay.ticp.net
+    sdp-ip: kindring.cn
     #sdp-ip: 192.168.1.203
     #sdp-ip: 113.88.194.58
     # [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip

+ 4 - 3
web_src/config/index.js

@@ -3,7 +3,8 @@
 // see http://vuejs-templates.github.io/webpack for documentation.
 
 const path = require('path')
-const baseUrl = "https://192.168.31.174:29001"
+const baseUrl = "https://192.168.1.26:29001"
+const ZLMServer = "https://kindring.cn:29010"
 module.exports = {
   dev: {
 
@@ -22,7 +23,7 @@ module.exports = {
         }
       },
       '/zlmServer': {
-        target: "https://szgpay.ticp.net:29010",
+        target: ZLMServer,
         changeOrigin: true,
         secure: false,
         pathRewrite: {
@@ -32,7 +33,7 @@ module.exports = {
         }
       },
       '/debug/zlmServer': {
-        target: "https://szgpay.ticp.net:29010",
+        target: ZLMServer,
         changeOrigin: true,
         secure: false,
         pathRewrite: {

+ 5 - 3
web_src/src/components/common/microphone.vue

@@ -8,6 +8,7 @@
 
 <script>
 import handle from "@/until/handle";
+import {sleep} from "@/until/time";
 import ZLMRTCClient from "@/assets/ZLMRTCClient";
 import CryptoJS from "crypto-js"
 export default {
@@ -133,9 +134,10 @@ export default {
           if(state === 'connected'){
             console.log(player);
             console.log(player._localStream.id);
-            if(player._localStream && player._localStream.id){
-              stream = player._localStream.id;
-            }
+            // if(player._localStream && player._localStream.id){
+            //   stream = player._localStream.id;
+            // }
+            await sleep(1000);
             [err,res] = await  handle(this.sendBroaderCast(stream));
 
             if(err){

+ 7 - 0
web_src/src/until/time.js

@@ -41,7 +41,14 @@ function timeStamp_to_Date(timeStamp,s = 1000){
     return new Date(timeStamp);
 }
 
+export function sleep(t=100){
+  return new Promise((resolve, reject) => {
+    setTimeout(resolve,t)
+  })
+}
+
 export default {
     dateFormat,
+    sleep,
     timeStamp_to_Date
 }