51 httpd_config_t config = HTTPD_DEFAULT_CONFIG();
52 config.server_port = this->
port_;
53 config.ctrl_port = this->
port_;
54 config.max_open_sockets = 1;
55 config.backlog_conn = 2;
56 config.lru_purge_enable =
true;
58 if (httpd_start(&this->
httpd_, &config) != ESP_OK) {
66 .handler = [](
struct httpd_req *req) {
return ((
CameraWebServer *) req->user_ctx)->handler_(req); },
69 httpd_register_uri_handler(this->
httpd_, &uri);
184 esp_err_t res = ESP_OK;
190 res = httpd_send_all(req, STREAM_HEADER, strlen(STREAM_HEADER));
192 ESP_LOGW(TAG,
"STREAM: failed to set HTTP header");
207 while (res == ESP_OK && this->
running_) {
214 ESP_LOGW(TAG,
"STREAM: failed to acquire frame");
219 size_t hlen = snprintf(part_buf, 64, STREAM_PART, image->get_data_length());
220 res = httpd_send_all(req, part_buf, hlen);
223 res = httpd_send_all(req, (
const char *) image->get_data_buffer(), image->get_data_length());
226 res = httpd_send_all(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
231 stats_bytes += image->get_data_length();
233 if (elapsed >= STREAM_STATS_INTERVAL) {
234 ESP_LOGD(TAG,
"MJPG: %.1ffps, %" PRIu32
"B/frame (%" PRIu32
" frames)", stats_frames * 1000.0f / elapsed,
235 stats_bytes / stats_frames, stats_frames);
245 if (stats_frames > 0) {
249 ESP_LOGD(TAG,
"MJPG: %.1ffps, %" PRIu32
"B/frame (%" PRIu32
" frames)", stats_frames * 1000.0f / elapsed,
250 stats_bytes / stats_frames, stats_frames);
254 res = httpd_send_all(req, STREAM_ERROR, strlen(STREAM_ERROR));
259 ESP_LOGI(TAG,
"STREAM: closed. Frames: %" PRIu32, frames);