Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/video-streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ workspace = true
[[bench]]
name = "vpx_reencode"
harness = false
required-features = ["bench"]
55 changes: 55 additions & 0 deletions crates/video-streamer/src/decoder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use anyhow::Context as _;
use cadeau::xmf::vpx::{VpxCodec, VpxDecoder, VpxImage};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct Dimensions {
pub width: u32,
pub height: u32,
}

pub(crate) struct DecodedFrame<'decoder> {
pub image: VpxImage<'decoder>,
pub dimensions: Dimensions,
}

pub(crate) struct InputDecoder {
codec: VpxCodec,
threads: u32,
decoder: Option<VpxDecoder>,
}

impl InputDecoder {
pub(crate) fn new(codec: VpxCodec, threads: u32) -> Self {
Self {
codec,
threads,
decoder: None,
}
}

pub(crate) fn decode<'decoder>(&'decoder mut self, data: &[u8]) -> anyhow::Result<DecodedFrame<'decoder>> {
if self.decoder.is_none() {
self.decoder = Some(
VpxDecoder::builder()
.threads(self.threads)
.width(0)
.height(0)
.codec(self.codec)
.build()?,
);
}

let decoder = self.decoder.as_mut().context("input decoder is missing")?;
decoder.decode(data)?;
let image = decoder.next_frame()?;
let dimensions = Dimensions {
width: image.width(),
height: image.height(),
};
anyhow::ensure!(
dimensions.width > 0 && dimensions.height > 0,
"decoder returned invalid frame dimensions"
);
Ok(DecodedFrame { image, dimensions })
}
}
6 changes: 6 additions & 0 deletions crates/video-streamer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ macro_rules! perf_debug {

pub mod config;
pub mod debug;
mod decoder;
mod normalizer;
mod protocol;
pub mod reopenable;
mod session;
pub(crate) mod streamer;

#[macro_use]
Expand All @@ -39,6 +43,8 @@ pub use streamer::reopenable_file::ReOpenableFile;
pub use streamer::signal_writer::SignalWriter;
#[rustfmt::skip]
pub use streamer::webm_stream;
#[rustfmt::skip]
pub use session::{RecordingClip, RecordingEvent, RecordingSource, SessionConfig, StartAt, stream_session};

#[cfg(feature = "bench")]
pub mod bench_support;
Loading
Loading