50 httpd_config_t config = HTTPD_DEFAULT_CONFIG();
51 config.server_port = this->
port_;
52 config.ctrl_port = this->
port_;
53 config.max_open_sockets = 1;
54 config.backlog_conn = 2;
55 config.lru_purge_enable =
true;
57 if (httpd_start(&this->
httpd_, &config) != ESP_OK) {
65 .handler = [](
struct httpd_req *req) {
return ((
CameraWebServer *) req->user_ctx)->handler_(req); },
68 httpd_register_uri_handler(this->
httpd_, &uri);
72 this->
image_ = std::move(image);
160 esp_err_t res = ESP_OK;
166 res = httpd_send_all(req, STREAM_HEADER, strlen(STREAM_HEADER));
168 ESP_LOGW(TAG,
"STREAM: failed to set HTTP header");
172 uint32_t last_frame =
millis();
177 while (res == ESP_OK && this->
running_) {
181 ESP_LOGW(TAG,
"STREAM: failed to acquire frame");
185 size_t hlen = snprintf(part_buf, 64, STREAM_PART, image->get_data_length());
186 res = httpd_send_all(req, part_buf, hlen);
189 res = httpd_send_all(req, (
const char *) image->get_data_buffer(), image->get_data_length());
192 res = httpd_send_all(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
196 int64_t frame_time =
millis() - last_frame;
199 ESP_LOGD(TAG,
"MJPG: %" PRIu32
"B %" PRIu32
"ms (%.1ffps)", (uint32_t) image->get_data_length(),
200 (uint32_t) frame_time, 1000.0 / (uint32_t) frame_time);
205 res = httpd_send_all(req, STREAM_ERROR, strlen(STREAM_ERROR));
210 ESP_LOGI(TAG,
"STREAM: closed. Frames: %" PRIu32, frames);