esp32cam & esp_camera_fb_return(fb) & jpeg glitch
Posted: Sun Dec 04, 2022 2:01 pm
Hello,
Can some one explain me why I need to return fb (esp_camera_fb_return(fb) ) AFTER using the buffer?
Give me nice (as esp32cam can) jpeg:
Give me crappy jpeg:
In my project i want to use sometime the same frame twice (one for the stream and one reduce size and compare after( take 100~400ms))
I try :
In all case, when i call esp_camera_fb_return(fb) the not yet used buffer give me a hazardus glitch frame.
For the moment i use multiple camera_fb for each fonction
But i lose in frame rate and power.
Merci
Can some one explain me why I need to return fb (esp_camera_fb_return(fb) ) AFTER using the buffer?
Give me nice (as esp32cam can) jpeg:
Code: Select all
static esp_err_t stream1_handler(httpd_req_t *req) {
esp_err_t res = ESP_OK;
res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_hdr(req, "X-Framerate", "60");
while (true) {
fb = esp_camera_fb_get();
if (!fb) res = ESP_FAIL;
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
_timestamp.tv_sec = fb->timestamp.tv_sec;
_timestamp.tv_usec = fb->timestamp.tv_usec;
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
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);
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
esp_camera_fb_return(fb); // NO PROBLEM
fb = NULL;
_jpg_buf = NULL;
if (res != ESP_OK) break;
}
return res;
}
Give me crappy jpeg:
Code: Select all
static esp_err_t stream1_handler(httpd_req_t *req) {
esp_err_t res = ESP_OK;
res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_hdr(req, "X-Framerate", "60");
while (true) {
fb = esp_camera_fb_get();
if (!fb) res = ESP_FAIL;
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
_timestamp.tv_sec = fb->timestamp.tv_sec;
_timestamp.tv_usec = fb->timestamp.tv_usec;
esp_camera_fb_return(fb); //PROBLEM
fb = NULL;
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
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);
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
_jpg_buf = NULL;
if (res != ESP_OK) break;
}
return res;
}
I try :
Code: Select all
size_t _jpg_buf_len;
size_t _jpg_buf_1_len;
uint8_t *_jpg_buf = NULL;
uint8_t *_jpg_buf_1= NULL;
Code: Select all
fb = esp_camera_fb_get();
if (!fb) res = ESP_FAIL;
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
_jpg_buf_1_len = fb->len;
_jpg_buf_1 = fb->buf;
OR
fb = esp_camera_fb_get();
if (!fb) res = ESP_FAIL;
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
_jpg_buf_1_len = _jpg_buf_len;
_jpg_buf_1 = _jpg_buf;
OR
fb = esp_camera_fb_get();
if (!fb) res = ESP_FAIL;
_jpg_buf_len = fb->len;
_jpg_buf = fb->buf;
memcpy(_jpg_buf_1, _jpg_buf , _jpg_buf_len );
For the moment i use multiple camera_fb for each fonction
Code: Select all
camera_fb_t *fb = NULL;
camera_fb_t *fb_1 = NULL;
Merci