|
29 | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | */ |
31 | 31 |
|
| 32 | +import {processUriTemplate as cmlProcessUriTemplate} from '@svta/common-media-library/dash/processUriTemplate.js'; |
32 | 33 | import Segment from './../vo/Segment.js'; |
33 | 34 |
|
34 | | -function zeroPadToLength(numStr, minStrLength) { |
35 | | - while (numStr.length < minStrLength) { |
36 | | - numStr = '0' + numStr; |
37 | | - } |
38 | | - return numStr; |
39 | | -} |
40 | | - |
41 | 35 | function getNumberForSegment(segment, segmentIndex) { |
42 | 36 | return segment.representation.startNumber + segmentIndex; |
43 | 37 | } |
44 | 38 |
|
45 | | -export function unescapeDollarsInTemplate(url) { |
46 | | - return url ? url.split('$$').join('$') : url; |
47 | | -} |
48 | | - |
49 | | -export function replaceIDForTemplate(url, value) { |
50 | | - if (!value || !url || url.indexOf('$RepresentationID$') === -1) { |
51 | | - return url; |
52 | | - } |
53 | | - let v = value.toString(); |
54 | | - return url.split('$RepresentationID$').join(v); |
55 | | -} |
56 | | - |
57 | | -export function replaceTokenForTemplate(url, token, value) { |
58 | | - const formatTag = '%0'; |
59 | | - |
60 | | - let startPos, |
61 | | - endPos, |
62 | | - formatTagPos, |
63 | | - specifier, |
64 | | - width, |
65 | | - paddedValue; |
66 | | - |
67 | | - const tokenLen = token.length; |
68 | | - const formatTagLen = formatTag.length; |
69 | | - |
70 | | - if (!url) { |
71 | | - return url; |
72 | | - } |
73 | | - |
74 | | - // keep looping round until all instances of <token> have been |
75 | | - // replaced. once that has happened, startPos below will be -1 |
76 | | - // and the completed url will be returned. |
77 | | - while (true) { |
78 | | - |
79 | | - // check if there is a valid $<token>...$ identifier |
80 | | - // if not, return the url as is. |
81 | | - startPos = url.indexOf('$' + token); |
82 | | - if (startPos < 0) { |
83 | | - return url; |
84 | | - } |
85 | | - |
86 | | - // the next '$' must be the end of the identifier |
87 | | - // if there isn't one, return the url as is. |
88 | | - endPos = url.indexOf('$', startPos + tokenLen); |
89 | | - if (endPos < 0) { |
90 | | - return url; |
91 | | - } |
92 | | - |
93 | | - // now see if there is an additional format tag suffixed to |
94 | | - // the identifier within the enclosing '$' characters |
95 | | - formatTagPos = url.indexOf(formatTag, startPos + tokenLen); |
96 | | - if (formatTagPos > startPos && formatTagPos < endPos) { |
97 | | - |
98 | | - specifier = url.charAt(endPos - 1); |
99 | | - width = parseInt(url.substring(formatTagPos + formatTagLen, endPos - 1), 10); |
100 | | - |
101 | | - // support the minimum specifiers required by IEEE 1003.1 |
102 | | - // (d, i , o, u, x, and X) for completeness |
103 | | - switch (specifier) { |
104 | | - // treat all int types as uint, |
105 | | - // hence deliberate fallthrough |
106 | | - case 'd': |
107 | | - case 'i': |
108 | | - case 'u': |
109 | | - paddedValue = zeroPadToLength(value.toString(), width); |
110 | | - break; |
111 | | - case 'x': |
112 | | - paddedValue = zeroPadToLength(value.toString(16), width); |
113 | | - break; |
114 | | - case 'X': |
115 | | - paddedValue = zeroPadToLength(value.toString(16), width).toUpperCase(); |
116 | | - break; |
117 | | - case 'o': |
118 | | - paddedValue = zeroPadToLength(value.toString(8), width); |
119 | | - break; |
120 | | - default: |
121 | | - return url; |
122 | | - } |
123 | | - } else { |
124 | | - paddedValue = value; |
125 | | - } |
126 | | - |
127 | | - url = url.substring(0, startPos) + paddedValue + url.substring(endPos + 1); |
128 | | - } |
129 | | -} |
130 | | - |
131 | 39 | function getSegment(representation, duration, presentationStartTime, mediaStartTime, timelineConverter, presentationEndTime, isDynamic, index) { |
132 | 40 | let seg = new Segment(); |
133 | 41 |
|
@@ -170,6 +78,14 @@ function isSegmentAvailable(timelineConverter, representation, segment, isDynami |
170 | 78 | return true; |
171 | 79 | } |
172 | 80 |
|
| 81 | +export function processUriTemplate(url, representationId, number, subNumber, bandwidth, time) { |
| 82 | + if (!url) { |
| 83 | + return url; |
| 84 | + } |
| 85 | + |
| 86 | + return cmlProcessUriTemplate(url, representationId, number, subNumber, bandwidth, time); |
| 87 | +} |
| 88 | + |
173 | 89 | export function getIndexBasedSegment(timelineConverter, isDynamic, representation, index) { |
174 | 90 | let duration, |
175 | 91 | presentationStartTime, |
@@ -222,10 +138,14 @@ export function getTimeBasedSegment(timelineConverter, isDynamic, representation |
222 | 138 | } |
223 | 139 |
|
224 | 140 | seg.replacementTime = tManifest ? tManifest : time; |
225 | | - |
226 | | - url = replaceTokenForTemplate(url, 'Number', seg.replacementNumber); |
227 | | - url = replaceTokenForTemplate(url, 'Time', seg.replacementTime); |
228 | | - seg.media = url; |
| 141 | + seg.media = processUriTemplate( |
| 142 | + url, |
| 143 | + undefined, |
| 144 | + seg.replacementNumber, |
| 145 | + undefined, |
| 146 | + undefined, |
| 147 | + seg.replacementTime, |
| 148 | + ); |
229 | 149 | seg.mediaRange = range; |
230 | 150 |
|
231 | 151 | return seg; |
|
0 commit comments