Просмотр исходного кода

Grow the persistent stream buffer without double PSRAM allocation

SybexXx 1 день назад
Родитель
Сommit
c475ccffda
1 измененных файлов с 4 добавлено и 5 удалено
  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)
                             {
-                                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)
                                 {
-                                    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;
                                 }
                                 else
                                 {
-                                    if (frameCopyBuffer != NULL)
-                                        free_psram_heap("Live stream JPEG copy", frameCopyBuffer);
                                     frameCopyBuffer = newBuffer;
                                     frameCopyCapacity = fb->len;
                                 }