gemercheung 3 年之前
父节点
当前提交
d000a392ff
共有 3 个文件被更改,包括 87 次插入81 次删除
  1. 16 16
      src/rotate/rotate.service.ts
  2. 65 64
      src/scene/scene.service.ts
  3. 6 1
      src/scene/stream/stream.service.ts

+ 16 - 16
src/rotate/rotate.service.ts

@@ -162,22 +162,22 @@ export class RotateService {
         },
       ],
       actionResponses: [
-        // {
-        //     "actionType": 15,
-        //     "pointType": 100,
-        //     "extra": "",
-        //     "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
-        //     "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
-        //     "nps": [],
-        //     "peopleNum": 0,
-        //     "zoneId": "",
-        //     "echoMsg": "",
-        //     "reserveDetail": null,
-        //     "userWithAvatarList": [],
-        //     "newUserStates": [],
-        //     "code": 0,
-        //     "msg": ""
-        // }
+        {
+          // "actionType": 15,
+          // "pointType": 100,
+          extra: '',
+          // "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
+          // "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
+          nps: [],
+          peopleNum: 0,
+          zoneId: '',
+          echoMsg: '',
+          reserveDetail: null,
+          userWithAvatarList: [],
+          newUserStates: [],
+          code: 0,
+          msg: '',
+        },
       ],
       getStateType: 0,
       code: 0,

+ 65 - 64
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;
@@ -100,7 +100,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   private isJoystickHasStream = false;
   private hasJoystickFocusRepeat = false;
-  private startSub: any
+  private startSub: any;
 
   public users = {};
 
@@ -284,7 +284,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);
@@ -323,7 +323,8 @@ 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;
@@ -334,12 +335,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(
@@ -365,7 +366,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 this.roRequestQueueSub.unsubscribe();
                 this.roRequestQueueSub = null;
               }
-            }, 50);
+            }, 100);
           } else {
             console.error('流地址有误::', res.frame, JSON.stringify(res));
             this.logger.error('流地址有误::', res.frame, JSON.stringify(res));
@@ -415,16 +416,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);
@@ -626,15 +627,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);
 
@@ -683,16 +684,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;
@@ -778,8 +779,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;
@@ -880,7 +881,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));
@@ -962,14 +963,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(
@@ -1197,12 +1198,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);
@@ -1223,7 +1224,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,
@@ -1251,15 +1252,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,
             );
           }
 

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

@@ -150,7 +150,12 @@ export class StreamService {
         steam.put(clipBuffer);
 
         let steamByteLength = 0;
-
+        console.log(
+          'stream-size %s : frame: %s',
+          ((coordBuff.byteLength + clipBuffer.byteLength) / 1024).toFixed(2) +
+          ' KB',
+          frame,
+        );
         steam.on('data', (data: Buffer) => {
           this.onSteaming.next(true);