Skip to content

Commit b96ece0

Browse files
committed
Restructured sample_config.c/h to app_webrtc.c/h
- We now handle specific initialization code in app_webrtc.c - Added event registration option
1 parent 673b037 commit b96ece0

File tree

10 files changed

+928
-385
lines changed

10 files changed

+928
-385
lines changed

esp_port/examples/app_common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(srcs "src/app_wifi.c" "src/app_storage.c" "src/sample_config.c" "src/app_media.c")
1+
set(srcs "src/app_wifi.c" "src/app_storage.c" "src/app_media.c" "src/app_webrtc.c")
22

33
set(requires esp_wifi fatfs spiffs media_stream)
44

esp_port/examples/app_common/idf_component.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ dependencies:
1515
path: ../../components/credential
1616
version: "*"
1717

18+
media_stream:
19+
path: ../../components/media_stream
20+
version: "*"
21+
1822
webrtc_bridge:
1923
path: ../../components/webrtc_bridge
2024
version: "*"

esp_port/examples/app_common/include/sample_config.h renamed to esp_port/examples/app_common/include/app_webrtc.h

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ extern "C" {
5656
#define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master"
5757
#define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer"
5858

59+
typedef enum {
60+
// Initialization / Deinitialization
61+
APP_WEBRTC_EVENT_INITIALIZED,
62+
APP_WEBRTC_EVENT_DEINITIALIZING,
63+
64+
// Signaling Client States
65+
APP_WEBRTC_EVENT_SIGNALING_CONNECTING,
66+
APP_WEBRTC_EVENT_SIGNALING_CONNECTED,
67+
APP_WEBRTC_EVENT_SIGNALING_DISCONNECTED,
68+
APP_WEBRTC_EVENT_SIGNALING_DESCRIBE,
69+
APP_WEBRTC_EVENT_SIGNALING_GET_ENDPOINT,
70+
APP_WEBRTC_EVENT_SIGNALING_GET_ICE,
71+
APP_WEBRTC_EVENT_PEER_CONNECTION_REQUESTED,
72+
APP_WEBRTC_EVENT_PEER_CONNECTED,
73+
APP_WEBRTC_EVENT_PEER_DISCONNECTED,
74+
APP_WEBRTC_EVENT_STREAMING_STARTED, // When media threads actually start for a peer
75+
APP_WEBRTC_EVENT_STREAMING_STOPPED, // When media threads stop for a peer
76+
APP_WEBRTC_EVENT_RECEIVED_OFFER,
77+
APP_WEBRTC_EVENT_SENT_ANSWER,
78+
APP_WEBRTC_EVENT_RECEIVED_ICE_CANDIDATE,
79+
APP_WEBRTC_EVENT_SENT_ICE_CANDIDATE,
80+
APP_WEBRTC_EVENT_ICE_GATHERING_COMPLETE,
81+
82+
// Peer Connection States
83+
APP_WEBRTC_EVENT_PEER_CONNECTING, // Peer connection attempt started
84+
APP_WEBRTC_EVENT_PEER_CONNECTION_FAILED, // Specific connection failure
85+
86+
// Error Events
87+
APP_WEBRTC_EVENT_ERROR,
88+
APP_WEBRTC_EVENT_SIGNALING_ERROR,
89+
} app_webrtc_event_t;
90+
5991
/**
6092
* @brief Structure to hold AWS credentials and related options
6193
*/
@@ -315,6 +347,112 @@ STATUS initSignaling(PSampleConfiguration, PCHAR);
315347
BOOL sampleFilterNetworkInterfaces(UINT64, PCHAR);
316348
UINT32 setLogLevel();
317349

350+
// Event data structure to pass to callbacks
351+
typedef struct {
352+
app_webrtc_event_t event_id;
353+
UINT32 status_code;
354+
CHAR peer_id[MAX_SIGNALING_CLIENT_ID_LEN + 1];
355+
CHAR message[256];
356+
} app_webrtc_event_data_t;
357+
358+
// Event callback type
359+
typedef void (*app_webrtc_event_callback_t) (app_webrtc_event_data_t *event_data, void *user_ctx);
360+
361+
/**
362+
* @brief Register a callback for WebRTC events
363+
*
364+
* @param callback Function to call when events occur
365+
* @param user_ctx User context pointer passed to the callback
366+
*
367+
* @return 0 on success, non-zero on failure
368+
*/
369+
INT32 app_webrtc_register_event_callback(app_webrtc_event_callback_t callback, void *user_ctx);
370+
371+
typedef enum {
372+
APP_WEBRTC_CLASSIC_MODE, // Default: both signaling and streaming
373+
APP_WEBRTC_SIGNALING_ONLY_MODE,
374+
APP_WEBRTC_STREAMING_ONLY_MODE,
375+
} app_webrtc_mode_t;
376+
377+
/**
378+
* @brief WebRTC application configuration structure
379+
*/
380+
typedef struct {
381+
// Channel configuration
382+
PCHAR pChannelName; // Name of the signaling channel
383+
SIGNALING_CHANNEL_ROLE_TYPE roleType; // Role type (master or viewer)
384+
385+
// AWS credentials configuration
386+
BOOL useIotCredentials; // Whether to use IoT Core credentials
387+
PCHAR iotCoreCredentialEndpoint; // IoT Core credential endpoint
388+
PCHAR iotCoreCert; // Path to IoT Core certificate
389+
PCHAR iotCorePrivateKey; // Path to IoT Core private key
390+
PCHAR iotCoreRoleAlias; // IoT Core role alias
391+
PCHAR iotCoreThingName; // IoT Core thing name
392+
393+
// Direct AWS credentials (if not using IoT credentials)
394+
PCHAR awsAccessKey; // AWS access key
395+
PCHAR awsSecretKey; // AWS secret key
396+
PCHAR awsSessionToken; // AWS session token
397+
398+
// Common AWS options
399+
PCHAR awsRegion; // AWS region
400+
PCHAR caCertPath; // Path to CA certificates
401+
402+
// WebRTC configuration
403+
BOOL trickleIce; // Whether to use trickle ICE
404+
BOOL useTurn; // Whether to use TURN servers
405+
UINT32 logLevel; // Log level
406+
407+
// Media configuration
408+
RTC_CODEC audioCodec; // Audio codec to use
409+
RTC_CODEC videoCodec; // Video codec to use
410+
SampleStreamingMediaType mediaType; // Media type (audio-only, video-only, or both)
411+
app_webrtc_mode_t mode; // Mode of the application
412+
413+
// Callbacks
414+
startRoutine audioSourceCallback; // Callback for audio source
415+
startRoutine videoSourceCallback; // Callback for video source
416+
startRoutine receiveAudioVideoCallback; // Callback for receiving audio/video
417+
} WebRtcAppConfig, *PWebRtcAppConfig;
418+
419+
/**
420+
* @brief Initialize WebRTC application with the given configuration
421+
*
422+
* This function creates and initializes the WebRTC configuration, sets up
423+
* the signaling client, and prepares the WebRTC stack for streaming.
424+
*
425+
* @param[in] pConfig Configuration for the WebRTC application
426+
*
427+
* @return STATUS code of the execution
428+
*/
429+
STATUS webrtcAppInit(PWebRtcAppConfig pConfig);
430+
431+
/**
432+
* @brief Run the WebRTC application and wait for termination
433+
*
434+
* This function starts the WebRTC streaming session and waits until it's terminated.
435+
*
436+
* @return STATUS code of the execution
437+
*/
438+
STATUS webrtcAppRun(VOID);
439+
440+
/**
441+
* @brief Terminate the WebRTC application
442+
*
443+
* This function cleans up resources and terminates the WebRTC application.
444+
*
445+
* @return STATUS code of the execution
446+
*/
447+
STATUS webrtcAppTerminate(VOID);
448+
449+
/**
450+
* @brief Get the sample configuration
451+
*
452+
* @return STATUS code of the execution
453+
*/
454+
STATUS webrtcAppGetSampleConfiguration(PSampleConfiguration *ppSampleConfiguration);
455+
318456
#ifdef __cplusplus
319457
}
320458
#endif

esp_port/examples/app_common/src/app_media.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "esp_log.h"
1010
#include "esp_timer.h"
1111
#include "app_media.h"
12-
#include "sample_config.h"
12+
#include "app_webrtc.h"
1313

1414
static const char *TAG = "app_media";
1515

0 commit comments

Comments
 (0)