Merge #3059 into ln from refs/changes/3059/head 3061/target/1
author胡传军 <1224667075@qq.com>
Fri, 9 Jan 2026 09:28:35 +0000 (09:28 +0000)
committeraliyun3243248791 <accounts_67aaf52ad497cd558d73ac32@mail.teambition.com>
Fri, 9 Jan 2026 09:28:35 +0000 (09:28 +0000)
Code review from 胡传军

* refs/changes/3059/head: (3 commits squashed)

  - 增加语音故事可选spi传输

  - 修改送给下行流数据间隔,优化蓝牙播放无声问题

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

Signed-off-by: aliyun8003852482 <1224667075@qq.com>
Merged-by: 薛文强 <accounts_67aaf52ad497cd558d73ac32@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/3059
code/sdk/zhihui/4g/cat1Service/Service/http_file_download_client.c
code/sdk/zhihui/ai/media/ai_media_service_ext.cpp
code/sdk/zhihui/utils/custom_spi.c
code/sdk/zhihui/utils/custom_spi.h

index 8b95ab6..66b9507 100644 (file)
@@ -182,10 +182,6 @@ static void http_download_spi_error_callback(const custom_spi_error_info_t *erro
         if (g_download_state == HTTP_DOWNLOAD_STATE_DOWNLOADING) {
             cat1_print_err("HTTP download: Critical error detected, reinitializing SPI...\n");
             
-            // 取消注册回调函数
-            custom_spi_register_data_callback(NULL);
-            custom_spi_register_error_callback(NULL);
-            
             // 反初始化SPI
             custom_spi_hw_deinit();
             cat1_print_info("HTTP download: SPI deinitialized\n");
@@ -194,10 +190,6 @@ static void http_download_spi_error_callback(const custom_spi_error_info_t *erro
             custom_spi_hw_init();
             cat1_print_info("HTTP download: SPI reinitialized\n");
             
-            // 重新注册回调函数
-            custom_spi_register_data_callback(http_download_spi_data_callback);
-            custom_spi_register_error_callback(http_download_spi_error_callback);
-            cat1_print_info("HTTP download: SPI callbacks re-registered\n");
             //等待重启稳定
             LOS_Msleep(1000);
             
@@ -383,7 +375,7 @@ void http_file_download_deinit(void)
         g_download_timeout_timer.timer = NULL;
         cat1_print_info("HTTP file download service: Timeout timer destroyed\n");
     }
-    
+
     if (g_download_complete_sem != NULL) {
         osSemaphoreRelease(g_download_complete_sem);
     }
@@ -430,6 +422,12 @@ int http_file_download_start(const char *url, const char *file_path, uint32_t ti
         cat1_print_err("HTTP file download: Invalid URL\n");
         return -1;
     }
+
+    if(g_spi_data_callback_is_register()==false)
+    {
+        cat1_print_err("HTTP file download: Service not initialized, call http_file_download_init() first\n");
+        return -1;
+    }
     
     if (g_download_complete_sem == NULL) {
         cat1_print_err("HTTP file download: Service not initialized, call http_file_download_init() first\n");
@@ -602,6 +600,12 @@ int http_file_download_start_with_resume(const char *url, const char *file_path,
         cat1_print_err("HTTP file download: Invalid URL\n");
         return -1;
     }
+
+    if(g_spi_data_callback_is_register()==false)
+    {
+        cat1_print_err("HTTP file download: Service not initialized, call http_file_download_init() first\n");
+        return -1;
+    }
     
     if (g_download_complete_sem == NULL) {
         cat1_print_err("HTTP file download: Service not initialized, call http_file_download_init() first\n");
@@ -794,6 +798,12 @@ int http_file_download_resume(const char *url, const char *file_path, uint32_t r
         return -1;
     }
     
+    if(g_spi_data_callback_is_register()==false)
+    {
+        cat1_print_err("HTTP file download: Service not initialized, call http_file_download_init() first\n");
+        return -1;
+    }
+
     if (g_download_complete_sem == NULL) {
         cat1_print_err("HTTP file download resume: Service not initialized, call http_file_download_init() first\n");
         return -1;
index 8d7c0fa..020e747 100644 (file)
@@ -2187,21 +2187,18 @@ int32_t AI_WriteAudioData(const uint8_t* data, uint32_t size)
     // 延迟时间(微秒)= (数据大小(字节)* 8 * 1000000) / 比特率(bps)
     // 当比特率更高时,延迟时间更短
     // 公式:延迟(微秒)= (size * 8 * 1000000) / bit_rate
-    uint32_t delay_us = (uint32_t)((uint64_t)(size-(size/10*3)) * 8 * 1000000ULL / g_tts_audio_bit_rate);
+    uint32_t delay_us = (uint32_t)((uint64_t)(size-(size/10*5)) * 8 * 1000000ULL / g_tts_audio_bit_rate);
     printf("delay_us %d\r\n",delay_us);
     
-    // ç¡®ä¿\9då»¶è¿\9fæ\97¶é\97´å\9c¨å\90\88ç\90\86è\8c\83å\9b´å\86\85ï¼\88æ\9c\80å°\8f10å¾®ç§\92ï¼\8cæ\9c\80大100毫ç§\92ï¼\89
+    // 确保延迟时间在合理范围内(最小10微秒)
     if (delay_us < 20) {
         delay_us = 20;
-    } else if (delay_us > 100000) {
-        delay_us = 100000;
     }
-    
     usleep(delay_us-20);
     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(delay_us*5);
+        usleep(delay_us*retry_count/10*5);
         goto AI_WRITE;
     }
     
index 8ed75b4..a668952 100644 (file)
@@ -714,6 +714,14 @@ void custom_spi_register_data_callback(custom_spi_data_callback_t callback)
     }
 }
 
+bool g_spi_data_callback_is_register(void)
+{
+    if(g_spi_data_callback)
+    return true;
+    else
+    return false;
+}
+
 /**
  * @brief 注册SPI传输错误回调函数
  * @param callback 回调函数指针,NULL表示取消注册
index 06fc993..9a9cb03 100644 (file)
@@ -101,6 +101,8 @@ void custom_spi_register_error_callback(custom_spi_error_callback_t callback);
 
 void set_expected_seq(uint8_t data);
 
+bool g_spi_data_callback_is_register(void);
+
 
 #ifdef __cplusplus
 }