@@ -32,7 +32,28 @@ static size_t app_get_min_buf_size(const struct video_format *const fmt)
3232 }
3333}
3434
35- static void app_add_format (uint32_t pixfmt , uint16_t width , uint16_t height )
35+ static bool app_is_standard_format (uint32_t pixfmt )
36+ {
37+ return pixfmt == VIDEO_PIX_FMT_GREY || pixfmt == VIDEO_PIX_FMT_JPEG ||
38+ pixfmt == VIDEO_PIX_FMT_YUYV ;
39+ }
40+
41+ /* Check whether the video device supports one of the wisespread image sensor formats */
42+ static bool app_has_standard_formats (void )
43+ {
44+ for (int i = 0 ;; i ++ ) {
45+ uint32_t pixfmt = video_caps .format_caps [i ].pixelformat ;
46+
47+ if (pixfmt == 0 ) {
48+ return false;
49+ }
50+ if (app_is_standard_format (pixfmt )) {
51+ return true;
52+ }
53+ }
54+ }
55+
56+ static void app_add_format (uint32_t pixfmt , uint16_t width , uint16_t height , bool has_std_fmts )
3657{
3758 struct video_format fmt = {
3859 .pixelformat = pixfmt ,
@@ -42,6 +63,11 @@ static void app_add_format(uint32_t pixfmt, uint16_t width, uint16_t height)
4263 };
4364 int ret ;
4465
66+ /* If the system has any standard pixel format, only propose them to the host */
67+ if (has_std_fmts && !app_is_standard_format (pixfmt )) {
68+ return ;
69+ }
70+
4571 /* Set the format to get the pitch */
4672 ret = video_set_format (video_dev , & fmt );
4773 if (ret != 0 ) {
@@ -60,13 +86,16 @@ static void app_add_format(uint32_t pixfmt, uint16_t width, uint16_t height)
6086/* Submit to UVC only the formats expected to be working (enough memory for the size, etc.) */
6187static void app_add_filtered_formats (void )
6288{
89+ const bool has_std_fmts = app_has_standard_formats ();
90+
6391 for (int i = 0 ; video_caps .format_caps [i ].pixelformat != 0 ; i ++ ) {
6492 const struct video_format_cap * vcap = & video_caps .format_caps [i ];
6593
66- app_add_format (vcap -> pixelformat , vcap -> width_min , vcap -> height_min );
94+ app_add_format (vcap -> pixelformat , vcap -> width_min , vcap -> height_min , has_std_fmts );
6795
6896 if (vcap -> width_min != vcap -> width_max || vcap -> height_min != vcap -> height_max ) {
69- app_add_format (vcap -> pixelformat , vcap -> width_max , vcap -> height_max );
97+ app_add_format (vcap -> pixelformat , vcap -> width_max , vcap -> height_max ,
98+ has_std_fmts );
7099 }
71100 }
72101}
0 commit comments