Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving conflicts with @raymanfx upsteam and adding @anatawa12 changes and an offset fix. #1

Open
wants to merge 16 commits into
base: mplane
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
- package-ecosystem: github-actions
directory: /.github/workflows/
schedule:
interval: weekly
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- run: sudo apt-get install libv4l-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- run: sudo apt-get install libv4l-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -53,7 +53,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -70,7 +70,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- run: sudo apt-get install libv4l-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -93,7 +93,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- run: sudo apt-get install libv4l-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ Multi-planar capture will not be targeted in the near future unless someone else
### Added
- Basic multi-planar streaming support

## [0.14.0] - 2023-05-13
### Added
- Expose raw file descriptor of streams through `Stream::handle()`
### Changed
- Updated `bindgen` dependency to 0.65.1
### Fixed
- Use proper C FFI struct field for `Integer64` controls
- Fix example in README.md to account for the negotiated pixelformat

## [0.13.1] - 2022-12-08
### Fixed
- Do not block when the device is disconnected
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ readme = "README.md"
repository= "https://github.com/raymanfx/libv4l-rs"

[dependencies]
bitflags = "1.2.1"
bitflags = "2"
libc = "0.2"
v4l-sys = { path = "v4l-sys", version = "0.2.1", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.2.1", package="v4l2-sys-mit", optional = true }
v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }

[dev-dependencies]
glium = "0.27.0"
jpeg-decoder = "0.2.1"
jpeg-decoder = "0.3.0"

[features]
default = ["v4l2"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() {
fmt.width = 1280;
fmt.height = 720;
fmt.fourcc = FourCC::new(b"YUYV");
dev.set_format(&fmt).expect("Failed to write format");
let fmt = dev.set_format(&fmt).expect("Failed to write format");

// The actual format chosen by the device driver may differ from what we
// requested! Print it out to get an idea of what is actually used now.
Expand Down
7 changes: 3 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bitflags::bitflags;
use std::fmt;

use crate::timestamp::Timestamp;
Expand Down Expand Up @@ -39,8 +38,8 @@ impl Type {
}
}

bitflags! {
#[allow(clippy::unreadable_literal)]
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Flags: u32 {
/// Buffer is mapped
const MAPPED = 0x00000001;
Expand Down Expand Up @@ -91,7 +90,7 @@ impl Default for Flags {

impl From<u32> for Flags {
fn from(flags: u32) -> Self {
Self::from_bits_truncate(flags)
Self::from_bits_retain(flags)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/capability.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use bitflags::bitflags;
use std::{fmt, str};

use crate::v4l_sys::*;

bitflags! {
#[allow(clippy::unreadable_literal)]
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Flags: u32 {
const VIDEO_CAPTURE = 0x00000001;
const VIDEO_OUTPUT = 0x00000002;
Expand Down Expand Up @@ -46,7 +45,7 @@ bitflags! {

impl From<u32> for Flags {
fn from(flags: u32) -> Self {
Self::from_bits_truncate(flags)
Self::from_bits_retain(flags)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/control.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bitflags::bitflags;
use std::convert::{TryFrom, TryInto};
use std::{ffi, fmt, mem, str};

Expand Down Expand Up @@ -63,8 +62,8 @@ impl fmt::Display for Type {
}
}

bitflags! {
#[allow(clippy::unreadable_literal)]
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Flags: u32 {
const DISABLED = 0x0001;
const GRABBED = 0x0002;
Expand All @@ -85,7 +84,7 @@ bitflags! {

impl From<u32> for Flags {
fn from(flags: u32) -> Self {
Self::from_bits_truncate(flags)
Self::from_bits_retain(flags)
}
}

Expand Down
33 changes: 10 additions & 23 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::{io, mem};

use libc;

use crate::control;
use crate::capability::Capabilities;
use crate::control::{self, Control, Description};
use crate::v4l2;
use crate::v4l2::videodev::v4l2_ext_controls;
use crate::v4l_sys::*;
use crate::{capability::Capabilities, control::Control};

pub const PLANES_ONE: bool = false;
pub const PLANES_MANY: bool = true;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Device {
}

/// Returns the supported controls for a device such as gain, focus, white balance, etc.
pub fn query_controls(&self) -> io::Result<Vec<control::Description>> {
pub fn query_controls(&self) -> io::Result<Vec<Description>> {
let mut controls = Vec::new();
unsafe {
let mut v4l2_ctrl: v4l2_query_ext_ctrl = mem::zeroed();
Expand All @@ -115,7 +115,7 @@ impl Device {
) {
Ok(_) => {
// get the basic control information
let mut control = control::Description::from(v4l2_ctrl);
let mut control = Description::from(v4l2_ctrl);

// if this is a menu control, enumerate its items
if control.typ == control::Type::Menu
Expand Down Expand Up @@ -175,29 +175,16 @@ impl Device {
Ok(controls)
}

/// Returns the control value for an ID
/// Returns the current control value from its [`Description`]
///
/// # Arguments
///
/// * `id` - Control identifier
pub fn control(&self, id: u32) -> io::Result<Control> {
/// * `desc` - Control description
pub fn control(&self, desc: &Description) -> io::Result<Control> {
unsafe {
let mut queryctrl = v4l2_query_ext_ctrl {
id,
..mem::zeroed()
};
v4l2::ioctl(
self.handle().fd(),
v4l2::vidioc::VIDIOC_QUERY_EXT_CTRL,
&mut queryctrl as *mut _ as *mut std::os::raw::c_void,
)?;

// determine the control type
let description = control::Description::from(queryctrl);

// query the actual control value
let mut v4l2_ctrl = v4l2_ext_control {
id,
id: desc.id,
..mem::zeroed()
};
let mut v4l2_ctrls = v4l2_ext_controls {
Expand All @@ -211,7 +198,7 @@ impl Device {
&mut v4l2_ctrls as *mut _ as *mut std::os::raw::c_void,
)?;

let value = match description.typ {
let value = match desc.typ {
control::Type::Integer64 => {
control::Value::Integer(v4l2_ctrl.__bindgen_anon_1.value64)
}
Expand All @@ -229,7 +216,7 @@ impl Device {
}
};

Ok(Control { id, value })
Ok(Control { id: desc.id, value })
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/format/description.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bitflags::bitflags;
use std::{fmt, str};

use crate::format::FourCC;
use crate::v4l_sys::*;

bitflags! {
#[allow(clippy::unreadable_literal)]
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Flags : u32 {
const COMPRESSED = 0x0001;
const EMULATED = 0x0002;
Expand All @@ -16,7 +15,7 @@ bitflags! {

impl From<u32> for Flags {
fn from(flags: u32) -> Self {
Self::from_bits_truncate(flags)
Self::from_bits_retain(flags)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bitflags::bitflags;
use std::{convert::TryFrom, fmt, mem};

use crate::v4l_sys::*;
Expand All @@ -21,16 +20,16 @@ pub use quantization::Quantization;
pub mod transfer;
pub use transfer::TransferFunction;

bitflags! {
#[allow(clippy::unreadable_literal)]
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Flags : u32 {
const PREMUL_ALPHA = 0x00000001;
}
}

impl From<u32> for Flags {
fn from(flags: u32) -> Self {
Self::from_bits_truncate(flags)
Self::from_bits_retain(flags)
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/io/mmap/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ impl<'a> Arena<'a> {
// each plane has to be mapped separately
let mut planes = Vec::new();
for plane in &v4l2_planes {
let (length, offset) = if !self.buf_type.planar() {
(v4l2_buf.length as usize, v4l2_buf.m.offset as libc::off_t)
} else {
(plane.length as usize, plane.m.mem_offset as libc::off_t)
};
let ptr = v4l2::mmap(
ptr::null_mut(),
plane.length as usize,
length,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_SHARED,
self.handle.fd(),
plane.m.mem_offset as libc::off_t,
offset,
)?;

planes.push(slice::from_raw_parts_mut::<u8>(
ptr as *mut u8, plane.length as usize
ptr as *mut u8, length,
));
}

Expand Down
7 changes: 3 additions & 4 deletions src/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use bitflags::bitflags;
use std::fmt;

bitflags! {
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Capabilities: u32 {
#[allow(clippy::unreadable_literal)]
const TIME_PER_FRAME = 0x1000;
}
}

impl From<u32> for Capabilities {
fn from(caps: u32) -> Self {
Self::from_bits_truncate(caps)
Self::from_bits_retain(caps)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/v4l2/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod detail {
) -> *mut std::os::raw::c_void {
// libv4l expects `request` to be a u64, but this is not guaranteed on all platforms.
// For the default CI platform (x86_64) clippy will complain about a useless conversion.
#![allow(clippy::useless_conversion)]
#![allow(clippy::useless_conversion, clippy::unnecessary_cast)]
v4l2_mmap(
start,
length.try_into().expect("usize -> c size_t failed"),
Expand All @@ -51,6 +51,7 @@ mod detail {
)
}
pub unsafe fn munmap(start: *mut std::os::raw::c_void, length: usize) -> std::os::raw::c_int {
#![allow(clippy::useless_conversion)]
v4l2_munmap(start, length.try_into().expect("usize -> c size_t failed"))
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/video/capture/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use bitflags::bitflags;
use std::{fmt, mem};

use crate::fraction::Fraction;
use crate::parameters::Capabilities;
use crate::v4l_sys::*;

bitflags! {
bitflags::bitflags! {
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct Modes: u32 {
const HIGH_QUALITY = 0x1000;
}
}

impl From<u32> for Modes {
fn from(caps: u32) -> Self {
Self::from_bits_truncate(caps)
Self::from_bits_retain(caps)
}
}

Expand Down
Loading