fix(control_plane): preserve VAD generation on repeated PTT activation
This commit is contained in:
@@ -720,6 +720,14 @@ static bool control_plane_deactivate_ptt(
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 调用方持有 s_runtime_lock;收尾期间仍允许排队下一轮。 */
|
||||
static bool control_plane_ptt_has_active_turn_locked(void)
|
||||
{
|
||||
return s_ptt_runtime.active &&
|
||||
s_ptt_runtime.state != PTT_STATE_TEARDOWN_LOCAL &&
|
||||
s_ptt_runtime.state != PTT_STATE_TEARDOWN_REMOTE;
|
||||
}
|
||||
|
||||
static void control_plane_set_ptt_active_with_trigger(
|
||||
bool active,
|
||||
domain_expression_trigger_t listening_ui_trigger)
|
||||
@@ -729,6 +737,14 @@ static void control_plane_set_ptt_active_with_trigger(
|
||||
return;
|
||||
}
|
||||
|
||||
portENTER_CRITICAL(&s_runtime_lock);
|
||||
bool duplicate = control_plane_ptt_has_active_turn_locked();
|
||||
portEXIT_CRITICAL(&s_runtime_lock);
|
||||
if (duplicate) {
|
||||
ESP_LOGI(TAG, "PTT activation ignored: turn already active");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!control_plane_ota_business_interactions_allowed()) {
|
||||
ESP_LOGI(TAG, "PTT activation ignored during OTA");
|
||||
return;
|
||||
@@ -746,6 +762,12 @@ static void control_plane_set_ptt_active_with_trigger(
|
||||
ptt_state_t new_state = PTT_STATE_IDLE;
|
||||
uint32_t generation = 0;
|
||||
portENTER_CRITICAL(&s_runtime_lock);
|
||||
/* 前置检查会让出执行权;提交意图前再次检查,防止并发入口换代。 */
|
||||
if (control_plane_ptt_has_active_turn_locked()) {
|
||||
portEXIT_CRITICAL(&s_runtime_lock);
|
||||
ESP_LOGI(TAG, "PTT activation ignored: turn already active");
|
||||
return;
|
||||
}
|
||||
old_state = s_ptt_runtime.state;
|
||||
s_ws_start_requested = true;
|
||||
s_ptt_runtime.generation++;
|
||||
@@ -1915,6 +1937,21 @@ static bool control_plane_service_ptt_lifecycle(void)
|
||||
if (!local_wake_prompt_gate &&
|
||||
ptt.press_tick != 0 &&
|
||||
(now - ptt.press_tick) >= capture_timeout_ticks) {
|
||||
#if CONFIG_TQ_SPEECH_ENDPOINT_ENABLE
|
||||
domain_speech_endpoint_snapshot_t endpoint = {0};
|
||||
esp_err_t endpoint_err = domain_speech_endpoint_get_snapshot(&endpoint);
|
||||
if (endpoint_err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "VAD capture timeout: ptt_generation=%u endpoint_generation=%u active=%d speech=%d ended=%d audio_ms=%u silence_ms=%u max_process_us=%u gaps=%u",
|
||||
(unsigned)ptt.generation, (unsigned)endpoint.generation,
|
||||
endpoint.active ? 1 : 0, endpoint.speech_confirmed ? 1 : 0,
|
||||
endpoint.ended ? 1 : 0, (unsigned)endpoint.audio_ms,
|
||||
(unsigned)endpoint.silence_ms, (unsigned)endpoint.max_process_us,
|
||||
(unsigned)endpoint.discontinuities);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "VAD capture timeout snapshot unavailable: %s",
|
||||
esp_err_to_name(endpoint_err));
|
||||
}
|
||||
#endif
|
||||
(void)control_plane_deactivate_ptt(true,
|
||||
ptt.generation,
|
||||
"capture_timeout");
|
||||
|
||||
Reference in New Issue
Block a user