uvc: clamp to configfs maxpacket
This commit is contained in:
parent
298aeabc10
commit
cfe2430521
@ -301,6 +301,22 @@ impl UvcConfig {
|
|||||||
max_packet
|
max_packet
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if let Some(cfg_max) = read_u32_file(
|
||||||
|
"/sys/kernel/config/usb_gadget/lesavka/functions/uvc.usb0/streaming_maxpacket",
|
||||||
|
) {
|
||||||
|
if max_packet > cfg_max {
|
||||||
|
eprintln!(
|
||||||
|
"[lesavka-uvc] configfs maxpacket {}: clamp max_packet {} -> {}",
|
||||||
|
cfg_max, max_packet, cfg_max
|
||||||
|
);
|
||||||
|
max_packet = cfg_max;
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"[lesavka-uvc] configfs maxpacket {}: max_packet {}",
|
||||||
|
cfg_max, max_packet
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
if env::var("LESAVKA_UVC_BULK").is_ok() {
|
if env::var("LESAVKA_UVC_BULK").is_ok() {
|
||||||
max_packet = max_packet.min(512);
|
max_packet = max_packet.min(512);
|
||||||
} else {
|
} else {
|
||||||
@ -773,6 +789,12 @@ fn env_u32_opt(name: &str) -> Option<u32> {
|
|||||||
env::var(name).ok().and_then(|v| v.parse::<u32>().ok())
|
env::var(name).ok().and_then(|v| v.parse::<u32>().ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_u32_file(path: &str) -> Option<u32> {
|
||||||
|
std::fs::read_to_string(path)
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.trim().parse::<u32>().ok())
|
||||||
|
}
|
||||||
|
|
||||||
fn adjust_length(mut bytes: Vec<u8>, w_length: u16) -> Vec<u8> {
|
fn adjust_length(mut bytes: Vec<u8>, w_length: u16) -> Vec<u8> {
|
||||||
let want = (w_length as usize).min(UVC_DATA_SIZE);
|
let want = (w_length as usize).min(UVC_DATA_SIZE);
|
||||||
if bytes.len() > want {
|
if bytes.len() > want {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user