mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Remove unnecessary sync getters
This commit is contained in:
@@ -109,7 +109,7 @@ const initMediaPlayer = async (resource: File | string) => {
|
|||||||
);
|
);
|
||||||
endTimestamp = await input.getDurationFromMetadata(tracks, { skipLiveWait: true })
|
endTimestamp = await input.getDurationFromMetadata(tracks, { skipLiveWait: true })
|
||||||
?? await input.computeDuration(tracks, { skipLiveWait: true });
|
?? await input.computeDuration(tracks, { skipLiveWait: true });
|
||||||
isRelativeToUnixEpoch = (await Promise.all(tracks.map(t => t.getIsRelativeToUnixEpoch()))).some(Boolean);
|
isRelativeToUnixEpoch = (await Promise.all(tracks.map(t => t.isRelativeToUnixEpoch()))).some(Boolean);
|
||||||
playbackTimeAtStart = firstTimestamp;
|
playbackTimeAtStart = firstTimestamp;
|
||||||
|
|
||||||
// Configure the time display elements accordingly
|
// Configure the time display elements accordingly
|
||||||
|
|||||||
+4
-73
@@ -98,13 +98,7 @@ export abstract class InputTrack {
|
|||||||
* Returns whether the track metadata says that this track only contains key packets. The actual packets may
|
* Returns whether the track metadata says that this track only contains key packets. The actual packets may
|
||||||
* differ.
|
* differ.
|
||||||
*/
|
*/
|
||||||
abstract getHasOnlyKeyPackets(): Promise<boolean>;
|
abstract hasOnlyKeyPackets(): Promise<boolean>;
|
||||||
/**
|
|
||||||
* Whether the track metadata says that this track only contains key packets. The actual packets may differ.
|
|
||||||
* @deprecated Use {@link InputTrack.getHasOnlyKeyPackets} instead.
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
||||||
abstract get hasOnlyKeyPackets(): boolean;
|
|
||||||
|
|
||||||
/** Returns true if and only if this track is a video track. */
|
/** Returns true if and only if this track is a video track. */
|
||||||
isVideoTrack(): this is InputVideoTrack {
|
isVideoTrack(): this is InputVideoTrack {
|
||||||
@@ -205,23 +199,10 @@ export abstract class InputTrack {
|
|||||||
* Returns whether the timestamps of this track are relative to the Unix epoch (January 1, 1970 00:00:00 UTC).
|
* Returns whether the timestamps of this track are relative to the Unix epoch (January 1, 1970 00:00:00 UTC).
|
||||||
* When `true`, each timestamp maps to a definitive point in time.
|
* When `true`, each timestamp maps to a definitive point in time.
|
||||||
*/
|
*/
|
||||||
async getIsRelativeToUnixEpoch() {
|
async isRelativeToUnixEpoch() {
|
||||||
return this._backing.isRelativeToUnixEpoch();
|
return this._backing.isRelativeToUnixEpoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the timestamps of this track are relative to the Unix epoch (January 1, 1970 00:00:00 UTC). When `true`,
|
|
||||||
* each timestamp maps to a definitive point in time.
|
|
||||||
* @deprecated Use {@link InputTrack.getIsRelativeToUnixEpoch} instead.
|
|
||||||
*/
|
|
||||||
get isRelativeToUnixEpoch() {
|
|
||||||
return requireSync(
|
|
||||||
this._backing.isRelativeToUnixEpoch(),
|
|
||||||
'isRelativeToUnixEpoch',
|
|
||||||
'getIsRelativeToUnixEpoch',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the track's disposition, i.e. information about its intended usage. */
|
/** Returns the track's disposition, i.e. information about its intended usage. */
|
||||||
async getDisposition() {
|
async getDisposition() {
|
||||||
return this._backing.getDisposition();
|
return this._backing.getDisposition();
|
||||||
@@ -243,15 +224,6 @@ export abstract class InputTrack {
|
|||||||
return this._backing.getBitrate();
|
return this._backing.getBitrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The peak bitrate of the track, in bits per second, as specified in the track's metadata. This might not match the
|
|
||||||
* actual media data's bitrate.
|
|
||||||
* @deprecated Use {@link InputTrack.getBitrate} instead.
|
|
||||||
*/
|
|
||||||
get bitrate() {
|
|
||||||
return requireSync(this._backing.getBitrate(), 'bitrate', 'getBitrate');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the average bitrate of the track in bits per second, as specified in the track's metadata. This might
|
* Returns the average bitrate of the track in bits per second, as specified in the track's metadata. This might
|
||||||
* not match the actual media data's bitrate.
|
* not match the actual media data's bitrate.
|
||||||
@@ -260,15 +232,6 @@ export abstract class InputTrack {
|
|||||||
return this._backing.getAverageBitrate();
|
return this._backing.getAverageBitrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The average bitrate of the track, in bits per second, as specified in the track's metadata. This might not match
|
|
||||||
* the actual media data's bitrate.
|
|
||||||
* @deprecated Use {@link InputTrack.getAverageBitrate} instead.
|
|
||||||
*/
|
|
||||||
get averageBitrate() {
|
|
||||||
return requireSync(this._backing.getAverageBitrate(), 'averageBitrate', 'getAverageBitrate');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value
|
* Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value
|
||||||
* may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples
|
* may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples
|
||||||
@@ -556,26 +519,10 @@ export class InputVideoTrack extends InputTrack {
|
|||||||
return requireSync(this._backing.getCodec(), 'codec', 'getCodec');
|
return requireSync(this._backing.getCodec(), 'codec', 'getCodec');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async hasOnlyKeyPackets() {
|
||||||
* Returns whether the track metadata says that this track only contains key packets. The actual packets may
|
|
||||||
* differ.
|
|
||||||
*/
|
|
||||||
async getHasOnlyKeyPackets() {
|
|
||||||
return (await this._backing.getHasOnlyKeyPackets?.()) ?? false;
|
return (await this._backing.getHasOnlyKeyPackets?.()) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the track metadata says that this track only contains key packets. The actual packets may differ.
|
|
||||||
* @deprecated Use {@link InputVideoTrack.getHasOnlyKeyPackets} instead.
|
|
||||||
*/
|
|
||||||
get hasOnlyKeyPackets() {
|
|
||||||
const raw = this._backing.getHasOnlyKeyPackets?.();
|
|
||||||
if (raw === undefined) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return requireSync(raw, 'hasOnlyKeyPackets', 'getHasOnlyKeyPackets') ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the width in pixels of the track's coded samples, before any transformations or rotations. */
|
/** Returns the width in pixels of the track's coded samples, before any transformations or rotations. */
|
||||||
async getCodedWidth() {
|
async getCodedWidth() {
|
||||||
return this._backing.getCodedWidth();
|
return this._backing.getCodedWidth();
|
||||||
@@ -859,26 +806,10 @@ export class InputAudioTrack extends InputTrack {
|
|||||||
return requireSync(this._backing.getCodec(), 'codec', 'getCodec');
|
return requireSync(this._backing.getCodec(), 'codec', 'getCodec');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async hasOnlyKeyPackets() {
|
||||||
* Returns whether the track metadata says that this track only contains key packets. The actual packets may
|
|
||||||
* differ.
|
|
||||||
*/
|
|
||||||
async getHasOnlyKeyPackets() {
|
|
||||||
return (await this._backing.getHasOnlyKeyPackets?.()) ?? true;
|
return (await this._backing.getHasOnlyKeyPackets?.()) ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the track metadata says that this track only contains key packets. The actual packets may differ.
|
|
||||||
* @deprecated Use {@link InputAudioTrack.getHasOnlyKeyPackets} instead.
|
|
||||||
*/
|
|
||||||
get hasOnlyKeyPackets() {
|
|
||||||
const raw = this._backing.getHasOnlyKeyPackets?.();
|
|
||||||
if (raw === undefined) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return requireSync(raw, 'hasOnlyKeyPackets', 'getHasOnlyKeyPackets') ?? true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the number of audio channels in the track. */
|
/** Returns the number of audio channels in the track. */
|
||||||
async getNumberOfChannels() {
|
async getNumberOfChannels() {
|
||||||
return this._backing.getNumberOfChannels();
|
return this._backing.getNumberOfChannels();
|
||||||
|
|||||||
+1
-1
@@ -543,7 +543,7 @@ export class Input<S extends Source = Source> extends EventEmitter<InputEvents>
|
|||||||
sortBy: async t => [
|
sortBy: async t => [
|
||||||
prefer((await t.getDisposition()).default),
|
prefer((await t.getDisposition()).default),
|
||||||
prefer(await t.hasPairableAudioTrack()),
|
prefer(await t.hasPairableAudioTrack()),
|
||||||
prefer(!(await t.getHasOnlyKeyPackets())),
|
prefer(!(await t.hasOnlyKeyPackets())),
|
||||||
desc(await t.getBitrate()),
|
desc(await t.getBitrate()),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ test.concurrent('Big Buck Bunny', { timeout: 15_000 }, async () => {
|
|||||||
|
|
||||||
// Force hydration of all tracks by loading actual media data
|
// Force hydration of all tracks by loading actual media data
|
||||||
for (const track of tracks) {
|
for (const track of tracks) {
|
||||||
expect(await track.getIsRelativeToUnixEpoch()).toBe(false);
|
expect(await track.isRelativeToUnixEpoch()).toBe(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(sourceCount).toBe(1 + 5 + 5);
|
expect(sourceCount).toBe(1 + 5 + 5);
|
||||||
@@ -342,18 +342,18 @@ test.concurrent('Out-of-band audio track via ADTS', { timeout: 15_000 }, async (
|
|||||||
|
|
||||||
const tracks = await input.getTracks();
|
const tracks = await input.getTracks();
|
||||||
const videoOnlyKeyPacketsFlags = await Promise.all(
|
const videoOnlyKeyPacketsFlags = await Promise.all(
|
||||||
tracks.filter((x): x is InputVideoTrack => x.isVideoTrack()).map(x => x.getHasOnlyKeyPackets()),
|
tracks.filter((x): x is InputVideoTrack => x.isVideoTrack()).map(x => x.hasOnlyKeyPackets()),
|
||||||
);
|
);
|
||||||
expect(videoOnlyKeyPacketsFlags.some(x => x)).toBe(true);
|
expect(videoOnlyKeyPacketsFlags.some(x => x)).toBe(true);
|
||||||
|
|
||||||
const audioTrack = tracks.find((x): x is InputAudioTrack => x.isAudioTrack());
|
const audioTrack = tracks.find((x): x is InputAudioTrack => x.isAudioTrack());
|
||||||
assert(audioTrack);
|
assert(audioTrack);
|
||||||
expect(await audioTrack.getHasOnlyKeyPackets()).toBe(true);
|
expect(await audioTrack.hasOnlyKeyPackets()).toBe(true);
|
||||||
|
|
||||||
expect(await audioTrack.getPairableVideoTracks()).toHaveLength(1); // Since the I-frame one isn't pairable
|
expect(await audioTrack.getPairableVideoTracks()).toHaveLength(1); // Since the I-frame one isn't pairable
|
||||||
const videoTrack = (await audioTrack.getPairableVideoTracks())[0]!;
|
const videoTrack = (await audioTrack.getPairableVideoTracks())[0]!;
|
||||||
assert(videoTrack);
|
assert(videoTrack);
|
||||||
expect(await videoTrack.getHasOnlyKeyPackets()).toBe(false);
|
expect(await videoTrack.hasOnlyKeyPackets()).toBe(false);
|
||||||
|
|
||||||
let lastTimestamp = -Infinity;
|
let lastTimestamp = -Infinity;
|
||||||
const sink = new EncodedPacketSink(audioTrack);
|
const sink = new EncodedPacketSink(audioTrack);
|
||||||
@@ -482,7 +482,7 @@ test.concurrent('Single-value PDT', { timeout: 15_000 }, async () => {
|
|||||||
using input = createInputFrom('https://playertest.longtailvideo.com/adaptive/aviion/manifest.m3u8', ALL_FORMATS);
|
using input = createInputFrom('https://playertest.longtailvideo.com/adaptive/aviion/manifest.m3u8', ALL_FORMATS);
|
||||||
|
|
||||||
const tracks = await input.getTracks();
|
const tracks = await input.getTracks();
|
||||||
expect((await Promise.all(tracks.map(x => x.getIsRelativeToUnixEpoch()))).every(x => x)).toBe(true);
|
expect((await Promise.all(tracks.map(x => x.isRelativeToUnixEpoch()))).every(x => x)).toBe(true);
|
||||||
|
|
||||||
const track = tracks[0]!;
|
const track = tracks[0]!;
|
||||||
const firstTimestamp = await track.getFirstTimestamp();
|
const firstTimestamp = await track.getFirstTimestamp();
|
||||||
@@ -545,7 +545,7 @@ test.concurrent('PDT with bad values', { timeout: 15_000 }, async () => {
|
|||||||
const audioTrack = await input.getPrimaryAudioTrack();
|
const audioTrack = await input.getPrimaryAudioTrack();
|
||||||
assert(audioTrack);
|
assert(audioTrack);
|
||||||
|
|
||||||
expect(await audioTrack.getIsRelativeToUnixEpoch()).toBe(false);
|
expect(await audioTrack.isRelativeToUnixEpoch()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.concurrent('Alternative audio only', { timeout: 15_000 }, async () => {
|
test.concurrent('Alternative audio only', { timeout: 15_000 }, async () => {
|
||||||
@@ -578,7 +578,7 @@ test.concurrent('Advanced Apple HLS', { timeout: 30_000 }, async () => {
|
|||||||
displayWidth: await t.getDisplayWidth(),
|
displayWidth: await t.getDisplayWidth(),
|
||||||
displayHeight: await t.getDisplayHeight(),
|
displayHeight: await t.getDisplayHeight(),
|
||||||
bitrate: await t.getBitrate(),
|
bitrate: await t.getBitrate(),
|
||||||
hasOnlyKeyPackets: await t.getHasOnlyKeyPackets(),
|
hasOnlyKeyPackets: await t.hasOnlyKeyPackets(),
|
||||||
codecParameterString: await t.getCodecParameterString(),
|
codecParameterString: await t.getCodecParameterString(),
|
||||||
});
|
});
|
||||||
const snapshotAudioTrack = async (t: InputAudioTrack) => ({
|
const snapshotAudioTrack = async (t: InputAudioTrack) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user