gemercheung 3 jaren geleden
bovenliggende
commit
2a72f8a046
1 gewijzigde bestanden met toevoegingen van 70 en 66 verwijderingen
  1. 70 66
      src/scene/scene.service.ts

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

@@ -38,7 +38,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;
@@ -291,7 +291,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),
             );
             if (!this.stopRotated) {
               await this.seqExehandleRotateStream(stream);
@@ -488,16 +488,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);
@@ -661,15 +661,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);
 
@@ -724,16 +724,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;
@@ -791,7 +791,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     //console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
     console.log(
       'handlejoystick-angle->相机角度-------------------------:' +
-        joystickRes['newUserStates'][0].playerState.camera.angle.yaw,
+      joystickRes['newUserStates'][0].playerState.camera.angle.yaw,
     );
     let streamData: StreamFrameType | StreamMetaType;
 
@@ -813,11 +813,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       };
       console.log(
         'handlejoystick-hasMedia->-------------------------:' +
-          ' frame: ' +
-          streamData.frame +
-          mediaSrc +
-          '  IDR :' +
-          setDIR,
+        ' frame: ' +
+        streamData.frame +
+        mediaSrc +
+        '  IDR :' +
+        setDIR,
       );
     } else {
       streamData = {
@@ -836,8 +836,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const hasPush = hasMedia
       ? await this.streamService.pushFrameToSteam(streamData as StreamFrameType)
       : await this.streamService.pushMetaDataToSteam(
-          streamData as StreamMetaType,
-        );
+        streamData as StreamMetaType,
+      );
 
     if (hasPush.done) {
       this.isJoystickHasStream = true;
@@ -874,9 +874,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (complementFrame) {
           console.log(
             '20220627test-complementFrame 进行' +
-              complementFrame.mediaSrc +
-              '***' +
-              this.frameCnt.value,
+            complementFrame.mediaSrc +
+            '***' +
+            this.frameCnt.value,
           );
           // 第二次或N次进入时如果有值直接重新进入流主程
           this.holdSteam();
@@ -949,7 +949,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', JSON.stringify(joystickRes));
@@ -1034,14 +1034,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(
@@ -1054,6 +1054,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.holdSteam();
         // this.globalOptLock = true;
         //console.log('20220627test:handleMoveSteam:' + stream.clipPath)
+        const frameTimeStart = performance.now();
         const res = await this.streamService.pushFrameToSteam(streamData);
 
         const isLastFrameIndex = this.lastMovingPointArray.findIndex(
@@ -1062,6 +1063,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         // this.logger.log('path-update-index', isLastFrameIndex);
 
         if (res.done) {
+          const frameTimeEnd = performance.now();
+          const frameAverage = frameTimeEnd - frameTimeStart;
+          console.log('walking-frameAverage', frameAverage);
           await this.sleep(40);
           this.frameCnt.next(res.frame);
           //关节点入库
@@ -1296,12 +1300,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(),
             ' state: ' + this.peer.state(),
           );
           if (frame === 1) {
@@ -1323,7 +1327,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,
@@ -1352,17 +1356,17 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
             console.log(
               '空白流条件-->:' +
-                isOk +
-                ' onMoving: ' +
-                this.onMoving.value +
-                ' onRotating: ' +
-                this.onRotating.value +
-                ' onJoysticking: ' +
-                this.onJoysticking.value +
-                ' onSteaming: ' +
-                this.onSteaming +
-                ' firstRender: ' +
-                this.firstRender,
+              isOk +
+              ' onMoving: ' +
+              this.onMoving.value +
+              ' onRotating: ' +
+              this.onRotating.value +
+              ' onJoysticking: ' +
+              this.onJoysticking.value +
+              ' onSteaming: ' +
+              this.onSteaming +
+              ' firstRender: ' +
+              this.firstRender,
             );
           }