mpd-parser
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -0,1 +1,8 @@ | ||
<a name="0.10.0"></a> | ||
# [0.10.0](https://github.com/videojs/mpd-parser/compare/v0.9.0...v0.10.0) (2020-02-04) | ||
### Features | ||
* expose suggestPresentationDelay if the type is dynamic ([#82](https://github.com/videojs/mpd-parser/issues/82)) ([cd27003](https://github.com/videojs/mpd-parser/commit/cd27003)) | ||
<a name="0.9.0"></a> | ||
@@ -2,0 +9,0 @@ # [0.9.0](https://github.com/videojs/mpd-parser/compare/v0.8.2...v0.9.0) (2019-08-30) |
@@ -1,2 +0,2 @@ | ||
/*! @name mpd-parser @version 0.9.0 @license Apache-2.0 */ | ||
/*! @name mpd-parser @version 0.10.0 @license Apache-2.0 */ | ||
'use strict'; | ||
@@ -13,3 +13,3 @@ | ||
var version = "0.9.0"; | ||
var version = "0.10.0"; | ||
@@ -649,4 +649,7 @@ var isObject = function isObject(obj) { | ||
duration = _dashPlaylists$0$attr.sourceDuration, | ||
_dashPlaylists$0$attr2 = _dashPlaylists$0$attr.minimumUpdatePeriod, | ||
minimumUpdatePeriod = _dashPlaylists$0$attr2 === void 0 ? 0 : _dashPlaylists$0$attr2; | ||
_dashPlaylists$0$attr2 = _dashPlaylists$0$attr.type, | ||
type = _dashPlaylists$0$attr2 === void 0 ? 'static' : _dashPlaylists$0$attr2, | ||
suggestedPresentationDelay = _dashPlaylists$0$attr.suggestedPresentationDelay, | ||
_dashPlaylists$0$attr3 = _dashPlaylists$0$attr.minimumUpdatePeriod, | ||
minimumUpdatePeriod = _dashPlaylists$0$attr3 === void 0 ? 0 : _dashPlaylists$0$attr3; | ||
@@ -686,2 +689,6 @@ var videoOnly = function videoOnly(_ref4) { | ||
if (type === 'dynamic') { | ||
master.suggestedPresentationDelay = suggestedPresentationDelay; | ||
} | ||
if (audioPlaylists.length) { | ||
@@ -1232,2 +1239,28 @@ master.mediaGroups.AUDIO.audio = organizeAudioPlaylists(audioPlaylists, sidxMapping); | ||
/** | ||
* Specifies the suggested presentation delay. Format is a | ||
* duration string as specified in ISO 8601 | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* @return {number} | ||
* The duration in seconds | ||
*/ | ||
suggestedPresentationDelay: function suggestedPresentationDelay(value) { | ||
return parseDuration(value); | ||
}, | ||
/** | ||
* specifices the type of mpd. Can be either "static" or "dynamic" | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* | ||
* @return {string} | ||
* The type as a string | ||
*/ | ||
type: function type(value) { | ||
return value; | ||
}, | ||
/** | ||
* Specifies the duration of the smallest time shifting buffer for any Representation | ||
@@ -1234,0 +1267,0 @@ * in the MPD. Format is a duration string as specified in ISO 8601 |
@@ -1,2 +0,2 @@ | ||
/*! @name mpd-parser @version 0.9.0 @license Apache-2.0 */ | ||
/*! @name mpd-parser @version 0.10.0 @license Apache-2.0 */ | ||
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url'; | ||
@@ -7,3 +7,3 @@ import window from 'global/window'; | ||
var version = "0.9.0"; | ||
var version = "0.10.0"; | ||
@@ -643,4 +643,7 @@ var isObject = function isObject(obj) { | ||
duration = _dashPlaylists$0$attr.sourceDuration, | ||
_dashPlaylists$0$attr2 = _dashPlaylists$0$attr.minimumUpdatePeriod, | ||
minimumUpdatePeriod = _dashPlaylists$0$attr2 === void 0 ? 0 : _dashPlaylists$0$attr2; | ||
_dashPlaylists$0$attr2 = _dashPlaylists$0$attr.type, | ||
type = _dashPlaylists$0$attr2 === void 0 ? 'static' : _dashPlaylists$0$attr2, | ||
suggestedPresentationDelay = _dashPlaylists$0$attr.suggestedPresentationDelay, | ||
_dashPlaylists$0$attr3 = _dashPlaylists$0$attr.minimumUpdatePeriod, | ||
minimumUpdatePeriod = _dashPlaylists$0$attr3 === void 0 ? 0 : _dashPlaylists$0$attr3; | ||
@@ -680,2 +683,6 @@ var videoOnly = function videoOnly(_ref4) { | ||
if (type === 'dynamic') { | ||
master.suggestedPresentationDelay = suggestedPresentationDelay; | ||
} | ||
if (audioPlaylists.length) { | ||
@@ -1226,2 +1233,28 @@ master.mediaGroups.AUDIO.audio = organizeAudioPlaylists(audioPlaylists, sidxMapping); | ||
/** | ||
* Specifies the suggested presentation delay. Format is a | ||
* duration string as specified in ISO 8601 | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* @return {number} | ||
* The duration in seconds | ||
*/ | ||
suggestedPresentationDelay: function suggestedPresentationDelay(value) { | ||
return parseDuration(value); | ||
}, | ||
/** | ||
* specifices the type of mpd. Can be either "static" or "dynamic" | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* | ||
* @return {string} | ||
* The type as a string | ||
*/ | ||
type: function type(value) { | ||
return value; | ||
}, | ||
/** | ||
* Specifies the duration of the smallest time shifting buffer for any Representation | ||
@@ -1228,0 +1261,0 @@ * in the MPD. Format is a duration string as specified in ISO 8601 |
@@ -1,2 +0,2 @@ | ||
/*! @name mpd-parser @version 0.9.0 @license Apache-2.0 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],e):e((t=t||self).mpdParser={},t.window,t.window)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t){return!!t&&"object"==typeof t},i=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce(function(e,r){return 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},{})},a=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},u=function(t){if(!t.length)return[];for(var e=[],r=0;r<t.length;r++)e.push(t[r]);return e},o="INVALID_NUMBER_OF_PERIOD",s="DASH_EMPTY_MANIFEST",d="DASH_INVALID_XML",c="NO_BASE_URL",l="SEGMENT_TIME_UNSPECIFIED",m="UNSUPPORTED_UTC_TIMING_SCHEME";function f(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var p=f(function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){!function(e){var r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,u={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var i=u.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=u.normalizePath(i.path),u.buildURLFromParts(i)}var a=u.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=u.normalizePath(a.path),u.buildURLFromParts(a)):e;var o=u.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var s=n.exec(o.path);o.netLoc=s[1],o.path=s[2]}o.netLoc&&!o.path&&(o.path="/");var d={scheme:o.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(d.netLoc=o.netLoc,"/"!==a.path[0]))if(a.path){var c=o.path,l=c.substring(0,c.lastIndexOf("/")+1)+a.path;d.path=u.normalizePath(l)}else d.path=o.path,a.params||(d.params=o.params,a.query||(d.query=o.query));return null===d.path&&(d.path=r.alwaysNormalize?u.normalizePath(a.path):a.path),u.buildURLFromParts(d)},parseURL:function(t){var e=r.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=u}()})),v=f(e),h=function(t,e){return/^[a-z]+:/i.test(e)?e:(/\/\//i.test(t)||(t=p.buildAbsoluteURL(v.location&&v.location.href||"",t)),p.buildAbsoluteURL(t,e))},g=function(t){var e=t.baseUrl,r=void 0===e?"":e,n=t.source,i=void 0===n?"":n,a=t.range,u=void 0===a?"":a,o=t.indexRange,s=void 0===o?"":o,d={uri:i,resolvedUri:h(r||"",i)};if(u||s){var c=(u||s).split("-"),l=parseInt(c[0],10),m=parseInt(c[1],10);d.byterange={length:m-l+1,offset:l}}return d},b={static:function(t){var e=t.duration,r=t.timescale,n=void 0===r?1:r,i=t.sourceDuration;return{start:0,end:Math.ceil(i/(e/n))}},dynamic:function(t){var e=t.NOW,r=t.clientOffset,n=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,u=t.duration,o=t.start,s=void 0===o?0:o,d=t.minimumUpdatePeriod,c=void 0===d?0:d,l=t.timeShiftBufferDepth,m=void 0===l?1/0:l,f=(e+r)/1e3,p=n+s,v=f+c-p,h=Math.ceil(v*a/u),g=Math.floor((f-p-m)*a/u),b=Math.floor((f-p)*a/u);return{start:Math.max(0,g),end:Math.min(h,b)}}},U=function(t){var e=t.type,r=void 0===e?"static":e,n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.sourceDuration,o=b[r](t),s=function(t,e){for(var r=[],n=t;n<e;n++)r.push(n);return r}(o.start,o.end).map(function(t){return function(e,r){var n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.periodIndex,o=t.startNumber;return{number:(void 0===o?1:o)+e,duration:n/a,timeline:u,time:r*n}}}(t));if("static"===r){var d=s.length-1;s[d].duration=u-n/a*d}return s},y=function(t){var e=t.baseUrl,r=t.initialization,n=void 0===r?{}:r,i=t.sourceDuration,a=t.timescale,u=void 0===a?1:a,o=t.indexRange,s=void 0===o?"":o,d=t.duration;if(!e)throw new Error(c);var l=g({baseUrl:e,source:n.sourceURL,range:n.range}),m=g({baseUrl:e,source:e,indexRange:s});if(m.map=l,d){var f=U(t);f.length&&(m.duration=f[0].duration,m.timeline=f[0].timeline)}else i&&(m.duration=i/u,m.timeline=0);return m.number=0,[m]},I=function(t,e,r){for(var n=t.sidx.map?t.sidx.map:null,i=t.sidx.duration,a=t.timeline||0,u=t.sidx.byterange,o=u.offset+u.length,s=e.timescale,d=e.references.filter(function(t){return 1!==t.referenceType}),c=[],l=o+e.firstOffset,m=0;m<d.length;m++){var f=e.references[m],p=f.referencedSize,v=f.subsegmentDuration,h=y({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:v,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(h.map=n),c.push(h),l+=p}return t.segments=c,t},D=function(t){var e;return(e=t.reduce(function(t,e){var r,n=e.attributes.id+(e.attributes.lang||"");return t[n]?(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)):t[n]=e,t},{}),Object.keys(e).map(function(t){return e[t]})).map(function(t){var e,r;return t.discontinuityStarts=(e=t.segments,r="discontinuity",e.reduce(function(t,e,n){return e[r]&&t.push(n),t},[])),t})},x=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var r in t){var n=t[r];if(n.sidx){var i=n.sidx.uri+"-"+(u=n.sidx.byterange,o=void 0,o=u.offset+u.length-1,u.offset+"-"+o),a=e[i]&&e[i].sidx;n.sidx&&a&&I(n,a,n.sidx.resolvedUri)}}var u,o;return t},L=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===(r.type||"static"),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},w=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===(r.type||"static"),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},R=function(t,e){var r;if(void 0===e&&(e={}),!t.length)return{};var n=t[0].attributes,i=n.sourceDuration,a=n.minimumUpdatePeriod,u=void 0===a?0:a,o=D(t.filter(function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video"===e.contentType})).map(w),s=D(t.filter(function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio"===e.contentType})),d=t.filter(function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType}),c={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(r={AUDIO:{},VIDEO:{}},r["CLOSED-CAPTIONS"]={},r.SUBTITLES={},r),uri:"",duration:i,playlists:x(o,e),minimumUpdatePeriod:1e3*u};return s.length&&(c.mediaGroups.AUDIO.audio=function(t,e){var r;void 0===e&&(e={});var n=t.reduce(function(t,n){var i=n.attributes.role&&n.attributes.role.value||"",a=n.attributes.lang||"",u="main";if(a){var o=i?" ("+i+")":"";u=""+n.attributes.lang+o}return t[u]&&t[u].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth?t:(t[u]={language:a,autoselect:!0,default:"main"===i,playlists:x([L(n)],e),uri:""},void 0===r&&"main"===i&&((r=n).default=!0),t)},{});r||(n[Object.keys(n)[0]].default=!0);return n}(s,e)),d.length&&(c.mediaGroups.SUBTITLES.subs=function(t,e){return void 0===e&&(e={}),t.reduce(function(t,r){var n,i,a,u,o=r.attributes.lang||"text";return t[o]?t:(t[o]={language:o,default:!1,autoselect:!1,playlists:x([(n=r,a=n.attributes,u=n.segments,void 0===u&&(u=[{uri:a.baseUrl,timeline:a.periodIndex,resolvedUri:a.baseUrl||"",duration:a.sourceDuration,number:0}],a.duration=a.sourceDuration),{attributes:(i={NAME:a.id,BANDWIDTH:a.bandwidth},i["PROGRAM-ID"]=1,i),uri:"",endList:"static"===(a.type||"static"),timeline:a.periodIndex,resolvedUri:a.baseUrl||"",targetDuration:a.duration,segments:u,mediaSequence:u.length?u[0].number:1})],e),uri:""},t)},{})}(d,e)),c},E=function(t,e,r){var n=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,u=t.timescale,o=void 0===u?1:u,s=t.start,d=void 0===s?0:s,c=t.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===c?0:c)-(a+d);return Math.ceil((l*o-e)/r)},P=function(t,e){for(var r=t.type,n=void 0===r?"static":r,i=t.minimumUpdatePeriod,a=void 0===i?0:i,u=t.media,o=void 0===u?"":u,s=t.sourceDuration,d=t.timescale,c=void 0===d?1:d,l=t.startNumber,m=void 0===l?1:l,f=t.periodIndex,p=[],v=-1,h=0;h<e.length;h++){var g=e[h],b=g.d,U=g.r||0,y=g.t||0;v<0&&(v=y),y&&y>v&&(v=y);var I=void 0;if(U<0){var D=h+1;I=D===e.length?"dynamic"===n&&a>0&&o.indexOf("$Number$")>0?E(t,v,b):(s*c-v)/b:(e[D].t-v)/b}else I=U+1;for(var x=m+p.length+I,L=m+p.length;L<x;)p.push({number:L,duration:b/c,time:v,timeline:f}),v+=b,L++}return p},T=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,S=function(t,e){return t.replace(T,function(t){return function(e,r,n,i){if("$$"===e)return"$";if(void 0===t[r])return e;var a=""+t[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},N=function(t,e){var r={RepresentationID:t.id,Bandwidth:t.bandwidth||0},n=t.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:t.baseUrl,source:S(i.sourceURL,r),range:i.range});return function(t,e){return t.duration||e?t.duration?U(t):P(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodIndex}]}(t,e).map(function(e){r.Number=e.number,r.Time=e.time;var n=S(t.media||"",r);return{uri:n,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",n),map:a,number:e.number}})},A=function(t,e){var r=t.duration,n=t.segmentUrls,i=void 0===n?[]:n;if(!r&&!e||r&&e)throw new Error(l);var a,u=i.map(function(e){return function(t,e){var r=t.baseUrl,n=t.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),u=g({baseUrl:r,source:e.media,range:e.mediaRange});return u.map=a,u}(t,e)});return r&&(a=U(t)),e&&(a=P(t,e)),a.map(function(t,e){if(u[e]){var r=u[e];return r.timeline=t.timeline,r.duration=t.duration,r.number=t.number,r}}).filter(function(t){return t})},O=function(t){var e,r,n=t.attributes,a=t.segmentInfo;a.template?(r=N,e=i(n,a.template)):a.base?(r=y,e=i(n,a.base)):a.list&&(r=A,e=i(n,a.list));var u={attributes:n};if(!r)return u;var o=r(e,a.timeline);if(e.duration){var s=e,d=s.duration,c=s.timescale,l=void 0===c?1:c;e.duration=d/l}else o.length?e.duration=o.reduce(function(t,e){return Math.max(t,Math.ceil(e.duration))},0):e.duration=0;return u.attributes=e,u.segments=o,a.base&&e.indexRange&&(u.sidx=o[0],u.segments=[]),u},M=function(t){return t.map(O)},z=function(t,e){return u(t.childNodes).filter(function(t){return t.tagName===e})},B=function(t){return t.textContent.trim()},C=function(t){var e=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(t);if(!e)return 0;var r=e.slice(1),n=r[0],i=r[1],a=r[2],u=r[3],o=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(u||0)+60*parseFloat(o||0)+parseFloat(s||0)},F={mediaPresentationDuration:function(t){return C(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 C(t)},timeShiftBufferDepth:function(t){return C(t)},start:function(t){return C(t)},width:function(t){return parseInt(t,10)},height:function(t){return parseInt(t,10)},bandwidth:function(t){return parseInt(t,10)},startNumber:function(t){return parseInt(t,10)},timescale:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?C(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}},_=function(t){return t&&t.attributes?u(t.attributes).reduce(function(t,e){var r=F[e.name]||F.DEFAULT;return t[e.name]=r(e.value),t},{}):{}};var j,q=(j=e)&&"object"==typeof j&&"default"in j?j.default:j,k=function(t){return q.atob?q.atob(t):Buffer.from(t,"base64").toString("binary")};var $=function(t){for(var e=k(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r},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(t,e){return e.length?a(t.map(function(t){return e.map(function(e){return h(t,B(e))})})):t},W=function(t){var e=z(t,"SegmentTemplate")[0],r=z(t,"SegmentList")[0],n=r&&z(r,"SegmentURL").map(function(t){return i({tag:"SegmentURL"},_(t))}),a=z(t,"SegmentBase")[0],u=r||e,o=u&&z(u,"SegmentTimeline")[0],s=r||a||e,d=s&&z(s,"Initialization")[0],c=e&&_(e);c&&d?c.initialization=d&&_(d):c&&c.initialization&&(c.initialization={sourceURL:c.initialization});var l={template:c,timeline:o&&z(o,"S").map(function(t){return _(t)}),list:r&&i(_(r),{segmentUrls:n,initialization:_(d)}),base:a&&i(_(a),{initialization:_(d)})};return Object.keys(l).forEach(function(t){l[t]||delete l[t]}),l},V=function(t,e,r){return function(n){var u=_(n),o=H(e,z(n,"BaseURL")),s=z(n,"Role")[0],d={role:_(s)},c=i(t,u,d),l=z(n,"ContentProtection").reduce(function(t,e){var r=_(e),n=G[r.schemeIdUri];if(n){t[n]={attributes:r};var i=z(e,"cenc:pssh")[0];if(i){var a=B(i),u=a&&$(a);t[n].pssh=u}}return t},{});Object.keys(l).length&&(c=i(c,{contentProtection:l}));var m=W(n),f=z(n,"Representation"),p=i(r,m);return a(f.map(function(t,e,r){return function(n){var a=z(n,"BaseURL"),u=H(e,a),o=i(t,_(n)),s=W(n);return u.map(function(t){return{segmentInfo:i(r,s),attributes:i(o,{baseUrl:t})}})}}(c,o,p)))}},X=function(t,r){void 0===r&&(r={});var n=r,u=n.manifestUri,s=void 0===u?"":u,d=n.NOW,c=void 0===d?Date.now():d,l=n.clientOffset,m=void 0===l?0:l,f=z(t,"Period");if(!f.length)throw new Error(o);var p=_(t),v=H([s],z(t,"BaseURL"));return p.sourceDuration=p.mediaPresentationDuration||0,p.NOW=c,p.clientOffset=m,a(f.map(function(t,r){return function(n,u){var o=H(r,z(n,"BaseURL")),s=_(n),d=parseInt(s.id,10),c=e.isNaN(d)?u:d,l=i(t,{periodIndex:c}),m=z(n,"AdaptationSet"),f=W(n);return a(m.map(V(l,o,f)))}}(p,v)))},Y=function(t){if(""===t)throw new Error(s);var e=(new r.DOMParser).parseFromString(t,"application/xml"),n=e&&"MPD"===e.documentElement.tagName?e.documentElement:null;if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(d);return n};t.VERSION="0.9.0",t.inheritAttributes=X,t.parse=function(t,e){return void 0===e&&(e={}),R(M(X(Y(t),e)),e.sidxMapping)},t.parseUTCTiming=function(t){return function(t){var e=z(t,"UTCTiming")[0];if(!e)return null;var r=_(e);switch(r.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":r.method="HEAD";break;case"urn:mpeg:dash:utc:http-xsdate:2014":case"urn:mpeg:dash:utc:http-iso:2014":case"urn:mpeg:dash:utc:http-xsdate:2012":case"urn:mpeg:dash:utc:http-iso:2012":r.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":r.method="DIRECT",r.value=Date.parse(r.value);break;case"urn:mpeg:dash:utc:http-ntp:2014":case"urn:mpeg:dash:utc:ntp:2014":case"urn:mpeg:dash:utc:sntp:2014":default:throw new Error(m)}return r}(Y(t))},t.stringToMpdXml=Y,t.toM3u8=R,t.toPlaylists=M,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
/*! @name mpd-parser @version 0.10.0 @license Apache-2.0 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],e):e((t=t||self).mpdParser={},t.window,t.window)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t){return!!t&&"object"==typeof t},i=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce(function(e,r){return 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},{})},a=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},u=function(t){if(!t.length)return[];for(var e=[],r=0;r<t.length;r++)e.push(t[r]);return e},o="INVALID_NUMBER_OF_PERIOD",s="DASH_EMPTY_MANIFEST",d="DASH_INVALID_XML",c="NO_BASE_URL",l="SEGMENT_TIME_UNSPECIFIED",m="UNSUPPORTED_UTC_TIMING_SCHEME";function f(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var p=f(function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){!function(e){var r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,u={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var i=u.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=u.normalizePath(i.path),u.buildURLFromParts(i)}var a=u.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=u.normalizePath(a.path),u.buildURLFromParts(a)):e;var o=u.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var s=n.exec(o.path);o.netLoc=s[1],o.path=s[2]}o.netLoc&&!o.path&&(o.path="/");var d={scheme:o.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(d.netLoc=o.netLoc,"/"!==a.path[0]))if(a.path){var c=o.path,l=c.substring(0,c.lastIndexOf("/")+1)+a.path;d.path=u.normalizePath(l)}else d.path=o.path,a.params||(d.params=o.params,a.query||(d.query=o.query));return null===d.path&&(d.path=r.alwaysNormalize?u.normalizePath(a.path):a.path),u.buildURLFromParts(d)},parseURL:function(t){var e=r.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=u}()})),v=f(e),h=function(t,e){return/^[a-z]+:/i.test(e)?e:(/\/\//i.test(t)||(t=p.buildAbsoluteURL(v.location&&v.location.href||"",t)),p.buildAbsoluteURL(t,e))},g=function(t){var e=t.baseUrl,r=void 0===e?"":e,n=t.source,i=void 0===n?"":n,a=t.range,u=void 0===a?"":a,o=t.indexRange,s=void 0===o?"":o,d={uri:i,resolvedUri:h(r||"",i)};if(u||s){var c=(u||s).split("-"),l=parseInt(c[0],10),m=parseInt(c[1],10);d.byterange={length:m-l+1,offset:l}}return d},b={static:function(t){var e=t.duration,r=t.timescale,n=void 0===r?1:r,i=t.sourceDuration;return{start:0,end:Math.ceil(i/(e/n))}},dynamic:function(t){var e=t.NOW,r=t.clientOffset,n=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,u=t.duration,o=t.start,s=void 0===o?0:o,d=t.minimumUpdatePeriod,c=void 0===d?0:d,l=t.timeShiftBufferDepth,m=void 0===l?1/0:l,f=(e+r)/1e3,p=n+s,v=f+c-p,h=Math.ceil(v*a/u),g=Math.floor((f-p-m)*a/u),b=Math.floor((f-p)*a/u);return{start:Math.max(0,g),end:Math.min(h,b)}}},U=function(t){var e=t.type,r=void 0===e?"static":e,n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.sourceDuration,o=b[r](t),s=function(t,e){for(var r=[],n=t;n<e;n++)r.push(n);return r}(o.start,o.end).map(function(t){return function(e,r){var n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.periodIndex,o=t.startNumber;return{number:(void 0===o?1:o)+e,duration:n/a,timeline:u,time:r*n}}}(t));if("static"===r){var d=s.length-1;s[d].duration=u-n/a*d}return s},y=function(t){var e=t.baseUrl,r=t.initialization,n=void 0===r?{}:r,i=t.sourceDuration,a=t.timescale,u=void 0===a?1:a,o=t.indexRange,s=void 0===o?"":o,d=t.duration;if(!e)throw new Error(c);var l=g({baseUrl:e,source:n.sourceURL,range:n.range}),m=g({baseUrl:e,source:e,indexRange:s});if(m.map=l,d){var f=U(t);f.length&&(m.duration=f[0].duration,m.timeline=f[0].timeline)}else i&&(m.duration=i/u,m.timeline=0);return m.number=0,[m]},I=function(t,e,r){for(var n=t.sidx.map?t.sidx.map:null,i=t.sidx.duration,a=t.timeline||0,u=t.sidx.byterange,o=u.offset+u.length,s=e.timescale,d=e.references.filter(function(t){return 1!==t.referenceType}),c=[],l=o+e.firstOffset,m=0;m<d.length;m++){var f=e.references[m],p=f.referencedSize,v=f.subsegmentDuration,h=y({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:v,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(h.map=n),c.push(h),l+=p}return t.segments=c,t},D=function(t){var e;return(e=t.reduce(function(t,e){var r,n=e.attributes.id+(e.attributes.lang||"");return t[n]?(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)):t[n]=e,t},{}),Object.keys(e).map(function(t){return e[t]})).map(function(t){var e,r;return t.discontinuityStarts=(e=t.segments,r="discontinuity",e.reduce(function(t,e,n){return e[r]&&t.push(n),t},[])),t})},x=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var r in t){var n=t[r];if(n.sidx){var i=n.sidx.uri+"-"+(u=n.sidx.byterange,o=void 0,o=u.offset+u.length-1,u.offset+"-"+o),a=e[i]&&e[i].sidx;n.sidx&&a&&I(n,a,n.sidx.resolvedUri)}}var u,o;return t},L=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===(r.type||"static"),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},w=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},e["PROGRAM-ID"]=1,e),uri:"",endList:"static"===(r.type||"static"),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},P=function(t,e){var r;if(void 0===e&&(e={}),!t.length)return{};var n=t[0].attributes,i=n.sourceDuration,a=n.type,u=void 0===a?"static":a,o=n.suggestedPresentationDelay,s=n.minimumUpdatePeriod,d=void 0===s?0:s,c=D(t.filter(function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video"===e.contentType})).map(w),l=D(t.filter(function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio"===e.contentType})),m=t.filter(function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType}),f={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(r={AUDIO:{},VIDEO:{}},r["CLOSED-CAPTIONS"]={},r.SUBTITLES={},r),uri:"",duration:i,playlists:x(c,e),minimumUpdatePeriod:1e3*d};return"dynamic"===u&&(f.suggestedPresentationDelay=o),l.length&&(f.mediaGroups.AUDIO.audio=function(t,e){var r;void 0===e&&(e={});var n=t.reduce(function(t,n){var i=n.attributes.role&&n.attributes.role.value||"",a=n.attributes.lang||"",u="main";if(a){var o=i?" ("+i+")":"";u=""+n.attributes.lang+o}return t[u]&&t[u].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth?t:(t[u]={language:a,autoselect:!0,default:"main"===i,playlists:x([L(n)],e),uri:""},void 0===r&&"main"===i&&((r=n).default=!0),t)},{});r||(n[Object.keys(n)[0]].default=!0);return n}(l,e)),m.length&&(f.mediaGroups.SUBTITLES.subs=function(t,e){return void 0===e&&(e={}),t.reduce(function(t,r){var n,i,a,u,o=r.attributes.lang||"text";return t[o]?t:(t[o]={language:o,default:!1,autoselect:!1,playlists:x([(n=r,a=n.attributes,u=n.segments,void 0===u&&(u=[{uri:a.baseUrl,timeline:a.periodIndex,resolvedUri:a.baseUrl||"",duration:a.sourceDuration,number:0}],a.duration=a.sourceDuration),{attributes:(i={NAME:a.id,BANDWIDTH:a.bandwidth},i["PROGRAM-ID"]=1,i),uri:"",endList:"static"===(a.type||"static"),timeline:a.periodIndex,resolvedUri:a.baseUrl||"",targetDuration:a.duration,segments:u,mediaSequence:u.length?u[0].number:1})],e),uri:""},t)},{})}(m,e)),f},R=function(t,e,r){var n=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,u=t.timescale,o=void 0===u?1:u,s=t.start,d=void 0===s?0:s,c=t.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===c?0:c)-(a+d);return Math.ceil((l*o-e)/r)},E=function(t,e){for(var r=t.type,n=void 0===r?"static":r,i=t.minimumUpdatePeriod,a=void 0===i?0:i,u=t.media,o=void 0===u?"":u,s=t.sourceDuration,d=t.timescale,c=void 0===d?1:d,l=t.startNumber,m=void 0===l?1:l,f=t.periodIndex,p=[],v=-1,h=0;h<e.length;h++){var g=e[h],b=g.d,U=g.r||0,y=g.t||0;v<0&&(v=y),y&&y>v&&(v=y);var I=void 0;if(U<0){var D=h+1;I=D===e.length?"dynamic"===n&&a>0&&o.indexOf("$Number$")>0?R(t,v,b):(s*c-v)/b:(e[D].t-v)/b}else I=U+1;for(var x=m+p.length+I,L=m+p.length;L<x;)p.push({number:L,duration:b/c,time:v,timeline:f}),v+=b,L++}return p},T=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,S=function(t,e){return t.replace(T,function(t){return function(e,r,n,i){if("$$"===e)return"$";if(void 0===t[r])return e;var a=""+t[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},N=function(t,e){var r={RepresentationID:t.id,Bandwidth:t.bandwidth||0},n=t.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:t.baseUrl,source:S(i.sourceURL,r),range:i.range});return function(t,e){return t.duration||e?t.duration?U(t):E(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodIndex}]}(t,e).map(function(e){r.Number=e.number,r.Time=e.time;var n=S(t.media||"",r);return{uri:n,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",n),map:a,number:e.number}})},A=function(t,e){var r=t.duration,n=t.segmentUrls,i=void 0===n?[]:n;if(!r&&!e||r&&e)throw new Error(l);var a,u=i.map(function(e){return function(t,e){var r=t.baseUrl,n=t.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),u=g({baseUrl:r,source:e.media,range:e.mediaRange});return u.map=a,u}(t,e)});return r&&(a=U(t)),e&&(a=E(t,e)),a.map(function(t,e){if(u[e]){var r=u[e];return r.timeline=t.timeline,r.duration=t.duration,r.number=t.number,r}}).filter(function(t){return t})},O=function(t){var e,r,n=t.attributes,a=t.segmentInfo;a.template?(r=N,e=i(n,a.template)):a.base?(r=y,e=i(n,a.base)):a.list&&(r=A,e=i(n,a.list));var u={attributes:n};if(!r)return u;var o=r(e,a.timeline);if(e.duration){var s=e,d=s.duration,c=s.timescale,l=void 0===c?1:c;e.duration=d/l}else o.length?e.duration=o.reduce(function(t,e){return Math.max(t,Math.ceil(e.duration))},0):e.duration=0;return u.attributes=e,u.segments=o,a.base&&e.indexRange&&(u.sidx=o[0],u.segments=[]),u},M=function(t){return t.map(O)},z=function(t,e){return u(t.childNodes).filter(function(t){return t.tagName===e})},B=function(t){return t.textContent.trim()},C=function(t){var e=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(t);if(!e)return 0;var r=e.slice(1),n=r[0],i=r[1],a=r[2],u=r[3],o=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(u||0)+60*parseFloat(o||0)+parseFloat(s||0)},F={mediaPresentationDuration:function(t){return C(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 C(t)},suggestedPresentationDelay:function(t){return C(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return C(t)},start:function(t){return C(t)},width:function(t){return parseInt(t,10)},height:function(t){return parseInt(t,10)},bandwidth:function(t){return parseInt(t,10)},startNumber:function(t){return parseInt(t,10)},timescale:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?C(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}},_=function(t){return t&&t.attributes?u(t.attributes).reduce(function(t,e){var r=F[e.name]||F.DEFAULT;return t[e.name]=r(e.value),t},{}):{}};var j,q=(j=e)&&"object"==typeof j&&"default"in j?j.default:j,k=function(t){return q.atob?q.atob(t):Buffer.from(t,"base64").toString("binary")};var $=function(t){for(var e=k(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r},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(t,e){return e.length?a(t.map(function(t){return e.map(function(e){return h(t,B(e))})})):t},W=function(t){var e=z(t,"SegmentTemplate")[0],r=z(t,"SegmentList")[0],n=r&&z(r,"SegmentURL").map(function(t){return i({tag:"SegmentURL"},_(t))}),a=z(t,"SegmentBase")[0],u=r||e,o=u&&z(u,"SegmentTimeline")[0],s=r||a||e,d=s&&z(s,"Initialization")[0],c=e&&_(e);c&&d?c.initialization=d&&_(d):c&&c.initialization&&(c.initialization={sourceURL:c.initialization});var l={template:c,timeline:o&&z(o,"S").map(function(t){return _(t)}),list:r&&i(_(r),{segmentUrls:n,initialization:_(d)}),base:a&&i(_(a),{initialization:_(d)})};return Object.keys(l).forEach(function(t){l[t]||delete l[t]}),l},V=function(t,e,r){return function(n){var u=_(n),o=H(e,z(n,"BaseURL")),s=z(n,"Role")[0],d={role:_(s)},c=i(t,u,d),l=z(n,"ContentProtection").reduce(function(t,e){var r=_(e),n=G[r.schemeIdUri];if(n){t[n]={attributes:r};var i=z(e,"cenc:pssh")[0];if(i){var a=B(i),u=a&&$(a);t[n].pssh=u}}return t},{});Object.keys(l).length&&(c=i(c,{contentProtection:l}));var m=W(n),f=z(n,"Representation"),p=i(r,m);return a(f.map(function(t,e,r){return function(n){var a=z(n,"BaseURL"),u=H(e,a),o=i(t,_(n)),s=W(n);return u.map(function(t){return{segmentInfo:i(r,s),attributes:i(o,{baseUrl:t})}})}}(c,o,p)))}},X=function(t,r){void 0===r&&(r={});var n=r,u=n.manifestUri,s=void 0===u?"":u,d=n.NOW,c=void 0===d?Date.now():d,l=n.clientOffset,m=void 0===l?0:l,f=z(t,"Period");if(!f.length)throw new Error(o);var p=_(t),v=H([s],z(t,"BaseURL"));return p.sourceDuration=p.mediaPresentationDuration||0,p.NOW=c,p.clientOffset=m,a(f.map(function(t,r){return function(n,u){var o=H(r,z(n,"BaseURL")),s=_(n),d=parseInt(s.id,10),c=e.isNaN(d)?u:d,l=i(t,{periodIndex:c}),m=z(n,"AdaptationSet"),f=W(n);return a(m.map(V(l,o,f)))}}(p,v)))},Y=function(t){if(""===t)throw new Error(s);var e=(new r.DOMParser).parseFromString(t,"application/xml"),n=e&&"MPD"===e.documentElement.tagName?e.documentElement:null;if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(d);return n};t.VERSION="0.10.0",t.inheritAttributes=X,t.parse=function(t,e){return void 0===e&&(e={}),P(M(X(Y(t),e)),e.sidxMapping)},t.parseUTCTiming=function(t){return function(t){var e=z(t,"UTCTiming")[0];if(!e)return null;var r=_(e);switch(r.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":r.method="HEAD";break;case"urn:mpeg:dash:utc:http-xsdate:2014":case"urn:mpeg:dash:utc:http-iso:2014":case"urn:mpeg:dash:utc:http-xsdate:2012":case"urn:mpeg:dash:utc:http-iso:2012":r.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":r.method="DIRECT",r.value=Date.parse(r.value);break;case"urn:mpeg:dash:utc:http-ntp:2014":case"urn:mpeg:dash:utc:ntp:2014":case"urn:mpeg:dash:utc:sntp:2014":default:throw new Error(m)}return r}(Y(t))},t.stringToMpdXml=Y,t.toM3u8=P,t.toPlaylists=M,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "mpd-parser", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "mpd parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/mpd-parser.cjs.js", |
@@ -47,2 +47,28 @@ import { from } from './utils/list'; | ||
/** | ||
* Specifies the suggested presentation delay. Format is a | ||
* duration string as specified in ISO 8601 | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* @return {number} | ||
* The duration in seconds | ||
*/ | ||
suggestedPresentationDelay(value) { | ||
return parseDuration(value); | ||
}, | ||
/** | ||
* specifices the type of mpd. Can be either "static" or "dynamic" | ||
* | ||
* @param {string} value | ||
* value of attribute as a string | ||
* | ||
* @return {string} | ||
* The type as a string | ||
*/ | ||
type(value) { | ||
return value; | ||
}, | ||
/** | ||
* Specifies the duration of the smallest time shifting buffer for any Representation | ||
@@ -49,0 +75,0 @@ * in the MPD. Format is a duration string as specified in ISO 8601 |
@@ -242,2 +242,4 @@ import { values } from './utils/object'; | ||
sourceDuration: duration, | ||
type = 'static', | ||
suggestedPresentationDelay, | ||
minimumUpdatePeriod = 0 | ||
@@ -274,2 +276,6 @@ } = dashPlaylists[0].attributes; | ||
if (type === 'dynamic') { | ||
master.suggestedPresentationDelay = suggestedPresentationDelay; | ||
} | ||
if (audioPlaylists.length) { | ||
@@ -276,0 +282,0 @@ master.mediaGroups.AUDIO.audio = organizeAudioPlaylists(audioPlaylists, sidxMapping); |
@@ -9,2 +9,3 @@ import { parse, VERSION } from '../src'; | ||
import multiperiod from './manifests/multiperiod.mpd'; | ||
import multiperiodDynamic from './manifests/multiperiod-dynamic.mpd'; | ||
import { | ||
@@ -22,2 +23,5 @@ parsedManifest as maatVttSegmentTemplateManifest | ||
} from './manifests/multiperiod.js'; | ||
import { | ||
parsedManifest as multiperiodDynamicManifest | ||
} from './manifests/multiperiod-dynamic.js'; | ||
@@ -50,2 +54,6 @@ QUnit.module('mpd-parser'); | ||
expected: multiperiodManifest | ||
}, { | ||
name: 'multiperiod_dynamic', | ||
input: multiperiodDynamic, | ||
expected: multiperiodDynamicManifest | ||
}].forEach(({ name, input, expected }) => { | ||
@@ -52,0 +60,0 @@ QUnit.test(`${name} test manifest`, function(assert) { |
@@ -553,1 +553,65 @@ import { toM3u8 } from '../src/toM3u8'; | ||
}); | ||
QUnit.test('dynamic playlists with suggestedPresentationDelay', function(assert) { | ||
const input = [{ | ||
attributes: { | ||
id: '1', | ||
codecs: 'foo;bar', | ||
sourceDuration: 100, | ||
duration: 0, | ||
bandwidth: 20000, | ||
periodIndex: 1, | ||
mimeType: 'audio/mp4', | ||
type: 'dynamic', | ||
suggestedPresentationDelay: 18 | ||
}, | ||
segments: [] | ||
}, { | ||
attributes: { | ||
id: '2', | ||
codecs: 'foo;bar', | ||
sourceDuration: 100, | ||
duration: 0, | ||
bandwidth: 10000, | ||
periodIndex: 1, | ||
mimeType: 'audio/mp4' | ||
}, | ||
segments: [] | ||
}, { | ||
attributes: { | ||
sourceDuration: 100, | ||
id: '1', | ||
width: 800, | ||
height: 600, | ||
codecs: 'foo;bar', | ||
duration: 0, | ||
bandwidth: 10000, | ||
periodIndex: 1, | ||
mimeType: 'video/mp4' | ||
}, | ||
segments: [] | ||
}, { | ||
attributes: { | ||
sourceDuration: 100, | ||
id: '1', | ||
bandwidth: 20000, | ||
periodIndex: 1, | ||
mimeType: 'text/vtt', | ||
baseUrl: 'https://www.example.com/vtt' | ||
} | ||
}, { | ||
attributes: { | ||
sourceDuration: 100, | ||
id: '1', | ||
bandwidth: 10000, | ||
periodIndex: 1, | ||
mimeType: 'text/vtt', | ||
baseUrl: 'https://www.example.com/vtt' | ||
} | ||
}]; | ||
const output = toM3u8(input); | ||
assert.ok('suggestedPresentationDelay' in output); | ||
assert.deepEqual(output.suggestedPresentationDelay, 18); | ||
}); |
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
519283
52
13908