Skip to content
Merged
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
4 changes: 3 additions & 1 deletion components/livekit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ idf_component_register(
)

idf_component_get_property(LIVEKIT_SDK_VERSION ${COMPONENT_NAME} COMPONENT_VERSION)
target_compile_definitions(${COMPONENT_LIB} PUBLIC "LIVEKIT_SDK_VERSION=\"${LIVEKIT_SDK_VERSION}\"")
target_compile_definitions(${COMPONENT_LIB} PUBLIC "LIVEKIT_SDK_VERSION=\"${LIVEKIT_SDK_VERSION}\"")

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wconversion")
78 changes: 39 additions & 39 deletions components/livekit/core/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef struct {

/// Detail for `EV_PEER_SDP`.
struct {
const char *sdp;
char *sdp;
peer_role_t role;
} peer_sdp;

Expand Down Expand Up @@ -163,7 +163,7 @@ static engine_err_t subscribe_tracks(engine_t *eng, livekit_pb_track_info_t *tra
// For now, subscribe to the first audio track.
ESP_LOGI(TAG, "Subscribing to audio track: sid=%s", track->sid);
signal_send_update_subscription(eng->signal_handle, track->sid, true);
strncpy(eng->session.sub_audio_track_sid, track->sid, sizeof(eng->session.sub_audio_track_sid));
strlcpy(eng->session.sub_audio_track_sid, track->sid, sizeof(eng->session.sub_audio_track_sid));
break;
}
return ENGINE_ERR_NONE;
Expand All @@ -190,7 +190,7 @@ static void on_peer_sub_audio_frame(esp_peer_audio_frame_t* frame, void *ctx)
av_render_audio_data_t audio_data = {
.pts = frame->pts,
.data = frame->data,
.size = frame->size,
.size = (uint32_t)frame->size,
};
av_render_add_audio_data(eng->renderer_handle, &audio_data);
}
Expand Down Expand Up @@ -320,8 +320,8 @@ static engine_err_t send_add_video_track(engine_t *eng)
{
livekit_pb_video_layer_t video_layer = {
.quality = LIVEKIT_PB_VIDEO_QUALITY_HIGH,
.width = eng->options.media.video_info.width,
.height = eng->options.media.video_info.height
.width = (uint32_t)eng->options.media.video_info.width,
.height = (uint32_t)eng->options.media.video_info.height
};
livekit_pb_add_track_request_t req = {
.cid = "v0",
Expand Down Expand Up @@ -473,20 +473,20 @@ static void destroy_peer_connections(engine_t *eng)
/// - Strings are not copied, so the caller must ensure the original ICE
/// server list stays alive until the peers are created.
///
static inline size_t map_ice_servers(
livekit_pb_ice_server_t *pb_servers_list,
int pb_servers_count,
static inline uint8_t map_ice_servers(
const livekit_pb_ice_server_t *pb_servers_list,
pb_size_t pb_servers_count,
esp_peer_ice_server_cfg_t *server_list,
size_t server_list_capacity
uint8_t server_list_capacity
) {
if (pb_servers_list == NULL ||
server_list == NULL ||
server_list_capacity == 0) {
return 0;
}
size_t count = 0;
for (int i = 0; i < pb_servers_count; i++) {
for (int j = 0; j < pb_servers_list[i].urls_count; j++) {
uint8_t count = 0;
for (pb_size_t i = 0; i < pb_servers_count; i++) {
for (pb_size_t j = 0; j < pb_servers_list[i].urls_count; j++) {
if (count >= server_list_capacity) {
ESP_LOGW(TAG, "ICE server list capacity exceeded");
return count;
Expand All @@ -500,10 +500,10 @@ static inline size_t map_ice_servers(
return count;
}

static bool establish_peer_connections(engine_t *eng, livekit_pb_join_response_t *join)
static bool establish_peer_connections(engine_t *eng, const livekit_pb_join_response_t *join)
{
esp_peer_ice_server_cfg_t server_list[CONFIG_LK_MAX_ICE_SERVERS];
int server_count = map_ice_servers(
uint8_t server_count = map_ice_servers(
join->ice_servers,
join->ice_servers_count,
server_list,
Expand Down Expand Up @@ -671,13 +671,13 @@ static inline void timer_stop(engine_t *eng)
xTimerStop(eng->timer, 0);
}

static bool handle_join(engine_t *eng, livekit_pb_join_response_t *join)
static bool handle_join(engine_t *eng, const livekit_pb_join_response_t *join)
{
// 1. Store connection settings
eng->session.is_subscriber_primary = join->subscriber_primary;

// 2. Store local Participant SID
strncpy(
strlcpy(
eng->session.local_participant_sid,
join->participant.sid,
sizeof(eng->session.local_participant_sid)
Expand All @@ -704,7 +704,7 @@ static bool handle_join(engine_t *eng, livekit_pb_join_response_t *join)
return true;
}

static void handle_trickle(engine_t *eng, livekit_pb_trickle_request_t *trickle)
static void handle_trickle(engine_t *eng, const livekit_pb_trickle_request_t *trickle)
{
char* candidate = NULL;
if (!protocol_signal_trickle_get_candidate(trickle, &candidate)) {
Expand All @@ -716,18 +716,18 @@ static void handle_trickle(engine_t *eng, livekit_pb_trickle_request_t *trickle)
free(candidate);
}

static void handle_room_update(engine_t *eng, livekit_pb_room_update_t *room_update)
static void handle_room_update(engine_t *eng, const livekit_pb_room_update_t *room_update)
{
if (eng->options.on_room_info && room_update->has_room) {
eng->options.on_room_info(&room_update->room, eng->options.ctx);
}
}

static void handle_participant_update(engine_t *eng, livekit_pb_participant_update_t *update)
static void handle_participant_update(engine_t *eng, const livekit_pb_participant_update_t *update)
{
bool found_local = false;
for (pb_size_t i = 0; i < update->participants_count; i++) {
livekit_pb_participant_info_t *participant = &update->participants[i];
const livekit_pb_participant_info_t *participant = &update->participants[i];
bool is_local = !found_local && strncmp(
participant->sid,
eng->session.local_participant_sid,
Expand Down Expand Up @@ -794,37 +794,37 @@ static bool handle_state_connecting(engine_t *eng, const engine_event_t *ev)
ESP_LOGW(TAG, "Engine already connecting, ignoring connect command");
break;
case EV_SIG_RES:
livekit_pb_signal_response_t *res = &ev->detail.res;
const livekit_pb_signal_response_t *res = &ev->detail.res;
switch (res->which_message) {
case LIVEKIT_PB_SIGNAL_RESPONSE_LEAVE_TAG:
livekit_pb_leave_request_t *leave = &res->message.leave;
const livekit_pb_leave_request_t *leave = &res->message.leave;
eng->failure_reason = map_disconnect_reason(leave->reason);
eng->state = ENGINE_STATE_DISCONNECTED;
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_ROOM_UPDATE_TAG:
livekit_pb_room_update_t *room_update = &res->message.room_update;
const livekit_pb_room_update_t *room_update = &res->message.room_update;
handle_room_update(eng, room_update);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_UPDATE_TAG:
livekit_pb_participant_update_t *update = &res->message.update;
const livekit_pb_participant_update_t *update = &res->message.update;
handle_participant_update(eng, update);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_JOIN_TAG:
livekit_pb_join_response_t *join = &res->message.join;
const livekit_pb_join_response_t *join = &res->message.join;
if (!handle_join(eng, join)) {
eng->state = ENGINE_STATE_BACKOFF;
}
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_ANSWER_TAG:
livekit_pb_session_description_t *answer = &res->message.answer;
const livekit_pb_session_description_t *answer = &res->message.answer;
peer_handle_sdp(eng->pub_peer_handle, answer->sdp);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_OFFER_TAG:
livekit_pb_session_description_t *offer = &res->message.offer;
const livekit_pb_session_description_t *offer = &res->message.offer;
peer_handle_sdp(eng->sub_peer_handle, offer->sdp);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_TRICKLE_TAG:
livekit_pb_trickle_request_t *trickle = &res->message.trickle;
const livekit_pb_trickle_request_t *trickle = &res->message.trickle;
handle_trickle(eng, trickle);
break;
default:
Expand Down Expand Up @@ -896,31 +896,31 @@ static bool handle_state_connected(engine_t *eng, const engine_event_t *ev)
ESP_LOGW(TAG, "Engine already connected, ignoring connect command");
break;
case EV_SIG_RES:
livekit_pb_signal_response_t *res = &ev->detail.res;
switch (ev->detail.res.which_message) {
const livekit_pb_signal_response_t *res = &ev->detail.res;
switch (res->which_message) {
case LIVEKIT_PB_SIGNAL_RESPONSE_LEAVE_TAG:
livekit_pb_leave_request_t *leave = &res->message.leave;
const livekit_pb_leave_request_t *leave = &res->message.leave;
eng->failure_reason = map_disconnect_reason(leave->reason);
eng->state = ENGINE_STATE_DISCONNECTED;
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_ROOM_UPDATE_TAG:
livekit_pb_room_update_t *room_update = &res->message.room_update;
const livekit_pb_room_update_t *room_update = &res->message.room_update;
handle_room_update(eng, room_update);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_UPDATE_TAG:
livekit_pb_participant_update_t *update = &res->message.update;
const livekit_pb_participant_update_t *update = &res->message.update;
handle_participant_update(eng, update);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_ANSWER_TAG:
livekit_pb_session_description_t *answer = &res->message.answer;
const livekit_pb_session_description_t *answer = &res->message.answer;
peer_handle_sdp(eng->pub_peer_handle, answer->sdp);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_OFFER_TAG:
livekit_pb_session_description_t *offer = &res->message.offer;
const livekit_pb_session_description_t *offer = &res->message.offer;
peer_handle_sdp(eng->sub_peer_handle, offer->sdp);
break;
case LIVEKIT_PB_SIGNAL_RESPONSE_TRICKLE_TAG:
livekit_pb_trickle_request_t *trickle = &res->message.trickle;
const livekit_pb_trickle_request_t *trickle = &res->message.trickle;
handle_trickle(eng, trickle);
break;
default:
Expand Down Expand Up @@ -1127,9 +1127,9 @@ engine_handle_t engine_init(const engine_options_t *options)
},
.video_info = {
.format_id = capture_video_codec_type(eng->options.media.video_info.codec),
.width = eng->options.media.video_info.width,
.height = eng->options.media.video_info.height,
.fps = eng->options.media.video_info.fps,
.width = (uint16_t)eng->options.media.video_info.width,
.height = (uint16_t)eng->options.media.video_info.height,
.fps = (uint8_t)eng->options.media.video_info.fps,
},
};
if (options->media.audio_info.codec != ESP_PEER_AUDIO_CODEC_NONE) {
Expand Down
8 changes: 4 additions & 4 deletions components/livekit/core/livekit.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void on_eng_room_info(const livekit_pb_room_t* info, void *ctx)
if (room->options.on_room_info == NULL) {
return;
}
livekit_room_info_t room_info = {
const livekit_room_info_t room_info = {
.sid = info->sid,
.name = info->name,
.metadata = info->metadata,
Expand All @@ -163,7 +163,7 @@ static void on_eng_participant_info(const livekit_pb_participant_info_t* info, b
if (room->options.on_participant_info == NULL) {
return;
}
livekit_participant_info_t participant_info = {
const livekit_participant_info_t participant_info = {
.sid = info->sid,
.identity = info->identity,
.name = info->name,
Expand Down Expand Up @@ -358,7 +358,7 @@ livekit_err_t livekit_room_publish_data(livekit_room_handle_t handle, livekit_da
if (bytes_array == NULL) {
return LIVEKIT_ERR_NO_MEM;
}
bytes_array->size = options->payload->size;
bytes_array->size = (pb_size_t)options->payload->size;
memcpy(bytes_array->bytes, options->payload->bytes, options->payload->size);

livekit_pb_user_packet_t user_packet = {
Expand All @@ -369,7 +369,7 @@ livekit_err_t livekit_room_publish_data(livekit_room_handle_t handle, livekit_da
packet.which_value = LIVEKIT_PB_DATA_PACKET_USER_TAG;
packet.value.user = user_packet;

packet.destination_identities_count = options->destination_identities_count;
packet.destination_identities_count = (pb_size_t)options->destination_identities_count;
packet.destination_identities = options->destination_identities;
// TODO: Set sender identity

Expand Down
8 changes: 4 additions & 4 deletions components/livekit/core/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int on_data(esp_peer_data_frame_t *frame, void *ctx)
}

livekit_pb_data_packet_t packet = {};
if (!protocol_data_packet_decode((const uint8_t *)frame->data, frame->size, &packet)) {
if (!protocol_data_packet_decode((const uint8_t *)frame->data, (size_t)frame->size, &packet)) {
ESP_LOGE(TAG(peer), "Failed to decode data packet");
return -1;
}
Expand Down Expand Up @@ -408,7 +408,7 @@ peer_err_t peer_handle_sdp(peer_handle_t handle, const char *sdp)
esp_peer_msg_t msg = {
.type = ESP_PEER_MSG_TYPE_SDP,
.data = (void *)sdp,
.size = strlen(sdp)
.size = (int)strlen(sdp)
};
if (esp_peer_send_msg(peer->connection, &msg) != ESP_PEER_ERR_NONE) {
ESP_LOGE(TAG(peer), "Failed to handle answer");
Expand All @@ -427,7 +427,7 @@ peer_err_t peer_handle_ice_candidate(peer_handle_t handle, const char *candidate
esp_peer_msg_t msg = {
.type = ESP_PEER_MSG_TYPE_CANDIDATE,
.data = (void *)candidate,
.size = strlen(candidate)
.size = (int)strlen(candidate)
};
if (esp_peer_send_msg(peer->connection, &msg) != ESP_PEER_ERR_NONE) {
ESP_LOGE(TAG(peer), "Failed to handle ICE candidate");
Expand Down Expand Up @@ -469,7 +469,7 @@ peer_err_t peer_send_data_packet(peer_handle_t handle, const livekit_pb_data_pac
break;
}
frame_info.data = enc_buf;
frame_info.size = encoded_size;
frame_info.size = (int)encoded_size;
if (esp_peer_send_data(peer->connection, &frame_info) != ESP_PEER_ERR_NONE) {
ESP_LOGE(TAG(peer), "Data channel send failed");
ret = PEER_ERR_RTC;
Expand Down
2 changes: 1 addition & 1 deletion components/livekit/core/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct {
esp_peer_ice_server_cfg_t* server_list;

/// Number of servers in the list.
int server_count;
uint8_t server_count;

/// Weather to force the use of relay ICE candidates.
bool force_relay;
Expand Down
8 changes: 4 additions & 4 deletions components/livekit/core/rpc_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static bool on_result(const livekit_rpc_result_t* result, void* ctx)
livekit_pb_data_packet_t res_packet = {
.which_value = LIVEKIT_PB_DATA_PACKET_RPC_RESPONSE_TAG
};
strncpy(res_packet.value.rpc_response.request_id,
strlcpy(res_packet.value.rpc_response.request_id,
result->id,
sizeof(res_packet.value.rpc_response.request_id));

Expand Down Expand Up @@ -79,7 +79,7 @@ static rpc_manager_err_t handle_request_packet(rpc_manager_t *manager, const liv
livekit_pb_data_packet_t ack_packet = {
.which_value = LIVEKIT_PB_DATA_PACKET_RPC_ACK_TAG
};
strncpy(ack_packet.value.rpc_ack.request_id,
strlcpy(ack_packet.value.rpc_ack.request_id,
request->id,
sizeof(ack_packet.value.rpc_ack.request_id));

Expand All @@ -98,7 +98,7 @@ static rpc_manager_err_t handle_request_packet(rpc_manager_t *manager, const liv
}
}
};
strncpy(res_packet.value.rpc_response.request_id,
strlcpy(res_packet.value.rpc_response.request_id,
request->id,
sizeof(res_packet.value.rpc_response.request_id));

Expand All @@ -120,7 +120,7 @@ static rpc_manager_err_t handle_request_packet(rpc_manager_t *manager, const liv
}
}
};
strncpy(res_packet.value.rpc_response.request_id,
strlcpy(res_packet.value.rpc_response.request_id,
request->id,
sizeof(res_packet.value.rpc_response.request_id));

Expand Down
4 changes: 2 additions & 2 deletions components/livekit/core/signaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static signal_err_t send_request(signal_t *sg, livekit_pb_signal_request_t *requ
}
if (esp_websocket_client_send_bin(sg->ws,
(const char *)enc_buf,
encoded_size,
(int)encoded_size,
portMAX_DELAY) < 0) {
//ESP_LOGE(TAG, "Failed to send request");
ret = SIGNAL_ERR_MESSAGE;
Expand Down Expand Up @@ -195,7 +195,7 @@ static void on_ws_event(void *ctx, esp_event_base_t base, int32_t event_id, void
}
if (data->data_len < 1) break;
livekit_pb_signal_response_t res = {};
if (!protocol_signal_response_decode((const uint8_t *)data->data_ptr, data->data_len, &res)) {
if (!protocol_signal_response_decode((const uint8_t *)data->data_ptr, (size_t)data->data_len, &res)) {
break;
}
if (res.which_message == 0) {
Expand Down
2 changes: 1 addition & 1 deletion components/livekit/core/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void capture_scheduler(const char *name, esp_capture_thread_schedule_cfg_
cfg->stack_in_ext = true;
cfg->stack_size = media_lib_cfg.stack_size;
cfg->priority = media_lib_cfg.priority;
cfg->core_id = media_lib_cfg.core_id;
cfg->core_id = (uint8_t)(media_lib_cfg.core_id & 0x0F);
}

// MARK: - Public API
Expand Down
Loading