Parcourir la source

Grow the persistent stream buffer without double PSRAM allocation

SybexXx il y a 1 jour
Parent
commit
c475ccffda
1 fichiers modifiés avec 4 ajouts et 5 suppressions
  1. 4 5
      code/components/jomjol_controlcamera/ClassControllCamera.cpp

+ 4 - 5
code/components/jomjol_controlcamera/ClassControllCamera.cpp

@@ -1415,17 +1415,16 @@ esp_err_t CCamera::CaptureToStream(httpd_req_t *req, bool FlashlightOn)
                         {
                         {
                             if (fb->len > frameCopyCapacity)
                             if (fb->len > frameCopyCapacity)
                             {
                             {
-                                uint8_t *newBuffer = static_cast<uint8_t *>(malloc_psram_heap(
-                                    "Live stream JPEG copy", fb->len, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
+                                uint8_t *newBuffer = static_cast<uint8_t *>(realloc_psram_heap(
+                                    "Live stream JPEG copy", frameCopyBuffer, fb->len,
+                                    MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
                                 if (newBuffer == NULL)
                                 if (newBuffer == NULL)
                                 {
                                 {
-                                    LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToStream: JPEG copy allocation failed");
+                                    LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToStream: JPEG copy buffer growth failed");
                                     result = ESP_ERR_NO_MEM;
                                     result = ESP_ERR_NO_MEM;
                                 }
                                 }
                                 else
                                 else
                                 {
                                 {
-                                    if (frameCopyBuffer != NULL)
-                                        free_psram_heap("Live stream JPEG copy", frameCopyBuffer);
                                     frameCopyBuffer = newBuffer;
                                     frameCopyBuffer = newBuffer;
                                     frameCopyCapacity = fb->len;
                                     frameCopyCapacity = fb->len;
                                 }
                                 }