Fix build failing due to missing includes

This commit is contained in:
Lorow 2022-08-30 20:42:12 +02:00
parent 440c755568
commit 2cc2992388
2 changed files with 76 additions and 73 deletions

View File

@ -6,80 +6,80 @@ constexpr static const char *STREAM_PART = "Content-Type: image/jpeg\r\nContent-
esp_err_t StreamHelpers::stream(httpd_req_t *req) esp_err_t StreamHelpers::stream(httpd_req_t *req)
{ {
long last_request_time = 0; long last_request_time = 0;
camera_fb_t *fb = NULL; camera_fb_t *fb = NULL;
struct timeval _timestamp; struct timeval _timestamp;
esp_err_t res = ESP_OK; esp_err_t res = ESP_OK;
size_t _jpg_buf_len = 0; size_t _jpg_buf_len = 0;
uint8_t *_jpg_buf = NULL; uint8_t *_jpg_buf = NULL;
char *part_buf[128]; char *part_buf[128];
static int64_t last_frame = 0; static int64_t last_frame = 0;
if (!last_frame) if (!last_frame)
last_frame = esp_timer_get_time(); last_frame = esp_timer_get_time();
res = httpd_resp_set_type(req, STREAM_CONTENT_TYPE); res = httpd_resp_set_type(req, STREAM_CONTENT_TYPE);
if (res != ESP_OK) if (res != ESP_OK)
return res; return res;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin; Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin; Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n", "*");
httpd_resp_set_hdr(req, "X-Framerate", "60"); httpd_resp_set_hdr(req, "X-Framerate", "60");
while (true) while (true)
{ {
fb = esp_camera_fb_get(); fb = esp_camera_fb_get();
if (!fb) if (!fb)
{ {
log_e("Camera capture failed"); log_e("Camera capture failed");
res = ESP_FAIL; res = ESP_FAIL;
} }
else else
{ {
_timestamp.tv_sec = fb->timestamp.tv_sec; _timestamp.tv_sec = fb->timestamp.tv_sec;
_timestamp.tv_usec = fb->timestamp.tv_usec; _timestamp.tv_usec = fb->timestamp.tv_usec;
_jpg_buf_len = fb->len; _jpg_buf_len = fb->len;
_jpg_buf = fb->buf; _jpg_buf = fb->buf;
} }
if (res == ESP_OK) if (res == ESP_OK)
res = httpd_resp_send_chunk(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY)); res = httpd_resp_send_chunk(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
if (res == ESP_OK) if (res == ESP_OK)
{ {
size_t hlen = snprintf((char *)part_buf, 128, STREAM_PART, _jpg_buf_len, _timestamp.tv_sec, _timestamp.tv_usec); size_t hlen = snprintf((char *)part_buf, 128, STREAM_PART, _jpg_buf_len, _timestamp.tv_sec, _timestamp.tv_usec);
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
} }
if (res == ESP_OK) if (res == ESP_OK)
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len); res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
if (fb) if (fb)
{ {
esp_camera_fb_return(fb); esp_camera_fb_return(fb);
fb = NULL; fb = NULL;
_jpg_buf = NULL; _jpg_buf = NULL;
} }
else if (_jpg_buf) else if (_jpg_buf)
{ {
free(_jpg_buf); free(_jpg_buf);
_jpg_buf = NULL; _jpg_buf = NULL;
} }
if (res != ESP_OK) if (res != ESP_OK)
break; break;
long request_end = millis(); long request_end = millis();
long latency = (request_end - last_request_time); long latency = (request_end - last_request_time);
last_request_time = request_end; last_request_time = request_end;
log_d("Size: %uKB, Time: %ums (%ifps)\n", _jpg_buf_len / 1024, latency, 1000 / latency); log_d("Size: %uKB, Time: %ums (%ifps)\n", _jpg_buf_len / 1024, latency, 1000 / latency);
} }
last_frame = 0; last_frame = 0;
return res; return res;
} }
int StreamServer::startStreamServer() int StreamServer::startStreamServer()
@ -91,20 +91,20 @@ int StreamServer::startStreamServer()
config.ctrl_port = this->STREAM_SERVER_PORT; config.ctrl_port = this->STREAM_SERVER_PORT;
config.stack_size = 20480; config.stack_size = 20480;
httpd_uri_t stream_page = { httpd_uri_t stream_page = {
.uri = "/", .uri = "/",
.method = HTTP_GET, .method = HTTP_GET,
.handler = &StreamHelpers::stream, .handler = &StreamHelpers::stream,
.user_ctx = nullptr}; .user_ctx = nullptr};
int status = httpd_start(&camera_stream, &config); int status = httpd_start(&camera_stream, &config);
if (status != ESP_OK) if (status != ESP_OK)
return -1; return -1;
else else
{ {
httpd_register_uri_handler(camera_stream, &stream_page); httpd_register_uri_handler(camera_stream, &stream_page);
log_d("Stream server initialized"); log_d("Stream server initialized");
return 0; return 0;
} }
} }

View File

@ -3,6 +3,9 @@
#include <Arduino.h> #include <Arduino.h>
#include "esp_camera.h" #include "esp_camera.h"
#include "esp_http_server.h" #include "esp_http_server.h"
// Used to disable brownout detection
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
namespace StreamHelpers namespace StreamHelpers
{ {