Merge #2589 into sdk650pathc0423 from refs/changes/2589/head
author胡传军 <1224667075@qq.com>
Thu, 23 Oct 2025 08:39:39 +0000 (08:39 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Thu, 23 Oct 2025 08:39:39 +0000 (08:39 +0000)
Code review from 胡传军

* refs/changes/2589/head: (5 commits squashed)

  - 增加优化 EG810 雷鸟对话

  - Merge branch &#39;sdk650pathc0423&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423

  - Merge branch &#39;sdk650pathc0423&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423

  - Merge branch &#39;sdk650pathc0423&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423

  - 修改雷鸟 播放卡顿问题

Signed-off-by: aliyun8003852482 <1224667075@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2589
code/sdk/zhihui/ai/media/ai_media_service_ext.cpp
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index 87d85dc..0371623 100644 (file)
@@ -1357,7 +1357,7 @@ int32_t old_Start_AIVoice(AIVoiceDataCallback dataCallback, void* userData,
     
     task_cfg.create_queue_handle = CreateAIVoiceQueue;  // 设置队列创建函数
     task_cfg.attr.name = "AIVoiceThread";
-    task_cfg.attr.priority = (osPriority_t)24;  // 使用合适的优先级
+    task_cfg.attr.priority = (osPriority_t)28;  // 使用合适的优先级
     task_cfg.attr.stack_size = 0x2000;  // 8KB栈空间
     task_cfg.func = AIVoiceThread;
     task_cfg.use_mem = USE_EXTEND_MEM;
@@ -1644,11 +1644,11 @@ int32_t AI_WriteAudioData(const uint8_t* data, uint32_t size)
 
     // 写入音频数据到输出流
     int32_t ret = AudioStreamOutStreamWrite(data, size);
-    usleep(50*size);
+    usleep(40*size);
     if (ret != 0) {
         retry_count++;
         // MEDIA_ERR_LOG("Failed to write audio data to output stream, ret=%d, retry %d/%d", ret, retry_count, MAX_RETRY_COUNT);
-        usleep(1000*600);
+        usleep(1000*300);
         goto AI_WRITE;
     }
     
@@ -1724,6 +1724,7 @@ int32_t AI_SendAudioDataToQueue(const uint8_t* data, uint32_t size)
         int32_t result = AI_WriteToFileCache(msg);
         if (result == 0) {
             MEDIA_DEBUG_LOG("Successfully wrote %u bytes to file cache", size);
+            free(dataCopy);
             return 0;
         } else {
             MEDIA_ERR_LOG("Failed to write to file cache");
@@ -1755,6 +1756,7 @@ int32_t AI_SendAudioDataToQueue(const uint8_t* data, uint32_t size)
         int32_t result = AI_WriteToFileCache(msg);
         if (result == 0) {
             MEDIA_INFO_LOG("Successfully wrote %u bytes to file cache to maintain order", size);
+            free(dataCopy);
             return 0;
         } else {
             MEDIA_ERR_LOG("Failed to write to file cache for order maintenance");
index aee8672..bd1dfb9 100644 (file)
@@ -301,8 +301,11 @@ static void ln_ws_url_callback(char *url, size_t url_size, char *header_buf, siz
     snprintf(url, url_size, "%s?deviceToken=%s&deviceId=%s&reconnect=%u",
              base, token, device_id, g_ws_reconnect_count);
     
-    /* 构建头部信息 */
+    // /* 构建头部信息 */
     snprintf(header_buf, header_size, "deviceId: %s\r\n", device_id);
+    // 110.42.224.129 8910
+    //  snprintf(url, url_size, "%s","ws://110.42.224.129:8910");
+            //  base, token, device_id, g_ws_reconnect_count);
 }
 
 /* 心跳处理回调函数 */
@@ -483,26 +486,7 @@ int ln_ws_send_audio_data(const uint8_t *audio_data, uint32_t audio_size, bool f
     
     // ========== VAD 处理:在录音接口层推送 ==========
     // 优势:1. 更上层更清晰  2. 天然只处理录音数据  3. finished即is_last
-#if ENABLE_VAD_SERVER
-    if (g_vad_server_enabled && g_vad_server_initialized && vad_server_is_running()) {
-        vad_audio_format_t format = VAD_AUDIO_FORMAT_MP3;  // 默认 MP3
-        
-        if (audio_data && audio_size > 0) {
-            errcode_t ret = vad_server_send_audio(format, audio_data, audio_size, finished);
-            if (ret != ERRCODE_SUCC) {
-                /* 静默失败,避免过多日志 */
-            } else {
-                LN_WS_DEBUG("VAD: Sent %u bytes (format=%d, is_last=%d)\n", 
-                           audio_size, format, finished);
-            }
-        }
-        
-        // 如果是结束标志,打印日志
-        if (finished) {
-            LN_WS_INFO("VAD: Audio recording ended\n");
-        }
-    }
-#endif
+
     // ================================================
     
     // 检查连接状态
@@ -726,6 +710,27 @@ static void AIVoiceDataCallback_ln(const uint8_t* data, uint32_t size, void* use
     
     // ========== VAD 处理已移到 ln_ws_send_audio_data (录音接口层) ==========
     // 更上层、更清晰、天然只处理录音数据
+    #if ENABLE_VAD_SERVER
+    if (g_vad_server_enabled && g_vad_server_initialized && vad_server_is_running()) {
+        vad_audio_format_t format = VAD_AUDIO_FORMAT_MP3;  // 默认 MP3
+        
+        if (data && size > 0) {
+            errcode_t ret = vad_server_send_audio(format, data, size, false);
+            if (ret != ERRCODE_SUCC) {
+                /* 静默失败,避免过多日志 */
+            } else {
+                LN_WS_DEBUG("VAD: Sent %u bytes (format=%d, is_last=%d)\n", 
+                           size, format, false);
+            }
+        }
+        
+        // 如果是结束标志,打印日志
+        if (false) {
+            LN_WS_INFO("VAD: Audio recording ended\n");
+        }
+    }
+    #endif
+
     
     // WebSocket 发送逻辑(如果需要同时发送到服务器)
     if (g_audio_chat_ctx.is_active == true)
@@ -800,6 +805,35 @@ static void ln_ws_incomplete_callback(const char *raw_data, size_t length, bool
     if (!raw_data || length == 0) {
         return;
     }
+
+    if(isBinary)
+    {
+         const size_t CHUNK_SIZE = 1024; // 1K 分块大小
+        if (length <= CHUNK_SIZE) {
+        // 数据小于等于1K,直接发送
+        LN_WS_DEBUG("Sending data directly (size: %d bytes)\n", length);
+        AI_SendAudioDataToQueue((uint8_t *)raw_data, length);
+        } else {
+            // 数据大于1K,分块发送
+            LN_WS_DEBUG("Data size %d bytes > %zu bytes, splitting into chunks\n", length, CHUNK_SIZE);
+            
+            size_t remaining = length;
+            const uint8_t *current_pos = (uint8_t *)raw_data;
+            int chunk_count = 0;
+            
+            while (remaining > 0) {
+                size_t current_chunk_size = (remaining > CHUNK_SIZE) ? CHUNK_SIZE : remaining;
+                
+                LN_WS_DEBUG("Sending chunk %d: %zu bytes\n", ++chunk_count, current_chunk_size);
+                AI_SendAudioDataToQueue(current_pos, current_chunk_size);
+                
+                current_pos += current_chunk_size;
+                remaining -= current_chunk_size;
+            }
+            
+            LN_WS_DEBUG("All %d chunks sent successfully\n", chunk_count);
+        }
+    }
     
     LN_WS_DEBUG("Incomplete message received: length=%zu, isBinary=%s\n", 
            length, isBinary ? "true" : "false");
@@ -961,8 +995,9 @@ void ln_ws_audio_init(void)
     #ifdef SUPPORT_CAT1_SERVICE
     cat1_api_keep_wakeup(1);
     cat1_api_wakeup_cat1(1);
-    uapi_cat1_add_cat1_vote();
+    
     #endif
+    uapi_cat1_add_cat1_vote();
 
     old_Start_AIVoice(AIVoiceDataCallback_ln,NULL,&audioParams_in,&audioParams_out,false);
     
@@ -1013,8 +1048,9 @@ void ln_ws_audio_deinit(void)
     #ifdef SUPPORT_CAT1_SERVICE
     cat1_api_keep_wakeup(0);
     cat1_api_wakeup_cat1(0);
-    uapi_cat1_remove_cat1_vote();
     #endif
+    uapi_cat1_remove_cat1_vote();
+
     
     // 清除初始化标志位
     g_audio_initialized = false;
@@ -1270,7 +1306,7 @@ int ln_ws_send_voice_chat_interrupt(const char *reason)
     if (ret == 0) {
         LN_WS_DEBUG("VoiceChatInterrupt sent successfully\n");
         
-        if (1) {
+        if (need_reconnect) {
             // 如果检测到频繁数据接收,直接重连
             LN_WS_INFO("Triggering reconnection due to frequent binary data reception\n");
             if (ln_ws_reconnect() != 0) {