import{AsyncMutex as r}from"./misc.js";export class Muxer{constructor(a){this.mutex=new r,this.firstMediaStreamTimestamp=null,this.trackTimestampInfo=new WeakMap,this.output=a}onTrackClose(a){}validateAndNormalizeTimestamp(a,e,m){e+=a.source._timestampOffset;let t=this.trackTimestampInfo.get(a);if(!t){if(!m)throw new Error("First frame must be a key frame.");t={maxTimestamp:e,maxTimestampBeforeLastKeyFrame:e},this.trackTimestampInfo.set(a,t)}if(e<0)throw new Error(`Timestamps must be non-negative (got ${e}s).`);if(m&&(t.maxTimestampBeforeLastKeyFrame=t.maxTimestamp),e<t.maxTimestampBeforeLastKeyFrame)throw new Error(`Timestamps cannot be smaller than the highest timestamp of the previous run (a run begins with a key frame and ends right before the next key frame). Got ${e}s, but highest timestamp is ${t.maxTimestampBeforeLastKeyFrame}s.`);return t.maxTimestamp=Math.max(t.maxTimestamp,e),e}}
