Skip to content

UVC: move application decision to the application #93192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

josuah
Copy link
Contributor

@josuah josuah commented Jul 16, 2025

Dependency:

The USB class was doing arbitrary "best guess" choices about what pixel formats or resolutions to include (all of them, and min/max only when format are ranges).

  • In the class, add a uvc_add_format() to allow the application to push the exact format it wants
  • In the class, remove all format-related video API calls away from the UVC stack, to let the application handle this
  • In the sample, filter out formats that are not supported by the host whenever standard formats are also supported
  • In the sample, filter out formats that are too large for the memory

What is added in the sample is a matter of application choices, and trapping these choices in the UVC class prevented the samples to work without manual configuration on diverse platform.

MacOS support still not confirmed.
Linux, Windows, Android tested functional with the hardware I have.

@josuah josuah marked this pull request as draft July 16, 2025 10:22
@github-actions github-actions bot added area: USB Universal Serial Bus area: Samples Samples labels Jul 16, 2025
@github-actions github-actions bot requested a review from nashif July 16, 2025 10:23
@josuah
Copy link
Contributor Author

josuah commented Jul 16, 2025

This is not ready for review, will be properly split in individual commits, and "un-drafted" when ready...

josuah added 4 commits July 18, 2025 21:22
Some OSes like MacOS request only the UVC 1.1 probe/commit messages, and
ignore the extra fields of the probe/commit struct: bUsage, bBitDepthLuma,
bmSettings, bMaxNumberOfRefFramesPlus1, bmRateControlModes
bmLayoutPerStream. Allow arbitrary size to safely be used by using a local
`struct uvc_probe` and memcpy() the result from/to buffers.
Given this is 48 bytes of temporary stack memory and control operation,
performance and memory footprint are not observed.

Signed-off-by: Josuah Demangeon <me@josuah.net>
In some cases, setup->wLength is shorter than the allocated buffer size.
This lead to responses larger than what the host requested, which it
rejected. Fix it by using the minimum between the allocated size, the
struct size, and the wLength requested.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The UVC class was deciding the format list for itself, which does not
allow the application to convert the format, or filter which formats
to expose to thoe host. Remove this logic out of the UVC class and
expose an extra API to add formats to the list.

Signed-off-by: Josuah Demangeon <me@josuah.net>
The UVC class now allows the application to select the formats itself.
Leverage this from the sample to filter out any format that is not
expected to work (buffer too big) or less likely supported by the host
when more standard formats are available.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah force-pushed the pr_uvc_no_policy branch from 70ab814 to 4833717 Compare July 18, 2025 21:48
@josuah josuah changed the title [WIP] UVC: remove the policies from the class UVC: remove the policies from the class Jul 18, 2025
@josuah
Copy link
Contributor Author

josuah commented Jul 18, 2025

Force-push:

  • Rebase on top of the MacOSX-related bugfix

Windows, Linux, MacOSX, Android are now expected to all work.

Tested with nRF52840-DK:

west build --board=nrf52840dk/nrf52840 --snippet=video-sw-generator samples/subsys/usb/uvc/

Tested with Arduino Nicla Vision:

west build --board=arduino_nicla_vision/stm32h747xx/m7 samples/subsys/usb/uvc/

@josuah josuah added area: Video Video subsystem Release Notes Required Release notes required for this change labels Jul 18, 2025
Copy link

@josuah josuah changed the title UVC: remove the policies from the class UVC: move application decision to the application Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: USB Universal Serial Bus area: Video Video subsystem Release Notes Required Release notes required for this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants