|
7 | 7 | #include <inttypes.h> |
8 | 8 | #include <string.h> // strncmp for guid format parsing |
9 | 9 | #include <math.h> // fabsf for float comparison |
| 10 | +#include "esp_log.h" |
10 | 11 | #include "usb/usb_helpers.h" |
11 | 12 | #include "usb/uvc_host.h" |
12 | 13 | #include "uvc_check_priv.h" |
13 | 14 | #include "uvc_descriptors_priv.h" |
| 15 | +#include "sdkconfig.h" |
| 16 | + |
| 17 | +#define UVC_PRINT_SUPPORTED_FORMATS CONFIG_UVC_HOST_PRINT_SUPPORTED_FORMATS |
14 | 18 |
|
15 | 19 | #define FLOAT_EQUAL(a, b) (fabsf(a - b) < 0.0001f) // For comparing float values with acceptable difference (epsilon value) |
16 | 20 |
|
| 21 | +#if (UVC_PRINT_SUPPORTED_FORMATS) |
| 22 | +static const char *format_to_string[UVC_VS_FORMAT_MAX] = { |
| 23 | + "Undefined", |
| 24 | + "MJPEG", |
| 25 | + "YUY2", |
| 26 | + "H264", |
| 27 | + "H265", |
| 28 | +}; |
| 29 | + |
| 30 | +static inline uint32_t make_fps(uint32_t frame_interval) |
| 31 | +{ |
| 32 | + return (frame_interval != 0) ? (10000000 / frame_interval) : 0; |
| 33 | +} |
| 34 | +#endif // UVC_PRINT_SUPPORTED_FORMATS |
| 35 | + |
| 36 | + |
17 | 37 | static const uvc_vs_input_header_desc_t *uvc_desc_get_streaming_input_header(const usb_config_desc_t *cfg_desc, uint8_t bInterfaceNumber) |
18 | 38 | { |
19 | 39 | UVC_CHECK(cfg_desc, NULL); |
@@ -365,16 +385,32 @@ esp_err_t uvc_desc_get_streaming_interface_num( |
365 | 385 | } |
366 | 386 | *bcdUVC = vc_header_desc->bcdUVC; |
367 | 387 |
|
368 | | - // Find video streaming interface that offers the requested format |
369 | | - for (int streaming_if = 0; streaming_if < vc_header_desc->bInCollection; streaming_if++) { |
370 | | - uint8_t current_bInterfaceNumber = vc_header_desc->baInterfaceNr[streaming_if]; |
371 | | - if (uvc_desc_is_format_supported(cfg_desc, current_bInterfaceNumber, vs_format)) { |
372 | | - *bInterfaceNumber = current_bInterfaceNumber; |
373 | | - ret = ESP_OK; |
374 | | - break; |
375 | | - } |
| 388 | +#if (UVC_PRINT_SUPPORTED_FORMATS) |
| 389 | + uvc_host_frame_info_t frames[20]; |
| 390 | + size_t size = 20; |
| 391 | + for (int iface = 0; iface < vc_header_desc->bInCollection; iface++) { |
| 392 | + ESP_ERROR_CHECK(uvc_desc_get_frame_list(cfg_desc, uvc_index, &frames, &size)); |
| 393 | + ESP_LOGW("UVC", "Supported frame formats:"); |
| 394 | + ESP_LOGW("UVC", "\t%dx%d, %s, default FPS: %d", |
| 395 | + frames[i].h_res, frames[i].v_res, |
| 396 | + format_to_string[frames[i].format], |
| 397 | + make_fps(frames[i].default_interval)); |
376 | 398 | } |
377 | | - return ret; |
| 399 | +} |
| 400 | +#endif // UVC_PRINT_SUPPORTED_FORMATS |
| 401 | + |
| 402 | +// Find video streaming interface that offers the requested format |
| 403 | +for (int streaming_if = 0; streaming_if < vc_header_desc->bInCollection; streaming_if++) |
| 404 | +{ |
| 405 | + uint8_t current_bInterfaceNumber = vc_header_desc->baInterfaceNr[streaming_if]; |
| 406 | + if (uvc_desc_is_format_supported(cfg_desc, current_bInterfaceNumber, vs_format)) { |
| 407 | + *bInterfaceNumber = current_bInterfaceNumber; |
| 408 | + ret = ESP_OK; |
| 409 | + break; |
| 410 | + } |
| 411 | +} |
| 412 | + |
| 413 | +return ret; |
378 | 414 | } |
379 | 415 |
|
380 | 416 | bool uvc_desc_is_uvc_device(const usb_config_desc_t *cfg_desc) |
|
0 commit comments