Jelajahi Sumber

feat: update

test pc 3 tahun lalu
induk
melakukan
e20a464349
1 mengubah file dengan 102 tambahan dan 100 penghapusan
  1. 102 100
      src/scene/scene.service.ts

+ 102 - 100
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;
@@ -283,7 +283,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const metaData: StreamReplyType = JSON.parse(
           lastStreamFrame.metaData,
         ) as any as StreamReplyType;
-        if(!metaData.endBreakPointId){
+        if (!metaData.endBreakPointId) {
         }
         console.log('stop-4', metaData.traceIds[0]);
         console.log('stop-5', request.trace_id);
@@ -304,19 +304,19 @@ 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)
+        console.log('moveService.stop-1:' + breakPointId)
         redisMeta = await this.moveService.stop(
           trace_id,
           userId,
@@ -362,7 +362,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);
@@ -394,54 +394,56 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     if (!this.moveSliceLastFrameSub) {
       this.moveSliceLastFrameSub = this.moveSliceLastFrame.subscribe(
         async (frame: MovingLastUpdateType) => {
-          // console.log('walkingStop-'+ this.latestWalkingRequest + ','+ this.onMoving.value);
           //TODO 正在行走时,有新的reqest
-          if (this.latestWalkingRequest && this.onMoving.value) {
-            this.logger.log('stop-data-1', frame);
-            this.moveQueueSubscription.unsubscribe();
-            this.moveQueueSubscription = null;
-            this.moveQueue.clean();
-            //step1 执行stop方法
-            const metaData: StreamReplyType = frame.metaData;
-            const newUserStates: NewUserStatesType =
-              metaData.newUserStates.find(
-                (item) => item.userId === this.user_id,
+          if (frame) {
+            this.logger.log('行走每段最后一帧', JSON.stringify(frame));
+            if (this.latestWalkingRequest && this.onMoving.value) {
+              this.logger.log('stop-data-1', frame);
+              this.moveQueueSubscription.unsubscribe();
+              this.moveQueueSubscription = null;
+              this.moveQueue.clean();
+              //step1 执行stop方法
+              const metaData: StreamReplyType = frame.metaData;
+              const newUserStates: NewUserStatesType =
+                metaData.newUserStates.find(
+                  (item) => item.userId === this.user_id,
+                );
+              const trace_id = metaData.traceIds[0];
+              const userId = newUserStates.userId;
+              const breakPointId = metaData.endBreakPointId;
+              const cameraAngle = newUserStates.playerState.camera.angle;
+              const playerAngle = newUserStates.playerState.player.angle;
+              this.logger.log(
+                'stop-data-2',
+                trace_id,
+                userId,
+                cameraAngle,
+                cameraAngle,
               );
-            const trace_id = metaData.traceIds[0];
-            const userId = newUserStates.userId;
-            const breakPointId = metaData.endBreakPointId;
-            const cameraAngle = newUserStates.playerState.camera.angle;
-            const playerAngle = newUserStates.playerState.player.angle;
-            this.logger.log(
-              'stop-data-2',
-              trace_id,
-              userId,
-              cameraAngle,
-              cameraAngle,
-            );
-            console.log('moveService.stop-2:'+breakPointId)
-            const redisMeta = await this.moveService.stop(
-              trace_id,
-              userId,
-              breakPointId,
-              cameraAngle,
-              playerAngle,
-            );
-            this.logger.log('stop-redisMeta', JSON.stringify(redisMeta));
-            // 2. 中断重新walking
-            console.log(
-              'walking-step-reWalking-1',
-              request.trace_id + ',' + this.latestWalkingRequest.trace_id,
-            );
-            // 中断清除上一次最后小段队列
-            // if (this.moveSliceLastFrameSub) {
-            //   this.moveSliceLastFrameSub.unsubscribe();
-            //   this.moveSliceLastFrameSub = null;
-            // }
-
-            this.logger.debug('重新行走---handleReWalking');
-            console.log('重新行走---handleReWalking');
-            this.handleReWalking(this.latestWalkingRequest);
+              console.log('moveService.stop-2:' + breakPointId)
+              const redisMeta = await this.moveService.stop(
+                trace_id,
+                userId,
+                breakPointId,
+                cameraAngle,
+                playerAngle,
+              );
+              this.logger.log('stop-redisMeta', JSON.stringify(redisMeta));
+              // 2. 中断重新walking
+              console.log(
+                'walking-step-reWalking-1',
+                request.trace_id + ',' + this.latestWalkingRequest.trace_id,
+              );
+              // 中断清除上一次最后小段队列
+              // if (this.moveSliceLastFrameSub) {
+              //   this.moveSliceLastFrameSub.unsubscribe();
+              //   this.moveSliceLastFrameSub = null;
+              // }
+
+              this.logger.debug('重新行走---handleReWalking');
+              console.log('重新行走---handleReWalking');
+              this.handleReWalking(this.latestWalkingRequest);
+            }
           }
         },
       );
@@ -464,15 +466,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);
 
@@ -542,16 +544,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;
@@ -607,7 +609,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);
@@ -752,6 +754,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.walkingSub = null;
     }
     if (this.moveSliceLastFrameSub) {
+      this.lastMoveStreamFrame.next(null);
       this.moveSliceLastFrameSub.unsubscribe();
       this.moveSliceLastFrameSub = null;
     }
@@ -781,14 +784,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(
@@ -982,8 +985,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;
@@ -994,12 +996,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(
@@ -1057,12 +1059,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);
@@ -1077,7 +1079,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,