|
@@ -11,6 +11,9 @@ import { BehaviorSubject } from 'rxjs';
|
|
|
import { ActionType } from './actionType';
|
|
|
import { CacheService } from 'src/cache/cache.service';
|
|
|
import { StreamService } from './stream/stream.service';
|
|
|
+import { InjectQueue } from '@nestjs/bull';
|
|
|
+import { Queue } from 'bull';
|
|
|
+import { RotateService } from 'src/rotate/rotate.service';
|
|
|
|
|
|
const frameMetaReply = {
|
|
|
traceIds: [''],
|
|
@@ -76,6 +79,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
constructor(
|
|
|
private cacheService: CacheService,
|
|
|
private streamService: StreamService,
|
|
|
+ private rotateService: RotateService,
|
|
|
+ @InjectQueue('rotate') private rotateQueue: Queue,
|
|
|
) {}
|
|
|
@Client(grpcClientOptions) private readonly client: ClientGrpc;
|
|
|
private sceneGrpcService: SceneGrpcService;
|
|
@@ -92,6 +97,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private testFrame = -1;
|
|
|
private RotateframeCnt = -1;
|
|
|
private mockserverTime = Date.now() - 1653000000478;
|
|
|
+ private lastRenderMedia = '';
|
|
|
+ // private rotateMap = new Map()<>;
|
|
|
|
|
|
setConfig(user_id: string, roomId: string) {
|
|
|
this.user_id = user_id;
|
|
@@ -135,6 +142,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// initReply.subscribe((reply) => {
|
|
|
// console.log('initReply', reply);
|
|
|
// });
|
|
|
+ this.rotateService.init(request.app_id, request.user_id);
|
|
|
} catch (error) {
|
|
|
console.log('error', error);
|
|
|
}
|
|
@@ -151,45 +159,52 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
return this.sceneGrpcService.move(request);
|
|
|
}
|
|
|
|
|
|
- async rotate1(request: RotateRequest) {
|
|
|
+ async rotate(request: RotateRequest) {
|
|
|
try {
|
|
|
// const reply = this.sceneGrpcService.rotate(request);
|
|
|
if (!this.onSteaming) {
|
|
|
this.RotateframeCnt = this.frameCnt;
|
|
|
- const redisMeta = await this.cacheService.rpop(
|
|
|
- `updateFrameMetadata:${this.user_id}`,
|
|
|
- );
|
|
|
- console.log('rotate信息', this.user_id, request);
|
|
|
+ // const redisMeta = await this.cacheService.get(
|
|
|
+ // `updateFrameMetadata:${this.user_id}`,
|
|
|
+ // );
|
|
|
+ // console.log('rotate信息', this.user_id, request.sampleRate);
|
|
|
+
|
|
|
+ const redisMeta = await this.rotateService.rotate(request);
|
|
|
+ console.log('rotate信息', redisMeta);
|
|
|
+ // await this.rotateQueue.add('processFrame', request, {
|
|
|
+ // jobId: request.trace_id,
|
|
|
+ // });
|
|
|
// console.log('rotate.user_id', this.user_id, redisMeta);
|
|
|
- if (redisMeta && redisMeta.length > 0) {
|
|
|
- const meta = JSON.parse(redisMeta);
|
|
|
- const mediaSrc: string = meta.mediaSrc || '';
|
|
|
+ if (redisMeta && 'mediaSrc' in redisMeta) {
|
|
|
+ // const meta = JSON.parse(redisMeta);
|
|
|
+ const mediaSrc: string = redisMeta.mediaSrc || '';
|
|
|
|
|
|
- console.log('meta', meta);
|
|
|
- console.log('mediaSrc', mediaSrc);
|
|
|
+ // console.log('meta', meta);
|
|
|
+ // console.log('mediaSrc', mediaSrc);
|
|
|
|
|
|
if (mediaSrc.length > 0) {
|
|
|
- this.frameCnt += 1;
|
|
|
- // this.onSteaming = true;
|
|
|
- const src = meta.mediaSrc.split('?')[0];
|
|
|
- const testclipPath = src.replace(
|
|
|
- '/mnt/oss/metaverse/scene/0000000001/100/',
|
|
|
- '',
|
|
|
- );
|
|
|
- console.log('testclipPath', testclipPath);
|
|
|
- const demoPath = path.join(
|
|
|
- __dirname,
|
|
|
- `../ws/video/${testclipPath}`,
|
|
|
- );
|
|
|
- delete meta.mediaSrc;
|
|
|
- const stream: StreamFrameType = {
|
|
|
- frame: this.frameCnt,
|
|
|
- clipPath: demoPath,
|
|
|
- metaData: JSON.stringify(meta),
|
|
|
- serverTime: this.mockserverTime,
|
|
|
- DIR: 3,
|
|
|
- };
|
|
|
- this.streamService.pushFrameToSteam(stream);
|
|
|
+ let src = mediaSrc.split('?')[0];
|
|
|
+ // 临时本地替换路经
|
|
|
+ src = src.replace('/0000000001/100/', '');
|
|
|
+ // 判断不是同一条源时才推出
|
|
|
+ console.log('[media]', this.lastRenderMedia, src);
|
|
|
+ if (this.lastRenderMedia !== src) {
|
|
|
+ console.log('不同源');
|
|
|
+ this.frameCnt += 1;
|
|
|
+ console.log('src', src);
|
|
|
+ this.lastRenderMedia = src;
|
|
|
+ const clipPath = path.join(__dirname, `../ws/video/${src}`);
|
|
|
+ console.log('src-clipPath', src, clipPath);
|
|
|
+ delete redisMeta.mediaSrc;
|
|
|
+ const stream: StreamFrameType = {
|
|
|
+ frame: this.frameCnt,
|
|
|
+ clipPath: clipPath,
|
|
|
+ metaData: JSON.stringify(redisMeta),
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
+ DIR: 3,
|
|
|
+ };
|
|
|
+ this.streamService.pushFrameToSteam(stream);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -203,7 +218,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async rotate(request: RotateRequest) {
|
|
|
+ async rotate1(request: RotateRequest) {
|
|
|
try {
|
|
|
// const reply = this.sceneGrpcService.rotate(request);
|
|
|
// const res = await this.cacheService.publish(
|
|
@@ -217,8 +232,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.frameCnt += 1;
|
|
|
this.RotateframeCnt = this.frameCnt;
|
|
|
// this.cacheService
|
|
|
- this.testFrame += 1;
|
|
|
- this.mockserverTime += 10;
|
|
|
+ this.testFrame += 3;
|
|
|
+ this.mockserverTime += 1;
|
|
|
this.onSteaming = true;
|
|
|
if (this.testFrame > 358) this.testFrame = 0;
|
|
|
const stream: StreamFrameType = {
|
|
@@ -242,7 +257,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// }
|
|
|
// });
|
|
|
} catch (error) {
|
|
|
- this.logger.error('rotate', error);
|
|
|
+ this.logger.error(
|
|
|
+ `rotate-${this.frameCnt},src:${this.testFrame}`,
|
|
|
+ JSON.stringify(error),
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -272,34 +290,57 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
handleMessage(message: string | Buffer) {
|
|
|
try {
|
|
|
if (typeof message === 'string') {
|
|
|
- const msg: RTCMessageRequest = JSON.parse(message);
|
|
|
- switch (msg.action_type) {
|
|
|
- case ActionType.walk:
|
|
|
- const walk = msg;
|
|
|
- this.walking(walk);
|
|
|
- break;
|
|
|
- case ActionType.breathPoint:
|
|
|
- this.handleBreath(msg);
|
|
|
- break;
|
|
|
- case ActionType.rotate:
|
|
|
- const rotateRequest: RotateRequest = msg;
|
|
|
- this.rotate(rotateRequest);
|
|
|
- break;
|
|
|
- case ActionType.userStatus:
|
|
|
- this.updateUserStatus(msg);
|
|
|
- break;
|
|
|
- case ActionType.status:
|
|
|
- this.updateStatus();
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ // wasm:特例, requestIframe
|
|
|
+ if (message.includes('wasm:')) {
|
|
|
+ const msg: RTCMessageRequest = JSON.parse(
|
|
|
+ message.replace('wasm:', ''),
|
|
|
+ );
|
|
|
+ if (msg.MstType === 0) {
|
|
|
+ this.logger.log('lost I frame');
|
|
|
+ this.handleIframeRequest();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const msg: RTCMessageRequest = JSON.parse(message);
|
|
|
+ switch (msg.action_type) {
|
|
|
+ case ActionType.walk:
|
|
|
+ const walk = msg;
|
|
|
+ this.walking(walk);
|
|
|
+ break;
|
|
|
+ case ActionType.breathPoint:
|
|
|
+ this.handleBreath(msg);
|
|
|
+ break;
|
|
|
+ case ActionType.rotate:
|
|
|
+ const rotateRequest: RotateRequest = msg;
|
|
|
+ this.rotate(rotateRequest);
|
|
|
+ break;
|
|
|
+ case ActionType.userStatus:
|
|
|
+ this.updateUserStatus(msg);
|
|
|
+ break;
|
|
|
+ case ActionType.status:
|
|
|
+ this.updateStatus();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- this.logger.error('handleMessage:rtc', error);
|
|
|
+ this.logger.error('handleMessage:rtc--error', message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ handleIframeRequest() {
|
|
|
+ this.frameCnt += 1;
|
|
|
+ this.onSteaming = true;
|
|
|
+ const stream: StreamFrameType = {
|
|
|
+ frame: this.frameCnt,
|
|
|
+ clipPath: path.join(__dirname, '../ws/video/100/100.0000.h264'),
|
|
|
+ metaData: JSON.stringify(frameMetaReply),
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
+ };
|
|
|
+ this.streamService.pushFrameToSteam(stream);
|
|
|
+ }
|
|
|
+
|
|
|
walking(request) {
|
|
|
console.log('walking', request);
|
|
|
console.log('walking-onSteaming', this.onSteaming);
|
|
@@ -599,20 +640,26 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
code: 0,
|
|
|
msg: '',
|
|
|
};
|
|
|
- // const redisMeta = await this.cacheService.rpop(
|
|
|
- // `updateFrameMetadata:${this.user_id}`,
|
|
|
- // );
|
|
|
+ const redisMeta = await this.cacheService.get(
|
|
|
+ `updateFrameMetadata:${this.user_id}`,
|
|
|
+ );
|
|
|
//TODO 接入redis数据
|
|
|
- // console.log('redisMeta', redisMeta);
|
|
|
- // if (redisMeta && redisMeta.length > 0) {
|
|
|
- // const meta = JSON.parse(redisMeta);
|
|
|
- // 'mediaSrc' in meta && delete meta.mediaSrc;
|
|
|
- // meta.action_type = 1024;
|
|
|
- // this.streamService.pushNormalDataToStream(meta);
|
|
|
- // } else {
|
|
|
- // this.streamService.pushNormalDataToStream(reply);
|
|
|
- // }
|
|
|
- this.streamService.pushNormalDataToStream(reply);
|
|
|
+ console.log(
|
|
|
+ 'redisMeta',
|
|
|
+ redisMeta && redisMeta.length,
|
|
|
+ `updateFrameMetadata:${this.user_id}`,
|
|
|
+ );
|
|
|
+
|
|
|
+ if (redisMeta && redisMeta.length > 0) {
|
|
|
+ console.log('updateUserStatus-真数据', redisMeta && redisMeta.length);
|
|
|
+ const meta = JSON.parse(redisMeta);
|
|
|
+ 'mediaSrc' in meta && delete meta.mediaSrc;
|
|
|
+ meta.action_type = 1024;
|
|
|
+ this.streamService.pushNormalDataToStream(redisMeta);
|
|
|
+ } else {
|
|
|
+ this.streamService.pushNormalDataToStream(reply);
|
|
|
+ }
|
|
|
+ // this.streamService.pushNormalDataToStream(reply);
|
|
|
}
|
|
|
handleStartCountingFrame() {
|
|
|
this._frameInteval = setInterval(async () => {
|
|
@@ -624,7 +671,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
frame: 1,
|
|
|
clipPath: path.join(__dirname, '../ws/video/100/100.0000.h264'),
|
|
|
metaData: JSON.stringify(frameMetaReply),
|
|
|
- serverTime: 754871824,
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
};
|
|
|
this.streamService.pushFrameToSteam(stream);
|
|
|
}
|