Skip to content

Commit b0f77aa

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 b0bfd59 commit b0f77aa

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-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 APP_VIDEO_MAX_RESOLUTIONS
12+
int "Maximum number of advertised 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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,65 @@ static void app_add_format(uint32_t pixfmt, uint32_t width, uint32_t height, boo
7676
uvc_add_format(uvc_dev, &fmt);
7777
}
7878

79+
struct video_resolution {
80+
uint16_t width;
81+
uint16_t height;
82+
};
83+
84+
static struct video_resolution video_common_fmts[] = {
85+
{ .width = 160, .height = 120, }, /* QQVGA */
86+
{ .width = 320, .height = 240, }, /* QVGA */
87+
{ .width = 640, .height = 480, }, /* VGA */
88+
{ .width = 854, .height = 480, }, /* WVGA */
89+
{ .width = 800, .height = 600, }, /* SVGA */
90+
{ .width = 1280, .height = 720, }, /* HD */
91+
{ .width = 1280, .height = 1024, }, /* SXGA */
92+
{ .width = 1920, .height = 1080, }, /* FHD */
93+
{ .width = 3840, .height = 2160, }, /* UHD */
94+
};
95+
7996
/* Submit to UVC only the formats expected to be working (enough memory for the size, etc.) */
8097
static void app_add_filtered_formats(void)
8198
{
8299
const bool has_sup_fmts = app_has_supported_format();
83100

84101
for (int i = 0; video_caps.format_caps[i].pixelformat != 0; i++) {
85102
const struct video_format_cap *vcap = &video_caps.format_caps[i];
103+
int count = 1;
86104

87105
app_add_format(vcap->pixelformat, vcap->width_min, vcap->height_min, has_sup_fmts);
88106

89107
if (vcap->width_min != vcap->width_max || vcap->height_min != vcap->height_max) {
90108
app_add_format(vcap->pixelformat, vcap->width_max, vcap->height_max,
91109
has_sup_fmts);
110+
count++;
111+
}
112+
113+
if (vcap->width_step == 0 && vcap->height_step == 0) {
114+
continue;
115+
}
116+
117+
/* RANGE Resolution processing */
118+
for (int j = 0; j < ARRAY_SIZE(video_common_fmts); j++) {
119+
if (count >= CONFIG_APP_VIDEO_MAX_RESOLUTIONS) {
120+
break;
121+
}
122+
123+
if (!IN_RANGE(video_common_fmts[j].width,
124+
vcap->width_min, vcap->width_max) ||
125+
!IN_RANGE(video_common_fmts[j].height,
126+
vcap->height_min, vcap->height_max)) {
127+
continue;
128+
}
129+
130+
if ((video_common_fmts[j].width - vcap->width_min) % vcap->width_step ||
131+
(video_common_fmts[j].height - vcap->height_min) % vcap->height_step) {
132+
continue;
133+
}
134+
135+
app_add_format(vcap->pixelformat, video_common_fmts[j].width,
136+
video_common_fmts[j].height, has_sup_fmts);
137+
count++;
92138
}
93139
}
94140
}

0 commit comments

Comments
 (0)