MCPcopy Create free account
hub / github.com/RustCV/RustCV / allocate_buffers

Method allocate_buffers

rustcv-camera/src/backend/linux/mod.rs:402–424  ·  view source on GitHub ↗

Allocate mmap buffers from the kernel. 从内核分配 mmap 缓冲区。 Steps: 1. VIDIOC_REQBUFS — ask kernel for N buffers 2. For each buffer: VIDIOC_QUERYBUF → mmap() 步骤: 1. VIDIOC_REQBUFS —— 向内核请求 N 个缓冲区 2. 对每个缓冲区:VIDIOC_QUERYBUF → mmap()

(&mut self, count: u32)

Source from the content-addressed store, hash-verified

400 /// 1. VIDIOC_REQBUFS —— 向内核请求 N 个缓冲区
401 /// 2. 对每个缓冲区:VIDIOC_QUERYBUF → mmap()
402 fn allocate_buffers(&mut self, count: u32) -> Result<()> {
403 let req = v4l2_sys::request_buffers(self.fd, count)?;
404 let actual_count = req.count;
405
406 if actual_count < 2 {
407 return Err(CameraError::BufferAllocationFailed);
408 }
409
410 let mut buffers = Vec::with_capacity(actual_count as usize);
411
412 for i in 0..actual_count {
413 let buf = v4l2_sys::query_buffer(self.fd, i)?;
414 let length = buf.length as usize;
415 let offset = unsafe { buf.m.offset };
416
417 let ptr = v4l2_sys::mmap_buffer(self.fd, length, offset)?;
418
419 buffers.push(MmapBuffer { ptr, length });
420 }
421
422 self.buffers = buffers;
423 Ok(())
424 }
425}
426
427impl Drop for V4l2Backend {

Callers 1

openMethod · 0.80

Calls 3

request_buffersFunction · 0.85
query_bufferFunction · 0.85
mmap_bufferFunction · 0.85

Tested by

no test coverage detected