gemercheung 3 年之前
父节点
当前提交
14af8f42f1
共有 2 个文件被更改,包括 38 次插入31 次删除
  1. 3 3
      config.yaml
  2. 35 28
      src/scene/scene.service.ts

+ 3 - 3
config.yaml

@@ -2,7 +2,7 @@ app:
   prefix: /mnt/metaverse/scene
 
 queueConfig:
-  move: 15
+  move: 10
   rotate: 5
 
 http:
@@ -14,8 +14,8 @@ grpc:
 
 redis:
   port: 6379
-  host: '120.24.252.95' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
-  password: 'sxz123321SxZ@' # 非远程不需要密码
+  host: '192.168.0.47' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+  password: '' # 非远程不需要密码
   decode_responses: true
   db: 9
   # server: ['stun:47.107.125.202:3478','stun:120.24.252.95:3478']

+ 35 - 28
src/scene/scene.service.ts

@@ -25,7 +25,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;
@@ -36,11 +36,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   public startSteaming = new BehaviorSubject<boolean>(false);
   public onRotating = new BehaviorSubject<boolean>(false);
   public onMoving = new BehaviorSubject<boolean>(false);
+  public onJoysticking = new BehaviorSubject<boolean>(false);
   public frameCnt = new BehaviorSubject<number>(-1);
   private rotateframeCnt = -1;
   private moveframeCnt = -1;
   private joystickFrameCnt = -1;
-  private moveKeyFrame = -1;
+  private rotateFirstIDR = true;
 
   private sceneGrpcService: SceneGrpcService;
   private channel: DataChannel;
@@ -518,6 +519,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const joystickRes = await this.moveService.seqExeJoystick(request);
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       console.log('joystickRes-1', joystickRes);
+      this.onJoysticking.next(true);
       if (Array.isArray(joystickRes)) {
         // 处理第一个镜头数据
         const rotateCamData = joystickRes[0];
@@ -571,8 +573,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           console.warn('joystick-move无数据');
         }
       } else {
-        console.warn('joystick-接收人物数据', this.onMoving);
-        if (!this.onMoving.value) {
+        console.warn('joystick-接收人物数据', this.onMoving.getValue());
+        if (!this.onMoving.getValue()) {
+          // 在非行走时接受
           this.holdSteam();
           if (this.joystickFrameCnt === -1) {
             this.joystickFrameCnt = this.frameCnt.getValue();
@@ -583,19 +586,19 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             metaData: JSON.stringify(joystickRes),
           };
           // console.log('rotate', stream, Date.now());
-          clearTimeout(this._JoyStickingTimeout);
           const res = await this.streamService.pushMetaDataToSteam(stream);
           if (res.done) {
             console.log('joystick-frame', res.frame);
             this.frameCnt.next(res.frame);
+            clearTimeout(this._JoyStickingTimeout);
             this._JoyStickingTimeout = setTimeout(() => {
               console.log('joystick opt done');
               console.log('joystick 交权给空流,当前pts', res.frame);
-              const next = res.frame + 1;
-              this.frameCnt.next(next);
+              // this.frameCnt.next(res.frame);
+              this.onJoysticking.next(false);
               this.resumeStream();
               this.joystickFrameCnt = -1;
-            }, 300);
+            }, 100);
           }
         }
       }
@@ -616,7 +619,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     this.onMoving.next(true);
     this.holdSteam();
     //TODO Remove
-    clearTimeout(this._JoyStickingTimeout);
+    // clearTimeout(this._JoyStickingTimeout);
 
     seqs.forEach((frame: StreamReplyType) => {
       const mediaSrc = frame.mediaSrc;
@@ -671,14 +674,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         };
         console.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,
         );
         console.log(
@@ -696,13 +699,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (isLastFrameIndex > -1) {
           // console.log('path-update-array', this.lastMovingPointArray);
           const currentMeta = this.lastMovingPointArray[isLastFrameIndex];
-          // console.log('currentMeta', currentMeta);
-          // const lastFrame = this.lastMoveStreamFrame.getValue();
-          // const lastFrameMeta: StreamReplyType = JSON.parse(lastFrame.metaData);
           const userId = this.user_id;
           const breakPointId = currentMeta.metaData.endBreakPointId;
           const lastReply = currentMeta.metaData;
-          // console.log('path-update', breakPointId);
           this.moveService.updateUser(userId, breakPointId, lastReply);
           //debugger
           this.lastMovingPointArray.splice(isLastFrameIndex, 1);
@@ -718,6 +717,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             this.resumeStream();
             this.rotateframeCnt = -1;
             this.onMoving.next(false);
+            this.onJoysticking.next(false);
             this.cleanMoveSteam();
             this.lastMovingPointArray = [];
             this.hasJoystickMoveRequest = false;
@@ -858,14 +858,19 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.rotateframeCnt += 1;
 
           stream.frame = this.rotateframeCnt;
+          stream.DIR = this.rotateFirstIDR ? 1 : 3;
+          if (this.rotateFirstIDR) {
+            this.rotateFirstIDR = false;
+          }
+
           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(
@@ -883,6 +888,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.rotateframeCnt = -1;
               this.onMoving.next(false);
               this.onRotating.next(false);
+              this.rotateFirstIDR = true;
               //TODO rotate完后清除request队列
               if (this.roRequestQueueSub) {
                 this.roRequestQueueSub.unsubscribe();
@@ -934,7 +940,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,
@@ -956,6 +962,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             frame > 1 &&
             !this.onMoving.value &&
             !this.onRotating.value &&
+            !this.onJoysticking.value &&
             this.firstRender
           ) {
             const redisDataAuto = await this.rotateService.echo(