gemercheung %!s(int64=3) %!d(string=hai) anos
pai
achega
4e04d26e02
Modificáronse 3 ficheiros con 1250 adicións e 73 borrados
  1. 1169 0
      src/scene/scene.service-b1.ts
  2. 2 2
      src/scene/scene.service copy 2.ts
  3. 79 71
      src/scene/scene.service.ts

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1169 - 0
src/scene/scene.service-b1.ts


+ 2 - 2
src/scene/scene.service copy 2.ts

@@ -609,8 +609,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           //const lastReply = JSON.stringify(joystickRes);
           //this.moveService.updateUser(userId, breakPointId, lastReply);
         }
-        clearTimeout(this._JoyStickingSteamTimeout);
-        this._JoyStickingSteamTimeout = setTimeout(() => {
+        clearTimeout(this._JoyStickingTimeout);
+        this._JoyStickingTimeout = setTimeout(() => {
           // const complementFrame = this.moveService.complementFrame(
           //   this.user_id,
           // ) as StreamReplyType;

+ 79 - 71
src/scene/scene.service.ts

@@ -34,6 +34,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   public _rotateTimeout: NodeJS.Timeout;
   public _moveTimeout: NodeJS.Timeout;
   public _JoyStickingTimeout: NodeJS.Timeout;
+  public _JoyStickingSteamTimeout: NodeJS.Timeout;
   public startSteaming = new BehaviorSubject<boolean>(false);
   public onRotating = new BehaviorSubject<boolean>(false);
   public onMoving = new BehaviorSubject<boolean>(false);
@@ -102,7 +103,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   private isJoystickHasStream = false;
 
-
   public users = {};
 
   public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
@@ -568,6 +568,74 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
    */
 
   async handlejoystick(request: JoystickRequest) {
+    // 二级方法start,为了 drain干complementFrame的pool
+    const pushJoyStickSteam = async (joystickRes: StreamReplyType) => {
+      this.holdSteam();
+      console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
+      const mediaSrc = joystickRes.mediaSrc.split('?')[0];
+      // IDR flag设置为I帧
+      const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
+      // 过滤新东西, 推完给回false
+      this.moveService.sendingFrameForJoystick = true;
+
+      if (this.joystickFrameCnt === -1) {
+        this.joystickFrameCnt = this.frameCnt.getValue();
+      }
+      this.joystickFrameCnt += 1;
+      const streamData: StreamFrameType = {
+        frame: this.joystickFrameCnt,
+        clipPath: mediaSrc,
+        metaData: JSON.stringify(joystickRes),
+        serverTime: this.mockserverTime,
+        DIR: setDIR,
+      };
+
+      const hasPush = await this.streamService.pushFrameToSteam(streamData);
+      if (hasPush.done) {
+        this.isJoystickHasStream = true;
+        console.log('joystick-hasPush', hasPush);
+        if (this.isJoystickHasStream) {
+          await this.sleep(30);
+        }
+        this.moveService.sendingFrameForJoystick = false;
+        const data = joystickRes as StreamReplyType;
+        console.log('handlejoystick-moveOver:' + data.moveOver);
+        if (data?.moveOver && data.moveOver) {
+          // moveOver
+          console.log('回传updateUser', data);
+          // const userId = this.user_id;
+          // 回传点暂时有问题,待修复
+          //const breakPointId = data.endBreakPointId || data.breakPointId;
+          //const lastReply = JSON.stringify(joystickRes);
+          //this.moveService.updateUser(userId, breakPointId, lastReply);
+        }
+        clearTimeout(this._JoyStickingTimeout);
+        this._JoyStickingTimeout = setTimeout(() => {
+          // const complementFrame = this.moveService.complementFrame(
+          //   this.user_id,
+          // ) as StreamReplyType;
+          // console.log('has-complementFrame', complementFrame);
+          // if (complementFrame) {
+          //   pushJoyStickSteam(complementFrame);
+          // } else {
+          this.frameCnt.next(hasPush.frame);
+          this.logger.log('joystick opt done');
+          this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
+          // this.frameCnt.next(res.frame);
+          this.onJoysticking.next(false);
+          this.resumeStream();
+          this.joystickFrameCnt = -1;
+          this.isJoystickHasStream = false;
+          // }
+        }, 200);
+      } else {
+        console.error('joystick-流地址有误::', joystickRes.mediaSrc);
+        this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
+        this.resumeStream();
+      }
+    };
+    // 二级方法end
+
     try {
       //const joystickRes = await this.moveService.joystick(request);
       this._rotateCount = 0;
@@ -577,7 +645,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.moveService.users[this.user_id].breakPointId,
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
-      this.logger.log('joystickRes-1', joystickRes);
+      this.logger.log('joystickRes', JSON.stringify(joystickRes));
 
       if (joystickRes) {
         this.onJoysticking.next(true);
@@ -597,71 +665,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           ),
         );
         if (joystickRes.mediaSrc) {
-          this.holdSteam();
-          console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
-          const mediaSrc = joystickRes.mediaSrc.split('?')[0];
-          // IDR flag设置为I帧
-          const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
-          // 过滤新东西, 推完给回false
-          this.moveService.sendingFrameForJoystick = true;
-
-          if (this.joystickFrameCnt === -1) {
-            this.joystickFrameCnt = this.frameCnt.getValue();
-          }
-          this.joystickFrameCnt += 1;
-          const streamData: StreamFrameType = {
-            frame: this.joystickFrameCnt,
-            clipPath: mediaSrc,
-            metaData: JSON.stringify(joystickRes),
-            serverTime: this.mockserverTime,
-            DIR: setDIR,
-          };
-
-          const hasPush = await this.streamService.pushFrameToSteam(streamData);
-          if (hasPush.done) {
-            this.isJoystickHasStream = true;
-            console.log('joystick-hasPush', hasPush);
-            if (this.isJoystickHasStream) {
-              await this.sleep(30);
-            }
-            this.moveService.sendingFrameForJoystick = false;
-            const data = joystickRes as StreamReplyType;
-            console.log('handlejoystick-moveOver:' + data.moveOver);
-            if (data?.moveOver && data.moveOver) {
-              // moveOver
-              console.log('回传updateUser', data);
-              // const userId = this.user_id;
-              // 回传点暂时有问题,待修复
-              //const breakPointId = data.endBreakPointId || data.breakPointId;
-              //const lastReply = JSON.stringify(joystickRes);
-              //this.moveService.updateUser(userId, breakPointId, lastReply);
-            }
-            clearTimeout(this._JoyStickingTimeout);
-            this._JoyStickingTimeout = setTimeout(() => {
-              this.frameCnt.next(hasPush.frame);
-              this.logger.log('joystick opt done');
-              this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
-              // this.frameCnt.next(res.frame);
-              this.onJoysticking.next(false);
-              this.resumeStream();
-              this.joystickFrameCnt = -1;
-              this.isJoystickHasStream = false;
-            }, 200);
-          } else {
-            console.error(
-              'joystick-流地址有误::',
-              hasPush.frame,
-              joystickRes.mediaSrc,
-            );
-            this.logger.error(
-              'joystick-流地址有误::',
-              hasPush.frame,
-              joystickRes.mediaSrc,
-            );
-            this.resumeStream();
-          }
+          pushJoyStickSteam(joystickRes);
         } else {
-          this.logger.log('joystick-接收人物数据', this.onMoving.getValue());
           if (!this.onMoving.getValue()) {
             // 在非行走时接受
             this.holdSteam();
@@ -679,12 +684,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             //this.logger.log('rotate', stream, Date.now());
             const res = await this.streamService.pushMetaDataToSteam(stream);
             if (res.done) {
-              this.logger.log('joystick-frame', res.frame);
+              this.logger.log('joystick-位置流', res.frame);
               this.frameCnt.next(res.frame);
               clearTimeout(this._JoyStickingTimeout);
               this._JoyStickingTimeout = setTimeout(() => {
-                this.logger.log('joystick opt done');
-                this.logger.log('joystick 交权给空流,当前pts', res.frame);
+                this.logger.log('joystick-位置流 opt done');
+                this.logger.log(
+                  'joystick-位置流 交权给空流,当前pts',
+                  res.frame,
+                );
                 // this.frameCnt.next(res.frame);
                 this.onJoysticking.next(false);
                 this.resumeStream();
@@ -701,6 +709,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 res.frame,
                 joystickRes.mediaSrc,
               );
+              this.onJoysticking.next(false);
+              this.joystickFrameCnt = -1;
               this.resumeStream();
             }
           }
@@ -716,8 +726,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     }
   }
 
-
-
   /**
    * 主要处理moving的序列动作
    * @param seqs StreamReplyType[]