From 63c5ec7390efeffe9e15f5e7a9edf856ae0b96b3 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Mon, 11 Sep 2023 16:28:52 +0200 Subject: [PATCH] qemu-usb: reduce overhead of capturing one picture from 3 USB packet to 1 packet per picture. Set the maximal supported payload to the size of one picture + the size of the required protocol header. --- repos/libports/src/lib/qemu-usb/dev-webcam.c | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/repos/libports/src/lib/qemu-usb/dev-webcam.c b/repos/libports/src/lib/qemu-usb/dev-webcam.c index fc97bf9fe9..1bc5a57807 100644 --- a/repos/libports/src/lib/qemu-usb/dev-webcam.c +++ b/repos/libports/src/lib/qemu-usb/dev-webcam.c @@ -412,6 +412,13 @@ static unsigned max_frame_size(unsigned const format) formats[format].bpp / 8; } +static void set_video_and_payload_size(unsigned const index, + struct vs_probe_control * const control) +{ + control->dwMaxVideoFrameSize = max_frame_size(index); + control->dwMaxPayLoadTransferSize = max_frame_size(index) + sizeof(struct payload_header); +} + static void usb_webcam_init_state(USBWebcamState *state) { state->delayed_packet = 0; @@ -666,9 +673,10 @@ static void usb_webcam_handle_control(USBDevice * const dev, (req->bFormatIndex != DEVICE_VS_FORMAT_YUV)) break; - vs_probe_state.bFormatIndex = req->bFormatIndex; - vs_probe_state.dwMaxVideoFrameSize = max_frame_size(vs_probe_state.bFormatIndex - 1); - vs_probe_state.dwMaxPayLoadTransferSize = max_frame_size(vs_probe_state.bFormatIndex - 1) / 2; + vs_probe_state.bFormatIndex = req->bFormatIndex; + + set_video_and_payload_size(vs_probe_state.bFormatIndex - 1, + &vs_probe_state); if (cs == VS_COMMIT_CONTROL) { bool const notify = vs_commit_state.bFormatIndex != vs_probe_state.bFormatIndex; @@ -800,10 +808,10 @@ static void usb_webcam_register_types(void) yuv_desc.dwMaxVideoFrameBufferSize = max_frame_size(DEVICE_VS_FORMAT_YUV - 1); } - vs_commit_state.dwFrameInterval = frame_interval; - vs_commit_state.dwMaxVideoFrameSize = max_frame_size(active_format()); - vs_commit_state.dwMaxPayLoadTransferSize = max_frame_size(active_format()) / 2; - vs_commit_state.dwClockFrequency = config.fps; + vs_commit_state.dwFrameInterval = frame_interval; + vs_commit_state.dwClockFrequency = config.fps; + + set_video_and_payload_size(active_format(), &vs_commit_state); vs_probe_state = vs_commit_state;