mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 03:13:51 +02:00
Merge pull request #3 from yonathan06/main
public getSize and input source
This commit is contained in:
+5
-5
@@ -35,7 +35,7 @@ export abstract class InputFormat {
|
||||
export abstract class IsobmffInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
protected async _getMajorBrand(input: Input) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
const sourceSize = await input._mainReader.source.getSize();
|
||||
if (sourceSize < 12) {
|
||||
return null;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export class QuickTimeInputFormat extends IsobmffInputFormat {
|
||||
export class MatroskaInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
protected async isSupportedEBMLOfDocType(input: Input, desiredDocType: string) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
const sourceSize = await input._mainReader.source.getSize();
|
||||
if (sourceSize < 8) {
|
||||
return false;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ export class WebMInputFormat extends MatroskaInputFormat {
|
||||
export class Mp3InputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
async _canReadInput(input: Input) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
const sourceSize = await input._mainReader.source.getSize();
|
||||
if (sourceSize < 4) {
|
||||
return false;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ export class Mp3InputFormat extends InputFormat {
|
||||
export class WaveInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
async _canReadInput(input: Input) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
const sourceSize = await input._mainReader.source.getSize();
|
||||
if (sourceSize < 12) {
|
||||
return false;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ export class WaveInputFormat extends InputFormat {
|
||||
export class OggInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
async _canReadInput(input: Input) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
const sourceSize = await input._mainReader.source.getSize();
|
||||
if (sourceSize < 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,14 @@ export class Input {
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source from which this input file reads its data. This is the same source that was passed to there
|
||||
* constructor.
|
||||
*/
|
||||
get source() {
|
||||
return this._source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format of the input file. You can compare this result directly to the InputFormat singletons or use
|
||||
* `instanceof` checks for subset-aware logic (for example, `format instanceof MatroskaInputFormat` is true for
|
||||
|
||||
@@ -198,7 +198,7 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
super(input);
|
||||
|
||||
this.metadataReader = new IsobmffReader(input._mainReader);
|
||||
this.chunkReader = new IsobmffReader(new Reader(input._source, 64 * 2 ** 20)); // Max 64 MiB of stored chunks
|
||||
this.chunkReader = new IsobmffReader(new Reader(input.source, 64 * 2 ** 20)); // Max 64 MiB of stored chunks
|
||||
}
|
||||
|
||||
override async computeDuration() {
|
||||
@@ -235,7 +235,7 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
|
||||
readMetadata() {
|
||||
return this.metadataPromise ??= (async () => {
|
||||
const sourceSize = await this.metadataReader.reader.source._getSize();
|
||||
const sourceSize = await this.metadataReader.reader.source.getSize();
|
||||
|
||||
while (this.metadataReader.pos < sourceSize) {
|
||||
await this.metadataReader.reader.loadRange(
|
||||
@@ -2191,7 +2191,7 @@ abstract class IsobmffTrackBacking implements InputTrackBacking {
|
||||
}
|
||||
|
||||
const metadataReader = demuxer.metadataReader;
|
||||
const sourceSize = await metadataReader.reader.source._getSize();
|
||||
const sourceSize = await metadataReader.reader.source.getSize();
|
||||
|
||||
let prevFragment: Fragment | null = null;
|
||||
let bestFragmentIndex = fragmentIndex;
|
||||
|
||||
@@ -165,7 +165,7 @@ export class MatroskaDemuxer extends Demuxer {
|
||||
this.metadataReader = new EBMLReader(input._mainReader);
|
||||
|
||||
// Max 64 MiB of stored clusters
|
||||
this.clusterReader = new EBMLReader(new Reader(input._source, 64 * 2 ** 20));
|
||||
this.clusterReader = new EBMLReader(new Reader(input.source, 64 * 2 ** 20));
|
||||
}
|
||||
|
||||
override async computeDuration() {
|
||||
@@ -211,7 +211,7 @@ export class MatroskaDemuxer extends Demuxer {
|
||||
return this.readMetadataPromise ??= (async () => {
|
||||
this.metadataReader.pos = 0;
|
||||
|
||||
const fileSize = await this.input._source._getSize();
|
||||
const fileSize = await this.input.source.getSize();
|
||||
|
||||
while (this.metadataReader.pos < fileSize - MIN_HEADER_SIZE) {
|
||||
await this.metadataReader.reader.loadRange(
|
||||
@@ -258,7 +258,7 @@ export class MatroskaDemuxer extends Demuxer {
|
||||
|
||||
dataStartPos: segmentDataStart,
|
||||
elementEndPos: dataSize === -1
|
||||
? (await this.input._source._getSize() - MIN_HEADER_SIZE)
|
||||
? (await this.input.source.getSize() - MIN_HEADER_SIZE)
|
||||
: segmentDataStart + dataSize,
|
||||
clusterSeekStartPos: segmentDataStart,
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export class Mp3Demuxer extends Demuxer {
|
||||
|
||||
async readMetadata() {
|
||||
return this.metadataPromise ??= (async () => {
|
||||
const fileSize = await this.input._source._getSize();
|
||||
const fileSize = await this.input.source.getSize();
|
||||
this.reader.fileSize = fileSize;
|
||||
|
||||
// Just load the entire file. Primitive, but the only way to actually ensure 100% correct timestamps.
|
||||
|
||||
@@ -38,12 +38,12 @@ export class OggDemuxer extends Demuxer {
|
||||
super(input);
|
||||
|
||||
// We don't need a persistent metadata reader as we read all metadata once at the start and then never again
|
||||
this.reader = new OggReader(new Reader(input._source, 64 * 2 ** 20));
|
||||
this.reader = new OggReader(new Reader(input.source, 64 * 2 ** 20));
|
||||
}
|
||||
|
||||
async readMetadata() {
|
||||
return this.metadataPromise ??= (async () => {
|
||||
this.fileSize = await this.input._source._getSize();
|
||||
this.fileSize = await this.input.source.getSize();
|
||||
|
||||
while (this.reader.pos < this.fileSize - MIN_PAGE_HEADER_SIZE) {
|
||||
await this.reader.reader.loadRange(
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ export class Reader {
|
||||
constructor(public source: Source, public maxStorableBytes = Infinity) {}
|
||||
|
||||
async loadRange(start: number, end: number) {
|
||||
end = Math.min(end, await this.source._getSize());
|
||||
end = Math.min(end, await this.source.getSize());
|
||||
|
||||
if (start >= end) {
|
||||
return;
|
||||
|
||||
+5
-2
@@ -13,8 +13,11 @@ export abstract class Source {
|
||||
/** @internal */
|
||||
_sizePromise: Promise<number> | null = null;
|
||||
|
||||
/** @internal */
|
||||
_getSize() {
|
||||
/**
|
||||
* Returns promise that resolves with the size of the file.
|
||||
* If the size is not known, it will be retrieved from the source.
|
||||
*/
|
||||
getSize() {
|
||||
return this._sizePromise ??= this._retrieveSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export class WaveDemuxer extends Demuxer {
|
||||
super(input);
|
||||
|
||||
this.metadataReader = new RiffReader(input._mainReader);
|
||||
this.chunkReader = new RiffReader(new Reader(input._source, 64 * 2 ** 20));
|
||||
this.chunkReader = new RiffReader(new Reader(input.source, 64 * 2 ** 20));
|
||||
}
|
||||
|
||||
async readMetadata() {
|
||||
|
||||
Reference in New Issue
Block a user