@amazon/vinyl-mpd-parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/dashTestAssets/index.js +1559 -0
  2. package/dist/dashTestAssets/index.js.map +7 -0
  3. package/dist/dashTestAssets/types/current/dash_personalizedResponse.d.ts +6 -0
  4. package/dist/dashTestAssets/types/current/dash_personalizedResponse.d.ts.map +1 -0
  5. package/dist/dashTestAssets/types/current/dash_personalizedResponse.js +831 -0
  6. package/dist/dashTestAssets/types/current/dash_segmentBase.d.ts +5 -0
  7. package/dist/dashTestAssets/types/current/dash_segmentBase.d.ts.map +1 -0
  8. package/dist/dashTestAssets/types/current/dash_segmentBase.js +144 -0
  9. package/dist/dashTestAssets/types/current/dash_segmentList.d.ts +6 -0
  10. package/dist/dashTestAssets/types/current/dash_segmentList.d.ts.map +1 -0
  11. package/dist/dashTestAssets/types/current/dash_segmentList.js +107 -0
  12. package/dist/dashTestAssets/types/current/dash_segmentListMediaRange.d.ts +8 -0
  13. package/dist/dashTestAssets/types/current/dash_segmentListMediaRange.d.ts.map +1 -0
  14. package/dist/dashTestAssets/types/current/dash_segmentListMediaRange.js +472 -0
  15. package/dist/dashTestAssets/types/current/dash_segmentTemplate.d.ts +5 -0
  16. package/dist/dashTestAssets/types/current/dash_segmentTemplate.d.ts.map +1 -0
  17. package/dist/dashTestAssets/types/current/dash_segmentTemplate.js +34 -0
  18. package/dist/dashTestAssets/types/current/index.d.ts +7 -0
  19. package/dist/dashTestAssets/types/current/index.d.ts.map +1 -0
  20. package/dist/dashTestAssets/types/current/index.js +6 -0
  21. package/dist/dashTestAssets/types/current/tsconfig.tsbuildinfo +1 -0
  22. package/dist/dashTestAssets/types/ts3.7/dash_personalizedResponse.d.ts +6 -0
  23. package/dist/dashTestAssets/types/ts3.7/dash_segmentBase.d.ts +5 -0
  24. package/dist/dashTestAssets/types/ts3.7/dash_segmentList.d.ts +6 -0
  25. package/dist/dashTestAssets/types/ts3.7/dash_segmentListMediaRange.d.ts +8 -0
  26. package/dist/dashTestAssets/types/ts3.7/dash_segmentTemplate.d.ts +5 -0
  27. package/dist/dashTestAssets/types/ts3.7/index.d.ts +7 -0
  28. package/dist/dashTestAssets/types/ts4.1/dash_personalizedResponse.d.ts +6 -0
  29. package/dist/dashTestAssets/types/ts4.1/dash_segmentBase.d.ts +5 -0
  30. package/dist/dashTestAssets/types/ts4.1/dash_segmentList.d.ts +6 -0
  31. package/dist/dashTestAssets/types/ts4.1/dash_segmentListMediaRange.d.ts +8 -0
  32. package/dist/dashTestAssets/types/ts4.1/dash_segmentTemplate.d.ts +5 -0
  33. package/dist/dashTestAssets/types/ts4.1/index.d.ts +7 -0
  34. package/dist/dashTestAssets/types/ts4.7/dash_personalizedResponse.d.ts +6 -0
  35. package/dist/dashTestAssets/types/ts4.7/dash_segmentBase.d.ts +5 -0
  36. package/dist/dashTestAssets/types/ts4.7/dash_segmentList.d.ts +6 -0
  37. package/dist/dashTestAssets/types/ts4.7/dash_segmentListMediaRange.d.ts +8 -0
  38. package/dist/dashTestAssets/types/ts4.7/dash_segmentTemplate.d.ts +5 -0
  39. package/dist/dashTestAssets/types/ts4.7/index.d.ts +7 -0
  40. package/dist/index.cjs +583 -0
  41. package/dist/index.cjs.map +7 -0
  42. package/dist/index.js +584 -0
  43. package/dist/index.js.map +7 -0
  44. package/dist/test/benchmark.es5.js +566 -0
  45. package/dist/test/benchmark.js +4497 -0
  46. package/dist/test/benchmark.js.map +7 -0
  47. package/dist/types/current/duration/duration.d.ts +34 -0
  48. package/dist/types/current/duration/duration.d.ts.map +1 -0
  49. package/dist/types/current/duration/duration.js +83 -0
  50. package/dist/types/current/error/parsingError.d.ts +2 -0
  51. package/dist/types/current/error/parsingError.d.ts.map +1 -0
  52. package/dist/types/current/error/parsingError.js +8 -0
  53. package/dist/types/current/index.d.ts +16 -0
  54. package/dist/types/current/index.d.ts.map +1 -0
  55. package/dist/types/current/index.js +15 -0
  56. package/dist/types/current/manifest/dashManifestXmlRules.d.ts +65 -0
  57. package/dist/types/current/manifest/dashManifestXmlRules.d.ts.map +1 -0
  58. package/dist/types/current/manifest/dashManifestXmlRules.js +360 -0
  59. package/dist/types/current/manifest/dashParser.d.ts +23 -0
  60. package/dist/types/current/manifest/dashParser.d.ts.map +1 -0
  61. package/dist/types/current/manifest/dashParser.js +28 -0
  62. package/dist/types/current/manifest/ext/drm/ContentProtectionScheme.d.ts +31 -0
  63. package/dist/types/current/manifest/ext/drm/ContentProtectionScheme.d.ts.map +1 -0
  64. package/dist/types/current/manifest/ext/drm/ContentProtectionScheme.js +34 -0
  65. package/dist/types/current/manifest/ext/drm/cencXmlRules.d.ts +8 -0
  66. package/dist/types/current/manifest/ext/drm/cencXmlRules.d.ts.map +1 -0
  67. package/dist/types/current/manifest/ext/drm/cencXmlRules.js +21 -0
  68. package/dist/types/current/manifest/ext/drm/contentProtection.d.ts +32 -0
  69. package/dist/types/current/manifest/ext/drm/contentProtection.d.ts.map +1 -0
  70. package/dist/types/current/manifest/ext/drm/contentProtection.js +32 -0
  71. package/dist/types/current/manifest/ext/drm/playreadyXmlRules.d.ts +4 -0
  72. package/dist/types/current/manifest/ext/drm/playreadyXmlRules.d.ts.map +1 -0
  73. package/dist/types/current/manifest/ext/drm/playreadyXmlRules.js +13 -0
  74. package/dist/types/current/media/byteRange.d.ts +12 -0
  75. package/dist/types/current/media/byteRange.d.ts.map +1 -0
  76. package/dist/types/current/media/byteRange.js +30 -0
  77. package/dist/types/current/media/frameRate.d.ts +14 -0
  78. package/dist/types/current/media/frameRate.d.ts.map +1 -0
  79. package/dist/types/current/media/frameRate.js +25 -0
  80. package/dist/types/current/media/ratio.d.ts +24 -0
  81. package/dist/types/current/media/ratio.d.ts.map +1 -0
  82. package/dist/types/current/media/ratio.js +36 -0
  83. package/dist/types/current/tsconfig.tsbuildinfo +1 -0
  84. package/dist/types/current/xmlns/microsoft/playready.d.ts +12 -0
  85. package/dist/types/current/xmlns/microsoft/playready.d.ts.map +1 -0
  86. package/dist/types/current/xmlns/microsoft/playready.js +11 -0
  87. package/dist/types/current/xmlns/mpeg/cenc/2013.d.ts +19 -0
  88. package/dist/types/current/xmlns/mpeg/cenc/2013.d.ts.map +1 -0
  89. package/dist/types/current/xmlns/mpeg/cenc/2013.js +11 -0
  90. package/dist/types/current/xmlns/mpeg/dash/schema/mpd/2011.d.ts +918 -0
  91. package/dist/types/current/xmlns/mpeg/dash/schema/mpd/2011.d.ts.map +1 -0
  92. package/dist/types/current/xmlns/mpeg/dash/schema/mpd/2011.js +5 -0
  93. package/dist/types/ts3.7/duration/duration.d.ts +34 -0
  94. package/dist/types/ts3.7/error/parsingError.d.ts +2 -0
  95. package/dist/types/ts3.7/index.d.ts +16 -0
  96. package/dist/types/ts3.7/manifest/dashManifestXmlRules.d.ts +65 -0
  97. package/dist/types/ts3.7/manifest/dashParser.d.ts +23 -0
  98. package/dist/types/ts3.7/manifest/ext/drm/ContentProtectionScheme.d.ts +31 -0
  99. package/dist/types/ts3.7/manifest/ext/drm/cencXmlRules.d.ts +8 -0
  100. package/dist/types/ts3.7/manifest/ext/drm/contentProtection.d.ts +32 -0
  101. package/dist/types/ts3.7/manifest/ext/drm/playreadyXmlRules.d.ts +4 -0
  102. package/dist/types/ts3.7/media/byteRange.d.ts +15 -0
  103. package/dist/types/ts3.7/media/frameRate.d.ts +17 -0
  104. package/dist/types/ts3.7/media/ratio.d.ts +27 -0
  105. package/dist/types/ts3.7/xmlns/microsoft/playready.d.ts +12 -0
  106. package/dist/types/ts3.7/xmlns/mpeg/cenc/2013.d.ts +19 -0
  107. package/dist/types/ts3.7/xmlns/mpeg/dash/schema/mpd/2011.d.ts +918 -0
  108. package/dist/types/ts4.1/duration/duration.d.ts +34 -0
  109. package/dist/types/ts4.1/error/parsingError.d.ts +2 -0
  110. package/dist/types/ts4.1/index.d.ts +16 -0
  111. package/dist/types/ts4.1/manifest/dashManifestXmlRules.d.ts +65 -0
  112. package/dist/types/ts4.1/manifest/dashParser.d.ts +23 -0
  113. package/dist/types/ts4.1/manifest/ext/drm/ContentProtectionScheme.d.ts +31 -0
  114. package/dist/types/ts4.1/manifest/ext/drm/cencXmlRules.d.ts +8 -0
  115. package/dist/types/ts4.1/manifest/ext/drm/contentProtection.d.ts +32 -0
  116. package/dist/types/ts4.1/manifest/ext/drm/playreadyXmlRules.d.ts +4 -0
  117. package/dist/types/ts4.1/media/byteRange.d.ts +15 -0
  118. package/dist/types/ts4.1/media/frameRate.d.ts +17 -0
  119. package/dist/types/ts4.1/media/ratio.d.ts +27 -0
  120. package/dist/types/ts4.1/xmlns/microsoft/playready.d.ts +12 -0
  121. package/dist/types/ts4.1/xmlns/mpeg/cenc/2013.d.ts +19 -0
  122. package/dist/types/ts4.1/xmlns/mpeg/dash/schema/mpd/2011.d.ts +918 -0
  123. package/dist/types/ts4.7/duration/duration.d.ts +34 -0
  124. package/dist/types/ts4.7/error/parsingError.d.ts +2 -0
  125. package/dist/types/ts4.7/index.d.ts +16 -0
  126. package/dist/types/ts4.7/manifest/dashManifestXmlRules.d.ts +65 -0
  127. package/dist/types/ts4.7/manifest/dashParser.d.ts +23 -0
  128. package/dist/types/ts4.7/manifest/ext/drm/ContentProtectionScheme.d.ts +31 -0
  129. package/dist/types/ts4.7/manifest/ext/drm/cencXmlRules.d.ts +8 -0
  130. package/dist/types/ts4.7/manifest/ext/drm/contentProtection.d.ts +32 -0
  131. package/dist/types/ts4.7/manifest/ext/drm/playreadyXmlRules.d.ts +4 -0
  132. package/dist/types/ts4.7/media/byteRange.d.ts +15 -0
  133. package/dist/types/ts4.7/media/frameRate.d.ts +17 -0
  134. package/dist/types/ts4.7/media/ratio.d.ts +27 -0
  135. package/dist/types/ts4.7/xmlns/microsoft/playready.d.ts +12 -0
  136. package/dist/types/ts4.7/xmlns/mpeg/cenc/2013.d.ts +19 -0
  137. package/dist/types/ts4.7/xmlns/mpeg/dash/schema/mpd/2011.d.ts +918 -0
  138. package/package.json +101 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A duration, in seconds. (This may be negative)
3
+ */
4
+ export type Duration = number;
5
+ /**
6
+ * Parses an ISO 8601 duration into seconds.
7
+ * The accepted format is P(n)Y(n)M(n)DT(n)H(n)M(n)S
8
+ *
9
+ * All units shall have a fixed size.
10
+ *
11
+ * P - Period designator, precedes all durations.
12
+ * 1Y (Year) = 365 * 24 * 60 * 60 Seconds
13
+ * 1M (Month) = 30 * 24 * 60 * 60 Seconds
14
+ * 1D (Day) = 24 * 60 * 60 Seconds
15
+ *
16
+ * T - Time designator, precedes all time components.
17
+ * 1H (Hour) = 60 * 60 Seconds
18
+ * 1M (Minute) = 60 Seconds
19
+ * 1S (Second)
20
+ *
21
+ *
22
+ * @param value
23
+ * @return Returns the duration in seconds or throws an {@link ValidationError}
24
+ * if not properly formatted.
25
+ * @see https://www.w3.org/TR/xmlschema-2/#duration
26
+ */
27
+ export declare function parseDuration(value: string): Duration;
28
+ /**
29
+ * Returns the iso 8601 string representation of a duration value.
30
+ *
31
+ * @param value A duration value, in seconds.
32
+ */
33
+ export declare function stringifyDuration(value: Duration): string;
34
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../../../src/duration/duration.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAQ7B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAkBrD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAoBzD"}
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { ErrorOrigin, roundToNearest, ValidationError, } from '@amazon/vinyl-util';
6
+ // ESBuild (https://github.com/evanw/esbuild/issues/3988) considers multiplication and division
7
+ // to have a side effect and will inhibit tree shaking.
8
+ // E.g. H = 60 * 60 will not be removed when not referenced.
9
+ const I = 60;
10
+ const H = 3600;
11
+ const D = 86400;
12
+ const M = 2592000;
13
+ const Y = 31536000;
14
+ /**
15
+ * https://www.w3.org/TR/xmlschema-2/#duration
16
+ */
17
+ const iso8601Duration = /^(-?)P?(\d+(?:\.\d*)?Y)?(\d+(?:\.\d*)?M)?(\d+(?:\.\d*)?D)?T?(\d+(?:\.\d*)?H)?(\d+(?:\.\d*)?M)?(\d+(?:\.\d*)?S?)?$/i;
18
+ /**
19
+ * Parses an ISO 8601 duration into seconds.
20
+ * The accepted format is P(n)Y(n)M(n)DT(n)H(n)M(n)S
21
+ *
22
+ * All units shall have a fixed size.
23
+ *
24
+ * P - Period designator, precedes all durations.
25
+ * 1Y (Year) = 365 * 24 * 60 * 60 Seconds
26
+ * 1M (Month) = 30 * 24 * 60 * 60 Seconds
27
+ * 1D (Day) = 24 * 60 * 60 Seconds
28
+ *
29
+ * T - Time designator, precedes all time components.
30
+ * 1H (Hour) = 60 * 60 Seconds
31
+ * 1M (Minute) = 60 Seconds
32
+ * 1S (Second)
33
+ *
34
+ *
35
+ * @param value
36
+ * @return Returns the duration in seconds or throws an {@link ValidationError}
37
+ * if not properly formatted.
38
+ * @see https://www.w3.org/TR/xmlschema-2/#duration
39
+ */
40
+ export function parseDuration(value) {
41
+ const match = iso8601Duration.exec(value);
42
+ if (match == null)
43
+ throw new ValidationError(`Unexpected duration: '${value}', should be in iso 8601 format`, ErrorOrigin.PARSING);
44
+ const sign = match[1] === '-' ? -1 : 1;
45
+ return (sign *
46
+ (parseFloat(match[2] || '0') * Y +
47
+ parseFloat(match[3] || '0') * M +
48
+ parseFloat(match[4] || '0') * D +
49
+ parseFloat(match[5] || '0') * H +
50
+ parseFloat(match[6] || '0') * I +
51
+ parseFloat(match[7] || '0')));
52
+ }
53
+ /**
54
+ * Returns the iso 8601 string representation of a duration value.
55
+ *
56
+ * @param value A duration value, in seconds.
57
+ */
58
+ export function stringifyDuration(value) {
59
+ const sign = value < 0 ? '-' : '';
60
+ let abs = Math.abs(value);
61
+ const years = Math.floor(abs / Y);
62
+ abs -= years * Y;
63
+ const months = Math.floor((abs % Y) / M);
64
+ const days = Math.floor((abs % M) / D);
65
+ const hours = Math.floor((abs % D) / H);
66
+ const minutes = Math.floor((abs % H) / I);
67
+ const seconds = abs % I;
68
+ let isoString = `${sign}P`;
69
+ if (years > 0)
70
+ isoString += `${years}Y`;
71
+ if (months > 0)
72
+ isoString += `${months}M`;
73
+ if (days > 0)
74
+ isoString += `${days}D`;
75
+ isoString += 'T';
76
+ if (hours > 0)
77
+ isoString += `${hours}H`;
78
+ if (minutes > 0)
79
+ isoString += `${minutes}M`;
80
+ if (seconds > 0 || !value)
81
+ isoString += `${roundToNearest(seconds, 0.001)}S`;
82
+ return isoString;
83
+ }
@@ -0,0 +1,2 @@
1
+ export declare function throwParsingError(message: string): never;
2
+ //# sourceMappingURL=parsingError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsingError.d.ts","sourceRoot":"","sources":["../../../../src/error/parsingError.ts"],"names":[],"mappings":"AAOA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAExD"}
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { ErrorOrigin, ValidationError } from '@amazon/vinyl-util';
6
+ export function throwParsingError(message) {
7
+ throw new ValidationError(message, ErrorOrigin.PARSING);
8
+ }
@@ -0,0 +1,16 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './xmlns/mpeg/dash/schema/mpd/2011';
3
+ export * from './xmlns/mpeg/cenc/2013';
4
+ export * from './xmlns/microsoft/playready';
5
+ export * from './media/ratio';
6
+ export * from './media/frameRate';
7
+ export * from './media/byteRange';
8
+ export * from './manifest/dashParser';
9
+ export * from './manifest/dashManifestXmlRules';
10
+ export * from './manifest/ext/drm/playreadyXmlRules';
11
+ export * from './manifest/ext/drm/contentProtection';
12
+ export * from './manifest/ext/drm/cencXmlRules';
13
+ export * from './manifest/ext/drm/ContentProtectionScheme';
14
+ export * from './error/parsingError';
15
+ export * from './duration/duration';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sCAAsC,CAAA;AACpD,cAAc,sCAAsC,CAAA;AACpD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4CAA4C,CAAA;AAC1D,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,15 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './xmlns/mpeg/dash/schema/mpd/2011';
3
+ export * from './xmlns/mpeg/cenc/2013';
4
+ export * from './xmlns/microsoft/playready';
5
+ export * from './media/ratio';
6
+ export * from './media/frameRate';
7
+ export * from './media/byteRange';
8
+ export * from './manifest/dashParser';
9
+ export * from './manifest/dashManifestXmlRules';
10
+ export * from './manifest/ext/drm/playreadyXmlRules';
11
+ export * from './manifest/ext/drm/contentProtection';
12
+ export * from './manifest/ext/drm/cencXmlRules';
13
+ export * from './manifest/ext/drm/ContentProtectionScheme';
14
+ export * from './error/parsingError';
15
+ export * from './duration/duration';
@@ -0,0 +1,65 @@
1
+ import { type XmlRules } from '@amazon/vinyl-xml';
2
+ import type { ConditionalUintType, DashManifest, PresentationType, SwitchingTypeType, VideoScanType } from '../xmlns/mpeg/dash/schema/mpd/2011';
3
+ export declare const dashNamespaceUri = "urn:mpeg:dash:schema:mpd:2011";
4
+ export declare function dashManifestXmlRules(): XmlRules<DashManifest>;
5
+ /**
6
+ * Parses a comma delimited list of profiles.
7
+ * Profile values are not whitespace trimmed.
8
+ *
9
+ * @param str
10
+ */
11
+ export declare function parseProfiles(str: string): readonly string[];
12
+ /**
13
+ * Returns the string representation of a {@link FrameRate} value.
14
+ *
15
+ * @param value
16
+ */
17
+ export declare function stringifyProfiles(value: readonly string[]): string;
18
+ /**
19
+ * @private
20
+ */
21
+ export declare function parseVideoScan(str: string): VideoScanType;
22
+ /**
23
+ * @private
24
+ */
25
+ export declare function parseSwitchingTypeType(str: string): SwitchingTypeType;
26
+ /**
27
+ * @private
28
+ */
29
+ export declare function parseSap(str: string): number;
30
+ /**
31
+ * Splits a string by whitespace.
32
+ *
33
+ * @private
34
+ */
35
+ export declare function parseStringVector(str: string): readonly string[];
36
+ /**
37
+ * Returns the string representation of a string vector value.
38
+ *
39
+ * @param value
40
+ */
41
+ export declare function stringifyStringVector(value: readonly string[]): string;
42
+ /**
43
+ * Splits a string by whitespace and parses as int.
44
+ *
45
+ * @private
46
+ */
47
+ export declare function parseIntVector(str: string): readonly number[];
48
+ /**
49
+ * Returns the string representation of an int vector value.
50
+ *
51
+ * @param value
52
+ */
53
+ export declare function stringifyIntVector(value: readonly number[]): string;
54
+ /**
55
+ * Asserts that the given string is one of the {@link PresentationType} enumerated values.
56
+ * @param str
57
+ */
58
+ export declare function parsePresentationTypeType(str: string): PresentationType;
59
+ /**
60
+ * Parses a string into true, false, or a number.
61
+ *
62
+ * @private
63
+ */
64
+ export declare function parseConditionalUint(str: string): ConditionalUintType;
65
+ //# sourceMappingURL=dashManifestXmlRules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashManifestXmlRules.d.ts","sourceRoot":"","sources":["../../../../src/manifest/dashManifestXmlRules.ts"],"names":[],"mappings":"AAaA,OAAO,EAWH,KAAK,QAAQ,EAChB,MAAM,mBAAmB,CAAA;AAO1B,OAAO,KAAK,EAGR,mBAAmB,EAEnB,YAAY,EAQZ,gBAAgB,EAchB,iBAAiB,EAEjB,aAAa,EAChB,MAAM,mCAAmC,CAAA;AAE1C,eAAO,MAAM,gBAAgB,kCAAkC,CAAA;AAE/D,wBAAgB,oBAAoB,IAAI,QAAQ,CAAC,YAAY,CAAC,CAkR7D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAElE;AAQD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAGzD;AAOD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAGrE;AAID;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEnE;AAOD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAGvE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAUrE"}
@@ -0,0 +1,360 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { assertActuateEnum, attr, attrBoolean, attrDateTime, attrFloat, attrInt, attrString, charactersString, element, elements, } from '@amazon/vinyl-xml';
6
+ import { ErrorOrigin, stringify } from '@amazon/vinyl-util';
7
+ import { isOneOf, number } from '@amazon/vinyl-validation';
8
+ import { parseDuration, stringifyDuration } from '../duration/duration';
9
+ import { parseByteRange, stringifyByteRange } from '../media/byteRange';
10
+ import { parseRatio, stringifyRatio } from '../media/ratio';
11
+ import { parseFrameRate, stringifyFrameRate } from '../media/frameRate';
12
+ export const dashNamespaceUri = 'urn:mpeg:dash:schema:mpd:2011';
13
+ export function dashManifestXmlRules() {
14
+ const attrActuateType = attr(assertActuateEnum, stringify, {
15
+ default: 'onRequest',
16
+ });
17
+ const descriptorType = {
18
+ id: attrString,
19
+ schemeIdUri: attrString({ required: true }),
20
+ value: attrString,
21
+ };
22
+ const baseURLType = {
23
+ availabilityTimeComplete: attrBoolean,
24
+ availabilityTimeOffset: attrFloat,
25
+ byteRange: attrString,
26
+ serviceLocation: attrString,
27
+ _content: charactersString,
28
+ };
29
+ const contentComponentType = {
30
+ contentType: attrString,
31
+ id: attrInt,
32
+ lang: attrString,
33
+ par: attr(parseRatio, stringifyRatio),
34
+ Accessibility: elements(descriptorType),
35
+ Rating: elements(descriptorType),
36
+ Role: elements(descriptorType),
37
+ Viewpoint: elements(descriptorType),
38
+ };
39
+ const urlType = {
40
+ range: attr(parseByteRange, stringifyByteRange),
41
+ sourceURL: attrString,
42
+ };
43
+ const uriType = { _content: charactersString };
44
+ const segmentBaseType = {
45
+ Initialization: element(urlType),
46
+ RepresentationIndex: element(urlType),
47
+ availabilityTimeComplete: attrBoolean,
48
+ availabilityTimeOffset: attrInt,
49
+ indexRange: attr(parseByteRange, stringifyByteRange),
50
+ indexRangeExact: attrBoolean({ default: false }),
51
+ presentationTimeOffset: attrFloat,
52
+ timescale: attrInt,
53
+ };
54
+ const segmentTimelineTypeSType = {
55
+ d: attrInt({ required: true }),
56
+ n: attrInt,
57
+ r: attrInt({ default: 0 }),
58
+ t: attrInt,
59
+ };
60
+ const segmentTimelineType = {
61
+ S: elements(segmentTimelineTypeSType),
62
+ };
63
+ const multipleSegmentBaseType = {
64
+ ...segmentBaseType,
65
+ SegmentTimeline: element(segmentTimelineType),
66
+ BitstreamSwitching: element(urlType),
67
+ duration: attrInt,
68
+ startNumber: attrInt,
69
+ };
70
+ const segmentURLType = {
71
+ index: attrString,
72
+ indexRange: attr(parseByteRange, stringifyByteRange),
73
+ media: attrString,
74
+ mediaRange: attr(parseByteRange, stringifyByteRange),
75
+ };
76
+ const segmentListType = {
77
+ ...multipleSegmentBaseType,
78
+ actuate: attrActuateType,
79
+ href: attrString,
80
+ SegmentURL: elements(segmentURLType),
81
+ };
82
+ const segmentTemplateType = {
83
+ ...multipleSegmentBaseType,
84
+ bitstreamSwitching: attrString,
85
+ index: attrString,
86
+ initialization: attrString,
87
+ media: attrString,
88
+ };
89
+ const subsetType = {
90
+ contains: attr(parseIntVector, stringifyIntVector, { required: true }),
91
+ id: attrString,
92
+ };
93
+ const eventType = {
94
+ duration: attrInt,
95
+ id: attrInt,
96
+ messageData: attrString,
97
+ presentationTime: attrInt({ default: 0 }),
98
+ };
99
+ const eventStreamType = {
100
+ Event: elements(eventType),
101
+ actuate: attrActuateType,
102
+ href: attrString,
103
+ messageData: attrString,
104
+ schemeIdUri: attrString({ required: true }),
105
+ timescale: attrInt,
106
+ value: attrString,
107
+ };
108
+ const switchingType = {
109
+ interval: attrInt({ required: true }),
110
+ type: attr(parseSwitchingTypeType, stringify),
111
+ };
112
+ const representationBaseType = {
113
+ FramePacking: elements(descriptorType),
114
+ AudioChannelConfiguration: elements(descriptorType),
115
+ ContentProtection: elements(descriptorType),
116
+ EssentialProperty: elements(descriptorType),
117
+ SupplementalProperty: elements(descriptorType),
118
+ InbandEventStream: elements(eventStreamType),
119
+ Switching: elements(switchingType),
120
+ audioSamplingRate: attr(parseIntVector, stringifyIntVector),
121
+ codecs: attrString,
122
+ codingDependency: attrBoolean,
123
+ frameRate: attr(parseFrameRate, stringifyFrameRate),
124
+ height: attrInt,
125
+ maximumSAPPeriod: attrInt,
126
+ maxPlayoutRate: attrInt,
127
+ mimeType: attrString,
128
+ profiles: attr(parseProfiles, stringifyProfiles),
129
+ sar: attr(parseRatio, stringifyRatio),
130
+ scanType: attr(parseVideoScan, stringify),
131
+ segmentProfiles: attrString,
132
+ startWithSAP: attr(parseSap, stringify),
133
+ width: attrInt,
134
+ };
135
+ const subRepresentationType = {
136
+ ...representationBaseType,
137
+ bandwidth: attrInt,
138
+ contentComponent: attr(parseStringVector, stringifyStringVector),
139
+ dependencyLevel: attr(parseIntVector, stringifyIntVector),
140
+ level: attrInt,
141
+ };
142
+ const representationType = {
143
+ ...representationBaseType,
144
+ bandwidth: attrInt({ required: true }),
145
+ bitrate: attrInt,
146
+ dependencyId: attr(parseStringVector, stringifyStringVector),
147
+ id: attrString({ required: true }),
148
+ mediaStreamStructureId: attr(parseStringVector, stringifyStringVector),
149
+ qualityRanking: attrInt,
150
+ BaseURL: elements(baseURLType),
151
+ SegmentBase: element(segmentBaseType),
152
+ SegmentList: element(segmentListType),
153
+ SegmentTemplate: element(segmentTemplateType),
154
+ SubRepresentation: elements(subRepresentationType),
155
+ };
156
+ const adaptationSetType = {
157
+ ...representationBaseType,
158
+ Accessibility: elements(descriptorType),
159
+ Role: elements(descriptorType),
160
+ Rating: elements(descriptorType),
161
+ Viewpoint: elements(descriptorType),
162
+ ContentComponent: elements(contentComponentType),
163
+ BaseURL: elements(baseURLType),
164
+ SegmentBase: element(segmentBaseType),
165
+ SegmentList: element(segmentListType),
166
+ SegmentTemplate: element(segmentTemplateType),
167
+ Representation: elements(representationType),
168
+ actuate: attrActuateType,
169
+ bitstreamSwitching: attrBoolean,
170
+ contentType: attrString,
171
+ group: attrInt,
172
+ href: attrString,
173
+ id: attrInt,
174
+ lang: attrString,
175
+ maxBandwidth: attrInt,
176
+ maxFrameRate: attr(parseFrameRate, stringifyFrameRate),
177
+ maxHeight: attrInt,
178
+ maxWidth: attrInt,
179
+ minBandwidth: attrInt,
180
+ minFrameRate: attr(parseFrameRate, stringifyFrameRate),
181
+ minHeight: attrInt,
182
+ minWidth: attrInt,
183
+ par: attr(parseRatio, stringifyRatio),
184
+ segmentAlignment: attr(parseConditionalUint, stringify, {
185
+ default: false,
186
+ }),
187
+ selectionPriority: attrInt({
188
+ default: 1,
189
+ }),
190
+ subsegmentAlignment: attr(parseConditionalUint, stringify, {
191
+ default: false,
192
+ }),
193
+ subsegmentStartsWithSAP: attr(parseSap, stringify, { default: 0 }),
194
+ };
195
+ const rangeType = {
196
+ duration: attr(parseDuration, stringifyDuration),
197
+ starttime: attr(parseDuration, stringifyDuration),
198
+ };
199
+ const metricsType = {
200
+ metrics: attrString({ required: true }),
201
+ Range: elements(rangeType),
202
+ Reporting: elements(descriptorType, { minOccurs: 1 }),
203
+ };
204
+ const periodType = {
205
+ BaseURL: elements(baseURLType),
206
+ SegmentBase: element(segmentBaseType),
207
+ SegmentList: element(segmentListType),
208
+ SegmentTemplate: element(segmentTemplateType),
209
+ AssetIdentifier: element(descriptorType),
210
+ EventStream: elements(eventStreamType),
211
+ AdaptationSet: elements(adaptationSetType),
212
+ Subset: elements(subsetType),
213
+ SupplementalProperty: elements(descriptorType),
214
+ actuate: attrActuateType,
215
+ bitstreamSwitching: attrBoolean({ default: false }),
216
+ duration: attr(parseDuration, stringifyDuration),
217
+ href: attrString,
218
+ id: attrString,
219
+ start: attr(parseDuration, stringifyDuration),
220
+ };
221
+ const programInformationType = {
222
+ lang: attrString,
223
+ moreInformationURL: attrString,
224
+ Copyright: attrString,
225
+ Source: attrString,
226
+ Title: attrString,
227
+ };
228
+ const mpdType = {
229
+ ProgramInformation: elements(programInformationType),
230
+ BaseURL: elements(baseURLType),
231
+ Location: elements(uriType),
232
+ Period: elements(periodType, { minOccurs: 1 }),
233
+ Metrics: elements(metricsType),
234
+ EssentialProperty: elements(descriptorType),
235
+ SupplementalProperty: elements(descriptorType),
236
+ UTCTiming: elements(descriptorType),
237
+ availabilityEndTime: attrDateTime,
238
+ availabilityStartTime: attrDateTime,
239
+ id: attrString,
240
+ maxSegmentDuration: attr(parseDuration, stringifyDuration),
241
+ maxSubsegmentDuration: attr(parseDuration, stringifyDuration),
242
+ mediaPresentationDuration: attr(parseDuration, stringifyDuration),
243
+ minBufferTime: attr(parseDuration, stringifyDuration, {
244
+ required: true,
245
+ }),
246
+ minimumUpdatePeriod: attr(parseDuration, stringifyDuration),
247
+ profiles: attr(parseProfiles, stringifyProfiles, { required: true }),
248
+ publishTime: attrDateTime,
249
+ suggestedPresentationDelay: attr(parseDuration, stringifyDuration),
250
+ timeShiftBufferDepth: attr(parseDuration, stringifyDuration),
251
+ type: attr(parsePresentationTypeType, stringify, {
252
+ default: 'static',
253
+ }),
254
+ };
255
+ return {
256
+ MPD: element(mpdType, {
257
+ required: true,
258
+ namespaceUri: dashNamespaceUri,
259
+ }),
260
+ };
261
+ }
262
+ /**
263
+ * Parses a comma delimited list of profiles.
264
+ * Profile values are not whitespace trimmed.
265
+ *
266
+ * @param str
267
+ */
268
+ export function parseProfiles(str) {
269
+ return str.split(',');
270
+ }
271
+ /**
272
+ * Returns the string representation of a {@link FrameRate} value.
273
+ *
274
+ * @param value
275
+ */
276
+ export function stringifyProfiles(value) {
277
+ return value.join(',');
278
+ }
279
+ const videoScanTypeValidator = isOneOf('progressive', 'interlaced', 'unknown');
280
+ /**
281
+ * @private
282
+ */
283
+ export function parseVideoScan(str) {
284
+ videoScanTypeValidator.assert(str, ErrorOrigin.PARSING);
285
+ return str;
286
+ }
287
+ const switchingTypeTypeValidator = isOneOf('media', 'bitstream');
288
+ /**
289
+ * @private
290
+ */
291
+ export function parseSwitchingTypeType(str) {
292
+ switchingTypeTypeValidator.assert(str, ErrorOrigin.PARSING);
293
+ return str;
294
+ }
295
+ const validateSap = number().within(0, 6);
296
+ /**
297
+ * @private
298
+ */
299
+ export function parseSap(str) {
300
+ const number = parseInt(str);
301
+ validateSap.assert(number, ErrorOrigin.PARSING);
302
+ return number;
303
+ }
304
+ /**
305
+ * Splits a string by whitespace.
306
+ *
307
+ * @private
308
+ */
309
+ export function parseStringVector(str) {
310
+ return str.split(/\s+/);
311
+ }
312
+ /**
313
+ * Returns the string representation of a string vector value.
314
+ *
315
+ * @param value
316
+ */
317
+ export function stringifyStringVector(value) {
318
+ return value.join(' ');
319
+ }
320
+ /**
321
+ * Splits a string by whitespace and parses as int.
322
+ *
323
+ * @private
324
+ */
325
+ export function parseIntVector(str) {
326
+ return str.split(/\s+/).map((subStr) => parseInt(subStr));
327
+ }
328
+ /**
329
+ * Returns the string representation of an int vector value.
330
+ *
331
+ * @param value
332
+ */
333
+ export function stringifyIntVector(value) {
334
+ return value.join(' ');
335
+ }
336
+ const presentationTypeValidator = isOneOf('static', 'dynamic');
337
+ /**
338
+ * Asserts that the given string is one of the {@link PresentationType} enumerated values.
339
+ * @param str
340
+ */
341
+ export function parsePresentationTypeType(str) {
342
+ presentationTypeValidator.assert(str, ErrorOrigin.PARSING);
343
+ return str;
344
+ }
345
+ /**
346
+ * Parses a string into true, false, or a number.
347
+ *
348
+ * @private
349
+ */
350
+ export function parseConditionalUint(str) {
351
+ const lower = str.toLowerCase();
352
+ switch (lower) {
353
+ case 'true':
354
+ return true;
355
+ case 'false':
356
+ return false;
357
+ default:
358
+ return parseInt(str);
359
+ }
360
+ }
@@ -0,0 +1,23 @@
1
+ import type { ReservedXmlRuleKeys } from '@amazon/vinyl-xml';
2
+ import { type Merged } from '@amazon/vinyl-xml';
3
+ import type { PlayreadyContentProtection } from '../xmlns/microsoft/playready';
4
+ import type { CencContentProtection } from '../xmlns/mpeg/cenc/2013';
5
+ import type { DashManifest, DescriptorType } from '../xmlns/mpeg/dash/schema/mpd/2011';
6
+ import type { DashProtections } from './ext/drm/contentProtection';
7
+ import type { OptionalDeep } from '@amazon/vinyl-util';
8
+ /**
9
+ * Creates a Dash Manifest parser with supported extensions.
10
+ *
11
+ * @module
12
+ */
13
+ export type DashDrmManifest = Merged<DashManifest & DashProtections<ContentProtection>>;
14
+ export interface ContentProtection extends DescriptorType, CencContentProtection, PlayreadyContentProtection {
15
+ }
16
+ /**
17
+ * Parses a Dash Manifest, according to the mpd:2011 schema.
18
+ * @see https://raw.githubusercontent.com/Dash-Industry-Forum/MPEG-Conformance-and-reference-source/master/conformance/MPDValidator/schemas/DASH-MPD.xsd
19
+ * @param manifest
20
+ */
21
+ export declare function parseDashManifest(manifest: string): DashDrmManifest;
22
+ export declare function stringifyDashManifest(manifest: OptionalDeep<DashDrmManifest, ReservedXmlRuleKeys>): string;
23
+ //# sourceMappingURL=dashParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashParser.d.ts","sourceRoot":"","sources":["../../../../src/manifest/dashParser.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAEH,KAAK,MAAM,EAKd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,KAAK,EACR,YAAY,EACZ,cAAc,EACjB,MAAM,mCAAmC,CAAA;AAG1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;;;GAIG;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAChC,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAC,CACpD,CAAA;AAED,MAAM,WAAW,iBACb,SAAQ,cAAc,EAAE,qBAAqB,EAAE,0BAA0B;CAAG;AAiBhF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAEnE;AAED,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,YAAY,CAAC,eAAe,EAAE,mBAAmB,CAAC,GAC7D,MAAM,CAER"}
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { mapXmlRules, mergeXmlRules, parseXml, ParseXmlHandlerImpl, stringifyXml, } from '@amazon/vinyl-xml';
6
+ import { dashManifestXmlRules } from './dashManifestXmlRules';
7
+ import { cencXmlRules } from './ext/drm/cencXmlRules';
8
+ import { createDashProtectionXmlRules } from './ext/drm/contentProtection';
9
+ import { playreadyXmlRules } from './ext/drm/playreadyXmlRules';
10
+ const dashDrmRules = mergeXmlRules(dashManifestXmlRules(), createDashProtectionXmlRules(cencXmlRules), createDashProtectionXmlRules(playreadyXmlRules));
11
+ const dashDrmRulesMapped = mapXmlRules(dashDrmRules);
12
+ /**
13
+ * A Content handler for a dash manifest.
14
+ */
15
+ function dashManifestHandler() {
16
+ return new ParseXmlHandlerImpl(dashDrmRulesMapped);
17
+ }
18
+ /**
19
+ * Parses a Dash Manifest, according to the mpd:2011 schema.
20
+ * @see https://raw.githubusercontent.com/Dash-Industry-Forum/MPEG-Conformance-and-reference-source/master/conformance/MPDValidator/schemas/DASH-MPD.xsd
21
+ * @param manifest
22
+ */
23
+ export function parseDashManifest(manifest) {
24
+ return parseXml(manifest, dashManifestHandler());
25
+ }
26
+ export function stringifyDashManifest(manifest) {
27
+ return stringifyXml(manifest, dashDrmRulesMapped);
28
+ }