!function(a,b){"function"==typeof define&&define.amd?define(["./Decoder","./YUVCanvas"],b):"object"==typeof exports?module.exports=b(require("./Decoder"),require("./YUVCanvas")):a.Player=b(a.Decoder,a.YUVCanvas)}(this,function(a,b){"use strict";var c=a.nowValue,d=function(b){var d=this;this._config=b||{},this.render=!0,this._config.render===!1&&(this.render=!1),this.nowValue=c,this._config.workerFile=this._config.workerFile||"Decoder.js",this._config.preserveDrawingBuffer&&(this._config.contextOptions=this._config.contextOptions||{},this._config.contextOptions.preserveDrawingBuffer=!0);var e="auto";if(this._config.webgl===!0?e=!0:this._config.webgl===!1&&(e=!1),"auto"==e){e=!0;try{if(window.WebGLRenderingContext)for(var f=document.createElement("canvas"),g=null,h=["webgl","experimental-webgl","moz-webgl","webkit-3d"],i=0;!g&&i<h.length;){var j=h[i];try{g=f.getContext(j)}catch(a){g=null}g?e=!0:g=null,++i}else e=!1}catch(a){e=!1}}this.webgl=e,this.webgl?(this.createCanvasObj=this.createCanvasWebGL,this.renderFrame=this.renderFrameWebGL):(this.createCanvasObj=this.createCanvasRGB,this.renderFrame=this.renderFrameRGB);var k,l,m=function(a,b,e,f){d.onPictureDecoded(a,b,e,f);c();a&&d.render&&(d.renderFrame({canvasObj:d.canvasObj,data:a,width:b,height:e}),d.onRenderFrameComplete&&d.onRenderFrameComplete({data:a,width:b,height:e,infos:f,canvasObj:d.canvasObj}))};if(this._config.size||(this._config.size={}),this._config.size.width=this._config.size.width||200,this._config.size.height=this._config.size.height||200,this._config.useWorker){var n=new Worker(this._config.workerFile);this.worker=n,n.addEventListener("message",function(a){var b=a.data;b.consoleLog||m.call(d,new Uint8Array(b.buf,0,b.length),b.width,b.height,b.infos)},!1),n.postMessage({type:"Broadway.js - Worker init",options:{rgb:!e,memsize:this.memsize,reuseMemory:!!this._config.reuseMemory}}),this._config.transferMemory?this.decode=function(a,b){n.postMessage({buf:a.buffer,offset:a.byteOffset,length:a.length,info:b},[a.buffer])}:this.decode=function(a,b){var c=new Uint8Array(a.length);c.set(a,0,a.length),n.postMessage({buf:c.buffer,offset:0,length:a.length,info:b},[c.buffer])},this._config.reuseMemory&&(this.recycleMemory=function(a){n.postMessage({reuse:a.buffer},[a.buffer])})}else this.decoder=new a({rgb:!e}),this.decoder.onPictureDecoded=m,this.decode=function(a,b){d.decoder.decode(a,b)};this.render&&(this.canvasObj=this.createCanvasObj({contextOptions:this._config.contextOptions}),this.canvas=this.canvasObj.canvas),this.domNode=this.canvas,k=this._config.size.width,l=this._config.size.height};return d.prototype={onPictureDecoded:function(a,b,c,d){},recycleMemory:function(a){},createCanvasWebGL:function(a){var b=this._createBasicCanvasObj(a);return b.contextOptions=a.contextOptions,b},createCanvasRGB:function(a){var b=this._createBasicCanvasObj(a);return b},_createBasicCanvasObj:function(a){a=a||{};var b={},c=a.width;c||(c=this._config.size.width);var d=a.height;return d||(d=this._config.size.height),b.canvas=document.createElement("canvas"),b.canvas.width=c,b.canvas.height=d,b.canvas.style.backgroundColor="#0D0E1B",b},renderFrameWebGL:function(a){var c=a.canvasObj,d=a.width||c.canvas.width,e=a.height||c.canvas.height;c.canvas.width===d&&c.canvas.height===e&&c.webGLCanvas||(c.canvas.width=d,c.canvas.height=e,c.webGLCanvas=new b({canvas:c.canvas,contextOptions:c.contextOptions,width:d,height:e}));var f=d*e,g=d/2*(e/2);c.webGLCanvas.drawNextOutputPicture({yData:a.data.subarray(0,f),uData:a.data.subarray(f,f+g),vData:a.data.subarray(f+g,f+g+g)});var h=this;h.recycleMemory(a.data)},renderFrameRGB:function(a){var b=a.canvasObj,c=a.width||b.canvas.width,d=a.height||b.canvas.height;b.canvas.width===c&&b.canvas.height===d||(b.canvas.width=c,b.canvas.height=d);var e=b.ctx,f=b.imgData;e||(b.ctx=b.canvas.getContext("2d"),e=b.ctx,b.imgData=e.createImageData(c,d),f=b.imgData),f.data.set(a.data),e.putImageData(f,0,0);var g=this;g.recycleMemory(a.data)}},d});