Browse Source

commit-2022年5月9日11:22:39

xiewenjie 3 years ago
parent
commit
e1134e26a8

+ 11 - 1
pom.xml

@@ -14,7 +14,12 @@
     <name>fdkk-meta</name>
     <description>fdkk-meta</description>
     <packaging>jar</packaging>
-
+    <repositories>
+        <repository>
+            <id>jitpack.io</id>
+            <url>https://jitpack.io</url>
+        </repository>
+    </repositories>
     <properties>
         <java.version>1.8</java.version>
         <hutool.version>5.7.7</hutool.version>
@@ -82,6 +87,11 @@
 <!--            <version>1.5.7</version>-->
 <!--        </dependency>-->
         <!--redis连接池 end-->
+        <dependency>
+            <groupId>com.github.soriole</groupId>
+            <artifactId>webrtc-signaling-server</artifactId>
+            <version>v0.0.6</version>
+        </dependency>
     </dependencies>
 
 

+ 29 - 9
src/main/java/com/fdkk/fdkkmeta/socketIO/SocketIoServer.java

@@ -33,6 +33,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * @author Xiewj
@@ -48,6 +49,23 @@ public class SocketIoServer {
     TrtcUtil trtcUtil;
     @Autowired
     RedisCache redisCache;
+
+    // 获取推送消息接收入口
+    @OnEvent(value = "getRotateVideoUrl")
+    public void getRotateVideoUrl (SocketIOClient client, AckRequest ackRequest, RotateDto param) throws IOException, InterruptedException {
+        //https://4dkk.4dage.com/meta/testApp/9/9.mp4
+        client.sendEvent("getRotateVideoUrl", "https://4dkk.4dage.com/meta/"+param.getSceneCode()+"/"+param.getVideoPath()+".mp4");
+    }
+    // 获取推送消息接收入口
+    @OnEvent(value = "getVideoUrl")
+    public void getVideoUrl  (SocketIOClient client, AckRequest ackRequest, PushDto param) throws IOException, InterruptedException {
+        List<String> collect = param.getVideoList().stream().map(item -> {
+            return "https://4dkk.4dage.com/meta/" + param.getSceneCode() + "/" + item + ".mp4";
+        }).collect(Collectors.toList());
+        //https://4dkk.4dage.com/meta/testApp/9/9.mp4
+        client.sendEvent("getVideoUrl", collect);
+    }
+
     // 获取推送消息接收入口
     @OnEvent(value = "pushVideo_test")
     public void pushVideo_test (SocketIOClient client, AckRequest ackRequest, PushDto param) throws IOException, InterruptedException {
@@ -61,7 +79,9 @@ public class SocketIoServer {
     public void getRoute (SocketIOClient client, AckRequest ackRequest, RouteDto param) throws IOException, InterruptedException {
         SocketIoServer.log.info("getRoute-接收到客户端消息:{}", JSON.toJSONString(param));
         JSONArray maps = GetRoute.getRoute("/home/webrtc/scenefreespacefile/target_freespace.json", param);
-        pushMessageToUser("getRoute",param.getUserId(),maps);
+//        JSONArray maps = GetRoute.getRoute("D:\\video\\target_freespace.json", param);
+        client.sendEvent("getRoute",maps);
+        log.info("getRoute返回,{}",maps);
     }
 
 
@@ -86,19 +106,19 @@ public class SocketIoServer {
 
         if (redisCache.hasKey(key)){
             byte[] bytes = redisCache.getCacheObject(key);
-            pushMessageToUser("getSocketVideo",param.getUserId(),bytes);
+            client.sendEvent("getSocketVideo",bytes);
             log.info("getVideo-redis-pushMessageToUser");
         }else {
             if (FileUtil.exist(outfilePath)){
                 byte[] bytes = IoUtil.readBytes(new FileInputStream(outfilePath));
-                pushMessageToUser("getSocketVideo",param.getUserId(),bytes);
+                client.sendEvent("getSocketVideo",bytes);
                 redisCache.setCacheObject(key,bytes);
             }else {
                 String token = redisCache.tryLock("getVideo:" + key, 1000 * 60 * 2);
                 if (token != null){
 
                     FileWriter writer = new FileWriter(filePath);
-                    Set<String> fileList=new HashSet<>();
+                    List<String> fileList=new LinkedList<>();
                     for (String s : param.getVideoList()) {
                         fileList.add("file '/home/webrtc/videofile/"+param.getSceneCode()+"/"+s+".mp4'");
                     }
@@ -109,7 +129,7 @@ public class SocketIoServer {
                     );
                     exec.waitFor();
                     byte[] bytes = IoUtil.readBytes(new FileInputStream(outfilePath));
-                    pushMessageToUser("getSocketVideo",param.getUserId(),bytes);
+                    client.sendEvent("getSocketVideo",bytes);
                     redisCache.setCacheObject(key,bytes);
                     log.info("getVideo-{} {} {}","/home/webrtc/socket-pushvideos.sh",
                             filePath,outfilePath);
@@ -133,12 +153,12 @@ public class SocketIoServer {
 
         if (redisCache.hasKey(key)) {
             byte[] bytes = redisCache.getCacheObject(key);
-            pushMessageToUser("getSocketVideo", param.getUserId(), bytes);
+            client.sendEvent("getSocketVideo", bytes);
             log.info("getRotateVideo-redis-pushMessageToUser");
         }else {
             if (FileUtil.exist(outfilePath)){
                 byte[] bytes = IoUtil.readBytes(new FileInputStream(outfilePath));
-                pushMessageToUser("getSocketVideo",param.getUserId(),bytes);
+                client.sendEvent("getSocketVideo",bytes);
                 redisCache.setCacheObject(key,bytes);
             }else {
                 String token = redisCache.tryLock("getRotateVideo:" + key, 1000 * 60 * 2);
@@ -149,14 +169,14 @@ public class SocketIoServer {
                     String videoPath = param.getVideoPath();
                     log.info("{}{}{}[}", sangle, eangle, reverses, videoPath);
                     Process exec = RuntimeUtil.exec("/home/webrtc/socket-pushvideo-rotate.sh",
-                            "/home/webrtc/videofile/" + videoPath,
+                            "/home/webrtc/videofile/" +param.getSceneCode()+"/"+ videoPath,
                             FpsUtil.getDateFormat(sangle),
                             FpsUtil.getDateFormat(eangle),
                             reverses, outfilePath
                     );
                     exec.waitFor();
                     byte[] bytes = IoUtil.readBytes(new FileInputStream(outfilePath));
-                    pushMessageToUser("getSocketVideo", param.getUserId(), bytes);
+                    client.sendEvent("getSocketVideo", bytes);
                     redisCache.setCacheObject(key,bytes);
                     log.info("getRotateVideo-{} {} {} {} {} {}", "/home/webrtc/socket-pushvideo-rotate.sh",
                             "/home/webrtc/videofile/"+param.getSceneCode()+"/" + videoPath,

+ 96 - 95
src/main/java/com/fdkk/fdkkmeta/test/test.java

@@ -1,41 +1,37 @@
-//package com.fdkk.fdkkmeta.test;
-//
-//import cn.hutool.core.date.DateUtil;
-//import cn.hutool.core.io.BufferUtil;
-//import cn.hutool.core.io.FileUtil;
-//import cn.hutool.core.io.IORuntimeException;
-//import cn.hutool.core.io.IoUtil;
-//import cn.hutool.core.io.file.FileWriter;
-//import cn.hutool.core.lang.Console;
-//import cn.hutool.core.util.StrUtil;
-//import cn.hutool.core.util.URLUtil;
-//import cn.hutool.log.StaticLog;
-//import cn.hutool.socket.aio.AioServer;
-//import cn.hutool.socket.aio.AioSession;
-//import cn.hutool.socket.aio.SimpleIoAction;
-//import cn.hutool.socket.nio.NioServer;
-//import com.alibaba.fastjson.JSON;
-//import com.alibaba.fastjson.JSONArray;
-//import com.alibaba.fastjson.JSONObject;
-//import com.fdkk.fdkkmeta.po.RoutePO;
-//import com.fdkk.fdkkmeta.util.FileUtils;
-//import org.bytedeco.ffmpeg.global.avcodec;
-//import org.bytedeco.javacv.FFmpegFrameGrabber;
-//import org.bytedeco.javacv.FFmpegFrameRecorder;
-//import org.bytedeco.javacv.Frame;
-//
-//import java.io.*;
-//import java.nio.ByteBuffer;
-//import java.nio.charset.Charset;
-//import java.text.SimpleDateFormat;
-//import java.util.*;
-//import java.util.stream.Collectors;
-//
-///**
-// * @author Xiewj
-// * @date 2022/3/29
-// */
-//public class test {
+package com.fdkk.fdkkmeta.test;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.BufferUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.IORuntimeException;
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.io.file.FileWriter;
+import cn.hutool.core.lang.Console;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.URLUtil;
+import cn.hutool.log.StaticLog;
+import cn.hutool.socket.aio.AioServer;
+import cn.hutool.socket.aio.AioSession;
+import cn.hutool.socket.aio.SimpleIoAction;
+import cn.hutool.socket.nio.NioServer;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkk.fdkkmeta.entity.po.RoutePO;
+import com.fdkk.fdkkmeta.util.FileUtils;
+
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author Xiewj
+ * @date 2022/3/29
+ */
+public class test {
 ////    public static void main(String[] args) throws IOException {
 ////        int d=6;
 ////        int fps=2 % d;
@@ -120,60 +116,65 @@
 //    }
 //
 //
-//    private static void createdPointsJson(String path) {
-//        List<String> list = FileUtils.readFileByLines2(path);
-//        JSONArray array=new JSONArray();
-//        FileWriter writer=new FileWriter("D:\\video\\points.json");
-//        for (int i = 0; i < list.size(); i++) {
-//            JSONObject jsonObject=new JSONObject();
-//            String[] s = list.get(i).split(" ");
-//            jsonObject.put("id",i );
-//            JSONObject position=new JSONObject();
-//            position.put("x",Double.valueOf(s[0]));
-//            position.put("y",Double.valueOf(s[1]));
-//            position.put("z",Double.valueOf(s[2]));
-//            jsonObject.put("position",position);
-//            JSONObject rotation=new JSONObject();
-//            rotation.put("x",0.0);
-//            rotation.put("y",0.0);
-//            rotation.put("z",0.0);
-//            rotation.put("w",1.0);
-//            jsonObject.put("rotation",rotation);
-//            List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
-//            List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
-//                return Integer.parseInt(a)-1;
-//            }).collect(Collectors.toList());
-//            jsonObject.put("contact",contact);
-//            array.add(jsonObject);
-//        }
-//        writer.write(array.toJSONString());
-//    }
-//
-//    private static void creatTargetJson(String path) {
-//        List<String> list = FileUtils.readFileByLines2(path);
-//        List<String> collect = new ArrayList<>();
-//        FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
-//        for (int i = 0; i < list.size(); i++) {
-//            RoutePO po = new RoutePO();
-//            String[] s = list.get(i).split(" ");
-//            po.setId(i );
-//            if (s.length == 12) {
-//                double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
-//                po.setX(oldPoint[0]);
-//                po.setY(oldPoint[1]);
-//                po.setZ(oldPoint[2]);
-//                po.setWeight(Double.parseDouble(s[3]));
-//                List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
-//                List<Integer> contact = strings.stream().map(a->{
-//                    if (Integer.parseInt(a)!=-1){
-//                        return Integer.parseInt(a)-1;
-//                    }
-//                    return Integer.parseInt(a);
-//                }).collect(Collectors.toList());
-//                po.setIds(contact);
-//            }
-//            collect.add(JSON.toJSONString(po));
-//        }
-//        writer.writeLines(collect);
-//    }
-//}
+        public static void main(String[] args) {
+            createdPointsJson("H:\\workfile\\final_freespace(3).csv");
+            creatTargetJson("H:\\workfile\\final_freespace(3).csv");
+
+        }
+    private static void createdPointsJson(String path) {
+        List<String> list = FileUtils.readFileByLines2(path);
+        JSONArray array=new JSONArray();
+        FileWriter writer=new FileWriter("H:\\workfile\\points.json");
+        for (int i = 0; i < list.size(); i++) {
+            JSONObject jsonObject=new JSONObject();
+            String[] s = list.get(i).split(" ");
+            jsonObject.put("id",i );
+            JSONObject position=new JSONObject();
+            position.put("x",Double.valueOf(s[0]));
+            position.put("y",Double.valueOf(s[1]));
+            position.put("z",Double.valueOf(s[2]));
+            jsonObject.put("position",position);
+            JSONObject rotation=new JSONObject();
+            rotation.put("x",0.0);
+            rotation.put("y",0.0);
+            rotation.put("z",0.0);
+            rotation.put("w",1.0);
+            jsonObject.put("rotation",rotation);
+            List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
+            List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
+                return Integer.parseInt(a)-1;
+            }).collect(Collectors.toList());
+            jsonObject.put("contact",contact);
+            array.add(jsonObject);
+        }
+        writer.write(array.toJSONString());
+    }
+
+    private static void creatTargetJson(String path) {
+        List<String> list = FileUtils.readFileByLines2(path);
+        List<String> collect = new ArrayList<>();
+        FileWriter writer=new FileWriter("H:\\workfile\\target_freespace.json");
+        for (int i = 0; i < list.size(); i++) {
+            RoutePO po = new RoutePO();
+            String[] s = list.get(i).split(" ");
+            po.setId(i );
+            if (s.length == 12) {
+                double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
+                po.setX(oldPoint[0]);
+                po.setY(oldPoint[1]);
+                po.setZ(oldPoint[2]);
+                po.setWeight(Double.parseDouble(s[3]));
+                List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
+                List<Integer> contact = strings.stream().map(a->{
+                    if (Integer.parseInt(a)!=-1){
+                        return Integer.parseInt(a)-1;
+                    }
+                    return Integer.parseInt(a);
+                }).collect(Collectors.toList());
+                po.setIds(contact);
+            }
+            collect.add(JSON.toJSONString(po));
+        }
+        writer.writeLines(collect);
+    }
+}

+ 26 - 0
src/main/java/com/fdkk/fdkkmeta/test/test3.java

@@ -0,0 +1,26 @@
+package com.fdkk.fdkkmeta.test;
+
+import cn.hutool.core.io.file.FileWriter;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author Xiewj
+ * @date 2022/4/6
+ */
+public class test3 {
+    public static void main(String[] args) {
+        FileWriter writer = new FileWriter("D:\\video\\1.txt");
+        ArrayList<String> a=new ArrayList();
+        a.add("0/0_12_7");
+        a.add("12/12_10_7");
+        List<String> fileList=new LinkedList<>();
+        for (String s : a) {
+            fileList.add("file '/home/webrtc/videofile/xxx/"+s+".mp4'");
+        }
+        writer.writeLines(fileList,false);
+
+    }
+}

+ 26 - 32
src/main/java/com/fdkk/fdkkmeta/util/kesar/GetRoute.java

@@ -2,6 +2,7 @@ package com.fdkk.fdkkmeta.util.kesar;
 
 import cn.hutool.core.io.LineHandler;
 import cn.hutool.core.io.file.FileReader;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -93,12 +94,12 @@ public class GetRoute {
             RoutePO po = JSON.toJavaObject(JSON.parseObject(s), RoutePO.class);
             Coord coord = new Coord(Double.valueOf(po.getX()), Double.valueOf(po.getY()), Double.valueOf(po.getZ()));
             Double _startDistance = GetRoute.g_AStar.calcH(_start, coord);
-            if (_startDistance < startDistance[0]) {
+            if (_startDistance <= startDistance[0]) {
                 GetRoute.minStartId = po;
                 startDistance[0] = _startDistance;
             }
             Double _endDistance = GetRoute.g_AStar.calcH(_end, coord);
-            if (_endDistance < endDistance[0]) {
+            if (_endDistance <= endDistance[0]) {
                 GetRoute.minEndId = po;
                 endDistance[0] = _endDistance;
             }
@@ -107,13 +108,13 @@ public class GetRoute {
         GetRoute.log.info("数量: {}", collect.size());
         GetRoute.log.info("棋盘获取路线点-开始点{},{}", _start.x, _start.y);
         GetRoute.log.info("棋盘获取路线点-结束点{},{}", _end.x, _end.y);
-////        超过1.1米就找不到路径
-//        if (startDistance[0] > 1.1 || endDistance[0] > 1.1) {
-//            GetRoute.log.info("超过1.1米就找不到路径startDistance {},endDistance{}", startDistance[0], endDistance[0]);
-//            GetRoute.log.info("开始最近距离{} ", startDistance[0]);
-//            GetRoute.log.info("结束最近距离{}", endDistance[0]);
-//            return null;
-//        }
+        //  开始结束点一样就直接返回
+        if (minStartId.getId()==minEndId.getId()){
+            GetRoute.log.info("超过1.1米就找不到路径startDistance {},endDistance{}", startDistance[0], endDistance[0]);
+            GetRoute.log.info("开始最近距离{} ", startDistance[0]);
+            GetRoute.log.info("结束最近距离{}", endDistance[0]);
+            return null;
+        }
 
         Coord startVirtualCoord = new Coord(GetRoute.minStartId.getX(), GetRoute.minStartId.getY(), GetRoute.minStartId.getZ());
         Coord endVirtualCoord = new Coord(GetRoute.minEndId.getX(), GetRoute.minEndId.getY(), GetRoute.minEndId.getZ());
@@ -132,40 +133,33 @@ public class GetRoute {
     private static JSONArray convertFromPath(List<Node> mappath, RouteDto dto) {
         double defaultdistance = 0.36;
         if (mappath == null || mappath.size() == 0) {
+            GetRoute.log.info("convertFromPath,mappath.size ,{}", mappath.size());
             return null;
         }
 
-        Double startX = dto.getS_location().getX();
-        Double startY = dto.getS_location().getY();
-        Double startZ = dto.getS_location().getZ();
-
-        Double endX = dto.getE_location().getX();
-        Double endY =  dto.getE_location().getY();
-        Double endZ =  dto.getE_location().getZ();
-
-
-
         JSONArray route = new JSONArray();
 
         //起点不在path上,path的第一个点对应的是格子
 
-//        JSONObject start = new JSONObject();
-//        start.put("id", GetRoute.start.id);
-//        start.put("location", GetRoute.start.coord);
-//        route.add(start);
+        JSONObject start = new JSONObject();
+        start.put("id", GetRoute.start.id);
+        start.put("location", GetRoute.start.coord);
+        route.add(start);
 
         Double[] virtualEndPosition = new Double[3];
-        for (int i = 0; i < mappath.size(); ++i) {
+        for (int i = mappath.size() - 1; i >= 0; i--) {
             Node node = mappath.get(i);
-            JSONObject item = new JSONObject();
-            item.put("location", node.coord);
-            item.put("id", node.id);
-            route.add(item);
+           if (node.id!=GetRoute.start.id&&node.id!=GetRoute.end.id) {
+               JSONObject item = new JSONObject();
+               item.put("location", node.coord);
+               item.put("id", node.id);
+               route.add(item);
+           }
         }
-//        JSONObject end = new JSONObject();
-//        start.put("id", GetRoute.end.id);
-//        end.put("location", GetRoute.end.coord);
-//        route.add(end);
+        JSONObject end = new JSONObject();
+        end.put("id", GetRoute.end.id);
+        end.put("location", GetRoute.end.coord);
+        route.add(end);
         return route;
     }