Skip to content

Commit

Permalink
feat: CMAF-Ham (#87)
Browse files Browse the repository at this point in the history
* Fix line issue

* Add byterange and url to track

* feat: Upgraded way to get codecs, frame rate, sar and number of segments.

* Add map to hls manifest

* Add quotes

* feat: Set und as empty language. Upgrade getChannels feature

* Add quotes

* Add sample cases

* Delete unnecesary tests

* Fix mapMpdToHam to parse mimeType, name and SegmentList

* fix: Fix tests.

* Delete test files and update newline formatter

* Fix typo issue

* Format code

* feat: Add 4 more samples that should be playable with a player.

* Working on converting mpd to ham and ham to mpd making it playable

* Fix mapMpdToHam and mapHamToMpd to consider segment list case, now mpdsample5 is working

* Fix mapMpdToHam and mapHamToMpd to consider segment list case, now mpdsample5 is working

* Change tabs for spaces in mpdSample5.ts

* Put original mpdSample5 xml code

* feat: Fix audio properties. Reduce long functions file.

* Undo eslint brace style log level change

* Update test imports

* Add playlist for manifest samples and fix undefined issue

* Delete output folder

* Convert tracks types to lower case when comparing

* Change the way unhandled undefined attributes are set

* Change hls manifest url

* Fix mapHamToHls checks

* fix: fix types export

* Fix Manifest import

* feat: Add some CMAF-HAM documentation

* feat: Set version to alpha instead of beta.

* feat: Create default export for cmaf-ham

* Add media-sequence and playlist type in hls resulting manifest

* Add end list tag

* Add documentation for track validity

* Add documentation for track validity type

* fix: Fix duration from mapper.

* fix: Update doc description.

* Update lib/src/cmaf/ham/mapper/hls/mapHamToHls.ts

Co-authored-by: Patricio Carrau <[email protected]>
Signed-off-by: Noelia Bentancor <[email protected]>

* Delete unnecesary condition

* feat: Fix mapper from ham to dash

* feat: Fix mapper from ham to dash. Add function description

* feat: Add documentation.

* feat: Remove comment

* feat: Upgrade ham to mpd timescale conversion.

* feat: Change ham to mpd function names.

* Fix byterange

* Delete unnecesary test

* feat: Update function names. Create unit tests.

* feat: Add more tests

* Add check for segment byterange

* Add url init to ham

* Format init url

* Add init url

* Delete unnecesary comment

* Delete unnecesary manifest sample

* Change track name to filename

* Extract initialization url to another function

* Update lib/src/cmaf/ham/mapper/hls/mapHamToHls.ts

Co-authored-by: Matías Rodriguez <[email protected]>
Signed-off-by: Noelia Bentancor <[email protected]>

* Add white space and white space encoded

* Delete harcoded code

* Add constants file in utils

* Change attribute name for file

* Fix text track hls map

* Fix text track for concating

* Fix representation mime type

* Delete test

* Fix expression condition

* Fix get url init function@

* Refactor code

* Improve code

* Improve code

* feat: Create HLS integration tests.

* Change types to lowercase

* Place hls and dash manifest in mappers folder

* Delete manifest samples

* Fix HLS to DASH conversion

* Add documentation for track

* Refactor mapHlsToHam

* Add more unit tests. Remove byteRange when unnecessary

* feat: Refactor HLS to be easier to understand and test. Remove old files.

* Create three constants for timescale, and put comments to explain some temp decisions

* Update TODO comment

* Set sample rate values as constants.

* Fix TARGETDURATION in HLS conversion

* Add hls unit tests

* Change m3u8 to hls

* Fix consistency in hls and dash nomenclature

* Update documentation

* Fix nomenclature issue related to hls and dash

* Add documentation for track

* Change uppercase in track formats

* Change nomenclature

* Refactor code

* Update documentation

* Change names

* Change name

* Update documentation

* Add more documentation

* Add aligned switching set type

* Types improvements

* Change map ham to dash

* Fix variable names

* Refactor code@

* Place hls manifest at the top of the code

* Update MPD tests with new HAM. Reformat hsl to ham mapper.

* Fix merge

* Fix imports

* Add first approach of readme

* Modify readme

* Add overview and features of the project

* Add features of the project in readme

* Improve documentation

* Change readme

* Change frameRate to two attributes numerator and denominator

* Fix merge problems.

* Update sample rate comments and constants.

* comments

* Change frameRate to a type with two values and put some constants to retrieve frameRate

* Delete validation track

* Fix typo error and put FrameRate type definition at the bottom of VideoTrack

* feat: Fix border cases for HLS. Move HLS samples. Update and fix tests.

* Methods refactor

* Use zero instead of undefined for denominator

* feat: Separate code into functions. Create tests.

* Create validation service

* Upgrade HlsManifest type. Fix some border cases. Add and fix tests.

* Remove validateTracks.ts file

* Delete track validation

* Introduce prevValidation in the validate methods to do avoid repeating code

* Fix PR comments.

* Update lib/src/cmaf/README.md

* Delete arrow functions

* Add prevValidation param to the docs in validate methods and create tests

* Remove string constants with samples. Set all samples to mpd or m3u8.

* Readd samples

* Delete unused file

* Support having SegmentList tag outside Representation tag and update tests

* Fix frameRate parsing

* Fix how the audio and subtitle groups are handled

* Change subtitleTracks name to textTracks to use ham concepts

* Fix failing test and types import

* Move conversion of the track to VideoTrack inside the if statement

* Add frameRate to Representation in Dash

* Update manifest 3

* Add docs.

* Delete unnecesary playlists

* Remove unnecesary playlists

* Fix dash tests.

* Add condition in track

* Fix hls tests.

* Fix some ham tests.

* Add new case when getting url from template

* Fix sample 2

* Delete functions

* Add imports

* Delete unnecesary spaces

* Update imports

* fix: Fix multiple tests. Remove old hls sample. Add new tests.

* Changed deepEqual to deepStrictEqual. Fix hls tests.

* Add more typedoc documentation.

* Add examples to validate.ts

* Use fileName if exists or the track id if fileName attribute does not exist.

* Undo changes in package.json

* Add docs to ham to dash and ham to dash

* Fix HLS sample 1 references

* Fix documentation

* Fix documentation

* Fixes in punctuation

* fixes in validation

* Modify targer duration

* reorder cmaf-ham files

* cmaf-ham: move tests from src/ to test/

* samples: added cmaf-ham-conversion sample

* samples: cmaf-ham-conversion fix typo in readme

* mapHamToHls: change default HLS EXT-X-VERSION from 1 to 7

* cmaf-man-conversion: export a file with the result of the validations

* cmaf-ham-conversion: README improvements

* cmaf-ham-conversion: added serve and player instructions in README

* deleted prettier and unused packages

* Functions are separated in new files  and the imports are refactored

* cmaf-ham-conversion: rename output folder to dist

* cmaf-ham-conversion: fix dependencies

* cmaf-ham-conversion: remove not needed dependencies

* add samples to workspaces and move cmaf-ham-conversion folder

* fix remove prettier scripts from package.json

* cmaf-ham.ts: fix blank space in

* fix some doc warnings

* Update .eslintrc.json

Signed-off-by: Casey Occhialini <[email protected]>

* move types to separate files

* move types to separate files

Signed-off-by: Casey Occhialini <[email protected]>

* Updated CHANGELOG.md

Signed-off-by: Nicolas Levy <[email protected]>

---------
Signed-off-by: Noelia Bentancor <[email protected]>
Signed-off-by: Casey Occhialini <[email protected]>
Signed-off-by: Nicolas Levy <[email protected]>
Co-authored-by: Noelia Bentancor <[email protected]>
Co-authored-by: DuckyCB <[email protected]>
Co-authored-by: Matías Rodriguez <[email protected]>
Co-authored-by: Matías Rodriguez <[email protected]>
Co-authored-by: Patricio Carrau <[email protected]>
Co-authored-by: Casey Occhialini <[email protected]>
Signed-off-by: Casey Occhialini <[email protected]>
  • Loading branch information
7 people committed Jun 5, 2024
1 parent 6b28c1a commit 1783a81
Show file tree
Hide file tree
Showing 217 changed files with 64,737 additions and 420 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
dist
temp
.vscode
.idea
RELEASE.md
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add CMAF-Ham types, mappers and services to convert and manipulate VOD HLS and VOD DASH manifests.
- Add cmaf-ham-converter sample to showcase the CMAF-Ham functions.

## [0.6.4] - 2024-03-04

Expand Down
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"exclude": [
"**/node_modules",
"**/dist"
"**/dist",
"**/samples"
],
"include": [
"**/*.js"
Expand Down
212 changes: 186 additions & 26 deletions lib/config/common-media-library.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
```ts

// @alpha
export type AlignedSwitchingSet = {
switchingSets: SwitchingSet[];
};

// @beta
export function appendCmcdHeaders(headers: Record<string, string>, cmcd: Cmcd, options?: CmcdEncodeOptions): Record<string, string>;

// @beta
export function appendCmcdQuery(url: string, cmcd: Cmcd, options?: CmcdEncodeOptions): string;

// @alpha
export type AudioTrack = Track & {
sampleRate: number;
channels: number;
};

// @beta
export function base64decode(str: string): Uint8Array;

Expand All @@ -31,12 +42,12 @@ export interface Cmcd {
mtp?: number;
nor?: string;
nrr?: string;
ot?: CmObjectType;
ot?: CmcdObjectType;
pr?: number;
rtp?: number;
sf?: CmStreamingFormat;
sf?: CmcdStreamingFormat;
sid?: string;
st?: CmStreamType;
st?: CmcdStreamType;
su?: boolean;
tb?: number;
v?: number;
Expand All @@ -49,7 +60,7 @@ export const CMCD_PARAM = "CMCD";
export const CMCD_V1 = 1;

// @beta
export type CmcdCustomKey = CmCustomKey;
export type CmcdCustomKey = `${string}-${string}`;

// @beta
export interface CmcdEncodeOptions {
Expand Down Expand Up @@ -87,13 +98,7 @@ export type CmcdHeadersMap = Record<CmcdHeaderField, CmcdKey[]>;
export type CmcdKey = keyof Cmcd;

// @beta
export type CmcdValue = CmValue;

// @beta
export type CmCustomKey = `${string}-${string}`;

// @beta
enum CmObjectType {
export enum CmcdObjectType {
AUDIO = "a",
CAPTION = "c",
INIT = "i",
Expand All @@ -104,8 +109,28 @@ enum CmObjectType {
TIMED_TEXT = "tt",
VIDEO = "v"
}
export { CmObjectType as CmcdObjectType }
export { CmObjectType as CmsdObjectType }

// @beta
export enum CmcdStreamingFormat {
DASH = "d",
HLS = "h",
OTHER = "o",
SMOOTH = "s"
}

// @beta
export enum CmcdStreamType {
LIVE = "l",
VOD = "v"
}

// @beta
export type CmcdValue = CmcdObjectType | CmcdStreamingFormat | CmcdStreamType | string | number | boolean | symbol | SfToken;

// Warning: (ae-internal-missing-underscore) The name "CmCustomKey" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export type CmCustomKey = `${string}-${string}`;

// @beta
export const CMSD_DYNAMIC = "CMSD-Dynamic";
Expand All @@ -117,7 +142,7 @@ export const CMSD_STATIC = "CMSD-Static";
export const CMSD_V1 = 1;

// @beta
export type CmsdCustomKey = CmCustomKey;
export type CmsdCustomKey = `${string}-${string}`;

// @beta
export interface CmsdDynamic {
Expand Down Expand Up @@ -146,6 +171,19 @@ export enum CmsdHeaderField {
STATIC = "CMSD-Static"
}

// @beta
export enum CmsdObjectType {
AUDIO = "a",
CAPTION = "c",
INIT = "i",
KEY = "k",
MANIFEST = "m",
MUXED = "av",
OTHER = "o",
TIMED_TEXT = "tt",
VIDEO = "v"
}

// @beta
export interface CmsdStatic {
[index: CmsdCustomKey]: CmsdValue;
Expand All @@ -156,35 +194,36 @@ export interface CmsdStatic {
n?: string;
nor?: string;
nrr?: string;
ot?: CmObjectType;
sf?: CmStreamingFormat;
st?: CmStreamType;
ot?: CmsdObjectType;
sf?: CmsdStreamingFormat;
st?: CmsdStreamType;
su?: boolean;
v?: number;
}

// @beta
export type CmsdValue = CmValue;

// @beta
enum CmStreamingFormat {
export enum CmsdStreamingFormat {
DASH = "d",
HLS = "h",
OTHER = "o",
SMOOTH = "s"
}
export { CmStreamingFormat as CmcdStreamingFormat }
export { CmStreamingFormat as CmsdStreamingFormat }

// @beta
enum CmStreamType {
export enum CmsdStreamType {
LIVE = "l",
VOD = "v"
}
export { CmStreamType as CmcdStreamType }
export { CmStreamType as CmsdStreamType }

// @beta
export type CmsdValue = CmsdObjectType | CmsdStreamingFormat | CmsdStreamType | string | number | boolean | symbol | SfToken;

// Warning: (ae-forgotten-export) The symbol "CmObjectType" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CmStreamingFormat" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CmStreamType" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "CmValue" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export type CmValue = CmObjectType | CmStreamingFormat | CmStreamType | string | number | boolean | symbol | SfToken;

// @beta
Expand Down Expand Up @@ -213,6 +252,9 @@ export interface CommonMediaResponse {
url?: string;
}

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

// @beta
export function decodeCmcd(cmcd: string): Cmcd;

Expand Down Expand Up @@ -279,6 +321,24 @@ export function getId3Frames(id3Data: Uint8Array): Id3Frame[];
// @beta
export function getId3Timestamp(data: Uint8Array): number | undefined;

// @alpha
export function getTracksFromPresentation(presentation: Presentation, predicate?: (track: Track) => boolean): Track[];

// @alpha
export function getTracksFromSelectionSet(selectionSet: SelectionSet, predicate?: (track: Track) => boolean): Track[];

// @alpha
export function getTracksFromSwitchingSet(switchingSet: SwitchingSet, predicate?: (track: Track) => boolean): Track[];

// @alpha
export function hamToDash(presentation: Presentation[]): Manifest;

// @alpha
export function hamToHls(presentation: Presentation[]): Manifest;

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

// @beta
export type Id3Frame = DecodedId3Frame<ArrayBuffer | string | number>;

Expand All @@ -287,6 +347,22 @@ export type Id3Frame = DecodedId3Frame<ArrayBuffer | string | number>;
// @internal
export function isId3TimestampFrame(frame: Id3Frame): boolean;

// @alpha
export type Manifest = {
manifest: string;
fileName?: string;
ancillaryManifests?: Manifest[];
type: ManifestFormat;
metadata?: Map<string, string>;
};

// Warning: (ae-forgotten-export) The symbol "Ham" needs to be exported by the entry point index.d.ts
//
// @alpha
export type Presentation = Ham & {
selectionSets: SelectionSet[];
};

// @beta
export type RequestInterceptor = (request: CommonMediaRequest) => Promise<CommonMediaRequest>;

Expand All @@ -310,6 +386,19 @@ export type ResponseInterceptor = (response: CommonMediaResponse) => Promise<Com
// @beta
export function roundToEven(value: number, precision: number): number;

// @alpha
export type Segment = {
duration: number;
url: string;
byteRange?: string;
};

// @alpha
export type SelectionSet = Ham & {
switchingSets: SwitchingSet[];
alignedSwitchingSets?: AlignedSwitchingSet[];
};

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

Expand Down Expand Up @@ -354,6 +443,15 @@ export class SfToken {
description: string;
}

// @alpha
export type SwitchingSet = Ham & {
tracks: Track[];
};

// @alpha
type TextTrack_2 = Track;
export { TextTrack_2 as TextTrack }

// @beta
export function toCmcdHeaders(cmcd: Cmcd, options?: CmcdEncodeOptions): {};

Expand All @@ -363,6 +461,19 @@ export function toCmcdJson(cmcd: Cmcd, options?: CmcdEncodeOptions): string;
// @beta
export function toCmcdQuery(cmcd: Cmcd, options?: CmcdEncodeOptions): string;

// @alpha
export type Track = Ham & {
type: TrackType;
fileName?: string;
codec: string;
duration: number;
language: string;
bandwidth: number;
byteRange?: string;
urlInitialization?: string;
segments: Segment[];
};

// @beta
export function urlToRelativePath(url: string, base: string): string;

Expand All @@ -372,4 +483,53 @@ export function utf8ArrayToStr(array: Uint8Array, exitOnNull?: boolean): string;
// @beta
export function uuid(): string;

// @alpha
export function validatePresentation(presentation: Presentation): Validation;

// @alpha
export function validateSegment(segment: Segment, trackId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateSegments(segments: Segment[], trackId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateSelectionSet(selectionSet: SelectionSet, presentationId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateSelectionSets(selectionSets: SelectionSet[], presentationId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateSwitchingSet(switchingSet: SwitchingSet, selectionSetId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateSwitchingSets(switchingSets: SwitchingSet[], selectionSetId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateTrack(track: Track, switchingSetId?: string, prevValidation?: Validation): Validation;

// @alpha
export function validateTracks(tracks: Track[], switchingSetId?: string, prevValidation?: Validation): Validation;

// @alpha
export type Validation = {
status: boolean;
errorMessages: string[];
};

// @alpha
export type VideoTrack = Track & {
width: number;
height: number;
frameRate: FrameRate;
par: string;
sar: string;
scanType: string;
};

// Warnings were encountered during analysis:
//
// src/cmaf/ham/types/manifest/Manifest.ts:13:2 - (ae-forgotten-export) The symbol "ManifestFormat" needs to be exported by the entry point index.d.ts
// src/cmaf/ham/types/model/Track.ts:23:2 - (ae-forgotten-export) The symbol "TrackType" needs to be exported by the entry point index.d.ts
// src/cmaf/ham/types/model/VideoTrack.ts:19:2 - (ae-forgotten-export) The symbol "FrameRate" needs to be exported by the entry point index.d.ts

```
Loading

0 comments on commit 1783a81

Please sign in to comment.