From 753ee2267bf2a20d93370aa24ffa282e20558140 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sat, 18 Apr 2026 16:39:59 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E6=B2=A1=E6=9C=89?= =?utf8?q?=E6=8C=89=E7=85=A7=E5=B8=A7=E7=BB=93=E6=9E=84=E5=8F=91=E9=80=81?= =?utf8?q?=E6=95=B0=E6=8D=AE=E5=AF=BC=E8=87=B4=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?utf8?q?=E6=9C=89=E5=9D=8F=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../zhihui/leiniao/imsl_ln/ln_api_websocket.c | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c index 93b82f36c..73ec355e3 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c @@ -250,7 +250,7 @@ static uint32_t g_audio_timeout_ticks = 1500; // 音频超时tick数(默认1.5 uint32_t g_last_binary_data_tick = 0; // 最后一次接收二进制数据的tick // 音频数据最近缓存(环形缓冲区,仅保留最近数据) -#define AUDIO_CACHE_BUFFER_SIZE (1024*3) // 8KB缓存 +#define AUDIO_CACHE_BUFFER_SIZE (72*6*5) // 8KB缓存 static uint8_t g_audio_cache_buffer[AUDIO_CACHE_BUFFER_SIZE]; static uint32_t g_audio_cache_pos = 0; // 当前写入位置 static uint32_t g_audio_cache_total = 0; // 总写入数据量 @@ -291,7 +291,7 @@ static void ln_ws_reset_audio_cache(void); static uint32_t ln_ws_copy_from_ring_cache(uint32_t start_pos, uint32_t length, uint8_t* output); static int ln_ws_send_cached_audio_data(void); - +#define TIME_TICKS_TEST 0 /* 握手成功回调:标记连接就绪 */ static void ln_ws_on_open(int client) @@ -347,7 +347,10 @@ static void ln_ws_message_callback(const char *raw_data, uint32_t timestamp) LN_WS_WARN("Invalid message\n"); } LN_WS_DEBUG("on_message: %s\n", buf); - +#if TIME_TICKS_TEST + uint32_t current_tick = osKernelGetTickCount(); + LN_WS_DEBUG("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx on_message current_tick: %u\n", current_tick); +#endif free(buf); } @@ -613,6 +616,12 @@ static void ln_ws_audio_write_callback(uint32_t size) { LN_WS_DEBUG("Audio data written successfully: %u bytes\n", size); +#if TIME_TICKS_TEST + uint32_t current_tick = osKernelGetTickCount(); + LN_WS_DEBUG("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx current_tick: %u\n", current_tick); +#endif + + // 更新最后一次音频写入tick g_last_audio_write_tick = osKernelGetTickCount(); g_audio_playback_active = true; @@ -723,7 +732,14 @@ int ln_ws_send_audio_data(const uint8_t *audio_data, uint32_t audio_size, bool f LN_WS_ERROR("Failed to allocate memory for base64 encoding\n"); return -1; } - + memset(audio_base64, 0, base64_size); + // LN_WS_DEBUG("audio_data before encode: \n"); + // for(int i = 0; i < 32; i++) + // { + // printf(" %02X",audio_data[i]); + // } + // LN_WS_DEBUG("audio_data end\n"); + size_t output_len = 0; int ret_encode = mbedtls_base64_encode((unsigned char*)audio_base64, base64_size - 1, &output_len, audio_data, audio_size); @@ -1153,7 +1169,11 @@ static void AIVoiceDataCallback_ln(const uint8_t* data, uint32_t size, void* use static void ai_binary_message_handler(const uint8_t *raw_data, uint32_t timestamp, uint32_t data_len) { LN_WS_INFO("Received binary message at %u, length: %d bytes\n", timestamp, data_len); - + +#if TIME_TICKS_TEST + uint32_t current_tick = osKernelGetTickCount(); + LN_WS_DEBUG("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ai_binary_message_handler current_tick: %u\n", current_tick); +#endif // 收到二进制消息时,清除 ping 超时检测 if (g_ping_timeout_active) { g_ping_timeout_active = false; @@ -4093,7 +4113,7 @@ static int ln_ws_send_cached_audio_data(void) LN_WS_INFO("Sending cached audio data: %u bytes (wrapped=%d, start_pos=%u)\n", total_size, g_audio_cache_wrapped, start_pos); - #define MAX_SEND_CHUNK_SIZE 512 // 每次最多发送4KB + #define MAX_SEND_CHUNK_SIZE 72*6 // 每次最多发送4KB int ret = 0; uint32_t remaining = total_size; -- 2.17.1