From 3087a2a1a99e233715b7ba8e95fae6f87ccec102 Mon Sep 17 00:00:00 2001 From: odudex Date: Wed, 29 Apr 2026 09:26:15 -0300 Subject: [PATCH] fix(simulator): MacOS simulator nits --- main/pages/capture_entropy.c | 4 ---- main/qr/scanner.c | 16 +++++++++++----- simulator/CMakeLists.txt | 4 ++++ .../platform/video_sim/v4l2_capture_macos.mm | 5 +++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/main/pages/capture_entropy.c b/main/pages/capture_entropy.c index f28fcb7..15e780d 100644 --- a/main/pages/capture_entropy.c +++ b/main/pages/capture_entropy.c @@ -31,13 +31,9 @@ static const char *TAG = "capture_entropy"; #define CAMERA_INPUT_WIDTH 1280 #define CAMERA_INPUT_HEIGHT 960 #define CAMERA_INPUT_CROP CAMERA_INPUT_HEIGHT -#define CAMERA_INPUT_CROP_OFFSET_X \ - ((CAMERA_INPUT_WIDTH - CAMERA_INPUT_CROP) / 2) -#define CAMERA_INPUT_CROP_OFFSET_Y 0 #define CAMERA_DIM_MIN \ ((BSP_LCD_H_RES) < (BSP_LCD_V_RES) ? (BSP_LCD_H_RES) : (BSP_LCD_V_RES)) #define CAMERA_PPA_FRAG ((CAMERA_DIM_MIN * 16) / CAMERA_INPUT_CROP) -#define CAMERA_PPA_SCALE ((float)CAMERA_PPA_FRAG / 16.0f) #define CAMERA_SIZE ((CAMERA_INPUT_CROP * CAMERA_PPA_FRAG) / 16) #define CAMERA_WIDTH CAMERA_SIZE #define CAMERA_HEIGHT CAMERA_SIZE diff --git a/main/qr/scanner.c b/main/qr/scanner.c index 05b5742..fd9bdd0 100644 --- a/main/qr/scanner.c +++ b/main/qr/scanner.c @@ -42,13 +42,8 @@ #define CAMERA_INPUT_HEIGHT 960 #define CAMERA_INPUT_CROP \ ((CAMERA_TARGET * 2 <= 960) ? (CAMERA_TARGET * 2) : 960) -#define CAMERA_INPUT_CROP_OFFSET_X \ - ((CAMERA_INPUT_WIDTH - CAMERA_INPUT_CROP) / 2) -#define CAMERA_INPUT_CROP_OFFSET_Y \ - ((CAMERA_INPUT_HEIGHT - CAMERA_INPUT_CROP) / 2) // Largest Q4.4 scale <= target/crop, and the exact preview size it yields. #define CAMERA_PPA_FRAG ((CAMERA_TARGET * 16) / CAMERA_INPUT_CROP) -#define CAMERA_PPA_SCALE ((float)CAMERA_PPA_FRAG / 16.0f) #define CAMERA_SCREEN_SIZE ((CAMERA_INPUT_CROP * CAMERA_PPA_FRAG) / 16) #define CAMERA_SCREEN_WIDTH CAMERA_SCREEN_SIZE #define CAMERA_SCREEN_HEIGHT CAMERA_SCREEN_SIZE @@ -812,6 +807,17 @@ static void camera_video_frame_operation(uint8_t *camera_buf, return; } + static bool resolution_mismatch_logged = false; + if (!resolution_mismatch_logged && (camera_buf_hes != CAMERA_INPUT_WIDTH || + camera_buf_ves != CAMERA_INPUT_HEIGHT)) { + ESP_LOGW(TAG, + "Camera resolution %" PRIu32 "x%" PRIu32 + " differs from expected %dx%d; cropping dynamically", + camera_buf_hes, camera_buf_ves, CAMERA_INPUT_WIDTH, + CAMERA_INPUT_HEIGHT); + resolution_mismatch_logged = true; + } + uint8_t *back_buffer = (current_display_buffer == display_buffer_a) ? display_buffer_b : display_buffer_a; diff --git a/simulator/CMakeLists.txt b/simulator/CMakeLists.txt index 5d8da38..555e23f 100644 --- a/simulator/CMakeLists.txt +++ b/simulator/CMakeLists.txt @@ -218,6 +218,10 @@ if(SIM_WEBCAM) ${COREVIDEO_FRAMEWORK} ${FOUNDATION_FRAMEWORK} ) + set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/platform/video_sim/v4l2_capture_macos.mm + PROPERTIES COMPILE_FLAGS "-fobjc-arc" + ) else() add_library(v4l2_capture STATIC ${CMAKE_CURRENT_SOURCE_DIR}/platform/video_sim/v4l2_capture.c diff --git a/simulator/platform/video_sim/v4l2_capture_macos.mm b/simulator/platform/video_sim/v4l2_capture_macos.mm index 97be1b2..5ba34c0 100644 --- a/simulator/platform/video_sim/v4l2_capture_macos.mm +++ b/simulator/platform/video_sim/v4l2_capture_macos.mm @@ -112,8 +112,8 @@ - (void)captureOutput:(AVCaptureOutput *)output static bool parse_device_index(const char *device, int *out_index) { if (!device || !out_index) return false; - if (strncmp(device, "/dev/video", 9) == 0) { - device += 9; + if (strncmp(device, "/dev/video", 10) == 0) { + device += 10; } char *end = NULL; long idx = strtol(device, &end, 10); @@ -292,6 +292,7 @@ void v4l2_capture_close(v4l2_capture_t *cap) { } cap->output = nil; cap->delegate = nil; + cap->queue = nil; free(cap->rgb565); cap->rgb565 = NULL;