Skip to content

Commit bde3198

Browse files
committed
Merge branch 'feature/support_whip_protocol' into 'main'
Add WHIP signaling support See merge request adf/esp-webrtc-solution!16
2 parents 91621a2 + 564ce54 commit bde3198

35 files changed

+1468
-46
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ This demo mainly show how to use `esp_peer` API to buildup a WebRTC application
2525

2626
### 4. Video Call Solution
2727
This demo show how to use `esp_webrtc` data channel to build up video call application.
28+
29+
### 5. WHIP Publisher Solution
30+
This demo show how to use `esp_webrtc` to publish streaming data to WHIP server.

components/av_render/src/av_render.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ static int _render_write_audio(av_render_thread_res_t *res, av_render_audio_fram
608608
if (res->flushing == false) {
609609
ret = audio_render_write(res->render->cfg.audio_render, audio_frame);
610610
if (ret != 0) {
611-
ESP_LOGE(TAG, "Fail to render audio");
611+
ESP_LOGE(TAG, "Fail to render audio ret %d", ret);
612612
return ret;
613613
}
614614
}

components/esp_webrtc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
set(component_srcdirs "src")
33

44
# AppRTC
5-
set(signalling_srcdirs "impl/apprtc_signal")
6-
set(signalling_incdirs "impl/apprtc_signal")
5+
set(signalling_srcdirs "impl/apprtc_signal" "impl/whip_signal")
6+
set(signalling_incdirs "impl/apprtc_signal" "impl/whip_signal/include")
77

88
list(APPEND component_srcdirs ${signalling_srcdirs})
99

components/esp_webrtc/impl/apprtc_signal/https_client.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
static const char *TAG = "HTTPS_CLIENT";
3434

3535
typedef struct {
36-
http_body_t body;
37-
uint8_t *data;
38-
int fill_size;
39-
int size;
40-
void *ctx;
36+
http_header_t header;
37+
http_body_t body;
38+
uint8_t *data;
39+
int fill_size;
40+
int size;
41+
void *ctx;
4142
} http_info_t;
4243

4344
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
@@ -54,6 +55,9 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
5455
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
5556
break;
5657
case HTTP_EVENT_ON_HEADER:
58+
if (info->header) {
59+
info->header(evt->header_key, evt->header_value, info->ctx);
60+
}
5761
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key,
5862
evt->header_value);
5963
break;
@@ -100,10 +104,11 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
100104
return ESP_OK;
101105
}
102106

103-
int https_send_request(const char *method, char **headers, const char *url, char *data, http_body_t body, void *ctx)
107+
int https_send_request(const char *method, char **headers, const char *url, char *data, http_header_t header_cb, http_body_t body, void *ctx)
104108
{
105109
http_info_t info = {
106110
.body = body,
111+
.header = header_cb,
107112
.ctx = ctx,
108113
};
109114
esp_http_client_config_t config = {
@@ -124,6 +129,8 @@ int https_send_request(const char *method, char **headers, const char *url, char
124129
esp_http_client_set_method(client, HTTP_METHOD_POST);
125130
} else if (strcmp(method, "DELETE") == 0) {
126131
esp_http_client_set_method(client, HTTP_METHOD_DELETE);
132+
} else if (strcmp(method, "PATCH") == 0) {
133+
esp_http_client_set_method(client, HTTP_METHOD_PATCH);
127134
} else {
128135
err = -1;
129136
goto _exit;
@@ -168,7 +175,7 @@ int https_send_request(const char *method, char **headers, const char *url, char
168175
return err;
169176
}
170177

171-
int https_post(const char *url, char **headers, char *data, http_body_t body, void *ctx)
178+
int https_post(const char *url, char **headers, char *data, http_header_t header_cb, http_body_t body, void *ctx)
172179
{
173-
return https_send_request("POST", headers, url, data, body, ctx);
180+
return https_send_request("POST", headers, url, data, header_cb, body, ctx);
174181
}

components/esp_webrtc/impl/apprtc_signal/https_client.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,51 @@ typedef struct {
4444
*/
4545
typedef void (*http_body_t)(http_resp_t *resp, void *ctx);
4646

47+
/**
48+
* @brief Https header callback
49+
*
50+
* @param[in] key Header key
51+
* @param[in] key Header value
52+
* @param[in] ctx User context
53+
*/
54+
typedef void (*http_header_t)(const char *key, const char *value, void *ctx);
55+
4756
/**
4857
* @brief Send https requests
4958
*
5059
* @note This API is run in synchronized until response or error returns
5160
*
52-
* @param[in] method HTTP method to do
53-
* @param[in] headers HTTP headers, headers are array of "Type: Info", last one need set to NULL
54-
* @param[in] url HTTPS URL
55-
* @param[in] data Content data to be sent
56-
* @param[in] body Body callback
57-
* @param[in] ctx User context
61+
* @param[in] method HTTP method to do
62+
* @param[in] headers HTTP headers, headers are array of "Type: Info", last one need set to NULL
63+
* @param[in] url HTTPS URL
64+
* @param[in] data Content data to be sent
65+
* @param[in] header_cb Header callback
66+
* @param[in] body Body callback
67+
* @param[in] ctx User context
5868
*
5969
* @return
6070
* - 0 On success
6171
* - Others Fail to do https request
6272
*/
63-
int https_send_request(const char *method, char **headers, const char *url, char *data, http_body_t body, void *ctx);
73+
int https_send_request(const char *method, char **headers, const char *url, char *data, http_header_t header_cb, http_body_t body_cb, void *ctx);
6474

6575
/**
6676
* @brief Do post https request
6777
*
6878
* @note This API will internally call `https_send_request`
6979
*
70-
* @param[in] url HTTPS URL to post
71-
* @param[in] headers HTTP headers, headers are array of "Type: Info", last one need set to NULL
72-
* @param[in] data Content data to be sent
73-
* @param[in] body Body callback
74-
* @param[in] ctx User context
80+
* @param[in] url HTTPS URL to post
81+
* @param[in] headers HTTP headers, headers are array of "Type: Info", last one need set to NULL
82+
* @param[in] data Content data to be sent
83+
* @param[in] header_cb Header callback
84+
* @param[in] body Body callback
85+
* @param[in] ctx User context
7586
*
7687
* @return
7788
* - 0 On success
7889
* - Others Fail to do https request
7990
*/
80-
int https_post(const char *url, char **headers, char *data, http_body_t body, void *ctx);
91+
int https_post(const char *url, char **headers, char *data, http_header_t header_cb, http_body_t body, void *ctx);
8192

8293
#ifdef __cplusplus
8394
}

components/esp_webrtc/impl/apprtc_signal/signal_default.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static void reload_ice_task(void *arg)
496496
media_lib_thread_sleep(50);
497497
uint32_t cur = time(NULL);
498498
if (cur > start + sg->ice_expire_time) {
499-
int ret = https_post(sg->client_info.ice_server, NULL, NULL, credential_body, &sg->ice_info);
499+
int ret = https_post(sg->client_info.ice_server, NULL, NULL, NULL, credential_body, &sg->ice_info);
500500
if (ret != 0) {
501501
break;
502502
}
@@ -546,7 +546,7 @@ static int wss_signal_start(esp_peer_signaling_cfg_t *cfg, esp_peer_signaling_ha
546546
}
547547
int ret = 0;
548548
// Http post to get client info firstly
549-
https_post(cfg->signal_url, NULL, NULL, get_client_info, &sg->client_info);
549+
https_post(cfg->signal_url, NULL, NULL, NULL, get_client_info, &sg->client_info);
550550
if (sg->client_info.client_id == NULL) {
551551
ESP_LOGE(TAG, "Fail to get client id for room %s", cfg->signal_url);
552552
ret = -1;
@@ -562,7 +562,7 @@ static int wss_signal_start(esp_peer_signaling_cfg_t *cfg, esp_peer_signaling_ha
562562
ret = -1;
563563
goto __exit;
564564
}
565-
https_post(sg->client_info.ice_server, NULL, NULL, credential_body, &sg->ice_info);
565+
https_post(sg->client_info.ice_server, NULL, NULL, NULL, credential_body, &sg->ice_info);
566566
sg->ice_info.is_initiator = sg->client_info.is_initiator;
567567
if (sg->ice_info.server_info.psw == NULL) {
568568
printf("Fail to get password\n");
@@ -646,7 +646,7 @@ static int wss_signal_send_msg(esp_peer_signaling_handle_t h, esp_peer_signaling
646646
}
647647
char *payload = cJSON_PrintUnformatted(json);
648648
cJSON_Delete(json);
649-
int ret = https_post(request_room, NULL, payload, NULL, NULL);
649+
int ret = https_post(request_room, NULL, payload, NULL, NULL, NULL);
650650
free(payload);
651651
return ret;
652652
}
@@ -660,7 +660,7 @@ static void wss_send_leave(wss_sig_t *sg)
660660
char header[128];
661661
char *headers[2] = { header, NULL };
662662
snprintf(header, 128, "Referer: %s/r/%s", sg->client_info.base_url, sg->client_info.room_id);
663-
https_post(request_room, headers, NULL, NULL, NULL);
663+
https_post(request_room, headers, NULL, NULL, NULL, NULL);
664664
esp_peer_signaling_msg_t msg = {
665665
.type = ESP_PEER_SIGNALING_MSG_BYE,
666666
};
@@ -669,7 +669,7 @@ static void wss_send_leave(wss_sig_t *sg)
669669
snprintf(request_room, 128, "%s/%s/%s",
670670
sg->client_info.wss_post_url,
671671
sg->client_info.room_id, sg->client_info.client_id);
672-
https_send_request("DELETE", NULL, request_room, NULL, NULL, NULL);
672+
https_send_request("DELETE", NULL, request_room, NULL, NULL, NULL, NULL);
673673
}
674674

675675
int wss_signal_stop(esp_peer_signaling_handle_t h)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)