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");
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);
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);
}
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");
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");
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;
// 延迟时间(微秒)= (数据大小(字节)* 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;
}