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