/*! @name mpd-parser @version 0.14.0 @license Apache-2.0 */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],e):e((t=t||self).mpdParser={},t.window,t.window)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t){return!!t&&"object"==typeof t},i=function t(){for(var e=arguments.length,r=new Array(e),i=0;i=0&&(m.minimumUpdatePeriod=1e3*c),e&&(m.locations=e),"dynamic"===o&&(m.suggestedPresentationDelay=s),l.length&&(m.mediaGroups.AUDIO.audio=function(t,e){var r;void 0===e&&(e={});var n=t.reduce(function(t,n){var i=n.attributes.role&&n.attributes.role.value||"",a=n.attributes.lang||"",u="main";if(a){var o=i?" ("+i+")":"";u=""+n.attributes.lang+o}return t[u]&&t[u].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth?t:(t[u]={language:a,autoselect:!0,default:"main"===i,playlists:x([L(n)],e),uri:""},void 0===r&&"main"===i&&((r=n).default=!0),t)},{});r||(n[Object.keys(n)[0]].default=!0);return n}(l,r)),f.length&&(m.mediaGroups.SUBTITLES.subs=function(t,e){return void 0===e&&(e={}),t.reduce(function(t,r){var n=r.attributes.lang||"text";return t[n]?t:(t[n]={language:n,default:!1,autoselect:!1,playlists:x([w(r)],e),uri:""},t)},{})}(f,r)),m},R=function(t,e,r){var n=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,u=t.timescale,o=void 0===u?1:u,s=t.start,c=void 0===s?0:s,d=t.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*o-e)/r)},T=function(t,e){for(var r=t.type,n=void 0===r?"static":r,i=t.minimumUpdatePeriod,a=void 0===i?0:i,u=t.media,o=void 0===u?"":u,s=t.sourceDuration,c=t.timescale,d=void 0===c?1:c,l=t.startNumber,f=void 0===l?1:l,m=t.periodIndex,p=[],v=-1,h=0;hv&&(v=y);var I=void 0;if(U<0){var D=h+1;I=D===e.length?"dynamic"===n&&a>0&&o.indexOf("$Number$")>0?R(t,v,b):(s*d-v)/b:(e[D].t-v)/b}else I=U+1;for(var x=f+p.length+I,L=f+p.length;L=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},O=function(t,e){var r={RepresentationID:t.id,Bandwidth:t.bandwidth||0},n=t.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:t.baseUrl,source:N(i.sourceURL,r),range:i.range});return function(t,e){return t.duration||e?t.duration?U(t):T(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodIndex}]}(t,e).map(function(e){r.Number=e.number,r.Time=e.time;var n=N(t.media||"",r);return{uri:n,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",n),map:a,number:e.number}})},A=function(t,e){var r=t.duration,n=t.segmentUrls,i=void 0===n?[]:n;if(!r&&!e||r&&e)throw new Error(l);var a,u=i.map(function(e){return function(t,e){var r=t.baseUrl,n=t.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),u=g({baseUrl:r,source:e.media,range:e.mediaRange});return u.map=a,u}(t,e)});return r&&(a=U(t)),e&&(a=T(t,e)),a.map(function(t,e){if(u[e]){var r=u[e];return r.timeline=t.timeline,r.duration=t.duration,r.number=t.number,r}}).filter(function(t){return t})},M=function(t){var e,r,n=t.attributes,a=t.segmentInfo;a.template?(r=O,e=i(n,a.template)):a.base?(r=y,e=i(n,a.base)):a.list&&(r=A,e=i(n,a.list));var u={attributes:n};if(!r)return u;var o=r(e,a.timeline);if(e.duration){var s=e,c=s.duration,d=s.timescale,l=void 0===d?1:d;e.duration=c/l}else o.length?e.duration=o.reduce(function(t,e){return Math.max(t,Math.ceil(e.duration))},0):e.duration=0;return u.attributes=e,u.segments=o,a.base&&e.indexRange&&(u.sidx=o[0],u.segments=[]),u},z=function(t){return t.map(M)},B=function(t,e){return u(t.childNodes).filter(function(t){return t.tagName===e})},C=function(t){return t.textContent.trim()},F=function(t){var e=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(t);if(!e)return 0;var r=e.slice(1),n=r[0],i=r[1],a=r[2],u=r[3],o=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(u||0)+60*parseFloat(o||0)+parseFloat(s||0)},_={mediaPresentationDuration:function(t){return F(t)},availabilityStartTime:function(t){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(e=t)&&(e+="Z"),Date.parse(e)/1e3;var e},minimumUpdatePeriod:function(t){return F(t)},suggestedPresentationDelay:function(t){return F(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return F(t)},start:function(t){return F(t)},width:function(t){return parseInt(t,10)},height:function(t){return parseInt(t,10)},bandwidth:function(t){return parseInt(t,10)},startNumber:function(t){return parseInt(t,10)},timescale:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?F(t):e},d:function(t){return parseInt(t,10)},t:function(t){return parseInt(t,10)},r:function(t){return parseInt(t,10)},DEFAULT:function(t){return t}},j=function(t){return t&&t.attributes?u(t.attributes).reduce(function(t,e){var r=_[e.name]||_.DEFAULT;return t[e.name]=r(e.value),t},{}):{}};function q(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var k=q(e),$=function(t){return k.default.atob?k.default.atob(t):Buffer.from(t,"base64").toString("binary")};var G=function(t){for(var e=$(t),r=new Uint8Array(e.length),n=0;n0)throw new Error(c);return n};t.VERSION="0.14.0",t.inheritAttributes=Z,t.parse=function(t,e){void 0===e&&(e={});var r=Z(J(t),e),n=z(r.representationInfo);return P(n,r.locations,e.sidxMapping)},t.parseUTCTiming=function(t){return function(t){var e=B(t,"UTCTiming")[0];if(!e)return null;var r=j(e);switch(r.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":r.method="HEAD";break;case"urn:mpeg:dash:utc:http-xsdate:2014":case"urn:mpeg:dash:utc:http-iso:2014":case"urn:mpeg:dash:utc:http-xsdate:2012":case"urn:mpeg:dash:utc:http-iso:2012":r.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":r.method="DIRECT",r.value=Date.parse(r.value);break;case"urn:mpeg:dash:utc:http-ntp:2014":case"urn:mpeg:dash:utc:ntp:2014":case"urn:mpeg:dash:utc:sntp:2014":default:throw new Error(f)}return r}(J(t))},t.stringToMpdXml=J,t.toM3u8=P,t.toPlaylists=z,Object.defineProperty(t,"__esModule",{value:!0})});