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);
158 esp_err_t res = ESP_OK;
164 res = httpd_send_all(req, STREAM_HEADER, strlen(STREAM_HEADER));
166 ESP_LOGW(TAG,
"STREAM: failed to set HTTP header");
170 uint32_t last_frame =
millis();
175 while (res == ESP_OK && this->
running_) {
179 ESP_LOGW(TAG,
"STREAM: failed to acquire frame");
183 size_t hlen = snprintf(part_buf, 64, STREAM_PART, image->get_data_length());
184 res = httpd_send_all(req, part_buf, hlen);
187 res = httpd_send_all(req, (
const char *) image->get_data_buffer(), image->get_data_length());
190 res = httpd_send_all(req, STREAM_BOUNDARY, strlen(STREAM_BOUNDARY));
194 int64_t frame_time =
millis() - last_frame;
197 ESP_LOGD(TAG,
"MJPG: %" PRIu32
"B %" PRIu32
"ms (%.1ffps)", (uint32_t) image->get_data_length(),
198 (uint32_t) frame_time, 1000.0 / (uint32_t) frame_time);
203 res = httpd_send_all(req, STREAM_ERROR, strlen(STREAM_ERROR));
208 ESP_LOGI(TAG,
"STREAM: closed. Frames: %" PRIu32, frames);