From e6acdbe8a13cbe92b00603e79f25b8ed5bebb105 Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Sun, 6 Nov 2022 11:02:32 +0100 Subject: [PATCH 1/3] Grab frame before snapshot --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 5a40f5c..9918c10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,6 +149,7 @@ void handle_snapshot() return; } + cam.run(); if (cam.getfb() == nullptr) { web_server.send(404, "text/plain", "Unable to obtain frame buffer from the camera"); From 11dfe22807d91fff2d0fe271219355f3fbec108c Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Sun, 6 Nov 2022 20:37:48 +0100 Subject: [PATCH 2/3] - Do not copy the framebuffer - Typo in logging --- src/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9918c10..4aca079 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,19 +150,18 @@ void handle_snapshot() } cam.run(); - if (cam.getfb() == nullptr) + auto fb_len = cam.getSize(); + auto fb = (const char*)cam.getfb(); + if (fb == nullptr) { web_server.send(404, "text/plain", "Unable to obtain frame buffer from the camera"); return; } - auto fb_len = cam.getSize(); - auto fb = (const char *)memcpy(new uint8_t[fb_len], cam.getfb(), fb_len); web_server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); web_server.setContentLength(fb_len); web_server.send(200, "image/jpeg", ""); web_server.sendContent(fb, fb_len); - delete[] fb; } void handle_flash() @@ -220,7 +219,7 @@ void start_rtsp_server() camera_init_result = initialize_camera(); if (camera_init_result != ESP_OK) { - log_e("Failed to initialize camera: 0x%0xd. Type: %s, frame size: %s, frame buffers: %s, frame rate: %s ms, jpeg quality: %s", camera_init_result, camera_config_val, frame_size_val, frame_buffers_val, frame_duration_val, jpeg_quality_val); + log_e("Failed to initialize camera: 0x%0x. Type: %s, frame size: %s, frame buffers: %s, frame rate: %s ms, jpeg quality: %s", camera_init_result, camera_config_val, frame_size_val, frame_buffers_val, frame_duration_val, jpeg_quality_val); return; } From 370f3c805cca21d05d584b4ecc0ff95104c21642 Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Sun, 6 Nov 2022 20:44:50 +0100 Subject: [PATCH 3/3] - remove old frames from the frame buffer before sending snapshot --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4aca079..586ea96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,7 +149,11 @@ void handle_snapshot() return; } - cam.run(); + // Remove old images stored in the framebuffer + auto frame_buffers = atoi(frame_buffers_val); + while (frame_buffers--) + cam.run(); + auto fb_len = cam.getSize(); auto fb = (const char*)cam.getfb(); if (fb == nullptr) @@ -188,7 +192,6 @@ void on_config_saved() log_v("on_config_saved"); // Set flash led intensity analogWrite(LED_FLASH, atoi(flash_led_intensity_val)); - config_changed = true; }