test pc 3 лет назад
Родитель
Сommit
5583f2c653
4 измененных файлов с 77 добавлено и 37 удалено
  1. 21 29
      src/move/move.service.ts
  2. 53 3
      src/rotate/rotate.service.ts
  3. 1 1
      src/scene/scene.service.ts
  4. 2 4
      src/scene/stream/stream.d.ts

+ 21 - 29
src/move/move.service.ts

@@ -48,8 +48,7 @@ export class MoveService implements OnModuleInit {
     traceIds: [],
     vehicle: null,
     mediaSrc: null,
-    //moveOver: false,
-    moveStart: false,
+    joystickIDR:false,
     newUserStates: [
       {
         userId: 'dcff36ae4fc1d',
@@ -1108,16 +1107,8 @@ export class MoveService implements OnModuleInit {
 
           if (cameraInfo.mediaSrc) {
             this.reply.mediaSrc = cameraInfo.mediaSrc;
-            if(this.cameraInfos.length == 0){
-              this.reply.moveStart = true;
-            }
-            else{
-              this.reply.moveStart = false;
-            }
+            this.reply.joystickIDR = cameraInfo.joystickIDR;
           }
-          // if (this.cameraInfos.length == 0) {
-          //   this.reply.moveOver = true;
-          // }
 
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
@@ -1190,16 +1181,8 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
-          if(this.cameraInfos.length == 0){
-            this.reply.moveStart = true;
-          }
-          else{
-            this.reply.moveStart = false;
-          }
+          this.reply.joystickIDR = cameraInfo.joystickIDR;
         }
-        // if (this.cameraInfos.length == 0) {
-        //   this.reply.moveOver = true;
-        // }
 
         user.camera.position = JSON.parse(
           JSON.stringify(cameraInfo.camera_position),
@@ -1248,11 +1231,15 @@ export class MoveService implements OnModuleInit {
       );
 
       for (let i = 0; i < checkReplys.length; ++i) {
-        //checkReplys[i].actionResponses[0].actionType = actionType;
+        let joystickIDR = false;
+        if(i == 0 || i == checkReplys.length-1){
+          joystickIDR = true;
+        }
         this.addCameraInfo(
           checkReplys[i]['newUserStates'][0].playerState.camera.position,
           checkReplys[i]['newUserStates'][0].playerState.camera.angle,
           checkReplys[i].mediaSrc,
+          joystickIDR,
         );
       }
 
@@ -1296,7 +1283,7 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
-          this.reply.moveStart = true;
+          this.reply.joystickIDR = cameraInfo.joystickIDR;
         }
         this.sendingFrameForJoystick = true;
       }
@@ -1339,15 +1326,25 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
+      if(i == 0){
+        moveFrames[i].joystickIDR = true;
+      }
+      else if(i == moveFrames.length -1){
+        moveFrames[i].joystickIDR = true;
+      }
+      else{
+        moveFrames[i].joystickIDR = false;
+      }
       this.cameraInfos.push(moveFrames[i]);
     }
   }
 
-  addCameraInfo(cameraPosition, cameraAngle, mediaSrc) {
+  addCameraInfo(cameraPosition, cameraAngle, mediaSrc,joystickIDR) {
     this.cameraInfos.push({
       camera_position: cameraPosition,
       camera_angle: cameraAngle,
       mediaSrc: mediaSrc,
+      joystickIDR:joystickIDR
     });
   }
 
@@ -1388,12 +1385,7 @@ export class MoveService implements OnModuleInit {
 
       if (cameraInfo.mediaSrc) {
         this.reply.mediaSrc = cameraInfo.mediaSrc;
-        if(this.cameraInfos.length == 0){
-          this.reply.moveStart = true;
-        }
-        else{
-          this.reply.moveStart = false;
-        }
+        this.reply.joystickIDR = cameraInfo.joystickIDR;
       }
 
       user.camera.position = JSON.parse(

+ 53 - 3
src/rotate/rotate.service.ts

@@ -36,6 +36,24 @@ export class RotateService {
   };
   public users = {};
   private replies = {};
+  private firstPoint = {
+    player: {
+      position: { x: -560.0, y: 320.0, z: 0.0 }, //{ x: -800.0, y: 100.0, z: 0.0 },
+      angle: {
+        pitch: 0,
+        yaw: 0,
+        roll: 0,
+      },
+    },
+    camera: {
+      position: { x: -998.0, y: 319.9999694824219, z: 120.0 }, //{ x: -1141.6719970703125, y: 94.03607940673828, z: 120.0 },
+      angle: {
+        pitch: 0,
+        yaw: 0,
+        roll: 0,
+      },
+    }
+  }
 
   init(app_id: string, userId: string) {
     const user = {
@@ -71,8 +89,11 @@ export class RotateService {
     user.appId = app_id;
     user.userId = userId;
     user.breakPointId = Number(this.configService.get('app.startPoint')) || 0;
+    user.player.position = JSON.parse(JSON.stringify(this.firstPoint.player.position));
+    user.camera.position = JSON.parse(JSON.stringify(this.firstPoint.camera.position));
     console.log('user-init', user);
     this.users[userId] = user;
+    
     const reply = {
       traceIds: [],
       vehicle: null,
@@ -158,17 +179,46 @@ export class RotateService {
       code: 0,
       msg: 'OK',
     };
-
+    
     reply['newUserStates'][0].playerState.player.position = JSON.parse(
-      JSON.stringify(user.player.position),
+      JSON.stringify(this.firstPoint.player.position),
     );
     reply['newUserStates'][0].playerState.camera.position = JSON.parse(
-      JSON.stringify(user.camera.position),
+      JSON.stringify(this.firstPoint.camera.position),
     );
     this.replies[userId] = reply;
     return reply;
   }
 
+//首帧
+getFristStreamData(appId,userId){
+  const user = this.users[userId];
+  let reply = this.replies[userId];
+  reply.traceIds = [];
+  reply['newUserStates'][0].userId = userId;
+  reply['newUserStates'][0].playerState.player.position = JSON.parse(JSON.stringify(this.firstPoint.player.position));
+  reply['newUserStates'][0].playerState.player.angle = JSON.parse(JSON.stringify(this.firstPoint.player.angle));
+  reply['newUserStates'][0].playerState.camera.position = JSON.parse(JSON.stringify(this.firstPoint.camera.position));
+  reply['newUserStates'][0].playerState.camera.angle = JSON.parse(JSON.stringify(this.firstPoint.camera.angle));
+  reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(JSON.stringify(this.firstPoint.player.position));
+  reply['actionResponses'][0].traceId = null;
+
+  reply.mediaSrc =
+    '/' +
+    appId +
+    '/' +
+    user.breakPointId +
+    '/' +
+    user.breakPointId +
+    '/' +
+    user.breakPointId+'.0000.h264' +
+    '?m=' +
+    new Date().getTime();
+  reply['newUserStates'][0].renderInfo.isMoving = 0;
+  this.replies[userId] = reply;
+  return reply;
+}
+
   /**
    * delete User object
    * @param userId

+ 1 - 1
src/scene/scene.service.ts

@@ -587,7 +587,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const src = joystickRes.mediaSrc.split('?')[0];
       const mediaSrc = this.configService.get('app.prefix') + src;
       // IDR flag设置为I帧
-      const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
+      const setDIR = joystickRes.joystickIDR ? 1 : 3;
       streamData = {
         frame: this.joystickFrameCnt,
         clipPath: mediaSrc,

+ 2 - 4
src/scene/stream/stream.d.ts

@@ -7,8 +7,7 @@ interface StreamFrameType {
   mediaSrc?: string; // 临时
   mType?: string;
   newUserStates?: NewUserStatesType[];
-  moveStart?: boolean;
-  moveOver?: boolean;
+  joystickIDR?: boolean;
 }
 interface StreamMetaType {
   frame: number;
@@ -83,8 +82,7 @@ interface StreamReplyType {
   breakPointId?: number; //临时记录存在的点()
   mType?: string; //类型
   DIR: ?number;
-  moveStart?: boolean;
-  moveOver?: boolean;
+  joystickIDR?: boolean;
 }
 
 // interface NewUserStatesType{