Clean up some code, add new source getting for Input

This commit is contained in:
Vanilagy
2026-03-04 09:34:37 +01:00
parent cfb5418fa0
commit 6d5821aa74
9 changed files with 498 additions and 430 deletions
+23 -3
View File
@@ -134,13 +134,17 @@ export class EncodedPacketSink {
* Retrieves the track's first packet (in decode order), or null if it has no packets. The first packet is very
* likely to be a key packet, but it doesn't have to be.
*/
getFirstPacket(options: PacketRetrievalOptions = {}) {
async getFirstPacket(options: PacketRetrievalOptions = {}) {
validatePacketRetrievalOptions(options);
if (this._track.input._disposed) {
throw new InputDisposedError();
}
if (!this._track.isHydrated) {
await this._track.hydrate();
}
return maybeFixPacketType(this._track, this._track._backing.getFirstPacket(options), options);
}
@@ -169,7 +173,7 @@ export class EncodedPacketSink {
*
* @param timestamp - The timestamp used for retrieval, in seconds.
*/
getPacket(timestamp: number, options: PacketRetrievalOptions = {}) {
async getPacket(timestamp: number, options: PacketRetrievalOptions = {}) {
validateTimestamp(timestamp);
validatePacketRetrievalOptions(options);
@@ -177,6 +181,10 @@ export class EncodedPacketSink {
throw new InputDisposedError();
}
if (!this._track.isHydrated) {
await this._track.hydrate();
}
return maybeFixPacketType(this._track, this._track._backing.getPacket(timestamp, options), options);
}
@@ -184,7 +192,7 @@ export class EncodedPacketSink {
* Retrieves the packet following the given packet (in decode order), or null if the given packet is the
* last packet.
*/
getNextPacket(packet: EncodedPacket, options: PacketRetrievalOptions = {}) {
async getNextPacket(packet: EncodedPacket, options: PacketRetrievalOptions = {}) {
if (!(packet instanceof EncodedPacket)) {
throw new TypeError('packet must be an EncodedPacket.');
}
@@ -194,6 +202,10 @@ export class EncodedPacketSink {
throw new InputDisposedError();
}
if (!this._track.isHydrated) {
await this._track.hydrate();
}
return maybeFixPacketType(this._track, this._track._backing.getNextPacket(packet, options), options);
}
@@ -216,6 +228,10 @@ export class EncodedPacketSink {
throw new InputDisposedError();
}
if (!this._track.isHydrated) {
await this._track.hydrate();
}
if (!options.verifyKeyPackets) {
return this._track._backing.getKeyPacket(timestamp, options);
}
@@ -251,6 +267,10 @@ export class EncodedPacketSink {
throw new InputDisposedError();
}
if (!this._track.isHydrated) {
await this._track.hydrate();
}
if (!options.verifyKeyPackets) {
return this._track._backing.getNextKeyPacket(packet, options);
}