Open a V4L2 device node (e.g., "/dev/video0"). 打开 V4L2 设备节点(如 "/dev/video0")。 Opens with `O_RDWR` (read/write) without `O_NONBLOCK`. Without `O_NONBLOCK`, `DQBUF` will block until a frame is ready, which is the desired behavior for maximum throughput. 以 `O_RDWR`(读写)模式打开,不加 `O_NONBLOCK`。 不加 `O_NONBLOCK` 时,`DQBUF` 会阻塞直到帧就绪, 这是取得最大吞吐量的期望行为。
(path: &str)
| 374 | /// 不加 `O_NONBLOCK` 时,`DQBUF` 会阻塞直到帧就绪, |
| 375 | /// 这是取得最大吞吐量的期望行为。 |
| 376 | pub fn open_device(path: &str) -> io::Result<RawFd> { |
| 377 | let c_path = |
| 378 | std::ffi::CString::new(path).map_err(|_| io::Error::other("invalid device path"))?; |
| 379 | let fd = unsafe { libc::open(c_path.as_ptr(), libc::O_RDWR) }; |
| 380 | if fd == -1 { |
| 381 | Err(io::Error::last_os_error()) |
| 382 | } else { |
| 383 | Ok(fd) |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /// Close a V4L2 device file descriptor. |
| 388 | /// 关闭 V4L2 设备文件描述符。 |