Skip to content

Commit

Permalink
Apply framerate limiting delay after serving content boundary.
Browse files Browse the repository at this point in the history
Putting delay after finishing serving the frame causes image to appear
in stream with a lag. The reason for this appears to be that browser
relies on next frame content boundary in order to determine the end of
image.

That means that in order for browser to show frame right after receiving
it, server needs to send next frame content boundary right after image
itself, and delay to limit framerate should be applied after content
boundary, not before it.

According to https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
sending first frame without content boundary will likely cause its
content to be ignored, which seems to be acceptable price for not
treating first iteration of the loop as special case.
  • Loading branch information
15498th committed Dec 18, 2021
1 parent a75627a commit 1b836c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ static esp_err_t stream_handler(httpd_req_t *req){
_jpg_buf = fb->buf;
}
}
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, 64, _STREAM_PART, _jpg_buf_len);
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){
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
}
if(fb){
esp_camera_fb_return(fb);
fb = NULL;
Expand Down

0 comments on commit 1b836c5

Please sign in to comment.