/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{inherits as t,createSuper as e,classCallCheck as i,createClass as s}from"../../_virtual/_rollupPluginBabelHelpers.js";import{PLAY as r,PAUSE as a,ENDED as o,EMPTIED as n,FPS_STUCK as c}from"../../events.js";import u from"../../plugin/plugin.js";var h=/* @__PURE__ */function(){t(l,u);var h=e(l);function l(){return i(this,l),h.apply(this,arguments)}return s(l,[{key:"afterCreate",value:function(){var t=this,e=this.player,i=this.config,s=e.media||e.video;(this.timer=null,this._lastDecodedFrames=0,this._currentStuckCount=0,this._lastCheckPoint=null,this._payload=[],i.disabled)||s.getVideoPlaybackQuality&&(this.on(r,function(){t._startTick()}),this.on(a,function(){t._stopTick()}),this.on(o,function(){t._stopTick()}),this.on(n,function(){t._stopTick()}))}},{key:"_startTick",value:function(){var t=this;this._stopTick(),this._timer=setTimeout(function(){t._checkDecodeFPS(),t._startTick()},this.config.tick)}},{key:"_stopTick",value:function(){clearTimeout(this._timer),this._timer=null}},{key:"_checkBuffer",value:function(t,e){for(var i=!1,s=[],r=0;r<e.length;r++){var a=e.start(r),o=e.end(r);if(s.push({start:a,end:o}),a<=t&&t<=o-1){i=!0;break}}return{enoughBuffer:i,buffers:s}}},{key:"_checkStuck",value:function(t,e,i,s){var r=this.player.media||this.player.video,a=document.hidden,o=r.paused,n=r.readyState,u=r.currentTime,h=r.buffered;if(!(a||o||n<4)){var l=this._checkBuffer(u,h),f=l.enoughBuffer,d=l.buffers;f&&(t<=this.config.reportFrame?(this._currentStuckCount++,this._payload.push({currentTime:u,buffers:d,curDecodedFrames:t,totalVideoFrames:e,droppedVideoFrames:i,checkInterval:s}),this._currentStuckCount>=this.config.stuckCount&&(this.emit(c,this._payload),this._reset())):this._reset())}}},{key:"_reset",value:function(){this._payload=[],this._currentStuckCount=0}},{key:"_checkDecodeFPS",value:function(){var t=this.player.media||this.player.video;if(t){var e=t.getVideoPlaybackQuality(),i=e.totalVideoFrames,s=e.droppedVideoFrames,r=performance.now();if(i&&this._lastCheckPoint){var a=i-this._lastDecodedFrames,o=r-this._lastCheckPoint;this._checkStuck(a,i,s,o)}this._lastDecodedFrames=i,this._lastCheckPoint=r}}},{key:"destroy",value:function(){this._stopTick()}}],[{key:"pluginName",get:function(){return"FpsDetect"}},{key:"defaultConfig",get:function(){return{disabled:!1,tick:1e3,stuckCount:3,reportFrame:0}}}]),l}();export{h as default};