Skip to content

Commit

Permalink
chore: dom testing config and initial mpd parsing scaffold (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
wseymour15 authored Oct 16, 2023
1 parent 11e0d45 commit 47fe2f5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = "./happydom.ts"
3 changes: 3 additions & 0 deletions happydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GlobalRegistrator } from "@happy-dom/global-registrator";

GlobalRegistrator.register();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build:dts": "dts-bundle-generator --config .dts-bundle-generator.config.json"
},
"devDependencies": {
"@happy-dom/global-registrator": "^12.9.1",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"bun-types": "^1.0.3",
Expand Down
28 changes: 28 additions & 0 deletions src/dash-parser/examples/mpd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const testString = `<?xml version="1.0" encoding="UTF-8"?><MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" maxSubsegmentDuration="PT5.0S" mediaPresentationDuration="PT9M57S" minBufferTime="PT5.0S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011,http://xmlns.sony.net/metadata/mpeg/dash/profile/senvu/2012" type="static" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd">
<Period duration="PT9M57S" id="P1">
<!-- Adaptation Set for main audio -->
<AdaptationSet audioSamplingRate="48000" codecs="mp4a.40.5" contentType="audio" group="2" id="2" lang="en" mimeType="audio/mp4" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
<Representation bandwidth="64000" id="2_1">
<BaseURL>DASH_vodaudio_Track5.m4a</BaseURL>
</Representation>
</AdaptationSet>
<!-- Adaptation Set for video -->
<AdaptationSet codecs="avc1.4D401E" contentType="video" frameRate="24000/1001" group="1" id="1" maxBandwidth="1609728" maxHeight="480" maxWidth="854" maximumSAPPeriod="5.0" mimeType="video/mp4" minBandwidth="452608" minHeight="480" minWidth="854" par="16:9" sar="1:1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
<Representation bandwidth="1005568" height="480" id="1_1" mediaStreamStructureId="1" width="854">
<BaseURL>DASH_vodvideo_Track2.m4v</BaseURL>
</Representation>
<Representation bandwidth="1609728" height="480" id="1_2" mediaStreamStructureId="1" width="854">
<BaseURL>DASH_vodvideo_Track1.m4v</BaseURL>
</Representation>
<Representation bandwidth="704512" height="480" id="1_3" mediaStreamStructureId="1" width="854">
<BaseURL>DASH_vodvideo_Track3.m4v</BaseURL>
</Representation>
<Representation bandwidth="452608" height="480" id="1_4" mediaStreamStructureId="1" width="854">
<BaseURL>DASH_vodvideo_Track4.m4v</BaseURL>
</Representation>
</AdaptationSet>
</Period>
</MPD>`;
4 changes: 1 addition & 3 deletions src/dash-parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export default function () {
return 'hello from dash-parser';
}
export { default as parse } from './parse.ts';
19 changes: 19 additions & 0 deletions src/dash-parser/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ParsedManifest } from "./types/parsedManifest";
import { testString } from "./examples/mpd";

/**
* Parses a MPD manifest file.
*
* @param playlist The URL of the mpd manifest to be parsed.
*/
export default function parse(playlist: string): ParsedManifest {
const parsedManifest: ParsedManifest = {
segments: [],
custom: {}
};

// TODO: implement parsing.
var doc = new DOMParser().parseFromString(testString, 'text/xml');

return parsedManifest;
}
5 changes: 5 additions & 0 deletions src/dash-parser/types/parsedManifest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ParsedManifest {
// TODO: There will be more fields here
segments: Array<unknown>;
custom: unknown;
}
8 changes: 6 additions & 2 deletions test/dash-parser/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import parse from '@/dash-parser/parse';
import { testString } from '@/dash-parser/examples/mpd';
import { describe, it, expect } from 'bun:test';

describe('dash-parser spec', () => {
it('mock spec', () => {
expect(true).toBe(true);
// TODO: create valid tests
it('testString should give us JSON', () => {
const parsed = parse(testString);
expect(parsed.segments.length).toBe(0);
});
});

0 comments on commit 47fe2f5

Please sign in to comment.