mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 05:43:50 +02:00
Clean up some code, add new source getting for Input
This commit is contained in:
+23
-3
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user