From ea7a76a216aa6f6e6d18d5c5873230b9a59406a4 Mon Sep 17 00:00:00 2001 From: Anatoli Arkhipenko Date: Fri, 27 Sep 2024 10:00:18 -0400 Subject: [PATCH] Code cleanup --- .../esp32-cam-rtos-pio/include/logging.h | 3 ++ PlatformIO/esp32-cam-rtos-pio/src/logging.cpp | 4 +- PlatformIO/esp32-cam-rtos-pio/src/main.cpp | 41 +++---------------- .../src/streaming_all_frames.cpp | 1 - .../src/streaming_multiclient_queue.cpp | 2 - 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/PlatformIO/esp32-cam-rtos-pio/include/logging.h b/PlatformIO/esp32-cam-rtos-pio/include/logging.h index fb4eb28..f0a7295 100644 --- a/PlatformIO/esp32-cam-rtos-pio/include/logging.h +++ b/PlatformIO/esp32-cam-rtos-pio/include/logging.h @@ -2,6 +2,9 @@ // ==== includes ================================= #include "references.h" +#define MILLIS_FUNCTION xTaskGetTickCount() +// #define MILLIS_FUNCTION millis() + // ==== prototypes =============================== void setupLogging(); diff --git a/PlatformIO/esp32-cam-rtos-pio/src/logging.cpp b/PlatformIO/esp32-cam-rtos-pio/src/logging.cpp index 10bd080..12fa116 100644 --- a/PlatformIO/esp32-cam-rtos-pio/src/logging.cpp +++ b/PlatformIO/esp32-cam-rtos-pio/src/logging.cpp @@ -14,7 +14,7 @@ void setupLogging() { // === millis() - based timestamp == void printTimestamp(Print* logOutput) { char c[24]; - sprintf(c, "%10lu ", (long unsigned int) xTaskGetTickCount()/*millis()*/); + sprintf(c, "%10lu ", (long unsigned int) MILLIS_FUNCTION); logOutput->print(c); } @@ -22,7 +22,7 @@ void printTimestamp(Print* logOutput) { // start-time-based timestamp ======== void printTimestampMillis(Print* logOutput) { char c[64]; - unsigned long mm = xTaskGetTickCount();//millis(); + unsigned long mm = MILLIS_FUNCTION; int ms = mm % 1000; int s = mm / 1000; int m = s / 60; diff --git a/PlatformIO/esp32-cam-rtos-pio/src/main.cpp b/PlatformIO/esp32-cam-rtos-pio/src/main.cpp index 90b70e3..2564ca3 100644 --- a/PlatformIO/esp32-cam-rtos-pio/src/main.cpp +++ b/PlatformIO/esp32-cam-rtos-pio/src/main.cpp @@ -1,23 +1,14 @@ /* - This is a simple MJPEG streaming webserver implemented for AI-Thinker ESP32-CAM + This is a MJPEG streaming webserver implemented for AI-Thinker ESP32-CAM and ESP-EYE modules. This is tested to work with VLC and Blynk video widget and can support up to 10 simultaneously connected streaming clients. - Simultaneous streaming is implemented with dedicated FreeRTOS tasks. + Simultaneous streaming is implemented with FreeRTOS tools: queue and tasks. Inspired by and based on this Instructable: $9 RTSP Video Streamer Using the ESP32-CAM Board (https://www.instructables.com/id/9-RTSP-Video-Streamer-Using-the-ESP32-CAM-Board/) - Board: AI-Thinker ESP32-CAM or ESP-EYE - Compile as: - ESP32 Dev Module - CPU Freq: 240 - Flash Freq: 80 - Flash mode: QIO - Flash Size: 4Mb - Partrition: Minimal SPIFFS - PSRAM: Enabled */ #include "definitions.h" @@ -44,11 +35,6 @@ const char *c_pwd = AP_PWD; // Camera models overview: // https://randomnerdtutorials.com/esp32-cam-camera-pin-gpios/ -// #define CAMERA_MODEL_WROVER_KIT -// #define CAMERA_MODEL_ESP_EYE -// #define CAMERA_MODEL_M5STACK_PSRAM -// #define CAMERA_MODEL_M5STACK_WIDE -// #define CAMERA_MODEL_AI_THINKER #include "camera_pins.h" @@ -56,11 +42,11 @@ WebServer server(80); // ===== rtos task handles ========================= // Streaming is implemented with tasks: -TaskHandle_t tMjpeg; // handles client connections to the webserver -TaskHandle_t tCam; // handles getting picture frames from the camera and storing them locally +TaskHandle_t tMjpeg; // handles client connections to the webserver +TaskHandle_t tCam; // handles getting picture frames from the camera and storing them locally TaskHandle_t tStream; -uint8_t noActiveClients; // number of active clients +uint8_t noActiveClients; // number of active clients // frameSync semaphore is used to prevent streaming buffer as it is replaced with the next frame SemaphoreHandle_t frameSync = NULL; @@ -119,22 +105,6 @@ void setup() .ledc_timer = LEDC_TIMER_0, .ledc_channel = LEDC_CHANNEL_0, .pixel_format = PIXFORMAT_JPEG, - /* - FRAMESIZE_96X96, // 96x96 - FRAMESIZE_QQVGA, // 160x120 - FRAMESIZE_QCIF, // 176x144 - FRAMESIZE_HQVGA, // 240x176 - FRAMESIZE_240X240, // 240x240 - FRAMESIZE_QVGA, // 320x240 - FRAMESIZE_CIF, // 400x296 - FRAMESIZE_HVGA, // 480x320 - FRAMESIZE_VGA, // 640x480 - FRAMESIZE_SVGA, // 800x600 - FRAMESIZE_XGA, // 1024x768 - FRAMESIZE_HD, // 1280x720 - FRAMESIZE_SXGA, // 1280x1024 - FRAMESIZE_UXGA, // 1600x1200 - */ .frame_size = FRAME_SIZE, .jpeg_quality = JPEG_QUALITY, .fb_count = 2, @@ -202,6 +172,5 @@ void setup() } void loop() { - // vTaskDelay(1000); vTaskDelete(NULL); } diff --git a/PlatformIO/esp32-cam-rtos-pio/src/streaming_all_frames.cpp b/PlatformIO/esp32-cam-rtos-pio/src/streaming_all_frames.cpp index 804d92b..86cc100 100644 --- a/PlatformIO/esp32-cam-rtos-pio/src/streaming_all_frames.cpp +++ b/PlatformIO/esp32-cam-rtos-pio/src/streaming_all_frames.cpp @@ -19,7 +19,6 @@ void camCB(void* pvParameters) { // Grab a frame from the camera and allocate frame chunk for it fb = esp_camera_fb_get(); -// frameChunck_t* f = (frameChunck_t*) ps_malloc( sizeof(frameChunck_t) ); frameChunck_t* f = (frameChunck_t*) allocateMemory(NULL, sizeof(frameChunck_t), true); if ( f ) { // char* d = (char*) ps_malloc( fb->len ); diff --git a/PlatformIO/esp32-cam-rtos-pio/src/streaming_multiclient_queue.cpp b/PlatformIO/esp32-cam-rtos-pio/src/streaming_multiclient_queue.cpp index 44b1a72..9d523af 100644 --- a/PlatformIO/esp32-cam-rtos-pio/src/streaming_multiclient_queue.cpp +++ b/PlatformIO/esp32-cam-rtos-pio/src/streaming_multiclient_queue.cpp @@ -2,8 +2,6 @@ #if defined(CAMERA_MULTICLIENT_QUEUE) -// frameChunck_t frameChunck; -// streamInfo_t streamInfo; QueueHandle_t streamingClients; volatile size_t camSize; // size of the current frame, byte