Add toDataView

This commit is contained in:
Vanilagy
2025-01-26 12:03:23 +01:00
parent d3566305df
commit b759fd8808
4 changed files with 10 additions and 4 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ import {
last,
readBits,
reverseBitsU32,
toDataView,
} from './misc';
import { SubtitleMetadata } from './subtitles';
@@ -306,7 +307,7 @@ export const extractVideoCodecString = (trackInfo: {
throw new TypeError('HEVC description must be provided.');
}
const view = new DataView(description.buffer, description.byteOffset, description.byteLength);
const view = toDataView(description);
let codecString = 'hev1.';
// general_profile_space and general_profile_idc
+2 -1
View File
@@ -9,6 +9,7 @@ import {
mapAsyncGenerator,
promiseWithResolvers,
toAsyncIterator,
toDataView,
validateAnyIterable,
} from './misc';
import { fromAlaw, fromUlaw } from './pcm';
@@ -1015,7 +1016,7 @@ class PcmAudioDecoderWrapper extends DecoderWrapper<EncodedAudioSample, AudioDat
}
decode(sample: EncodedAudioSample) {
const inputView = new DataView(sample.data.buffer, sample.data.byteOffset, sample.byteLength);
const inputView = toDataView(sample.data);
const numberOfFrames = sample.byteLength / this.decoderConfig.numberOfChannels / this.inputSampleSize;
+4
View File
@@ -54,6 +54,10 @@ export const toUint8Array = (source: AllowSharedBufferSource): Uint8Array => {
}
};
export const toDataView = (bytes: Uint8Array) => {
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
};
export const textEncoder = new TextEncoder();
const invertObject = <K extends PropertyKey, V extends PropertyKey>(object: Record<K, V>) => {
+2 -2
View File
@@ -1,4 +1,4 @@
import { assert } from '../misc';
import { assert, toDataView } from '../misc';
import { Muxer } from '../muxer';
import { Output, OutputAudioTrack } from '../output';
import { EncodedAudioSample } from '../sample';
@@ -36,7 +36,7 @@ export class Mp3Muxer extends Muxer {
try {
if (!this.xingFrameData) {
const view = new DataView(sample.data.buffer, sample.data.byteOffset, sample.data.byteLength);
const view = toDataView(sample.data);
if (view.byteLength < 4) {
throw new Error('Invalid MP3 header in sample.');
}