3636#define EXAMPLE_NUMBER_OF_STREAMS (1) // This example shows how to control multiple UVC streams. Set this to 1 if you camera offers only 1 stream
3737#define EXAMPLE_USE_SDCARD (0) // SD card on P4 evaluation board will be initialized
3838
39+ #define UVC_DESC_DWFRAMEINTERVAL_TO_FPS (dwFrameInterval ) (((dwFrameInterval) != 0) ? 10000000 / ((float)(dwFrameInterval)) : 0)
40+
3941static const char * TAG = "UVC example" ;
4042static QueueHandle_t rx_frames_queue [EXAMPLE_NUMBER_OF_STREAMS ];
4143static bool dev_connected = false;
4244
45+ static const char * FORMAT_STR [] = {
46+ "FORMAT_UNDEFINED" ,
47+ "FORMAT_MJPEG" ,
48+ "FORMAT_YUY2" ,
49+ "FORMAT_H264" ,
50+ "FORMAT_H265" ,
51+ };
52+
4353bool frame_callback (const uvc_host_frame_t * frame , void * user_ctx )
4454{
4555 assert (frame );
@@ -279,6 +289,27 @@ void app_init_sdcard(void)
279289}
280290#endif // EXAMPLE_USE_SDCARD
281291
292+ static void uvc_event_cb (const uvc_host_driver_event_data_t * event , void * user_ctx )
293+ {
294+ switch (event -> type ) {
295+ case UVC_HOST_DRIVER_EVENT_DEVICE_CONNECTED : {
296+ ESP_LOGI (TAG , "Device connected, addr: %d" , event -> device_connected .dev_addr );
297+
298+ size_t list_size = event -> device_connected .frame_info_num ;
299+ uvc_host_frame_info_t * frame_info = (uvc_host_frame_info_t * )calloc (list_size , sizeof (uvc_host_frame_info_t ));
300+ assert (frame_info );
301+ uvc_host_get_frame_list (event -> device_connected .dev_addr , event -> device_connected .uvc_stream_index , (uvc_host_frame_info_t (* )[])frame_info , & list_size );
302+ for (int i = 0 ; i < list_size ; i ++ ) {
303+ ESP_LOGI (TAG , "Camera format: %s %d*%d@%.1ffps" , FORMAT_STR [frame_info [i ].format ], frame_info [i ].h_res , frame_info [i ].v_res , UVC_DESC_DWFRAMEINTERVAL_TO_FPS (frame_info [i ].default_interval ));
304+ }
305+ free (frame_info );
306+ break ;
307+ }
308+ default :
309+ break ;
310+ }
311+ }
312+
282313/**
283314 * @brief Main application
284315 */
@@ -311,6 +342,7 @@ void app_main(void)
311342 .driver_task_priority = EXAMPLE_USB_HOST_PRIORITY + 1 ,
312343 .xCoreID = tskNO_AFFINITY ,
313344 .create_background_task = true,
345+ .event_cb = uvc_event_cb ,
314346 };
315347 ESP_ERROR_CHECK (uvc_host_install (& uvc_driver_config ));
316348
@@ -321,5 +353,5 @@ void app_main(void)
321353 vTaskDelay (pdMS_TO_TICKS (1000 ));
322354 task_created = xTaskCreatePinnedToCore (frame_handling_task , "h265_handling" , 4096 , (void * )& stream_h265_config , EXAMPLE_USB_HOST_PRIORITY - 3 , NULL , tskNO_AFFINITY );
323355 assert (task_created == pdTRUE );
324- #endif // EXAMPLE_USE_SDCARD
356+ #endif // EXAMPLE_NUMBER_OF_STREAMS > 1
325357}
0 commit comments