(function(){var g={}; var _ = _ || {}
var f=function(window){var Tz="No thumbnail found for position: ",Uz="Position is out of range: ",Vz="Thumbnail URL is mandatory",Wz="Wrong gridSize format",Xz="clpp.thumbnails",Yz=function(){this.log=new _.J(Xz);this.player=null;this.a=[];this.w=!1},$z=function(a,b){b.reduce(function(c,d){var e=d,f=!1;typeof d===_.Re&&(e=d.step,f=d.preloadWhileBuffering);return c.then(function(){return Zz(a,0,e,!!f)})},Promise.resolve())},Zz=function(a,b,c,d){if(a.w||b>=a.a.length)return Promise.resolve();var e=b+c;return aA(a,d).then(function(){return a.a[b].load()}).then(function(){return Zz(a,
e,c,d)})},aA=function(a,b){return new Promise(function(c){if(b||a.player.getState()!==_.yq)c();else a.player.one(_.$c,function(){c()})})},bA=function(a,b,c,d,e,f,g,h,l,m,n,p){d=void 0===d?0:d;e=void 0===e?0:e;f=void 0===f?0:f;g=void 0===g?0:g;h=void 0===h?1:h;l=void 0===l?1:l;m=void 0===m?0:m;n=void 0===n?0:n;p=void 0===p?new Image:p;this.time=b;this.src=a;this.duration=c;this.x=d;this.y=e;this.width=f;this.height=g;this.ua=p;this.nl=h;this.ko=l;this.hm=m;this.im=n;this.og=null},cA=function(){Yz.call(this);
this.f=null;this.o=this.h=1;this.j=0},dA=function(a,b){this.time=a;this.duration=0;this.offset=b;this.length=0;this.zd=new _.kk},eA=function(){this.g=new _.J(Xz);this.f=new ArrayBuffer(0);this.a=[];this.h=new _.kk},fA=function(a){var b=a.f.byteLength;a.a.forEach(function(c){c.offset+c.length<b&&c.zd.resolve()})},hA=function(a,b){return gA(a,b).then(function(c){return new bA(c,b.time,b.duration)})},gA=function(a,b){return b.load().then(function(){var c=_.Oj(a.f,b.offset,b.length);return"data:image/jpeg;base64,"+
_.Lm(c)})},iA=function(){Yz.call(this);this.f=null},jA=function(a){a=a.split(/\.|:/).map(parseFloat);var b=0,c,d={3:.001,2:1,1:60,0:3600};for(c=a.length-1;0<=c;c--)b+=a[c]*d[c];return b},kA=function(){Yz.apply(this,arguments)},lA=function(a,b){var c=a.horizontalTiles||b.horizontalTiles||1,d=a.verticalTiles||b.verticalTiles||1,e=c*d;return{ne:c,$g:d,mi:e,durationPerTile:a.durationPerTile||b.durationPerTile||(a.endTime-a.startTime)/e}},mA=function(){this.g=new _.J(Xz);this.a=this.m=null},nA=function(a){return a.some(function(b){return 0<
b.thumbStreams.length})},sA=function(a){return a?a===oA||a===pA?new cA:a===qA?new iA:a===rA?new eA:null:null},tA=function(a){if(!a)return null;a=new _.Mk(a);return a.path.match(/.*\.vtt$/i)?qA:a.path.match(/.*\.bif$/i)?rA:a.path.match(/.*\.(png|jpg|jpeg)$/i)?oA:null},uA=function(){};Yz.prototype.init=function(a,b){var c=this;this.player=a;a.one(_.Kf,function(){c.w=!0});a.isLive()||this.l().then(function(){b&&b.preload&&$z(c,b.preload)})};bA.prototype.raw=function(){return this.ua.cloneNode(!1)};
bA.prototype.element=function(a,b){var c=this.width,d=this.height,e=this.width/this.height;void 0!==a&&void 0===b&&(b=0);null!==a&&void 0!==a&&(c=a);null!==b&&void 0!==b&&(d=b);c||(c=Math.ceil(d*e));d||(d=Math.ceil(c/e));e=document.createElement(_.Qd);e.style.width=c+_.Hf;e.style.height=d+_.Hf;e.style.backgroundColor="#000";e.style.backgroundRepeat="no-repeat";e.style.backgroundImage='url("'+this.src+'")';e.style.backgroundSize=Math.ceil(c/this.width*(this.ua.naturalWidth||this.ua.width))+"px "+Math.ceil(d/
this.height*(this.ua.naturalHeight||this.ua.height))+_.Hf;var f=this.y/this.height;e.style.backgroundPositionX="-"+this.x/this.width*c+_.Hf;e.style.backgroundPositionY="-"+f*d+_.Hf;return e};
bA.prototype.load=function(){var a=this;this.og||(this.og=new Promise(function(b,c){function d(){a.width||(a.width=(a.ua.naturalWidth||a.ua.width)/a.nl);a.height||(a.height=(a.ua.naturalHeight||a.ua.height)/a.ko);a.x||(a.x=a.width*a.hm);a.y||(a.y=a.height*a.im)}if(a.ua.src&&a.ua.complete)d(),b(a);else{var e=null,f=function(){d();a.ua.removeEventListener(_.Be,f);a.ua.removeEventListener(_.ie,e);b(a)};e=function(g){a.ua.removeEventListener(_.Be,f);a.ua.removeEventListener(_.ie,e);c(new _.N(1,9,2014,
"Failed to load thumbnail.",g))};a.ua.addEventListener(_.Be,f);a.ua.addEventListener(_.ie,e);a.ua.src=a.src}}));return this.og};_.I("clpp.thumbnails.Thumbnail",bA);bA.prototype.load=bA.prototype.load;bA.prototype.element=bA.prototype.element;bA.prototype.raw=bA.prototype.raw;_.w(cA,Yz);
cA.prototype.init=function(a,b){if(!b||!b.url)throw new _.N(1,9,7100,Vz);if("GRID"===b.mode&&!b.gridSize)throw new _.N(1,9,7100,"Grid size is mandatory for GRID mode");if(!b.duration)throw new _.N(1,9,7100,"Duration is mandatory");this.f=b;this.j=this.f.duration;if(this.f.gridSize)try{var c=this.f.gridSize.split(/x/).map(function(d){return parseInt(d,10)}).filter(function(d){return 0<d});if(2===c.length)this.h=c[0],this.o=c[1];else throw new _.N(1,9,7100,Wz);}catch(d){throw this.log.error("Error during parsing gridSize",d),
new _.N(1,9,7100,Wz);}Yz.prototype.init.call(this,a,b)};cA.prototype.get=function(a){var b=this,c,d,e,f;return _.H(function(g){if(1==g.a){c=b.player.getDuration();if(0>a||a>c)throw new _.N(1,9,2014,Uz+a);d=b.f.duration;e=Math.floor(a/d);f=b.a[e];if(!f)throw new _.N(1,9,2014,"No thumbnail found for position "+a+" at index "+e);return _.x(g,f.load(),2)}return g["return"](f)})};
cA.prototype.l=function(){if(0<this.a.length)return Promise.resolve();var a=this.player.getDuration(),b=this.h*this.o;a=Math.ceil(Math.ceil(a/this.j)/b);for(var c=this.f.templateKey||"$index$",d=0;d<a;d++)for(var e=this.f.url.replace(c,String(d+1)),f=new Image,g=0;g<b;g++)this.a.push(new bA(e,this.j*(d*b+g),this.j,0,0,0,0,this.h,this.o,g%this.h,Math.floor(g/this.h),f));return Promise.resolve()};dA.prototype.load=function(){return this.zd};
eA.prototype.init=function(a,b){var c=this;if(!b||!b.url)throw new _.N(1,9,7100,Vz);var d=b.url,e=_.ck(d);e.type=_.bk;a.getNetworkEngine().fetch(e).S.then(function(f){f=f.data;var g=_.Oj(c.f);f=_.Oj(f);for(var h=g.byteLength+f.byteLength,l=new ArrayBuffer(h),m=new DataView(l),n=0,p=0,q=g.byteLength;p<q;p++)m.setUint8(n,g[p]),n+=1;g=0;for(p=f.byteLength;g<p;g++)m.setUint8(n,f[g]),n+=1;c.f=l;c.g.info("Appended "+f.byteLength+" bytes.Total data now "+(h+" bytes."));l=c.f;f=_.Oj(l);n=String.fromCharCode.apply(null,
vA);g=Array.prototype.slice.call(f,0,8);f=64;h=0;m=!1;if(n===String.fromCharCode.apply(null,g))for(l=new DataView(l,16,20),l=l.getUint32(0,!0),0===l&&(l=1E3);!m;){h+=1;g=l;n=new DataView(c.f,f);m=n.getUint32(0,!0);g=m*g/1E3;n=n.getUint32(4,!0);n=new dA(g,n);if(g=c.a.length)g=c.a[g-1],g.length=n.offset-g.offset,g.duration=n.time-g.time;c.a.push(n);f+=8;(m=4294967295===m)&&c.h.resolve();if(1E5<h)throw Error("There was a problem during reading BIF entries");}else throw Error("The file is not a valid BIF format");
fA(c)})["catch"](function(f){c.g.error("[BIF] Error while loading thumbnails '\n            + 'URL: "+d,f);a.onError(new _.N(1,9,2013,"Error while loading and parsing BIF thumbnails.",f))})};eA.prototype.get=function(a){var b=this,c,d;return _.H(function(e){switch(e.a){case 1:if(0>a)throw new _.N(1,9,2014,Uz+a);return _.x(e,b.h,2);case 2:c=b.a.find(function(f){return a>=f.time&&a<f.time+f.duration});if(!c)throw new _.N(1,9,2014,Tz+a);return _.x(e,hA(b,c),3);case 3:return d=e.f,_.x(e,d.load(),4);case 4:return e["return"](d)}})};
eA.prototype.Jc=function(){return 0<this.a.length};var vA=[137,66,73,70,13,10,26,10];_.w(iA,Yz);
iA.prototype.init=function(a,b){var c=this;if(!b||!b.url)throw new _.N(1,9,7100,Vz);var d=b.url,e=_.ck(d);e.type=_.bk;this.f=a.getNetworkEngine().fetch(e).S.then(function(f){f=f.data;if(!f)throw Error("No data in the response");f=_.Q.ea(f).split(/\n/);for(var g=0;g<f.length;g++){var h=f[g],l=h.split(" --\x3e ");if(2===l.length){h=f[++g];var m=h.indexOf("\x3d"),n=0>m?[]:h.substr(m+1).split(/,/).map(parseFloat);m=n[0];var p=n[1],q=n[2];n=n[3];var t=h.indexOf("#");h=0>t?h:h.substr(0,t);h.match(/^http|^\/\//)||(h=
d.substr(0,d.lastIndexOf("/"))+"/"+h);t=jA(l[0]);l=jA(l[1])-t;c.a.push(new bA(h,t,l,m,p,q,n,0,0))}}})["catch"](function(f){c.log.error("[VTT] Error while loading thumbnails URL: "+d,f);a.onError(new _.N(1,9,2013,"Error while loading VTT thumbnails.",f))});Yz.prototype.init.call(this,a,b)};
iA.prototype.get=function(a){var b=this,c;return _.H(function(d){if(1==d.a){if(0>a)throw new _.N(1,9,2014,Uz+a);return _.x(d,b.f,2)}if(3!=d.a){c=b.a.find(function(e){return a>=e.time&&a<e.time+e.duration});if(!c)throw new _.N(1,9,2014,Tz+a);return _.x(d,c.load(),3)}return d["return"](c)})};iA.prototype.l=function(){return this.f};_.w(kA,Yz);
kA.prototype.get=function(a){function b(){return new _.N(1,9,2014,Tz+a)}var c=this,d,e,f,g,h,l,m,n,p,q,t,v,z;return _.H(function(A){if(1==A.a){if(0>a)throw c.log.error("Position must be greater than 0 but is "+a),new _.N(1,9,2014,Uz+a);d=c.player.getPeriods();for(var D=null,G=_.u(d),B=G.next();!B.done;B=G.next())B=B.value,B.startTime<=a&&(D=B);e=D;if(!e)throw c.log.error("Could not find period for specified position",a),b();f=e.thumbStreams.sort(c.f)[0];if(!f)throw c.log.error("Could not find thumb stream for specified position",a),
b();g=f.findSegmentPosition(a-e.startTime);if(null===g||void 0===g)throw c.log.error("Could not find segment index for specified position",a),b();h=f.getSegmentReference(g);if(!h)return A.D(2);l=lA(h,f);m=Math.floor((a-h.startTime)/l.durationPerTile);0<c.a.length?(p=f.findSegmentPosition(0),null!==p&&(n=c.a[(g-p)*l.mi+m])):(q=h.cb())&&0<q.length&&(v=t=0,z=h.startTime,1<l.mi&&(t=m%l.ne,v=Math.floor(m/l.ne),z+=m*l.durationPerTile),n=new bA(q[0],z,l.durationPerTile,void 0,void 0,void 0,void 0,l.ne,l.$g,
t,v));return n?_.x(A,n.load(),4):A.D(2)}if(2!=A.a)return A["return"](n);c.log.error("segment reference for specified segment index does not exist",g);throw b();})};kA.prototype.f=function(a,b){return void 0!==a.bandwidth&&void 0!==b.bandwidth?a.bandwidth-b.bandwidth:0};
kA.prototype.l=function(){if(0<this.a.length)return Promise.resolve();var a=this.player.getPeriods();a=_.u(a);for(var b=a.next();!b.done;b=a.next())if(b=b.value.thumbStreams.sort(this.f)[0])for(var c=b.findSegmentPosition(0),d=void 0;null!==c&&!_.L.R(d=b.getSegmentReference(c++));)for(var e=lA(d,b),f=d.cb()[0],g=new Image,h=d.startTime,l=0;l<e.$g;++l)for(var m=0;m<e.ne;++m)this.a.push(new bA(f,h,e.durationPerTile,void 0,void 0,void 0,void 0,e.ne,e.$g,m,l,g)),h+=e.durationPerTile;return Promise.resolve()};_.r=mA.prototype;_.r.onPlayerCreated=function(a){this.m=a};_.r.onPlayerWillDestroy=function(){this.m=null};_.r.onPlayerWillRelease=function(){this.a=null};
_.r.onContentWillLoad=function(a){var b=this,c=a.getConfiguration().thumbnails;if(c)if(!1===c.enabled)this.g.info("Thumbnails disabled.");else{var d=c.mode||null;d||(d=tA(c.url||null));(this.a=sA(d))?(this.g.info("Loading thumbs configuration",c),this.m.one(_.De,function(){b.g.info("Initialize thumbnails provider");try{b.a.init(a,c)}catch(e){b.m.onError(e)}})):this.g.warn("Unknown thumbnail mode",d)}else this.a=null};
_.r.onContentLoaded=function(a,b){for(var c=1;c<arguments.length;++c);if(!this.a&&(c=(c=a.getConfiguration())&&c.thumbnails,!c||void 0===c.enabled||c.enabled)){var d=a.getPeriods();if(nA(d)){this.a=new kA;try{this.a.init(a,c)}catch(e){this.m.onError(e)}}}};_.r.get=function(a){return this.a?this.a.get(a):Promise.reject(new _.N(1,9,2014,"Thumbnail format is not supported"))};_.r.id=function(){return"thumbnails"};_.I("clpp.thumbnails.ThumbnailsPlugin",mA);mA.prototype.get=mA.prototype.get;mA.Id="thumbnails";
uA.prototype.create=function(){return new mA};_.Yt(new uA);var oA="SINGLE",pA="GRID",qA="WEBVTT",rA="BIF";};
if(typeof(module)!="undefined"&&module.exports){var x=require("./cl.core.js");_ = x._;(f.call(g,this));module.exports=g;}
else if (typeof(define)!="undefined"&&define.amd) {define(["./cl.core"], function(c){_=c._;(f.call(g,this));return g;});}
else{_=this.clpp._;(f.call(g,this));}
})();