|
@@ -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;
|
|
@@ -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));
|
|
@@ -269,16 +269,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);
|
|
@@ -327,7 +327,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);
|
|
@@ -431,15 +431,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);
|
|
|
|
|
@@ -509,16 +509,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;
|
|
@@ -568,16 +568,86 @@ 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._JoyStickingSteamTimeout);
|
|
|
+ this._JoyStickingSteamTimeout = 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasPush;
|
|
|
+ };
|
|
|
+ // 二级方法end
|
|
|
+
|
|
|
try {
|
|
|
//const joystickRes = await this.moveService.joystick(request);
|
|
|
this._rotateCount = 0;
|
|
|
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-1', joystickRes);
|
|
|
+ this.logger.log('joystickRes', JSON.stringify(joystickRes));
|
|
|
|
|
|
if (joystickRes) {
|
|
|
this.onJoysticking.next(true);
|
|
@@ -590,76 +660,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// ),
|
|
|
console.log(
|
|
|
'handlejoysticktesttest:' +
|
|
|
- joystickRes.mediaSrc +
|
|
|
- ',相机坐标:' +
|
|
|
- JSON.stringify(
|
|
|
- joystickRes.newUserStates[0].playerState.player.position,
|
|
|
- ),
|
|
|
+ joystickRes.mediaSrc +
|
|
|
+ ',相机坐标:' +
|
|
|
+ JSON.stringify(
|
|
|
+ joystickRes.newUserStates[0].playerState.player.position,
|
|
|
+ ),
|
|
|
);
|
|
|
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()) {
|
|
@@ -716,8 +724,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 主要处理moving的序列动作
|
|
|
* @param seqs StreamReplyType[]
|
|
@@ -791,14 +797,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(
|
|
@@ -994,7 +1000,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;
|
|
@@ -1005,12 +1012,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(
|
|
@@ -1072,12 +1079,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);
|
|
@@ -1092,7 +1099,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,
|
|
@@ -1120,15 +1127,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,
|
|
|
);
|
|
|
}
|
|
|
|