|
|
@@ -113,21 +113,32 @@ bool ClassFlowAlignment::PublishAlgROI(const ImageData *image)
|
|
|
esp_err_t ClassFlowAlignment::SendAlgROIToHTTP(httpd_req_t *req)
|
|
|
{
|
|
|
if (req == NULL || AlgROIMutex == NULL) return ESP_ERR_INVALID_ARG;
|
|
|
+
|
|
|
+ // Copy under the publication mutex, then release it before network I/O.
|
|
|
+ // A slow browser must never stall the flow task publishing the next frame.
|
|
|
+ ImageData *snapshot = new (std::nothrow) ImageData;
|
|
|
+ if (snapshot == NULL) return ESP_ERR_NO_MEM;
|
|
|
+
|
|
|
if (xSemaphoreTake(AlgROIMutex, pdMS_TO_TICKS(250)) != pdTRUE) {
|
|
|
+ delete snapshot;
|
|
|
return ESP_ERR_TIMEOUT;
|
|
|
}
|
|
|
|
|
|
if (AlgROI == NULL || AlgROI->size == 0 || AlgROI->size > MAX_JPG_SIZE) {
|
|
|
(void)xSemaphoreGive(AlgROIMutex);
|
|
|
+ delete snapshot;
|
|
|
return ESP_ERR_NOT_FOUND;
|
|
|
}
|
|
|
|
|
|
+ std::memcpy(snapshot->data, AlgROI->data, AlgROI->size);
|
|
|
+ snapshot->size = AlgROI->size;
|
|
|
+ (void)xSemaphoreGive(AlgROIMutex);
|
|
|
+
|
|
|
esp_err_t result = httpd_resp_set_type(req, "image/jpeg");
|
|
|
if (result == ESP_OK) {
|
|
|
- result = httpd_resp_send(req, (const char *)AlgROI->data, AlgROI->size);
|
|
|
+ result = httpd_resp_send(req, (const char *)snapshot->data, snapshot->size);
|
|
|
}
|
|
|
-
|
|
|
- (void)xSemaphoreGive(AlgROIMutex);
|
|
|
+ delete snapshot;
|
|
|
return result;
|
|
|
}
|
|
|
|