summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordyknon dyknonr5fjp2025-02-24 21:13:53 +0900
committerdyknon dyknonr5fjp2025-02-24 21:13:53 +0900
commit4d59425948efaa3345adb02730d084dc83d559d2 (patch)
tree1c48fe8e0cea926fbf04198f0216e09818fb1e85
parent6ecbf0d55695335f52d6fcf2b6a22ed45f5e4d99 (diff)
32bit arch compat + binary w/o gui.
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml11
-rw-r--r--src/bin/sshcamera.rs6
-rw-r--r--src/bin/usshcamera.rs44
-rw-r--r--src/gtk.rs6
-rw-r--r--src/v4l2.rs28
-rw-r--r--src/v4l2abst.rs14
-rw-r--r--src/v4l2cairo.rs2
8 files changed, 83 insertions, 36 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0d8c62f..4711969 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -213,9 +213,9 @@ dependencies = [
[[package]]
name = "gdk-pixbuf"
-version = "0.20.7"
+version = "0.20.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6efc7705f7863d37b12ad6974cbb310d35d054f5108cdc1e69037742f573c4c"
+checksum = "7563afd6ff0a221edfbb70a78add5075b8d9cb48e637a40a24c3ece3fea414d0"
dependencies = [
"gdk-pixbuf-sys",
"gio",
@@ -527,9 +527,9 @@ dependencies = [
[[package]]
name = "log"
-version = "0.4.22"
+version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "Could not get crate checksum"
+checksum = "3d6ea2a48c204030ee31a7d7fc72c93294c92fe87ecb1789881c9543516e1a0d"
[[package]]
name = "memchr"
diff --git a/Cargo.toml b/Cargo.toml
index 6f02405..0acbe72 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,8 +8,15 @@ libc = "0.2"
chrono = { version = "0.4", features = ["now"] }
v4l2-sys = { version = "1", path = "v4l2-sys/" }
anyhow = "1"
-gtk4 = { version = "0.9", features = ["v4_12"] }
-zune-jpeg = "0.4"
+gtk4 = { version = "0.9", features = ["v4_12"], optional = true}
+zune-jpeg = { version = "0.4", optional = true }
+
+[features]
+gui = ["gtk4", "zune-jpeg"]
+default = ["gui"]
[[bin]]
name = "sshcamera"
+required-features = ["gui"]
+[[bin]]
+name = "usshcamera"
diff --git a/src/bin/sshcamera.rs b/src/bin/sshcamera.rs
index 02c8778..270700a 100644
--- a/src/bin/sshcamera.rs
+++ b/src/bin/sshcamera.rs
@@ -17,11 +17,7 @@ fn main() -> Result<ExitCode>{
let Some(arg1) = args.next() else{
return Err(anyhow!("Give me args"));
};
- if arg1.contains('/'){
- if args.next() != None{
- return Err(anyhow!("too many args"));
- }
-
+ if args.len() == 0{
let v = V4l2::open(arg1)?;
// TODO: It should be better.
diff --git a/src/bin/usshcamera.rs b/src/bin/usshcamera.rs
new file mode 100644
index 0000000..6d73e92
--- /dev/null
+++ b/src/bin/usshcamera.rs
@@ -0,0 +1,44 @@
+use anyhow::{anyhow, Result};
+use sshcamera::v4l2::{Device as V4l2, Field};
+use sshcamera::v4l2abst::CaptStream;
+use sshcamera::io::RWBundle;
+use std::env;
+use std::io::{self, Read as _, Write as _};
+
+fn main() -> Result<()>{
+ let mut args = env::args();
+ if args.next() == None{
+ return Err(anyhow!("arg0 is not present??"));
+ }
+ let Some(arg1) = args.next() else{
+ return Err(anyhow!("Give me args"));
+ };
+ if args.next() != None{
+ return Err(anyhow!("too many args"));
+ }
+
+ let v = V4l2::open(arg1)?;
+
+ // TODO: It should be better.
+ let mut c = v.captstream_builder()?
+ .set_pixelformat("MJPG".into())
+ //.set_pixelformat("YUYV".into())
+ .set_field(Field::None)
+ .build()?;
+ assert!(["YUYV", "MJPG"].contains(&c.pixelformat().as_str()));
+ assert!(c.field() == Field::None);
+
+ let mut io = RWBundle(io::stdin(), io::stdout());
+ loop{
+ CaptStream::next(&mut c, |frame|{
+ frame.serialize(&mut io)?;
+ io.flush()?;
+ let mut rb = [0];
+ io.read_exact(&mut rb)?;
+ if rb[0] != 0x2e{
+ return Err(anyhow!("protocol error"));
+ }
+ Ok(())
+ })??;
+ }
+}
diff --git a/src/gtk.rs b/src/gtk.rs
index c72b524..6ebd992 100644
--- a/src/gtk.rs
+++ b/src/gtk.rs
@@ -1,3 +1,5 @@
+#![cfg(feature = "gui")]
+
use anyhow::{anyhow, Result};
use gtk4::{self as gtk, glib, cairo, gio};
use gtk4::prelude::*;
@@ -203,9 +205,5 @@ pub fn main(src: impl Source + 'static) -> Result<glib::ExitCode>{
0
}
});
- //app.connect_activate(clone!{
- // #[strong] apps,
- // move |app| activate(app, apps.clone())
- //});
Ok(app.run())
}
diff --git a/src/v4l2.rs b/src/v4l2.rs
index a8aff0c..59b7ab4 100644
--- a/src/v4l2.rs
+++ b/src/v4l2.rs
@@ -178,23 +178,23 @@ impl BufAttrs{
buf.assume_init()
};
let now_wallclock = Local::now();
- let mut timestamp = c::timespec{
- tv_sec: self.timestamp.tv_sec as _,
- tv_nsec: self.timestamp.tv_usec as _,
- };
- timestamp.tv_nsec *= 1000;
+ let timestamp_sec = self.timestamp.tv_sec as c::time_t;
+ #[allow(unused_assignments)] // it is used to copy type...
+ let mut timestamp_nsec = now_monotonic.tv_nsec;
+ timestamp_nsec = self.timestamp.tv_usec as _;
+ timestamp_nsec *= 1000;
let (mut so, mut nso, future);
- if now_monotonic.tv_sec < timestamp.tv_sec
- || now_monotonic.tv_sec == timestamp.tv_sec
- && now_monotonic.tv_nsec < timestamp.tv_nsec
+ if now_monotonic.tv_sec < timestamp_sec
+ || now_monotonic.tv_sec == timestamp_sec
+ && now_monotonic.tv_nsec < timestamp_nsec
{
future = true;
- so = timestamp.tv_sec - now_monotonic.tv_sec;
- nso = timestamp.tv_nsec - now_monotonic.tv_nsec;
+ so = timestamp_sec - now_monotonic.tv_sec;
+ nso = timestamp_nsec - now_monotonic.tv_nsec;
}else{
future = false;
- so = now_monotonic.tv_sec - timestamp.tv_sec;
- nso = now_monotonic.tv_nsec - timestamp.tv_nsec;
+ so = now_monotonic.tv_sec - timestamp_sec;
+ nso = now_monotonic.tv_nsec - timestamp_nsec;
}
if nso < 0{
nso += 1000_000_000;
@@ -221,8 +221,8 @@ impl Debug for BufAttrs{
.field("flags", &self.flags)
.field("field", &self.field)
.field("timestamp", &timeval{
- tv_sec: self.timestamp.tv_sec,
- tv_usec: self.timestamp.tv_usec,
+ tv_sec: self.timestamp.tv_sec as _,
+ tv_usec: self.timestamp.tv_usec as _,
})
.field("sequence", &self.sequence)
.finish()
diff --git a/src/v4l2abst.rs b/src/v4l2abst.rs
index baefea0..03983bc 100644
--- a/src/v4l2abst.rs
+++ b/src/v4l2abst.rs
@@ -2,7 +2,6 @@ use anyhow::{anyhow, Result};
use crate::v4l2;
use chrono::{DateTime, Local};
use std::io::{Read, Write};
-use std::mem::size_of;
pub struct Frame<'a>{
pub format: v4l2::ImageFormat,
@@ -17,10 +16,10 @@ impl<'a> Frame<'a>{
dst.write_all(&u32::to_be_bytes(self.format.into()))?;
dst.write_all(&self.timestamp.timestamp_subsec_nanos().to_be_bytes())?;
dst.write_all(&self.timestamp.timestamp().to_be_bytes())?;
- dst.write_all(&self.width.to_be_bytes())?;
- dst.write_all(&self.height.to_be_bytes())?;
- dst.write_all(&self.stride.to_be_bytes())?;
- dst.write_all(&self.buf.len().to_be_bytes())?;
+ dst.write_all(&(self.width as u64).to_be_bytes())?;
+ dst.write_all(&(self.height as u64).to_be_bytes())?;
+ dst.write_all(&(self.stride as u64).to_be_bytes())?;
+ dst.write_all(&(self.buf.len() as u64).to_be_bytes())?;
dst.write_all(self.buf)?;
Ok(())
}
@@ -39,11 +38,12 @@ impl<'a> Frame<'a>{
Ok(i64::from_be_bytes(tmp))
}
fn usize(&mut self) -> Result<usize>{
- let mut tmp: [u8; size_of::<usize>()] = Default::default();
+ let mut tmp: [u8; 8] = Default::default();
self.0.read_exact(&mut tmp)?;
- Ok(usize::from_be_bytes(tmp))
+ Ok(u64::from_be_bytes(tmp) as usize)
}
}
+ // XXX: limit allocation length?
let mut src = Rh(src);
let format = src.u32()?.into();
let (ns, s) = (src.u32()?, src.i64()?);
diff --git a/src/v4l2cairo.rs b/src/v4l2cairo.rs
index 83be3b1..de89df8 100644
--- a/src/v4l2cairo.rs
+++ b/src/v4l2cairo.rs
@@ -1,3 +1,5 @@
+#![cfg(feature = "gui")]
+
use anyhow::{anyhow, Result};
use gtk4 as gtk;
use gtk::prelude::*;