|
@@ -33,7 +33,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
public _frameTimeout: NodeJS.Timeout;
|
|
|
public _rotateTimeout: NodeJS.Timeout;
|
|
|
public _moveTimeout: NodeJS.Timeout;
|
|
|
- public _JoyStickingTimeout: NodeJS.Timeout;
|
|
|
+ // public _JoyStickingTimeout: NodeJS.Timeout;
|
|
|
public _JoyStickingSteamTimeout: NodeJS.Timeout;
|
|
|
public startSteaming = new BehaviorSubject<boolean>(false);
|
|
|
public onRotating = new BehaviorSubject<boolean>(false);
|
|
@@ -563,99 +563,115 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /***
|
|
|
- * joystick
|
|
|
+ /**
|
|
|
+ * joystick 二合一推流
|
|
|
+ * @param joystickRes StreamMetaType | StreamFrameType;
|
|
|
*/
|
|
|
+ async handlePushJoyStickSteam(joystickRes: StreamReplyType) {
|
|
|
+ this.holdSteam();
|
|
|
+ console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
|
|
|
+ let streamData: StreamFrameType | StreamMetaType;
|
|
|
|
|
|
- async handlejoystick(request: JoystickRequest) {
|
|
|
- // 二级方法start,为了 drain干complementFrame的pool
|
|
|
- const pushJoyStickSteam = async (
|
|
|
- joystickRes: StreamReplyType,
|
|
|
- _noNeedSleep = false,
|
|
|
- ) => {
|
|
|
- this.holdSteam();
|
|
|
- console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
|
|
|
+ // if (this.joystickFrameCnt === -1) {
|
|
|
+ this.joystickFrameCnt = this.frameCnt.getValue();
|
|
|
+ // }
|
|
|
+ this.joystickFrameCnt += 1;
|
|
|
+ const hasMedia = joystickRes?.mediaSrc && joystickRes?.mediaSrc.length > 0;
|
|
|
+
|
|
|
+ if (hasMedia) {
|
|
|
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 = {
|
|
|
+ streamData = {
|
|
|
frame: this.joystickFrameCnt,
|
|
|
clipPath: mediaSrc,
|
|
|
metaData: JSON.stringify(joystickRes),
|
|
|
serverTime: this.mockserverTime,
|
|
|
DIR: setDIR,
|
|
|
};
|
|
|
+ } else {
|
|
|
+ streamData = {
|
|
|
+ frame: this.joystickFrameCnt,
|
|
|
+ metaData: JSON.stringify(joystickRes),
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- const hasPush = await this.streamService.pushFrameToSteam(streamData);
|
|
|
- if (hasPush.done) {
|
|
|
- this.isJoystickHasStream = true;
|
|
|
- console.log('joystick-hasPush', hasPush);
|
|
|
- if (this.isJoystickHasStream && !_noNeedSleep) {
|
|
|
- await this.sleep(20);
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
- // 共用_JoyStickingTimeout
|
|
|
- this.frameCnt.next(hasPush.frame);
|
|
|
- clearTimeout(this._JoyStickingSteamTimeout);
|
|
|
- this._JoyStickingSteamTimeout = setTimeout(async () => {
|
|
|
- const complementFrame = this.moveService.complementFrame(
|
|
|
- this.user_id,
|
|
|
- ) as StreamReplyType;
|
|
|
- console.log('has-complementFrame', complementFrame);
|
|
|
- if (complementFrame) {
|
|
|
- const start = performance.now();
|
|
|
- pushJoyStickSteam(complementFrame, true);
|
|
|
- const stop = performance.now();
|
|
|
- const inMillSeconds = stop - start;
|
|
|
- const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
- console.log(`complementFrame调用时间---->${rounded}`);
|
|
|
- } else {
|
|
|
- this.logger.log('joystick opt done');
|
|
|
- this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
|
|
|
- const stopFrameData = this.moveService.stopJoystick(this.user_id);
|
|
|
- const stopFrame: StreamMetaType = {
|
|
|
- frame: hasPush.frame + 1,
|
|
|
- metaData: JSON.stringify(stopFrameData),
|
|
|
- };
|
|
|
- const stopRes = await this.streamService.pushMetaDataToSteam(
|
|
|
- stopFrame,
|
|
|
- );
|
|
|
- console.log('stopFrame', stopFrame);
|
|
|
- if (stopRes.done) {
|
|
|
- this.onJoysticking.next(false);
|
|
|
- this.resumeStream();
|
|
|
- this.joystickFrameCnt = -1;
|
|
|
- this.isJoystickHasStream = false;
|
|
|
- }
|
|
|
- // this.frameCnt.next(res.frame);
|
|
|
- }
|
|
|
- }, 200);
|
|
|
- } else {
|
|
|
- console.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
- this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
- this.resumeStream();
|
|
|
+ // 过滤新东西, 推完给回false
|
|
|
+ this.moveService.sendingFrameForJoystick = true;
|
|
|
+
|
|
|
+ const hasPush = hasMedia
|
|
|
+ ? await this.streamService.pushFrameToSteam(streamData as StreamFrameType)
|
|
|
+ : await this.streamService.pushMetaDataToSteam(
|
|
|
+ streamData as StreamMetaType,
|
|
|
+ );
|
|
|
+
|
|
|
+ if (hasPush.done) {
|
|
|
+ this.isJoystickHasStream = true;
|
|
|
+ console.log('joystick-hasPush', hasPush);
|
|
|
+ if (this.isJoystickHasStream) {
|
|
|
+ await this.sleep(20);
|
|
|
}
|
|
|
- };
|
|
|
- // 二级方法end
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ this.frameCnt.next(hasPush.frame);
|
|
|
+
|
|
|
+ // 最后一帧200ms
|
|
|
+ clearTimeout(this._JoyStickingSteamTimeout);
|
|
|
+ this._JoyStickingSteamTimeout = setTimeout(async () => {
|
|
|
+ const complementFrame = this.moveService.complementFrame(
|
|
|
+ this.user_id,
|
|
|
+ ) as StreamReplyType;
|
|
|
+ console.log('has-complementFrame', complementFrame);
|
|
|
+ if (complementFrame) {
|
|
|
+ const start = performance.now();
|
|
|
+ this.handlePushJoyStickSteam(complementFrame);
|
|
|
+ const stop = performance.now();
|
|
|
+ const inMillSeconds = stop - start;
|
|
|
+ const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
+ console.log(`complementFrame调用时间---->${rounded}`);
|
|
|
+ } else {
|
|
|
+ this.logger.log('joystick opt done');
|
|
|
+ this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
|
|
|
+ // const stopFrameData = this.moveService.stopJoystick(this.user_id);
|
|
|
+ // const stopFrame: StreamMetaType = {
|
|
|
+ // frame: hasPush.frame + 1,
|
|
|
+ // metaData: JSON.stringify(stopFrameData),
|
|
|
+ // };
|
|
|
+ // const stopRes = await this.streamService.pushMetaDataToSteam(
|
|
|
+ // stopFrame,
|
|
|
+ // );
|
|
|
+ // console.log('stopFrame', stopFrame);
|
|
|
+ // if (stopRes.done) {
|
|
|
+ // }
|
|
|
+ this.onJoysticking.next(false);
|
|
|
+ this.resumeStream();
|
|
|
+ this.joystickFrameCnt = -1;
|
|
|
+ this.isJoystickHasStream = false;
|
|
|
+ // this.frameCnt.next(res.frame);
|
|
|
+ }
|
|
|
+ }, 200);
|
|
|
+ } else {
|
|
|
+ console.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
+ this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
+ this.resumeStream();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * joystick
|
|
|
+ */
|
|
|
|
|
|
+ async handlejoystick(request: JoystickRequest) {
|
|
|
try {
|
|
|
//const joystickRes = await this.moveService.joystick(request);
|
|
|
this._rotateCount = 0;
|
|
@@ -669,13 +685,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
if (joystickRes) {
|
|
|
this.onJoysticking.next(true);
|
|
|
- // console.log(
|
|
|
- // 'handlejoystick:' +
|
|
|
- // joystickRes.mediaSrc +
|
|
|
- // ',相机坐标:' +
|
|
|
- // JSON.stringify(
|
|
|
- // joystickRes.newUserStates[0].playerState.camera.position,
|
|
|
- // ),
|
|
|
console.log(
|
|
|
'handlejoysticktesttest:' +
|
|
|
joystickRes.mediaSrc +
|
|
@@ -684,82 +693,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
joystickRes.newUserStates[0].playerState.player.position,
|
|
|
),
|
|
|
);
|
|
|
- if (joystickRes.mediaSrc) {
|
|
|
- pushJoyStickSteam(joystickRes);
|
|
|
- } else {
|
|
|
- if (!this.onMoving.getValue()) {
|
|
|
- // 在非行走时接受
|
|
|
- this.holdSteam();
|
|
|
- // if (this.joystickFrameCnt === -1) {
|
|
|
- this.joystickFrameCnt = this.frameCnt.getValue();
|
|
|
- // }
|
|
|
- // 人物数据去掉mediaSrc以免前误会
|
|
|
- joystickRes?.mediaSrc && delete joystickRes.mediaSrc;
|
|
|
-
|
|
|
- this.joystickFrameCnt += 1;
|
|
|
- const stream: StreamMetaType = {
|
|
|
- frame: this.joystickFrameCnt,
|
|
|
- metaData: JSON.stringify(joystickRes),
|
|
|
- };
|
|
|
- //this.logger.log('rotate', stream, Date.now());
|
|
|
- const res = await this.streamService.pushMetaDataToSteam(stream);
|
|
|
- if (res.done) {
|
|
|
- this.logger.log('joystick-位置流', res.frame);
|
|
|
- this.frameCnt.next(res.frame);
|
|
|
- clearTimeout(this._JoyStickingTimeout);
|
|
|
- this._JoyStickingTimeout = setTimeout(async () => {
|
|
|
- this.logger.log('joystick-位置流 opt done');
|
|
|
- this.logger.log(
|
|
|
- 'joystick-位置流 交权给空流,当前pts',
|
|
|
- res.frame,
|
|
|
- );
|
|
|
- // const complementFrame = this.moveService.complementFrame(
|
|
|
- // this.user_id,
|
|
|
- // ) as StreamReplyType;
|
|
|
- // console.log('has-complementFrame', complementFrame);
|
|
|
- // if (complementFrame) {
|
|
|
- // pushJoyStickSteam(complementFrame);
|
|
|
- // } else {
|
|
|
- // this.moveService.stopJoystick(this.user_id);
|
|
|
- const stopFrameData = this.moveService.stopJoystick(
|
|
|
- this.user_id,
|
|
|
- );
|
|
|
- const stopFrame: StreamMetaType = {
|
|
|
- frame: res.frame + 1,
|
|
|
- metaData: JSON.stringify(stopFrameData),
|
|
|
- };
|
|
|
- const stopRes = await this.streamService.pushMetaDataToSteam(
|
|
|
- stopFrame,
|
|
|
- );
|
|
|
- if (stopRes.done) {
|
|
|
- this.resumeStream();
|
|
|
- this.joystickFrameCnt = -1;
|
|
|
- this.isJoystickHasStream = false;
|
|
|
- this.onJoysticking.next(false);
|
|
|
- }
|
|
|
-
|
|
|
- // }
|
|
|
- }, 200);
|
|
|
- } else {
|
|
|
- console.error(
|
|
|
- 'joystick-位置流有误::',
|
|
|
- res.frame,
|
|
|
- joystickRes.mediaSrc,
|
|
|
- );
|
|
|
- this.logger.error(
|
|
|
- 'joystick-位置流有误::',
|
|
|
- res.frame,
|
|
|
- joystickRes.mediaSrc,
|
|
|
- );
|
|
|
- this.onJoysticking.next(false);
|
|
|
- this.joystickFrameCnt = -1;
|
|
|
- this.resumeStream();
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!this.onMoving.getValue()) {
|
|
|
+ this.handlePushJoyStickSteam(joystickRes);
|
|
|
}
|
|
|
} else {
|
|
|
console.log('handlejoystick:null');
|
|
|
- this.onJoysticking.next(false);
|
|
|
+ // this.onJoysticking.next(false);
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('joystick错误', error);
|