mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 19:33:51 +02:00
Make more use of sequenceNumber in getNextPacket
This commit is contained in:
@@ -14,7 +14,6 @@ import { PacketRetrievalOptions } from '../media-sink';
|
||||
import {
|
||||
assert,
|
||||
AsyncMutex4,
|
||||
binarySearchExact,
|
||||
binarySearchLessOrEqual,
|
||||
Bitstream,
|
||||
ResultValue,
|
||||
@@ -261,16 +260,13 @@ class AdtsAudioTrackBacking implements InputAudioTrackBacking {
|
||||
using lock = this.demuxer.readingMutex.lock();
|
||||
if (lock.pending) await lock.ready;
|
||||
|
||||
const sampleIndex = binarySearchExact(
|
||||
this.demuxer.loadedSamples,
|
||||
packet.timestamp,
|
||||
x => x.timestamp,
|
||||
);
|
||||
const sampleIndex = packet.sequenceNumber;
|
||||
if (sampleIndex === -1) {
|
||||
throw new Error('Packet was not created from this track.');
|
||||
}
|
||||
|
||||
const nextIndex = sampleIndex + 1;
|
||||
|
||||
// Ensure the next sample exists
|
||||
while (
|
||||
nextIndex >= this.demuxer.loadedSamples.length
|
||||
|
||||
@@ -644,6 +644,10 @@ class FlacAudioTrackBacking implements InputAudioTrackBacking {
|
||||
using lock = this.demuxer.readingMutex.lock();
|
||||
if (lock.pending) await lock.ready;
|
||||
|
||||
if (packet.sequenceNumber < 0) {
|
||||
throw new Error('Packet was not created from this track.');
|
||||
}
|
||||
|
||||
const nextIndex = packet.sequenceNumber + 1;
|
||||
if (
|
||||
this.demuxer.lastSampleLoaded
|
||||
|
||||
@@ -15,7 +15,6 @@ import { PacketRetrievalOptions } from '../media-sink';
|
||||
import {
|
||||
assert,
|
||||
AsyncMutex4,
|
||||
binarySearchExact,
|
||||
binarySearchLessOrEqual,
|
||||
ResultValue,
|
||||
UNDETERMINED_LANGUAGE,
|
||||
@@ -318,16 +317,13 @@ class Mp3AudioTrackBacking implements InputAudioTrackBacking {
|
||||
using lock = this.demuxer.readingMutex.lock();
|
||||
if (lock.pending) await lock.ready;
|
||||
|
||||
const sampleIndex = binarySearchExact(
|
||||
this.demuxer.loadedSamples,
|
||||
packet.timestamp,
|
||||
x => x.timestamp,
|
||||
);
|
||||
if (sampleIndex === -1) {
|
||||
const sampleIndex = packet.sequenceNumber;
|
||||
if (sampleIndex < 0) {
|
||||
throw new Error('Packet was not created from this track.');
|
||||
}
|
||||
|
||||
const nextIndex = sampleIndex + 1;
|
||||
|
||||
// Ensure the next sample exists
|
||||
while (
|
||||
nextIndex >= this.demuxer.loadedSamples.length
|
||||
|
||||
@@ -516,7 +516,11 @@ class WaveAudioTrackBacking implements InputAudioTrackBacking {
|
||||
options: PacketRetrievalOptions,
|
||||
): Promise<Yo> {
|
||||
assert(this.demuxer.audioInfo);
|
||||
const packetIndex = Math.round(packet.timestamp * this.demuxer.audioInfo.sampleRate / PACKET_SIZE_IN_FRAMES);
|
||||
|
||||
const packetIndex = packet.sequenceNumber;
|
||||
if (packetIndex < 0) {
|
||||
throw new Error('Packet was not created from this track.');
|
||||
}
|
||||
|
||||
return this.getPacketAtIndex(res, packetIndex + 1, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user