inheritAttributes.test.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  1. import {
  2. inheritAttributes,
  3. buildBaseUrls,
  4. parseCaptionServiceMetadata,
  5. getSegmentInformation,
  6. getPeriodStart,
  7. toEventStream
  8. } from '../src/inheritAttributes';
  9. import { stringToMpdXml } from '../src/stringToMpdXml';
  10. import errors from '../src/errors';
  11. import QUnit from 'qunit';
  12. import { toPlaylists } from '../src/toPlaylists';
  13. import decodeB64ToUint8Array from '@videojs/vhs-utils/es/decode-b64-to-uint8-array';
  14. import { findChildren } from '../src/utils/xml';
  15. QUnit.module('buildBaseUrls');
  16. QUnit.test('returns reference urls when no BaseURL nodes', function(assert) {
  17. const reference = ['https://example.com/', 'https://foo.com/'];
  18. assert.deepEqual(buildBaseUrls(reference, []), reference, 'returns reference urls');
  19. });
  20. QUnit.test('single reference url with single BaseURL node', function(assert) {
  21. const reference = ['https://example.com'];
  22. const node = [{ textContent: 'bar/' }];
  23. const expected = ['https://example.com/bar/'];
  24. assert.deepEqual(buildBaseUrls(reference, node), expected, 'builds base url');
  25. });
  26. QUnit.test('multiple reference urls with single BaseURL node', function(assert) {
  27. const reference = ['https://example.com/', 'https://foo.com/'];
  28. const node = [{ textContent: 'bar/' }];
  29. const expected = ['https://example.com/bar/', 'https://foo.com/bar/'];
  30. assert.deepEqual(
  31. buildBaseUrls(reference, node), expected,
  32. 'base url for each reference url'
  33. );
  34. });
  35. QUnit.test('multiple BaseURL nodes with single reference url', function(assert) {
  36. const reference = ['https://example.com/'];
  37. const nodes = [{ textContent: 'bar/' }, { textContent: 'baz/' }];
  38. const expected = ['https://example.com/bar/', 'https://example.com/baz/'];
  39. assert.deepEqual(buildBaseUrls(reference, nodes), expected, 'base url for each node');
  40. });
  41. QUnit.test('multiple reference urls with multiple BaseURL nodes', function(assert) {
  42. const reference = ['https://example.com/', 'https://foo.com/', 'http://example.com'];
  43. const nodes =
  44. [{ textContent: 'bar/' }, { textContent: 'baz/' }, { textContent: 'buzz/' }];
  45. const expected = [
  46. 'https://example.com/bar/',
  47. 'https://example.com/baz/',
  48. 'https://example.com/buzz/',
  49. 'https://foo.com/bar/',
  50. 'https://foo.com/baz/',
  51. 'https://foo.com/buzz/',
  52. 'http://example.com/bar/',
  53. 'http://example.com/baz/',
  54. 'http://example.com/buzz/'
  55. ];
  56. assert.deepEqual(buildBaseUrls(reference, nodes), expected, 'creates all base urls');
  57. });
  58. QUnit.test('absolute BaseURL overwrites reference', function(assert) {
  59. const reference = ['https://example.com'];
  60. const node = [{ textContent: 'https://foo.com/bar/' }];
  61. const expected = ['https://foo.com/bar/'];
  62. assert.deepEqual(
  63. buildBaseUrls(reference, node), expected,
  64. 'absolute url overwrites reference'
  65. );
  66. });
  67. QUnit.module('getPeriodStart');
  68. QUnit.test('gets period start when available', function(assert) {
  69. assert.equal(
  70. getPeriodStart({
  71. attributes: { start: 11 },
  72. priorPeriodAttributes: null,
  73. mpdType: 'static'
  74. }),
  75. 11,
  76. 'returned period start value'
  77. );
  78. });
  79. QUnit.test('gets period start when prior period and duration', function(assert) {
  80. assert.equal(
  81. getPeriodStart({
  82. attributes: {},
  83. priorPeriodAttributes: { start: 11, duration: 20 },
  84. mpdType: 'static'
  85. }),
  86. 31,
  87. 'returned correct period start value'
  88. );
  89. });
  90. QUnit.test('gets period start when no prior period and static', function(assert) {
  91. assert.equal(
  92. getPeriodStart({
  93. attributes: {},
  94. priorPeriodAttributes: null,
  95. mpdType: 'static'
  96. }),
  97. 0,
  98. 'returned correct period start value'
  99. );
  100. });
  101. QUnit.test('null when static and prior period but missing attributes', function(assert) {
  102. assert.equal(
  103. getPeriodStart({
  104. attributes: {},
  105. priorPeriodAttributes: { start: 11 },
  106. mpdType: 'static'
  107. }),
  108. null,
  109. 'null when no duration in prior period'
  110. );
  111. assert.equal(
  112. getPeriodStart({
  113. attributes: {},
  114. priorPeriodAttributes: { duration: 20 },
  115. mpdType: 'static'
  116. }),
  117. null,
  118. 'null when no start in prior period'
  119. );
  120. });
  121. QUnit.test('null when dynamic, no prior period, and no start attribute', function(assert) {
  122. assert.equal(
  123. getPeriodStart({
  124. attributes: {},
  125. priorPeriodAttributes: null,
  126. mpdType: 'dyanmic'
  127. }),
  128. null,
  129. 'null when no dynamic, no start attribute, and no prior period'
  130. );
  131. });
  132. QUnit.module('getSegmentInformation');
  133. QUnit.test('undefined Segment information when no Segment nodes', function(assert) {
  134. const adaptationSet = { childNodes: [] };
  135. const expected = {};
  136. assert.deepEqual(
  137. getSegmentInformation(adaptationSet), expected,
  138. 'undefined segment info'
  139. );
  140. });
  141. QUnit.test('gets SegmentTemplate attributes', function(assert) {
  142. const adaptationSet = {
  143. childNodes: [{
  144. tagName: 'SegmentTemplate',
  145. attributes: [{ name: 'media', value: 'video.mp4' }],
  146. childNodes: []
  147. }]
  148. };
  149. const expected = {
  150. template: { media: 'video.mp4' }
  151. };
  152. assert.deepEqual(
  153. getSegmentInformation(adaptationSet), expected,
  154. 'SegmentTemplate info'
  155. );
  156. });
  157. QUnit.test('gets SegmentList attributes', function(assert) {
  158. const adaptationSet = {
  159. childNodes: [{
  160. tagName: 'SegmentList',
  161. attributes: [{ name: 'duration', value: '10' }],
  162. childNodes: []
  163. }]
  164. };
  165. const expected = {
  166. list: {
  167. duration: 10,
  168. segmentUrls: [],
  169. initialization: {}
  170. }
  171. };
  172. assert.deepEqual(
  173. getSegmentInformation(adaptationSet), expected,
  174. 'SegmentList info'
  175. );
  176. });
  177. QUnit.test('gets SegmentBase attributes', function(assert) {
  178. const adaptationSet = {
  179. childNodes: [{
  180. tagName: 'SegmentBase',
  181. attributes: [{ name: 'duration', value: '10' }],
  182. childNodes: []
  183. }]
  184. };
  185. const expected = {
  186. base: { duration: 10, initialization: {} }
  187. };
  188. assert.deepEqual(
  189. getSegmentInformation(adaptationSet), expected,
  190. 'SegmentBase info'
  191. );
  192. });
  193. QUnit.test('gets SegmentTemplate and SegmentTimeline attributes', function(assert) {
  194. const adaptationSet = {
  195. childNodes: [{
  196. tagName: 'SegmentTemplate',
  197. attributes: [{ name: 'media', value: 'video.mp4' }],
  198. childNodes: [{
  199. tagName: 'SegmentTimeline',
  200. childNodes: [{
  201. tagName: 'S',
  202. attributes: [{ name: 'd', value: '10' }]
  203. }, {
  204. tagName: 'S',
  205. attributes: [{ name: 'd', value: '5' }]
  206. }, {
  207. tagName: 'S',
  208. attributes: [{ name: 'd', value: '7' }]
  209. }]
  210. }]
  211. }]
  212. };
  213. const expected = {
  214. template: { media: 'video.mp4' },
  215. segmentTimeline: [{ d: 10 }, { d: 5 }, { d: 7 }]
  216. };
  217. assert.deepEqual(
  218. getSegmentInformation(adaptationSet), expected,
  219. 'SegmentTemplate and SegmentTimeline info'
  220. );
  221. });
  222. QUnit.module('caption service metadata');
  223. QUnit.test('parsed 608 metadata', function(assert) {
  224. const getmd = (value) => ({
  225. schemeIdUri: 'urn:scte:dash:cc:cea-608:2015',
  226. value
  227. });
  228. const assertServices = (services, expected, message) => {
  229. if (!services) {
  230. assert.notOk(expected, message);
  231. return;
  232. }
  233. services.forEach((service, i) => {
  234. assert.deepEqual(service, expected[i], message);
  235. });
  236. };
  237. assertServices(parseCaptionServiceMetadata({
  238. schemeIdUri: 'random scheme',
  239. value: 'CC1'
  240. }), undefined, 'dont parse incorrect scheme ID for 608');
  241. assertServices(parseCaptionServiceMetadata(getmd('CC1')), [{
  242. channel: 'CC1',
  243. language: 'CC1'
  244. }], 'CC1');
  245. assertServices(parseCaptionServiceMetadata(getmd('CC2')), [{
  246. channel: 'CC2',
  247. language: 'CC2'
  248. }], 'CC2');
  249. assertServices(parseCaptionServiceMetadata(getmd('English')), [{
  250. channel: undefined,
  251. language: 'English'
  252. }], 'English');
  253. assertServices(parseCaptionServiceMetadata(getmd('CC1;CC2')), [{
  254. channel: 'CC1',
  255. language: 'CC1'
  256. }, {
  257. channel: 'CC2',
  258. language: 'CC2'
  259. }], 'CC1;CC2');
  260. assertServices(parseCaptionServiceMetadata(getmd('CC1=eng;CC3=swe')), [{
  261. channel: 'CC1',
  262. language: 'eng'
  263. }, {
  264. channel: 'CC3',
  265. language: 'swe'
  266. }], 'CC1=eng;CC3=swe');
  267. assertServices(parseCaptionServiceMetadata(getmd('CC1=Hello;CC3=World')), [{
  268. channel: 'CC1',
  269. language: 'Hello'
  270. }, {
  271. channel: 'CC3',
  272. language: 'World'
  273. }], 'CC1=Hello;CC3=World');
  274. assertServices(parseCaptionServiceMetadata(getmd('eng;swe')), [{
  275. channel: undefined,
  276. language: 'eng'
  277. }, {
  278. channel: undefined,
  279. language: 'swe'
  280. }], 'eng;CC3');
  281. });
  282. QUnit.test('parsed 708 metadata', function(assert) {
  283. const getmd = (value) => ({
  284. schemeIdUri: 'urn:scte:dash:cc:cea-708:2015',
  285. value
  286. });
  287. const assertServices = (services, expected, message) => {
  288. if (!services) {
  289. assert.notOk(expected, message);
  290. return;
  291. }
  292. services.forEach((service, i) => {
  293. assert.deepEqual(service, expected[i], message);
  294. });
  295. };
  296. assertServices(parseCaptionServiceMetadata({
  297. schemeIdUri: 'random scheme',
  298. value: 'eng'
  299. }), undefined, 'dont parse incorrect scheme for 708');
  300. assertServices(parseCaptionServiceMetadata(getmd('eng')), [{
  301. 'channel': undefined,
  302. 'language': 'eng',
  303. 'aspectRatio': 1,
  304. 'easyReader': 0,
  305. '3D': 0
  306. }], 'simple eng');
  307. assertServices(parseCaptionServiceMetadata(getmd('eng;swe')), [{
  308. 'channel': undefined,
  309. 'language': 'eng',
  310. 'aspectRatio': 1,
  311. 'easyReader': 0,
  312. '3D': 0
  313. }, {
  314. 'channel': undefined,
  315. 'language': 'swe',
  316. 'aspectRatio': 1,
  317. 'easyReader': 0,
  318. '3D': 0
  319. }], 'eng;swe');
  320. assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;2=lang:swe')), [{
  321. 'channel': 'SERVICE1',
  322. 'language': 'eng',
  323. 'aspectRatio': 1,
  324. 'easyReader': 0,
  325. '3D': 0
  326. }, {
  327. 'channel': 'SERVICE2',
  328. 'language': 'swe',
  329. 'aspectRatio': 1,
  330. 'easyReader': 0,
  331. '3D': 0
  332. }], '1=lang:eng;2=lang:swe');
  333. assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;swe')), [{
  334. 'channel': 'SERVICE1',
  335. 'language': 'eng',
  336. 'aspectRatio': 1,
  337. 'easyReader': 0,
  338. '3D': 0
  339. }, {
  340. 'channel': undefined,
  341. 'language': 'swe',
  342. 'aspectRatio': 1,
  343. 'easyReader': 0,
  344. '3D': 0
  345. }], 'mixed 1=lang:eng;swe');
  346. assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;2=lang:eng,war:1,er:1')), [{
  347. 'channel': 'SERVICE1',
  348. 'language': 'eng',
  349. 'aspectRatio': 1,
  350. 'easyReader': 0,
  351. '3D': 0
  352. }, {
  353. 'channel': 'SERVICE2',
  354. 'language': 'eng',
  355. 'aspectRatio': 1,
  356. 'easyReader': 1,
  357. '3D': 0
  358. }], '1=lang:eng;2=lang:eng,war:1,er:1');
  359. assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng,war:0;2=lang:eng,3D:1,er:1')), [{
  360. 'channel': 'SERVICE1',
  361. 'language': 'eng',
  362. 'aspectRatio': 0,
  363. 'easyReader': 0,
  364. '3D': 0
  365. }, {
  366. 'channel': 'SERVICE2',
  367. 'language': 'eng',
  368. 'aspectRatio': 1,
  369. 'easyReader': 1,
  370. '3D': 1
  371. }], '1=lang:eng,war:0;2=lang:eng,3D:1,er:1');
  372. assertServices(parseCaptionServiceMetadata(getmd('eng;fre;spa;jpn;deu;swe;kor;lat;zho;heb;rus;ara;hin;por;tur')), [{
  373. 'channel': undefined,
  374. 'language': 'eng',
  375. 'aspectRatio': 1,
  376. 'easyReader': 0,
  377. '3D': 0
  378. }, {
  379. 'channel': undefined,
  380. 'language': 'fre',
  381. 'aspectRatio': 1,
  382. 'easyReader': 0,
  383. '3D': 0
  384. }, {
  385. 'channel': undefined,
  386. 'language': 'spa',
  387. 'aspectRatio': 1,
  388. 'easyReader': 0,
  389. '3D': 0
  390. }, {
  391. 'channel': undefined,
  392. 'language': 'jpn',
  393. 'aspectRatio': 1,
  394. 'easyReader': 0,
  395. '3D': 0
  396. }, {
  397. 'channel': undefined,
  398. 'language': 'deu',
  399. 'aspectRatio': 1,
  400. 'easyReader': 0,
  401. '3D': 0
  402. }, {
  403. 'channel': undefined,
  404. 'language': 'swe',
  405. 'aspectRatio': 1,
  406. 'easyReader': 0,
  407. '3D': 0
  408. }, {
  409. 'channel': undefined,
  410. 'language': 'kor',
  411. 'aspectRatio': 1,
  412. 'easyReader': 0,
  413. '3D': 0
  414. }, {
  415. 'channel': undefined,
  416. 'language': 'lat',
  417. 'aspectRatio': 1,
  418. 'easyReader': 0,
  419. '3D': 0
  420. }, {
  421. 'channel': undefined,
  422. 'language': 'zho',
  423. 'aspectRatio': 1,
  424. 'easyReader': 0,
  425. '3D': 0
  426. }, {
  427. 'channel': undefined,
  428. 'language': 'heb',
  429. 'aspectRatio': 1,
  430. 'easyReader': 0,
  431. '3D': 0
  432. }, {
  433. 'channel': undefined,
  434. 'language': 'rus',
  435. 'aspectRatio': 1,
  436. 'easyReader': 0,
  437. '3D': 0
  438. }, {
  439. 'channel': undefined,
  440. 'language': 'ara',
  441. 'aspectRatio': 1,
  442. 'easyReader': 0,
  443. '3D': 0
  444. }, {
  445. 'channel': undefined,
  446. 'language': 'hin',
  447. 'aspectRatio': 1,
  448. 'easyReader': 0,
  449. '3D': 0
  450. }, {
  451. 'channel': undefined,
  452. 'language': 'por',
  453. 'aspectRatio': 1,
  454. 'easyReader': 0,
  455. '3D': 0
  456. }, {
  457. 'channel': undefined,
  458. 'language': 'tur',
  459. 'aspectRatio': 1,
  460. 'easyReader': 0,
  461. '3D': 0
  462. }], 'make sure that parsing 15 services works');
  463. });
  464. QUnit.module('inheritAttributes');
  465. QUnit.test('needs at least one Period', function(assert) {
  466. assert.throws(
  467. () => inheritAttributes(stringToMpdXml('<MPD></MPD>')),
  468. new RegExp(errors.INVALID_NUMBER_OF_PERIOD)
  469. );
  470. });
  471. QUnit.test('end to end - basic', function(assert) {
  472. const NOW = Date.now();
  473. const actual = inheritAttributes(stringToMpdXml(`
  474. <MPD mediaPresentationDuration="PT30S" >
  475. <BaseURL>https://www.example.com/base/</BaseURL>
  476. <Period>
  477. <AdaptationSet mimeType="video/mp4" >
  478. <Role value="main"></Role>
  479. <SegmentTemplate></SegmentTemplate>
  480. <Representation
  481. bandwidth="5000000"
  482. codecs="avc1.64001e"
  483. height="404"
  484. id="test"
  485. width="720">
  486. </Representation>
  487. </AdaptationSet>
  488. <AdaptationSet mimeType="text/vtt" lang="en">
  489. <Representation bandwidth="256" id="en">
  490. <BaseURL>https://example.com/en.vtt</BaseURL>
  491. </Representation>
  492. </AdaptationSet>
  493. </Period>
  494. </MPD>
  495. `), { NOW });
  496. const expected = {
  497. eventStream: [],
  498. locations: undefined,
  499. representationInfo: [{
  500. attributes: {
  501. bandwidth: 5000000,
  502. baseUrl: 'https://www.example.com/base/',
  503. codecs: 'avc1.64001e',
  504. height: 404,
  505. id: 'test',
  506. mediaPresentationDuration: 30,
  507. mimeType: 'video/mp4',
  508. periodStart: 0,
  509. role: {
  510. value: 'main'
  511. },
  512. sourceDuration: 30,
  513. type: 'static',
  514. width: 720,
  515. NOW,
  516. clientOffset: 0
  517. },
  518. segmentInfo: {
  519. template: {}
  520. }
  521. }, {
  522. attributes: {
  523. bandwidth: 256,
  524. baseUrl: 'https://example.com/en.vtt',
  525. id: 'en',
  526. lang: 'en',
  527. mediaPresentationDuration: 30,
  528. mimeType: 'text/vtt',
  529. periodStart: 0,
  530. role: {},
  531. sourceDuration: 30,
  532. type: 'static',
  533. NOW,
  534. clientOffset: 0
  535. },
  536. segmentInfo: {}
  537. }]
  538. };
  539. assert.equal(actual.representationInfo.length, 2);
  540. assert.deepEqual(actual, expected);
  541. });
  542. QUnit.test('end to end - basic dynamic', function(assert) {
  543. const NOW = Date.now();
  544. const actual = inheritAttributes(stringToMpdXml(`
  545. <MPD type="dyanmic">
  546. <BaseURL>https://www.example.com/base/</BaseURL>
  547. <Period start="PT0S">
  548. <AdaptationSet mimeType="video/mp4">
  549. <Role value="main"></Role>
  550. <SegmentTemplate></SegmentTemplate>
  551. <Representation
  552. bandwidth="5000000"
  553. codecs="avc1.64001e"
  554. height="404"
  555. id="test"
  556. width="720">
  557. </Representation>
  558. </AdaptationSet>
  559. <AdaptationSet mimeType="text/vtt" lang="en">
  560. <Representation bandwidth="256" id="en">
  561. <BaseURL>https://example.com/en.vtt</BaseURL>
  562. </Representation>
  563. </AdaptationSet>
  564. </Period>
  565. </MPD>
  566. `), { NOW });
  567. const expected = {
  568. eventStream: [],
  569. locations: undefined,
  570. representationInfo: [{
  571. attributes: {
  572. bandwidth: 5000000,
  573. baseUrl: 'https://www.example.com/base/',
  574. codecs: 'avc1.64001e',
  575. height: 404,
  576. id: 'test',
  577. mimeType: 'video/mp4',
  578. periodStart: 0,
  579. role: {
  580. value: 'main'
  581. },
  582. sourceDuration: 0,
  583. type: 'dyanmic',
  584. width: 720,
  585. NOW,
  586. clientOffset: 0
  587. },
  588. segmentInfo: {
  589. template: {}
  590. }
  591. }, {
  592. attributes: {
  593. bandwidth: 256,
  594. baseUrl: 'https://example.com/en.vtt',
  595. id: 'en',
  596. lang: 'en',
  597. mimeType: 'text/vtt',
  598. periodStart: 0,
  599. role: {},
  600. sourceDuration: 0,
  601. type: 'dyanmic',
  602. NOW,
  603. clientOffset: 0
  604. },
  605. segmentInfo: {}
  606. }]
  607. };
  608. assert.equal(actual.representationInfo.length, 2);
  609. assert.deepEqual(actual, expected);
  610. });
  611. QUnit.test('end to end - basic multiperiod', function(assert) {
  612. const NOW = Date.now();
  613. // no start time attributes on either period, should be inferred
  614. const actual = inheritAttributes(stringToMpdXml(`
  615. <MPD mediaPresentationDuration="PT60S" >
  616. <BaseURL>https://www.example.com/base/</BaseURL>
  617. <Period duration="PT30S">
  618. <AdaptationSet mimeType="video/mp4" >
  619. <Role value="main"></Role>
  620. <SegmentTemplate></SegmentTemplate>
  621. <Representation
  622. bandwidth="5000000"
  623. codecs="avc1.64001e"
  624. height="404"
  625. id="test"
  626. width="720">
  627. </Representation>
  628. </AdaptationSet>
  629. </Period>
  630. <Period>
  631. <AdaptationSet mimeType="video/mp4" >
  632. <Role value="main"></Role>
  633. <SegmentTemplate></SegmentTemplate>
  634. <Representation
  635. bandwidth="5000000"
  636. codecs="avc1.64001e"
  637. height="404"
  638. id="test"
  639. width="720">
  640. </Representation>
  641. </AdaptationSet>
  642. </Period>
  643. </MPD>
  644. `), { NOW });
  645. const expected = {
  646. eventStream: [],
  647. locations: undefined,
  648. representationInfo: [{
  649. attributes: {
  650. bandwidth: 5000000,
  651. baseUrl: 'https://www.example.com/base/',
  652. codecs: 'avc1.64001e',
  653. height: 404,
  654. id: 'test',
  655. mediaPresentationDuration: 60,
  656. mimeType: 'video/mp4',
  657. periodDuration: 30,
  658. // inferred start
  659. periodStart: 0,
  660. role: {
  661. value: 'main'
  662. },
  663. sourceDuration: 60,
  664. type: 'static',
  665. width: 720,
  666. NOW,
  667. clientOffset: 0
  668. },
  669. segmentInfo: {
  670. template: {}
  671. }
  672. }, {
  673. attributes: {
  674. bandwidth: 5000000,
  675. baseUrl: 'https://www.example.com/base/',
  676. codecs: 'avc1.64001e',
  677. height: 404,
  678. id: 'test',
  679. mediaPresentationDuration: 60,
  680. mimeType: 'video/mp4',
  681. // inferred start
  682. periodStart: 30,
  683. role: {
  684. value: 'main'
  685. },
  686. sourceDuration: 60,
  687. type: 'static',
  688. width: 720,
  689. NOW,
  690. clientOffset: 0
  691. },
  692. segmentInfo: {
  693. template: {}
  694. }
  695. }]
  696. };
  697. assert.equal(actual.representationInfo.length, 2);
  698. assert.deepEqual(actual, expected);
  699. });
  700. QUnit.test('end to end - inherits BaseURL from all levels', function(assert) {
  701. const NOW = Date.now();
  702. const actual = inheritAttributes(stringToMpdXml(`
  703. <MPD mediaPresentationDuration="PT30S" >
  704. <BaseURL>https://www.example.com/base/</BaseURL>
  705. <Period>
  706. <BaseURL>foo/</BaseURL>
  707. <AdaptationSet mimeType="video/mp4" >
  708. <BaseURL>bar/</BaseURL>
  709. <Role value="main"></Role>
  710. <SegmentTemplate></SegmentTemplate>
  711. <Representation
  712. bandwidth="5000000"
  713. codecs="avc1.64001e"
  714. height="404"
  715. id="test"
  716. width="720">
  717. <BaseURL>buzz/</BaseURL>
  718. </Representation>
  719. </AdaptationSet>
  720. <AdaptationSet mimeType="text/vtt" lang="en">
  721. <Representation bandwidth="256" id="en">
  722. <BaseURL>https://example.com/en.vtt</BaseURL>
  723. </Representation>
  724. </AdaptationSet>
  725. </Period>
  726. </MPD>
  727. `), { NOW });
  728. const expected = {
  729. eventStream: [],
  730. locations: undefined,
  731. representationInfo: [{
  732. attributes: {
  733. bandwidth: 5000000,
  734. baseUrl: 'https://www.example.com/base/foo/bar/buzz/',
  735. clientOffset: 0,
  736. codecs: 'avc1.64001e',
  737. height: 404,
  738. id: 'test',
  739. mediaPresentationDuration: 30,
  740. mimeType: 'video/mp4',
  741. periodStart: 0,
  742. role: {
  743. value: 'main'
  744. },
  745. sourceDuration: 30,
  746. type: 'static',
  747. width: 720,
  748. NOW
  749. },
  750. segmentInfo: {
  751. template: {}
  752. }
  753. }, {
  754. attributes: {
  755. bandwidth: 256,
  756. baseUrl: 'https://example.com/en.vtt',
  757. id: 'en',
  758. lang: 'en',
  759. mediaPresentationDuration: 30,
  760. mimeType: 'text/vtt',
  761. periodStart: 0,
  762. role: {},
  763. sourceDuration: 30,
  764. type: 'static',
  765. NOW,
  766. clientOffset: 0
  767. },
  768. segmentInfo: { }
  769. }]
  770. };
  771. assert.equal(actual.representationInfo.length, 2);
  772. assert.deepEqual(actual, expected);
  773. });
  774. QUnit.test('end to end - alternate BaseURLs', function(assert) {
  775. const NOW = Date.now();
  776. const actual = inheritAttributes(stringToMpdXml(`
  777. <MPD mediaPresentationDuration= "PT30S" >
  778. <BaseURL>https://www.example.com/base/</BaseURL>
  779. <BaseURL>https://www.test.com/base/</BaseURL>
  780. <Period>
  781. <AdaptationSet mimeType= "video/mp4" >
  782. <BaseURL>segments/</BaseURL>
  783. <BaseURL>media/</BaseURL>
  784. <Role value= "main" ></Role>
  785. <SegmentTemplate></SegmentTemplate>
  786. <Representation
  787. bandwidth= "5000000"
  788. codecs= "avc1.64001e"
  789. height= "404"
  790. id= "test"
  791. width= "720" >
  792. </Representation>
  793. </AdaptationSet>
  794. <AdaptationSet mimeType= "text/vtt" lang= "en" >
  795. <Representation bandwidth= "256" id= "en" >
  796. <BaseURL>https://example.com/en.vtt</BaseURL>
  797. </Representation>
  798. </AdaptationSet>
  799. </Period>
  800. </MPD>
  801. `), { NOW });
  802. const expected = {
  803. eventStream: [],
  804. locations: undefined,
  805. representationInfo: [{
  806. attributes: {
  807. bandwidth: 5000000,
  808. baseUrl: 'https://www.example.com/base/segments/',
  809. codecs: 'avc1.64001e',
  810. height: 404,
  811. id: 'test',
  812. mediaPresentationDuration: 30,
  813. mimeType: 'video/mp4',
  814. periodStart: 0,
  815. role: {
  816. value: 'main'
  817. },
  818. sourceDuration: 30,
  819. type: 'static',
  820. width: 720,
  821. NOW,
  822. clientOffset: 0
  823. },
  824. segmentInfo: {
  825. template: {}
  826. }
  827. }, {
  828. attributes: {
  829. bandwidth: 5000000,
  830. baseUrl: 'https://www.example.com/base/media/',
  831. codecs: 'avc1.64001e',
  832. height: 404,
  833. id: 'test',
  834. mediaPresentationDuration: 30,
  835. mimeType: 'video/mp4',
  836. periodStart: 0,
  837. role: {
  838. value: 'main'
  839. },
  840. sourceDuration: 30,
  841. type: 'static',
  842. width: 720,
  843. NOW,
  844. clientOffset: 0
  845. },
  846. segmentInfo: {
  847. template: {}
  848. }
  849. }, {
  850. attributes: {
  851. bandwidth: 5000000,
  852. baseUrl: 'https://www.test.com/base/segments/',
  853. codecs: 'avc1.64001e',
  854. height: 404,
  855. id: 'test',
  856. mediaPresentationDuration: 30,
  857. mimeType: 'video/mp4',
  858. periodStart: 0,
  859. role: {
  860. value: 'main'
  861. },
  862. sourceDuration: 30,
  863. type: 'static',
  864. width: 720,
  865. NOW,
  866. clientOffset: 0
  867. },
  868. segmentInfo: {
  869. template: {}
  870. }
  871. }, {
  872. attributes: {
  873. bandwidth: 5000000,
  874. baseUrl: 'https://www.test.com/base/media/',
  875. codecs: 'avc1.64001e',
  876. height: 404,
  877. id: 'test',
  878. mediaPresentationDuration: 30,
  879. mimeType: 'video/mp4',
  880. periodStart: 0,
  881. role: {
  882. value: 'main'
  883. },
  884. sourceDuration: 30,
  885. type: 'static',
  886. width: 720,
  887. NOW,
  888. clientOffset: 0
  889. },
  890. segmentInfo: {
  891. template: {}
  892. }
  893. }, {
  894. attributes: {
  895. bandwidth: 256,
  896. baseUrl: 'https://example.com/en.vtt',
  897. id: 'en',
  898. lang: 'en',
  899. mediaPresentationDuration: 30,
  900. mimeType: 'text/vtt',
  901. periodStart: 0,
  902. role: {},
  903. sourceDuration: 30,
  904. type: 'static',
  905. NOW,
  906. clientOffset: 0
  907. },
  908. segmentInfo: {}
  909. }, {
  910. attributes: {
  911. bandwidth: 256,
  912. baseUrl: 'https://example.com/en.vtt',
  913. id: 'en',
  914. lang: 'en',
  915. mediaPresentationDuration: 30,
  916. mimeType: 'text/vtt',
  917. periodStart: 0,
  918. role: {},
  919. sourceDuration: 30,
  920. type: 'static',
  921. NOW,
  922. clientOffset: 0
  923. },
  924. segmentInfo: {}
  925. }]
  926. };
  927. assert.equal(actual.representationInfo.length, 6);
  928. assert.deepEqual(actual, expected);
  929. });
  930. QUnit.test(
  931. ' End to End test for checking support of segments in representation',
  932. function(assert) {
  933. const NOW = Date.now();
  934. const actual = inheritAttributes(stringToMpdXml(`
  935. <MPD mediaPresentationDuration= "PT30S" >
  936. <BaseURL>https://www.example.com/base/</BaseURL>
  937. <Period>
  938. <AdaptationSet mimeType= "video/mp4" >
  939. <Role value= "main" ></Role>
  940. <SegmentBase indexRangeExact= "true" indexRange= "820-2087" >
  941. <Initialization range= "0-987" />
  942. </SegmentBase>
  943. <Representation
  944. mimeType= "video/mp6"
  945. bandwidth= "5000000"
  946. codecs= "avc1.64001e"
  947. height= "404"
  948. id= "test"
  949. width= "720" >
  950. <SegmentBase>
  951. <Initialization range= "0-567" />
  952. </SegmentBase>
  953. </Representation>
  954. <Representation
  955. height= "545" >
  956. </Representation>
  957. </AdaptationSet>
  958. <AdaptationSet mimeType= "text/vtt" lang= "en" >
  959. <Representation bandwidth= "256" id= "en" >
  960. <BaseURL>https://example.com/en.vtt</BaseURL>
  961. </Representation>
  962. </AdaptationSet>
  963. </Period>
  964. </MPD>
  965. `), { NOW });
  966. const expected = {
  967. eventStream: [],
  968. locations: undefined,
  969. representationInfo: [{
  970. attributes: {
  971. bandwidth: 5000000,
  972. baseUrl: 'https://www.example.com/base/',
  973. codecs: 'avc1.64001e',
  974. height: 404,
  975. id: 'test',
  976. mediaPresentationDuration: 30,
  977. mimeType: 'video/mp6',
  978. periodStart: 0,
  979. role: {
  980. value: 'main'
  981. },
  982. sourceDuration: 30,
  983. type: 'static',
  984. width: 720,
  985. NOW,
  986. clientOffset: 0
  987. },
  988. segmentInfo: {
  989. base: {
  990. indexRange: '820-2087',
  991. indexRangeExact: 'true',
  992. initialization: {
  993. range: '0-567'
  994. }
  995. }
  996. }
  997. }, {
  998. attributes: {
  999. baseUrl: 'https://www.example.com/base/',
  1000. mediaPresentationDuration: 30,
  1001. mimeType: 'video/mp4',
  1002. periodStart: 0,
  1003. height: 545,
  1004. role: {
  1005. value: 'main'
  1006. },
  1007. sourceDuration: 30,
  1008. type: 'static',
  1009. NOW,
  1010. clientOffset: 0
  1011. },
  1012. segmentInfo: {
  1013. base: {
  1014. indexRange: '820-2087',
  1015. indexRangeExact: 'true',
  1016. initialization: {
  1017. range: '0-987'
  1018. }
  1019. }
  1020. }
  1021. }, {
  1022. attributes: {
  1023. bandwidth: 256,
  1024. baseUrl: 'https://example.com/en.vtt',
  1025. id: 'en',
  1026. lang: 'en',
  1027. mediaPresentationDuration: 30,
  1028. mimeType: 'text/vtt',
  1029. periodStart: 0,
  1030. role: {},
  1031. sourceDuration: 30,
  1032. type: 'static',
  1033. NOW,
  1034. clientOffset: 0
  1035. },
  1036. segmentInfo: {}
  1037. }]
  1038. };
  1039. assert.equal(actual.representationInfo.length, 3);
  1040. assert.deepEqual(actual, expected);
  1041. }
  1042. );
  1043. QUnit.test(
  1044. ' End to End test for checking support of segments in period ',
  1045. function(assert) {
  1046. const NOW = Date.now();
  1047. const actual = inheritAttributes(stringToMpdXml(`
  1048. <MPD mediaPresentationDuration= "PT30S" >
  1049. <BaseURL>https://www.example.com/base/</BaseURL>
  1050. <Period duration= "PT0H4M40.414S" >
  1051. <SegmentBase indexRangeExact= "false" indexRange= "9999" >
  1052. <Initialization range= "0-1111" />
  1053. </SegmentBase>
  1054. <AdaptationSet mimeType= "video/mp4" >
  1055. <Role value= "main" ></Role>
  1056. <Representation
  1057. mimeType= "video/mp6"
  1058. bandwidth= "5000000"
  1059. codecs= "avc1.64001e"
  1060. height= "404"
  1061. id= "test"
  1062. width= "720" >
  1063. </Representation>
  1064. <Representation
  1065. height= "545" >
  1066. </Representation>
  1067. </AdaptationSet>
  1068. <AdaptationSet mimeType= "text/vtt" lang= "en" >
  1069. <Representation bandwidth= "256" id= "en" >
  1070. <BaseURL>https://example.com/en.vtt</BaseURL>
  1071. </Representation>
  1072. </AdaptationSet>
  1073. </Period>
  1074. </MPD>
  1075. `), { NOW });
  1076. const expected = {
  1077. eventStream: [],
  1078. locations: undefined,
  1079. representationInfo: [{
  1080. attributes: {
  1081. bandwidth: 5000000,
  1082. baseUrl: 'https://www.example.com/base/',
  1083. codecs: 'avc1.64001e',
  1084. height: 404,
  1085. id: 'test',
  1086. mediaPresentationDuration: 30,
  1087. mimeType: 'video/mp6',
  1088. periodDuration: 280.414,
  1089. periodStart: 0,
  1090. role: {
  1091. value: 'main'
  1092. },
  1093. sourceDuration: 30,
  1094. type: 'static',
  1095. width: 720,
  1096. NOW,
  1097. clientOffset: 0
  1098. },
  1099. segmentInfo: {
  1100. base: {
  1101. indexRange: '9999',
  1102. indexRangeExact: 'false',
  1103. initialization: {
  1104. range: '0-1111'
  1105. }
  1106. }
  1107. }
  1108. }, {
  1109. attributes: {
  1110. baseUrl: 'https://www.example.com/base/',
  1111. mediaPresentationDuration: 30,
  1112. mimeType: 'video/mp4',
  1113. periodDuration: 280.414,
  1114. periodStart: 0,
  1115. height: 545,
  1116. role: {
  1117. value: 'main'
  1118. },
  1119. sourceDuration: 30,
  1120. type: 'static',
  1121. NOW,
  1122. clientOffset: 0
  1123. },
  1124. segmentInfo: {
  1125. base: {
  1126. indexRange: '9999',
  1127. indexRangeExact: 'false',
  1128. initialization: {
  1129. range: '0-1111'
  1130. }
  1131. }
  1132. }
  1133. }, {
  1134. attributes: {
  1135. bandwidth: 256,
  1136. baseUrl: 'https://example.com/en.vtt',
  1137. id: 'en',
  1138. lang: 'en',
  1139. mediaPresentationDuration: 30,
  1140. mimeType: 'text/vtt',
  1141. periodDuration: 280.414,
  1142. periodStart: 0,
  1143. role: {},
  1144. sourceDuration: 30,
  1145. type: 'static',
  1146. NOW,
  1147. clientOffset: 0
  1148. },
  1149. segmentInfo: {
  1150. base: {
  1151. indexRange: '9999',
  1152. indexRangeExact: 'false',
  1153. initialization: {
  1154. range: '0-1111'
  1155. }
  1156. }
  1157. }
  1158. }]
  1159. };
  1160. assert.equal(actual.representationInfo.length, 3);
  1161. assert.deepEqual(actual, expected);
  1162. }
  1163. );
  1164. QUnit.test(
  1165. ' End to End test for checking support of Segments in Adaptation set',
  1166. function(assert) {
  1167. const NOW = Date.now();
  1168. const actual = inheritAttributes(stringToMpdXml(`
  1169. <MPD mediaPresentationDuration= "PT30S" >
  1170. <BaseURL>https://www.example.com/base/</BaseURL>
  1171. <Period>
  1172. <AdaptationSet mimeType= "video/mp4" >
  1173. <Role value= "main" ></Role>
  1174. <SegmentBase indexRange= "1212" indexRangeExact= "true" >
  1175. <Initialization range= "0-8888" />
  1176. </SegmentBase>
  1177. <Representation
  1178. mimeType= "video/mp6"
  1179. bandwidth= "5000000"
  1180. codecs= "avc1.64001e"
  1181. height= "404"
  1182. id= "test"
  1183. width= "720" >
  1184. </Representation>
  1185. <Representation
  1186. height= "545" >
  1187. </Representation>
  1188. </AdaptationSet>
  1189. <AdaptationSet mimeType= "text/vtt" lang= "en" >
  1190. <Representation bandwidth= "256" id= "en" >
  1191. <BaseURL>https://example.com/en.vtt</BaseURL>
  1192. </Representation>
  1193. </AdaptationSet>
  1194. </Period>
  1195. </MPD>
  1196. `), { NOW });
  1197. const expected = {
  1198. eventStream: [],
  1199. locations: undefined,
  1200. representationInfo: [{
  1201. attributes: {
  1202. bandwidth: 5000000,
  1203. baseUrl: 'https://www.example.com/base/',
  1204. codecs: 'avc1.64001e',
  1205. height: 404,
  1206. id: 'test',
  1207. mediaPresentationDuration: 30,
  1208. mimeType: 'video/mp6',
  1209. periodStart: 0,
  1210. role: {
  1211. value: 'main'
  1212. },
  1213. sourceDuration: 30,
  1214. type: 'static',
  1215. width: 720,
  1216. NOW,
  1217. clientOffset: 0
  1218. },
  1219. segmentInfo: {
  1220. base: {
  1221. indexRange: '1212',
  1222. indexRangeExact: 'true',
  1223. initialization: {
  1224. range: '0-8888'
  1225. }
  1226. }
  1227. }
  1228. }, {
  1229. attributes: {
  1230. baseUrl: 'https://www.example.com/base/',
  1231. mediaPresentationDuration: 30,
  1232. mimeType: 'video/mp4',
  1233. periodStart: 0,
  1234. height: 545,
  1235. role: {
  1236. value: 'main'
  1237. },
  1238. sourceDuration: 30,
  1239. type: 'static',
  1240. NOW,
  1241. clientOffset: 0
  1242. },
  1243. segmentInfo: {
  1244. base: {
  1245. indexRange: '1212',
  1246. indexRangeExact: 'true',
  1247. initialization: {
  1248. range: '0-8888'
  1249. }
  1250. }
  1251. }
  1252. }, {
  1253. attributes: {
  1254. bandwidth: 256,
  1255. baseUrl: 'https://example.com/en.vtt',
  1256. id: 'en',
  1257. lang: 'en',
  1258. mediaPresentationDuration: 30,
  1259. mimeType: 'text/vtt',
  1260. periodStart: 0,
  1261. role: {},
  1262. sourceDuration: 30,
  1263. type: 'static',
  1264. NOW,
  1265. clientOffset: 0
  1266. },
  1267. segmentInfo: {}
  1268. }]
  1269. };
  1270. assert.equal(actual.representationInfo.length, 3);
  1271. assert.deepEqual(actual, expected);
  1272. }
  1273. );
  1274. // Although according to the Spec, at most one set of Segment information should be
  1275. // present at each level, this test would still handle the case and prevent errors if
  1276. // multiple set of segment information are present at any particular level.
  1277. QUnit.test(
  1278. 'Test for checking use of only one set of Segment Information when multiple are present',
  1279. function(assert) {
  1280. const NOW = Date.now();
  1281. const actual = toPlaylists(inheritAttributes(stringToMpdXml(`
  1282. <MPD mediaPresentationDuration= "PT30S" >
  1283. <BaseURL>https://www.example.com/base</BaseURL>
  1284. <Period>
  1285. <AdaptationSet
  1286. mimeType= "video/mp4"
  1287. segmentAlignment= "true"
  1288. startWithSAP= "1"
  1289. lang= "es" >
  1290. <Role value= "main" ></Role>
  1291. <SegmentTemplate
  1292. duration= "95232"
  1293. initialization= "$RepresentationID$/es/init.m4f"
  1294. media= "$RepresentationID$/es/$Number$.m4f"
  1295. startNumber= "0"
  1296. timescale= "48000" >
  1297. </SegmentTemplate>
  1298. <SegmentList timescale= "1000" duration= "1000" >
  1299. <RepresentationIndex sourceURL= "representation-index-low" />
  1300. <SegmentURL media= "low/segment-1.ts" />
  1301. <SegmentURL media= "low/segment-2.ts" />
  1302. <SegmentURL media= "low/segment-3.ts" />
  1303. <SegmentURL media= "low/segment-4.ts" />
  1304. <SegmentURL media= "low/segment-5.ts" />
  1305. <SegmentURL media= "low/segment-6.ts" />
  1306. </SegmentList>
  1307. <Representation
  1308. mimeType= "video/mp6"
  1309. bandwidth= "5000000"
  1310. codecs= "avc1.64001e"
  1311. height= "404"
  1312. id= "125000"
  1313. width= "720" >
  1314. </Representation>
  1315. <Representation
  1316. height= "545"
  1317. id="125000" >
  1318. </Representation>
  1319. </AdaptationSet>
  1320. </Period>
  1321. </MPD>
  1322. `), { NOW }).representationInfo);
  1323. const expected = [{
  1324. attributes: {
  1325. NOW,
  1326. bandwidth: 5000000,
  1327. baseUrl: 'https://www.example.com/base',
  1328. duration: 1.984,
  1329. codecs: 'avc1.64001e',
  1330. height: 404,
  1331. id: '125000',
  1332. lang: 'es',
  1333. mediaPresentationDuration: 30,
  1334. mimeType: 'video/mp6',
  1335. periodStart: 0,
  1336. startNumber: 0,
  1337. timescale: 48000,
  1338. role: {
  1339. value: 'main'
  1340. },
  1341. clientOffset: 0,
  1342. initialization: {
  1343. sourceURL: '$RepresentationID$/es/init.m4f'
  1344. },
  1345. media: '$RepresentationID$/es/$Number$.m4f',
  1346. segmentAlignment: 'true',
  1347. sourceDuration: 30,
  1348. type: 'static',
  1349. width: 720,
  1350. startWithSAP: '1'
  1351. },
  1352. segments: [{
  1353. duration: 1.984,
  1354. map: {
  1355. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1356. uri: '125000/es/init.m4f'
  1357. },
  1358. resolvedUri: 'https://www.example.com/125000/es/0.m4f',
  1359. timeline: 0,
  1360. uri: '125000/es/0.m4f',
  1361. number: 0,
  1362. presentationTime: 0
  1363. }, {
  1364. duration: 1.984,
  1365. map: {
  1366. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1367. uri: '125000/es/init.m4f'
  1368. },
  1369. resolvedUri: 'https://www.example.com/125000/es/1.m4f',
  1370. timeline: 0,
  1371. uri: '125000/es/1.m4f',
  1372. number: 1,
  1373. presentationTime: 1.984
  1374. }, {
  1375. duration: 1.984,
  1376. map: {
  1377. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1378. uri: '125000/es/init.m4f'
  1379. },
  1380. resolvedUri: 'https://www.example.com/125000/es/2.m4f',
  1381. timeline: 0,
  1382. uri: '125000/es/2.m4f',
  1383. number: 2,
  1384. presentationTime: 3.968
  1385. }, {
  1386. duration: 1.984,
  1387. map: {
  1388. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1389. uri: '125000/es/init.m4f'
  1390. },
  1391. resolvedUri: 'https://www.example.com/125000/es/3.m4f',
  1392. timeline: 0,
  1393. uri: '125000/es/3.m4f',
  1394. number: 3,
  1395. presentationTime: 5.952
  1396. }, {
  1397. duration: 1.984,
  1398. map: {
  1399. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1400. uri: '125000/es/init.m4f'
  1401. },
  1402. resolvedUri: 'https://www.example.com/125000/es/4.m4f',
  1403. timeline: 0,
  1404. uri: '125000/es/4.m4f',
  1405. number: 4,
  1406. presentationTime: 7.936
  1407. }, {
  1408. duration: 1.984,
  1409. map: {
  1410. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1411. uri: '125000/es/init.m4f'
  1412. },
  1413. resolvedUri: 'https://www.example.com/125000/es/5.m4f',
  1414. timeline: 0,
  1415. uri: '125000/es/5.m4f',
  1416. number: 5,
  1417. presentationTime: 9.92
  1418. }, {
  1419. duration: 1.984,
  1420. map: {
  1421. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1422. uri: '125000/es/init.m4f'
  1423. },
  1424. resolvedUri: 'https://www.example.com/125000/es/6.m4f',
  1425. timeline: 0,
  1426. uri: '125000/es/6.m4f',
  1427. number: 6,
  1428. presentationTime: 11.904
  1429. }, {
  1430. duration: 1.984,
  1431. map: {
  1432. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1433. uri: '125000/es/init.m4f'
  1434. },
  1435. resolvedUri: 'https://www.example.com/125000/es/7.m4f',
  1436. timeline: 0,
  1437. uri: '125000/es/7.m4f',
  1438. number: 7,
  1439. presentationTime: 13.888
  1440. }, {
  1441. duration: 1.984,
  1442. map: {
  1443. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1444. uri: '125000/es/init.m4f'
  1445. },
  1446. resolvedUri: 'https://www.example.com/125000/es/8.m4f',
  1447. timeline: 0,
  1448. uri: '125000/es/8.m4f',
  1449. number: 8,
  1450. presentationTime: 15.872
  1451. }, {
  1452. duration: 1.984,
  1453. map: {
  1454. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1455. uri: '125000/es/init.m4f'
  1456. },
  1457. resolvedUri: 'https://www.example.com/125000/es/9.m4f',
  1458. timeline: 0,
  1459. uri: '125000/es/9.m4f',
  1460. number: 9,
  1461. presentationTime: 17.856
  1462. }, {
  1463. duration: 1.984,
  1464. map: {
  1465. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1466. uri: '125000/es/init.m4f'
  1467. },
  1468. resolvedUri: 'https://www.example.com/125000/es/10.m4f',
  1469. timeline: 0,
  1470. uri: '125000/es/10.m4f',
  1471. number: 10,
  1472. presentationTime: 19.84
  1473. }, {
  1474. duration: 1.984,
  1475. map: {
  1476. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1477. uri: '125000/es/init.m4f'
  1478. },
  1479. resolvedUri: 'https://www.example.com/125000/es/11.m4f',
  1480. timeline: 0,
  1481. uri: '125000/es/11.m4f',
  1482. number: 11,
  1483. presentationTime: 21.824
  1484. }, {
  1485. duration: 1.984,
  1486. map: {
  1487. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1488. uri: '125000/es/init.m4f'
  1489. },
  1490. resolvedUri: 'https://www.example.com/125000/es/12.m4f',
  1491. timeline: 0,
  1492. uri: '125000/es/12.m4f',
  1493. number: 12,
  1494. presentationTime: 23.808
  1495. }, {
  1496. duration: 1.984,
  1497. map: {
  1498. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1499. uri: '125000/es/init.m4f'
  1500. },
  1501. resolvedUri: 'https://www.example.com/125000/es/13.m4f',
  1502. timeline: 0,
  1503. uri: '125000/es/13.m4f',
  1504. number: 13,
  1505. presentationTime: 25.792
  1506. }, {
  1507. duration: 1.984,
  1508. map: {
  1509. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1510. uri: '125000/es/init.m4f'
  1511. },
  1512. resolvedUri: 'https://www.example.com/125000/es/14.m4f',
  1513. timeline: 0,
  1514. uri: '125000/es/14.m4f',
  1515. number: 14,
  1516. presentationTime: 27.776
  1517. }, {
  1518. duration: 0.240000000000002,
  1519. map: {
  1520. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1521. uri: '125000/es/init.m4f'
  1522. },
  1523. resolvedUri: 'https://www.example.com/125000/es/15.m4f',
  1524. timeline: 0,
  1525. uri: '125000/es/15.m4f',
  1526. number: 15,
  1527. presentationTime: 29.76
  1528. }]
  1529. }, {
  1530. attributes: {
  1531. NOW,
  1532. baseUrl: 'https://www.example.com/base',
  1533. duration: 1.984,
  1534. lang: 'es',
  1535. height: 545,
  1536. id: '125000',
  1537. mediaPresentationDuration: 30,
  1538. mimeType: 'video/mp4',
  1539. periodStart: 0,
  1540. role: {
  1541. value: 'main'
  1542. },
  1543. segmentAlignment: 'true',
  1544. sourceDuration: 30,
  1545. type: 'static',
  1546. startWithSAP: '1',
  1547. clientOffset: 0,
  1548. initialization: {
  1549. sourceURL: '$RepresentationID$/es/init.m4f'
  1550. },
  1551. media: '$RepresentationID$/es/$Number$.m4f',
  1552. startNumber: 0,
  1553. timescale: 48000
  1554. },
  1555. segments: [{
  1556. duration: 1.984,
  1557. map: {
  1558. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1559. uri: '125000/es/init.m4f'
  1560. },
  1561. resolvedUri: 'https://www.example.com/125000/es/0.m4f',
  1562. timeline: 0,
  1563. uri: '125000/es/0.m4f',
  1564. number: 0,
  1565. presentationTime: 0
  1566. }, {
  1567. duration: 1.984,
  1568. map: {
  1569. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1570. uri: '125000/es/init.m4f'
  1571. },
  1572. resolvedUri: 'https://www.example.com/125000/es/1.m4f',
  1573. timeline: 0,
  1574. uri: '125000/es/1.m4f',
  1575. number: 1,
  1576. presentationTime: 1.984
  1577. }, {
  1578. duration: 1.984,
  1579. map: {
  1580. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1581. uri: '125000/es/init.m4f'
  1582. },
  1583. resolvedUri: 'https://www.example.com/125000/es/2.m4f',
  1584. timeline: 0,
  1585. uri: '125000/es/2.m4f',
  1586. number: 2,
  1587. presentationTime: 3.968
  1588. }, {
  1589. duration: 1.984,
  1590. map: {
  1591. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1592. uri: '125000/es/init.m4f'
  1593. },
  1594. resolvedUri: 'https://www.example.com/125000/es/3.m4f',
  1595. timeline: 0,
  1596. uri: '125000/es/3.m4f',
  1597. number: 3,
  1598. presentationTime: 5.952
  1599. }, {
  1600. duration: 1.984,
  1601. map: {
  1602. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1603. uri: '125000/es/init.m4f'
  1604. },
  1605. resolvedUri: 'https://www.example.com/125000/es/4.m4f',
  1606. timeline: 0,
  1607. uri: '125000/es/4.m4f',
  1608. number: 4,
  1609. presentationTime: 7.936
  1610. }, {
  1611. duration: 1.984,
  1612. map: {
  1613. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1614. uri: '125000/es/init.m4f'
  1615. },
  1616. resolvedUri: 'https://www.example.com/125000/es/5.m4f',
  1617. timeline: 0,
  1618. uri: '125000/es/5.m4f',
  1619. number: 5,
  1620. presentationTime: 9.92
  1621. }, {
  1622. duration: 1.984,
  1623. map: {
  1624. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1625. uri: '125000/es/init.m4f'
  1626. },
  1627. resolvedUri: 'https://www.example.com/125000/es/6.m4f',
  1628. timeline: 0,
  1629. uri: '125000/es/6.m4f',
  1630. number: 6,
  1631. presentationTime: 11.904
  1632. }, {
  1633. duration: 1.984,
  1634. map: {
  1635. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1636. uri: '125000/es/init.m4f'
  1637. },
  1638. resolvedUri: 'https://www.example.com/125000/es/7.m4f',
  1639. timeline: 0,
  1640. uri: '125000/es/7.m4f',
  1641. number: 7,
  1642. presentationTime: 13.888
  1643. }, {
  1644. duration: 1.984,
  1645. map: {
  1646. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1647. uri: '125000/es/init.m4f'
  1648. },
  1649. resolvedUri: 'https://www.example.com/125000/es/8.m4f',
  1650. timeline: 0,
  1651. uri: '125000/es/8.m4f',
  1652. number: 8,
  1653. presentationTime: 15.872
  1654. }, {
  1655. duration: 1.984,
  1656. map: {
  1657. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1658. uri: '125000/es/init.m4f'
  1659. },
  1660. resolvedUri: 'https://www.example.com/125000/es/9.m4f',
  1661. timeline: 0,
  1662. uri: '125000/es/9.m4f',
  1663. number: 9,
  1664. presentationTime: 17.856
  1665. }, {
  1666. duration: 1.984,
  1667. map: {
  1668. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1669. uri: '125000/es/init.m4f'
  1670. },
  1671. resolvedUri: 'https://www.example.com/125000/es/10.m4f',
  1672. timeline: 0,
  1673. uri: '125000/es/10.m4f',
  1674. number: 10,
  1675. presentationTime: 19.84
  1676. }, {
  1677. duration: 1.984,
  1678. map: {
  1679. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1680. uri: '125000/es/init.m4f'
  1681. },
  1682. resolvedUri: 'https://www.example.com/125000/es/11.m4f',
  1683. timeline: 0,
  1684. uri: '125000/es/11.m4f',
  1685. number: 11,
  1686. presentationTime: 21.824
  1687. }, {
  1688. duration: 1.984,
  1689. map: {
  1690. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1691. uri: '125000/es/init.m4f'
  1692. },
  1693. resolvedUri: 'https://www.example.com/125000/es/12.m4f',
  1694. timeline: 0,
  1695. uri: '125000/es/12.m4f',
  1696. number: 12,
  1697. presentationTime: 23.808
  1698. }, {
  1699. duration: 1.984,
  1700. map: {
  1701. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1702. uri: '125000/es/init.m4f'
  1703. },
  1704. resolvedUri: 'https://www.example.com/125000/es/13.m4f',
  1705. timeline: 0,
  1706. uri: '125000/es/13.m4f',
  1707. number: 13,
  1708. presentationTime: 25.792
  1709. }, {
  1710. duration: 1.984,
  1711. map: {
  1712. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1713. uri: '125000/es/init.m4f'
  1714. },
  1715. resolvedUri: 'https://www.example.com/125000/es/14.m4f',
  1716. timeline: 0,
  1717. uri: '125000/es/14.m4f',
  1718. number: 14,
  1719. presentationTime: 27.776
  1720. }, {
  1721. duration: 0.240000000000002,
  1722. map: {
  1723. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1724. uri: '125000/es/init.m4f'
  1725. },
  1726. resolvedUri: 'https://www.example.com/125000/es/15.m4f',
  1727. timeline: 0,
  1728. uri: '125000/es/15.m4f',
  1729. number: 15,
  1730. presentationTime: 29.76
  1731. }]
  1732. }];
  1733. assert.equal(actual.length, 2);
  1734. assert.deepEqual(actual, expected);
  1735. }
  1736. );
  1737. // Although the Spec states that if SegmentTemplate or SegmentList is present on one
  1738. // level of the hierarchy the other one shall not be present on any lower level, this
  1739. // test would still handle the case if both are present in the hierarchy and would
  1740. // prevent throwing errors.
  1741. QUnit.test('Test to check use of either Segment Template or Segment List when both are' +
  1742. ' present in the hierarchy', function(assert) {
  1743. const NOW = Date.now();
  1744. const actual = toPlaylists(inheritAttributes(stringToMpdXml(`
  1745. <MPD mediaPresentationDuration= "PT30S" >
  1746. <BaseURL>https://www.example.com/base</BaseURL>
  1747. <Period>
  1748. <AdaptationSet
  1749. mimeType= "video/mp4"
  1750. segmentAlignment= "true"
  1751. startWithSAP= "1"
  1752. lang= "es" >
  1753. <Role value= "main" ></Role>
  1754. <SegmentTemplate
  1755. duration= "95232"
  1756. initialization= "$RepresentationID$/es/init.m4f"
  1757. media= "$RepresentationID$/es/$Number$.m4f"
  1758. startNumber= "0"
  1759. timescale= "48000" >
  1760. </SegmentTemplate>
  1761. <Representation
  1762. mimeType= "video/mp6"
  1763. bandwidth= "5000000"
  1764. codecs= "avc1.64001e"
  1765. height= "404"
  1766. id= "125000"
  1767. width= "720" >
  1768. <SegmentList timescale= "1000" duration= "1000" >
  1769. <RepresentationIndex sourceURL= "representation-index-low" />
  1770. <SegmentURL media= "low/segment-1.ts" />
  1771. <SegmentURL media= "low/segment-2.ts" />
  1772. <SegmentURL media= "low/segment-3.ts" />
  1773. <SegmentURL media= "low/segment-4.ts" />
  1774. <SegmentURL media= "low/segment-5.ts" />
  1775. <SegmentURL media= "low/segment-6.ts" />
  1776. </SegmentList>
  1777. </Representation>
  1778. </AdaptationSet>
  1779. </Period>
  1780. </MPD>
  1781. `), { NOW }).representationInfo);
  1782. const expected = [{
  1783. attributes: {
  1784. NOW,
  1785. clientOffset: 0,
  1786. initialization: {
  1787. sourceURL: '$RepresentationID$/es/init.m4f'
  1788. },
  1789. media: '$RepresentationID$/es/$Number$.m4f',
  1790. bandwidth: 5000000,
  1791. baseUrl: 'https://www.example.com/base',
  1792. duration: 1.984,
  1793. codecs: 'avc1.64001e',
  1794. height: 404,
  1795. id: '125000',
  1796. lang: 'es',
  1797. mediaPresentationDuration: 30,
  1798. mimeType: 'video/mp6',
  1799. periodStart: 0,
  1800. role: {
  1801. value: 'main'
  1802. },
  1803. segmentAlignment: 'true',
  1804. sourceDuration: 30,
  1805. type: 'static',
  1806. width: 720,
  1807. startWithSAP: '1',
  1808. startNumber: 0,
  1809. timescale: 48000
  1810. },
  1811. segments: [{
  1812. duration: 1.984,
  1813. map: {
  1814. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1815. uri: '125000/es/init.m4f'
  1816. },
  1817. resolvedUri: 'https://www.example.com/125000/es/0.m4f',
  1818. timeline: 0,
  1819. uri: '125000/es/0.m4f',
  1820. number: 0,
  1821. presentationTime: 0
  1822. }, {
  1823. duration: 1.984,
  1824. map: {
  1825. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1826. uri: '125000/es/init.m4f'
  1827. },
  1828. resolvedUri: 'https://www.example.com/125000/es/1.m4f',
  1829. timeline: 0,
  1830. uri: '125000/es/1.m4f',
  1831. number: 1,
  1832. presentationTime: 1.984
  1833. }, {
  1834. duration: 1.984,
  1835. map: {
  1836. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1837. uri: '125000/es/init.m4f'
  1838. },
  1839. resolvedUri: 'https://www.example.com/125000/es/2.m4f',
  1840. timeline: 0,
  1841. uri: '125000/es/2.m4f',
  1842. number: 2,
  1843. presentationTime: 3.968
  1844. }, {
  1845. duration: 1.984,
  1846. map: {
  1847. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1848. uri: '125000/es/init.m4f'
  1849. },
  1850. resolvedUri: 'https://www.example.com/125000/es/3.m4f',
  1851. timeline: 0,
  1852. uri: '125000/es/3.m4f',
  1853. number: 3,
  1854. presentationTime: 5.952
  1855. }, {
  1856. duration: 1.984,
  1857. map: {
  1858. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1859. uri: '125000/es/init.m4f'
  1860. },
  1861. resolvedUri: 'https://www.example.com/125000/es/4.m4f',
  1862. timeline: 0,
  1863. uri: '125000/es/4.m4f',
  1864. number: 4,
  1865. presentationTime: 7.936
  1866. }, {
  1867. duration: 1.984,
  1868. map: {
  1869. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1870. uri: '125000/es/init.m4f'
  1871. },
  1872. resolvedUri: 'https://www.example.com/125000/es/5.m4f',
  1873. timeline: 0,
  1874. uri: '125000/es/5.m4f',
  1875. number: 5,
  1876. presentationTime: 9.92
  1877. }, {
  1878. duration: 1.984,
  1879. map: {
  1880. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1881. uri: '125000/es/init.m4f'
  1882. },
  1883. resolvedUri: 'https://www.example.com/125000/es/6.m4f',
  1884. timeline: 0,
  1885. uri: '125000/es/6.m4f',
  1886. number: 6,
  1887. presentationTime: 11.904
  1888. }, {
  1889. duration: 1.984,
  1890. map: {
  1891. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1892. uri: '125000/es/init.m4f'
  1893. },
  1894. resolvedUri: 'https://www.example.com/125000/es/7.m4f',
  1895. timeline: 0,
  1896. uri: '125000/es/7.m4f',
  1897. number: 7,
  1898. presentationTime: 13.888
  1899. }, {
  1900. duration: 1.984,
  1901. map: {
  1902. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1903. uri: '125000/es/init.m4f'
  1904. },
  1905. resolvedUri: 'https://www.example.com/125000/es/8.m4f',
  1906. timeline: 0,
  1907. uri: '125000/es/8.m4f',
  1908. number: 8,
  1909. presentationTime: 15.872
  1910. }, {
  1911. duration: 1.984,
  1912. map: {
  1913. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1914. uri: '125000/es/init.m4f'
  1915. },
  1916. resolvedUri: 'https://www.example.com/125000/es/9.m4f',
  1917. timeline: 0,
  1918. uri: '125000/es/9.m4f',
  1919. number: 9,
  1920. presentationTime: 17.856
  1921. }, {
  1922. duration: 1.984,
  1923. map: {
  1924. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1925. uri: '125000/es/init.m4f'
  1926. },
  1927. resolvedUri: 'https://www.example.com/125000/es/10.m4f',
  1928. timeline: 0,
  1929. uri: '125000/es/10.m4f',
  1930. number: 10,
  1931. presentationTime: 19.84
  1932. }, {
  1933. duration: 1.984,
  1934. map: {
  1935. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1936. uri: '125000/es/init.m4f'
  1937. },
  1938. resolvedUri: 'https://www.example.com/125000/es/11.m4f',
  1939. timeline: 0,
  1940. uri: '125000/es/11.m4f',
  1941. number: 11,
  1942. presentationTime: 21.824
  1943. }, {
  1944. duration: 1.984,
  1945. map: {
  1946. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1947. uri: '125000/es/init.m4f'
  1948. },
  1949. resolvedUri: 'https://www.example.com/125000/es/12.m4f',
  1950. timeline: 0,
  1951. uri: '125000/es/12.m4f',
  1952. number: 12,
  1953. presentationTime: 23.808
  1954. }, {
  1955. duration: 1.984,
  1956. map: {
  1957. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1958. uri: '125000/es/init.m4f'
  1959. },
  1960. resolvedUri: 'https://www.example.com/125000/es/13.m4f',
  1961. timeline: 0,
  1962. uri: '125000/es/13.m4f',
  1963. number: 13,
  1964. presentationTime: 25.792
  1965. }, {
  1966. duration: 1.984,
  1967. map: {
  1968. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1969. uri: '125000/es/init.m4f'
  1970. },
  1971. resolvedUri: 'https://www.example.com/125000/es/14.m4f',
  1972. timeline: 0,
  1973. uri: '125000/es/14.m4f',
  1974. number: 14,
  1975. presentationTime: 27.776
  1976. }, {
  1977. duration: 0.240000000000002,
  1978. map: {
  1979. resolvedUri: 'https://www.example.com/125000/es/init.m4f',
  1980. uri: '125000/es/init.m4f'
  1981. },
  1982. resolvedUri: 'https://www.example.com/125000/es/15.m4f',
  1983. timeline: 0,
  1984. uri: '125000/es/15.m4f',
  1985. number: 15,
  1986. presentationTime: 29.76
  1987. }]
  1988. }];
  1989. assert.equal(actual.length, 1);
  1990. assert.deepEqual(actual, expected);
  1991. });
  1992. QUnit.test('keySystem info for representation - lowercase UUIDs', function(assert) {
  1993. const NOW = Date.now();
  1994. const widevinePsshB64 = 'AAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARIQCHJ4bvnnRl+jok5bDvj6RQ==';
  1995. const playreadyPsshB64 = 'AAAB5HBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAcTEAQAAAQABALoBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBiAG4AaAB5AEMATwBmADUAWAAwAGEAagBvAGsANQBiAEQAdgBqADYAUgBRAD0APQA8AC8ASwBJAEQAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==';
  1996. const widevinePsshBytes = decodeB64ToUint8Array(widevinePsshB64);
  1997. const playreadyPsshBytes = decodeB64ToUint8Array(playreadyPsshB64);
  1998. // Content protection info from dash.js demo
  1999. const actual = inheritAttributes(stringToMpdXml(`
  2000. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2001. <BaseURL>https://www.example.com/base/</BaseURL>
  2002. <Period>
  2003. <AdaptationSet mimeType="video/mp4" >
  2004. <ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="0872786e-f9e7-465f-a3a2-4e5b0ef8fa45" />
  2005. <ContentProtection value="MSPR 2.0" schemeIdUri="urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95">
  2006. <cenc:pssh>AAAB5HBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAcTEAQAAAQABALoBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBiAG4AaAB5AEMATwBmADUAWAAwAGEAagBvAGsANQBiAEQAdgBqADYAUgBRAD0APQA8AC8ASwBJAEQAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==</cenc:pssh>
  2007. <pro xmlns="urn:microsoft:playready">xAEAAAEAAQC6ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AYgBuAGgAeQBDAE8AZgA1AFgAMABhAGoAbwBrADUAYgBEAHYAagA2AFIAUQA9AD0APAAvAEsASQBEAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA=</pro>
  2008. </ContentProtection>
  2009. <ContentProtection value="Widevine" schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed">
  2010. <cenc:pssh>AAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARIQCHJ4bvnnRl+jok5bDvj6RQ==</cenc:pssh>
  2011. </ContentProtection>
  2012. <Role value="main"></Role>
  2013. <SegmentTemplate></SegmentTemplate>
  2014. <Representation
  2015. bandwidth="5000000"
  2016. codecs="avc1.64001e"
  2017. height="404"
  2018. id="test"
  2019. width="720">
  2020. </Representation>
  2021. </AdaptationSet>
  2022. </Period>
  2023. </MPD>
  2024. `), { NOW });
  2025. // inconsistent quoting because of quote-props
  2026. const expected = {
  2027. eventStream: [],
  2028. locations: undefined,
  2029. representationInfo: [{
  2030. attributes: {
  2031. 'bandwidth': 5000000,
  2032. 'baseUrl': 'https://www.example.com/base/',
  2033. 'codecs': 'avc1.64001e',
  2034. 'contentProtection': {
  2035. 'com.microsoft.playready': {
  2036. attributes: {
  2037. schemeIdUri: 'urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95',
  2038. value: 'MSPR 2.0'
  2039. },
  2040. pssh: playreadyPsshBytes
  2041. },
  2042. 'com.widevine.alpha': {
  2043. attributes: {
  2044. schemeIdUri: 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed',
  2045. value: 'Widevine'
  2046. },
  2047. pssh: widevinePsshBytes
  2048. }
  2049. },
  2050. 'height': 404,
  2051. 'id': 'test',
  2052. 'mediaPresentationDuration': 30,
  2053. 'mimeType': 'video/mp4',
  2054. 'periodStart': 0,
  2055. 'role': {
  2056. value: 'main'
  2057. },
  2058. 'sourceDuration': 30,
  2059. 'type': 'static',
  2060. 'width': 720,
  2061. NOW,
  2062. 'clientOffset': 0,
  2063. 'xmlns:cenc': 'urn:mpeg:cenc:2013'
  2064. },
  2065. segmentInfo: {
  2066. template: {}
  2067. }
  2068. }]
  2069. };
  2070. assert.equal(actual.representationInfo.length, 1);
  2071. assert.deepEqual(actual, expected);
  2072. });
  2073. QUnit.test('keySystem info for representation - uppercase UUIDs', function(assert) {
  2074. const NOW = Date.now();
  2075. const widevinePsshB64 = 'AAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARIQCHJ4bvnnRl+jok5bDvj6RQ==';
  2076. const playreadyPsshB64 = 'AAAB5HBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAcTEAQAAAQABALoBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBiAG4AaAB5AEMATwBmADUAWAAwAGEAagBvAGsANQBiAEQAdgBqADYAUgBRAD0APQA8AC8ASwBJAEQAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==';
  2077. const widevinePsshBytes = decodeB64ToUint8Array(widevinePsshB64);
  2078. const playreadyPsshBytes = decodeB64ToUint8Array(playreadyPsshB64);
  2079. // Content protection info from dash.js demo
  2080. const actual = inheritAttributes(stringToMpdXml(`
  2081. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2082. <BaseURL>https://www.example.com/base/</BaseURL>
  2083. <Period>
  2084. <AdaptationSet mimeType="video/mp4" >
  2085. <ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="0872786E-F9E7-465F-A3A2-4E5B0EF8FA45" />
  2086. <ContentProtection value="MSPR 2.0" schemeIdUri="urn:uuid:9A04F079-9840-4286-AB92-E65BE0885F95">
  2087. <cenc:pssh>AAAB5HBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAcTEAQAAAQABALoBPABXAFIATQBIAEUAQQBEAEUAUgAgAHgAbQBsAG4AcwA9ACIAaAB0AHQAcAA6AC8ALwBzAGMAaABlAG0AYQBzAC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAEQAUgBNAC8AMgAwADAANwAvADAAMwAvAFAAbABhAHkAUgBlAGEAZAB5AEgAZQBhAGQAZQByACIAIAB2AGUAcgBzAGkAbwBuAD0AIgA0AC4AMAAuADAALgAwACIAPgA8AEQAQQBUAEEAPgA8AFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBFAFkATABFAE4APgAxADYAPAAvAEsARQBZAEwARQBOAD4APABBAEwARwBJAEQAPgBBAEUAUwBDAFQAUgA8AC8AQQBMAEcASQBEAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwASwBJAEQAPgBiAG4AaAB5AEMATwBmADUAWAAwAGEAagBvAGsANQBiAEQAdgBqADYAUgBRAD0APQA8AC8ASwBJAEQAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==</cenc:pssh>
  2088. <pro xmlns="urn:microsoft:playready">xAEAAAEAAQC6ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AYgBuAGgAeQBDAE8AZgA1AFgAMABhAGoAbwBrADUAYgBEAHYAagA2AFIAUQA9AD0APAAvAEsASQBEAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA=</pro>
  2089. </ContentProtection>
  2090. <ContentProtection value="Widevine" schemeIdUri="urn:uuid:EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED">
  2091. <cenc:pssh>AAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARIQCHJ4bvnnRl+jok5bDvj6RQ==</cenc:pssh>
  2092. </ContentProtection>
  2093. <Role value="main"></Role>
  2094. <SegmentTemplate></SegmentTemplate>
  2095. <Representation
  2096. bandwidth="5000000"
  2097. codecs="avc1.64001e"
  2098. height="404"
  2099. id="test"
  2100. width="720">
  2101. </Representation>
  2102. </AdaptationSet>
  2103. </Period>
  2104. </MPD>
  2105. `), { NOW });
  2106. // inconsistent quoting because of quote-props
  2107. const expected = {
  2108. eventStream: [],
  2109. locations: undefined,
  2110. representationInfo: [{
  2111. attributes: {
  2112. 'bandwidth': 5000000,
  2113. 'baseUrl': 'https://www.example.com/base/',
  2114. 'codecs': 'avc1.64001e',
  2115. 'contentProtection': {
  2116. 'com.microsoft.playready': {
  2117. attributes: {
  2118. schemeIdUri: 'urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95',
  2119. value: 'MSPR 2.0'
  2120. },
  2121. pssh: playreadyPsshBytes
  2122. },
  2123. 'com.widevine.alpha': {
  2124. attributes: {
  2125. schemeIdUri: 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed',
  2126. value: 'Widevine'
  2127. },
  2128. pssh: widevinePsshBytes
  2129. }
  2130. },
  2131. 'height': 404,
  2132. 'id': 'test',
  2133. 'mediaPresentationDuration': 30,
  2134. 'mimeType': 'video/mp4',
  2135. 'periodStart': 0,
  2136. 'role': {
  2137. value: 'main'
  2138. },
  2139. 'sourceDuration': 30,
  2140. 'type': 'static',
  2141. 'width': 720,
  2142. NOW,
  2143. 'clientOffset': 0,
  2144. 'xmlns:cenc': 'urn:mpeg:cenc:2013'
  2145. },
  2146. segmentInfo: {
  2147. template: {}
  2148. }
  2149. }]
  2150. };
  2151. assert.equal(actual.representationInfo.length, 1);
  2152. assert.deepEqual(actual, expected);
  2153. });
  2154. QUnit.test('gets EventStream data from toEventStream', function(assert) {
  2155. const mpd = stringToMpdXml(`
  2156. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2157. <Period id="dai_pod-0001065804-ad-1" start="PT17738H17M14.156S" duration="PT9.977S">
  2158. <BaseURL>https://www.example.com/base/</BaseURL>
  2159. <SegmentTemplate media="$RepresentationID$/$Number$.mp4" initialization="$RepresentationID$/init.mp4"/>
  2160. <EventStream schemeIdUri="urn:google:dai:2018" timescale="1000" contentEncoding="foo" presentationTimeOffset="1">
  2161. <Event presentationTime="100" duration="0" id="0" messageData="foo"/>
  2162. <Event presentationTime="900" duration="0" id="5" messageData="bar"/>
  2163. <Event presentationTime="1900" duration="0" id="6" messageData="foo_bar"/>
  2164. </EventStream>
  2165. </Period>
  2166. </MPD>`);
  2167. const expected = [
  2168. {
  2169. end: 2.1,
  2170. id: '0',
  2171. messageData: 'foo',
  2172. schemeIdUri: 'urn:google:dai:2018',
  2173. start: 2.1,
  2174. value: undefined,
  2175. contentEncoding: 'foo',
  2176. presentationTimeOffset: 1
  2177. },
  2178. {
  2179. end: 2.9,
  2180. id: '5',
  2181. messageData: 'bar',
  2182. schemeIdUri: 'urn:google:dai:2018',
  2183. start: 2.9,
  2184. value: undefined,
  2185. contentEncoding: 'foo',
  2186. presentationTimeOffset: 1
  2187. },
  2188. {
  2189. end: 3.9,
  2190. id: '6',
  2191. messageData: 'foo_bar',
  2192. schemeIdUri: 'urn:google:dai:2018',
  2193. start: 3.9,
  2194. value: undefined,
  2195. contentEncoding: 'foo',
  2196. presentationTimeOffset: 1
  2197. }
  2198. ];
  2199. const firstPeriod = { node: findChildren(mpd, 'Period')[0], attributes: { start: 2 } };
  2200. const eventStreams = toEventStream(firstPeriod);
  2201. assert.deepEqual(eventStreams, expected, 'toEventStream returns the expected object');
  2202. });
  2203. QUnit.test('can get EventStream data from toEventStream with no schemeIdUri', function(assert) {
  2204. const mpd = stringToMpdXml(`
  2205. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2206. <Period id="dai_pod-0001065804-ad-1" start="PT17738H17M14.156S" duration="PT9.977S">
  2207. <BaseURL>https://www.example.com/base/</BaseURL>
  2208. <SegmentTemplate media="$RepresentationID$/$Number$.mp4" initialization="$RepresentationID$/init.mp4"/>
  2209. <EventStream timescale="1000">
  2210. <Event presentationTime="100" duration="0" id="0" messageData="foo"/>
  2211. <Event presentationTime="900" duration="0" id="5" messageData="bar"/>
  2212. <Event presentationTime="1900" duration="0" id="6" messageData="foo_bar"/>
  2213. </EventStream>
  2214. </Period>
  2215. </MPD>`);
  2216. const expected = [
  2217. {
  2218. end: 2.1,
  2219. id: '0',
  2220. messageData: 'foo',
  2221. schemeIdUri: undefined,
  2222. start: 2.1,
  2223. value: undefined,
  2224. contentEncoding: undefined,
  2225. presentationTimeOffset: 0
  2226. },
  2227. {
  2228. end: 2.9,
  2229. id: '5',
  2230. messageData: 'bar',
  2231. schemeIdUri: undefined,
  2232. start: 2.9,
  2233. value: undefined,
  2234. contentEncoding: undefined,
  2235. presentationTimeOffset: 0
  2236. },
  2237. {
  2238. end: 3.9,
  2239. id: '6',
  2240. messageData: 'foo_bar',
  2241. schemeIdUri: undefined,
  2242. start: 3.9,
  2243. value: undefined,
  2244. contentEncoding: undefined,
  2245. presentationTimeOffset: 0
  2246. }
  2247. ];
  2248. const firstPeriod = { node: findChildren(mpd, 'Period')[0], attributes: { start: 2} };
  2249. const eventStreams = toEventStream(firstPeriod);
  2250. assert.deepEqual(eventStreams, expected, 'toEventStream returns the expected object');
  2251. });
  2252. QUnit.test('gets eventStream from inheritAttributes', function(assert) {
  2253. const mpd = stringToMpdXml(`
  2254. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2255. <Period id="dai_pod-0001065804-ad-1" start="PT0H0M14.9S" duration="PT9.977S">
  2256. <BaseURL>https://www.example.com/base/</BaseURL>
  2257. <SegmentTemplate media="$RepresentationID$/$Number$.mp4" initialization="$RepresentationID$/init.mp4"/>
  2258. <EventStream schemeIdUri="urn:google:dai:2018" timescale="1000" value="foo">
  2259. <Event presentationTime="100" duration="0" id="0" messageData="foo"/>
  2260. <Event presentationTime="1100" duration="0" id="5" messageData="bar"/>
  2261. <Event presentationTime="2100" duration="0" id="6" messageData="foo_bar"/>
  2262. </EventStream>
  2263. </Period>
  2264. </MPD>`);
  2265. const expected = {
  2266. eventStream: [
  2267. {
  2268. end: 15,
  2269. id: '0',
  2270. messageData: 'foo',
  2271. schemeIdUri: 'urn:google:dai:2018',
  2272. start: 15,
  2273. value: 'foo',
  2274. contentEncoding: undefined,
  2275. presentationTimeOffset: 0
  2276. },
  2277. {
  2278. end: 16,
  2279. id: '5',
  2280. messageData: 'bar',
  2281. schemeIdUri: 'urn:google:dai:2018',
  2282. start: 16,
  2283. value: 'foo',
  2284. contentEncoding: undefined,
  2285. presentationTimeOffset: 0
  2286. },
  2287. {
  2288. end: 17,
  2289. id: '6',
  2290. messageData: 'foo_bar',
  2291. schemeIdUri: 'urn:google:dai:2018',
  2292. start: 17,
  2293. value: 'foo',
  2294. contentEncoding: undefined,
  2295. presentationTimeOffset: 0
  2296. }
  2297. ],
  2298. locations: undefined,
  2299. representationInfo: []
  2300. };
  2301. const eventStreams = inheritAttributes(mpd);
  2302. assert.deepEqual(eventStreams, expected, 'inheritAttributes returns the expected object');
  2303. });
  2304. QUnit.test('can get EventStream data from toEventStream with data in Event tags', function(assert) {
  2305. const mpd = stringToMpdXml(`
  2306. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2307. <Period id="dai_pod-0001065804-ad-1" start="PT17738H17M14.156S" duration="PT9.977S">
  2308. <BaseURL>https://www.example.com/base/</BaseURL>
  2309. <SegmentTemplate media="$RepresentationID$/$Number$.mp4" initialization="$RepresentationID$/init.mp4"/>
  2310. <EventStream timescale="1000">
  2311. <Event presentationTime="100" duration="0" id="0">foo</Event>
  2312. <Event presentationTime="900" duration="0" id="5">bar</Event>
  2313. <Event presentationTime="1900" duration="0" id="6">foo_bar</Event>
  2314. </EventStream>
  2315. </Period>
  2316. </MPD>`);
  2317. const expected = [
  2318. {
  2319. end: 2.1,
  2320. id: '0',
  2321. messageData: 'foo',
  2322. schemeIdUri: undefined,
  2323. start: 2.1,
  2324. value: undefined,
  2325. contentEncoding: undefined,
  2326. presentationTimeOffset: 0
  2327. },
  2328. {
  2329. end: 2.9,
  2330. id: '5',
  2331. messageData: 'bar',
  2332. schemeIdUri: undefined,
  2333. start: 2.9,
  2334. value: undefined,
  2335. contentEncoding: undefined,
  2336. presentationTimeOffset: 0
  2337. },
  2338. {
  2339. end: 3.9,
  2340. id: '6',
  2341. messageData: 'foo_bar',
  2342. schemeIdUri: undefined,
  2343. start: 3.9,
  2344. value: undefined,
  2345. contentEncoding: undefined,
  2346. presentationTimeOffset: 0
  2347. }
  2348. ];
  2349. const firstPeriod = { node: findChildren(mpd, 'Period')[0], attributes: { start: 2} };
  2350. const eventStreams = toEventStream(firstPeriod);
  2351. assert.deepEqual(eventStreams, expected, 'toEventStream returns the expected object');
  2352. });
  2353. QUnit.test('gets eventStream from inheritAttributes with data in Event tags', function(assert) {
  2354. const mpd = stringToMpdXml(`
  2355. <MPD mediaPresentationDuration="PT30S" xmlns:cenc="urn:mpeg:cenc:2013">
  2356. <Period id="dai_pod-0001065804-ad-1" start="PT0H0M14.9S" duration="PT9.977S">
  2357. <BaseURL>https://www.example.com/base/</BaseURL>
  2358. <SegmentTemplate media="$RepresentationID$/$Number$.mp4" initialization="$RepresentationID$/init.mp4"/>
  2359. <EventStream schemeIdUri="urn:google:dai:2018" timescale="1000" value="foo">
  2360. <Event presentationTime="100" duration="0" id="0">foo</Event>
  2361. <Event presentationTime="1100" duration="0" id="5">bar</Event>
  2362. <Event presentationTime="2100" duration="0" id="6">foo_bar</Event>
  2363. </EventStream>
  2364. </Period>
  2365. </MPD>`);
  2366. const expected = {
  2367. eventStream: [
  2368. {
  2369. end: 15,
  2370. id: '0',
  2371. messageData: 'foo',
  2372. schemeIdUri: 'urn:google:dai:2018',
  2373. start: 15,
  2374. value: 'foo',
  2375. contentEncoding: undefined,
  2376. presentationTimeOffset: 0
  2377. },
  2378. {
  2379. end: 16,
  2380. id: '5',
  2381. messageData: 'bar',
  2382. schemeIdUri: 'urn:google:dai:2018',
  2383. start: 16,
  2384. value: 'foo',
  2385. contentEncoding: undefined,
  2386. presentationTimeOffset: 0
  2387. },
  2388. {
  2389. end: 17,
  2390. id: '6',
  2391. messageData: 'foo_bar',
  2392. schemeIdUri: 'urn:google:dai:2018',
  2393. start: 17,
  2394. value: 'foo',
  2395. contentEncoding: undefined,
  2396. presentationTimeOffset: 0
  2397. }
  2398. ],
  2399. locations: undefined,
  2400. representationInfo: []
  2401. };
  2402. const eventStreams = inheritAttributes(mpd);
  2403. assert.deepEqual(eventStreams, expected, 'inheritAttributes returns the expected object');
  2404. });