Skip to content

Commit

Permalink
fix: move CMAF HAM dependencies from lib to samples (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: Casey Occhialini <1508707+littlespex@users.noreply.github.com>
  • Loading branch information
littlespex authored Oct 29, 2024
1 parent 98649c7 commit 9a56ebb
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Replace Typescript enums with constants [#103](https://github.com/streaming-video-technology-alliance/common-media-library/issues/103)
- Remove CMAF HAM dependencies [#119](https://github.com/streaming-video-technology-alliance/common-media-library/issues/119)


## [0.7.3] - 2024-08-30
Expand Down
48 changes: 48 additions & 0 deletions lib/config/common-media-library.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ export type CueHandler = {
dispatchCue?(): void;
};

// @alpha
export type DashManifest = {
MPD: {
$?: {
maxSegmentDuration?: string;
mediaPresentationDuration?: string;
minBufferTime?: string;
profiles?: string;
type?: string;
xmlns?: string;
};
Period: Period[];
};
};

// @alpha
export function dashToHam(manifest: string): Presentation[];

Expand Down Expand Up @@ -483,6 +498,14 @@ export function hamToDash(presentation: Presentation[]): Manifest;
// @alpha
export function hamToHls(presentation: Presentation[]): Manifest;

// @alpha
export type HlsManifest = {
playlists: PlayList[];
mediaGroups: MediaGroups;
segments: SegmentHls[];
targetDuration?: number;
};

// @alpha
export function hlsToHam(manifest: string, ancillaryManifests: string[]): Presentation[];

Expand Down Expand Up @@ -639,6 +662,24 @@ export type SelectionSet = Ham & {
alignedSwitchingSets?: AlignedSwitchingSet[];
};

// Warning: (ae-forgotten-export) The symbol "DashParser" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "setDashParser" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export function setDashParser(parser: DashParser): void;

// Warning: (ae-forgotten-export) The symbol "DashSerializer" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "setDashSerializer" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export function setDashSerializer(serializer: DashSerializer): void;

// Warning: (ae-forgotten-export) The symbol "HlsParser" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "setHlsParser" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export function setHlsParser(parser: HlsParser): void;

// @beta
export type SfBareItem = string | Uint8Array | boolean | number | symbol | Date | SfToken;

Expand Down Expand Up @@ -805,4 +846,11 @@ export type VideoTrack = Track & {
scanType: string;
};

// Warnings were encountered during analysis:
//
// src/cmaf/ham/types/mapper/dash/DashManifest.ts:19:3 - (ae-forgotten-export) The symbol "Period" needs to be exported by the entry point index.d.ts
// src/cmaf/ham/types/mapper/hls/HlsManifest.ts:12:2 - (ae-forgotten-export) The symbol "PlayList" needs to be exported by the entry point index.d.ts
// src/cmaf/ham/types/mapper/hls/HlsManifest.ts:13:2 - (ae-forgotten-export) The symbol "MediaGroups" needs to be exported by the entry point index.d.ts
// src/cmaf/ham/types/mapper/hls/HlsManifest.ts:14:2 - (ae-forgotten-export) The symbol "SegmentHls" needs to be exported by the entry point index.d.ts

```
5 changes: 0 additions & 5 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,5 @@
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
"test": "tsx --test ./test/**/*.test.ts",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@types/xml2js": "0.4.14",
"m3u8-parser": "7.1.0",
"xml2js": "0.6.2"
}
}
8 changes: 7 additions & 1 deletion lib/src/cmaf-ham.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ export type { Track } from './cmaf/ham/types/model/Track.js';
export type { TrackType } from './cmaf/ham/types/model/TrackType.js';
export type { VideoTrack } from './cmaf/ham/types/model/VideoTrack.js';

export type { Validation } from './cmaf/ham/types/Validation.js';
export type { Manifest } from './cmaf/ham/types/manifest/Manifest.js';
export type { ManifestFormat } from './cmaf/ham/types/manifest/ManifestFormat.js';
export type { DashManifest } from './cmaf/ham/types/mapper/dash/DashManifest.js';
export type { HlsManifest } from './cmaf/ham/types/mapper/hls/HlsManifest.js';
export type { Validation } from './cmaf/ham/types/Validation.js';

export { setDashParser } from './cmaf/ham/utils/dash/parseDashManifest.js';
export { setDashSerializer } from './cmaf/ham/utils/dash/serializeDashManifest.js';
export { setHlsParser } from './cmaf/ham/utils/hls/parseHlsManifest.js';

export { dashToHam } from './cmaf/ham/services/converters/dashToHam.js';
export { hamToDash } from './cmaf/ham/services/converters/hamToDash.js';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmaf/ham/mapper/dash/DashMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Presentation } from '../../types/model/Presentation.js';
import { mapDashToHam } from './mapDashToHam/mapDashToHam.js';
import { mapHamToDash } from './mapHamToDash/mapHamToDash.js';

import { xmlToJson } from '../../utils/dash/xmlToJson.js';
import { parseDashManifest } from '../../utils/dash/parseDashManifest.js';
import { addMetadataToDash } from '../../utils/manifest/addMetadataToDash.js';
import { getMetadata } from '../../utils/manifest/getMetadata.js';

Expand All @@ -19,7 +19,7 @@ export class DashMapper implements Mapper {
}

toHam(manifest: Manifest): Presentation[] {
const dashManifest: DashManifest | undefined = xmlToJson(
const dashManifest: DashManifest | undefined = parseDashManifest(
manifest.manifest,
);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmaf/ham/mapper/dash/mapHamToDash/mapHamToDash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Period } from '../../../types/mapper/dash/Period.js';

import { presentationsToPeriods } from './presentationsToPeriods.js';

import { jsonToXml } from '../../../utils/dash/jsonToXml.js';
import { serializeDashManifest } from '../../../utils/dash/serializeDashManifest.js';

export function mapHamToDash(hamManifests: Presentation[]): string {
const periods: Period[] = presentationsToPeriods(hamManifests);
Expand All @@ -20,5 +20,5 @@ export function mapHamToDash(hamManifests: Presentation[]): string {
},
};

return jsonToXml(manifest);
return serializeDashManifest(manifest);
}
6 changes: 0 additions & 6 deletions lib/src/cmaf/ham/utils/dash/jsonToXml.ts

This file was deleted.

30 changes: 30 additions & 0 deletions lib/src/cmaf/ham/utils/dash/parseDashManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { DashManifest } from '../../types/mapper/dash/DashManifest.js';

export type DashParser = (raw: string) => DashManifest;

let dashParser: DashParser;

/**
* @internal
*/
export function setDashParser(parser: DashParser): void {
dashParser = parser;
}

/**
* @internal
*/
export function getDashParser(): DashParser {
return dashParser;
}

/**
* @internal
* Parse XML to Json
*
* @param raw - Raw string containing the xml from the Dash Manifest
* @returns json with the Dash Manifest structure
*/
export function parseDashManifest(raw: string): DashManifest {
return dashParser(raw);
}
23 changes: 23 additions & 0 deletions lib/src/cmaf/ham/utils/dash/serializeDashManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { DashManifest } from '../../types/mapper/dash/DashManifest';

export type DashSerializer = (json: DashManifest) => string;

let xmlSerializer: DashSerializer;

/**
* @internal
*/
export function setDashSerializer(serializer: DashSerializer): void {
xmlSerializer = serializer;
}

/**
* @internal
*/
export function getDashSerializer(): DashSerializer {
return xmlSerializer;
}

export function serializeDashManifest(json: DashManifest): string {
return xmlSerializer(json);
}
20 changes: 0 additions & 20 deletions lib/src/cmaf/ham/utils/dash/xmlToJson.ts

This file was deleted.

33 changes: 20 additions & 13 deletions lib/src/cmaf/ham/utils/hls/parseHlsManifest.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
// @ts-ignore
import { Parser } from 'm3u8-parser';
import type { HlsManifest } from '../../types/mapper/hls/HlsManifest.js';

export function parseHlsManifest(text: string | undefined): HlsManifest {
export type HlsParser = (text: string) => HlsManifest;

let hlsParser: HlsParser;

/**
* @internal
*/
export function setHlsParser(parser: HlsParser): void {
hlsParser = parser;
}

/**
* @internal
*/
export function getHlsParser(): HlsParser {
return hlsParser;
}

export function parseHlsManifest(text?: string): HlsManifest {
if (!text) {
console.error("Can't parse empty HLS Manifest");
return {} as HlsManifest;
}

const parser = new Parser();

parser.push(text);
parser.end();
const parsedHlsManifest = parser.manifest;
if (!parsedHlsManifest) {
throw new Error();
}

return parsedHlsManifest;
return hlsParser(text);
}
Loading

0 comments on commit 9a56ebb

Please sign in to comment.