Skip to content

Commit e53b739

Browse files
committed
Added WebRTC split functionality
- Added streaming_only and signaling_only examples - streaming_only can be flashed on P4 and signaling only on C6 - The message exchange between the two happens over webrtc_bridge
1 parent bf6ee37 commit e53b739

28 files changed

+1722
-110
lines changed

esp_port/components/esp_webrtc_utils/src/esp_work_queue.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,13 @@ esp_err_t esp_work_queue_start(void)
129129
}
130130

131131
StaticTask_t *task_buffer = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL);
132-
// void *task_stack = heap_caps_calloc_prefer(1, ESP_WORKQ_TASK_STACK, MALLOC_CAP_SPIRAM, MALLOC_CAP_INTERNAL);
133-
void *task_stack = heap_caps_malloc(ESP_WORKQ_TASK_STACK, MALLOC_CAP_INTERNAL);
132+
void *task_stack = heap_caps_malloc_prefer(ESP_WORKQ_TASK_STACK, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL);
134133
assert(task_buffer && task_stack);
135134

136135
/* the task never exits, so do not bother to free the buffers */
137136
xTaskCreateStatic(&esp_work_queue_task, "esp_workq_task", ESP_WORKQ_TASK_STACK,
138137
NULL, ESP_WORKQ_TASK_PRIO, task_stack, task_buffer);
139138

140-
// if (xTaskCreate(&esp_work_queue_task, "rmaker_queue_task", ESP_WORKQ_TASK_STACK,
141-
// NULL, ESP_WORKQ_TASK_PRIO, NULL) != pdPASS) {
142-
// ESP_LOGE(TAG, "Couldn't create RainMaker work queue task");
143-
// return ESP_FAIL;
144-
// }
145139
queue_state = WORK_QUEUE_STATE_RUNNING;
146140
return ESP_OK;
147141
}

esp_port/components/esp_webrtc_utils/src/flash_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ esp_err_t flash_wrapper_init(void)
230230
BaseType_t res = xTaskCreate(
231231
flash_op_task,
232232
"flash_op_task",
233-
8192,
233+
4096,
234234
NULL,
235235
5,
236236
&flash_task_handle

esp_port/components/kvs_webrtc/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ if(CONFIG_USE_ESP_WEBSOCKET_CLIENT)
102102
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DUSE_ESP_WEBSOCKET -DESP_PLATFORM)
103103
endif()
104104

105-
option(ENABLE_KVS_THREADPOOL "Enable support for KVS thread pool in signaling" ON)
105+
# option(ENABLE_KVS_THREADPOOL "Enable support for KVS thread pool in signaling" OFF)
106106
set(KVS_PLAT_ESP_FREERTOS ON CACHE BOOL "Build for ESP FreeRTOS")
107107
add_definitions(-DKVS_PLAT_ESP_FREERTOS)
108-
if (ENABLE_KVS_THREADPOOL)
109-
add_definitions(-DENABLE_KVS_THREADPOOL)
110-
endif()
108+
# if (ENABLE_KVS_THREADPOOL)
109+
# add_definitions(-DENABLE_KVS_THREADPOOL)
110+
# endif()
111111

112112
# Check for ifaddrs.h and poll.h
113113
include(CheckIncludeFiles)

esp_port/components/webrtc_bridge/idf_component.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ dependencies:
55
esp_webrtc_utils:
66
path: ../esp_webrtc_utils
77
version: "*"
8-
# espressif/esp_hosted:
9-
# override_path: ../esp_hosted
10-
# version: "*"
8+
9+
espressif/esp_hosted:
10+
override_path: ../esp_hosted
11+
version: "*"
12+
rules:
13+
- if: "target not in [linux]"
14+
15+
network_coprocessor:
16+
path: ../network_coprocessor
17+
version: "*"
18+
rules:
19+
- if: target in [esp32c6, esp32c5]

esp_port/components/webrtc_bridge/src/webrtc_bridge.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,16 @@ void webrtc_bridge_send_message(const char *data, int len)
275275
#ifndef CONFIG_ESP_WEBRTC_BRIDGE_HOSTED
276276
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
277277
{
278-
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id);
279278
esp_mqtt_event_handle_t event = event_data;
280279
esp_mqtt_client_handle_t client = event->client;
281280
int msg_id;
282-
283-
switch ((esp_mqtt_event_id_t)event_id) {
281+
// your_context_t *context = event->context;
282+
switch (event->event_id) {
284283
case MQTT_EVENT_CONNECTED:
284+
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
285285
msg_id = esp_mqtt_client_subscribe(client, FROM_TOPIC, 0);
286286
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
287287

288-
289-
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
290-
// msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0);
291-
// ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
292-
293-
// msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
294-
// ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
295-
296288
// msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
297289
// ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
298290

@@ -318,7 +310,11 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
318310
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
319311
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
320312
printf("DATA=%.*s\r\n", event->data_len, event->data);
321-
on_webrtc_bridge_msg_received(event->data, event->data_len);
313+
if (message_handler) {
314+
message_handler(event->data, event->data_len);
315+
} else {
316+
on_webrtc_bridge_msg_received((void *) event->data, event->data_len);
317+
}
322318
break;
323319
case MQTT_EVENT_ERROR:
324320
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");

esp_port/examples/app_common/idf_component.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ dependencies:
1111
version: "*"
1212
public: true
1313

14-
# espressif/esp_hosted:
15-
# override_path: ../../components/esp_hosted
16-
# version: "*"
14+
credential:
15+
path: ../../components/credential
16+
version: "*"
1717

1818
media_stream:
1919
path: ../../components/media_stream
@@ -23,3 +23,7 @@ dependencies:
2323
webrtc_bridge:
2424
path: ../../components/webrtc_bridge
2525
version: "*"
26+
27+
signaling_serializer:
28+
path: ../../components/signaling_serializer
29+
version: "*"

esp_port/examples/app_common/include/app_webrtc.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ typedef struct {
186186
RtcOnDataChannel onDataChannel;
187187
SignalingClientMetrics signalingClientMetrics;
188188

189+
// Callbacks for signaling messages
190+
VOID (*onAnswer)(UINT64, PSignalingMessage);
191+
VOID (*onIceCandidate)(UINT64, PSignalingMessage);
192+
189193
PStackQueue pPendingSignalingMessageForRemoteClient;
190194
PHashTable pRtcPeerConnectionForRemoteClient;
191195

@@ -291,7 +295,6 @@ STATUS createSampleConfiguration(PCHAR, SIGNALING_CHANNEL_ROLE_TYPE, BOOL, BOOL,
291295
STATUS freeSampleConfiguration(PSampleConfiguration*);
292296
STATUS signalingClientStateChanged(UINT64, SIGNALING_CLIENT_STATE);
293297
STATUS signalingMessageReceived(UINT64, PReceivedSignalingMessage);
294-
STATUS handleAnswer(PSampleConfiguration, PSampleStreamingSession, PSignalingMessage);
295298
STATUS handleOffer(PSampleConfiguration, PSampleStreamingSession, PSignalingMessage);
296299
STATUS handleRemoteCandidate(PSampleStreamingSession, PSignalingMessage);
297300
STATUS initializePeerConnection(PSampleConfiguration, PRtcPeerConnection*);
@@ -302,6 +305,28 @@ STATUS streamingSessionOnShutdown(PSampleStreamingSession, UINT64, StreamSession
302305
STATUS sendSignalingMessage(PSampleStreamingSession, PSignalingMessage);
303306
STATUS respondWithAnswer(PSampleStreamingSession);
304307
STATUS resetSampleConfigurationState(PSampleConfiguration);
308+
309+
#ifdef DYNAMIC_SIGNALING_PAYLOAD
310+
/**
311+
* @brief Allocate memory for the payload of a SignalingMessage
312+
*
313+
* @param[in,out] pSignalingMessage The signaling message for which to allocate payload
314+
* @param[in] size Size in bytes to allocate
315+
*
316+
* @return STATUS code of the execution
317+
*/
318+
STATUS allocateSignalingMessagePayload(PSignalingMessage pSignalingMessage, UINT32 size);
319+
320+
/**
321+
* @brief Free the dynamically allocated payload of a SignalingMessage
322+
*
323+
* @param[in,out] pSignalingMessage The signaling message whose payload should be freed
324+
*
325+
* @return STATUS code of the execution
326+
*/
327+
STATUS freeSignalingMessagePayload(PSignalingMessage pSignalingMessage);
328+
#endif
329+
305330
VOID sampleVideoFrameHandler(UINT64, PFrame);
306331
VOID sampleAudioFrameHandler(UINT64, PFrame);
307332
VOID sampleFrameHandler(UINT64, PFrame);
@@ -431,4 +456,4 @@ STATUS webrtcAppGetSampleConfiguration(PSampleConfiguration *ppSampleConfigurati
431456
#ifdef __cplusplus
432457
}
433458
#endif
434-
#endif /* __KINESIS_VIDEO_SAMPLE_INCLUDE__ */
459+
#endif /* __KINESIS_VIDEO_SAMPLE_INCLUDE__ */

0 commit comments

Comments
 (0)