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

Serve Flowstate_at_work.jpg in GetJPGStream

Refactor image serving logic to send Flowstate_at_work.jpg in various conditions instead of returning ESP_FAIL.
SybexXx 1 день назад
Родитель
Сommit
e306c0d5fb
1 измененных файлов с 34 добавлено и 12 удалено
  1. 34 12
      code/components/jomjol_flowcontroll/ClassFlowControll.cpp

+ 34 - 12
code/components/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -725,7 +725,11 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
         }
         else {
             LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ClassFlowControll::GetJPGStream: alg.jpg cannot be served");
-            return ESP_FAIL;
+            std::string filename = "/sdcard/html/Flowstate_at_work.jpg";
+            result = send_file(req, filename);
+            /* Respond with an empty chunk to signal HTTP response completion */
+            httpd_resp_send_chunk(req, NULL, 0);
+            return result;
         }
     }
     else if (_fn == "alg_roi.jpg") {
@@ -734,15 +738,24 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
             if (status.find("Initialization (delayed)") != -1) {
                 std::string filename = "/sdcard/html/Flowstate_initialization_delayed.jpg";
                 result = send_file(req, filename);
+				/* Respond with an empty chunk to signal HTTP response completion */
+                httpd_resp_send_chunk(req, NULL, 0);
+				return result;
             }
             else if (status.find("Initialization") != -1) {
                 std::string filename = "/sdcard/html/Flowstate_initialization.jpg";
                 result = send_file(req, filename);
+				/* Respond with an empty chunk to signal HTTP response completion */
+                httpd_resp_send_chunk(req, NULL, 0);
+				return result;
             }
             else if (status.find("Take Image") != -1) {
                 if (flowalignment != NULL) {
                     std::string filename = "/sdcard/html/Flowstate_take_image.jpg";
                     result = send_file(req, filename);
+                    /* Respond with an empty chunk to signal HTTP response completion */
+                    httpd_resp_send_chunk(req, NULL, 0);
+                    return result;
                 }
                 else {
                     LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ClassFlowControll::GetJPGStream: alg_roi.jpg cannot be served -> alg.jpg is going to be served!");
@@ -752,6 +765,9 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
                     else {
                         std::string filename = "/sdcard/html/Flowstate_at_work.jpg";
                         result = send_file(req, filename);
+                        /* Respond with an empty chunk to signal HTTP response completion */
+                        httpd_resp_send_chunk(req, NULL, 0);
+                        return result;
                     }
                 }
             }
@@ -763,23 +779,28 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
                     }
                 }
 
-                // A missing preview must not fall back to ImageBasis: that would
-                // make the single HTTP server task wait on the global image lock.
-                LogFile.WriteToFile(ESP_LOG_WARN, TAG, "ClassFlowControll::GetJPGStream: ROI preview is not ready");
-                httpd_resp_set_status(req, "503 Service Unavailable");
-                httpd_resp_set_type(req, "text/plain");
-                return httpd_resp_send(req, "ROI preview not ready", HTTPD_RESP_USE_STRLEN);
+                std::string filename = "/sdcard/html/Flowstate_at_work.jpg";
+                result = send_file(req, filename);
+                /* Respond with an empty chunk to signal HTTP response completion */
+                httpd_resp_send_chunk(req, NULL, 0);
+                return result;
             }
         #else
             if (!flowalignment) {
                 ESP_LOGD(TAG, "ClassFloDControll::GetJPGStream: FlowAlignment is not (yet) initialized. Interrupt serving!");
-                httpd_resp_send(req, NULL, 0);
-                return ESP_FAIL;
+                std::string filename = "/sdcard/html/Flowstate_at_work.jpg";
+                result = send_file(req, filename);
+                /* Respond with an empty chunk to signal HTTP response completion */
+                httpd_resp_send_chunk(req, NULL, 0);
+                return result;
             }
 
             if (flowalignment->ImageBasis == NULL || !flowalignment->ImageBasis->ImageOkay()) {
-                httpd_resp_send(req, NULL, 0);
-                return ESP_FAIL;
+                std::string filename = "/sdcard/html/Flowstate_at_work.jpg";
+                result = send_file(req, filename);
+                /* Respond with an empty chunk to signal HTTP response completion */
+                httpd_resp_send_chunk(req, NULL, 0);
+                return result;
             }
             _send = new (std::nothrow) CImageBasis("alg_roi", flowalignment->ImageBasis);
 
@@ -788,7 +809,8 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
                 if (flowdigit) flowdigit->DrawROI(_send);
                 if (flowanalog) flowanalog->DrawROI(_send);
                 _sendDelete = true;
-            } else {
+            } 
+			else {
                 LogFile.WriteToFile(ESP_LOG_WARN, TAG, "ClassFlowControll::GetJPGStream: Not enough memory to create alg_roi.jpg -> alg.jpg is going to be served!");
                 delete _send;
                 _send = flowalignment->ImageBasis;