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; // 总写入数据量
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)
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);
}
{
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;
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);
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;
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;