|
@@ -160,24 +160,14 @@ export class StreamService {
|
|
|
|
|
|
const metaDataString = metaData.replace(/\s/g, '');
|
|
|
const coordBuff = Buffer.from(metaDataString, 'utf-8');
|
|
|
- // console.warn('coordBuff', coordBuff.byteLength);
|
|
|
- // const steamStat = statSync(clipPath);
|
|
|
- // const steamTotalSize = metaData.length + steamStat.size;
|
|
|
-
|
|
|
const clipBuffer = readFileSync(clipPath);
|
|
|
|
|
|
const allData = Buffer.concat([coordBuff, clipBuffer]);
|
|
|
- // console.log('allData', allData);
|
|
|
- // const stream1 = new ReadableStream(allData, {
|
|
|
- // highWaterMark: this.chunk_size - this.block,
|
|
|
- // });
|
|
|
+
|
|
|
const slices = Math.floor(
|
|
|
allData.byteLength / (this.chunk_size - this.block),
|
|
|
);
|
|
|
|
|
|
- console.log('allData', allData.byteLength);
|
|
|
- console.log('slices', slices);
|
|
|
-
|
|
|
let steamByteLength = 0;
|
|
|
|
|
|
for (let i = 0; i <= slices; i++) {
|
|
@@ -224,28 +214,29 @@ export class StreamService {
|
|
|
framePack.setUint32(this.block - 4, steamByteLength);
|
|
|
steamByteLength += currentSlice.byteLength;
|
|
|
// const isLastFrame = framePack.byteLength - this.chunk_size < 0;
|
|
|
-
|
|
|
+ let isPush: boolean;
|
|
|
// this.logger.log('statusPack', statusPack);
|
|
|
if (this.channel && this.channel.isOpen()) {
|
|
|
- const isPush = this.channel.sendMessageBinary(
|
|
|
+ isPush = this.channel.sendMessageBinary(
|
|
|
Buffer.from(framePack.buffer),
|
|
|
);
|
|
|
- if (isPush) {
|
|
|
- console.log('slice push');
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
if (i === slices) {
|
|
|
- this.onSteaming.next(false);
|
|
|
- steamByteLength = 0;
|
|
|
- // debugger;
|
|
|
- const stop = performance.now();
|
|
|
- const inMillSeconds = stop - start;
|
|
|
- const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
- this.logger.log(
|
|
|
- `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
|
|
|
- );
|
|
|
- return resolve({ frame: stream.frame, done: true });
|
|
|
+ if (isPush) {
|
|
|
+ this.onSteaming.next(false);
|
|
|
+ steamByteLength = 0;
|
|
|
+ // debugger;
|
|
|
+ const stop = performance.now();
|
|
|
+ const inMillSeconds = stop - start;
|
|
|
+ const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
+ this.logger.log(
|
|
|
+ `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
|
|
|
+ );
|
|
|
+ return resolve({ frame: stream.frame, done: true });
|
|
|
+ } else {
|
|
|
+ return resolve({ frame: stream.frame, done: false });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// let steamByteLength = 0;
|
|
@@ -256,74 +247,6 @@ export class StreamService {
|
|
|
frame,
|
|
|
dir,
|
|
|
);
|
|
|
- // steam.on('data', (data: Buffer) => {
|
|
|
- // this.onSteaming.next(true);
|
|
|
-
|
|
|
- // // this.logger.log('data', data, data.byteLength);
|
|
|
- // const blockBuffStart = Buffer.alloc(this.block);
|
|
|
- // const packBuffer = Buffer.concat([blockBuffStart, data]);
|
|
|
-
|
|
|
- // const framePack = new DataView(
|
|
|
- // packBuffer.buffer.slice(
|
|
|
- // packBuffer.byteOffset,
|
|
|
- // packBuffer.byteOffset + packBuffer.byteLength,
|
|
|
- // ),
|
|
|
- // );
|
|
|
-
|
|
|
- // // 16 bit slot
|
|
|
- // // framePack.setUint32(4)
|
|
|
- // framePack.setUint16(6, this.block);
|
|
|
- // framePack.setUint16(8, frame); // first render cnt
|
|
|
- // framePack.setUint16(10, dir); // isDIR
|
|
|
- // framePack.setUint16(24, 0);
|
|
|
- // framePack.setUint16(26, 0);
|
|
|
-
|
|
|
- // // 32 bit slot
|
|
|
- // // statusPack.setUint32(12, buff.byteLength);
|
|
|
- // // this.logger.log('metaLen', coordBuff.byteLength);
|
|
|
- // // this.logger.log('metaLen', clipBuffer.byteLength);
|
|
|
-
|
|
|
- // framePack.setUint32(0, 1437227610);
|
|
|
- // framePack.setUint32(12, coordBuff.byteLength); // metaLen
|
|
|
- // framePack.setUint32(16, clipBuffer.byteLength); // mediaLen
|
|
|
- // framePack.setUint32(20, serverTime); //server_time
|
|
|
- // framePack.setUint32(24, 0);
|
|
|
- // framePack.setUint32(28, 0);
|
|
|
- // framePack.setUint32(this.block - 4, steamByteLength);
|
|
|
- // const isLastFrame = framePack.byteLength - this.chunk_size < 0;
|
|
|
-
|
|
|
- // // this.logger.log('statusPack', statusPack);
|
|
|
- // if (this.channel && this.channel.isOpen()) {
|
|
|
- // this.channel.sendMessageBinary(Buffer.from(framePack.buffer));
|
|
|
- // }
|
|
|
- // steamByteLength += data.byteLength;
|
|
|
- // if (isLastFrame) {
|
|
|
- // // this.logger.log('isLastFrame', isLastFrame);
|
|
|
- // // steamByteLength = 0;
|
|
|
- // // this.onSteaming.next(false);
|
|
|
- // steam.stop();
|
|
|
- // }
|
|
|
- // });
|
|
|
- // //TODO steam can't trigger end
|
|
|
- // steam.on('end', () => {
|
|
|
- // steamByteLength = 0;
|
|
|
- // // this.logger.log('stream end');
|
|
|
- // const stop = performance.now();
|
|
|
- // const inMillSeconds = stop - start;
|
|
|
- // const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
- // this.logger.log(
|
|
|
- // `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
|
|
|
- // );
|
|
|
- // if (this.onSteaming.value) {
|
|
|
- // this.onSteaming.next(false);
|
|
|
- // }
|
|
|
-
|
|
|
- // return resolve({ frame: stream.frame, done: true });
|
|
|
- // });
|
|
|
- // steam.on('error', (error) => {
|
|
|
- // this.logger.error('steam-error', error.message);
|
|
|
- // return reject({ frame: stream.frame, done: false });
|
|
|
- // });
|
|
|
} catch (error) {
|
|
|
this.logger.error(error);
|
|
|
return reject({ frame: stream.frame, done: false });
|