Add : RTSP audio/video with back channel, and auth
- cam_stream: shared JPEG feed for /pic, /stream and RTSP; RTSP server (port 554, TCP) with MJPEG video, G.711 mic audio and an ONVIF-style back channel to the speaker - cam_auth: RTSP Digest login and HTTP Basic / ?key= check on all endpoints - Mic task feeds HTTP and RTSP with a sticky channel choice
This commit is contained in:
+48
-70
@@ -3,6 +3,7 @@
|
||||
#include "esp_camera.h"
|
||||
#include "camera_pinout.h"
|
||||
#include "esp32_s3_cam_ovxxxx.h"
|
||||
#include "cam_stream.h"
|
||||
#include "board.h"
|
||||
|
||||
#if defined CONFIG_CAMERA_AF_SUPPORT
|
||||
@@ -106,82 +107,59 @@ static void maybe_init_autofocus(void)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
esp_err_t capture_handler(httpd_req_t *req) {
|
||||
camera_fb_t *fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
ESP_LOGE(TAG, "Camera capture failed");
|
||||
esp_err_t capture_handler(httpd_req_t *req)
|
||||
{
|
||||
uint8_t *jpg = NULL;
|
||||
size_t cap = 0;
|
||||
uint32_t seq;
|
||||
|
||||
if (!cam_http_check(req)) return ESP_OK;
|
||||
|
||||
cam_feed_viewer_add(&seq);
|
||||
size_t n = cam_feed_wait(&jpg, &cap, &seq, 3000);
|
||||
cam_feed_viewer_remove();
|
||||
|
||||
if (!n) {
|
||||
free(jpg);
|
||||
httpd_resp_send_500(req);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
uint8_t *jpeg_buf = NULL;
|
||||
size_t jpeg_len = 0;
|
||||
|
||||
bool jpeg_converted = frame2jpg(fb, 50, &jpeg_buf, &jpeg_len);
|
||||
|
||||
esp_camera_fb_return(fb);
|
||||
|
||||
if (!jpeg_converted) {
|
||||
ESP_LOGE(TAG, "JPEG compression failed");
|
||||
httpd_resp_send_500(req);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
httpd_resp_set_type(req, "image/jpeg");
|
||||
httpd_resp_send(req, (const char *)jpeg_buf, jpeg_len);
|
||||
|
||||
free(jpeg_buf);
|
||||
|
||||
return ESP_OK;
|
||||
esp_err_t r = httpd_resp_send(req, (const char *)jpg, n);
|
||||
free(jpg);
|
||||
return r;
|
||||
}
|
||||
|
||||
esp_err_t stream_handler(httpd_req_t *req) {
|
||||
camera_fb_t * fb = NULL;
|
||||
esp_err_t res = ESP_OK;
|
||||
size_t _jpg_buf_len = 0;
|
||||
uint8_t * _jpg_buf = NULL;
|
||||
char * part_buf[64];
|
||||
esp_err_t stream_handler(httpd_req_t *req)
|
||||
{
|
||||
uint8_t *jpg = NULL;
|
||||
size_t cap = 0;
|
||||
uint32_t seq;
|
||||
int idle = 0;
|
||||
char part[64];
|
||||
|
||||
res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
|
||||
if (res != ESP_OK) {
|
||||
return res;
|
||||
}
|
||||
|
||||
while(true) {
|
||||
fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
ESP_LOGE(TAG, "Camera capture failed");
|
||||
res = ESP_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
|
||||
esp_camera_fb_return(fb);
|
||||
|
||||
if (!jpeg_converted) {
|
||||
ESP_LOGE(TAG, "JPEG compression failed");
|
||||
res = ESP_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
free(_jpg_buf);
|
||||
_jpg_buf = NULL;
|
||||
|
||||
if (res != ESP_OK) {
|
||||
break;
|
||||
}
|
||||
vTaskDelay(1);
|
||||
if (!cam_http_check(req)) return ESP_OK;
|
||||
esp_err_t res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
|
||||
if (res != ESP_OK) return res;
|
||||
|
||||
cam_feed_viewer_add(&seq);
|
||||
while (1) {
|
||||
size_t n = cam_feed_wait(&jpg, &cap, &seq, 2000);
|
||||
if (!n) {
|
||||
if (++idle >= 5) { res = ESP_FAIL; break; } // no frames for 10 s: give up
|
||||
continue;
|
||||
}
|
||||
idle = 0;
|
||||
|
||||
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
|
||||
if (res == ESP_OK) {
|
||||
size_t hl = snprintf(part, sizeof(part), _STREAM_PART, (unsigned)n);
|
||||
res = httpd_resp_send_chunk(req, part, hl);
|
||||
}
|
||||
if (res == ESP_OK) res = httpd_resp_send_chunk(req, (const char *)jpg, n);
|
||||
if (res != ESP_OK) break; // browser left
|
||||
}
|
||||
cam_feed_viewer_remove();
|
||||
free(jpg);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user