mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Fix build failing due to missing includes
This commit is contained in:
parent
440c755568
commit
2cc2992388
@ -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)
|
||||
{
|
||||
long last_request_time = 0;
|
||||
camera_fb_t *fb = NULL;
|
||||
struct timeval _timestamp;
|
||||
long last_request_time = 0;
|
||||
camera_fb_t *fb = NULL;
|
||||
struct timeval _timestamp;
|
||||
|
||||
esp_err_t res = ESP_OK;
|
||||
esp_err_t res = ESP_OK;
|
||||
|
||||
size_t _jpg_buf_len = 0;
|
||||
uint8_t *_jpg_buf = NULL;
|
||||
size_t _jpg_buf_len = 0;
|
||||
uint8_t *_jpg_buf = NULL;
|
||||
|
||||
char *part_buf[128];
|
||||
char *part_buf[128];
|
||||
|
||||
static int64_t last_frame = 0;
|
||||
if (!last_frame)
|
||||
last_frame = esp_timer_get_time();
|
||||
static int64_t last_frame = 0;
|
||||
if (!last_frame)
|
||||
last_frame = esp_timer_get_time();
|
||||
|
||||
res = httpd_resp_set_type(req, STREAM_CONTENT_TYPE);
|
||||
if (res != ESP_OK)
|
||||
return res;
|
||||
res = httpd_resp_set_type(req, STREAM_CONTENT_TYPE);
|
||||
if (res != ESP_OK)
|
||||
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, "X-Framerate", "60");
|
||||
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");
|
||||
|
||||
while (true)
|
||||
{
|
||||
fb = esp_camera_fb_get();
|
||||
if (!fb)
|
||||
{
|
||||
log_e("Camera capture failed");
|
||||
res = ESP_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timestamp.tv_sec = fb->timestamp.tv_sec;
|
||||
_timestamp.tv_usec = fb->timestamp.tv_usec;
|
||||
_jpg_buf_len = fb->len;
|
||||
_jpg_buf = fb->buf;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
fb = esp_camera_fb_get();
|
||||
if (!fb)
|
||||
{
|
||||
log_e("Camera capture failed");
|
||||
res = ESP_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timestamp.tv_sec = fb->timestamp.tv_sec;
|
||||
_timestamp.tv_usec = fb->timestamp.tv_usec;
|
||||
_jpg_buf_len = fb->len;
|
||||
_jpg_buf = fb->buf;
|
||||
}
|
||||
|
||||
if (res == ESP_OK)
|
||||
res = httpd_resp_send_chunk(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
|
||||
if (res == ESP_OK)
|
||||
res = httpd_resp_send_chunk(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
|
||||
|
||||
if (res == ESP_OK)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (res == ESP_OK)
|
||||
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
|
||||
if (res == ESP_OK)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (res == ESP_OK)
|
||||
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
|
||||
|
||||
if (fb)
|
||||
{
|
||||
esp_camera_fb_return(fb);
|
||||
fb = NULL;
|
||||
_jpg_buf = NULL;
|
||||
}
|
||||
if (fb)
|
||||
{
|
||||
esp_camera_fb_return(fb);
|
||||
fb = NULL;
|
||||
_jpg_buf = NULL;
|
||||
}
|
||||
|
||||
else if (_jpg_buf)
|
||||
{
|
||||
free(_jpg_buf);
|
||||
_jpg_buf = NULL;
|
||||
}
|
||||
else if (_jpg_buf)
|
||||
{
|
||||
free(_jpg_buf);
|
||||
_jpg_buf = NULL;
|
||||
}
|
||||
|
||||
if (res != ESP_OK)
|
||||
break;
|
||||
if (res != ESP_OK)
|
||||
break;
|
||||
|
||||
long request_end = millis();
|
||||
long latency = (request_end - last_request_time);
|
||||
last_request_time = request_end;
|
||||
log_d("Size: %uKB, Time: %ums (%ifps)\n", _jpg_buf_len / 1024, latency, 1000 / latency);
|
||||
}
|
||||
long request_end = millis();
|
||||
long latency = (request_end - last_request_time);
|
||||
last_request_time = request_end;
|
||||
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()
|
||||
@ -91,20 +91,20 @@ int StreamServer::startStreamServer()
|
||||
config.ctrl_port = this->STREAM_SERVER_PORT;
|
||||
config.stack_size = 20480;
|
||||
|
||||
httpd_uri_t stream_page = {
|
||||
.uri = "/",
|
||||
.method = HTTP_GET,
|
||||
.handler = &StreamHelpers::stream,
|
||||
.user_ctx = nullptr};
|
||||
httpd_uri_t stream_page = {
|
||||
.uri = "/",
|
||||
.method = HTTP_GET,
|
||||
.handler = &StreamHelpers::stream,
|
||||
.user_ctx = nullptr};
|
||||
|
||||
int status = httpd_start(&camera_stream, &config);
|
||||
int status = httpd_start(&camera_stream, &config);
|
||||
|
||||
if (status != ESP_OK)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
httpd_register_uri_handler(camera_stream, &stream_page);
|
||||
log_d("Stream server initialized");
|
||||
return 0;
|
||||
}
|
||||
if (status != ESP_OK)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
httpd_register_uri_handler(camera_stream, &stream_page);
|
||||
log_d("Stream server initialized");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
#include <Arduino.h>
|
||||
#include "esp_camera.h"
|
||||
#include "esp_http_server.h"
|
||||
// Used to disable brownout detection
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
|
||||
namespace StreamHelpers
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user