77#include <inttypes.h>
88#include <string.h> // strncmp for guid format parsing
99#include <math.h> // fabsf for float comparison
10+ #include "esp_log.h"
1011#include "usb/usb_helpers.h"
1112#include "usb/uvc_host.h"
1213#include "uvc_check_priv.h"
1314#include "uvc_descriptors_priv.h"
15+ #include "sdkconfig.h"
16+
17+ #define UVC_PRINT_SUPPORTED_FORMATS CONFIG_UVC_HOST_PRINT_SUPPORTED_FORMATS
1418
1519#define FLOAT_EQUAL (a , b ) (fabsf(a - b) < 0.0001f) // For comparing float values with acceptable difference (epsilon value)
1620
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+
1737static const uvc_vs_input_header_desc_t * uvc_desc_get_streaming_input_header (const usb_config_desc_t * cfg_desc , uint8_t bInterfaceNumber )
1838{
1939 UVC_CHECK (cfg_desc , NULL );
@@ -365,6 +385,21 @@ esp_err_t uvc_desc_get_streaming_interface_num(
365385 }
366386 * bcdUVC = vc_header_desc -> bcdUVC ;
367387
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+ for (uint8_t i = 0 ; i < size ; i ++ ) {
395+ ESP_LOGW ("UVC" , "\t%dx%d, %s, default FPS: %d" ,
396+ frames [i ].h_res , frames [i ].v_res ,
397+ format_to_string [frames [i ].format ],
398+ make_fps (frames [i ].default_interval ));
399+ }
400+ }
401+ #endif // UVC_PRINT_SUPPORTED_FORMATS
402+
368403 // Find video streaming interface that offers the requested format
369404 for (int streaming_if = 0 ; streaming_if < vc_header_desc -> bInCollection ; streaming_if ++ ) {
370405 uint8_t current_bInterfaceNumber = vc_header_desc -> baInterfaceNr [streaming_if ];
@@ -374,6 +409,7 @@ esp_err_t uvc_desc_get_streaming_interface_num(
374409 break ;
375410 }
376411 }
412+
377413 return ret ;
378414}
379415
0 commit comments