var XpraVideoDecoderLoader={hasNativeDecoder(){return"undefined"!=typeof VideoDecoder}};class XpraVideoDecoder{constructor(){this.initialized=!1,this.had_first_key=!1,this.draining=!1,this.decoder_queue=[],this.frame_threshold=250,this.on_frame_decoded={},this.on_frame_error=(packet,error)=>{console.error("VideoDecoder error on packet",packet,":",error)}}init(width,height){this.videoDecoder=new VideoDecoder({output:this._on_decoded_frame.bind(this),error:this._on_decoder_error.bind(this)}),this.videoDecoder.configure({codec:"avc1.42C01E",optimizeForLatency:!0,codedWidth:width,codedHeight:height}),this.last_timestamp=0,this.initialized=!0}_on_decoded_frame(videoFrame){if(0===this.decoder_queue.length)videoFrame.close();else{var frame_timestamp=videoFrame.timestamp,current_frame=this.decoder_queue.filter(q=>q.p[10].frame==frame_timestamp);if(1!=current_frame.length)videoFrame.close();else{if(this.decoder_queue=this.decoder_queue.filter(q=>q.p[10].frame!=frame_timestamp),current_frame=current_frame[0],0==frame_timestamp&&(this.last_timestamp=0),this.decoder_queue.length>this.frame_threshold||this.last_timestamp>frame_timestamp)return videoFrame.close(),(packet=current_frame.p)[6]="throttle",packet[7]=null,void this.on_frame_decoded(packet);this.last_timestamp=frame_timestamp;var packet=current_frame.p;this.draining?videoFrame.close():(packet[6]="frame:"+packet[6],packet[7]=videoFrame,this.on_frame_decoded(packet,current_frame))}}}_on_decoder_error(error){this._close()}queue_frame(packet){var options=packet[10]||{},data=packet[7];decode_error=error=>{this.on_frame_error(packet,error)},this.had_first_key||"IDR"==options.type?"closed"==this.videoDecoder.state?decode_error("video decoder is closed"):this.draining?decode_error("video decoder is draining"):(this.had_first_key=!0,this.decoder_queue.push({p:packet}),data={type:"IDR"==options.type?"key":"delta",data:data,timestamp:options.frame},options=new EncodedVideoChunk(data),this.videoDecoder.decode(options)):decode_error("first frame must be a key frame")}_close(){if(this.initialized){"closed"!=this.videoDecoder.state&&this.videoDecoder.close(),this.had_first_key=!1,this.draining=!0;var frame,drain_queue=this.decoder_queue;this.decoder_queue=[];for(frame of drain_queue){var packet=frame.p;this.on_frame_error(packet,"video decoder is draining")}this.draining=!1}this.initialized=!1}}