summaryrefslogtreecommitdiff
path: root/crates/renderer/src/overlay/handcam.rs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-06-09 03:20:53 -0400
committerLLLL Colonq <llll@colonq>2026-06-09 03:20:53 -0400
commit9065f3c9765123f5f5bc503407c493fdb7c79488 (patch)
treea442c9be93715217fd6e05b1bab2a20dc2fe7d18 /crates/renderer/src/overlay/handcam.rs
parent01899d77e0e04a470fbc1ca000fef6e467334516 (diff)
Initial handcam stuff
Diffstat (limited to 'crates/renderer/src/overlay/handcam.rs')
-rw-r--r--crates/renderer/src/overlay/handcam.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/renderer/src/overlay/handcam.rs b/crates/renderer/src/overlay/handcam.rs
new file mode 100644
index 0000000..fadbf24
--- /dev/null
+++ b/crates/renderer/src/overlay/handcam.rs
@@ -0,0 +1,43 @@
+use teleia::*;
+
+use crate::overlay;
+
+const WIDTH: usize = 1920;
+const HEIGHT: usize = 1080;
+const BLOCK_SIZE: usize = 16;
+const BWIDTH: usize = WIDTH / BLOCK_SIZE;
+const BHEIGHT: usize = HEIGHT / BLOCK_SIZE;
+
+pub struct Overlay {
+ camera: nokhwa::Camera,
+ texbuf: Vec<u8>,
+}
+impl Overlay {
+ pub fn new(ctx: &context::Context) -> Self {
+ let index = nokhwa::utils::CameraIndex::Index(0);
+ let requested = nokhwa::utils::RequestedFormat::new::<nokhwa::pixel_format::RgbAFormat>(
+ nokhwa::utils::RequestedFormatType::AbsoluteHighestFrameRate
+ );
+ let mut camera = nokhwa::Camera::new(index, requested).expect("failed to open webcam");
+ camera.open_stream().expect("failed to open stream");
+ Self {
+ camera,
+ texbuf: vec![0; WIDTH * HEIGHT * 4],
+ }
+ }
+}
+
+impl overlay::Overlay for Overlay {
+ fn handle_binary(&mut self, ctx: &context::Context, st: &mut state::State, ost: &mut overlay::State, msg: &net::fig::BinaryMessage) -> Erm<()> {
+ Ok(())
+ }
+ fn update(&mut self, ctx: &context::Context, st: &mut state::State, ost: &mut overlay::State) -> Erm<()> {
+ let frame = self.camera.frame().unwrap();
+ frame.decode_image_to_buffer::<nokhwa::pixel_format::RgbAFormat>(&mut self.texbuf)
+ .expect("failed to decode frame");
+ Ok(())
+ }
+ fn render(&mut self, ctx: &context::Context, st: &mut state::State, ost: &mut overlay::State) -> Erm<()> {
+ Ok(())
+ }
+}