mpd-parser
Advanced tools
Comparing version 0.19.2 to 0.20.0
@@ -0,1 +1,16 @@ | ||
<a name="0.20.0"></a> | ||
# [0.20.0](https://github.com/videojs/mpd-parser/compare/v0.19.2...v0.20.0) (2021-11-29) | ||
### Features | ||
* support BigInt values ([#135](https://github.com/videojs/mpd-parser/issues/135)) ([50eb434](https://github.com/videojs/mpd-parser/commit/50eb434)) | ||
### Chores | ||
* don't run tests on version ([#154](https://github.com/videojs/mpd-parser/issues/154)) ([bcbe162](https://github.com/videojs/mpd-parser/commit/bcbe162)) | ||
### Documentation | ||
* fixed examples of using "parse" ([#149](https://github.com/videojs/mpd-parser/issues/149)) ([bf0421e](https://github.com/videojs/mpd-parser/commit/bf0421e)) | ||
<a name="0.19.2"></a> | ||
@@ -2,0 +17,0 @@ ## [0.19.2](https://github.com/videojs/mpd-parser/compare/v0.19.1...v0.19.2) (2021-10-06) |
@@ -1,2 +0,2 @@ | ||
/*! @name mpd-parser @version 0.19.2 @license Apache-2.0 */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","@xmldom/xmldom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mpdParser={},e.window)}(this,(function(e,t){"use strict";var r=function(e){return!!e&&"object"==typeof e},n=function e(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return n.reduce((function(t,n){return"object"!=typeof n||Object.keys(n).forEach((function(i){Array.isArray(t[i])&&Array.isArray(n[i])?t[i]=t[i].concat(n[i]):r(t[i])&&r(n[i])?t[i]=e(t[i],n[i]):t[i]=n[i]})),t}),{})},i=function(e){return e.reduce((function(e,t){return e.concat(t)}),[])},a=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},o="INVALID_NUMBER_OF_PERIOD",u="DASH_EMPTY_MANIFEST",s="DASH_INVALID_XML",c="NO_BASE_URL",d="SEGMENT_TIME_UNSPECIFIED",l="UNSUPPORTED_UTC_TIMING_SCHEME";var m=function(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}((function(e,t){var r,n,i,a,o;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/,n=/^([^\/?#]*)([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=o.parseURL(e);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(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):t;var u=o.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=n.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=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(c)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=o})),f="http://example.com",p=function(e,t){if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");var r="function"==typeof window.URL,n=/^\/\//.test(e),i=!window.location&&!/\/\//i.test(e);if(r?e=new window.URL(e,window.location||f):/\/\//i.test(e)||(e=m.buildAbsoluteURL(window.location&&window.location.href||"",e)),r){var a=new URL(t,e);return i?a.href.slice(f.length):n?a.href.slice(a.protocol.length):a.href}return m.buildAbsoluteURL(e,t)},h=function(e){var t=e.baseUrl,r=void 0===t?"":t,n=e.source,i=void 0===n?"":n,a=e.range,o=void 0===a?"":a,u=e.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:p(r||"",i)};if(o||s){var d=(o||s).split("-"),l=parseInt(d[0],10),m=parseInt(d[1],10);c.byterange={length:m-l+1,offset:l}}return c},v=function(e){return e&&"number"!=typeof e&&(e=parseInt(e,10)),isNaN(e)?null:e},b={static:function(e){var t=e.duration,r=e.timescale,n=void 0===r?1:r,i=e.sourceDuration,a=e.periodDuration,o=v(e.endNumber),u=t/n;return"number"==typeof o?{start:0,end:o}:"number"==typeof a?{start:0,end:a/u}:{start:0,end:i/u}},dynamic:function(e){var t=e.NOW,r=e.clientOffset,n=e.availabilityStartTime,i=e.timescale,a=void 0===i?1:i,o=e.duration,u=e.start,s=void 0===u?0:u,c=e.minimumUpdatePeriod,d=void 0===c?0:c,l=e.timeShiftBufferDepth,m=void 0===l?1/0:l,f=v(e.endNumber),p=(t+r)/1e3,h=n+s,b=p+d-h,g=Math.ceil(b*a/o),y=Math.floor((p-h-m)*a/o),U=Math.floor((p-h)*a/o);return{start:Math.max(0,y),end:"number"==typeof f?f:Math.min(g,U)}}},g=function(e){var t=e.type,r=e.duration,n=e.timescale,i=void 0===n?1:n,a=e.periodDuration,o=e.sourceDuration,u=b[t](e),s=function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(u.start,u.end).map(function(e){return function(t,r){var n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.periodIndex,u=e.startNumber;return{number:(void 0===u?1:u)+t,duration:n/a,timeline:o,time:r*n}}}(e));if("static"===t){var c=s.length-1,d="number"==typeof a?a:o;s[c].duration=d-r/i*c}return s},y=function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.indexRange,o=void 0===a?"":a,u=e.duration;if(!t)throw new Error(c);var s=h({baseUrl:t,source:n.sourceURL,range:n.range}),d=h({baseUrl:t,source:t,indexRange:o});if(d.map=s,u){var l=g(e);l.length&&(d.duration=l[0].duration,d.timeline=l[0].timeline)}else i&&(d.duration=i,d.timeline=0);return d.number=0,[d]},U=function(e,t,r){for(var n=e.sidx.map?e.sidx.map:null,i=e.sidx.duration,a=e.timeline||0,o=e.sidx.byterange,u=o.offset+o.length,s=t.timescale,c=t.references.filter((function(e){return 1!==e.referenceType})),d=[],l=e.endList?"static":"dynamic",m=u+t.firstOffset,f=0;f<c.length;f++){var p=t.references[f],h=p.referencedSize,v=p.subsegmentDuration,b=y({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:v,sourceDuration:i,indexRange:m+"-"+(m+h-1),type:l})[0];n&&(b.map=n),d.push(b),m+=h}return e.segments=d,e},w=function(e){return e&&e.uri+"-"+(t=e.byterange,r=t.offset+t.length-1,t.offset+"-"+r);var t,r},D=function(e){var t;return(t=e.reduce((function(e,t){var r,n=t.attributes.id+(t.attributes.lang||"");return e[n]?(t.segments[0]&&(t.segments[0].discontinuity=!0),(r=e[n].segments).push.apply(r,t.segments),t.attributes.contentProtection&&(e[n].attributes.contentProtection=t.attributes.contentProtection)):e[n]=t,e}),{}),Object.keys(t).map((function(e){return t[e]}))).map((function(e){var t,r;return e.discontinuityStarts=(t=e.segments,r="discontinuity",t.reduce((function(e,t,n){return t[r]&&e.push(n),e}),[])),e}))},I=function(e,t){var r=w(e.sidx),n=r&&t[r]&&t[r].sidx;return n&&U(e,n,e.sidx.resolvedUri),e},R=function(e,t){if(void 0===t&&(t={}),!Object.keys(t).length)return e;for(var r in e)e[r]=I(e[r],t);return e},T=function(e){var t,r=e.attributes,n=e.segments,i=e.sidx,a={attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},t["PROGRAM-ID"]=1,t),uri:"",endList:"static"===r.type,timeline:r.periodIndex,resolvedUri:"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1};return r.contentProtection&&(a.contentProtection=r.contentProtection),i&&(a.sidx=i),a},L=function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video/webm"===t.mimeType||"video"===t.contentType},E=function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio/webm"===t.mimeType||"audio"===t.contentType},S=function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType},x=function(e,t,r){var n;if(void 0===r&&(r={}),!e.length)return{};var i=e[0].attributes,a=i.sourceDuration,o=i.type,u=i.suggestedPresentationDelay,s=i.minimumUpdatePeriod,c=D(e.filter(L)).map(T),d=D(e.filter(E)),l=e.filter(S),m=e.map((function(e){return e.attributes.captionServices})).filter(Boolean),f={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:R(c,r)};s>=0&&(f.minimumUpdatePeriod=1e3*s),t&&(f.locations=t),"dynamic"===o&&(f.suggestedPresentationDelay=u);var p=0===f.playlists.length;return d.length&&(f.mediaGroups.AUDIO.audio=function(e,t,r){var n;void 0===t&&(t={}),void 0===r&&(r=!1);var i=e.reduce((function(e,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}e[u]||(e[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var c=I(function(e,t){var r,n=e.attributes,i=e.segments,a=e.sidx,o={attributes:(r={NAME:n.id,BANDWIDTH:n.bandwidth,CODECS:n.codecs},r["PROGRAM-ID"]=1,r),uri:"",endList:"static"===n.type,timeline:n.periodIndex,resolvedUri:"",targetDuration:n.duration,segments:i,mediaSequence:i.length?i[0].number:1};return n.contentProtection&&(o.contentProtection=n.contentProtection),a&&(o.sidx=a),t&&(o.attributes.AUDIO="audio",o.attributes.SUBTITLES="subs"),o}(i,r),t);return e[u].playlists.push(c),void 0===n&&"main"===a&&((n=i).default=!0),e}),{});return n||(i[Object.keys(i)[0]].default=!0),i}(d,r,p)),l.length&&(f.mediaGroups.SUBTITLES.subs=function(e,t){return void 0===t&&(t={}),e.reduce((function(e,r){var n=r.attributes.lang||"text";return e[n]||(e[n]={language:n,default:!1,autoselect:!1,playlists:[],uri:""}),e[n].playlists.push(I(function(e){var t,r=e.attributes,n=e.segments;void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration,number:0}],r.duration=r.sourceDuration);var i=((t={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,t);return r.codecs&&(i.CODECS=r.codecs),{attributes:i,uri:"",endList:"static"===r.type,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1}}(r),t)),e}),{})}(l,r)),m.length&&(f.mediaGroups["CLOSED-CAPTIONS"].cc=m.reduce((function(e,t){return t?(t.forEach((function(t){var r=t.channel,n=t.language;e[n]={autoselect:!1,default:!1,instreamId:r,language:n},t.hasOwnProperty("aspectRatio")&&(e[n].aspectRatio=t.aspectRatio),t.hasOwnProperty("easyReader")&&(e[n].easyReader=t.easyReader),t.hasOwnProperty("3D")&&(e[n]["3D"]=t["3D"])})),e):e}),{})),f},P=function(e,t,r){var n=e.NOW,i=e.clientOffset,a=e.availabilityStartTime,o=e.timescale,u=void 0===o?1:o,s=e.start,c=void 0===s?0:s,d=e.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*u-t)/r)},N=function(e,t){for(var r=e.type,n=e.minimumUpdatePeriod,i=void 0===n?0:n,a=e.media,o=void 0===a?"":a,u=e.sourceDuration,s=e.timescale,c=void 0===s?1:s,d=e.startNumber,l=void 0===d?1:d,m=e.periodIndex,f=[],p=-1,h=0;h<t.length;h++){var v=t[h],b=v.d,g=v.r||0,y=v.t||0;p<0&&(p=y),y&&y>p&&(p=y);var U=void 0;if(g<0){var w=h+1;U=w===t.length?"dynamic"===r&&i>0&&o.indexOf("$Number$")>0?P(e,p,b):(u*c-p)/b:(t[w].t-p)/b}else U=g+1;for(var D=l+f.length+U,I=l+f.length;I<D;)f.push({number:I,duration:b/c,time:p,timeline:m}),p+=b,I++}return f},O=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,A=function(e,t){return e.replace(O,function(e){return function(t,r,n,i){if("$$"===t)return"$";if(void 0===e[r])return t;var a=""+e[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(t))},M=function(e,t){var r={RepresentationID:e.id,Bandwidth:e.bandwidth||0},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=h({baseUrl:e.baseUrl,source:A(i.sourceURL,r),range:i.range}),o=function(e,t){return e.duration||t?e.duration?g(e):N(e,t):[{number:e.startNumber||1,duration:e.sourceDuration,time:0,timeline:e.periodIndex}]}(e,t);return o.map((function(t){r.Number=t.number,r.Time=t.time;var n=A(e.media||"",r),i=e.timescale||1,o=e.presentationTimeOffset||0,u=e.periodStart+(t.time-o)/i;return{uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:p(e.baseUrl||"",n),map:a,number:t.number,presentationTime:u}}))},C=function(e,t){var r=e.duration,n=e.segmentUrls,i=void 0===n?[]:n,a=e.periodStart;if(!r&&!t||r&&t)throw new Error(d);var o,u=i.map((function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=h({baseUrl:r,source:i.sourceURL,range:i.range}),o=h({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}));return r&&(o=g(e)),t&&(o=N(e,t)),o.map((function(t,r){if(u[r]){var n=u[r],i=e.timescale||1,o=e.presentationTimeOffset||0;return n.timeline=t.timeline,n.duration=t.duration,n.number=t.number,n.presentationTime=a+(t.time-o)/i,n}})).filter((function(e){return e}))},z=function(e){var t,r,i=e.attributes,a=e.segmentInfo;a.template?(r=M,t=n(i,a.template)):a.base?(r=y,t=n(i,a.base)):a.list&&(r=C,t=n(i,a.list));var o={attributes:i};if(!r)return o;var u=r(t,a.segmentTimeline);if(t.duration){var s=t,c=s.duration,d=s.timescale,l=void 0===d?1:d;t.duration=c/l}else u.length?t.duration=u.reduce((function(e,t){return Math.max(e,Math.ceil(t.duration))}),0):t.duration=0;return o.attributes=t,o.segments=u,a.base&&t.indexRange&&(o.sidx=u[0],o.segments=[]),o},B=function(e){return e.map(z)},F=function(e,t){return a(e.childNodes).filter((function(e){return e.tagName===t}))},_=function(e){return e.textContent.trim()},j=function(e){var t=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(e);if(!t)return 0;var r=t.slice(1),n=r[0],i=r[1],a=r[2],o=r[3],u=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)},q={mediaPresentationDuration:function(e){return j(e)},availabilityStartTime:function(e){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(t=e)&&(t+="Z"),Date.parse(t)/1e3;var t},minimumUpdatePeriod:function(e){return j(e)},suggestedPresentationDelay:function(e){return j(e)},type:function(e){return e},timeShiftBufferDepth:function(e){return j(e)},start:function(e){return j(e)},width:function(e){return parseInt(e,10)},height:function(e){return parseInt(e,10)},bandwidth:function(e){return parseInt(e,10)},startNumber:function(e){return parseInt(e,10)},timescale:function(e){return parseInt(e,10)},presentationTimeOffset:function(e){return parseInt(e,10)},duration:function(e){var t=parseInt(e,10);return isNaN(t)?j(e):t},d:function(e){return parseInt(e,10)},t:function(e){return parseInt(e,10)},r:function(e){return parseInt(e,10)},DEFAULT:function(e){return e}},$=function(e){return e&&e.attributes?a(e.attributes).reduce((function(e,t){var r=q[t.name]||q.DEFAULT;return e[t.name]=r(t.value),e}),{}):{}};function k(e){for(var t,r=(t=e,window.atob?window.atob(t):Buffer.from(t,"base64").toString("binary")),n=new Uint8Array(r.length),i=0;i<r.length;i++)n[i]=r.charCodeAt(i);return n}var G={"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"},H=function(e,t){return t.length?i(e.map((function(e){return t.map((function(t){return p(e,_(t))}))}))):e},W=function(e){var t=F(e,"SegmentTemplate")[0],r=F(e,"SegmentList")[0],i=r&&F(r,"SegmentURL").map((function(e){return n({tag:"SegmentURL"},$(e))})),a=F(e,"SegmentBase")[0],o=r||t,u=o&&F(o,"SegmentTimeline")[0],s=r||a||t,c=s&&F(s,"Initialization")[0],d=t&&$(t);d&&c?d.initialization=c&&$(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,segmentTimeline:u&&F(u,"S").map((function(e){return $(e)})),list:r&&n($(r),{segmentUrls:i,initialization:$(c)}),base:a&&n($(a),{initialization:$(c)})};return Object.keys(l).forEach((function(e){l[e]||delete l[e]})),l},V=function(e,t,r){return function(a){var o,u=$(a),s=H(t,F(a,"BaseURL")),c=F(a,"Role")[0],d={role:$(c)},l=n(e,u,d),m=F(a,"Accessibility")[0],f="urn:scte:dash:cc:cea-608:2015"===(o=$(m)).schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(e){var t,r;if(r=e,/^CC\d=/.test(e)){var n=e.split("=");t=n[0],r=n[1]}else/^CC\d$/.test(e)&&(t=e);return{channel:t,language:r}})):"urn:scte:dash:cc:cea-708:2015"===o.schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(e){var t={channel:void 0,language:void 0,aspectRatio:1,easyReader:0,"3D":0};if(/=/.test(e)){var r=e.split("="),n=r[0],i=r[1],a=void 0===i?"":i;t.channel=n,t.language=e,a.split(",").forEach((function(e){var r=e.split(":"),n=r[0],i=r[1];"lang"===n?t.language=i:"er"===n?t.easyReader=Number(i):"war"===n?t.aspectRatio=Number(i):"3D"===n&&(t["3D"]=Number(i))}))}else t.language=e;return t.channel&&(t.channel="SERVICE"+t.channel),t})):void 0;f&&(l=n(l,{captionServices:f}));var p=F(a,"Label")[0];if(p&&p.childNodes.length){var h=p.childNodes[0].nodeValue.trim();l=n(l,{label:h})}var v=F(a,"ContentProtection").reduce((function(e,t){var r=$(t),n=G[r.schemeIdUri];if(n){e[n]={attributes:r};var i=F(t,"cenc:pssh")[0];if(i){var a=_(i),o=a&&k(a);e[n].pssh=o}}return e}),{});Object.keys(v).length&&(l=n(l,{contentProtection:v}));var b=W(a),g=F(a,"Representation"),y=n(r,b);return i(g.map(function(e,t,r){return function(i){var a=F(i,"BaseURL"),o=H(t,a),u=n(e,$(i)),s=W(i);return o.map((function(e){return{segmentInfo:n(r,s),attributes:n(u,{baseUrl:e})}}))}}(l,s,y)))}},X=function(e,t){return function(r,a){var o=H(t,F(r.node,"BaseURL")),u=parseInt(r.attributes.id,10),s=window.isNaN(u)?a:u,c=n(e,{periodIndex:s,periodStart:r.attributes.start});"number"==typeof r.attributes.duration&&(c.periodDuration=r.attributes.duration);var d=F(r.node,"AdaptationSet"),l=W(r.node);return i(d.map(V(c,o,l)))}},Y=function(e,t){void 0===t&&(t={});var r=t,n=r.manifestUri,a=void 0===n?"":n,u=r.NOW,s=void 0===u?Date.now():u,c=r.clientOffset,d=void 0===c?0:c,l=F(e,"Period");if(!l.length)throw new Error(o);var m=F(e,"Location"),f=$(e),p=H([a],F(e,"BaseURL"));f.type=f.type||"static",f.sourceDuration=f.mediaPresentationDuration||0,f.NOW=s,f.clientOffset=d,m.length&&(f.locations=m.map(_));var h=[];return l.forEach((function(e,t){var r=$(e),n=h[t-1];r.start=function(e){var t=e.attributes,r=e.priorPeriodAttributes,n=e.mpdType;return"number"==typeof t.start?t.start:r&&"number"==typeof r.start&&"number"==typeof r.duration?r.start+r.duration:r||"static"!==n?null:0}({attributes:r,priorPeriodAttributes:n?n.attributes:null,mpdType:f.type}),h.push({node:e,attributes:r})})),{locations:f.locations,representationInfo:i(h.map(X(f,p)))}},Z=function(e){if(""===e)throw new Error(u);var r,n,i=new t.DOMParser;try{n=(r=i.parseFromString(e,"application/xml"))&&"MPD"===r.documentElement.tagName?r.documentElement:null}catch(e){}if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(s);return n};e.VERSION="0.19.2",e.addSidxSegmentsToPlaylist=U,e.generateSidxKey=w,e.inheritAttributes=Y,e.parse=function(e,t){void 0===t&&(t={});var r=Y(Z(e),t),n=B(r.representationInfo);return x(n,r.locations,t.sidxMapping)},e.parseUTCTiming=function(e){return function(e){var t=F(e,"UTCTiming")[0];if(!t)return null;var r=$(t);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;default:throw new Error(l)}return r}(Z(e))},e.stringToMpdXml=Z,e.toM3u8=x,e.toPlaylists=B,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/*! @name mpd-parser @version 0.20.0 @license Apache-2.0 */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","@xmldom/xmldom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mpdParser={},e.window)}(this,(function(e,t){"use strict";var r=function(e){return!!e&&"object"==typeof e},n=function e(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return n.reduce((function(t,n){return"object"!=typeof n||Object.keys(n).forEach((function(i){Array.isArray(t[i])&&Array.isArray(n[i])?t[i]=t[i].concat(n[i]):r(t[i])&&r(n[i])?t[i]=e(t[i],n[i]):t[i]=n[i]})),t}),{})},i=function(e){return e.reduce((function(e,t){return e.concat(t)}),[])},a=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},o="INVALID_NUMBER_OF_PERIOD",u="DASH_EMPTY_MANIFEST",s="DASH_INVALID_XML",d="NO_BASE_URL",c="SEGMENT_TIME_UNSPECIFIED",l="UNSUPPORTED_UTC_TIMING_SCHEME";var f=function(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}((function(e,t){var r,n,i,a,o;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/,n=/^([^\/?#]*)([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,o={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=o.parseURL(e);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(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):t;var u=o.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=n.exec(u.path);u.netLoc=s[1],u.path=s[2]}u.netLoc&&!u.path&&(u.path="/");var d={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(d.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var c=u.path,l=c.substring(0,c.lastIndexOf("/")+1)+a.path;d.path=o.normalizePath(l)}else d.path=u.path,a.params||(d.params=u.params,a.query||(d.query=u.query));return null===d.path&&(d.path=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(d)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=o})),m="http://example.com",p=function(e,t){if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");var r="function"==typeof window.URL,n=/^\/\//.test(e),i=!window.location&&!/\/\//i.test(e);if(r?e=new window.URL(e,window.location||m):/\/\//i.test(e)||(e=f.buildAbsoluteURL(window.location&&window.location.href||"",e)),r){var a=new URL(t,e);return i?a.href.slice(m.length):n?a.href.slice(a.protocol.length):a.href}return f.buildAbsoluteURL(e,t)},g=function(e){var t=e.baseUrl,r=void 0===t?"":t,n=e.source,i=void 0===n?"":n,a=e.range,o=void 0===a?"":a,u=e.indexRange,s=void 0===u?"":u,d={uri:i,resolvedUri:p(r||"",i)};if(o||s){var c,l=(o||s).split("-"),f=window.BigInt?window.BigInt(l[0]):parseInt(l[0],10),m=window.BigInt?window.BigInt(l[1]):parseInt(l[1],10);f<Number.MAX_SAFE_INTEGER&&"bigint"==typeof f&&(f=Number(f)),m<Number.MAX_SAFE_INTEGER&&"bigint"==typeof m&&(m=Number(m)),"bigint"==typeof(c="bigint"==typeof m||"bigint"==typeof f?window.BigInt(m)-window.BigInt(f)+window.BigInt(1):m-f+1)&&c<Number.MAX_SAFE_INTEGER&&(c=Number(c)),d.byterange={length:c,offset:f}}return d},h=function(e){return e&&"number"!=typeof e&&(e=parseInt(e,10)),isNaN(e)?null:e},v={static:function(e){var t=e.duration,r=e.timescale,n=void 0===r?1:r,i=e.sourceDuration,a=e.periodDuration,o=h(e.endNumber),u=t/n;return"number"==typeof o?{start:0,end:o}:"number"==typeof a?{start:0,end:a/u}:{start:0,end:i/u}},dynamic:function(e){var t=e.NOW,r=e.clientOffset,n=e.availabilityStartTime,i=e.timescale,a=void 0===i?1:i,o=e.duration,u=e.start,s=void 0===u?0:u,d=e.minimumUpdatePeriod,c=void 0===d?0:d,l=e.timeShiftBufferDepth,f=void 0===l?1/0:l,m=h(e.endNumber),p=(t+r)/1e3,g=n+s,v=p+c-g,b=Math.ceil(v*a/o),y=Math.floor((p-g-f)*a/o),w=Math.floor((p-g)*a/o);return{start:Math.max(0,y),end:"number"==typeof m?m:Math.min(b,w)}}},b=function(e){var t=e.type,r=e.duration,n=e.timescale,i=void 0===n?1:n,a=e.periodDuration,o=e.sourceDuration,u=v[t](e),s=function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(u.start,u.end).map(function(e){return function(t,r){var n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.periodIndex,u=e.startNumber;return{number:(void 0===u?1:u)+t,duration:n/a,timeline:o,time:r*n}}}(e));if("static"===t){var d=s.length-1,c="number"==typeof a?a:o;s[d].duration=c-r/i*d}return s},y=function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.indexRange,o=void 0===a?"":a,u=e.duration;if(!t)throw new Error(d);var s=g({baseUrl:t,source:n.sourceURL,range:n.range}),c=g({baseUrl:t,source:t,indexRange:o});if(c.map=s,u){var l=b(e);l.length&&(c.duration=l[0].duration,c.timeline=l[0].timeline)}else i&&(c.duration=i,c.timeline=0);return c.number=0,[c]},w=function(e,t,r){var n,i=e.sidx.map?e.sidx.map:null,a=e.sidx.duration,o=e.timeline||0,u=e.sidx.byterange,s=u.offset+u.length,d=t.timescale,c=t.references.filter((function(e){return 1!==e.referenceType})),l=[],f=e.endList?"static":"dynamic";n="bigint"==typeof t.firstOffset?window.BigInt(s)+t.firstOffset:s+t.firstOffset;for(var m=0;m<c.length;m++){var p=t.references[m],g=p.referencedSize,h=p.subsegmentDuration,v=void 0;v="bigint"==typeof n?n+window.BigInt(g)-window.BigInt(1):n+g-1;var b=y({baseUrl:r,timescale:d,timeline:o,periodIndex:o,duration:h,sourceDuration:a,indexRange:n+"-"+v,type:f})[0];i&&(b.map=i),l.push(b),n+="bigint"==typeof n?window.BigInt(g):g}return e.segments=l,e},I=function(e){return e&&e.uri+"-"+(t=e.byterange,r="bigint"==typeof t.offset||"bigint"==typeof t.length?window.BigInt(t.offset)+window.BigInt(t.length)-window.BigInt(1):t.offset+t.length-1,t.offset+"-"+r);var t,r},U=function(e){var t;return(t=e.reduce((function(e,t){var r,n=t.attributes.id+(t.attributes.lang||"");return e[n]?(t.segments[0]&&(t.segments[0].discontinuity=!0),(r=e[n].segments).push.apply(r,t.segments),t.attributes.contentProtection&&(e[n].attributes.contentProtection=t.attributes.contentProtection)):e[n]=t,e}),{}),Object.keys(t).map((function(e){return t[e]}))).map((function(e){var t,r;return e.discontinuityStarts=(t=e.segments,r="discontinuity",t.reduce((function(e,t,n){return t[r]&&e.push(n),e}),[])),e}))},D=function(e,t){var r=I(e.sidx),n=r&&t[r]&&t[r].sidx;return n&&w(e,n,e.sidx.resolvedUri),e},E=function(e,t){if(void 0===t&&(t={}),!Object.keys(t).length)return e;for(var r in e)e[r]=D(e[r],t);return e},R=function(e){var t,r=e.attributes,n=e.segments,i=e.sidx,a={attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},t["PROGRAM-ID"]=1,t),uri:"",endList:"static"===r.type,timeline:r.periodIndex,resolvedUri:"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1};return r.contentProtection&&(a.contentProtection=r.contentProtection),i&&(a.sidx=i),a},T=function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video/webm"===t.mimeType||"video"===t.contentType},L=function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio/webm"===t.mimeType||"audio"===t.contentType},S=function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType},N=function(e,t,r){var n;if(void 0===r&&(r={}),!e.length)return{};var i=e[0].attributes,a=i.sourceDuration,o=i.type,u=i.suggestedPresentationDelay,s=i.minimumUpdatePeriod,d=U(e.filter(T)).map(R),c=U(e.filter(L)),l=e.filter(S),f=e.map((function(e){return e.attributes.captionServices})).filter(Boolean),m={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:E(d,r)};s>=0&&(m.minimumUpdatePeriod=1e3*s),t&&(m.locations=t),"dynamic"===o&&(m.suggestedPresentationDelay=u);var p=0===m.playlists.length;return c.length&&(m.mediaGroups.AUDIO.audio=function(e,t,r){var n;void 0===t&&(t={}),void 0===r&&(r=!1);var i=e.reduce((function(e,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}e[u]||(e[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var d=D(function(e,t){var r,n=e.attributes,i=e.segments,a=e.sidx,o={attributes:(r={NAME:n.id,BANDWIDTH:n.bandwidth,CODECS:n.codecs},r["PROGRAM-ID"]=1,r),uri:"",endList:"static"===n.type,timeline:n.periodIndex,resolvedUri:"",targetDuration:n.duration,segments:i,mediaSequence:i.length?i[0].number:1};return n.contentProtection&&(o.contentProtection=n.contentProtection),a&&(o.sidx=a),t&&(o.attributes.AUDIO="audio",o.attributes.SUBTITLES="subs"),o}(i,r),t);return e[u].playlists.push(d),void 0===n&&"main"===a&&((n=i).default=!0),e}),{});return n||(i[Object.keys(i)[0]].default=!0),i}(c,r,p)),l.length&&(m.mediaGroups.SUBTITLES.subs=function(e,t){return void 0===t&&(t={}),e.reduce((function(e,r){var n=r.attributes.lang||"text";return e[n]||(e[n]={language:n,default:!1,autoselect:!1,playlists:[],uri:""}),e[n].playlists.push(D(function(e){var t,r=e.attributes,n=e.segments;void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration,number:0}],r.duration=r.sourceDuration);var i=((t={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,t);return r.codecs&&(i.CODECS=r.codecs),{attributes:i,uri:"",endList:"static"===r.type,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1}}(r),t)),e}),{})}(l,r)),f.length&&(m.mediaGroups["CLOSED-CAPTIONS"].cc=f.reduce((function(e,t){return t?(t.forEach((function(t){var r=t.channel,n=t.language;e[n]={autoselect:!1,default:!1,instreamId:r,language:n},t.hasOwnProperty("aspectRatio")&&(e[n].aspectRatio=t.aspectRatio),t.hasOwnProperty("easyReader")&&(e[n].easyReader=t.easyReader),t.hasOwnProperty("3D")&&(e[n]["3D"]=t["3D"])})),e):e}),{})),m},x=function(e,t,r){var n=e.NOW,i=e.clientOffset,a=e.availabilityStartTime,o=e.timescale,u=void 0===o?1:o,s=e.start,d=void 0===s?0:s,c=e.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===c?0:c)-(a+d);return Math.ceil((l*u-t)/r)},P=function(e,t){for(var r=e.type,n=e.minimumUpdatePeriod,i=void 0===n?0:n,a=e.media,o=void 0===a?"":a,u=e.sourceDuration,s=e.timescale,d=void 0===s?1:s,c=e.startNumber,l=void 0===c?1:c,f=e.periodIndex,m=[],p=-1,g=0;g<t.length;g++){var h=t[g],v=h.d,b=h.r||0,y=h.t||0;p<0&&(p=y),y&&y>p&&(p=y);var w=void 0;if(b<0){var I=g+1;w=I===t.length?"dynamic"===r&&i>0&&o.indexOf("$Number$")>0?x(e,p,v):(u*d-p)/v:(t[I].t-p)/v}else w=b+1;for(var U=l+m.length+w,D=l+m.length;D<U;)m.push({number:D,duration:v/d,time:p,timeline:f}),p+=v,D++}return m},O=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,A=function(e,t){return e.replace(O,function(e){return function(t,r,n,i){if("$$"===t)return"$";if(void 0===e[r])return t;var a=""+e[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(t))},B=function(e,t){var r={RepresentationID:e.id,Bandwidth:e.bandwidth||0},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:e.baseUrl,source:A(i.sourceURL,r),range:i.range}),o=function(e,t){return e.duration||t?e.duration?b(e):P(e,t):[{number:e.startNumber||1,duration:e.sourceDuration,time:0,timeline:e.periodIndex}]}(e,t);return o.map((function(t){r.Number=t.number,r.Time=t.time;var n=A(e.media||"",r),i=e.timescale||1,o=e.presentationTimeOffset||0,u=e.periodStart+(t.time-o)/i;return{uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:p(e.baseUrl||"",n),map:a,number:t.number,presentationTime:u}}))},M=function(e,t){var r=e.duration,n=e.segmentUrls,i=void 0===n?[]:n,a=e.periodStart;if(!r&&!t||r&&t)throw new Error(c);var o,u=i.map((function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),o=g({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}));return r&&(o=b(e)),t&&(o=P(e,t)),o.map((function(t,r){if(u[r]){var n=u[r],i=e.timescale||1,o=e.presentationTimeOffset||0;return n.timeline=t.timeline,n.duration=t.duration,n.number=t.number,n.presentationTime=a+(t.time-o)/i,n}})).filter((function(e){return e}))},C=function(e){var t,r,i=e.attributes,a=e.segmentInfo;a.template?(r=B,t=n(i,a.template)):a.base?(r=y,t=n(i,a.base)):a.list&&(r=M,t=n(i,a.list));var o={attributes:i};if(!r)return o;var u=r(t,a.segmentTimeline);if(t.duration){var s=t,d=s.duration,c=s.timescale,l=void 0===c?1:c;t.duration=d/l}else u.length?t.duration=u.reduce((function(e,t){return Math.max(e,Math.ceil(t.duration))}),0):t.duration=0;return o.attributes=t,o.segments=u,a.base&&t.indexRange&&(o.sidx=u[0],o.segments=[]),o},z=function(e){return e.map(C)},_=function(e,t){return a(e.childNodes).filter((function(e){return e.tagName===t}))},F=function(e){return e.textContent.trim()},j=function(e){var t=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(e);if(!t)return 0;var r=t.slice(1),n=r[0],i=r[1],a=r[2],o=r[3],u=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)},q={mediaPresentationDuration:function(e){return j(e)},availabilityStartTime:function(e){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(t=e)&&(t+="Z"),Date.parse(t)/1e3;var t},minimumUpdatePeriod:function(e){return j(e)},suggestedPresentationDelay:function(e){return j(e)},type:function(e){return e},timeShiftBufferDepth:function(e){return j(e)},start:function(e){return j(e)},width:function(e){return parseInt(e,10)},height:function(e){return parseInt(e,10)},bandwidth:function(e){return parseInt(e,10)},startNumber:function(e){return parseInt(e,10)},timescale:function(e){return parseInt(e,10)},presentationTimeOffset:function(e){return parseInt(e,10)},duration:function(e){var t=parseInt(e,10);return isNaN(t)?j(e):t},d:function(e){return parseInt(e,10)},t:function(e){return parseInt(e,10)},r:function(e){return parseInt(e,10)},DEFAULT:function(e){return e}},G=function(e){return e&&e.attributes?a(e.attributes).reduce((function(e,t){var r=q[t.name]||q.DEFAULT;return e[t.name]=r(t.value),e}),{}):{}};function $(e){for(var t,r=(t=e,window.atob?window.atob(t):Buffer.from(t,"base64").toString("binary")),n=new Uint8Array(r.length),i=0;i<r.length;i++)n[i]=r.charCodeAt(i);return n}var k={"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"},H=function(e,t){return t.length?i(e.map((function(e){return t.map((function(t){return p(e,F(t))}))}))):e},W=function(e){var t=_(e,"SegmentTemplate")[0],r=_(e,"SegmentList")[0],i=r&&_(r,"SegmentURL").map((function(e){return n({tag:"SegmentURL"},G(e))})),a=_(e,"SegmentBase")[0],o=r||t,u=o&&_(o,"SegmentTimeline")[0],s=r||a||t,d=s&&_(s,"Initialization")[0],c=t&&G(t);c&&d?c.initialization=d&&G(d):c&&c.initialization&&(c.initialization={sourceURL:c.initialization});var l={template:c,segmentTimeline:u&&_(u,"S").map((function(e){return G(e)})),list:r&&n(G(r),{segmentUrls:i,initialization:G(d)}),base:a&&n(G(a),{initialization:G(d)})};return Object.keys(l).forEach((function(e){l[e]||delete l[e]})),l},V=function(e,t,r){return function(a){var o,u=G(a),s=H(t,_(a,"BaseURL")),d=_(a,"Role")[0],c={role:G(d)},l=n(e,u,c),f=_(a,"Accessibility")[0],m="urn:scte:dash:cc:cea-608:2015"===(o=G(f)).schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(e){var t,r;if(r=e,/^CC\d=/.test(e)){var n=e.split("=");t=n[0],r=n[1]}else/^CC\d$/.test(e)&&(t=e);return{channel:t,language:r}})):"urn:scte:dash:cc:cea-708:2015"===o.schemeIdUri?("string"!=typeof o.value?[]:o.value.split(";")).map((function(e){var t={channel:void 0,language:void 0,aspectRatio:1,easyReader:0,"3D":0};if(/=/.test(e)){var r=e.split("="),n=r[0],i=r[1],a=void 0===i?"":i;t.channel=n,t.language=e,a.split(",").forEach((function(e){var r=e.split(":"),n=r[0],i=r[1];"lang"===n?t.language=i:"er"===n?t.easyReader=Number(i):"war"===n?t.aspectRatio=Number(i):"3D"===n&&(t["3D"]=Number(i))}))}else t.language=e;return t.channel&&(t.channel="SERVICE"+t.channel),t})):void 0;m&&(l=n(l,{captionServices:m}));var p=_(a,"Label")[0];if(p&&p.childNodes.length){var g=p.childNodes[0].nodeValue.trim();l=n(l,{label:g})}var h=_(a,"ContentProtection").reduce((function(e,t){var r=G(t),n=k[r.schemeIdUri];if(n){e[n]={attributes:r};var i=_(t,"cenc:pssh")[0];if(i){var a=F(i),o=a&&$(a);e[n].pssh=o}}return e}),{});Object.keys(h).length&&(l=n(l,{contentProtection:h}));var v=W(a),b=_(a,"Representation"),y=n(r,v);return i(b.map(function(e,t,r){return function(i){var a=_(i,"BaseURL"),o=H(t,a),u=n(e,G(i)),s=W(i);return o.map((function(e){return{segmentInfo:n(r,s),attributes:n(u,{baseUrl:e})}}))}}(l,s,y)))}},X=function(e,t){return function(r,a){var o=H(t,_(r.node,"BaseURL")),u=parseInt(r.attributes.id,10),s=window.isNaN(u)?a:u,d=n(e,{periodIndex:s,periodStart:r.attributes.start});"number"==typeof r.attributes.duration&&(d.periodDuration=r.attributes.duration);var c=_(r.node,"AdaptationSet"),l=W(r.node);return i(c.map(V(d,o,l)))}},Y=function(e,t){void 0===t&&(t={});var r=t,n=r.manifestUri,a=void 0===n?"":n,u=r.NOW,s=void 0===u?Date.now():u,d=r.clientOffset,c=void 0===d?0:d,l=_(e,"Period");if(!l.length)throw new Error(o);var f=_(e,"Location"),m=G(e),p=H([a],_(e,"BaseURL"));m.type=m.type||"static",m.sourceDuration=m.mediaPresentationDuration||0,m.NOW=s,m.clientOffset=c,f.length&&(m.locations=f.map(F));var g=[];return l.forEach((function(e,t){var r=G(e),n=g[t-1];r.start=function(e){var t=e.attributes,r=e.priorPeriodAttributes,n=e.mpdType;return"number"==typeof t.start?t.start:r&&"number"==typeof r.start&&"number"==typeof r.duration?r.start+r.duration:r||"static"!==n?null:0}({attributes:r,priorPeriodAttributes:n?n.attributes:null,mpdType:m.type}),g.push({node:e,attributes:r})})),{locations:m.locations,representationInfo:i(g.map(X(m,p)))}},Z=function(e){if(""===e)throw new Error(u);var r,n,i=new t.DOMParser;try{n=(r=i.parseFromString(e,"application/xml"))&&"MPD"===r.documentElement.tagName?r.documentElement:null}catch(e){}if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(s);return n};e.VERSION="0.20.0",e.addSidxSegmentsToPlaylist=w,e.generateSidxKey=I,e.inheritAttributes=Y,e.parse=function(e,t){void 0===t&&(t={});var r=Y(Z(e),t),n=z(r.representationInfo);return N(n,r.locations,t.sidxMapping)},e.parseUTCTiming=function(e){return function(e){var t=_(e,"UTCTiming")[0];if(!t)return null;var r=G(t);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;default:throw new Error(l)}return r}(Z(e))},e.stringToMpdXml=Z,e.toM3u8=N,e.toPlaylists=z,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "mpd-parser", | ||
"version": "0.19.2", | ||
"version": "0.20.0", | ||
"description": "mpd parser", | ||
@@ -30,3 +30,2 @@ "main": "dist/mpd-parser.cjs.js", | ||
"posttest": "shx cat test/dist/coverage/text.txt", | ||
"preversion": "npm test", | ||
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md", | ||
@@ -76,3 +75,3 @@ "update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s", | ||
"videojs-generator-verify": "~3.0.2", | ||
"videojs-standard": "^8.0.4" | ||
"videojs-standard": "^9.0.1" | ||
}, | ||
@@ -79,0 +78,0 @@ "generator-videojs-plugin": { |
@@ -128,3 +128,3 @@ # mpd-parser | ||
var mpdParser = window['mpd-parser']; | ||
var parsedManifest = mpdParser.parse(manifest, manifestUrl); | ||
var parsedManifest = mpdParser.parse(manifest, { manifestUri }); | ||
</script> | ||
@@ -140,3 +140,3 @@ ``` | ||
var parsedManifest = mpdParser.parse(manifest, manifestUrl); | ||
var parsedManifest = mpdParser.parse(manifest, { manifestUri }); | ||
``` | ||
@@ -148,3 +148,3 @@ | ||
const parsedManifest = parse(manifest, manifestUrl); | ||
const parsedManifest = parse(manifest, { manifestUri }); | ||
``` | ||
@@ -158,3 +158,3 @@ | ||
require(['mpd-parser'], function(mpdParser) { | ||
var parsedManifest = mpdParser.parse(manifest, manifestUrl); | ||
var parsedManifest = mpdParser.parse(manifest, { manifestUri }); | ||
}); | ||
@@ -161,0 +161,0 @@ ``` |
@@ -321,3 +321,3 @@ import window from 'global/window'; | ||
adaptationSetAttributes, | ||
roleAttributes, | ||
roleAttributes | ||
); | ||
@@ -324,0 +324,0 @@ |
import errors from '../errors'; | ||
import urlTypeConverter from './urlType'; | ||
import { parseByDuration } from './durationTimeParser'; | ||
import window from 'global/window'; | ||
@@ -87,4 +88,11 @@ /** | ||
// firstOffset is the offset from the end of the sidx box | ||
let startIndex = sidxEnd + sidx.firstOffset; | ||
let startIndex; | ||
// eslint-disable-next-line | ||
if (typeof sidx.firstOffset === 'bigint') { | ||
startIndex = window.BigInt(sidxEnd) + sidx.firstOffset; | ||
} else { | ||
startIndex = sidxEnd + sidx.firstOffset; | ||
} | ||
for (let i = 0; i < mediaReferences.length; i++) { | ||
@@ -98,3 +106,10 @@ const reference = sidx.references[i]; | ||
// should be an inclusive range | ||
const endIndex = startIndex + size - 1; | ||
let endIndex; | ||
// eslint-disable-next-line | ||
if (typeof startIndex === 'bigint') { | ||
endIndex = startIndex + window.BigInt(size) - window.BigInt(1); | ||
} else { | ||
endIndex = startIndex + size - 1; | ||
} | ||
const indexRange = `${startIndex}-${endIndex}`; | ||
@@ -121,3 +136,7 @@ | ||
segments.push(segment); | ||
startIndex += size; | ||
if (typeof startIndex === 'bigint') { | ||
startIndex += window.BigInt(size); | ||
} else { | ||
startIndex += size; | ||
} | ||
} | ||
@@ -124,0 +143,0 @@ |
import resolveUrl from '@videojs/vhs-utils/es/resolve-url'; | ||
import window from 'global/window'; | ||
@@ -37,9 +38,32 @@ /** | ||
const ranges = rangeStr.split('-'); | ||
const startRange = parseInt(ranges[0], 10); | ||
const endRange = parseInt(ranges[1], 10); | ||
// default to parsing this as a BigInt if possible | ||
let startRange = window.BigInt ? window.BigInt(ranges[0]) : parseInt(ranges[0], 10); | ||
let endRange = window.BigInt ? window.BigInt(ranges[1]) : parseInt(ranges[1], 10); | ||
// convert back to a number if less than MAX_SAFE_INTEGER | ||
if (startRange < Number.MAX_SAFE_INTEGER && typeof startRange === 'bigint') { | ||
startRange = Number(startRange); | ||
} | ||
if (endRange < Number.MAX_SAFE_INTEGER && typeof endRange === 'bigint') { | ||
endRange = Number(endRange); | ||
} | ||
let length; | ||
if (typeof endRange === 'bigint' || typeof startRange === 'bigint') { | ||
length = window.BigInt(endRange) - window.BigInt(startRange) + window.BigInt(1); | ||
} else { | ||
length = endRange - startRange + 1; | ||
} | ||
if (typeof length === 'bigint' && length < Number.MAX_SAFE_INTEGER) { | ||
length = Number(length); | ||
} | ||
// byterange should be inclusive according to | ||
// RFC 2616, Clause 14.35.1 | ||
segment.byterange = { | ||
length: endRange - startRange + 1, | ||
length, | ||
offset: startRange | ||
@@ -55,4 +79,10 @@ }; | ||
// header uses inclusive ranges | ||
const endRange = byterange.offset + byterange.length - 1; | ||
let endRange; | ||
if (typeof byterange.offset === 'bigint' || typeof byterange.length === 'bigint') { | ||
endRange = window.BigInt(byterange.offset) + window.BigInt(byterange.length) - window.BigInt(1); | ||
} else { | ||
endRange = byterange.offset + byterange.length - 1; | ||
} | ||
return `${byterange.offset}-${endRange}`; | ||
@@ -59,0 +89,0 @@ }; |
@@ -7,2 +7,3 @@ import QUnit from 'qunit'; | ||
import errors from '../../src/errors'; | ||
import window from 'global/window'; | ||
@@ -210,1 +211,57 @@ QUnit.module('segmentBase - segmentsFromBase'); | ||
}); | ||
if (window.BigInt) { | ||
const BigInt = window.BigInt; | ||
QUnit.test('generates playlist from sidx references with BigInt', function(assert) { | ||
const baseUrl = 'http://www.example.com/i.fmp4'; | ||
const playlist = { | ||
sidx: { | ||
map: { | ||
byterange: { | ||
offset: 0, | ||
length: 10 | ||
} | ||
}, | ||
duration: 10, | ||
byterange: { | ||
offset: 9, | ||
length: 11 | ||
} | ||
}, | ||
segments: [] | ||
}; | ||
const offset = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(10); | ||
const sidx = { | ||
timescale: 1, | ||
firstOffset: offset, | ||
references: [{ | ||
referenceType: 0, | ||
referencedSize: 5, | ||
subsegmentDuration: 2 | ||
}] | ||
}; | ||
const segments = addSidxSegmentsToPlaylist(playlist, sidx, baseUrl).segments; | ||
assert.equal(typeof segments[0].byterange.offset, 'bigint', 'bigint offset'); | ||
segments[0].byterange.offset = segments[0].byterange.offset.toString(); | ||
assert.deepEqual(segments, [{ | ||
map: { | ||
byterange: { | ||
offset: 0, | ||
length: 10 | ||
} | ||
}, | ||
uri: 'http://www.example.com/i.fmp4', | ||
resolvedUri: 'http://www.example.com/i.fmp4', | ||
byterange: { | ||
// sidx byterange offset + length = 20 | ||
offset: (window.BigInt(20) + offset).toString(), | ||
length: 5 | ||
}, | ||
number: 0 | ||
}]); | ||
}); | ||
} |
@@ -6,2 +6,3 @@ import QUnit from 'qunit'; | ||
} from '../../src/segment/urlType'; | ||
import window from 'global/window'; | ||
@@ -85,2 +86,47 @@ QUnit.module('urlType - urlTypeConverter'); | ||
if (window.BigInt) { | ||
const BigInt = window.BigInt; | ||
QUnit.test('can use BigInt range', function(assert) { | ||
const bigNumber = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(10); | ||
const result = urlTypeConverter({ | ||
baseUrl: 'http://example.com', | ||
source: 'init.fmp4', | ||
range: `${bigNumber}-${bigNumber + BigInt(4)}` | ||
}); | ||
assert.equal(typeof result.byterange.offset, 'bigint', 'is bigint'); | ||
result.byterange.offset = result.byterange.offset.toString(); | ||
assert.deepEqual(result, { | ||
resolvedUri: 'http://example.com/init.fmp4', | ||
uri: 'init.fmp4', | ||
byterange: { | ||
offset: bigNumber.toString(), | ||
length: 5 | ||
} | ||
}); | ||
}); | ||
QUnit.test('returns number range if bigint not nedeed', function(assert) { | ||
const bigNumber = BigInt(5); | ||
const result = urlTypeConverter({ | ||
baseUrl: 'http://example.com', | ||
source: 'init.fmp4', | ||
range: `${bigNumber}-${bigNumber + BigInt(4)}` | ||
}); | ||
assert.deepEqual(result, { | ||
resolvedUri: 'http://example.com/init.fmp4', | ||
uri: 'init.fmp4', | ||
byterange: { | ||
offset: 5, | ||
length: 5 | ||
} | ||
}); | ||
}); | ||
} | ||
QUnit.module('urlType - byteRangeToString'); | ||
@@ -97,1 +143,18 @@ | ||
}); | ||
if (window.BigInt) { | ||
const BigInt = window.BigInt; | ||
QUnit.test('can handle bigint numbers', function(assert) { | ||
const offset = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(10); | ||
const length = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(5); | ||
assert.strictEqual( | ||
byteRangeToString({ | ||
offset, | ||
length | ||
}), | ||
`${offset}-${offset + length - BigInt(1)}` | ||
); | ||
}); | ||
} |
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
724018
19137