@@ -76,20 +76,62 @@ 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 = 3840 , .height = 2160 , }, /* UHD */
86+ { .width = 1920 , .height = 1080 , }, /* FHD */
87+ { .width = 1280 , .height = 1024 , }, /* SXGA */
88+ { .width = 1280 , .height = 720 , }, /* HD */
89+ { .width = 800 , .height = 600 , }, /* SVGA */
90+ { .width = 854 , .height = 480 , }, /* WVGA */
91+ { .width = 640 , .height = 480 , }, /* VGA */
92+ { .width = 320 , .height = 240 , }, /* QVGA */
93+ { .width = 160 , .height = 120 , }, /* QQVGA */
94+ };
95+
7996/* Submit to UVC only the formats expected to be working (enough memory for the size, etc.) */
8097static 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 range_count = 0 ;
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 );
92110 }
111+
112+ if (vcap -> width_step == 0 && vcap -> height_step == 0 ) {
113+ continue ;
114+ }
115+
116+ /* RANGE Resolution processing */
117+ for (int j = 0 ; j < ARRAY_SIZE (video_common_fmts ); j ++ ) {
118+ if (range_count >= CONFIG_VIDEO_MAX_RANGE_RESOLUTIONS ) {
119+ break ;
120+ }
121+ if (!IN_RANGE (video_common_fmts [j ].width ,
122+ vcap -> width_min , vcap -> width_max ) ||
123+ !IN_RANGE (video_common_fmts [j ].height ,
124+ vcap -> height_min , vcap -> height_max )) {
125+ continue ;
126+ }
127+ if ((video_common_fmts [j ].width - vcap -> width_min ) % vcap -> width_step ||
128+ (video_common_fmts [j ].height - vcap -> height_min ) % vcap -> height_step ) {
129+ continue ;
130+ }
131+
132+ app_add_format (vcap -> pixelformat , video_common_fmts [j ].width ,
133+ video_common_fmts [j ].height , has_sup_fmts );
134+ }
93135 }
94136}
95137
0 commit comments