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:
@@ -0,0 +1,28 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {build} from 'esbuild';
|
||||
async function module(path){const compiled=await build({entryPoints:[new URL(path,import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'});return import('data:text/javascript;base64,'+Buffer.from(compiled.outputFiles[0].contents).toString('base64'));}
|
||||
const {previewEvidence}=await module('../../../packages/sensor-ui/src/previewEvidence.ts');
|
||||
const {connectRoverEvidence,roverPreviewEvidence}=await module('../src/core/fleet/roverDevEvents.ts');
|
||||
test('preview projection separates the budget, encoder and receiver without private payload',()=>{
|
||||
const sample=previewEvidence('peer_a','session_a',{sdp:'secret',media_budget:{mode:'observing',allocation_bps:5000000,target_bps:3250000,encoder_bps:500000,receiver_bps:307644,encoder_reinitializations:68,sample_mono_ms:1234,egress:{sent_bytes:900,queue_dropped:0},last_encoder_reset:{frame:70,reason:'private'}}},{fps:11,round_trip_ms:90,mbps:.3,interval_ms:2000,packets_lost:NaN},1280,640,100);
|
||||
assert.equal(sample.allocation_bps,5000000);assert.equal(sample.encoder_bps,500000);assert.equal(sample.receiver_bps,307644);
|
||||
assert.equal(sample.reset_frame,70);assert.equal(sample.source_age_ms,100);assert.equal(sample.interval_ms,2000);
|
||||
assert.equal(sample.packets_lost,undefined);assert.equal(sample.sdp,undefined);assert.equal(sample.reason,undefined);
|
||||
assert.ok(JSON.stringify(sample).length<1500);
|
||||
assert.deepEqual(previewEvidence('p','s',null,null,-1,Infinity,NaN),{peer_id:'p',device_session:'s'});
|
||||
});
|
||||
test('preview evidence is isolated by vehicle and local capture; remote DEV cannot upload it',async()=>{
|
||||
const original=globalThis.fetch,calls=[];globalThis.fetch=async(url,init)=>{calls.push({url,body:JSON.parse(init.body)});return {ok:true,json:async()=>({accepted:true})};};
|
||||
const a=connectRoverEvidence('/a'),b=connectRoverEvidence('/b');
|
||||
try{
|
||||
a.set('a'.repeat(32));b.set(null,'b'.repeat(32));
|
||||
roverPreviewEvidence('/a',{peer_id:'p'});roverPreviewEvidence('/b',{peer_id:'q'});
|
||||
await new Promise(r=>setTimeout(r,280));
|
||||
assert.equal(calls.length,1);assert.equal(calls[0].url,'/b/diagnostics/local/events');
|
||||
assert.equal(calls[0].body.id,'b'.repeat(32));assert.equal(calls[0].body.events[1].event,'preview');
|
||||
assert.equal(calls[0].body.events[1].sample.peer_id,'q');
|
||||
b.set(null);roverPreviewEvidence('/b',{peer_id:'later'});await new Promise(r=>setTimeout(r,280));
|
||||
assert.equal(calls.length,1);
|
||||
}finally{a.close();b.close();globalThis.fetch=original;}
|
||||
});
|
||||
Reference in New Issue
Block a user