Verify a decoded colour transition in native WebRTC loopback
This commit is contained in:
1 parent
6053e8b315
commit
f0ed160cd0
3 files changed
+26
-13
No files matched your search
@@ -27,21 +27,30 @@ async fn main()->Result<(),Box<dyn std::error::Error>> {
|
||||
let a=tokio::spawn(async move{while let Some(event)=outgoing.recv().await{if let SignalPeerEvent::LocalCandidate(candidate)=event{target.add_candidate(candidate).await?;}}Ok::<_,teamspeach_native::media::stream::signal::StreamError>(())});
|
||||
let target=publisher.clone();
|
||||
let b=tokio::spawn(async move{while let Some(event)=incoming.recv().await{if let SignalPeerEvent::LocalCandidate(candidate)=event{target.add_candidate(candidate).await?;}}Ok::<_,teamspeach_native::media::stream::signal::StreamError>(())});
|
||||
let mut pixels=I420Buffer::new(64,48);
|
||||
{let(y,u,v)=pixels.data_mut();y.fill(81);u.fill(90);v.fill(240);}
|
||||
let mut frame=VideoFrame::new(VideoRotation::VideoRotation0,pixels);
|
||||
frame.color_matrix=6;frame.color_range=1;
|
||||
let started=Instant::now();let mut shown=0;let mut sent=0;
|
||||
while started.elapsed()<Duration::from_secs(12)&&shown<12 {
|
||||
let mut frames=[(81,90,240),(145,54,34)].map(|(luma,cb,cr)|{
|
||||
let mut pixels=I420Buffer::new(64,48);
|
||||
let(y,u,v)=pixels.data_mut();y.fill(luma);u.fill(cb);v.fill(cr);
|
||||
let mut frame=VideoFrame::new(VideoRotation::VideoRotation0,pixels);
|
||||
frame.color_matrix=6;frame.color_range=1;frame
|
||||
});
|
||||
let output=std::path::Path::new("target/codec-fixtures");std::fs::create_dir_all(output)?;
|
||||
let started=Instant::now();let mut shown=[0usize;2];let mut sent=0;
|
||||
while started.elapsed()<Duration::from_secs(12)&&shown[1]<6 {
|
||||
let phase=usize::from(shown[0]>=6);
|
||||
let frame=&mut frames[phase];
|
||||
frame.timestamp_us=started.elapsed().as_micros().max(1) as i64;
|
||||
source.capture_video(&frame)?;sent+=1;
|
||||
source.capture_video(frame)?;sent+=1;
|
||||
let surface=surfaces.lock().unwrap().clone();
|
||||
if let Some(surface)=surface {
|
||||
if let Some(image)=surface.take_image(64,48)?{
|
||||
let bytes=image.pixels.as_bytes();let at=((24*64+32)*4) as usize;
|
||||
if bytes[at]<220||bytes[at+1]>30||bytes[at+2]>30{return Err(format!("Wrong decoded red pixel {:?}",&bytes[at..at+4]).into())}
|
||||
if shown==0{image::save_buffer("target/codec-fixtures/peer-loopback.png",bytes,image.pixels.width(),image.pixels.height(),image::ColorType::Rgba8)?;}
|
||||
shown+=1;drop(image.image);surface.recycle(image.pixels);
|
||||
let colour=match bytes[at..at+3] {
|
||||
[220..=255,0..=30,0..=30] if shown[1]==0=>0,
|
||||
[0..=30,220..=255,0..=30] if phase==1=>1,
|
||||
_=>return Err(format!("Unexpected decoded pixel {:?} in phase {phase}",&bytes[at..at+4]).into()),
|
||||
};
|
||||
if shown[colour]==0{image::save_buffer(output.join(["peer-loopback-red.png","peer-loopback-green.png"][colour]),bytes,image.pixels.width(),image.pixels.height(),image::ColorType::Rgba8)?;}
|
||||
shown[colour]+=1;drop(image.image);surface.recycle(image.pixels);
|
||||
}
|
||||
}
|
||||
for event in events.try_iter(){if matches!(event,AudioEvent::Started{..}){return Err("A physical audio device was unexpectedly started".into())}}
|
||||
@@ -49,13 +58,13 @@ async fn main()->Result<(),Box<dyn std::error::Error>> {
|
||||
tokio::time::sleep(Duration::from_millis(34)).await;
|
||||
}
|
||||
let statistics=viewer.decoder_status().await?;
|
||||
source.ended();assert!(source.capture_video(&frame).is_err());
|
||||
source.ended();assert!(source.capture_video(&frames[1]).is_err());
|
||||
publisher.close();viewer.close();a.abort();b.abort();let _=a.await;let _=b.await;
|
||||
if let Some(surface)=surfaces.lock().unwrap().take(){assert!(surface.take_image(64,48)?.is_none());}
|
||||
assert_eq!(stopped.load(Ordering::SeqCst),1);
|
||||
audio.shutdown().await?;manager.shutdown().await?;
|
||||
if shown<12{return Err(format!("Only {shown} decoded frames from {sent} generated frames; stats={statistics:?}").into())}
|
||||
if shown[0]<6||shown[1]<6{return Err(format!("Only {shown:?} red/green frames from {sent} generated frames; stats={statistics:?}").into())}
|
||||
if !statistics.iter().any(|stat|stat.frames_decoded>=12&&!stat.implementation.is_empty()){return Err(format!("Missing actual decoder statistics: {statistics:?}").into())}
|
||||
println!("native_peer_loopback sent={sent} presented={shown} stop_callbacks=1 no_physical_audio=true stats={statistics:?}");
|
||||
println!("native_peer_loopback sent={sent} red={} green={} stop_callbacks=1 no_physical_audio=true stats={statistics:?}",shown[0],shown[1]);
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user