Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async sync(): Promise {
let gotFirstSync = false;
while (true) {
let bo = 0;
this.syncPeek.len = await this.tokenizer.peekBuffer(this.syncPeek.buf, 0, maxPeekLen, this.tokenizer.position, true);
if (this.syncPeek.len <= 256) {
throw new EndOfStreamError();
}
while (true) {
if (gotFirstSync && (this.syncPeek.buf[bo] & 0xE0) === 0xE0) {
this.buf_frame_header[0] = MpegFrameHeader.SyncByte1;
this.buf_frame_header[1] = this.syncPeek.buf[bo];
await this.tokenizer.ignore(bo);
debug(`Sync at offset=${this.tokenizer.position - 1}, frameCount=${this.frameCount}`);
if (this.syncFrameCount === this.frameCount) {
debug(`Re-synced MPEG stream, frameCount=${this.frameCount}`);
this.frameCount = 0;
this.frame_size = 0;
}
this.syncFrameCount = this.frameCount;
return; // sync
} else {
gotFirstSync = false;