summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
6 files changed, 70 insertions, 30 deletions
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::*;