Set the video format (VIDIOC_S_FMT). 设置视频格式(VIDIOC_S_FMT)。 The driver may adjust the requested values to the nearest supported ones. The returned struct contains the actual applied values. 驱动可能将请求值调整为最接近的支持值。返回的结构体包含实际应用的值。
(fd: RawFd, width: u32, height: u32, fourcc: u32)
| 186 | /// The returned struct contains the actual applied values. |
| 187 | /// 驱动可能将请求值调整为最接近的支持值。返回的结构体包含实际应用的值。 |
| 188 | pub fn set_format(fd: RawFd, width: u32, height: u32, fourcc: u32) -> io::Result<v4l2_format> { |
| 189 | let mut fmt: v4l2_format = unsafe { std::mem::zeroed() }; |
| 190 | fmt.type_ = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 191 | |
| 192 | // Access the pix member of the anonymous union via raw pointer. |
| 193 | // 通过裸指针访问匿名联合体的 pix 成员。 |
| 194 | let pix = unsafe { &mut fmt.fmt.pix }; |
| 195 | pix.width = width; |
| 196 | pix.height = height; |
| 197 | pix.pixelformat = fourcc; |
| 198 | pix.field = V4L2_FIELD_NONE; |
| 199 | |
| 200 | unsafe { |
| 201 | v4l2_ioctl(fd, VIDIOC_S_FMT, &mut fmt as *mut _ as *mut libc::c_void)?; |
| 202 | } |
| 203 | Ok(fmt) |
| 204 | } |
| 205 | |
| 206 | // ─── Frame rate ───────────────────────────────────────────────────────────── |
| 207 |
no test coverage detected