Skip to content
Merged

CI #5

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build Examples
on:
workflow_call: {}
workflow_dispatch: {}
jobs:
build-examples:
name: Build Examples
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Add additional targets later
device: [esp32s3]
steps:
- name: Checkout
uses: actions/checkout@v4
with: { submodules: recursive }
- name: Build Examples
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4
command: |
export WIFI_SSID="---"
export WIFI_PASSWORD="---"
export LK_SERVER_URL="---"
export LK_TOKEN="---"
pip install idf-build-apps
idf-build-apps build -p ./examples --recursive --target ${{ matrix.device }}
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI
on:
schedule:
- cron: 0 0 * * 1
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]
push:
branches: [main]
concurrency:
group: "ci"
cancel-in-progress: true
jobs:
build-examples:
name: Build Examples
uses: ./.github/workflows/build_examples.yml
26 changes: 2 additions & 24 deletions components/livekit/core/engine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "esp_log.h"
#include "webrtc_utils_time.h"
#include "media_lib_os.h"
#include "esp_codec_dev.h"

Expand Down Expand Up @@ -39,21 +38,6 @@ typedef struct {
esp_peer_audio_stream_info_t sub_audio_info;
} engine_t;

/// @brief Performs one-time system initialization.
static void sys_init(void)
{
static bool is_initialized = false;
if (is_initialized) {
ESP_LOGI(TAG, "System already initialized");
return;
}
is_initialized = webrtc_utils_time_sync_init() == ESP_OK;
if (!is_initialized) {
ESP_LOGE(TAG, "System initialization failed");
return;
}
}

static esp_capture_codec_type_t capture_audio_codec_type(esp_peer_audio_codec_t peer_codec)
{
switch (peer_codec) {
Expand Down Expand Up @@ -153,7 +137,7 @@ static engine_err_t media_stream_begin(engine_t *eng)
}
media_lib_thread_handle_t handle = NULL;
eng->is_media_streaming = true;
if (media_lib_thread_create_from_scheduler(&handle, "lk_stream", media_stream_task, eng) != ESP_OK) {
if (media_lib_thread_create_from_scheduler(&handle, STREAM_THREAD_NAME, media_stream_task, eng) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create media stream thread");
eng->is_media_streaming = false;
return ENGINE_ERR_MEDIA;
Expand Down Expand Up @@ -267,6 +251,7 @@ static void free_ice_servers(engine_t *eng)
eng->ice_server_count = 0;
}

__attribute__((unused))
static engine_err_t set_ice_servers(engine_t* eng, livekit_pb_ice_server_t *servers, int count)
{
if (eng == NULL || servers == NULL || count <= 0) {
Expand Down Expand Up @@ -327,7 +312,6 @@ static void on_peer_pub_state_changed(peer_state_t state, void *ctx)

static void on_peer_sub_state_changed(peer_state_t state, void *ctx)
{
engine_t *eng = (engine_t *)ctx;
if (state == PEER_STATE_CONNECTED) {
// TODO: Subscribe
}
Expand All @@ -347,7 +331,6 @@ static void on_peer_sub_answer(const char *sdp, void *ctx)

static void on_peer_ice_candidate(const char *candidate, void *ctx)
{
engine_t *eng = (engine_t *)ctx;
ESP_LOGI(TAG, "Peer generated ice candidate: %s", candidate);
}

Expand Down Expand Up @@ -389,21 +372,18 @@ static void on_peer_sub_audio_frame(esp_peer_audio_frame_t* frame, void *ctx)

static void on_sig_connect(void *ctx)
{
engine_t *eng = (engine_t *)ctx;
ESP_LOGI(TAG, "Signaling connected");
// TODO: Implement
}

static void on_sig_disconnect(void *ctx)
{
engine_t *eng = (engine_t *)ctx;
ESP_LOGI(TAG, "Signaling disconnected");
// TODO: Implement
}

static void on_sig_error(void *ctx)
{
engine_t *eng = (engine_t *)ctx;
ESP_LOGI(TAG, "Signaling error");
// TODO: Implement
}
Expand Down Expand Up @@ -582,8 +562,6 @@ engine_err_t engine_connect(engine_handle_t handle, const char* server_url, cons
}
engine_t *eng = (engine_t *)handle;

sys_init();

if (signal_connect(eng->sig, server_url, token) != SIGNAL_ERR_NONE) {
ESP_LOGE(TAG, "Failed to connect signaling client");
return ENGINE_ERR_SIGNALING;
Expand Down
2 changes: 2 additions & 0 deletions components/livekit/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "common.h"
#include "protocol.h"

#define STREAM_THREAD_NAME "lk_stream"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
14 changes: 13 additions & 1 deletion components/livekit/core/livekit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "esp_peer.h"
#include "engine.h"
#include "rpc_manager.h"

#include "system.h"
#include "livekit.h"

static const char *TAG = "livekit";
Expand Down Expand Up @@ -141,6 +141,10 @@ livekit_err_t livekit_room_create(livekit_room_handle_t *handle, const livekit_r
if (handle == NULL || options == NULL) {
return LIVEKIT_ERR_INVALID_ARG;
}
if (!system_is_media_lib_setup()) {
ESP_LOGE(TAG, "Must perform system initialization before creating a room");
return LIVEKIT_ERR_SYSTEM_INIT;
}

// Validate options
if (options->publish.kind != LIVEKIT_MEDIA_TYPE_NONE &&
Expand Down Expand Up @@ -308,4 +312,12 @@ livekit_err_t livekit_room_rpc_unregister(livekit_room_handle_t handle, const ch
return LIVEKIT_ERR_INVALID_STATE;
}
return LIVEKIT_ERR_NONE;
}

livekit_err_t livekit_system_init(void)
{
if (!system_setup_media_lib()) {
return LIVEKIT_ERR_SYSTEM_INIT;
}
return LIVEKIT_ERR_NONE;
}
7 changes: 5 additions & 2 deletions components/livekit/core/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ static const char *SUB_TAG = "livekit_peer.sub";
static const char *PUB_TAG = "livekit_peer.pub";
#define TAG(peer) (peer->options.target == LIVEKIT_PB_SIGNAL_TARGET_SUBSCRIBER ? SUB_TAG : PUB_TAG)

#define SUB_THREAD_NAME (PEER_THREAD_NAME_PREFIX "sub")
#define PUB_THREAD_NAME (PEER_THREAD_NAME_PREFIX "pub")

#define RELIABLE_CHANNEL_LABEL "_reliable"
#define LOSSY_CHANNEL_LABEL "_lossy"
#define STREAM_ID_INVALID 0xFFFF
Expand Down Expand Up @@ -332,9 +335,9 @@ peer_err_t peer_connect(peer_handle_t handle)
peer->running = true;
media_lib_thread_handle_t thread;
const char* thread_name = peer->options.target == LIVEKIT_PB_SIGNAL_TARGET_SUBSCRIBER ?
"lk_sub_task" : "lk_pub_task";
SUB_THREAD_NAME : PUB_THREAD_NAME;
if (media_lib_thread_create_from_scheduler(&thread, thread_name, peer_task, peer) != ESP_PEER_ERR_NONE) {
ESP_LOGE(TAG(peer), "Failed to create task");
ESP_LOGE(TAG(peer), "Failed to create thread");
return PEER_ERR_RTC;
}

Expand Down
2 changes: 2 additions & 0 deletions components/livekit/core/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "engine.h"
#include "protocol.h"

#define PEER_THREAD_NAME_PREFIX "lk_peer_"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
31 changes: 0 additions & 31 deletions components/livekit/core/protocol.c

This file was deleted.

17 changes: 3 additions & 14 deletions components/livekit/core/protocol.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@

#pragma once

#include <pb_encode.h>
#include <pb_decode.h>
#include "pb_encode.h"
#include "pb_decode.h"

#include "livekit_rtc.pb.h"
#include "livekit_models.pb.h"
#include "livekit_metrics.pb.h"
#include "timestamp.pb.h"

#ifdef __cplusplus
extern "C" {
#endif

/// @brief Gets the name of the signaling response type.
const char* livekit_protocol_sig_res_name(pb_size_t which_message);

#ifdef __cplusplus
}
#endif
#include "timestamp.pb.h"
4 changes: 1 addition & 3 deletions components/livekit/core/signaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ static void on_data(signal_t *sg, const char *data, size_t len)
return;
}

ESP_LOGI(TAG, "Decoded res: type=%s(%d)",
livekit_protocol_sig_res_name(res.which_message),
res.which_message);
ESP_LOGI(TAG, "Decoded res: type=%d", res.which_message);
handle_res(sg, &res);
}

Expand Down
96 changes: 96 additions & 0 deletions components/livekit/core/system.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <stdbool.h>
#include "esp_log.h"
#include "webrtc_utils_time.h"
#include "media_lib_os.h"
#include "media_lib_adapter.h"
#include "system.h"
#include "peer.h"
#include "engine.h"

#define VIDEO_ENCODE_THREAD_NAME "venc"
#define AUDIO_ENCODE_THREAD_NAME "aenc"
#define AUDIO_DECODE_THREAD_NAME "Adec"
#define AEC_SRC_READ_THREAD_NAME "SrcRead"
#define AEC_BUFFER_IN_THREAD_NAME "buffer_in"

static const char *TAG = "livekit_system";
static bool is_media_lib_setup = false;

static void thread_scheduler(const char *thread_name, media_lib_thread_cfg_t *thread_cfg)
{
ESP_LOGI(TAG, "Scheduling thread '%s'", thread_name);

// LiveKit threads
if (strncmp(thread_name, PEER_THREAD_NAME_PREFIX, strlen(PEER_THREAD_NAME_PREFIX)) == 0) {
thread_cfg->stack_size = 25 * 1024;
thread_cfg->priority = 18;
thread_cfg->core_id = 1;
return;
}
if (strcmp(thread_name, STREAM_THREAD_NAME) == 0) {
thread_cfg->stack_size = 4 * 1024;
thread_cfg->priority = 15;
thread_cfg->core_id = 1;
return;
}

// Media lib threads
if (strcmp(thread_name, AUDIO_DECODE_THREAD_NAME) == 0) {
thread_cfg->stack_size = 40 * 1024;
thread_cfg->priority = 10;
thread_cfg->core_id = 1;
return;
}
if (strcmp(thread_name, AUDIO_ENCODE_THREAD_NAME) == 0) {
// Required for Opus
thread_cfg->stack_size = 40 * 1024;
thread_cfg->priority = 10;
return;
}
if (strcmp(thread_name, AEC_SRC_READ_THREAD_NAME) == 0) {
thread_cfg->stack_size = 40 * 1024;
thread_cfg->priority = 16;
thread_cfg->core_id = 0;
return;
}
if (strcmp(thread_name, AEC_BUFFER_IN_THREAD_NAME) == 0) {
thread_cfg->stack_size = 6 * 1024;
thread_cfg->priority = 10;
thread_cfg->core_id = 0;
return;
}
if (strcmp(thread_name, VIDEO_ENCODE_THREAD_NAME) == 0) {
#if CONFIG_IDF_TARGET_ESP32S3
thread_cfg->stack_size = 20 * 1024;
#endif
thread_cfg->priority = 10;
return;
}
}

bool system_setup_media_lib(void)
{
esp_err_t ret = media_lib_add_default_adapter();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to setup media lib");
return false;
}
media_lib_thread_set_schedule_cb(thread_scheduler);
is_media_lib_setup = true;
return true;
}

bool system_is_media_lib_setup(void)
{
return is_media_lib_setup;
}

bool system_sync_time(void)
{
esp_err_t ret = webrtc_utils_time_sync_init();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to sync time");
return false;
}
return true;
}
15 changes: 15 additions & 0 deletions components/livekit/core/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

bool system_setup_media_lib(void);
bool system_is_media_lib_setup(void);

bool system_sync_time(void);

#ifdef __cplusplus
}
#endif
Loading