-
Notifications
You must be signed in to change notification settings - Fork 1
/
dash.spec.ts
158 lines (139 loc) · 7.51 KB
/
dash.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const chai = require('chai');
import { mpdParser } from '../src/index';
import { dash1, dash2, dash3 } from './mocks/dash.data';
chai.should();
describe('#mpdParser', function() {
const TAG_ATTR_PATTERN = /\s*(?:<\/?([^\s>]+))?\s*([^>]+)*(?:\/?>)?/;
it('test tag attr parse', () => {
let text1 = `<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" \
profiles="urn:mpeg:dash:profile:isoff-live:2011" \
type="static" mediaPresentationDuration="PT6M16S" \
minBufferTime="PT1.97S">`;
let text2 = `</Period>`;
let text3 = `<mspr:pro>`;
let text4 = `<SegmentTemplate duration="1968" initialization="$RepresentationID$/video/1/init.mp4" media="$RepresentationID$/video/1/seg-$Number$.m4f" startNumber="0" timescale="1000">`;
let text5 = `<ProgramInformation moreInformationURL="http://gpac.sourceforge.net">`;
let text6 = `http://example.com/content/sintel/subtitles/subtitles_en.vtt`;
let text7 = `<SegmentURL mediaRange="2658108-5233361" t="10060" d="10000" />`;
let text8 = `/data/tm p/123.webm`;
let m1 = text1.match(TAG_ATTR_PATTERN);
m1[1]['should']['be'].equal('MPD');
let m2 = text2.match(TAG_ATTR_PATTERN);
m2[1]['should']['be'].equal('Period');
chai.should().not.exist(m2[2]);
let m3 = text3.match(TAG_ATTR_PATTERN);
m3[1]['should']['be'].equal('mspr:pro');
chai.should().not.exist(m3[2]);
let m4 = text4.match(TAG_ATTR_PATTERN);
m4[1]['should']['be'].equal('SegmentTemplate');
m4[2]['should']['be'].equal(
'duration="1968" initialization="$RepresentationID$/video/1/init.mp4" media="$Rep' +
'resentationID$/video/1/seg-$Number$.m4f" startNumber="0" timescale="1000"'
);
let m5 = text5.match(TAG_ATTR_PATTERN);
m5[1]['should']['be'].equal('ProgramInformation');
m5[2]['should']['be'].equal(
'moreInformationURL="http://gpac.sourceforge.net"'
);
let m6 = text6.match(TAG_ATTR_PATTERN);
m6[2]['should']['be'].equal(
'http://example.com/content/sintel/subtitles/subtitles_en.vtt'
);
chai.should().not.exist(m6[1]);
let m7 = text7.match(TAG_ATTR_PATTERN);
m7[1]['should']['be'].equal('SegmentURL');
let len = m7[2].length;
m7[2].charAt(len - 1).should.be.equal('/');
let m8 = text8.match(TAG_ATTR_PATTERN);
m8[2]['should']['be'].equal('/data/tm p/123.webm');
chai.should().not.exist(m8[1]);
});
it('test partail tags merge', () => {
let text = `<AdaptationSet mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="und">
<ContentProtection cenc:default_KID="08e36702-8f33-436c-a5dd-60ffe5571e60" schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" xmlns:cenc="urn:mpeg:cenc:2013"></ContentProtection>
<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed">
<Test>
<Test1>lllll</Test1>
</Test>
</ContentProtection>
<SegmentTemplate duration="1968" initialization="$RepresentationID$/audio/en/init.mp4" media="$RepresentationID$/audio/en/seg-$Number$.m4f" startNumber="0" timescale="1000"></SegmentTemplate>
<Representation audioSamplingRate="44100" bandwidth="67095" codecs="mp4a.40.2" id="800"></Representation>
</AdaptationSet>`;
let ret = mpdParser(text, (tagName, attrs) => {
// console.log(tagName);
return attrs;
});
ret['should']['have'].property('adaptationSet');
ret['adaptationSet']['should']['have']
.property('contentProtection')
.length(2);
ret['adaptationSet']['should']['have'].property('segmentTemplate');
ret['adaptationSet']['should']['have'].property('representation');
});
it('test contains self closed tags', () => {
let text = `
<AdaptationSet mimeType="video/mp4" scanType="progressive" segmentAlignment="true" startWithSAP="1">
<ContentProtection cenc:default_KID="08e36702-8f33-436c-a5dd-60ffe5571e60" schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" xmlns:cenc="urn:mpeg:cenc:2013"></ContentProtection>
<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"></ContentProtection>
<ContentProtection schemeIdUri="urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95">
<mspr:pro>mgIAAAEAAQCQAjwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AQQBtAGYAagBDAFQATwBQAGIARQBPAGwAMwBXAEQALwA1AG0AYwBlAGMAQQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBCAEcAdwAxAGEAWQBaADEAWQBYAE0APQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APABMAEEAXwBVAFIATAA+AGgAdAB0AHAAOgAvAC8AcABsAGEAeQByAGUAYQBkAHkALgBkAGkAcgBlAGMAdAB0AGEAcABzAC4AbgBlAHQALwBwAHIALwBzAHYAYwAvAHIAaQBnAGgAdABzAG0AYQBuAGEAZwBlAHIALgBhAHMAbQB4ADwALwBMAEEAXwBVAFIATAA+ADwALwBEAEEAVABBAD4APAAvAFcAUgBNAEgARQBBAEQARQBSAD4A</mspr:pro>
</ContentProtection>
<SegmentTemplate duration="1968" initialization="$RepresentationID$/video/1/init.mp4" media="$RepresentationID$/video/1/seg-$Number$.m4f" startNumber="0" timescale="1000"></SegmentTemplate>
<Representation bandwidth="1518664" codecs="avc1.4d401f" frameRate="30000/1001" height="540" id="800" width="960">
<SegmentList timescale="90000" duration="69043">
<Initialization sourceURL="bipbop_videoinit.mp4"/>
<SegmentURL media="bipbop_video1.m4s"/>
<SegmentURL media="bipbop_video2.m4s"/>
</SegmentList>
</Representation>
<Representation bandwidth="1911775" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1000" width="1024"></Representation>
<Representation bandwidth="2295158" codecs="avc1.4d401f" frameRate="30000/1001" height="576" id="1200" width="1024"></Representation>
<Representation bandwidth="2780732" codecs="avc1.4d401f" frameRate="30000/1001" height="720" id="1500" width="1280"></Representation>
</AdaptationSet>
`;
let ret = mpdParser(text);
ret['should']['have'].property('adaptationSet');
ret['adaptationSet']['should']['have']
.property('contentProtection')
.length(3);
ret['adaptationSet']['should']['have'].property('representation').length(4);
ret['adaptationSet']['representation'][0]['should']['have'].property(
'segmentList'
);
ret['adaptationSet']['representation'][0]['segmentList']['should']['have']
.property('segmentURL')
.length(2);
ret[
'adaptationSet'
].representation[0].segmentList.segmentURL[0].media.should.be.equal(
'bipbop_video1.m4s'
);
});
it('test parse', () => {
let ret = mpdParser(dash1);
let ret2 = mpdParser(dash2);
let ret3 = mpdParser(dash3);
ret['mPD']['period']['should']['have'].property('adaptationSet').length(3);
ret2['mPD']['period']['should']['have'].property('adaptationSet').length(2);
ret2['mPD']['period']['adaptationSet'][0]['representation']['segmentList'][
'should'
]['have']
.property('segmentURL')
.length(10);
ret3['mPD']['clipList']['should']['have'].property('clip').length(4);
});
it('test postHooks param', () => {
const text = `
<clip>
<start_ts_in_ms>60</start_ts_in_ms>
</clip>
`;
let ret = mpdParser(text, (tagName, attrs) => {
if (tagName == 'startTsInMs') {
attrs.value = parseFloat(attrs.value);
}
return attrs;
});
ret['clip']['startTsInMs']['value'].should.be.equal(60);
});
});