feat(video): recover camera previews and reduce encoding and playout cost

Improve camera recovery, shared preview lifecycle and receiver playout diagnostics. Preserve qualified X4 runtime changes and restore async admission in loopback media tests.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:10:01 +03:00
parent e06ff9a214
commit fa8bde584f
94 changed files with 8892 additions and 375 deletions
+21 -5
View File
@@ -3,19 +3,35 @@ export class PreviewLiveness {
private lastFrame:number|null=null;
private sourceSeen=Number.NEGATIVE_INFINITY;
private staleSince:number|null=null;
constructor(private connectedAt:number){}
connected(now:number){this.connectedAt=now;}
frame(now:number){this.lastFrame=now;}
private connectedAt:number|null=null;
private budgetPauseUntil=0;
private budgetResumeAt:number|null=null;
constructor(private negotiatedAt:number){}
negotiated(now:number){this.negotiatedAt=now;}
connected(now:number){this.connectedAt??=now;}
frame(now:number){this.connected(now);this.lastFrame=now;}
allocation(paused:boolean,now:number){
if(paused)this.budgetPauseUntil=now+3000;
else if(this.budgetPauseUntil){this.budgetPauseUntil=0;this.budgetResumeAt=now;}
}
source(fresh:boolean,now:number){
this.sourceSeen=now;
this.staleSince=fresh?null:this.staleSince??now;
}
state(now:number):'live'|'waiting'|'delayed'|'source-stalled'|'peer-stalled'{
state(now:number):'connecting'|'live'|'waiting'|'delayed'|'source-stalled'|'peer-stalled'{
// SDP is only signaling. ICE/DTLS can still be establishing the private route.
if(this.connectedAt===null)return now-this.negotiatedAt>30000?'peer-stalled':'connecting';
if(this.staleSince!==null&&now-this.sourceSeen<3000){
return now-this.staleSince>=12000?'source-stalled':'delayed';
}
// A fresh allocation pause is not a dead peer and never claims live imagery.
// Missing hints still expire normally; actual source-stall evidence wins above.
if(now<this.budgetPauseUntil)return 'waiting';
if(this.budgetResumeAt!==null&&(this.lastFrame===null||this.lastFrame<this.budgetResumeAt)&&now-this.budgetResumeAt<8000)return 'waiting';
const elapsed=now-(this.lastFrame??this.connectedAt);
if(elapsed>8000)return 'peer-stalled';
// A short route interruption must not tear down an established decoder.
// The image is still marked delayed after 2 s; this only bounds reconnection.
if(elapsed>(this.lastFrame===null?8000:30000))return 'peer-stalled';
if(this.lastFrame===null)return 'waiting';
return elapsed>2000?'delayed':'live';
}