mediabunny 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9138,13 +9138,21 @@ ${cue.notes ?? ""}`;
9138
9138
  this.customDecoder = null;
9139
9139
  this.customDecoderCallSerializer = new CallSerializer();
9140
9140
  this.customDecoderQueueSize = 0;
9141
+ // Internal state to accumulate a precise current timestamp based on audio durations, not the (potentially
9142
+ // inaccurate) packet timestamps.
9143
+ this.currentTimestamp = null;
9141
9144
  const sampleHandler = (sample) => {
9145
+ if (this.currentTimestamp === null || Math.abs(sample.timestamp - this.currentTimestamp) >= sample.duration) {
9146
+ this.currentTimestamp = sample.timestamp;
9147
+ }
9148
+ const preciseTimestamp = this.currentTimestamp;
9149
+ this.currentTimestamp += sample.duration;
9142
9150
  if (sample.numberOfFrames === 0) {
9143
9151
  sample.close();
9144
9152
  return;
9145
9153
  }
9146
9154
  const sampleRate = decoderConfig.sampleRate;
9147
- sample.setTimestamp(Math.round(sample.timestamp * sampleRate) / sampleRate);
9155
+ sample.setTimestamp(Math.round(preciseTimestamp * sampleRate) / sampleRate);
9148
9156
  onSample(sample);
9149
9157
  };
9150
9158
  const MatchingCustomDecoder = customAudioDecoders.find((x) => x.supports(codec, decoderConfig));
@@ -9206,7 +9214,7 @@ ${cue.notes ?? ""}`;
9206
9214
  super(onSample, onError);
9207
9215
  this.decoderConfig = decoderConfig;
9208
9216
  // Internal state to accumulate a precise current timestamp based on audio durations, not the (potentially
9209
- // inaccurate) sample timestamps.
9217
+ // inaccurate) packet timestamps.
9210
9218
  this.currentTimestamp = null;
9211
9219
  assert(PCM_AUDIO_CODECS.includes(decoderConfig.codec));
9212
9220
  this.codec = decoderConfig.codec;