mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-28 00:10:50 +08:00
perf(video): 减少闲置缓冲并容忍短时输出背压
This commit is contained in:
@@ -42,6 +42,12 @@ pub struct CaptureMeta {
|
||||
pub sequence: u64,
|
||||
}
|
||||
|
||||
fn append_capture_plane(dst: &mut Vec<u8>, mapping: &[u8], offset: usize, bytes: usize) {
|
||||
let start = offset.min(mapping.len());
|
||||
let end = offset.saturating_add(bytes).min(mapping.len());
|
||||
dst.extend_from_slice(&mapping[start..end]);
|
||||
}
|
||||
|
||||
/// When set, DV ioctls use the subdev (rkcif: video node has no DV ioctls).
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BridgeContext {
|
||||
@@ -629,12 +635,12 @@ impl CaptureStream {
|
||||
}
|
||||
let mapping = &self.mappings[index][plane_idx];
|
||||
let start = data_offset.min(mapping.len());
|
||||
let end = (data_offset + bytes_used).min(mapping.len());
|
||||
let end = data_offset.saturating_add(bytes_used).min(mapping.len());
|
||||
total += end.saturating_sub(start);
|
||||
}
|
||||
|
||||
dst.resize(total, 0);
|
||||
let mut cursor = 0usize;
|
||||
dst.clear();
|
||||
dst.reserve(total);
|
||||
for (plane_idx, plane) in dqbuf.planes_iter().enumerate() {
|
||||
let bytes_used = *plane.bytesused as usize;
|
||||
let data_offset = plane.data_offset.copied().unwrap_or(0) as usize;
|
||||
@@ -642,14 +648,7 @@ impl CaptureStream {
|
||||
continue;
|
||||
}
|
||||
let mapping = &self.mappings[index][plane_idx];
|
||||
let start = data_offset.min(mapping.len());
|
||||
let end = (data_offset + bytes_used).min(mapping.len());
|
||||
let len = end.saturating_sub(start);
|
||||
if len == 0 {
|
||||
continue;
|
||||
}
|
||||
dst[cursor..cursor + len].copy_from_slice(&mapping[start..end]);
|
||||
cursor += len;
|
||||
append_capture_plane(dst, mapping, data_offset, bytes_used);
|
||||
}
|
||||
|
||||
self.queue_buffer(index as u32)
|
||||
@@ -1153,9 +1152,23 @@ fn set_fps(fd: &File, queue: QueueType, fps: u32) -> std::result::Result<(), ioc
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{open_capture_device, DvTimingsSignature, NativeHdmirxState};
|
||||
use super::{append_capture_plane, open_capture_device, DvTimingsSignature, NativeHdmirxState};
|
||||
use crate::video::format::PixelFormat;
|
||||
|
||||
#[test]
|
||||
fn capture_planes_append_without_stale_bytes_or_reallocation() {
|
||||
let mut data = vec![99; 64];
|
||||
let pointer = data.as_ptr();
|
||||
data.clear();
|
||||
append_capture_plane(&mut data, &[1, 2, 3, 4], 1, 2);
|
||||
append_capture_plane(&mut data, &[5, 6, 7], 0, 10);
|
||||
assert_eq!(data, [2, 3, 5, 6, 7]);
|
||||
assert_eq!(data.as_ptr(), pointer);
|
||||
append_capture_plane(&mut data, &[8], usize::MAX, usize::MAX);
|
||||
append_capture_plane(&mut data, &[8], 0, 0);
|
||||
assert_eq!(data, [2, 3, 5, 6, 7]);
|
||||
}
|
||||
|
||||
fn timing() -> DvTimingsSignature {
|
||||
DvTimingsSignature {
|
||||
width: 1920,
|
||||
|
||||
Reference in New Issue
Block a user