Skip to content

Commit

Permalink
Add some stats to sleep logger
Browse files Browse the repository at this point in the history
  • Loading branch information
longnguyen2004 committed Jan 24, 2025
1 parent 1e005b5 commit e34019b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/media/BaseMediaStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,24 @@ export class BaseMediaStream extends Writable {
}, `Frame takes too long to send (${(ratio * 100).toFixed(2)}% frametime)`)
}
const now = performance.now();
const sleep = Math.max(0, this._pts - this._startPts + frametime - (now - this._startTime));
this._loggerSleep.debug(`Sleeping for ${sleep}ms`);
if (this._noSleep)
{
callback(null);
}
else
{
const sleep = Math.max(0, this._pts - this._startPts + frametime - (now - this._startTime));
this._loggerSleep.debug({
stats: {
pts: this._pts,
startPts: this._startPts,
time: now,
startTime: this._startTime,
frametime
}
}, `Sleeping for ${sleep}ms`);
setTimeout(sleep).then(() => callback(null));
}
}
_destroy(error: Error | null, callback: (error?: Error | null) => void): void {
super._destroy(error, callback);
Expand Down

0 comments on commit e34019b

Please sign in to comment.