Skip to main content

libobsbot_core/transport/
mod.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! Transport abstraction for camera control transfers.
3//!
4//! Every method on [`crate::Device`] is a thin shim that calls into a
5//! `Transport` implementation. The default in-tree implementation is
6//! `usb::UsbTransport` (ioctls on `/dev/videoN` via the `uvcvideo` driver
7//! on Linux); test code substitutes a mock.
8//!
9//! The trait expresses USB Video Class class-specific control transfers
10//! identified by `(entity_id, selector)`. Higher layers know which entity
11//! they target - Camera Terminal, Processing Unit, or vendor Extension Unit.
12
13#[cfg(target_os = "linux")]
14pub mod usb;
15#[cfg(target_os = "linux")]
16pub(crate) mod uvcvideo;
17
18#[cfg(target_os = "macos")]
19pub mod macos;
20
21use crate::uvc::UvcGet;
22use crate::Result;
23
24/// Camera control transport. One instance per opened device.
25pub(crate) trait Transport: Send + Sync {
26    /// Issue a UVC class-specific `SET_CUR` on `(entity, selector)`.
27    fn uvc_set(&self, entity: u8, selector: u8, payload: &[u8]) -> Result<()>;
28
29    /// Issue a UVC class-specific `GET_*` on `(entity, selector)` and write
30    /// the response into `out`. Returns the number of bytes written.
31    fn uvc_get(&self, req: UvcGet, entity: u8, selector: u8, out: &mut [u8]) -> Result<usize>;
32}