Skip to content

Commit 371ef0e

Browse files
author
Alain Volmat
committed
samples: usb: uvc: select applicable resolutions from range
Select from commonly used resolution when the video device advertise capabilities using range. Signed-off-by: Alain Volmat <[email protected]>
1 parent d017970 commit 371ef0e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

samples/subsys/usb/uvc/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@
66
# tree, you cannot use them in your own application.
77
source "samples/subsys/usb/common/Kconfig.sample_usbd"
88

9+
menu "UVC specific configuration"
10+
11+
config VIDEO_MAX_RANGE_RESOLUTIONS
12+
int "Maximum number of intermediate resolutions"
13+
default 5
14+
help
15+
Control the maximum number of resolution that will be advertised
16+
to the USB client in case of the video capture supports a range
17+
of resolutions.
18+
19+
endmenu
20+
921
source "Kconfig.zephyr"

samples/subsys/usb/uvc/src/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,62 @@ static void app_add_format(uint32_t pixfmt, uint16_t width, uint16_t height, boo
8383
uvc_add_format(uvc_dev, &fmt);
8484
}
8585

86+
struct video_resolution {
87+
uint16_t width;
88+
uint16_t height;
89+
};
90+
91+
static struct video_resolution video_common_fmts[] = {
92+
{ .width = 3840, .height = 2160, }, /* UHD */
93+
{ .width = 1920, .height = 1080, }, /* FHD */
94+
{ .width = 1280, .height = 1024, }, /* SXGA */
95+
{ .width = 1280, .height = 720, }, /* HD */
96+
{ .width = 800, .height = 600, }, /* SVGA */
97+
{ .width = 854, .height = 480, }, /* WVGA */
98+
{ .width = 640, .height = 480, }, /* VGA */
99+
{ .width = 320, .height = 240, }, /* QVGA */
100+
{ .width = 160, .height = 120, }, /* QQVGA */
101+
};
102+
86103
/* Submit to UVC only the formats expected to be working (enough memory for the size, etc.) */
87104
static void app_add_filtered_formats(void)
88105
{
89106
const bool has_std_fmts = app_has_standard_formats();
90107

91108
for (int i = 0; video_caps.format_caps[i].pixelformat != 0; i++) {
92109
const struct video_format_cap *vcap = &video_caps.format_caps[i];
110+
int range_count = 0;
93111

94112
app_add_format(vcap->pixelformat, vcap->width_min, vcap->height_min, has_std_fmts);
95113

96114
if (vcap->width_min != vcap->width_max || vcap->height_min != vcap->height_max) {
97115
app_add_format(vcap->pixelformat, vcap->width_max, vcap->height_max,
98116
has_std_fmts);
99117
}
118+
119+
if (vcap->width_step == 0 && vcap->height_step == 0) {
120+
continue;
121+
}
122+
123+
/* RANGE Resolution processing */
124+
for (int j = 0; j < ARRAY_SIZE(video_common_fmts); j++) {
125+
if (range_count >= CONFIG_VIDEO_MAX_RANGE_RESOLUTIONS) {
126+
break;
127+
}
128+
if (!IN_RANGE(video_common_fmts[j].width,
129+
vcap->width_min, vcap->width_max) ||
130+
!IN_RANGE(video_common_fmts[j].height,
131+
vcap->height_min, vcap->height_max)) {
132+
continue;
133+
}
134+
if ((video_common_fmts[j].width - vcap->width_min) % vcap->width_step ||
135+
(video_common_fmts[j].height - vcap->height_min) % vcap->height_step) {
136+
continue;
137+
}
138+
139+
app_add_format(vcap->pixelformat, video_common_fmts[j].width,
140+
video_common_fmts[j].height, has_std_fmts);
141+
}
100142
}
101143
}
102144

0 commit comments

Comments
 (0)