ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

When Can I delete ESP32CAM Image Buffer After Serving with ESPAsyncWebServer?

Open gfvalvo opened this issue 2 years ago • 0 comments

I'm using ESPAsyncWebServer to serve an ESP32CAM image to a web page (a pointer to the image buffer has been stored in a FreeRTOS queue by a different task):

void handleImageRequest(AsyncWebServerRequest *request) {
  camera_fb_t *photoBuffer;
  BaseType_t result = xQueueReceive(imageQueue, &photoBuffer, 0);
  if (result == pdPASS) {
    request->send_P(200, "image/jpeg", photoBuffer->buf, photoBuffer->len);
  } else {
    request->send(200, "text/plain", "No Photo Available");
  }
}

Now I want to delete the buffer and free the memory with: esp_camera_fb_return(photoBuffer); But I can't do it right after the call to send_P() because that function returns almost immediately while the buffer is still being served in the background.

So, does ESPAsyncWebServer provide a callback or other method to inform my code that the entire buffer has been served and may now be deleted?

Thanks.

gfvalvo avatar Aug 13 '23 23:08 gfvalvo