Browse Source

Merge branch 'jointWorker' of http://192.168.0.115:3000/zhangyupeng/meta-server into jointWorker

test pc 3 years ago
parent
commit
a9ca2cfbc8
4 changed files with 53 additions and 29 deletions
  1. 2 2
      src/meta.gateway.ts
  2. 15 15
      src/rotate/rotate.service.ts
  3. 29 11
      src/scene/scene.service.ts
  4. 7 1
      src/scene/stream/stream.service.ts

+ 2 - 2
src/meta.gateway.ts

@@ -99,9 +99,9 @@ export class MetaGateway
       portRangeBegin: portRangeBegin,
       portRangeEnd: portRangeEnd,
       iceServers: stun_server,
-      enableIceTcp: true,
+      // enableIceTcp: true,
       maxMessageSize: 662144,
-      mtu: 1500,
+      mtu: 1200,
     });
 
     this.peer.onLocalDescription((sdp, type) => {

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

@@ -163,21 +163,21 @@ 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,

+ 29 - 11
src/scene/scene.service.ts

@@ -34,6 +34,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   public _rotateTimeout: NodeJS.Timeout;
   public _moveTimeout: NodeJS.Timeout;
   public _JoyStickingSteamTimeout: NodeJS.Timeout;
+  public _packFrameTimeout: NodeJS.Timeout;
   public startSteaming = new BehaviorSubject<boolean>(false);
   public onRotating = new BehaviorSubject<boolean>(false);
   public onMoving = new BehaviorSubject<boolean>(false);
@@ -100,7 +101,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   private isJoystickHasStream = false;
   private hasJoystickFocusRepeat = false;
-  private startSub: any
+  private startSub: any;
 
   public users = {};
 
@@ -213,6 +214,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   exit() {
     this.frameCnt.next(-1);
     this.rotateService.deleteUser(this.user_id);
+    this.hasJoystickFocusRepeat = false;
     if (this.startSub) {
       this.startSub.unsubscribe();
       this.startSub = null;
@@ -365,7 +367,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));
@@ -501,7 +503,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         async (frame: MovingLastUpdateType) => {
           //TODO 正在行走时,有新的reqest
           if (frame) {
-            console.log('unlock-Joints', JSON.stringify(frame));
+            // console.log('unlock-Joints', JSON.stringify(frame));
             this.logger.log('Joints', JSON.stringify(frame));
             let isRotateStop = false;
             let isWalkingStop = false;
@@ -646,6 +648,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.logger.log('walking-path', path);
       if (!path) {
         console.log('不存在--path', path);
+        this.cleanMoveSteam();
+        this.clearWalkingJoints();
         this.resumeStream();
         return;
       }
@@ -1084,7 +1088,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           const msg: RTCMessageRequest = JSON.parse(parseData);
           this.logger.error('lostIframe-message', JSON.stringify(msg));
           if (Number(msg.MstType) === 0) {
-            // this.handleIframeRequest();
+            this.handleIframeRequest();
           }
         } else {
           const msg: RTCMessageRequest = JSON.parse(message);
@@ -1123,16 +1127,30 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   async handleIframeRequest() {
     //TODO Iframe 最终传什么?
+    this.holdSteam();
     this.requestIFrameQueue.next(this.streamService.lastStreamFrame.getValue());
     if (!this.requestIFrameQueueSub) {
       this.requestIFrameQueueSub = this.requestIFrameQueue.subscribe(
-        (frameData: StreamFrameType) => {
-          const nextFrame = this.frameCnt.getValue() + 1;
-          this.logger.warn('lostIframe', nextFrame);
-          frameData.frame = nextFrame;
-          this.streamService.pushFrameToSteam(frameData);
-          this.frameCnt.next(nextFrame);
-          this.resumeStream();
+        async (frameData: StreamFrameType) => {
+          if (frameData) {
+            const nextFrame = this.frameCnt.getValue() + 1;
+            this.logger.warn('lostIframe', nextFrame);
+            frameData.frame = nextFrame;
+            frameData.DIR = 1;
+            const res = await this.streamService.pushFrameToSteam(frameData);
+            if (res.done) {
+              this.logger.error(
+                ' frame:' + res.frame + '  补帧::' + JSON.stringify(frameData),
+              );
+              this.frameCnt.next(res.frame);
+              clearTimeout(this._packFrameTimeout);
+              this._packFrameTimeout = setTimeout(() => {
+                this.resumeStream();
+              }, 100);
+            } else {
+              console.error('补帧有误:', JSON.stringify(frameData));
+            }
+          }
         },
       );
     }

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

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