From f1bc8a7b1eb1465d83a192f0968cca55412eb08a Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Thu, 27 Mar 2025 14:02:23 +0100 Subject: [PATCH] Minor improvement --- node-hub/dora-av1-encoder/src/main.rs | 24 ++++++++---------------- node-hub/dora-dav1d/src/main.rs | 4 +++- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/node-hub/dora-av1-encoder/src/main.rs b/node-hub/dora-av1-encoder/src/main.rs index b53a8684..75218ec0 100644 --- a/node-hub/dora-av1-encoder/src/main.rs +++ b/node-hub/dora-av1-encoder/src/main.rs @@ -7,15 +7,12 @@ // Media Patent License 1.0 was not distributed with this source code in the // PATENTS file, you can obtain it at www.aomedia.org/license/patent. -use std::time::Duration; - use dora_node_api::arrow::array::UInt8Array; use dora_node_api::dora_core::config::DataId; use dora_node_api::{DoraNode, Event, IntoArrow, MetadataParameters, Parameter}; use eyre::{Context as EyreContext, Result}; use log::warn; // Encode the same tiny blank frame 30 times -use rav1e::config::RateControlConfig; use rav1e::config::SpeedSettings; use rav1e::*; @@ -90,18 +87,14 @@ fn main() -> Result<()> { let cfg = Config::new() // .with_rate_control(RateControlConfig::new().with_emit_data(true)) - .with_encoder_config(enc.clone()) - .with_threads(16); + .with_encoder_config(enc.clone()); //.with_threads(16); cfg.validate()?; - let mut ctx: Context = cfg.new_context().unwrap(); - let (mut node, mut events) = DoraNode::init_from_env().context("Could not initialize dora node")?; - let mut time = std::time::Instant::now(); loop { - let buffer = match events.recv() { + let _buffer = match events.recv() { Some(Event::Input { id, data, metadata }) => { if let Some(Parameter::Integer(h)) = metadata.parameters.get("height") { height = *h as usize; @@ -130,6 +123,7 @@ fn main() -> Result<()> { let buffer = buffer.values(); //.to_vec(); let (y, u, v) = get_yuv_planes(buffer, width, height); + let mut ctx: Context = cfg.new_context().unwrap(); let mut f = ctx.new_frame(); let xdec = f.planes[0].cfg.xdec; @@ -153,13 +147,12 @@ fn main() -> Result<()> { } }, } + ctx.flush(); match ctx.receive_packet() { Ok(pkt) => { - println!("Time to encode: {:?}", time.elapsed()); - time = std::time::Instant::now(); let data = pkt.data; - println!("frame compression: {:#?}", width * height * 3 / data.len()); - println!("frame size: {:#?}", data.len()); + println!("Packet data: {:?}", data.len()); + println!("Compression: {:?}", height * width * 3 / data.len()); let arrow = data.into_arrow(); node.send_output( DataId::from("frame".to_owned()), @@ -183,6 +176,7 @@ fn main() -> Result<()> { unimplemented!("We haven't worked on additional encodings."); let buffer: &UInt8Array = data.as_any().downcast_ref().unwrap(); let buffer: &[u8] = buffer.values(); + let mut ctx: Context = cfg.new_context().unwrap(); let mut f = ctx.new_frame(); for p in &mut f.planes { @@ -192,15 +186,13 @@ fn main() -> Result<()> { buffer.to_vec() } else { unimplemented!("We haven't worked on additional encodings."); - continue; } } - Some(Event::Error(e)) => { + Some(Event::Error(_e)) => { continue; } _ => break, }; - //let (y, u, v) = bgr_to_yuv(buffer, 640 as usize, 480 as usize); } Ok(()) diff --git a/node-hub/dora-dav1d/src/main.rs b/node-hub/dora-dav1d/src/main.rs index 22c160da..1486601e 100644 --- a/node-hub/dora-dav1d/src/main.rs +++ b/node-hub/dora-dav1d/src/main.rs @@ -64,6 +64,7 @@ fn main() -> Result<()> { let mut now = std::time::Instant::now(); loop { + let time = std::time::Instant::now(); match events.recv() { Some(Event::Input { id: _, @@ -81,6 +82,7 @@ fn main() -> Result<()> { } Ok(()) => { if let Ok(p) = dec.get_picture() { + // println!("Time to decode: {:?}", time.elapsed()); let mut y = p.plane(dav1d::PlanarImageComponent::Y); //.to_vec(); let mut u = p.plane(dav1d::PlanarImageComponent::U); //.to_vec(); let mut v = p.plane(dav1d::PlanarImageComponent::V); //.to_vec(); @@ -119,7 +121,7 @@ fn main() -> Result<()> { ); node.send_output(DataId::from("frame".to_string()), metadata, arrow) .unwrap(); - println!("Time to decode: {:?}", now.elapsed()); + //println!("Time to decode: {:?}", now.elapsed()); now = std::time::Instant::now(); }