@@ -32,7 +32,28 @@ static size_t app_get_min_buf_size(const struct video_format *const fmt)
32
32
}
33
33
}
34
34
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 )
36
57
{
37
58
struct video_format fmt = {
38
59
.pixelformat = pixfmt ,
@@ -42,6 +63,11 @@ static void app_add_format(uint32_t pixfmt, uint16_t width, uint16_t height)
42
63
};
43
64
int ret ;
44
65
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
+
45
71
/* Set the format to get the pitch */
46
72
ret = video_set_format (video_dev , & fmt );
47
73
if (ret != 0 ) {
@@ -60,13 +86,16 @@ static void app_add_format(uint32_t pixfmt, uint16_t width, uint16_t height)
60
86
/* Submit to UVC only the formats expected to be working (enough memory for the size, etc.) */
61
87
static void app_add_filtered_formats (void )
62
88
{
89
+ const bool has_std_fmts = app_has_standard_formats ();
90
+
63
91
for (int i = 0 ; video_caps .format_caps [i ].pixelformat != 0 ; i ++ ) {
64
92
const struct video_format_cap * vcap = & video_caps .format_caps [i ];
65
93
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 );
67
95
68
96
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 );
70
99
}
71
100
}
72
101
}
0 commit comments