From 0bb7b9555e7661c72dc3376cf8a001c6fd3758c8 Mon Sep 17 00:00:00 2001 From: TNeutron Date: Thu, 30 Jan 2025 19:44:01 -0500 Subject: [PATCH 1/3] fix(logging): Corrected FPS calculation Previously, last_frame was only updated once at the beginning of stream_handler, leading to incorrect FPS and avg_frame_time computation. This commit ensures last_frame is updated on each iteration after last FPS computation, resulting in accurate FPS logging. Fixes #10920 --- .../examples/Camera/CameraWebServer/app_httpd.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 6b62ee9b6cf..fb298d70716 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -216,12 +216,8 @@ static esp_err_t stream_handler(httpd_req_t *req) { size_t _jpg_buf_len = 0; uint8_t *_jpg_buf = NULL; char *part_buf[128]; - static int64_t last_frame = 0; - if (!last_frame) { - last_frame = esp_timer_get_time(); - } - + res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); if (res != ESP_OK) { return res; @@ -236,6 +232,11 @@ static esp_err_t stream_handler(httpd_req_t *req) { #endif while (true) { + + if (!last_frame) { + last_frame = esp_timer_get_time(); + } + fb = esp_camera_fb_get(); if (!fb) { log_e("Camera capture failed"); From 25484e14833991b4349fb63d9b922d19128b3aea Mon Sep 17 00:00:00 2001 From: TNeutron Date: Fri, 31 Jan 2025 14:43:08 -0500 Subject: [PATCH 2/3] Revert "fix(logging): Corrected FPS calculation" This reverts commit 0bb7b9555e7661c72dc3376cf8a001c6fd3758c8. --- .../examples/Camera/CameraWebServer/app_httpd.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index fb298d70716..6b62ee9b6cf 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -216,8 +216,12 @@ static esp_err_t stream_handler(httpd_req_t *req) { size_t _jpg_buf_len = 0; uint8_t *_jpg_buf = NULL; char *part_buf[128]; + static int64_t last_frame = 0; - + if (!last_frame) { + last_frame = esp_timer_get_time(); + } + res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); if (res != ESP_OK) { return res; @@ -232,11 +236,6 @@ static esp_err_t stream_handler(httpd_req_t *req) { #endif while (true) { - - if (!last_frame) { - last_frame = esp_timer_get_time(); - } - fb = esp_camera_fb_get(); if (!fb) { log_e("Camera capture failed"); From b4bf5783bd032ba7d89703c07e96bd623188114e Mon Sep 17 00:00:00 2001 From: TNeutron Date: Fri, 31 Jan 2025 14:49:18 -0500 Subject: [PATCH 3/3] fix(loggin): Incorrect FPS computation fixed Corrected and tested change in FPS computation, suggested by @me-no-dev and found working with correct numbers. Previously, last_frame was only updated once at the beginning of stream_handler, leading to incorrect FPS and avg_frame_time computation. This commit ensures last_frame is updated on each iteration after last FPS computation, resulting in accurate FPS logging. Fixes #10920 --- libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 6b62ee9b6cf..81d643e37ac 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -281,6 +281,8 @@ static esp_err_t stream_handler(httpd_req_t *req) { int64_t fr_end = esp_timer_get_time(); int64_t frame_time = fr_end - last_frame; + last_frame = fr_end; + frame_time /= 1000; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO uint32_t avg_frame_time = ra_filter_run(&ra_filter, frame_time);