mpd-parser
Advanced tools
Comparing version 0.21.0 to 0.21.1
@@ -0,1 +1,9 @@ | ||
<a name="0.21.1"></a> | ||
## [0.21.1](https://github.com/videojs/mpd-parser/compare/v0.21.0...v0.21.1) (2022-04-05) | ||
### Bug Fixes | ||
* DASH content protection schemeIdUri as lowercase ([#157](https://github.com/videojs/mpd-parser/issues/157)) ([aa02006](https://github.com/videojs/mpd-parser/commit/aa02006)), closes [#156](https://github.com/videojs/mpd-parser/issues/156) | ||
* update to vhs-utils 3.0.5 for tizen 2.4 support ([#158](https://github.com/videojs/mpd-parser/issues/158)) ([d7003a3](https://github.com/videojs/mpd-parser/commit/d7003a3)) | ||
<a name="0.21.0"></a> | ||
@@ -2,0 +10,0 @@ # [0.21.0](https://github.com/videojs/mpd-parser/compare/v0.20.0...v0.21.0) (2021-12-17) |
@@ -1,2 +0,2 @@ | ||
/*! @name mpd-parser @version 0.21.0 @license Apache-2.0 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","@xmldom/xmldom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mpdParser={},t.window)}(this,(function(t,e){"use strict";var n=function(t){return!!t&&"object"==typeof t},r=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce((function(e,r){return"object"!=typeof r||Object.keys(r).forEach((function(i){Array.isArray(e[i])&&Array.isArray(r[i])?e[i]=e[i].concat(r[i]):n(e[i])&&n(r[i])?e[i]=t(e[i],r[i]):e[i]=r[i]})),e}),{})},i=function(t){return Object.keys(t).map((function(e){return t[e]}))},a=function(t){return t.reduce((function(t,e){return t.concat(e)}),[])},o=function(t){if(!t.length)return[];for(var e=[],n=0;n<t.length;n++)e.push(t[n]);return e},u=function(t,e){for(var n=0;n<t.length;n++)if(e(t[n]))return n;return-1},s="INVALID_NUMBER_OF_PERIOD",c="DASH_EMPTY_MANIFEST",d="DASH_INVALID_XML",l="NO_BASE_URL",m="SEGMENT_TIME_UNSPECIFIED",f="UNSUPPORTED_UTC_TIMING_SCHEME";var p=function(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}((function(t,e){var n,r,i,a,o;n=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/,r=/^([^\/?#]*)([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(t,e,n){if(n=n||{},t=t.trim(),!(e=e.trim())){if(!n.alwaysNormalize)return t;var i=o.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=o.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return n.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):e;var u=o.parseURL(t);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=r.exec(u.path);u.netLoc=s[1],u.path=s[2]}u.netLoc&&!u.path&&(u.path="/");var c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,l=d.substring(0,d.lastIndexOf("/")+1)+a.path;c.path=o.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=n.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(c)},parseURL:function(t){var e=n.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(i,"");t.length!==(t=t.replace(a,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}},t.exports=o})),g="http://example.com",h=function(t,e){if(/^[a-z]+:/i.test(e))return e;/^data:/.test(t)&&(t=window.location&&window.location.href||"");var n="function"==typeof window.URL,r=/^\/\//.test(t),i=!window.location&&!/\/\//i.test(t);if(n?t=new window.URL(t,window.location||g):/\/\//i.test(t)||(t=p.buildAbsoluteURL(window.location&&window.location.href||"",t)),n){var a=new URL(e,t);return i?a.href.slice(g.length):r?a.href.slice(a.protocol.length):a.href}return p.buildAbsoluteURL(t,e)},v=function(t){var e=t.baseUrl,n=void 0===e?"":e,r=t.source,i=void 0===r?"":r,a=t.range,o=void 0===a?"":a,u=t.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:h(n||"",i)};if(o||s){var d,l=(o||s).split("-"),m=window.BigInt?window.BigInt(l[0]):parseInt(l[0],10),f=window.BigInt?window.BigInt(l[1]):parseInt(l[1],10);m<Number.MAX_SAFE_INTEGER&&"bigint"==typeof m&&(m=Number(m)),f<Number.MAX_SAFE_INTEGER&&"bigint"==typeof f&&(f=Number(f)),"bigint"==typeof(d="bigint"==typeof f||"bigint"==typeof m?window.BigInt(f)-window.BigInt(m)+window.BigInt(1):f-m+1)&&d<Number.MAX_SAFE_INTEGER&&(d=Number(d)),c.byterange={length:d,offset:m}}return c},b=function(t){return t&&"number"!=typeof t&&(t=parseInt(t,10)),isNaN(t)?null:t},y={static:function(t){var e=t.duration,n=t.timescale,r=void 0===n?1:n,i=t.sourceDuration,a=t.periodDuration,o=b(t.endNumber),u=e/r;return"number"==typeof o?{start:0,end:o}:"number"==typeof a?{start:0,end:a/u}:{start:0,end:i/u}},dynamic:function(t){var e=t.NOW,n=t.clientOffset,r=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,o=t.duration,u=t.periodStart,s=void 0===u?0:u,c=t.minimumUpdatePeriod,d=void 0===c?0:c,l=t.timeShiftBufferDepth,m=void 0===l?1/0:l,f=b(t.endNumber),p=(e+n)/1e3,g=r+s,h=p+d-g,v=Math.ceil(h*a/o),y=Math.floor((p-g-m)*a/o),S=Math.floor((p-g)*a/o);return{start:Math.max(0,y),end:"number"==typeof f?f:Math.min(v,S)}}},S=function(t){var e=t.type,n=t.duration,r=t.timescale,i=void 0===r?1:r,a=t.periodDuration,o=t.sourceDuration,u=y[e](t),s=function(t,e){for(var n=[],r=t;r<e;r++)n.push(r);return n}(u.start,u.end).map(function(t){return function(e){var n=t.duration,r=t.timescale,i=void 0===r?1:r,a=t.periodStart,o=t.startNumber;return{number:(void 0===o?1:o)+e,duration:n/i,timeline:a,time:e*n}}}(t));if("static"===e){var c=s.length-1,d="number"==typeof a?a:o;s[c].duration=d-n/i*c}return s},w=function(t){var e=t.baseUrl,n=t.initialization,r=void 0===n?{}:n,i=t.sourceDuration,a=t.indexRange,o=void 0===a?"":a,u=t.periodStart,s=t.presentationTime,c=t.number,d=void 0===c?0:c,m=t.duration;if(!e)throw new Error(l);var f=v({baseUrl:e,source:r.sourceURL,range:r.range}),p=v({baseUrl:e,source:e,indexRange:o});if(p.map=f,m){var g=S(t);g.length&&(p.duration=g[0].duration,p.timeline=g[0].timeline)}else i&&(p.duration=i,p.timeline=u);return p.presentationTime=s||u,p.number=d,[p]},U=function(t,e,n){var r,i=t.sidx.map?t.sidx.map:null,a=t.sidx.duration,o=t.timeline||0,u=t.sidx.byterange,s=u.offset+u.length,c=e.timescale,d=e.references.filter((function(t){return 1!==t.referenceType})),l=[],m=t.endList?"static":"dynamic",f=t.sidx.timeline,p=f,g=t.mediaSequence||0;r="bigint"==typeof e.firstOffset?window.BigInt(s)+e.firstOffset:s+e.firstOffset;for(var h=0;h<d.length;h++){var v=e.references[h],b=v.referencedSize,y=v.subsegmentDuration,S=void 0;S="bigint"==typeof r?r+window.BigInt(b)-window.BigInt(1):r+b-1;var U=w({baseUrl:n,timescale:c,timeline:o,periodStart:f,presentationTime:p,number:g,duration:y,sourceDuration:a,indexRange:r+"-"+S,type:m})[0];i&&(U.map=i),l.push(U),r+="bigint"==typeof r?window.BigInt(b):b,p+=y/c,g++}return t.segments=l,t},I=["AUDIO","SUBTITLES"],E=function(t){return(e=t,n=function(t){return t.timeline},i(e.reduce((function(t,e){return e.forEach((function(e){t[n(e)]=e})),t}),{}))).sort((function(t,e){return t.timeline>e.timeline?1:-1}));var e,n},D=function(t){var e,n,r=[];return e=t,n=function(t,e,n,i){r=r.concat(t.playlists||[])},I.forEach((function(t){for(var r in e.mediaGroups[t])for(var i in e.mediaGroups[t][r]){var a=e.mediaGroups[t][r][i];n(a,t,r,i)}})),r},T=function(t){var e=t.playlist,n=t.mediaSequence;e.mediaSequence=n,e.segments.forEach((function(t,n){t.number=e.mediaSequence+n}))},R=function(t){var e=t.oldManifest,n=t.newManifest,r=e.playlists.concat(D(e)),i=n.playlists.concat(D(n));return n.timelineStarts=E([e.timelineStarts,n.timelineStarts]),function(t){var e=t.oldPlaylists,n=t.newPlaylists,r=t.timelineStarts;n.forEach((function(t){t.discontinuitySequence=u(r,(function(e){return e.timeline===t.timeline}));var n=function(t,e){for(var n=0;n<t.length;n++)if(t[n].attributes.NAME===e)return t[n];return null}(e,t.attributes.NAME);if(n&&!t.sidx){var i=t.segments[0],a=u(n.segments,(function(t){return Math.abs(t.presentationTime-i.presentationTime)<.016666666666666666}));if(-1===a)return T({playlist:t,mediaSequence:n.mediaSequence+n.segments.length}),t.segments[0].discontinuity=!0,t.discontinuityStarts.unshift(0),void((!n.segments.length&&t.timeline>n.timeline||n.segments.length&&t.timeline>n.segments[n.segments.length-1].timeline)&&t.discontinuitySequence--);n.segments[a].discontinuity&&!i.discontinuity&&(i.discontinuity=!0,t.discontinuityStarts.unshift(0),t.discontinuitySequence--),T({playlist:t,mediaSequence:n.segments[a].number})}}))}({oldPlaylists:r,newPlaylists:i,timelineStarts:n.timelineStarts}),n},L=function(t){return t&&t.uri+"-"+(e=t.byterange,n="bigint"==typeof e.offset||"bigint"==typeof e.length?window.BigInt(e.offset)+window.BigInt(e.length)-window.BigInt(1):e.offset+e.length-1,e.offset+"-"+n);var e,n},P=function(t){return i(t.reduce((function(t,e){var n=e.attributes.id+(e.attributes.lang||"");if(t[n]){var r;if(e.segments)e.segments[0]&&(e.segments[0].discontinuity=!0),(r=t[n].segments).push.apply(r,e.segments);e.attributes.contentProtection&&(t[n].attributes.contentProtection=e.attributes.contentProtection)}else t[n]=e,t[n].attributes.timelineStarts=[];return t[n].attributes.timelineStarts.push({start:e.attributes.periodStart,timeline:e.attributes.periodStart}),t}),{})).map((function(t){var e,n;return t.discontinuityStarts=(e=t.segments||[],n="discontinuity",e.reduce((function(t,e,r){return e[n]&&t.push(r),t}),[])),t}))},N=function(t,e){var n=L(t.sidx),r=n&&e[n]&&e[n].sidx;return r&&U(t,r,t.sidx.resolvedUri),t},A=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var n in t)t[n]=N(t[n],e);return t},O=function(t){var e,n=t.attributes,r=t.segments,i=t.sidx,a=t.discontinuityStarts,o={attributes:(e={NAME:n.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:n.width,height:n.height},CODECS:n.codecs,BANDWIDTH:n.bandwidth},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===n.type,timeline:n.periodStart,resolvedUri:"",targetDuration:n.duration,discontinuityStarts:a,timelineStarts:n.timelineStarts,segments:r};return n.contentProtection&&(o.contentProtection=n.contentProtection),i&&(o.sidx=i),o},x=function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video/webm"===e.mimeType||"video"===e.contentType},M=function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio/webm"===e.mimeType||"audio"===e.contentType},B=function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType},q=function(t){return t?Object.keys(t).reduce((function(e,n){var r=t[n];return e.concat(r.playlists)}),[]):[]},C=function(t){var e,n=t.dashPlaylists,r=t.locations,i=t.sidxMapping,a=void 0===i?{}:i,o=t.previousManifest;if(!n.length)return{};var s=n[0].attributes,c=s.sourceDuration,d=s.type,l=s.suggestedPresentationDelay,m=s.minimumUpdatePeriod,f=P(n.filter(x)).map(O),p=P(n.filter(M)),g=P(n.filter(B)),h=n.map((function(t){return t.attributes.captionServices})).filter(Boolean),v={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(e={AUDIO:{},VIDEO:{}},e["CLOSED-CAPTIONS"]={},e.SUBTITLES={},e),uri:"",duration:c,playlists:A(f,a)};m>=0&&(v.minimumUpdatePeriod=1e3*m),r&&(v.locations=r),"dynamic"===d&&(v.suggestedPresentationDelay=l);var b,y,S=0===v.playlists.length,w=p.length?function(t,e,n){var r;void 0===e&&(e={}),void 0===n&&(n=!1);var i=t.reduce((function(t,i){var a=i.attributes.role&&i.attributes.role.value||"",o=i.attributes.lang||"",u=i.attributes.label||"main";if(o&&!i.attributes.label){var s=a?" ("+a+")":"";u=""+i.attributes.lang+s}t[u]||(t[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var c=N(function(t,e){var n,r=t.attributes,i=t.segments,a=t.sidx,o=t.mediaSequence,u=t.discontinuitySequence,s=t.discontinuityStarts,c={attributes:(n={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},n["PROGRAM-ID"]=1,n),uri:"",endList:"static"===r.type,timeline:r.periodStart,resolvedUri:"",targetDuration:r.duration,discontinuitySequence:u,discontinuityStarts:s,timelineStarts:r.timelineStarts,mediaSequence:o,segments:i};return r.contentProtection&&(c.contentProtection=r.contentProtection),a&&(c.sidx=a),e&&(c.attributes.AUDIO="audio",c.attributes.SUBTITLES="subs"),c}(i,n),e);return t[u].playlists.push(c),void 0===r&&"main"===a&&((r=i).default=!0),t}),{});return r||(i[Object.keys(i)[0]].default=!0),i}(p,a,S):null,U=g.length?function(t,e){return void 0===e&&(e={}),t.reduce((function(t,n){var r=n.attributes.lang||"text";return t[r]||(t[r]={language:r,default:!1,autoselect:!1,playlists:[],uri:""}),t[r].playlists.push(N(function(t){var e,n=t.attributes,r=t.segments,i=t.mediaSequence,a=t.discontinuityStarts,o=t.discontinuitySequence;void 0===r&&(r=[{uri:n.baseUrl,timeline:n.periodStart,resolvedUri:n.baseUrl||"",duration:n.sourceDuration,number:0}],n.duration=n.sourceDuration);var u=((e={NAME:n.id,BANDWIDTH:n.bandwidth})["PROGRAM-ID"]=1,e);return n.codecs&&(u.CODECS=n.codecs),{attributes:u,uri:"",endList:"static"===n.type,timeline:n.periodStart,resolvedUri:n.baseUrl||"",targetDuration:n.duration,timelineStarts:n.timelineStarts,discontinuityStarts:a,discontinuitySequence:o,mediaSequence:i,segments:r}}(n),e)),t}),{})}(g,a):null,I=f.concat(q(w),q(U)),D=I.map((function(t){return t.timelineStarts}));return v.timelineStarts=E(D),b=I,y=v.timelineStarts,b.forEach((function(t){t.mediaSequence=0,t.discontinuitySequence=u(y,(function(e){return e.timeline===t.timeline})),t.segments&&t.segments.forEach((function(t,e){t.number=e}))})),w&&(v.mediaGroups.AUDIO.audio=w),U&&(v.mediaGroups.SUBTITLES.subs=U),h.length&&(v.mediaGroups["CLOSED-CAPTIONS"].cc=h.reduce((function(t,e){return e?(e.forEach((function(e){var n=e.channel,r=e.language;t[r]={autoselect:!1,default:!1,instreamId:n,language:r},e.hasOwnProperty("aspectRatio")&&(t[r].aspectRatio=e.aspectRatio),e.hasOwnProperty("easyReader")&&(t[r].easyReader=e.easyReader),e.hasOwnProperty("3D")&&(t[r]["3D"]=e["3D"])})),t):t}),{})),o?R({oldManifest:o,newManifest:v}):v},z=function(t,e,n){var r=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,o=t.timescale,u=void 0===o?1:o,s=t.periodStart,c=void 0===s?0:s,d=t.minimumUpdatePeriod,l=(r+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*u-e)/n)},_=function(t,e){for(var n=t.type,r=t.minimumUpdatePeriod,i=void 0===r?0:r,a=t.media,o=void 0===a?"":a,u=t.sourceDuration,s=t.timescale,c=void 0===s?1:s,d=t.startNumber,l=void 0===d?1:d,m=t.periodStart,f=[],p=-1,g=0;g<e.length;g++){var h=e[g],v=h.d,b=h.r||0,y=h.t||0;p<0&&(p=y),y&&y>p&&(p=y);var S=void 0;if(b<0){var w=g+1;S=w===e.length?"dynamic"===n&&i>0&&o.indexOf("$Number$")>0?z(t,p,v):(u*c-p)/v:(e[w].t-p)/v}else S=b+1;for(var U=l+f.length+S,I=l+f.length;I<U;)f.push({number:I,duration:v/c,time:p,timeline:m}),p+=v,I++}return f},F=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,G=function(t,e){return t.replace(F,function(t){return function(e,n,r,i){if("$$"===e)return"$";if(void 0===t[n])return e;var a=""+t[n];return"RepresentationID"===n?a:(i=r?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},j=function(t,e){var n={RepresentationID:t.id,Bandwidth:t.bandwidth||0},r=t.initialization,i=void 0===r?{sourceURL:"",range:""}:r,a=v({baseUrl:t.baseUrl,source:G(i.sourceURL,n),range:i.range}),o=function(t,e){return t.duration||e?t.duration?S(t):_(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodStart}]}(t,e);return o.map((function(e){n.Number=e.number,n.Time=e.time;var r=G(t.media||"",n),i=t.timescale||1,o=t.presentationTimeOffset||0,u=t.periodStart+(e.time-o)/i;return{uri:r,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",r),map:a,number:e.number,presentationTime:u}}))},k=function(t,e){var n=t.duration,r=t.segmentUrls,i=void 0===r?[]:r,a=t.periodStart;if(!n&&!e||n&&e)throw new Error(m);var o,u=i.map((function(e){return function(t,e){var n=t.baseUrl,r=t.initialization,i=void 0===r?{}:r,a=v({baseUrl:n,source:i.sourceURL,range:i.range}),o=v({baseUrl:n,source:e.media,range:e.mediaRange});return o.map=a,o}(t,e)}));return n&&(o=S(t)),e&&(o=_(t,e)),o.map((function(e,n){if(u[n]){var r=u[n],i=t.timescale||1,o=t.presentationTimeOffset||0;return r.timeline=e.timeline,r.duration=e.duration,r.number=e.number,r.presentationTime=a+(e.time-o)/i,r}})).filter((function(t){return t}))},$=function(t){var e,n,i=t.attributes,a=t.segmentInfo;a.template?(n=j,e=r(i,a.template)):a.base?(n=w,e=r(i,a.base)):a.list&&(n=k,e=r(i,a.list));var o={attributes:i};if(!n)return o;var u=n(e,a.segmentTimeline);if(e.duration){var s=e,c=s.duration,d=s.timescale,l=void 0===d?1:d;e.duration=c/l}else u.length?e.duration=u.reduce((function(t,e){return Math.max(t,Math.ceil(e.duration))}),0):e.duration=0;return o.attributes=e,o.segments=u,a.base&&e.indexRange&&(o.sidx=u[0],o.segments=[]),o},H=function(t){return t.map($)},W=function(t,e){return o(t.childNodes).filter((function(t){return t.tagName===e}))},V=function(t){return t.textContent.trim()},X=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 n=e.slice(1),r=n[0],i=n[1],a=n[2],o=n[3],u=n[4],s=n[5];return 31536e3*parseFloat(r||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)},Y={mediaPresentationDuration:function(t){return X(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 X(t)},suggestedPresentationDelay:function(t){return X(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return X(t)},start:function(t){return X(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)},presentationTimeOffset:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?X(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}},Z=function(t){return t&&t.attributes?o(t.attributes).reduce((function(t,e){var n=Y[e.name]||Y.DEFAULT;return t[e.name]=n(e.value),t}),{}):{}};function K(t){for(var e,n=(e=t,window.atob?window.atob(e):Buffer.from(e,"base64").toString("binary")),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}var J={"urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b":"org.w3.clearkey","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":"com.widevine.alpha","urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":"com.microsoft.playready","urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb":"com.adobe.primetime"},Q=function(t,e){return e.length?a(t.map((function(t){return e.map((function(e){return h(t,V(e))}))}))):t},tt=function(t){var e=W(t,"SegmentTemplate")[0],n=W(t,"SegmentList")[0],i=n&&W(n,"SegmentURL").map((function(t){return r({tag:"SegmentURL"},Z(t))})),a=W(t,"SegmentBase")[0],o=n||e,u=o&&W(o,"SegmentTimeline")[0],s=n||a||e,c=s&&W(s,"Initialization")[0],d=e&&Z(e);d&&c?d.initialization=c&&Z(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,segmentTimeline:u&&W(u,"S").map((function(t){return Z(t)})),list:n&&r(Z(n),{segmentUrls:i,initialization:Z(c)}),base:a&&r(Z(a),{initialization:Z(c)})};return Object.keys(l).forEach((function(t){l[t]||delete l[t]})),l},et=function(t,e,n){return function(i){var o,u=Z(i),s=Q(e,W(i,"BaseURL")),c=W(i,"Role")[0],d={role:Z(c)},l=r(t,u,d),m=W(i,"Accessibility")[0],f="urn:scte:dash:cc:cea-608:2015"===(o=Z(m)).schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(t){var e,n;if(n=t,/^CC\d=/.test(t)){var r=t.split("=");e=r[0],n=r[1]}else/^CC\d$/.test(t)&&(e=t);return{channel:e,language:n}})):"urn:scte:dash:cc:cea-708:2015"===o.schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(t){var e={channel:void 0,language:void 0,aspectRatio:1,easyReader:0,"3D":0};if(/=/.test(t)){var n=t.split("="),r=n[0],i=n[1],a=void 0===i?"":i;e.channel=r,e.language=t,a.split(",").forEach((function(t){var n=t.split(":"),r=n[0],i=n[1];"lang"===r?e.language=i:"er"===r?e.easyReader=Number(i):"war"===r?e.aspectRatio=Number(i):"3D"===r&&(e["3D"]=Number(i))}))}else e.language=t;return e.channel&&(e.channel="SERVICE"+e.channel),e})):void 0;f&&(l=r(l,{captionServices:f}));var p=W(i,"Label")[0];if(p&&p.childNodes.length){var g=p.childNodes[0].nodeValue.trim();l=r(l,{label:g})}var h=W(i,"ContentProtection").reduce((function(t,e){var n=Z(e),r=J[n.schemeIdUri];if(r){t[r]={attributes:n};var i=W(e,"cenc:pssh")[0];if(i){var a=V(i),o=a&&K(a);t[r].pssh=o}}return t}),{});Object.keys(h).length&&(l=r(l,{contentProtection:h}));var v=tt(i),b=W(i,"Representation"),y=r(n,v);return a(b.map(function(t,e,n){return function(i){var a=W(i,"BaseURL"),o=Q(e,a),u=r(t,Z(i)),s=tt(i);return o.map((function(t){return{segmentInfo:r(n,s),attributes:r(u,{baseUrl:t})}}))}}(l,s,y)))}},nt=function(t,e){return function(n,i){var o=Q(e,W(n.node,"BaseURL")),u=r(t,{periodStart:n.attributes.start});"number"==typeof n.attributes.duration&&(u.periodDuration=n.attributes.duration);var s=W(n.node,"AdaptationSet"),c=tt(n.node);return a(s.map(et(u,o,c)))}},rt=function(t,e){void 0===e&&(e={});var n=e,r=n.manifestUri,i=void 0===r?"":r,o=n.NOW,u=void 0===o?Date.now():o,c=n.clientOffset,d=void 0===c?0:c,l=W(t,"Period");if(!l.length)throw new Error(s);var m=W(t,"Location"),f=Z(t),p=Q([i],W(t,"BaseURL"));f.type=f.type||"static",f.sourceDuration=f.mediaPresentationDuration||0,f.NOW=u,f.clientOffset=d,m.length&&(f.locations=m.map(V));var g=[];return l.forEach((function(t,e){var n=Z(t),r=g[e-1];n.start=function(t){var e=t.attributes,n=t.priorPeriodAttributes,r=t.mpdType;return"number"==typeof e.start?e.start:n&&"number"==typeof n.start&&"number"==typeof n.duration?n.start+n.duration:n||"static"!==r?null:0}({attributes:n,priorPeriodAttributes:r?r.attributes:null,mpdType:f.type}),g.push({node:t,attributes:n})})),{locations:f.locations,representationInfo:a(g.map(nt(f,p)))}},it=function(t){if(""===t)throw new Error(c);var n,r,i=new e.DOMParser;try{r=(n=i.parseFromString(t,"application/xml"))&&"MPD"===n.documentElement.tagName?n.documentElement:null}catch(t){}if(!r||r&&r.getElementsByTagName("parsererror").length>0)throw new Error(d);return r};t.VERSION="0.21.0",t.addSidxSegmentsToPlaylist=U,t.generateSidxKey=L,t.inheritAttributes=rt,t.parse=function(t,e){void 0===e&&(e={});var n=rt(it(t),e),r=H(n.representationInfo);return C({dashPlaylists:r,locations:n.locations,sidxMapping:e.sidxMapping,previousManifest:e.previousManifest})},t.parseUTCTiming=function(t){return function(t){var e=W(t,"UTCTiming")[0];if(!e)return null;var n=Z(e);switch(n.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":n.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":n.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":n.method="DIRECT",n.value=Date.parse(n.value);break;default:throw new Error(f)}return n}(it(t))},t.stringToMpdXml=it,t.toM3u8=C,t.toPlaylists=H,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
/*! @name mpd-parser @version 0.21.1 @license Apache-2.0 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","@xmldom/xmldom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mpdParser={},t.window)}(this,(function(t,e){"use strict";var n=function(t){return!!t&&"object"==typeof t},r=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce((function(e,r){return"object"!=typeof r||Object.keys(r).forEach((function(i){Array.isArray(e[i])&&Array.isArray(r[i])?e[i]=e[i].concat(r[i]):n(e[i])&&n(r[i])?e[i]=t(e[i],r[i]):e[i]=r[i]})),e}),{})},i=function(t){return Object.keys(t).map((function(e){return t[e]}))},a=function(t){return t.reduce((function(t,e){return t.concat(e)}),[])},o=function(t){if(!t.length)return[];for(var e=[],n=0;n<t.length;n++)e.push(t[n]);return e},u=function(t,e){for(var n=0;n<t.length;n++)if(e(t[n]))return n;return-1},s="INVALID_NUMBER_OF_PERIOD",c="DASH_EMPTY_MANIFEST",d="DASH_INVALID_XML",l="NO_BASE_URL",m="SEGMENT_TIME_UNSPECIFIED",f="UNSUPPORTED_UTC_TIMING_SCHEME";var p=function(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}((function(t,e){var n,r,i,a,o;n=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,r=/^(?=([^\/?#]*))\1([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(t,e,n){if(n=n||{},t=t.trim(),!(e=e.trim())){if(!n.alwaysNormalize)return t;var i=o.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=o.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return n.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):e;var u=o.parseURL(t);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=r.exec(u.path);u.netLoc=s[1],u.path=s[2]}u.netLoc&&!u.path&&(u.path="/");var c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,l=d.substring(0,d.lastIndexOf("/")+1)+a.path;c.path=o.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=n.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(c)},parseURL:function(t){var e=n.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(i,"");t.length!==(t=t.replace(a,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}},t.exports=o})),g="http://example.com",h=function(t,e){if(/^[a-z]+:/i.test(e))return e;/^data:/.test(t)&&(t=window.location&&window.location.href||"");var n="function"==typeof window.URL,r=/^\/\//.test(t),i=!window.location&&!/\/\//i.test(t);if(n?t=new window.URL(t,window.location||g):/\/\//i.test(t)||(t=p.buildAbsoluteURL(window.location&&window.location.href||"",t)),n){var a=new URL(e,t);return i?a.href.slice(g.length):r?a.href.slice(a.protocol.length):a.href}return p.buildAbsoluteURL(t,e)},v=function(t){var e=t.baseUrl,n=void 0===e?"":e,r=t.source,i=void 0===r?"":r,a=t.range,o=void 0===a?"":a,u=t.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:h(n||"",i)};if(o||s){var d,l=(o||s).split("-"),m=window.BigInt?window.BigInt(l[0]):parseInt(l[0],10),f=window.BigInt?window.BigInt(l[1]):parseInt(l[1],10);m<Number.MAX_SAFE_INTEGER&&"bigint"==typeof m&&(m=Number(m)),f<Number.MAX_SAFE_INTEGER&&"bigint"==typeof f&&(f=Number(f)),"bigint"==typeof(d="bigint"==typeof f||"bigint"==typeof m?window.BigInt(f)-window.BigInt(m)+window.BigInt(1):f-m+1)&&d<Number.MAX_SAFE_INTEGER&&(d=Number(d)),c.byterange={length:d,offset:m}}return c},b=function(t){return t&&"number"!=typeof t&&(t=parseInt(t,10)),isNaN(t)?null:t},y={static:function(t){var e=t.duration,n=t.timescale,r=void 0===n?1:n,i=t.sourceDuration,a=t.periodDuration,o=b(t.endNumber),u=e/r;return"number"==typeof o?{start:0,end:o}:"number"==typeof a?{start:0,end:a/u}:{start:0,end:i/u}},dynamic:function(t){var e=t.NOW,n=t.clientOffset,r=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,o=t.duration,u=t.periodStart,s=void 0===u?0:u,c=t.minimumUpdatePeriod,d=void 0===c?0:c,l=t.timeShiftBufferDepth,m=void 0===l?1/0:l,f=b(t.endNumber),p=(e+n)/1e3,g=r+s,h=p+d-g,v=Math.ceil(h*a/o),y=Math.floor((p-g-m)*a/o),S=Math.floor((p-g)*a/o);return{start:Math.max(0,y),end:"number"==typeof f?f:Math.min(v,S)}}},S=function(t){var e=t.type,n=t.duration,r=t.timescale,i=void 0===r?1:r,a=t.periodDuration,o=t.sourceDuration,u=y[e](t),s=function(t,e){for(var n=[],r=t;r<e;r++)n.push(r);return n}(u.start,u.end).map(function(t){return function(e){var n=t.duration,r=t.timescale,i=void 0===r?1:r,a=t.periodStart,o=t.startNumber;return{number:(void 0===o?1:o)+e,duration:n/i,timeline:a,time:e*n}}}(t));if("static"===e){var c=s.length-1,d="number"==typeof a?a:o;s[c].duration=d-n/i*c}return s},w=function(t){var e=t.baseUrl,n=t.initialization,r=void 0===n?{}:n,i=t.sourceDuration,a=t.indexRange,o=void 0===a?"":a,u=t.periodStart,s=t.presentationTime,c=t.number,d=void 0===c?0:c,m=t.duration;if(!e)throw new Error(l);var f=v({baseUrl:e,source:r.sourceURL,range:r.range}),p=v({baseUrl:e,source:e,indexRange:o});if(p.map=f,m){var g=S(t);g.length&&(p.duration=g[0].duration,p.timeline=g[0].timeline)}else i&&(p.duration=i,p.timeline=u);return p.presentationTime=s||u,p.number=d,[p]},U=function(t,e,n){var r,i=t.sidx.map?t.sidx.map:null,a=t.sidx.duration,o=t.timeline||0,u=t.sidx.byterange,s=u.offset+u.length,c=e.timescale,d=e.references.filter((function(t){return 1!==t.referenceType})),l=[],m=t.endList?"static":"dynamic",f=t.sidx.timeline,p=f,g=t.mediaSequence||0;r="bigint"==typeof e.firstOffset?window.BigInt(s)+e.firstOffset:s+e.firstOffset;for(var h=0;h<d.length;h++){var v=e.references[h],b=v.referencedSize,y=v.subsegmentDuration,S=void 0;S="bigint"==typeof r?r+window.BigInt(b)-window.BigInt(1):r+b-1;var U=w({baseUrl:n,timescale:c,timeline:o,periodStart:f,presentationTime:p,number:g,duration:y,sourceDuration:a,indexRange:r+"-"+S,type:m})[0];i&&(U.map=i),l.push(U),r+="bigint"==typeof r?window.BigInt(b):b,p+=y/c,g++}return t.segments=l,t},I=["AUDIO","SUBTITLES"],E=function(t){return(e=t,n=function(t){return t.timeline},i(e.reduce((function(t,e){return e.forEach((function(e){t[n(e)]=e})),t}),{}))).sort((function(t,e){return t.timeline>e.timeline?1:-1}));var e,n},D=function(t){var e,n,r=[];return e=t,n=function(t,e,n,i){r=r.concat(t.playlists||[])},I.forEach((function(t){for(var r in e.mediaGroups[t])for(var i in e.mediaGroups[t][r]){var a=e.mediaGroups[t][r][i];n(a,t,r,i)}})),r},T=function(t){var e=t.playlist,n=t.mediaSequence;e.mediaSequence=n,e.segments.forEach((function(t,n){t.number=e.mediaSequence+n}))},R=function(t){var e=t.oldManifest,n=t.newManifest,r=e.playlists.concat(D(e)),i=n.playlists.concat(D(n));return n.timelineStarts=E([e.timelineStarts,n.timelineStarts]),function(t){var e=t.oldPlaylists,n=t.newPlaylists,r=t.timelineStarts;n.forEach((function(t){t.discontinuitySequence=u(r,(function(e){return e.timeline===t.timeline}));var n=function(t,e){for(var n=0;n<t.length;n++)if(t[n].attributes.NAME===e)return t[n];return null}(e,t.attributes.NAME);if(n&&!t.sidx){var i=t.segments[0],a=u(n.segments,(function(t){return Math.abs(t.presentationTime-i.presentationTime)<.016666666666666666}));if(-1===a)return T({playlist:t,mediaSequence:n.mediaSequence+n.segments.length}),t.segments[0].discontinuity=!0,t.discontinuityStarts.unshift(0),void((!n.segments.length&&t.timeline>n.timeline||n.segments.length&&t.timeline>n.segments[n.segments.length-1].timeline)&&t.discontinuitySequence--);n.segments[a].discontinuity&&!i.discontinuity&&(i.discontinuity=!0,t.discontinuityStarts.unshift(0),t.discontinuitySequence--),T({playlist:t,mediaSequence:n.segments[a].number})}}))}({oldPlaylists:r,newPlaylists:i,timelineStarts:n.timelineStarts}),n},L=function(t){return t&&t.uri+"-"+(e=t.byterange,n="bigint"==typeof e.offset||"bigint"==typeof e.length?window.BigInt(e.offset)+window.BigInt(e.length)-window.BigInt(1):e.offset+e.length-1,e.offset+"-"+n);var e,n},P=function(t){return i(t.reduce((function(t,e){var n=e.attributes.id+(e.attributes.lang||"");if(t[n]){var r;if(e.segments)e.segments[0]&&(e.segments[0].discontinuity=!0),(r=t[n].segments).push.apply(r,e.segments);e.attributes.contentProtection&&(t[n].attributes.contentProtection=e.attributes.contentProtection)}else t[n]=e,t[n].attributes.timelineStarts=[];return t[n].attributes.timelineStarts.push({start:e.attributes.periodStart,timeline:e.attributes.periodStart}),t}),{})).map((function(t){var e,n;return t.discontinuityStarts=(e=t.segments||[],n="discontinuity",e.reduce((function(t,e,r){return e[n]&&t.push(r),t}),[])),t}))},N=function(t,e){var n=L(t.sidx),r=n&&e[n]&&e[n].sidx;return r&&U(t,r,t.sidx.resolvedUri),t},A=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var n in t)t[n]=N(t[n],e);return t},O=function(t){var e,n=t.attributes,r=t.segments,i=t.sidx,a=t.discontinuityStarts,o={attributes:(e={NAME:n.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:n.width,height:n.height},CODECS:n.codecs,BANDWIDTH:n.bandwidth},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===n.type,timeline:n.periodStart,resolvedUri:"",targetDuration:n.duration,discontinuityStarts:a,timelineStarts:n.timelineStarts,segments:r};return n.contentProtection&&(o.contentProtection=n.contentProtection),i&&(o.sidx=i),o},x=function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video/webm"===e.mimeType||"video"===e.contentType},M=function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio/webm"===e.mimeType||"audio"===e.contentType},B=function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType},q=function(t){return t?Object.keys(t).reduce((function(e,n){var r=t[n];return e.concat(r.playlists)}),[]):[]},C=function(t){var e,n=t.dashPlaylists,r=t.locations,i=t.sidxMapping,a=void 0===i?{}:i,o=t.previousManifest;if(!n.length)return{};var s=n[0].attributes,c=s.sourceDuration,d=s.type,l=s.suggestedPresentationDelay,m=s.minimumUpdatePeriod,f=P(n.filter(x)).map(O),p=P(n.filter(M)),g=P(n.filter(B)),h=n.map((function(t){return t.attributes.captionServices})).filter(Boolean),v={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(e={AUDIO:{},VIDEO:{}},e["CLOSED-CAPTIONS"]={},e.SUBTITLES={},e),uri:"",duration:c,playlists:A(f,a)};m>=0&&(v.minimumUpdatePeriod=1e3*m),r&&(v.locations=r),"dynamic"===d&&(v.suggestedPresentationDelay=l);var b,y,S=0===v.playlists.length,w=p.length?function(t,e,n){var r;void 0===e&&(e={}),void 0===n&&(n=!1);var i=t.reduce((function(t,i){var a=i.attributes.role&&i.attributes.role.value||"",o=i.attributes.lang||"",u=i.attributes.label||"main";if(o&&!i.attributes.label){var s=a?" ("+a+")":"";u=""+i.attributes.lang+s}t[u]||(t[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var c=N(function(t,e){var n,r=t.attributes,i=t.segments,a=t.sidx,o=t.mediaSequence,u=t.discontinuitySequence,s=t.discontinuityStarts,c={attributes:(n={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},n["PROGRAM-ID"]=1,n),uri:"",endList:"static"===r.type,timeline:r.periodStart,resolvedUri:"",targetDuration:r.duration,discontinuitySequence:u,discontinuityStarts:s,timelineStarts:r.timelineStarts,mediaSequence:o,segments:i};return r.contentProtection&&(c.contentProtection=r.contentProtection),a&&(c.sidx=a),e&&(c.attributes.AUDIO="audio",c.attributes.SUBTITLES="subs"),c}(i,n),e);return t[u].playlists.push(c),void 0===r&&"main"===a&&((r=i).default=!0),t}),{});return r||(i[Object.keys(i)[0]].default=!0),i}(p,a,S):null,U=g.length?function(t,e){return void 0===e&&(e={}),t.reduce((function(t,n){var r=n.attributes.lang||"text";return t[r]||(t[r]={language:r,default:!1,autoselect:!1,playlists:[],uri:""}),t[r].playlists.push(N(function(t){var e,n=t.attributes,r=t.segments,i=t.mediaSequence,a=t.discontinuityStarts,o=t.discontinuitySequence;void 0===r&&(r=[{uri:n.baseUrl,timeline:n.periodStart,resolvedUri:n.baseUrl||"",duration:n.sourceDuration,number:0}],n.duration=n.sourceDuration);var u=((e={NAME:n.id,BANDWIDTH:n.bandwidth})["PROGRAM-ID"]=1,e);return n.codecs&&(u.CODECS=n.codecs),{attributes:u,uri:"",endList:"static"===n.type,timeline:n.periodStart,resolvedUri:n.baseUrl||"",targetDuration:n.duration,timelineStarts:n.timelineStarts,discontinuityStarts:a,discontinuitySequence:o,mediaSequence:i,segments:r}}(n),e)),t}),{})}(g,a):null,I=f.concat(q(w),q(U)),D=I.map((function(t){return t.timelineStarts}));return v.timelineStarts=E(D),b=I,y=v.timelineStarts,b.forEach((function(t){t.mediaSequence=0,t.discontinuitySequence=u(y,(function(e){return e.timeline===t.timeline})),t.segments&&t.segments.forEach((function(t,e){t.number=e}))})),w&&(v.mediaGroups.AUDIO.audio=w),U&&(v.mediaGroups.SUBTITLES.subs=U),h.length&&(v.mediaGroups["CLOSED-CAPTIONS"].cc=h.reduce((function(t,e){return e?(e.forEach((function(e){var n=e.channel,r=e.language;t[r]={autoselect:!1,default:!1,instreamId:n,language:r},e.hasOwnProperty("aspectRatio")&&(t[r].aspectRatio=e.aspectRatio),e.hasOwnProperty("easyReader")&&(t[r].easyReader=e.easyReader),e.hasOwnProperty("3D")&&(t[r]["3D"]=e["3D"])})),t):t}),{})),o?R({oldManifest:o,newManifest:v}):v},z=function(t,e,n){var r=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,o=t.timescale,u=void 0===o?1:o,s=t.periodStart,c=void 0===s?0:s,d=t.minimumUpdatePeriod,l=(r+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*u-e)/n)},_=function(t,e){for(var n=t.type,r=t.minimumUpdatePeriod,i=void 0===r?0:r,a=t.media,o=void 0===a?"":a,u=t.sourceDuration,s=t.timescale,c=void 0===s?1:s,d=t.startNumber,l=void 0===d?1:d,m=t.periodStart,f=[],p=-1,g=0;g<e.length;g++){var h=e[g],v=h.d,b=h.r||0,y=h.t||0;p<0&&(p=y),y&&y>p&&(p=y);var S=void 0;if(b<0){var w=g+1;S=w===e.length?"dynamic"===n&&i>0&&o.indexOf("$Number$")>0?z(t,p,v):(u*c-p)/v:(e[w].t-p)/v}else S=b+1;for(var U=l+f.length+S,I=l+f.length;I<U;)f.push({number:I,duration:v/c,time:p,timeline:m}),p+=v,I++}return f},F=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,G=function(t,e){return t.replace(F,function(t){return function(e,n,r,i){if("$$"===e)return"$";if(void 0===t[n])return e;var a=""+t[n];return"RepresentationID"===n?a:(i=r?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},j=function(t,e){var n={RepresentationID:t.id,Bandwidth:t.bandwidth||0},r=t.initialization,i=void 0===r?{sourceURL:"",range:""}:r,a=v({baseUrl:t.baseUrl,source:G(i.sourceURL,n),range:i.range}),o=function(t,e){return t.duration||e?t.duration?S(t):_(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodStart}]}(t,e);return o.map((function(e){n.Number=e.number,n.Time=e.time;var r=G(t.media||"",n),i=t.timescale||1,o=t.presentationTimeOffset||0,u=t.periodStart+(e.time-o)/i;return{uri:r,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",r),map:a,number:e.number,presentationTime:u}}))},k=function(t,e){var n=t.duration,r=t.segmentUrls,i=void 0===r?[]:r,a=t.periodStart;if(!n&&!e||n&&e)throw new Error(m);var o,u=i.map((function(e){return function(t,e){var n=t.baseUrl,r=t.initialization,i=void 0===r?{}:r,a=v({baseUrl:n,source:i.sourceURL,range:i.range}),o=v({baseUrl:n,source:e.media,range:e.mediaRange});return o.map=a,o}(t,e)}));return n&&(o=S(t)),e&&(o=_(t,e)),o.map((function(e,n){if(u[n]){var r=u[n],i=t.timescale||1,o=t.presentationTimeOffset||0;return r.timeline=e.timeline,r.duration=e.duration,r.number=e.number,r.presentationTime=a+(e.time-o)/i,r}})).filter((function(t){return t}))},$=function(t){var e,n,i=t.attributes,a=t.segmentInfo;a.template?(n=j,e=r(i,a.template)):a.base?(n=w,e=r(i,a.base)):a.list&&(n=k,e=r(i,a.list));var o={attributes:i};if(!n)return o;var u=n(e,a.segmentTimeline);if(e.duration){var s=e,c=s.duration,d=s.timescale,l=void 0===d?1:d;e.duration=c/l}else u.length?e.duration=u.reduce((function(t,e){return Math.max(t,Math.ceil(e.duration))}),0):e.duration=0;return o.attributes=e,o.segments=u,a.base&&e.indexRange&&(o.sidx=u[0],o.segments=[]),o},H=function(t){return t.map($)},W=function(t,e){return o(t.childNodes).filter((function(t){return t.tagName===e}))},V=function(t){return t.textContent.trim()},X=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 n=e.slice(1),r=n[0],i=n[1],a=n[2],o=n[3],u=n[4],s=n[5];return 31536e3*parseFloat(r||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)},Y={mediaPresentationDuration:function(t){return X(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 X(t)},suggestedPresentationDelay:function(t){return X(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return X(t)},start:function(t){return X(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)},presentationTimeOffset:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?X(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}},Z=function(t){return t&&t.attributes?o(t.attributes).reduce((function(t,e){var n=Y[e.name]||Y.DEFAULT;return t[e.name]=n(e.value),t}),{}):{}};function K(t){for(var e,n=(e=t,window.atob?window.atob(e):Buffer.from(e,"base64").toString("binary")),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}var J={"urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b":"org.w3.clearkey","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":"com.widevine.alpha","urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":"com.microsoft.playready","urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb":"com.adobe.primetime"},Q=function(t,e){return e.length?a(t.map((function(t){return e.map((function(e){return h(t,V(e))}))}))):t},tt=function(t){var e=W(t,"SegmentTemplate")[0],n=W(t,"SegmentList")[0],i=n&&W(n,"SegmentURL").map((function(t){return r({tag:"SegmentURL"},Z(t))})),a=W(t,"SegmentBase")[0],o=n||e,u=o&&W(o,"SegmentTimeline")[0],s=n||a||e,c=s&&W(s,"Initialization")[0],d=e&&Z(e);d&&c?d.initialization=c&&Z(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,segmentTimeline:u&&W(u,"S").map((function(t){return Z(t)})),list:n&&r(Z(n),{segmentUrls:i,initialization:Z(c)}),base:a&&r(Z(a),{initialization:Z(c)})};return Object.keys(l).forEach((function(t){l[t]||delete l[t]})),l},et=function(t,e,n){return function(i){var o,u=Z(i),s=Q(e,W(i,"BaseURL")),c=W(i,"Role")[0],d={role:Z(c)},l=r(t,u,d),m=W(i,"Accessibility")[0],f="urn:scte:dash:cc:cea-608:2015"===(o=Z(m)).schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(t){var e,n;if(n=t,/^CC\d=/.test(t)){var r=t.split("=");e=r[0],n=r[1]}else/^CC\d$/.test(t)&&(e=t);return{channel:e,language:n}})):"urn:scte:dash:cc:cea-708:2015"===o.schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(t){var e={channel:void 0,language:void 0,aspectRatio:1,easyReader:0,"3D":0};if(/=/.test(t)){var n=t.split("="),r=n[0],i=n[1],a=void 0===i?"":i;e.channel=r,e.language=t,a.split(",").forEach((function(t){var n=t.split(":"),r=n[0],i=n[1];"lang"===r?e.language=i:"er"===r?e.easyReader=Number(i):"war"===r?e.aspectRatio=Number(i):"3D"===r&&(e["3D"]=Number(i))}))}else e.language=t;return e.channel&&(e.channel="SERVICE"+e.channel),e})):void 0;f&&(l=r(l,{captionServices:f}));var p=W(i,"Label")[0];if(p&&p.childNodes.length){var g=p.childNodes[0].nodeValue.trim();l=r(l,{label:g})}var h=W(i,"ContentProtection").reduce((function(t,e){var n=Z(e);n.schemeIdUri&&(n.schemeIdUri=n.schemeIdUri.toLowerCase());var r=J[n.schemeIdUri];if(r){t[r]={attributes:n};var i=W(e,"cenc:pssh")[0];if(i){var a=V(i);t[r].pssh=a&&K(a)}}return t}),{});Object.keys(h).length&&(l=r(l,{contentProtection:h}));var v=tt(i),b=W(i,"Representation"),y=r(n,v);return a(b.map(function(t,e,n){return function(i){var a=W(i,"BaseURL"),o=Q(e,a),u=r(t,Z(i)),s=tt(i);return o.map((function(t){return{segmentInfo:r(n,s),attributes:r(u,{baseUrl:t})}}))}}(l,s,y)))}},nt=function(t,e){return function(n,i){var o=Q(e,W(n.node,"BaseURL")),u=r(t,{periodStart:n.attributes.start});"number"==typeof n.attributes.duration&&(u.periodDuration=n.attributes.duration);var s=W(n.node,"AdaptationSet"),c=tt(n.node);return a(s.map(et(u,o,c)))}},rt=function(t,e){void 0===e&&(e={});var n=e,r=n.manifestUri,i=void 0===r?"":r,o=n.NOW,u=void 0===o?Date.now():o,c=n.clientOffset,d=void 0===c?0:c,l=W(t,"Period");if(!l.length)throw new Error(s);var m=W(t,"Location"),f=Z(t),p=Q([i],W(t,"BaseURL"));f.type=f.type||"static",f.sourceDuration=f.mediaPresentationDuration||0,f.NOW=u,f.clientOffset=d,m.length&&(f.locations=m.map(V));var g=[];return l.forEach((function(t,e){var n=Z(t),r=g[e-1];n.start=function(t){var e=t.attributes,n=t.priorPeriodAttributes,r=t.mpdType;return"number"==typeof e.start?e.start:n&&"number"==typeof n.start&&"number"==typeof n.duration?n.start+n.duration:n||"static"!==r?null:0}({attributes:n,priorPeriodAttributes:r?r.attributes:null,mpdType:f.type}),g.push({node:t,attributes:n})})),{locations:f.locations,representationInfo:a(g.map(nt(f,p)))}},it=function(t){if(""===t)throw new Error(c);var n,r,i=new e.DOMParser;try{r=(n=i.parseFromString(t,"application/xml"))&&"MPD"===n.documentElement.tagName?n.documentElement:null}catch(t){}if(!r||r&&r.getElementsByTagName("parsererror").length>0)throw new Error(d);return r};t.VERSION="0.21.1",t.addSidxSegmentsToPlaylist=U,t.generateSidxKey=L,t.inheritAttributes=rt,t.parse=function(t,e){void 0===e&&(e={});var n=rt(it(t),e),r=H(n.representationInfo);return C({dashPlaylists:r,locations:n.locations,sidxMapping:e.sidxMapping,previousManifest:e.previousManifest})},t.parseUTCTiming=function(t){return function(t){var e=W(t,"UTCTiming")[0];if(!e)return null;var n=Z(e);switch(n.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":n.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":n.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":n.method="DIRECT",n.value=Date.parse(n.value);break;default:throw new Error(f)}return n}(it(t))},t.stringToMpdXml=it,t.toM3u8=C,t.toPlaylists=H,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "mpd-parser", | ||
"version": "0.21.0", | ||
"version": "0.21.1", | ||
"description": "mpd parser", | ||
@@ -59,3 +59,3 @@ "main": "dist/mpd-parser.cjs.js", | ||
"@babel/runtime": "^7.12.5", | ||
"@videojs/vhs-utils": "^3.0.2", | ||
"@videojs/vhs-utils": "^3.0.5", | ||
"@xmldom/xmldom": "^0.7.2", | ||
@@ -62,0 +62,0 @@ "global": "^4.4.0" |
@@ -178,2 +178,10 @@ import { flatten } from './utils/list'; | ||
const attributes = parseAttributes(node); | ||
// Although it could be argued that according to the UUID RFC spec the UUID string (a-f chars) should be generated | ||
// as a lowercase string it also mentions it should be treated as case-insensitive on input. Since the key system | ||
// UUIDs in the keySystemsMap are hardcoded as lowercase in the codebase there isn't any reason not to do | ||
// .toLowerCase() on the input UUID string from the manifest (at least I could not think of one). | ||
if (attributes.schemeIdUri) { | ||
attributes.schemeIdUri = attributes.schemeIdUri.toLowerCase(); | ||
} | ||
const keySystem = keySystemsMap[attributes.schemeIdUri]; | ||
@@ -188,5 +196,4 @@ | ||
const pssh = getContent(psshNode); | ||
const psshBuffer = pssh && decodeB64ToUint8Array(pssh); | ||
acc[keySystem].pssh = psshBuffer; | ||
acc[keySystem].pssh = pssh && decodeB64ToUint8Array(pssh); | ||
} | ||
@@ -193,0 +200,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
933209
24072
Updated@videojs/vhs-utils@^3.0.5