* Capturing a still image from the image sensor and transferring it via HTTP * content. This function is an internal, static entry and URI handler. * If the format of the current sensor is other than JPEG, the response code * 200 will be sent along with a simple text message. * Also, if the capture of the image frame fails, a 500 response will be * returned to the client. * @param req
| 260 | * @return ESP_FAIL |
| 261 | */ |
| 262 | esp_err_t ESP32WebCam::_captureHandler(httpd_req_t* req) { |
| 263 | esp_err_t rc; |
| 264 | |
| 265 | camera_fb_t* fb = esp_camera_fb_get(); |
| 266 | if (fb) { |
| 267 | if (fb->format == PIXFORMAT_JPEG) { |
| 268 | // Specifies it can be displayed inside the Web page. |
| 269 | httpd_resp_set_hdr(req, ESP32WebCam::_CONTENT_DISPOSITION, "inline"); |
| 270 | rc = _sendResponse(req, 200, "image/jpeg", reinterpret_cast<const char*>(fb->buf), fb->len); |
| 271 | } |
| 272 | else { |
| 273 | // Respond with JPEG converted buffer. |
| 274 | httpd_resp_set_status(req, HTTPD_200); |
| 275 | httpd_resp_set_type(req, "image/jpeg"); |
| 276 | httpd_resp_set_hdr(req, ESP32WebCam::_CONTENT_DISPOSITION, "inline"); |
| 277 | httpd_resp_set_hdr(req, ESP32WebCam::_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); |
| 278 | |
| 279 | _jpgChunking_t jChunk = {req, 0}; |
| 280 | rc = frame2jpg_cb(fb, 80, _jpgEncodeStream, &jChunk) ? ESP_OK : ESP_FAIL; |
| 281 | httpd_resp_send_chunk(req, NULL, 0); |
| 282 | } |
| 283 | esp_camera_fb_return(fb); |
| 284 | } |
| 285 | else { |
| 286 | _sendResponse(req, HTTPD_500_INTERNAL_SERVER_ERROR, "text/plain", "failed to esp_camera_fb_get"); |
| 287 | rc = ESP_FAIL; |
| 288 | } |
| 289 | return rc; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Request handler that prompts ESP32Cam function execution by an HTTP request. |
nothing calls this directly
no outgoing calls
no test coverage detected