onix 0.2.0

Decode image files using V4L2
Documentation
use crate::info::DeviceInfo;
use crate::topology::Topology;
use crate::video::{
    BufType, Buffer, Capability, Control, ExportBuffer, ExtControls, FmtDesc, Format,
    FrameSizeEnum, QueryCtrl, RequestBuffers, Selection,
};
use rustix::fd::BorrowedFd;
use rustix::io;
use rustix::ioctl::{
    ioctl, Getter, NoArg, NoneOpcode, ReadOpcode, ReadWriteOpcode, Setter, Updater, WriteOpcode,
};

macro_rules! ioctl_readwrite {
    ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
        pub unsafe fn $name(fd: BorrowedFd, data: &mut $ty) -> io::Result<()> {
            type Opcode = ReadWriteOpcode<$ioty, $nr, $ty>;
            Ok(ioctl(fd, Updater::<Opcode, $ty>::new(data))?)
        }
    };
}

macro_rules! ioctl_read {
    ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
        pub unsafe fn $name(fd: BorrowedFd) -> io::Result<$ty> {
            type Opcode = ReadOpcode<$ioty, $nr, $ty>;
            Ok(ioctl(fd, Getter::<Opcode, $ty>::new())?)
        }
    };
}

macro_rules! ioctl_write_ptr {
    ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
        pub unsafe fn $name(fd: BorrowedFd, data: &$ty) -> io::Result<()> {
            type Opcode = WriteOpcode<$ioty, $nr, $ty>;
            Ok(ioctl(fd, Setter::<Opcode, $ty>::new(*data))?)
        }
    };
}

macro_rules! ioctl_none {
    ($name:ident, $ioty:expr, $nr:expr) => {
        pub unsafe fn $name(fd: BorrowedFd) -> io::Result<()> {
            type Opcode = NoneOpcode<$ioty, $nr, ()>;
            Ok(ioctl(fd, NoArg::<Opcode>::new())?)
        }
    };
}

ioctl_readwrite!(device_info, b'|', 0x00, DeviceInfo);
ioctl_readwrite!(get_topology, b'|', 0x04, Topology);
ioctl_read!(request_alloc, b'|', 0x05, i32);
ioctl_none!(request_queue, b'|', 0x80);
ioctl_none!(request_reinit, b'|', 0x81);

ioctl_read!(querycap, b'V', 0, Capability);
ioctl_readwrite!(enum_fmt, b'V', 2, FmtDesc);
ioctl_readwrite!(g_fmt, b'V', 4, Format);
ioctl_readwrite!(s_fmt, b'V', 5, Format);
ioctl_readwrite!(reqbufs, b'V', 8, RequestBuffers);
ioctl_readwrite!(querybuf, b'V', 9, Buffer);
ioctl_readwrite!(qbuf, b'V', 15, Buffer);
ioctl_readwrite!(expbuf, b'V', 16, ExportBuffer);
ioctl_readwrite!(dqbuf, b'V', 17, Buffer);
ioctl_write_ptr!(streamon, b'V', 18, BufType);
ioctl_write_ptr!(streamoff, b'V', 19, BufType);
ioctl_readwrite!(g_ctrl, b'V', 27, Control);
ioctl_readwrite!(s_ctrl, b'V', 28, Control);
ioctl_readwrite!(queryctrl, b'V', 36, QueryCtrl);
ioctl_readwrite!(s_ext_ctrls, b'V', 72, ExtControls);
ioctl_readwrite!(enum_framesizes, b'V', 74, FrameSizeEnum);
ioctl_readwrite!(g_selection, b'V', 94, Selection);
ioctl_readwrite!(s_selection, b'V', 95, Selection);