@@ -34,16 +34,18 @@ extern "C" {
34
34
* @brief Peer state
35
35
*/
36
36
typedef enum {
37
- ESP_PEER_STATE_CLOSED = 0 , /*!< Closed */
38
- ESP_PEER_STATE_DISCONNECTED = 1 , /*!< Disconnected */
39
- ESP_PEER_STATE_NEW_CONNECTION = 2 , /*!< New connection comming */
40
- ESP_PEER_STATE_PAIRING = 3 , /*!< Under candidate pairing */
41
- ESP_PEER_STATE_PAIRED = 4 , /*!< Candidate pairing success */
42
- ESP_PEER_STATE_CONNECTING = 5 , /*!< Building connection with peer */
43
- ESP_PEER_STATE_CONNECTED = 6 , /*!< Connected with peer */
44
- ESP_PEER_STATE_CONNECT_FAILED = 7 , /*!< Connect failed */
45
- ESP_PEER_STATE_DATA_CHANNEL_OPENED = 8 , /*!< Data channel is opened */
46
- ESP_PEER_STATE_DATA_CHANNEL_CLOSED = 9 , /*!< Data channel is closed */
37
+ ESP_PEER_STATE_CLOSED = 0 , /*!< Closed */
38
+ ESP_PEER_STATE_DISCONNECTED = 1 , /*!< Disconnected */
39
+ ESP_PEER_STATE_NEW_CONNECTION = 2 , /*!< New connection comming */
40
+ ESP_PEER_STATE_PAIRING = 3 , /*!< Under candidate pairing */
41
+ ESP_PEER_STATE_PAIRED = 4 , /*!< Candidate pairing success */
42
+ ESP_PEER_STATE_CONNECTING = 5 , /*!< Building connection with peer */
43
+ ESP_PEER_STATE_CONNECTED = 6 , /*!< Connected with peer */
44
+ ESP_PEER_STATE_CONNECT_FAILED = 7 , /*!< Connect failed */
45
+ ESP_PEER_STATE_DATA_CHANNEL_CONNECTED = 8 , /*!< Data channel is connected */
46
+ ESP_PEER_STATE_DATA_CHANNEL_OPENED = 9 , /*!< Data channel is opened */
47
+ ESP_PEER_STATE_DATA_CHANNEL_CLOSED = 10 , /*!< Data channel is closed */
48
+ ESP_PEER_STATE_DATA_CHANNEL_DISCONNECTED = 11 , /*!< Data channel is disconencted */
47
49
} esp_peer_state_t ;
48
50
49
51
/**
@@ -134,9 +136,10 @@ typedef struct {
134
136
* @brief Data frame information
135
137
*/
136
138
typedef struct {
137
- esp_peer_data_channel_type_t type ; /*!< Data channel type */
138
- uint8_t * data ; /*!< Pointer to data to be sent through data channel */
139
- int size ; /*!< Data size */
139
+ esp_peer_data_channel_type_t type ; /*!< Data channel type */
140
+ uint16_t stream_id ; /*!< Data channel stream ID */
141
+ uint8_t * data ; /*!< Pointer to data to be sent through data channel */
142
+ int size ; /*!< Data size */
140
143
} esp_peer_data_frame_t ;
141
144
142
145
/**
@@ -157,6 +160,21 @@ typedef struct {
157
160
int size ; /*!< Message data size */
158
161
} esp_peer_msg_t ;
159
162
163
+ /**
164
+ * @brief Peer data channel configuration for create
165
+ */
166
+ typedef struct {
167
+ char * label ; /*!< Data channel label */
168
+ } esp_peer_data_channel_cfg_t ;
169
+
170
+ /**
171
+ * @brief Peer data channel information
172
+ */
173
+ typedef struct {
174
+ const char * label ; /*!< Data channel label */
175
+ uint16_t stream_id ; /*!< Chunk stream id for this channel */
176
+ } esp_peer_data_channel_info_t ;
177
+
160
178
/**
161
179
* @brief Peer handle
162
180
*/
@@ -174,7 +192,12 @@ typedef struct {
174
192
esp_peer_video_stream_info_t video_info ; /*!< Video stream information */
175
193
esp_peer_media_dir_t audio_dir ; /*!< Audio transmission direction */
176
194
esp_peer_media_dir_t video_dir ; /*!< Video transmission direction */
195
+ bool no_auto_reconnect ; /*!< Disable auto reconnect if connected fail */
177
196
bool enable_data_channel ; /*!< Enable data channel */
197
+ bool manual_ch_create ; /*!< Manual create data channel
198
+ When SCTP role is client, it will try to send DCEP automatically
199
+ To disable this behavior can create data channel manually and set this flag
200
+ */
178
201
void * extra_cfg ; /*!< Extra configuration */
179
202
int extra_size ; /*!< Extra configuration size */
180
203
void * ctx ; /*!< User context */
@@ -227,13 +250,29 @@ typedef struct {
227
250
*/
228
251
int (* on_video_data )(esp_peer_video_frame_t * frame , void * ctx );
229
252
253
+ /**
254
+ * @brief Peer data channel opened event callback
255
+ * @param[in] ch Data channel information
256
+ * @param[in] ctx User context
257
+ * @return Status code indicating success or failure.
258
+ */
259
+ int (* on_channel_open )(esp_peer_data_channel_info_t * ch , void * ctx );
260
+
230
261
/**
231
262
* @brief Peer data frame callback
232
263
* @param[in] frame Data frame information
233
264
* @param[in] ctx User context
234
265
* @return Status code indicating success or failure.
235
266
*/
236
- int (* on_data )(esp_peer_data_frame_t * frame , void * ctx );
267
+ int (* on_data )(esp_peer_data_frame_t * frame , void * ctx );
268
+
269
+ /**
270
+ * @brief Peer data channel closed event callback
271
+ * @param[in] ch Data channel information
272
+ * @param[in] ctx User context
273
+ * @return Status code indicating success or failure.
274
+ */
275
+ int (* on_channel_close )(esp_peer_data_channel_info_t * ch , void * ctx );
237
276
} esp_peer_cfg_t ;
238
277
239
278
/**
@@ -296,6 +335,22 @@ typedef struct {
296
335
*/
297
336
int (* send_data )(esp_peer_handle_t peer , esp_peer_data_frame_t * frame );
298
337
338
+ /**
339
+ * @brief Manually create data chanel for peer
340
+ * @param[in] peer Peer handle
341
+ * @param[in] ch_cfg Data channel configuration
342
+ * @return Status code indicating success or failure.
343
+ */
344
+ int (* create_data_channel )(esp_peer_handle_t peer , esp_peer_data_channel_cfg_t * ch_cfg );
345
+
346
+ /**
347
+ * @brief Close data chanel for peer
348
+ * @param[in] peer Peer handle
349
+ * @param[in] label Data channel label
350
+ * @return Status code indicating success or failure.
351
+ */
352
+ int (* close_data_channel )(esp_peer_handle_t peer , const char * label );
353
+
299
354
/**
300
355
* @brief Peer main loop
301
356
* @note Peer connection need handle peer status change, receive stream data in this loop
@@ -338,7 +393,7 @@ typedef struct {
338
393
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
339
394
* - ESP_PEER_ERR_NOT_SUPPORT Not support
340
395
*/
341
- int esp_peer_open (esp_peer_cfg_t * cfg , const esp_peer_ops_t * ops , esp_peer_handle_t * handle );
396
+ int esp_peer_open (esp_peer_cfg_t * cfg , const esp_peer_ops_t * ops , esp_peer_handle_t * peer );
342
397
343
398
/**
344
399
* @brief Create new conenction
@@ -353,22 +408,53 @@ int esp_peer_open(esp_peer_cfg_t *cfg, const esp_peer_ops_t *ops, esp_peer_handl
353
408
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
354
409
* - ESP_PEER_ERR_NOT_SUPPORT Not support
355
410
*/
356
- int esp_peer_new_connection (esp_peer_handle_t handle );
411
+ int esp_peer_new_connection (esp_peer_handle_t peer );
412
+
413
+ /**
414
+ * @brief Manually create data channel
415
+ *
416
+ * @note It will send DCEP event to peer until data channel created
417
+ *
418
+ * @param[in] peer Peer handle
419
+ * @param[in] ch_cfg Configuration for data channel creation
420
+ *
421
+ * @return
422
+ * - ESP_PEER_ERR_NONE Open data channel success
423
+ * - ESP_PEER_ERR_INVALID_ARG Invalid argument
424
+ * - ESP_PEER_ERR_NOT_SUPPORT Not support
425
+ */
426
+ int esp_peer_create_data_channel (esp_peer_handle_t peer , esp_peer_data_channel_cfg_t * ch_cfg );
427
+
428
+ /**
429
+ * @brief Manually close data channel by label
430
+ *
431
+ * @param[in] peer Peer handle
432
+ * @param[in] label Channel label
433
+ *
434
+ * @return
435
+ * - ESP_PEER_ERR_NONE Close data channel success
436
+ * - ESP_PEER_ERR_INVALID_ARG Invalid argument
437
+ * - ESP_PEER_ERR_NOT_SUPPORT Not support
438
+ */
439
+ int esp_peer_close_data_channel (esp_peer_handle_t peer , const char * label );
357
440
358
441
/**
359
442
* @brief Update ICE server information
360
443
*
361
444
* @note After new connection is created, It will try gather ICE candidate from ICE servers.
362
445
* And report local SDP to let user send to signaling server.
363
446
*
364
- * @param[in] peer Peer handle
447
+ * @param[in] peer Peer handle
448
+ * @param[in] role Peer roles of controlling or controlled
449
+ * @param[in] server Pointer to array of ICE server configuration
450
+ * @param[in] server_num ICE server number
365
451
*
366
452
* @return
367
453
* - ESP_PEER_ERR_NONE Open peer connection success
368
454
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
369
455
* - ESP_PEER_ERR_NOT_SUPPORT Not support
370
456
*/
371
- int esp_peer_update_ice_info (esp_peer_handle_t handle , esp_peer_role_t role , esp_peer_ice_server_cfg_t * server , int server_num );
457
+ int esp_peer_update_ice_info (esp_peer_handle_t peer , esp_peer_role_t role , esp_peer_ice_server_cfg_t * server , int server_num );
372
458
373
459
/**
374
460
* @brief Send message to peer
@@ -453,7 +539,7 @@ int esp_peer_main_loop(esp_peer_handle_t peer);
453
539
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
454
540
* - ESP_PEER_ERR_NOT_SUPPORT Not support
455
541
*/
456
- int esp_peer_disconnect (esp_peer_handle_t handle );
542
+ int esp_peer_disconnect (esp_peer_handle_t peer );
457
543
458
544
/**
459
545
* @brief Query of peer connection
@@ -466,7 +552,7 @@ int esp_peer_disconnect(esp_peer_handle_t handle);
466
552
* - ESP_PEER_ERR_NONE Open peer connection success
467
553
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
468
554
*/
469
- int esp_peer_query (esp_peer_handle_t handle );
555
+ int esp_peer_query (esp_peer_handle_t peer );
470
556
471
557
/**
472
558
* @brief Close peer connection
@@ -480,7 +566,7 @@ int esp_peer_query(esp_peer_handle_t handle);
480
566
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
481
567
* - ESP_PEER_ERR_NOT_SUPPORT Not support
482
568
*/
483
- int esp_peer_close (esp_peer_handle_t handle );
569
+ int esp_peer_close (esp_peer_handle_t peer );
484
570
485
571
#ifdef __cplusplus
486
572
}
0 commit comments