Skip to content

Commit 527a6ca

Browse files
committed
Merge branch 'feature/add_pedestrian_detect_demo' into 'main'
Add pedestrian_detect into doorbell local demo See merge request adf/esp-webrtc-solution!43
2 parents 052b930 + e390bc6 commit 527a6ca

File tree

16 files changed

+660
-51
lines changed

16 files changed

+660
-51
lines changed

components/esp_webrtc/include/esp_webrtc.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ int esp_webrtc_open(esp_webrtc_cfg_t *cfg, esp_webrtc_handle_t *rtc_handle);
186186
*/
187187
int esp_webrtc_set_media_provider(esp_webrtc_handle_t rtc_handle, esp_webrtc_media_provider_t *provider);
188188

189+
/**
190+
* @brief Set to disable auto capture for WebRTC
191+
*
192+
* @note In default capture will start and stop internally by WebRTC
193+
* In some scenario capture is controlled by other module, capture is only one sink path of it
194+
* Users can call this API to disable auto control of capture
195+
*
196+
* @param[in] rtc_handle WebRTC handle
197+
* @param[in] no_auto_capture Disable auto capture or not
198+
*
199+
* @return
200+
* - ESP_PEER_ERR_NONE On success
201+
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
202+
*/
203+
int esp_webrtc_set_no_auto_capture(esp_webrtc_handle_t rtc_handle, bool no_auto_capture);
204+
189205
/**
190206
* @brief WebRTC set event handler
191207
*

components/esp_webrtc/src/esp_webrtc.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct {
8181
esp_peer_signaling_ice_info_t ice_info;
8282
bool ice_info_loaded;
8383
bool signaling_connected;
84+
bool no_auto_capture;
8485

8586
uint8_t *aud_fifo;
8687
uint32_t aud_fifo_size;
@@ -201,7 +202,11 @@ static int stop_stream(webrtc_t *rtc)
201202
rtc->send_going = false;
202203
WAIT_FOR_BITS(PC_SEND_QUIT_BIT);
203204
}
204-
esp_capture_stop(rtc->media_provider.capture);
205+
if (rtc->no_auto_capture == false) {
206+
esp_capture_stop(rtc->media_provider.capture);
207+
} else {
208+
esp_capture_sink_enable(rtc->capture_path, ESP_CAPTURE_RUN_MODE_DISABLE);
209+
}
205210
av_render_reset(rtc->play_handle);
206211
return 0;
207212
}
@@ -790,6 +795,16 @@ int esp_webrtc_set_media_provider(esp_webrtc_handle_t handle, esp_webrtc_media_p
790795
return ESP_PEER_ERR_NONE;
791796
}
792797

798+
int esp_webrtc_set_no_auto_capture(esp_webrtc_handle_t handle, bool no_auto_capture)
799+
{
800+
if (handle == NULL) {
801+
return ESP_PEER_ERR_INVALID_ARG;
802+
}
803+
webrtc_t *rtc = (webrtc_t *)handle;
804+
rtc->no_auto_capture = no_auto_capture;
805+
return ESP_PEER_ERR_NONE;
806+
}
807+
793808
int esp_webrtc_start(esp_webrtc_handle_t handle)
794809
{
795810
if (handle == NULL) {

solutions/doorbell_local/README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## Overview
55

6-
This demo shows how to use `esp_webrtc` to build a local doorbell application. An ESP32 series board acts as an HTTPS signaling server.
6+
This demo shows how to use `esp_webrtc` to build a local doorbell application with optional AI-powered pedestrian detection. An ESP32 series board acts as an HTTPS signaling server and provides real-time video streaming, two-way audio communication, and intelligent motion detection capabilities.
77

88
## Hardware Requirements
99

@@ -21,13 +21,20 @@ This demo depends only on **ESP-IDF**. All other required components will be aut
2121

2222
### Configuration
2323

24-
1. **Wi-Fi Settings**
24+
1. **Wi-Fi Settings**
2525
Set your Wi-Fi SSID and password in [`settings.h`](main/settings.h).
2626

27-
2. **Camera Configuration**
27+
2. **Camera Configuration**
2828
If using a different camera model or resolution, update the corresponding settings in [`settings.h`](main/settings.h).
2929

30-
3. **USB-JTAG Download (Optional)**
30+
3. **Pedestrian Detection (Optional)**
31+
To enable pedestrian detection functionality:
32+
- Set `CONFIG_DOORBELL_SUPPORT_PEDESTRIAN_DETECT=y` in your configuration
33+
- The detection resolution is defined by `DETECT_WIDTH` and `DETECT_HEIGHT` in [`settings.h`](main/settings.h)
34+
- Detection frame rate is controlled by `DETECT_FPS` setting
35+
- Requires additional memory and processing power
36+
37+
4. **USB-JTAG Download (Optional)**
3138
If using USB-JTAG, uncomment the following line in [`sdkconfig.defaults.esp32p4`](sdkconfig.defaults.esp32p4):
3239
```c
3340
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
@@ -66,35 +73,42 @@ Open **Chrome** or **Edge** and visit the printed URL. Since the site uses a sel
6673

6774
Also, disable mDNS ICE candidates to ensure proper WebRTC connectivity:
6875

69-
- **Chrome**: `chrome://flags/#enable-webrtc-hide-local-ips-with-mdns`
76+
- **Chrome**: `chrome://flags/#enable-webrtc-hide-local-ips-with-mdns`
7077
- **Edge**: `edge://flags/#enable-webrtc-hide-local-ips-with-mdns`
7178

72-
Disable the option: **WebRTC mDNS ICE candidates**
79+
Disable the option: **WebRTC mDNS ICE candidates**
7380
Restart the browser for the change to take effect.
7481

7582
### Interactions
7683

7784
After opening the page in the browser:
7885

79-
1. **Open Door**
80-
- Click the **Door** icon.
81-
- The board will play a "Door is opened" tone.
86+
1. **Open Door**
87+
- Click the **Door** icon.
88+
- The board will play a "Door is opened" tone.
8289
- The browser will display: `Receiving Door opened event`.
8390

84-
2. **Calling (Ring Button)**
85-
- Press the **boot key** on the board.
86-
- The board plays ring music, and the browser shows **Accept Call** and **Deny Call** icons.
87-
- If accepted: starts **two-way audio** and **one-way video** (board → browser).
88-
- If denied: the call ends.
91+
2. **Calling (Ring Button)**
92+
- Press the **boot key** on the board.
93+
- The board plays ring music, and the browser shows **Accept Call** and **Deny Call** icons.
94+
- If accepted: starts **two-way audio** and **one-way video** (board → browser).
95+
- If denied: the call ends.
8996
- To change the ring button, modify `DOOR_BELL_RING_BUTTON` in [`settings.h`](main/settings.h).
9097

91-
3. **End Call / Cleanup**
92-
- In the browser: click the **Hangup** icon.
98+
3. **Pedestrian Detection** *(if enabled)*
99+
- The system automatically detects pedestrians using the camera feed.
100+
- When a pedestrian is detected, a `PEDESTRIAN_DETECTED` event is sent to the browser.
101+
- The browser displays detection events in a scrollable list with timestamps.
102+
- Click the **Detection Events** button to view/clear the event history.
103+
- Events are displayed in chronological order (newest first) with animation effects.
104+
105+
4. **End Call / Cleanup**
106+
- In the browser: click the **Hangup** icon.
93107
- On the board: run the `stop` command.
94108

95109
## Technical Details
96110

97-
This demo use SSE to send instant message to browser and use POST to receive instant message from browser.
111+
This demo uses SSE (Server-Sent Events) to send instant messages to the browser and HTTP POST to receive instant messages from the browser.
98112

99113
### Enhancements in `esp_webrtc`
100114

@@ -103,8 +117,21 @@ This demo use SSE to send instant message to browser and use POST to receive ins
103117

104118
For a detailed call flow, refer to the [esp_webrtc connection flow](../../components/esp_webrtc/README.md#typical-call-sequence-of-esp_webrtc).
105119

120+
### Pedestrian Detection Implementation
121+
122+
When enabled, the pedestrian detection system:
123+
124+
- **Camera Processing**: Captures frames from the camera at the configured resolution and frame rate
125+
- **AI Detection**: Uses ESP-DL (Deep Learning) library for real-time pedestrian detection
126+
- **Event Notification**: Sends `PEDESTRIAN_DETECTED` custom commands via WebRTC signaling
127+
- **Browser UI**: Displays detection events with timestamps in a scrollable, animated list
128+
129+
The detection system operates independently of video calls and continues running in the background when enabled.
130+
106131
### Limitations
107132

108133
- Only one peer can connect at a time.
109134
- A heartbeat timeout of 5 seconds is enforced.
110135
- If the peer leaves unexpectedly, wait a few seconds before reconnecting.
136+
- Pedestrian detection requires additional CPU and memory resources, which may affect overall system performance.
137+
- Detection accuracy depends on lighting conditions, camera quality, and pedestrian positioning.
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
idf_component_register(SRCS "webrtc.c" "main.c" "board.c" "media_sys.c" "webrtc_http_server.c"
1+
2+
set(srcs "webrtc.c" "main.c" "board.c" "media_sys.c" "webrtc_http_server.c")
3+
4+
if(CONFIG_DOORBELL_SUPPORT_PEDESTRIAN_DETECT)
5+
list(APPEND srcs "pedestrain_detect.cpp")
6+
endif()
7+
8+
idf_component_register(SRCS ${srcs}
29
EMBED_TXTFILES "ring.aac" "open.aac" "join.aac" "webrtc_test.html"
310
"certs/servercert.pem" "certs/prvtkey.pem"
411
INCLUDE_DIRS ".")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menu "DoorBell Local Demo"
2+
3+
config DOORBELL_SUPPORT_PEDESTRIAN_DETECT
4+
bool "Support pedestrian detection"
5+
default n
6+
depends on IDF_TARGET_ESP32P4 || IDF_TARGET_ESP32S3
7+
help
8+
Enable this option to enable pedestrian detection
9+
endmenu

solutions/doorbell_local/main/common.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "media_sys.h"
1414
#include "network.h"
1515
#include "sys_state.h"
16+
#include "esp_capture_sink.h"
1617

1718
#ifdef __cplusplus
1819
extern "C" {
@@ -58,6 +59,30 @@ void send_cmd(char *cmd);
5859
*/
5960
int close_data_channel(int idx);
6061

62+
/**
63+
* @brief Get capture sink handle by index
64+
*/
65+
esp_capture_sink_handle_t get_detect_sink(void);
66+
67+
/**
68+
* @brief pedestrian detection configuration
69+
*/
70+
typedef struct {
71+
int (*detected)(esp_capture_rgn_t *rgn, void *ctx);
72+
void *ctx;
73+
} pedestrian_detect_cfg_t;
74+
75+
/**
76+
* @brief Start pedestrian detection
77+
*/
78+
int start_pedestrian_detection(pedestrian_detect_cfg_t *cfg);
79+
80+
/**
81+
* @brief Stop pedestrian detection
82+
*/
83+
void stop_pedestrian_detection();
84+
85+
6186
#ifdef __cplusplus
6287
}
6388
#endif

solutions/doorbell_local/main/idf_component.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ dependencies:
1010
version: "1.0.4"
1111
rules:
1212
- if: target in [esp32p4, esp32s3]
13+
espressif/pedestrian_detect:
14+
version: "^0.2.0"
15+
rules:
16+
- if: target in [esp32p4, esp32s3]

solutions/doorbell_local/main/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ static void thread_scheduler(const char *thread_name, media_lib_thread_cfg_t *sc
193193
#endif
194194
else if (strcmp(thread_name, "AUD_SRC") == 0) {
195195
schedule_cfg->priority = 15;
196-
} else if (strcmp(thread_name, "pc_task") == 0) {
196+
} else if (strcmp(thread_name, "detect") == 0) {
197+
schedule_cfg->priority = 8;
198+
}
199+
else if (strcmp(thread_name, "pc_task") == 0) {
197200
schedule_cfg->stack_size = 25 * 1024;
198201
schedule_cfg->priority = 18;
199202
schedule_cfg->core_id = 1;
@@ -224,6 +227,8 @@ static char *get_network_ip(void)
224227
return media_lib_ipv4_ntoa(&ip_info.ip);
225228
}
226229

230+
void sctp_show_details(bool enable);
231+
227232
static int network_event_handler(bool connected)
228233
{
229234
if (connected) {
@@ -232,6 +237,7 @@ static int network_event_handler(bool connected)
232237
start_webrtc(NULL);
233238
ESP_LOGI(TAG, "Use browser to enter https://%s/webrtc/test for test", get_network_ip());
234239
});
240+
// sctp_show_details(true);
235241
} else {
236242
stop_webrtc();
237243
}

0 commit comments

Comments
 (0)