Skip to content

Commit

Permalink
device: add a few capability-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnurou committed Mar 8, 2023
1 parent c576e4f commit 7e29b41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/examples/vicodec_test/device_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn run<F: FnMut(&[u8])>(
mut save_output: F,
) {
let device = Device::open(device_path, DeviceConfig::new()).expect("Failed to open device");
let caps = &device.capability;
let caps = device.caps();
println!(
"Opened device: {}\n\tdriver: {}\n\tbus: {}\n\tcapabilities: {}",
caps.card, caps.driver, caps.bus_info, caps.capabilities
Expand Down
7 changes: 6 additions & 1 deletion lib/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DeviceConfig {

/// An opened V4L2 device. `Queue` objects can be instantiated from it.
pub struct Device {
pub capability: Capability,
capability: Capability,
fd: File,
used_queues: Mutex<BTreeSet<QueueType>>,
}
Expand Down Expand Up @@ -91,6 +91,11 @@ impl Device {
// Safe because we are constructing a file from Fd we just opened.
Ok(Device::new(unsafe { File::from_raw_fd(fd) })?)
}

/// Returns the capabilities of the device, i.e. the result of QUERYCAPS.
pub fn caps(&self) -> &Capability {
&self.capability
}
}

impl AsRawFd for Device {
Expand Down
13 changes: 13 additions & 0 deletions lib/src/ioctl/querycap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ pub struct Capability {
pub device_caps: Option<Capabilities>,
}

impl Capability {
/// Returns the set of capabilities of the hardware as a whole.
pub fn capabilities(&self) -> Capabilities {
self.capabilities
}

/// Returns the capabilities that apply to the currently opened V4L2 node.
pub fn device_caps(&self) -> Capabilities {
self.device_caps
.unwrap_or_else(|| self.capabilities.difference(Capabilities::DEVICE_CAPS))
}
}

impl QueryCap for Capability {
fn from(qcap: bindings::v4l2_capability) -> Self {
Capability {
Expand Down

0 comments on commit 7e29b41

Please sign in to comment.