Use new sample classes for muxers as well

This commit is contained in:
Vanilagy
2025-01-04 00:28:54 +01:00
parent e83356662e
commit 1145e0ebbe
8 changed files with 90 additions and 233 deletions
+32
View File
@@ -41,6 +41,22 @@ export class EncodedVideoSample {
duration: this.microsecondDuration,
});
}
static fromEncodedVideoChunk(chunk: EncodedVideoChunk) {
if (typeof EncodedVideoChunk === 'undefined') {
throw new Error('Your browser does not support EncodedVideoChunk.');
}
const data = new Uint8Array(chunk.byteLength);
chunk.copyTo(data);
return new EncodedVideoSample(
data,
chunk.type,
chunk.timestamp / 1e6,
(chunk.duration ?? 0) / 1e6,
);
}
}
/** @public */
@@ -81,4 +97,20 @@ export class EncodedAudioSample {
duration: this.microsecondDuration,
});
}
static fromEncodedAudioChunk(chunk: EncodedAudioChunk) {
if (typeof EncodedAudioChunk === 'undefined') {
throw new Error('Your browser does not support EncodedAudioChunk.');
}
const data = new Uint8Array(chunk.byteLength);
chunk.copyTo(data);
return new EncodedAudioSample(
data,
chunk.type as SampleType, // Typing is weird
chunk.timestamp / 1e6,
(chunk.duration ?? 0) / 1e6,
);
}
}