mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 05:13:50 +02:00
Add TrackDescriptor concept
This commit is contained in:
+14
-8
@@ -10,7 +10,7 @@ import { OPUS_SAMPLE_RATE } from '../codec';
|
||||
import { parseModesFromVorbisSetupPacket, parseOpusIdentificationHeader, readVorbisComments } from '../codec-data';
|
||||
import { Demuxer } from '../demuxer';
|
||||
import { Input } from '../input';
|
||||
import { InputAudioTrack, InputAudioTrackBacking } from '../input-track';
|
||||
import { InputAudioTrackBacking } from '../input-track';
|
||||
import { PacketRetrievalOptions } from '../media-sink';
|
||||
import { DEFAULT_TRACK_DISPOSITION, MetadataTags, TrackDisposition } from '../metadata';
|
||||
import {
|
||||
@@ -57,7 +57,7 @@ export class OggDemuxer extends Demuxer {
|
||||
|
||||
metadataPromise: Promise<void> | null = null;
|
||||
bitstreams: LogicalBitstream[] = [];
|
||||
tracks: InputAudioTrack[] = [];
|
||||
trackBackings: OggAudioTrackBacking[] = [];
|
||||
metadataTags: MetadataTags = {};
|
||||
|
||||
constructor(input: Input) {
|
||||
@@ -138,7 +138,7 @@ export class OggDemuxer extends Demuxer {
|
||||
}
|
||||
|
||||
if (bitstream.codecInfo.codec !== null) {
|
||||
this.tracks.push(new InputAudioTrack(this.input, new OggAudioTrackBacking(bitstream, this)));
|
||||
this.trackBackings.push(new OggAudioTrackBacking(bitstream, this));
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -379,7 +379,9 @@ export class OggDemuxer extends Demuxer {
|
||||
async getMimeType() {
|
||||
await this.readMetadata();
|
||||
|
||||
const codecStrings = await Promise.all(this.tracks.map(x => x.getCodecParameterString()));
|
||||
const codecStrings = await Promise.all(this.trackBackings.map(
|
||||
x => x.getDecoderConfig().then(c => c?.codec ?? null),
|
||||
));
|
||||
|
||||
return buildOggMimeType({
|
||||
codecStrings: codecStrings.filter(Boolean) as string[],
|
||||
@@ -390,9 +392,9 @@ export class OggDemuxer extends Demuxer {
|
||||
return null; // Not stored anywhere
|
||||
}
|
||||
|
||||
async getTracks() {
|
||||
async getTrackBackings() {
|
||||
await this.readMetadata();
|
||||
return this.tracks;
|
||||
return this.trackBackings;
|
||||
}
|
||||
|
||||
async getMetadataTags() {
|
||||
@@ -422,14 +424,18 @@ class OggAudioTrackBacking implements InputAudioTrackBacking {
|
||||
: bitstream.sampleRate;
|
||||
}
|
||||
|
||||
getType() {
|
||||
return 'audio' as const;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.bitstream.serialNumber;
|
||||
}
|
||||
|
||||
getNumber() {
|
||||
// All Ogg tracks are audio, so the track's index + 1 is its number
|
||||
const index = this.demuxer.tracks.findIndex(
|
||||
t => (t._backing as OggAudioTrackBacking).bitstream === this.bitstream,
|
||||
const index = this.demuxer.trackBackings.findIndex(
|
||||
x => x.bitstream === this.bitstream,
|
||||
);
|
||||
assert(index !== -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user