优化了不必要的任务,待测

This commit is contained in:
CSBOOK\44744
2026-06-26 22:20:39 +08:00
parent 7d915e6fb0
commit 0635bd17f7
6 changed files with 126 additions and 356 deletions
@@ -35,14 +35,6 @@
#define CONFIG_MULTIMODAL_AUDIO_PREWARM_OPUS_BEFORE_WS 1
#endif
#if defined(CONFIG_MULTIMODAL_AUTO_START_ON_WAKEUP)
#define CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG CONFIG_MULTIMODAL_AUTO_START_ON_WAKEUP
#elif defined(CONFIG_MULTIMODAL_WS_AUTO_START)
#define CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG CONFIG_MULTIMODAL_WS_AUTO_START
#else
#define CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG 0
#endif
#define CONTROL_PLANE_DOWNSTREAM_PLAYBACK_GUARD_MS 220
#define CONTROL_PLANE_IDLE_TRANSPORT_SHUTDOWN_MS 30000
#define CONTROL_PLANE_WATCHDOG_TASK_STACK_SIZE 6144
@@ -60,11 +52,8 @@
static const char *TAG = "control_plane_mm_rt";
static TaskHandle_t s_multimodal_watchdog_task;
static TaskHandle_t s_multimodal_autostart_task;
static bool s_multimodal_watchdog_stop_requested;
static bool s_multimodal_autostart_stop_requested;
static bool s_multimodal_watchdog_task_starting;
static bool s_multimodal_autostart_task_starting;
static bool s_model_command_dispatched;
static bool s_server_success_prompt_played;
static control_plane_model_command_callback_t s_model_command_cb;
@@ -370,104 +359,6 @@ esp_err_t control_plane_multimodal_update_info(
return control_plane_multimodal_send_update_info(request);
}
static void multimodal_autostart_task(void *arg)
{
(void)arg;
TaskHandle_t self = xTaskGetCurrentTaskHandle();
TickType_t wait_step = pdMS_TO_TICKS(200);
TickType_t wait_timeout = pdMS_TO_TICKS(CONFIG_MULTIMODAL_RECONNECT_DELAY_MS + 3000);
if (wait_timeout < pdMS_TO_TICKS(3000)) {
wait_timeout = pdMS_TO_TICKS(3000);
}
TickType_t start_tick = xTaskGetTickCount();
while (!get_multimodal_stop_flag(&s_multimodal_autostart_stop_requested) &&
!control_plane_multimodal_is_connected()) {
if ((xTaskGetTickCount() - start_tick) >= wait_timeout) {
ESP_LOGW(TAG, "Auto Start aborted: transport not ready");
clear_multimodal_task_handle_if_match(&s_multimodal_autostart_task, self);
vTaskDelete(NULL);
return;
}
vTaskDelay(wait_step);
}
for (int attempt = 1;
!get_multimodal_stop_flag(&s_multimodal_autostart_stop_requested) && attempt <= 5 &&
control_plane_multimodal_is_connected();
++attempt) {
esp_err_t err = control_plane_multimodal_send_start();
if (err == ESP_OK) {
break;
}
if (attempt < 5 && control_plane_multimodal_is_connected()) {
ESP_LOGW(TAG,
"Auto Start send failed (%d/5): %s",
attempt,
esp_err_to_name(err));
vTaskDelay(pdMS_TO_TICKS(300));
} else {
ESP_LOGW(TAG, "Auto Start send failed: %s", esp_err_to_name(err));
}
}
clear_multimodal_task_handle_if_match(&s_multimodal_autostart_task, self);
vTaskDelete(NULL);
}
static void stop_autostart_task(void)
{
set_multimodal_stop_flag(&s_multimodal_autostart_stop_requested, true);
if (get_multimodal_task_handle(&s_multimodal_autostart_task) != NULL ||
get_multimodal_start_flag(&s_multimodal_autostart_task_starting)) {
if (!wait_task_exit(&s_multimodal_autostart_task,
&s_multimodal_autostart_task_starting,
800)) {
TaskHandle_t task = get_multimodal_task_handle(&s_multimodal_autostart_task);
if (task != NULL) {
vTaskDelete(task);
}
set_multimodal_task_handle(&s_multimodal_autostart_task, NULL);
}
}
set_multimodal_start_flag(&s_multimodal_autostart_task_starting, false);
set_multimodal_stop_flag(&s_multimodal_autostart_stop_requested, false);
}
static void schedule_autostart_if_enabled(void)
{
if (!CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG) {
return;
}
if (get_multimodal_task_handle(&s_multimodal_autostart_task) != NULL ||
get_multimodal_start_flag(&s_multimodal_autostart_task_starting)) {
return;
}
if (!try_begin_multimodal_task_start(&s_multimodal_autostart_task,
&s_multimodal_autostart_task_starting)) {
return;
}
set_multimodal_stop_flag(&s_multimodal_autostart_stop_requested, false);
if (xTaskCreatePinnedToCore(multimodal_autostart_task,
"mm_autostart",
6144,
NULL,
4,
&s_multimodal_autostart_task,
CONTROL_PLANE_MULTIMODAL_NETWORK_TASK_CORE) != pdPASS) {
set_multimodal_task_handle(&s_multimodal_autostart_task, NULL);
set_multimodal_start_flag(&s_multimodal_autostart_task_starting, false);
ESP_LOGW(TAG, "Auto Start task create failed");
return;
}
set_multimodal_start_flag(&s_multimodal_autostart_task_starting, false);
}
static void stop_watchdog_task(void)
{
set_multimodal_stop_flag(&s_multimodal_watchdog_stop_requested, true);
@@ -520,7 +411,6 @@ static void multimodal_watchdog_task(void *arg)
"Idle multimodal transport timeout, stopping client after %u ms",
(unsigned)CONTROL_PLANE_IDLE_TRANSPORT_SHUTDOWN_MS);
control_plane_multimodal_stop_uplink();
stop_autostart_task();
control_plane_multimodal_stop();
idle_transport_started_ms = 0U;
}
@@ -599,21 +489,16 @@ static void control_plane_multimodal_event_bridge(control_plane_multimodal_event
if (should_play_prompt) {
(void)domain_runtime_behavior_play_prompt_file(CONTROL_PLANE_SERVER_SUCCESS_PROMPT_FILE);
}
if (CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG) {
schedule_autostart_if_enabled();
}
break;
}
case CONTROL_PLANE_MULTIMODAL_EVENT_TRANSPORT_DISCONNECTED:
control_plane_multimodal_stop_uplink();
stop_autostart_task();
break;
case CONTROL_PLANE_MULTIMODAL_EVENT_TASK_FAILED:
control_plane_request_server_error_expression(DOMAIN_EXPRESSION_TRIGGER_SERVER_TASK_FAILED);
control_plane_multimodal_stop_uplink();
schedule_autostart_if_enabled();
break;
case CONTROL_PLANE_MULTIMODAL_EVENT_TASK_STARTED:
@@ -701,16 +586,11 @@ esp_err_t control_plane_start_multimodal_client(void)
return err;
}
if (CONTROL_PLANE_MULTIMODAL_AUTO_START_FLAG && control_plane_multimodal_is_connected()) {
schedule_autostart_if_enabled();
}
return ESP_OK;
}
void control_plane_stop_multimodal_client(void)
{
stop_autostart_task();
stop_watchdog_task();
control_plane_multimodal_stop();
}