Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/controller/eme-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import {
requestMediaKeySystemAccess,
} from '../utils/mediakeys-helper';
import { KeySystemFormats } from '../utils/mediakeys-helper';
import { bin2str, parseMultiPssh, parseSinf } from '../utils/mp4-tools';
import { base64Decode } from '../utils/numeric-encoding-utils';
import { parseMultiPssh, parseSinf } from '../utils/mp4-tools';
import { base64Decode, bin2str } from '../utils/numeric-encoding-utils';
import { stringify } from '../utils/safe-json-stringify';
import { strToUtf8array } from '../utils/utf8-utils';
import type { EMEControllerConfig, HlsConfig, LoadPolicy } from '../config';
Expand Down Expand Up @@ -1364,10 +1364,7 @@ class EMEController extends Logger implements ComponentAPI {
// actual license request) and any HttpHeader elements (sent as request
// headers).
// For PlayReady CDMs, we need to dig the Challenge out of the XML.
const xmlString = String.fromCharCode.apply(
null,
new Uint16Array(licenseChallenge.buffer),
);
const xmlString = bin2str(new Uint16Array(licenseChallenge.buffer));
// eslint-disable-next-line no-restricted-syntax
if (!xmlString.includes('PlayReadyKeyMessage')) {
// This does not appear to be a wrapped message as on Edge. Some
Expand Down
15 changes: 0 additions & 15 deletions src/controller/fragment-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,6 @@ export function pdtWithinToleranceTest(
return endProgramDateTime - candidateLookupTolerance > pdtBufferEnd;
}

export function findFragWithCC(
fragments: MediaFragment[],
cc: number,
): MediaFragment | null {
return BinarySearch.search(fragments, (candidate) => {
if (candidate.cc < cc) {
return 1;
} else if (candidate.cc > cc) {
return -1;
} else {
return 0;
}
});
}

export function findNearestWithCC(
details: LevelDetails | undefined,
cc: number,
Expand Down
10 changes: 0 additions & 10 deletions src/demux/video/exp-golomb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ class ExpGolomb {
readUByte(): number {
return this.readBits(8);
}

// ():int
readUShort(): number {
return this.readBits(16);
}

// ():int
readUInt(): number {
return this.readBits(32);
}
}

export default ExpGolomb;
6 changes: 2 additions & 4 deletions src/demux/video/hevc-video-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BaseVideoParser from './base-video-parser';
import ExpGolomb from './exp-golomb';
import { parseSEIMessageFromNALu } from '../../utils/mp4-tools';
import { bin2str } from '../../utils/numeric-encoding-utils';
import type {
DemuxedUserdataTrack,
DemuxedVideoTrack,
Expand Down Expand Up @@ -764,10 +765,7 @@ class HevcVideoParser extends BaseVideoParser {

matchSPS(sps1: Uint8Array, sps2: Uint8Array): boolean {
// compare without headers and VPS related params
return (
String.fromCharCode.apply(null, sps1).substr(3) ===
String.fromCharCode.apply(null, sps2).substr(3)
);
return bin2str(sps1).substring(3) === bin2str(sps2).substring(3);
}
}

Expand Down
41 changes: 0 additions & 41 deletions src/utils/chunker.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/utils/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ export function hexToArrayBuffer(str: string): ArrayBuffer {
.split(' '),
).buffer;
}

const Hex = {
hexDump: arrayToHex,
};

export default Hex;
10 changes: 0 additions & 10 deletions src/utils/level-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ type FragmentIntersection = (
) => void;
type PartIntersection = (oldPart: Part, newPart: Part) => void;

export function updatePTS(
fragments: MediaFragment[],
fromIdx: number,
toIdx: number,
): void {
const fragFrom = fragments[fromIdx];
const fragTo = fragments[toIdx];
updateFromToPTS(fragFrom, fragTo);
}

function updateFromToPTS(fragFrom: MediaFragment, fragTo: MediaFragment) {
const fragToPTS = fragTo.startPTS as number;
// if we know startPTS[toIdx]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mediakeys-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { optionalSelf } from './global';
import { changeEndianness } from './keysystem-util';
import { base64Decode } from './numeric-encoding-utils';
import { base64Decode, bin2str } from './numeric-encoding-utils';
import type { DRMSystemOptions, EMEControllerConfig } from '../config';

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ export function parsePlayReadyWRM(keyBytes: Uint8Array<ArrayBuffer>) {
keyBytes.byteOffset,
keyBytes.byteLength / 2,
);
const keyByteStr = String.fromCharCode.apply(null, Array.from(keyBytesUtf16));
const keyByteStr = bin2str(keyBytesUtf16);

// Parse Playready WRMHeader XML
const xmlKeyBytes = keyByteStr.substring(
Expand Down
13 changes: 5 additions & 8 deletions src/utils/mp4-tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { utf8ArrayToStr } from '@svta/cml-id3';
import { arrayToHex } from './hex';
import { bin2str } from './numeric-encoding-utils';
import { ElementaryStreamTypes } from '../loader/fragment';
import { logger } from '../utils/logger';
import type { ChunkMetadata } from '../hls';
Expand Down Expand Up @@ -72,28 +73,24 @@ export const RemuxerTrackIdConfig = {
text: 4,
};

export function bin2str(data: Uint8Array): string {
return String.fromCharCode.apply(null, data);
}

export function readUint16(buffer: Uint8Array, offset: number): number {
function readUint16(buffer: Uint8Array, offset: number): number {
const val = (buffer[offset] << 8) | buffer[offset + 1];
return val < 0 ? 65536 + val : val;
}

export function readUint32(buffer: Uint8Array, offset: number): number {
function readUint32(buffer: Uint8Array, offset: number): number {
const val = readSint32(buffer, offset);
return val < 0 ? 4294967296 + val : val;
}

export function readUint64(buffer: Uint8Array, offset: number) {
function readUint64(buffer: Uint8Array, offset: number) {
let result = readUint32(buffer, offset);
result *= Math.pow(2, 32);
result += readUint32(buffer, offset + 4);
return result;
}

export function readSint32(buffer: Uint8Array, offset: number): number {
function readSint32(buffer: Uint8Array, offset: number): number {
return (
(buffer[offset] << 24) |
(buffer[offset + 1] << 16) |
Expand Down
27 changes: 4 additions & 23 deletions src/utils/numeric-encoding-utils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
export function base64ToBase64Url(base64encodedStr: string): string {
return base64encodedStr
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
}

export function strToBase64Encode(str: string): string {
return btoa(str);
}

export function base64DecodeToStr(str: string): string {
return atob(str);
}

export function base64Encode(input: Uint8Array): string {
return btoa(String.fromCharCode(...input));
}

export function base64UrlEncode(input: Uint8Array): string {
return base64ToBase64Url(base64Encode(input));
}

export function base64Decode(base64encodedStr: string) {
return Uint8Array.from(atob(base64encodedStr), (c) => c.charCodeAt(0));
}

export function bin2str(data: number[] | Uint8Array | Uint16Array): string {
return String.fromCharCode.apply(null, data);
}
Loading