gemercheung пре 3 година
родитељ
комит
39d906889f
1 измењених фајлова са 84 додато и 70 уклоњено
  1. 84 70
      src/scene/scene.service.ts

+ 84 - 70
src/scene/scene.service.ts

@@ -26,7 +26,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     private rotateService: RotateService,
     private moveService: MoveService,
     private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
-  ) {}
+  ) { }
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
 
   public _frameInteval: NodeJS.Timeout;
@@ -267,16 +267,16 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const playerAngle = newUserStates.playerState.player.angle;
         this.logger.log(
           'stop-data-0' +
-            'trace_id: ' +
-            trace_id +
-            'userId:' +
-            userId +
-            'breakPointId :' +
-            breakPointId +
-            'cameraAngle :' +
-            JSON.stringify(cameraAngle) +
-            'playerAngle: ' +
-            JSON.stringify(playerAngle),
+          'trace_id: ' +
+          trace_id +
+          'userId:' +
+          userId +
+          'breakPointId :' +
+          breakPointId +
+          'cameraAngle :' +
+          JSON.stringify(cameraAngle) +
+          'playerAngle: ' +
+          JSON.stringify(playerAngle),
         );
         //debugger;
         console.log('moveService.stop-1:' + breakPointId);
@@ -325,7 +325,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             const rounded = Number(inMillSeconds).toFixed(3);
             this.logger.log(
               `[timer]-rotate-入队列前: ${rounded}ms -->` +
-                JSON.stringify(stream),
+              JSON.stringify(stream),
             );
 
             this.roQueue.next(stream);
@@ -429,15 +429,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       console.log('进入1 - searchRoad');
       this.logger.log(
         'handleWalking-users' +
-          JSON.stringify(this.moveService.users) +
-          ' this.user_id: ' +
-          this.user_id,
+        JSON.stringify(this.moveService.users) +
+        ' this.user_id: ' +
+        this.user_id,
       );
       this.logger.log(
         'handleWalking-currentUser' +
-          JSON.stringify(user) +
-          ' this.user_id: ' +
-          this.user_id,
+        JSON.stringify(user) +
+        ' this.user_id: ' +
+        this.user_id,
       );
       console.log('path-start' + user.breakPointId);
 
@@ -507,16 +507,16 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (seqs?.length) {
           this.logger.log(
             'walking --队列总览:' +
-              ' 总段数: ' +
-              walkingRes.length +
-              ' 镜头帧数:' +
-              walkingRes[0].length +
-              ' 行走段数:' +
-              (walkingRes[0]?.length
-                ? walkingRes.length - 1
-                : walkingRes.length) +
-              ' 队列总帧数:' +
-              seqs.length,
+            ' 总段数: ' +
+            walkingRes.length +
+            ' 镜头帧数:' +
+            walkingRes[0].length +
+            ' 行走段数:' +
+            (walkingRes[0]?.length
+              ? walkingRes.length - 1
+              : walkingRes.length) +
+            ' 队列总帧数:' +
+            seqs.length,
           );
           const stop = performance.now();
           const inMillSeconds = stop - start;
@@ -572,7 +572,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const joystickRes = await this.moveService.seqExeJoystick(request);
       this.logger.log(
         'joystick-breakPointId:' +
-          this.moveService.users[this.user_id].breakPointId,
+        this.moveService.users[this.user_id].breakPointId,
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       this.logger.log('joystickRes-1', joystickRes);
@@ -581,11 +581,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.onJoysticking.next(true);
         console.log(
           'handlejoystick:' +
-            joystickRes.mediaSrc +
-            ',相机坐标:' +
-            JSON.stringify(
-              joystickRes.newUserStates[0].playerState.camera.position,
-            ),
+          joystickRes.mediaSrc +
+          ',相机坐标:' +
+          JSON.stringify(
+            joystickRes.newUserStates[0].playerState.camera.position,
+          ),
         );
         if (joystickRes.mediaSrc) {
           this.holdSteam();
@@ -632,6 +632,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               hasPush.frame,
               joystickRes.mediaSrc,
             );
+            this.resumeStream();
           }
 
           // // 处理第一个镜头数据
@@ -715,6 +716,18 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 this.resumeStream();
                 this.joystickFrameCnt = -1;
               }, 50);
+            } else {
+              console.error(
+                'joystick-位置流有误::',
+                res.frame,
+                joystickRes.mediaSrc,
+              );
+              this.logger.error(
+                'joystick-位置流有误::',
+                res.frame,
+                joystickRes.mediaSrc,
+              );
+              this.resumeStream();
             }
           }
         }
@@ -740,7 +753,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     this.onMoving.next(true);
     this.holdSteam();
     // 保证每一段都是序列动作的前面队列是空的
-    this.moveQueue.clean();
+    // this.moveQueue.clean();
 
     seqs.forEach((frame: StreamReplyType) => {
       const mediaSrc = frame.mediaSrc;
@@ -801,14 +814,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           };
           this.logger.log(
             '[media-move]: ' +
-              ', moveframeCnt: ' +
-              this.moveframeCnt +
-              ', clipPath: ' +
-              stream.clipPath +
-              ', mType: ' +
-              stream.mType +
-              ', DIR: ' +
-              stream.DIR,
+            ', moveframeCnt: ' +
+            this.moveframeCnt +
+            ', clipPath: ' +
+            stream.clipPath +
+            ', mType: ' +
+            stream.mType +
+            ', DIR: ' +
+            stream.DIR,
             // stream.metaData,
           );
           this.logger.log(
@@ -844,20 +857,21 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.logger.log('move 交权给空流,当前pts', res.frame);
               this.rewalking = false;
               this.frameCnt.next(res.frame);
-              this.resumeStream();
               this.rotateframeCnt = -1;
               this.onMoving.next(false);
               this.onJoysticking.next(false);
-              this.cleanMoveSteam();
               this.lastMovingPointArray = [];
               this.hasJoystickMoveRequest = false;
+              this.cleanMoveSteam();
+              this.resumeStream();
               this.logger.log('move end');
-            }, 80);
+            }, 200);
           } else {
             console.error('流地址有误::', res.frame, JSON.stringify(res));
             this.logger.error(
               `movesteam::当前帧:${res.frame}` + JSON.stringify(res),
             );
+            this.resumeStream();
           }
         } catch (error) {
           this.logger.error('handleMoveSteam::error', error);
@@ -1003,8 +1017,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
           const IDRflag = this._rotateCurrentFame % 5 === 0 ? 1 : 3;
           this.logger.log(
-            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${
-              this._rotateCurrentFame
+            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${this._rotateCurrentFame
             } IDRflag:${IDRflag}`,
           );
           stream.DIR = this.rotateFirstIDR ? 1 : IDRflag;
@@ -1015,12 +1028,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
           this.logger.log(
             '[media-rotate]: ' +
-              ', frame: ' +
-              stream.frame +
-              ', rotateframeCnt: ' +
-              this.rotateframeCnt +
-              ', clipPath: ' +
-              stream.clipPath,
+            ', frame: ' +
+            stream.frame +
+            ', rotateframeCnt: ' +
+            this.rotateframeCnt +
+            ', clipPath: ' +
+            stream.clipPath,
             // stream.metaData,
           );
           // this.logger.log(
@@ -1049,6 +1062,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           } else {
             console.error('流地址有误::', res.frame, JSON.stringify(res));
             this.logger.error('流地址有误::', res.frame, JSON.stringify(res));
+            this.resumeStream();
           }
         },
       );
@@ -1081,12 +1095,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.logger.log('frame', frame);
           console.log(
             'mock' +
-              ' maxMessageSize: ' +
-              this.channel.maxMessageSize() +
-              ' bytesReceived: ' +
-              this.peer.bytesReceived() +
-              ' bytesSent: ' +
-              this.peer.bytesSent(),
+            ' maxMessageSize: ' +
+            this.channel.maxMessageSize() +
+            ' bytesReceived: ' +
+            this.peer.bytesReceived() +
+            ' bytesSent: ' +
+            this.peer.bytesSent(),
           );
           if (frame === 1) {
             redisData = await this.rotateService.echo(this.user_id, true);
@@ -1101,7 +1115,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 delete redisData.mediaSrc;
                 this.logger.log(
                   `user:${this.user_id}:first render stream` +
-                    JSON.stringify({ path: clipPath, meta: redisData }),
+                  JSON.stringify({ path: clipPath, meta: redisData }),
                 );
                 const status = await this.pushFirstRender(
                   clipPath,
@@ -1129,15 +1143,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
             console.log(
               '空白流条件-->:' +
-                isOk +
-                ' onMoving: ' +
-                this.onMoving.value +
-                ' onRotating: ' +
-                this.onRotating.value +
-                ' onJoysticking: ' +
-                this.onJoysticking.value +
-                ' firstRender: ' +
-                this.firstRender,
+              isOk +
+              ' onMoving: ' +
+              this.onMoving.value +
+              ' onRotating: ' +
+              this.onRotating.value +
+              ' onJoysticking: ' +
+              this.onJoysticking.value +
+              ' firstRender: ' +
+              this.firstRender,
             );
           }