Skip to content

Commit 524f81d

Browse files
Merge branch 'ref'
2 parents 4bf2b10 + 0ff456e commit 524f81d

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

examples/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
for wformat in camera.formats() {
1010
let format = wformat.unwrap();
1111
println!("{:?}", format);
12-
println!(" {:?}", camera.resolutions(&format.format).unwrap());
12+
println!(" {:?}", camera.resolutions(format.format).unwrap());
1313
}
1414

1515
camera

examples/formats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ fn main() {
99
let format = wformat.unwrap();
1010
println!("{:?}", format);
1111

12-
let resolutions = camera.resolutions(&format.format).unwrap();
12+
let resolutions = camera.resolutions(format.format).unwrap();
1313

1414
if let ResolutionInfo::Discretes(d) = resolutions {
1515
for resol in &d {
1616
println!(
1717
" {}x{} {:?}",
1818
resol.0,
1919
resol.1,
20-
camera.intervals(&format.format, *resol).unwrap()
20+
camera.intervals(format.format, *resol).unwrap()
2121
);
2222
}
2323
} else {

src/lib.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct Config<'a> {
112112
pub resolution: (u32, u32),
113113
/// FourCC of format (e.g. `b"RGB3"`). Note that case matters.
114114
/// Default is `b"YUYV"`.
115-
pub format: &'a [u8],
115+
pub format: &'a [u8; 4],
116116
/// Storage method of interlaced video. See `FIELD_*` constants.
117117
/// [Details](http://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/field-order.html#v4l2-field).
118118
/// Default is `FIELD_NONE` (progressive).
@@ -160,7 +160,7 @@ impl FormatInfo {
160160
}
161161
}
162162

163-
fn fourcc(fmt: &[u8]) -> u32 {
163+
fn fourcc(fmt: [u8; 4]) -> u32 {
164164
u32::from(fmt[0])
165165
| (u32::from(fmt[1])) << 8
166166
| (u32::from(fmt[2])) << 16
@@ -315,11 +315,7 @@ impl Camera {
315315
}
316316

317317
/// Get detailed info about the available resolutions.
318-
pub fn resolutions(&self, format: &[u8]) -> Result<ResolutionInfo> {
319-
if format.len() != 4 {
320-
return Err(Error::BadFormat);
321-
}
322-
318+
pub fn resolutions(&self, format: [u8; 4]) -> Result<ResolutionInfo> {
323319
let fourcc = FormatInfo::fourcc(format);
324320
let mut size = v4l2::Frmsizeenum::new(fourcc);
325321

@@ -354,11 +350,7 @@ impl Camera {
354350
}
355351

356352
/// Get detailed info about the available intervals.
357-
pub fn intervals(&self, format: &[u8], resolution: (u32, u32)) -> Result<IntervalInfo> {
358-
if format.len() != 4 {
359-
return Err(Error::BadFormat);
360-
}
361-
353+
pub fn intervals(&self, format: [u8; 4], resolution: (u32, u32)) -> Result<IntervalInfo> {
362354
let fourcc = FormatInfo::fourcc(format);
363355
let mut ival = v4l2::Frmivalenum::new(fourcc, resolution);
364356

@@ -559,7 +551,7 @@ impl Camera {
559551
pub fn start(&mut self, config: &Config) -> Result<()> {
560552
assert_eq!(self.state, State::Idle);
561553

562-
self.tune_format(config.resolution, config.format, config.field)?;
554+
self.tune_format(config.resolution, *config.format, config.field)?;
563555
self.tune_stream(config.interval)?;
564556
self.alloc_buffers(config.nbuffers)?;
565557

@@ -619,11 +611,7 @@ impl Camera {
619611
Ok(())
620612
}
621613

622-
fn tune_format(&self, resolution: (u32, u32), format: &[u8], field: u32) -> Result<()> {
623-
if format.len() != 4 {
624-
return Err(Error::BadFormat);
625-
}
626-
614+
fn tune_format(&self, resolution: (u32, u32), format: [u8; 4], field: u32) -> Result<()> {
627615
let fourcc = FormatInfo::fourcc(format);
628616
let mut fmt = v4l2::Format::new(resolution, fourcc, field as u32);
629617

0 commit comments

Comments
 (0)