Loading
function(e,t,n){"use strict";var i=n(77729),r=n(311043),a=n(97770),s=n(46653),l=n(779559),o=n(419490),d=n(395378),c=n(489496),u=n(335182),_=n(598213),E=n(799),A=n(160330),f=n(696016),h=n(792996);n.d(t,{},{k:class{gameId;startedAt;id=crypto.randomUUID();status="active";finalization=null;savedClipIds=[];candidateClipsById=new Map;manualClipsSavedCount=0;candidateClipsSavedCount=0;candidateClipsPromotedCount=0;constructor(e,t=performance.now()){this.gameId=e,this.startedAt=t}get clipIds(){return this.savedClipIds}get candidates(){return[...this.candidateClipsById.values()]}get isActive(){return"active"===this.status}get hasClips(){return this.savedClipIds.length>0}get manualClipsSaved(){return this.manualClipsSavedCount}get candidateClipsSaved(){return this.candidateClipsSavedCount}get candidateClipsPromoted(){return this.candidateClipsPromotedCount}recordSavedClip(e){if("manual"===e.clipMethod&&(this.manualClipsSavedCount+=1),!0===e.isCandidate){this.candidateClipsSavedCount+=1,this.candidateClipsById.set(e.id,e);return}this.savedClipIds=[...this.savedClipIds,e.id]}recordPromotedClip(e){this.candidateClipsPromotedCount+=1,this.removeCandidate(e.id),this.savedClipIds=[...this.savedClipIds,e.id]}removeCandidate(e){this.candidateClipsById.delete(e)}removeClip(e){this.removeCandidate(e),this.savedClipIds=this.savedClipIds.filter(t=>t!==e)}getCandidate(e){return this.candidateClipsById.get(e)}recordMontageClip(e){this.savedClipIds=[...this.savedClipIds,e.id]}end(){"active"===this.status&&(this.status="ended")}finalize(e){return null!=this.finalization||(this.status="finalizing",this.finalization=this.runFinalization(e).finally(()=>{this.status="ended"})),this.finalization}async runFinalization(e){let t=this.candidates;if(f.GU.info(`decider: finalizing session \u{2014} sessionId=${this.id} candidates=${t.length} autoStashEnabled=${o.Ay.isAutoStashEnabled()}`),o.Ay.isAutoStashEnabled())try{await this.stashDeciderData(t,e)}catch(e){f.GU.error("decider: auto-stash failed",e)}let n=(0,d.Ly)(t,e,s.default.getId(),this.gameId??void 0);f.GU.info("ranked clips:",n);let i=null;try{i=this.createAutoMontage(t,e)}catch(e){f.GU.error("decider: auto-montage creation failed",e)}let r=n.selected;if(null!=i&&r.length>2){let e=i,t=new Map(r.map(t=>[t,function(e,t){let{startMs:n,endMs:i}=(0,d.tA)(e.clip),r=0;for(let a of t.resolved){if(a.clip.id!==e.clip.id)continue;let t=(0,_.lQ)(a.clip),s=t+a.videoStartMs;r+=Math.max(0,Math.min(i,t+a.videoEndMs)-Math.max(n,s))}return r}(t,e)])),n=r.reduce((e,n)=>(t.get(n)??0)>(t.get(e)??0)?n:e),a=t.get(n)??0,s=a>0?n:r.reduce((e,t)=>t.score<e.score?t:e);r=r.filter(e=>e!==s),f.GU.info(a>0?`decider: auto-montage replaces the selected clip it already covers most (id=${s.clip.id}, score=${s.score}, overlapMs=${a})`:`decider: auto-montage replaces worst selected clip (id=${s.clip.id}, score=${s.score})`)}let a=new Set(r.map(e=>{let{clip:t}=e;return t.id}));await Promise.all(r.map(async e=>{let{clip:t,score:n,audioEvents:i}=e;try{await (0,c.K7)(t,n,this,i)}catch(e){f.GU.error("decider: failed to promote clip candidate",e)}}));let l=Promise.resolve();if(null!=i)try{let e=this.buildMontagePlaceholderClip(i,t);l=this.startAutoMontageRender(i,e)}catch(e){f.GU.error("decider: failed to start the auto-montage render",e)}let u=t.filter(e=>!a.has(e.id));l.finally(async function(){await Promise.all(u.map(async e=>{try{await (0,c.oH)(e,!1)}catch(e){f.GU.error("decider: failed to delete unpromoted clip candidate",e)}}))})}async stashDeciderData(e,t){let n={decisionSignals:t,clipCandidates:[...e],localUserId:s.default.getId(),gameId:this.gameId??void 0,fps:o.Ay.getSettings().clipsQuality.frameRate},r=i.A.clips.debugStashClipDeciderData;if(null==r)return;let a=this.buildStashName();await r(n,a),f.GU.info(`stashDeciderData: stashed ${e.length} candidates to ${a}`)}buildStashName(){let e=r.A.getGame(this.gameId)?.name,t=null!=e?(0,a.A)(e).slice(0,40):"";return""!==t?`${this.id}_${t}`:this.id}createAutoMontage(e,t){if(!l.A.getConfig({location:"ClipsSession#createAutoMontage"}).enableAutomontage)return null;if(null==i.A.clips.renderMontageRecipe)return f.GU.warn("decider: auto-montage unavailable (host is missing renderMontageRecipe) \u2014 skipping"),null;let n={clipCandidates:e,decisionSignals:t,localUserId:s.default.getId(),gameId:this.gameId??void 0,fps:o.Ay.getSettings().clipsQuality.frameRate},r=(0,u.$Q)(n);return null==r?(f.GU.info("decider: no auto-montage could be built for this session"),null):(f.GU.info(`decider: auto-montage built \u{2014} type=${r.type} sections=${r.resolved.length} skipped=${r.skipped.length} durationMs=${r.durationMs}`),r)}buildMontagePlaceholderClip(e,t){let n=(0,A.A)("auto",f.nQ.CLIP,[],void 0,this.id),a=new Set(e.resolved.map(e=>e.clip.id)),s=new Set(n.users);for(let e of t)if(a.has(e.id))for(let t of e.users)s.add(t);let l=r.A.getGame(this.gameId)?.name,d=i.A.fileManager.join(o.Ay.getSettings().storageLocation,`${e.type}_${n.id}.mp4`);return{...n,name:h.intl.string(u.qn[e.type]),filepath:d,type:f.nQ.CLIP,applicationName:l??n.applicationName,applicationId:this.gameId??n.applicationId,users:Array.from(s),length:e.durationMs,syncTimestamp:void 0,pending:!0}}resolveClipPath=e=>{let t=o.Ay.getClipById(e.id)??this.getCandidate(e.id);if(null==t)throw Error(`auto-montage: source clip ${e.id} is no longer in the clips store`);return t.filepath};startAutoMontageRender(e,t){let n=i.A.clips.renderMontageRecipe;return null==n?(f.GU.warn("decider: auto-montage render unavailable (host is missing renderMontageRecipe) \u2014 skipping"),Promise.resolve()):((0,c.ef)(t),f.GU.info(`decider: auto-montage render started - type=${e.type} output=${t.filepath} durationMs=${e.durationMs} sections=${e.resolved.length}`),(async()=>{try{let i=await (0,E.y)(e,this.resolveClipPath);await n(JSON.stringify(i),t.filepath,(0,c.h5)(t)),f.GU.info(`decider: auto-montage render succeeded \u{2014} ${t.filepath}`),await (0,c.EM)(t,this)}catch(e){f.GU.error("decider: auto-montage failed",e),await (0,c.t9)(t)}})())}}})}