From e73f9b34571e456594600244e580f648518e8ede Mon Sep 17 00:00:00 2001 From: dijunkun Date: Wed, 24 Jul 2024 16:11:40 +0800 Subject: [PATCH] Fix crash: send audio data when encoder has not inited yet --- src/pc/peer_connection.cpp | 8 ++++++++ xmake.lua | 18 +++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pc/peer_connection.cpp b/src/pc/peer_connection.cpp index 90f979f..a5f2020 100644 --- a/src/pc/peer_connection.cpp +++ b/src/pc/peer_connection.cpp @@ -603,6 +603,14 @@ int PeerConnection::SendVideoData(const char *data, size_t size) { } int PeerConnection::SendAudioData(const char *data, size_t size) { + if (!ice_ready_) { + return -1; + } + + if (ice_transmission_list_.empty()) { + return -1; + } + int ret = audio_encoder_->Encode( (uint8_t *)data, size, [this](char *encoded_audio_buffer, size_t size) -> int { diff --git a/xmake.lua b/xmake.lua index c8eeca5..fb46227 100644 --- a/xmake.lua +++ b/xmake.lua @@ -181,7 +181,7 @@ target("pc") add_includedirs("src/transmission", "src/interface", {public = true}) target("projectx") - set_kind("shared") + set_kind("static") add_deps("log", "pc") add_files("src/rtc/*.cpp") add_includedirs("src/rtc", "src/pc", "src/interface") @@ -203,14 +203,14 @@ target("projectx") end add_installfiles("src/interface/*.h", {prefixdir = "include"}) - add_rules("utils.symbols.export_list", {symbols = { - "CreatePeer", - "DestroyPeer", - "Init", - "CreateConnection", - "JoinConnection", - "LeaveConnection", - "SendData"}}) + -- add_rules("utils.symbols.export_list", {symbols = { + -- "CreatePeer", + -- "DestroyPeer", + -- "Init", + -- "CreateConnection", + -- "JoinConnection", + -- "LeaveConnection", + -- "SendData"}}) -- add_rules("utils.symbols.export_all", {export_classes = true})