Browse Source

Minor improvement

tags/v0.3.11-rc1
haixuanTao haixuantao 10 months ago
parent
commit
f1bc8a7b1e
2 changed files with 11 additions and 17 deletions
  1. +8
    -16
      node-hub/dora-av1-encoder/src/main.rs
  2. +3
    -1
      node-hub/dora-dav1d/src/main.rs

+ 8
- 16
node-hub/dora-av1-encoder/src/main.rs View File

@@ -7,15 +7,12 @@
// Media Patent License 1.0 was not distributed with this source code in the // 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. // 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::arrow::array::UInt8Array;
use dora_node_api::dora_core::config::DataId; use dora_node_api::dora_core::config::DataId;
use dora_node_api::{DoraNode, Event, IntoArrow, MetadataParameters, Parameter}; use dora_node_api::{DoraNode, Event, IntoArrow, MetadataParameters, Parameter};
use eyre::{Context as EyreContext, Result}; use eyre::{Context as EyreContext, Result};
use log::warn; use log::warn;
// Encode the same tiny blank frame 30 times // Encode the same tiny blank frame 30 times
use rav1e::config::RateControlConfig;
use rav1e::config::SpeedSettings; use rav1e::config::SpeedSettings;


use rav1e::*; use rav1e::*;
@@ -90,18 +87,14 @@ fn main() -> Result<()> {


let cfg = Config::new() let cfg = Config::new()
// .with_rate_control(RateControlConfig::new().with_emit_data(true)) // .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()?; cfg.validate()?;


let mut ctx: Context<u16> = cfg.new_context().unwrap();

let (mut node, mut events) = let (mut node, mut events) =
DoraNode::init_from_env().context("Could not initialize dora node")?; DoraNode::init_from_env().context("Could not initialize dora node")?;


let mut time = std::time::Instant::now();
loop { loop {
let buffer = match events.recv() {
let _buffer = match events.recv() {
Some(Event::Input { id, data, metadata }) => { Some(Event::Input { id, data, metadata }) => {
if let Some(Parameter::Integer(h)) = metadata.parameters.get("height") { if let Some(Parameter::Integer(h)) = metadata.parameters.get("height") {
height = *h as usize; height = *h as usize;
@@ -130,6 +123,7 @@ fn main() -> Result<()> {
let buffer = buffer.values(); //.to_vec(); let buffer = buffer.values(); //.to_vec();


let (y, u, v) = get_yuv_planes(buffer, width, height); let (y, u, v) = get_yuv_planes(buffer, width, height);
let mut ctx: Context<u8> = cfg.new_context().unwrap();
let mut f = ctx.new_frame(); let mut f = ctx.new_frame();


let xdec = f.planes[0].cfg.xdec; let xdec = f.planes[0].cfg.xdec;
@@ -153,13 +147,12 @@ fn main() -> Result<()> {
} }
}, },
} }
ctx.flush();
match ctx.receive_packet() { match ctx.receive_packet() {
Ok(pkt) => { Ok(pkt) => {
println!("Time to encode: {:?}", time.elapsed());
time = std::time::Instant::now();
let data = pkt.data; 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(); let arrow = data.into_arrow();
node.send_output( node.send_output(
DataId::from("frame".to_owned()), DataId::from("frame".to_owned()),
@@ -183,6 +176,7 @@ fn main() -> Result<()> {
unimplemented!("We haven't worked on additional encodings."); unimplemented!("We haven't worked on additional encodings.");
let buffer: &UInt8Array = data.as_any().downcast_ref().unwrap(); let buffer: &UInt8Array = data.as_any().downcast_ref().unwrap();
let buffer: &[u8] = buffer.values(); let buffer: &[u8] = buffer.values();
let mut ctx: Context<u8> = cfg.new_context().unwrap();
let mut f = ctx.new_frame(); let mut f = ctx.new_frame();


for p in &mut f.planes { for p in &mut f.planes {
@@ -192,15 +186,13 @@ fn main() -> Result<()> {
buffer.to_vec() buffer.to_vec()
} else { } else {
unimplemented!("We haven't worked on additional encodings."); unimplemented!("We haven't worked on additional encodings.");
continue;
} }
} }
Some(Event::Error(e)) => {
Some(Event::Error(_e)) => {
continue; continue;
} }
_ => break, _ => break,
}; };
//let (y, u, v) = bgr_to_yuv(buffer, 640 as usize, 480 as usize);
} }


Ok(()) Ok(())


+ 3
- 1
node-hub/dora-dav1d/src/main.rs View File

@@ -64,6 +64,7 @@ fn main() -> Result<()> {


let mut now = std::time::Instant::now(); let mut now = std::time::Instant::now();
loop { loop {
let time = std::time::Instant::now();
match events.recv() { match events.recv() {
Some(Event::Input { Some(Event::Input {
id: _, id: _,
@@ -81,6 +82,7 @@ fn main() -> Result<()> {
} }
Ok(()) => { Ok(()) => {
if let Ok(p) = dec.get_picture() { 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 y = p.plane(dav1d::PlanarImageComponent::Y); //.to_vec();
let mut u = p.plane(dav1d::PlanarImageComponent::U); //.to_vec(); let mut u = p.plane(dav1d::PlanarImageComponent::U); //.to_vec();
let mut v = p.plane(dav1d::PlanarImageComponent::V); //.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) node.send_output(DataId::from("frame".to_string()), metadata, arrow)
.unwrap(); .unwrap();
println!("Time to decode: {:?}", now.elapsed());
//println!("Time to decode: {:?}", now.elapsed());


now = std::time::Instant::now(); now = std::time::Instant::now();
} }


Loading…
Cancel
Save