mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 05:13:50 +02:00
Add ESLint and lint a bunch
This commit is contained in:
+39
-23
@@ -12,17 +12,17 @@ export const last = <T>(arr: T[]) => {
|
||||
};
|
||||
|
||||
export const isU32 = (value: number) => {
|
||||
return value >= 0 && value < 2**32;
|
||||
return value >= 0 && value < 2 ** 32;
|
||||
};
|
||||
|
||||
export const readBits = (bytes: Uint8Array, start: number, end: number) => {
|
||||
let result = 0;
|
||||
|
||||
for (let i = start; i < end; i++) {
|
||||
let byteIndex = Math.floor(i / 8);
|
||||
let byte = bytes[byteIndex]!;
|
||||
let bitIndex = 0b111 - (i & 0b111);
|
||||
let bit = (byte & (1 << bitIndex)) >> bitIndex;
|
||||
const byteIndex = Math.floor(i / 8);
|
||||
const byte = bytes[byteIndex]!;
|
||||
const bitIndex = 0b111 - (i & 0b111);
|
||||
const bit = (byte & (1 << bitIndex)) >> bitIndex;
|
||||
|
||||
result <<= 1;
|
||||
result |= bit;
|
||||
@@ -33,9 +33,9 @@ export const readBits = (bytes: Uint8Array, start: number, end: number) => {
|
||||
|
||||
export const writeBits = (bytes: Uint8Array, start: number, end: number, value: number) => {
|
||||
for (let i = start; i < end; i++) {
|
||||
let byteIndex = Math.floor(i / 8);
|
||||
const byteIndex = Math.floor(i / 8);
|
||||
let byte = bytes[byteIndex]!;
|
||||
let bitIndex = 0b111 - (i & 0b111);
|
||||
const bitIndex = 0b111 - (i & 0b111);
|
||||
|
||||
byte &= ~(1 << bitIndex);
|
||||
byte |= ((value & (1 << (end - i - 1))) >> (end - i - 1)) << bitIndex;
|
||||
@@ -56,29 +56,45 @@ export const textEncoder = new TextEncoder();
|
||||
// These maps are taken from https://www.matroska.org/technical/elements.html,
|
||||
// which references the tables in ITU-T H.273 - they should be valid for Matroska and ISOBMFF.
|
||||
export const COLOR_PRIMARIES_MAP: Record<VideoColorPrimaries, number> = {
|
||||
'bt709': 1, // ITU-R BT.709
|
||||
'bt470bg': 5, // ITU-R BT.470BG
|
||||
'smpte170m': 6 // ITU-R BT.601 525 - SMPTE 170M
|
||||
bt709: 1, // ITU-R BT.709
|
||||
bt470bg: 5, // ITU-R BT.470BG
|
||||
smpte170m: 6, // ITU-R BT.601 525 - SMPTE 170M
|
||||
};
|
||||
export const TRANSFER_CHARACTERISTICS_MAP: Record<VideoTransferCharacteristics, number> = {
|
||||
'bt709': 1, // ITU-R BT.709
|
||||
'smpte170m': 6, // SMPTE 170M
|
||||
'iec61966-2-1': 13 // IEC 61966-2-1
|
||||
'bt709': 1, // ITU-R BT.709
|
||||
'smpte170m': 6, // SMPTE 170M
|
||||
'iec61966-2-1': 13, // IEC 61966-2-1
|
||||
};
|
||||
export const MATRIX_COEFFICIENTS_MAP: Record<VideoMatrixCoefficients, number> = {
|
||||
'rgb': 0, // Identity
|
||||
'bt709': 1, // ITU-R BT.709
|
||||
'bt470bg': 5, // ITU-R BT.470BG
|
||||
'smpte170m': 6 // SMPTE 170M
|
||||
rgb: 0, // Identity
|
||||
bt709: 1, // ITU-R BT.709
|
||||
bt470bg: 5, // ITU-R BT.470BG
|
||||
smpte170m: 6, // SMPTE 170M
|
||||
};
|
||||
|
||||
export const colorSpaceIsComplete = (colorSpace: VideoColorSpaceInit | undefined) => {
|
||||
return !!colorSpace && !!colorSpace.primaries && !!colorSpace.transfer && !!colorSpace.matrix && colorSpace.fullRange !== undefined;
|
||||
export type RequiredNonNull<T> = {
|
||||
[K in keyof T]-?: NonNullable<T[K]>;
|
||||
};
|
||||
|
||||
export const colorSpaceIsComplete = (
|
||||
colorSpace: VideoColorSpaceInit | undefined,
|
||||
): colorSpace is RequiredNonNull<VideoColorSpaceInit> => {
|
||||
return (
|
||||
!!colorSpace
|
||||
&& !!colorSpace.primaries
|
||||
&& !!colorSpace.transfer
|
||||
&& !!colorSpace.matrix
|
||||
&& colorSpace.fullRange !== undefined
|
||||
);
|
||||
};
|
||||
|
||||
export const isAllowSharedBufferSource = (x: unknown) => {
|
||||
// Quite a mouthful:
|
||||
return x instanceof ArrayBuffer || (typeof SharedArrayBuffer !== 'undefined' && x instanceof SharedArrayBuffer) || (ArrayBuffer.isView(x) && !(x instanceof DataView));
|
||||
return (
|
||||
x instanceof ArrayBuffer
|
||||
|| (typeof SharedArrayBuffer !== 'undefined' && x instanceof SharedArrayBuffer)
|
||||
|| (ArrayBuffer.isView(x) && !(x instanceof DataView))
|
||||
);
|
||||
};
|
||||
|
||||
export class AsyncMutex {
|
||||
@@ -86,15 +102,15 @@ export class AsyncMutex {
|
||||
|
||||
async acquire() {
|
||||
let resolver: () => void;
|
||||
let nextPromise = new Promise<void>(resolve => {
|
||||
const nextPromise = new Promise<void>((resolve) => {
|
||||
resolver = resolve;
|
||||
});
|
||||
|
||||
let currentPromiseAlias = this.currentPromise;
|
||||
const currentPromiseAlias = this.currentPromise;
|
||||
this.currentPromise = nextPromise;
|
||||
|
||||
await currentPromiseAlias;
|
||||
|
||||
return resolver!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user