Skip to content

Commit

Permalink
Simplify examples
Browse files Browse the repository at this point in the history
Get rid of the clap dev dependency.

Signed-off-by: Christopher N. Hesse <[email protected]>
  • Loading branch information
raymanfx committed Jul 21, 2021
1 parent 8ff1ecb commit 788dd4f
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 517 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Multi-planar capture will not be targeted in the near future unless someone else



## [0.13.0]
### Changed
- Simplified examples, removing clap argument parsing

## [0.12.1] - 2020-05-01
### Fixed
- Update the buffer index for output streams
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ v4l-sys = { path = "v4l-sys", version = "0.2.0", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.2.0", package="v4l2-sys-mit", optional = true }

[dev-dependencies]
clap = "^2.33.0"
glium = "0.27.0"

[features]
Expand Down
38 changes: 0 additions & 38 deletions examples/capture_controls.rs

This file was deleted.

67 changes: 0 additions & 67 deletions examples/capture_device.rs

This file was deleted.

2 changes: 0 additions & 2 deletions examples/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate v4l;

use v4l::context;

fn main() {
Expand Down
17 changes: 17 additions & 0 deletions examples/controls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::io;

use v4l::prelude::*;

fn main() -> io::Result<()> {
let path = "/dev/video0";
println!("Using device: {}\n", path);

let dev = Device::with_path(path)?;
let controls = dev.query_controls()?;

for control in controls {
println!("{}", control);
}

Ok(())
}
38 changes: 9 additions & 29 deletions examples/device.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
extern crate clap;
extern crate v4l;
use std::io;

use clap::{App, Arg};
use v4l::prelude::*;

fn main() {
let matches = App::new("v4l device")
.version("0.2")
.author("Christopher N. Hesse <[email protected]>")
.about("Video4Linux device example")
.arg(
Arg::with_name("device")
.short("d")
.long("device")
.value_name("INDEX or PATH")
.help("Capture device node path or index (default: 0)")
.takes_value(true),
)
.get_matches();

// Determine which device to use
let mut path: String = matches
.value_of("device")
.unwrap_or("/dev/video0")
.to_string();
if path.parse::<u64>().is_ok() {
path = format!("/dev/video{}", path);
}
fn main() -> io::Result<()> {
let path = "/dev/video0";
println!("Using device: {}\n", path);
let dev = Device::with_path(path).unwrap();

let caps = dev.query_caps().unwrap();
let dev = Device::with_path(path)?;

let caps = dev.query_caps()?;
println!("Device capabilities:\n{}", caps);

let controls = dev.query_controls().unwrap();
let controls = dev.query_controls()?;
println!("Device controls:");
let mut max_name_len = 0;
for ctrl in &controls {
Expand All @@ -50,4 +28,6 @@ fn main() {
indent = max_name_len
);
}

Ok(())
}
38 changes: 38 additions & 0 deletions examples/formats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::io;

use v4l::prelude::*;
use v4l::video::Capture;

fn main() -> io::Result<()> {
let path = "/dev/video0";
println!("Using device: {}\n", path);

let dev = Device::with_path(path)?;

let format = dev.format()?;
println!("Active format:\n{}", format);

let params = dev.params()?;
println!("Active parameters:\n{}", params);

println!("Available formats:");
for format in dev.enum_formats()? {
println!(" {} ({})", format.fourcc, format.description);

for framesize in dev.enum_framesizes(format.fourcc)? {
for discrete in framesize.size.to_discrete() {
println!(" Size: {}", discrete);

for frameinterval in
dev.enum_frameintervals(framesize.fourcc, discrete.width, discrete.height)?
{
println!(" Interval: {}", frameinterval);
}
}
}

println!("")
}

Ok(())
}
63 changes: 17 additions & 46 deletions examples/glium.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,43 @@
extern crate clap;
extern crate v4l;
use std::io;
use std::sync::{mpsc, RwLock};
use std::thread;
use std::time::Instant;

use clap::{App, Arg};
use glium::index::PrimitiveType;
use glium::{glutin, Surface};
use glium::{implement_vertex, program, uniform};
use std::sync::{mpsc, RwLock};
use std::thread;
use std::time::Instant;
use v4l::buffer::Type;
use v4l::io::traits::CaptureStream;
use v4l::prelude::*;
use v4l::video::capture::Parameters;
use v4l::video::Capture;
use v4l::{Format, FourCC};

fn main() {
let matches = App::new("v4l capture")
.version("0.2")
.author("Christopher N. Hesse <[email protected]>")
.about("Video4Linux device example")
.arg(
Arg::with_name("device")
.short("d")
.long("device")
.value_name("INDEX or PATH")
.help("Device node path or index (default: 0)")
.takes_value(true),
)
.arg(
Arg::with_name("buffers")
.short("b")
.long("buffers")
.value_name("INT")
.help("Number of buffers to allocate (default: 4)")
.takes_value(true),
)
.get_matches();

// Determine which device to use
let mut path: String = matches
.value_of("device")
.unwrap_or("/dev/video0")
.to_string();
if path.parse::<u64>().is_ok() {
path = format!("/dev/video{}", path);
}
fn main() -> io::Result<()> {
let path = "/dev/video0";
println!("Using device: {}\n", path);

// Allocate 4 buffers by default
let buffers = matches.value_of("buffers").unwrap_or("4").to_string();
let buffers = buffers.parse::<u32>().unwrap();
let buffer_count = 4;

let mut format: Format;
let params: Parameters;

let dev = RwLock::new(Device::with_path(path.clone()).unwrap());
let dev = RwLock::new(Device::with_path(path.clone())?);
{
let dev = dev.write().unwrap();
format = dev.format().unwrap();
params = dev.params().unwrap();
format = dev.format()?;
params = dev.params()?;

// enforce RGB3
format.fourcc = FourCC::new(b"RGB3");
format = dev.set_format(&format).unwrap();
format = dev.set_format(&format)?;

if format.fourcc != FourCC::new(b"RGB3") {
println!("RGB3 not supported by the device, but required by this example!");
return;
return Err(io::Error::new(
io::ErrorKind::Other,
"RGB3 not supported by the device, but required by this example!",
));
}
}

Expand Down Expand Up @@ -153,7 +123,8 @@ fn main() {
let mut dev = dev.write().unwrap();

// Setup a buffer stream
let mut stream = MmapStream::with_buffers(&mut *dev, Type::VideoCapture, buffers).unwrap();
let mut stream =
MmapStream::with_buffers(&mut *dev, Type::VideoCapture, buffer_count).unwrap();

loop {
let (buf, _) = stream.next().unwrap();
Expand Down
38 changes: 0 additions & 38 deletions examples/output_controls.rs

This file was deleted.

Loading

0 comments on commit 788dd4f

Please sign in to comment.