"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[430],{82252:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.BufferController=void 0;var i,n,a=r(91261),o=r(74929),s=r(57497),l=r(68302),d=r(21730),u=r(65972),c=r(5200),f=r(78746),h=r(21997),p=r(45e3),_=r(15968),v=r(23658),g=r(75321),m=r(20217),y=r(59863),E=r(39708),R=r(87248),S=r(96798),C=r(72949),w=r(53269),D=r(86460),P=r(66262),T=r(8339),b=r(49977),B=r(8125),A=r(34167),F=r(73981),V=r(93678),U=r(24286),M=r(86915),I=r(30617),G=r(76760),O=r(37289),k=r(22553),W=r(11202),x=r(28813),N=r(9408),L=r(93158),H=r(57999),j=r(39336),Y=r(74165),q=r(91037),K=r(93218);(i=n||(n={})).ATTACH_START="Gluon.BufferController.attach_start",i.ATTACH_END="Gluon.BufferController.attach_end",i.ATTACH_MEASURE="Gluon.BufferController.attach",i.DESTROY_START="Gluon.BufferController.destroy_start",i.DESTROY_END="Gluon.BufferController.destroy_end",i.DESTROY_MEASURE="Gluon.BufferController.destroy",i.PREPARE_START="Gluon.BufferController.prepare_start",i.PREPARE_END="Gluon.BufferController.prepare_end",i.PREPARE_MEASURE="Gluon.BufferController.prepare",i.UPDATE_START="Gluon.BufferController.update_start",i.UPDATE_END="Gluon.BufferController.update_end",i.UPDATE_MEASURE="Gluon.BufferController.update",i.DRM_START="Gluon.BufferController.drm_start",i.DRM_END="Gluon.BufferController.drm_end",i.DRM_MEASURE="Gluon.BufferController.drm",i.SELECT_VARIANT_START="Gluon.BufferController.select_variant_start",i.SELECT_VARIANT_END="Gluon.BufferController.select_variant_end",i.SELECT_VARIANT_MEASURE="Gluon.BufferController.select_variant",i.SELECT_VARIANT_METADATA_START="Gluon.BufferController.select_variant_metadata_start",i.SELECT_VARIANT_METADATA_END="Gluon.BufferController.select_variant_metadata_end",i.SELECT_VARIANT_METADATA_MEASURE="Gluon.BufferController.select_variant_metadata",i.LOAD_VARIANT_DETAILS_START="Gluon.BufferController.load_variant_details_start",i.LOAD_VARIANT_DETAILS_END="Gluon.BufferController.load_variant_details_end",i.LOAD_VARIANT_DETAILS_MEASURE="Gluon.BufferController.load_variant_details";var z=function(){function e(t,r,i,n,o,s,l,d){var c,f,h,p,v=this;void 0===n&&(n=[]),this.onError=new m.Emitter,this.onWarning=new m.Emitter,this.onBufferItemPhaseChange=new m.Emitter,this.onTextChange=new m.Emitter,this.onContentRangeChange=new m.Emitter,this.onSegmentDurationChanged=new m.Emitter,this.onBufferCapacityChanged=new m.Emitter,this.onBufferLevelChanged=new m.Emitter,this.onSegmentRetry=new m.Emitter,this._allowDrmReuse=!0,this._variantFilters=[],this._trackPreferences=[],this._bufferItemMap=new B.Map,this._filteredVariantMap=new B.Map,this._selectedVariants=new B.Map,this._selectedVariantMap=new B.Map,this._bufferRegions=[],this._appendRegions=[],this._isBufferUpdatePending=!1,this._requiresBufferUpdate=!1,this._disposed=!1,this._textEnabled=!1,this._failedStreams=new B.Map;var y=(null==s?void 0:s.probePastFailedSegmentDownload)===!0&&void 0!==r.dynamicInfo,E=(null==r?void 0:r.dynamicInfo)!==void 0&&(null==s?void 0:s.liveBufferRetryOverridesOptions)!==void 0?a.__assign(a.__assign({},null==s?void 0:s.bufferRetryOptions),null==s?void 0:s.liveBufferRetryOverridesOptions):null==s?void 0:s.bufferRetryOptions;this._system=t,this._manifest=r,this.metricBus=i,this._noAudio=null!==(c=null==s?void 0:s.noAudio)&&void 0!==c&&c,this._noReloadBetweenCompatiblePeriods=null!==(f=null==s?void 0:s.noReloadBetweenCompatiblePeriods)&&void 0!==f?f:e.DEFAULT_NO_RELOAD_BETWEEN_COMPATIBLE_PERIODS,this._segmentDownloadDuringDrmInitialization=null!==(h=null==s?void 0:s.segmentDownloadDuringDrmInitialization)&&void 0!==h&&h,this._delayedHydrate=l,this._variantSelector=o,this._cmcd=d,this._downloadFailedRebufferingSeconds=null!==(p=null==s?void 0:s.retryErrorsWhileBufferingSeconds)&&void 0!==p?p:e.DEFAULT_DOWNLOAD_FAILED_REBUFFER_SECONDS,this.mediaSourceController=new D.MediaSourceController(t),this.bufferLogic=new _.DefaultBufferLogic(y),this.mediaSourceController.onTextChange.on(this,function(e){return v.onTextChange.emit(e)}),this.mediaSourceController.onWarning.on(this,function(e){return v.onWarning.emit(e)}),this.mediaSourceController.onBufferedRangesRemoved.on(this,function(e){return v._onBufferedRangesRemovedHandler(e)}),this._trackPreferences=n,this.addVariantFilter(new L.SupportedVariantFilter(t)),this.addVariantFilter(new g.DigitalRightsVariantFilter(t,this)),this.addVariantFilter(new j.TrackPreferenceVariantFilter),this.addVariantFilter(new u.BufferRetryHandlerVariantFilter(this._system,this,y,{getBufferItem:function(e){return v._bufferItemMap.tryGet(e)},getVariants:function(e){return v._selectedVariants.get(e)},getVariantDetails:function(e,t){return v._getVariantDetailsOrScheduleForRecover(e,t)},getActivePipelines:function(){return v.getActivePipelines()}},E)),(null==s?void 0:s.disableSmoothnessTracker)!==!0&&this.addVariantFilter(new N.SmoothnessTrackerVariantFilter(this,this._system,null==s?void 0:s.smoothnessOptions))}return e.clearDrainDataForStreamType=function(e,t){var r=e.mediaSourceDrain.tryGet(t);if(void 0!==r){k.SegmentPipeline.cleanDrained(r);for(var i=0;i0){var r=this._filteredVariantMap.tryGet(e);if(void 0!==r)for(var i=0;i0?this._filteredVariantMap.forEach(function(r){t.invalidateVariants(r,e)}):this._filteredVariantMap.clear()},e.prototype.clearAsync=function(e){return a.__awaiter(this,void 0,void 0,function(){var t,r,i,n,o;return a.__generator(this,function(a){switch(a.label){case 0:for(i=0,t=this.mediaSourceController.getPipelines(),r=[],n=t;i0))return[3,2];return[4,I.PromiseUtil.waitAll(o)];case 1:return a.sent(),[2,this.updateBufferRegions()];case 2:return[2]}})})},e.prototype.isSegmentDownloadable=function(e){if(void 0===this.drm)return!0;var t=!0;return void 0!==e.segment.keyId&&e.segment.keyId.length>0&&(t=this._segmentDownloadDuringDrmInitialization?!this.drm.isRestricted([e.segment.keyId]):this.drm.isUsable([e.segment.keyId])),t},e.prototype.isSegmentAppendable=function(e){var t=this._bufferItemMap.tryGet(e),r=!0;return this._segmentDownloadDuringDrmInitialization&&(r=void 0===this.drm||void 0===e.segment.keyId||0===e.segment.keyId.length||this.drm.isUsable([e.segment.keyId])),r&&((null==t?void 0:t.period)===this._appendPeriod||this._noReloadBetweenCompatiblePeriods&&void 0!==this._manifest&&void 0!==this._appendPeriod&&void 0!==t&&A.PlayerUtil.periodsCompatibleWithoutReload(this._manifest,this._appendPeriod,t.period,this._system.requireSingleFramerate()))},e.prototype.getBufferItem=function(e){return this._bufferItemMap.tryGet(e)},e.prototype.getActivePipelines=function(){return this.mediaSourceController.getPipelines()},e.prototype.getPeriods=function(){var e,t;return null!==(t=null===(e=this._manifest)||void 0===e?void 0:e.periods)&&void 0!==t?t:[]},e.prototype.getBufferRegions=function(){return this._bufferRegions},e.prototype.getAppendRegions=function(){return this._appendRegions},e.prototype.getContentRange=function(e){var t;return void 0===e&&(e="union"),null===(t=this._lastContentRange)||void 0===t?void 0:t[e]},e.prototype.getBufferItems=function(e){for(var t=[],r=this.mediaSourceController.getPipelineItems(e),i=0;i0))return[3,3];return void 0===this._choosePipelinesPromise&&(this._choosePipelinesPromise=this._chooseStreamPipelines(null!==(_=this._appendPeriod)&&void 0!==_?_:t[0]).catch(function(e){throw v._choosePipelinesPromise=void 0,e})),[4,this._choosePipelinesPromise];case 2:a.sent(),a.label=3;case 3:return[4,I.PromiseUtil.waitAll(t.map(function(e){return v._updatePeriodBufferRegions(e)}))];case 4:if(!a.sent().every(function(e){return e}))return[3,6];return[4,this._updateContentRange()];case 5:for(a.sent(),this.bufferLogic.applyToPipelines(this),s=this.mediaSourceController.getPipelines(),l=0,d=s;l0))return[3,8];return[4,I.PromiseUtil.waitAll(h)];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:return(p=a.sent())instanceof K.WrappedError&&K.WrappedError.causedBy(p,V.OperationCanceledError.NAME)?this.onWarning.emit(new q.WarningError("ignoring operation canceled",p)):e=new c.BufferUpdateError("Failed to apply periods to pipelines",K.WrappedError.wrap(p,"BufferRegionError")),[3,10];case 10:if(this._currentBufferUpdatePromise=void 0,this._requiresBufferUpdate=!1,void 0!==e)throw this._isBufferUpdatePending=!1,e;if(!this._isBufferUpdatePending||(this._isBufferUpdatePending=!1,this._disposed))return[3,12];return[4,this.updateBufferRegions()];case 11:a.sent(),a.label=12;case 12:return[2]}})})})},e.prototype._chooseStreamPipelines=function(e){var t;return a.__awaiter(this,void 0,void 0,function(){var r,i;return a.__generator(this,function(n){switch(n.label){case 0:return this._fillVariantFiltersDrain(),[4,this._selectVariant(e)];case 1:return[4,null===(t=(r=n.sent()).currentSelection)||void 0===t?void 0:t.getDetails()];case 2:if(void 0===(i=n.sent()))return[2];if(!(void 0!==i.videoDetails))return[3,4];return[4,this._ensurePipelineForStream(i.videoDetails,i,r)];case 3:n.sent(),n.label=4;case 4:if(!(!this._noAudio&&void 0!==i.audioDetails))return[3,6];return[4,this._ensurePipelineForStream(i.audioDetails,i,r)];case 5:n.sent(),n.label=6;case 6:return[4,void 0!==i.textDetails?this._ensurePipelineForStream(i.textDetails,i,r):this._ensureTextPipeline()];case 7:return n.sent(),void 0!==this._delayedHydrate&&(this._fillPipelinesFromDrain(this._delayedHydrate),this._delayedHydrate=void 0),[2]}})})},e.prototype._fillVariantFiltersDrain=function(){var e=this;this._variantFilters.forEach(function(t){var r,i,n,a=null===(r=e._delayedHydrate)||void 0===r?void 0:r.variantFilterDrains.tryGet(t.id);void 0!==a&&(null===(i=t.setDrainData)||void 0===i||i.call(t,a),null===(n=e._delayedHydrate)||void 0===n||n.variantFilterDrains.delete(t.id))})},e.prototype._fillPipelinesFromDrain=function(e){for(var t,r=this.mediaSourceController.getPipelines(),i=0;i0,this._system.logInfo("Creating ".concat(t," pipeline with stream '").concat(l,"', extractEmbeddedCaptions=").concat(d)),[4,this.mediaSourceController.makePipeline(t,e,d,this._cmcd)];case 2:o=a.sent(),this._onAttachPipeline(o),a.label=3;case 3:return[2,o]}})})},e.prototype._calculateSegmentDurationSec=function(){for(var e=this.getActivePipelines().filter(function(e){return"video"===e.type}),t=0;t0)return this._system.logWarn("Missing segment ".concat(f.id," at position ").concat(f.position,". Switching to alternate stream ").concat(g.id,".")),f=g,h=!0,[3,5];S.label=4;case 4:return _++,[3,2];case 5:if(!h)return this._system.logWarn("No replacement found for missing segment ".concat(f.id," at position ").concat(f.position,".")),[3,7];S.label=6;case 6:if(m=H.TimeRangeUtil.contains(this._bufferRegions,[f]),y=null===(o=this.bufferRetryHandlerVariantFilter)||void 0===o?void 0:o.shouldSkipSegment(f.position),!m||!0===y)return[3,7];u&&void 0!==d&&!H.TimeRangeUtil.isTimeClose(f.start,d.start)&&f.start0))return[3,5];return this._system.logVerbose("Invalidating specific period filters:",i),this.invalidateVariants(e,i),[4,this._selectVariantMetadata(e)];case 4:return t=a.sent(),[3,6];case 5:return[3,7];case 6:return[3,2];case 7:return void 0!==t.currentSelection&&this._validatePeriodRangeWithVariant(e,t.currentSelection),[2,t]}})})})]})})},e.prototype._getVariantDetailsOrScheduleForRecover=function(e,t){var r,i,n,o;return a.__awaiter(this,void 0,void 0,function(){var s,l,d,u,c,f,h,p,_,v;return a.__generator(this,function(a){switch(a.label){case 0:if(s="".concat(null===(r=t.audio)||void 0===r?void 0:r.id,"/").concat(null===(i=t.video)||void 0===i?void 0:i.id,"/").concat(null===(n=t.text)||void 0===n?void 0:n.id),!((l=t.getDetails())instanceof Promise))return[3,2];return[4,M.PerformanceUtil.wrap(this._system,"".concat("Gluon.BufferController.load_variant_details_start",":").concat(e.id,":").concat(s),"".concat("Gluon.BufferController.load_variant_details_end",":").concat(e.id,":").concat(s),"".concat("Gluon.BufferController.load_variant_details",":").concat(e.id,":").concat(s),function(){return l})];case 1:return d=a.sent(),[3,3];case 2:d=l,a.label=3;case 3:if(u=null!==(o=d.failedStreamDetails)&&void 0!==o?o:[],c=!1,u.length>0){for(f=0,h=u;f0?v:void 0,currentBufferCapacitySec:g>0?g:void 0})]}})})})]})})},e.prototype._throwFilteredToZeroError=function(e,t,r,i){var n=t.join(", "),a="Period ".concat(r,": '").concat(e.id,"' reduced ").concat(n," to zero, there are no variants left to play!");if(void 0!==e.getContextualInfo&&(a+="\nFilter Contextual Info:\n"+e.getContextualInfo(this._system).split("\n").map(function(e){return" ".concat(e)}).join("\n")),this._failedStreams.getCount()>0){var o=new S.HashMap;this._failedStreams.forEach(function(e){var t=o.tryGet(e.type);void 0!==t?t.push(e):o.set(e.type,[e])}),a+="\n\nStreams filtered because of the failure to get details:\n",o.forEach(function(e,t){var r=t.sort(function(e,t){return e.id-t.id}).map(function(e){return"".concat(e.id,"|").concat(e.codecs)});a+=" ".concat(e," (id|codecs): ").concat(r.join(", "),"\n")})}var s=this._getVariantFilterErrorByType(e.id,a,i,1===t.length?t[0]:void 0);if(void 0!==e.getFilterError)throw e.getFilterError(i,s,1===t.length?t[0]:void 0);throw s},e.prototype._getVariantFilterErrorByType=function(e,t,r,i){var n=new f.BufferVariantError(r,t,void 0,i);return"Digital Rights Variant Filter"===e?new v.DigitalRightsError(n):n},e.prototype._filterVariantContext=function(e){var t;return a.__awaiter(this,void 0,void 0,function(){var r,i,n,o,s,l,d,u,c,f,h,p;return a.__generator(this,function(_){switch(_.label){case 0:r=e.period,i=null!==(t=this._filteredVariantMap.tryGet(r))&&void 0!==t?t:{},e.hadFilterChange=!1,n=0,o=this._variantFilters,_.label=1;case 1:if(!(n0&&this._throwFilteredToZeroError(s,p,r.id,e)),i[s.id]={audio:e.audio,video:e.video,text:e.text},e.hadFilterChange=!0,_.label=5;case 5:e.filterCodecMap.set(s.id,this._getCodecGroups(a.__spreadArray(a.__spreadArray([],e.audio,!0),e.video,!0))),e.filterMap.set(s.id,e.audio.length+e.video.length+e.text.length),_.label=6;case 6:return n++,[3,1];case 7:return this._filteredVariantMap.set(r,i),[2]}})})},e.prototype._makePreferences=function(){var t=this._trackPreferences.slice(),r=new C.HashSet(t.map(function(e){return e.streamType}));return r.has("audio")||t.push(e.DEFAULT_AUDIO_PREFERENCE),r.has("video")||t.push(e.DEFAULT_VIDEO_PREFERENCE),r.has("text")||t.push(e.DEFAULT_TEXT_PREFERENCE),t},e.prototype._getCodecGroups=function(e){for(var t=new C.HashSet,r=0;r0?r.video[0].codecs:""},e.prototype._getSupplementalCodecs=function(e,t){var r;return null===(r=t.video[0])||void 0===r?void 0:r.supplementalCodecs},e.prototype._updateContentRange=function(){var e,t;return a.__awaiter(this,void 0,void 0,function(){var r,i,n,o;return a.__generator(this,function(a){switch(a.label){case 0:if(r=null===(e=this._lastContentRange)||void 0===e?void 0:e.union,i=A.PlayerUtil.getRangeOfPeriods(this.getPeriods(),"union"),n=A.PlayerUtil.getRangeOfPeriods(this.getPeriods(),"intersection"),this._lastContentRange=void 0!==i&&void 0!==n?{union:i,intersection:n}:void 0,o=void 0===r&&void 0!==i||void 0!==r&&void 0===i,void 0!==r&&void 0!==i&&(o=r.start!==i.start||r.end!==i.end),!o)return[3,3];if(!(void 0!==i))return[3,2];return[4,null===(t=this.mediaSourceController.getMediaSource())||void 0===t?void 0:t.setContentRange(i.start,i.end)];case 1:a.sent(),a.label=2;case 2:this.onContentRangeChange.emit(i),a.label=3;case 3:return[2]}})})},e.prototype.removeOutsideOfRange=function(){for(var e=this._bufferRegions[0],t=this.mediaSourceController.getPipelines(),r=0;r0&&a[a.length-1].end>=e.end)i.removeAll();else{for(var o=[],s=0,l=0,d=i.active.getAllRanges();l0){var c=s-1;e.start-o[c].end<1&&o.splice(c,1)}for(var f=0;fa){this._variantFilters.splice(s,0,t),o=!0;break}}o||this._variantFilters.push(t)}},e.prototype.clearVariantFilters=function(){var e=this;this._variantFilters.forEach(function(t){var r,i,n;null===(r=t.destroy)||void 0===r||r.call(t),null===(i=t.onWarning)||void 0===i||i.off(e),null===(n=t.onError)||void 0===n||n.off(e)}),this._variantFilters=[]},e.prototype.removeVariantFilter=function(e){var t=this;this._variantFilters=this._variantFilters.filter(function(r){var i,n,a,o=r===e;return o&&(null===(i=r.destroy)||void 0===i||i.call(r),null===(n=r.onWarning)||void 0===n||n.off(t),null===(a=r.onError)||void 0===a||a.off(t)),!o})},e.prototype.selectVariant=function(e){return this._selectVariant(e)},e.prototype.setPlayerVitals=function(e){var t;null===(t=this._drm)||void 0===t||t.setPlayerVitals(e)},e.prototype._removeDrm=function(){var e=this._drm;return this._removeDrmEvents(),this._drm=void 0,e},e.prototype.setDrm=function(e){this._removeDrmEvents(),this._drm=e,this._attachDrmEvents()},e.prototype.getRestrictedSegments=function(){var e=this.drm;if(void 0===e)return[];for(var t=new S.HashMap,r=0,i=this.getActivePipelines();rn&&(null===(i=this._manifest)||void 0===i?void 0:i.dynamicInfo)===void 0&&this._system.logWarn("Period '".concat(t.id,"' mismatch start compared to variant. Period starts at ").concat(t.start," with variant starting at ").concat(a.start)),void 0!==a&&Math.abs(a.end-t.end)>n&&this._system.logWarn("Period '".concat(t.id,"' mismatch end compared to variant. Period ends at ").concat(t.end," with variant ending at ").concat(a.end))},e.prototype._ensureMediaKeys=function(){return a.__awaiter(this,void 0,void 0,function(){var e,t,r,i,n;return a.__generator(this,function(a){switch(a.label){case 0:if(void 0===this.drm)return[2];if(void 0!==this.drm.getChosenMediaKeyOptions())return[3,5];if(!(void 0!==(e=s.ArrayUtil.find(this.getPeriods(),function(e){return A.PlayerUtil.isPeriodEncrypted(e)}))))return[3,2];return[4,this._selectVariant(e)];case 1:return r=a.sent().currentSelection,[3,3];case 2:r=void 0,a.label=3;case 3:if(t=r,this.drm.isDestroyed())return[3,5];return i=this.drm.getMediaKeys(),[4,this.drm.chooseMediaKeyOption(t)];case 4:void 0!==(n=a.sent()).mediaKeys&&n.mediaKeys!==i&&(this._system.logVerbose("Invalidating all variants due to new media keys being created"),this.invalidateAllVariants(["Digital Rights Variant Filter"])),a.label=5;case 5:return[2]}})})},e.prototype._ensureDetailsForContentRange=function(){return a.__awaiter(this,void 0,void 0,function(){var e,t,r,i,n,o;return a.__generator(this,function(a){switch(a.label){case 0:for(e=this.getPeriods(),t=[],e.length>0&&t.push(e[0]),e.length>1&&t.push(e[e.length-1]),r=[],i=0,n=t;i0&&o.audio.every(function(e){return void 0===e.getCachedDetails()})||o.video.length>0&&o.video.every(function(e){return void 0===e.getCachedDetails()}))&&r.push(this._selectVariant(o).then(function(e){var t;return null===(t=e.currentSelection)||void 0===t?void 0:t.getDetails()}));if(!(r.length>0))return[3,2];return[4,I.PromiseUtil.waitAll(r)];case 1:a.sent(),a.label=2;case 2:return[2]}})})},e.prototype._getVariantFilter=function(e){return s.ArrayUtil.find(this._variantFilters,function(t){return t.id===e})},e.prototype._onBufferedRangesRemovedHandler=function(e){var t=this,r=this.mediaSourceController.getPipeline(e.streamType),i=null==r?void 0:r.active.getInside(e.ranges),n=!1;if(void 0!==i)for(var a=0;a