mirror of
https://github.com/esphome/esphome.git
synced 2025-11-02 16:11:53 +00:00
Compare commits
4 Commits
web_server
...
voice_get_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fbb2a12b8 | ||
|
|
f1fddc058e | ||
|
|
d5ee5c7861 | ||
|
|
542ca43cf6 |
@@ -953,11 +953,21 @@ void VoiceAssistant::on_set_configuration(const std::vector<std::string> &active
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mark configuration dirty to trigger rebuild on next get_configuration() call.
|
||||
this->config_needs_rebuild_ = true;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
const Configuration &VoiceAssistant::get_configuration() {
|
||||
// Return cached configuration if it hasn't changed. This prevents a use-after-free
|
||||
// race condition when API message serialization creates StringRef pointers to strings
|
||||
// in config_.available_wake_words, and avoids wastefully rebuilding on every call.
|
||||
if (!this->config_needs_rebuild_) {
|
||||
return this->config_;
|
||||
}
|
||||
|
||||
this->config_.available_wake_words.clear();
|
||||
this->config_.active_wake_words.clear();
|
||||
|
||||
@@ -986,6 +996,8 @@ const Configuration &VoiceAssistant::get_configuration() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Mark configuration as clean now that we've rebuilt it
|
||||
this->config_needs_rebuild_ = false;
|
||||
return this->config_;
|
||||
};
|
||||
|
||||
|
||||
@@ -112,7 +112,10 @@ class VoiceAssistant : public Component {
|
||||
|
||||
void set_microphone_source(microphone::MicrophoneSource *mic_source) { this->mic_source_ = mic_source; }
|
||||
#ifdef USE_MICRO_WAKE_WORD
|
||||
void set_micro_wake_word(micro_wake_word::MicroWakeWord *mww) { this->micro_wake_word_ = mww; }
|
||||
void set_micro_wake_word(micro_wake_word::MicroWakeWord *mww) {
|
||||
this->micro_wake_word_ = mww;
|
||||
this->config_needs_rebuild_ = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_SPEAKER
|
||||
void set_speaker(speaker::Speaker *speaker) {
|
||||
@@ -313,7 +316,11 @@ class VoiceAssistant : public Component {
|
||||
bool udp_socket_running_{false};
|
||||
bool start_udp_socket_();
|
||||
|
||||
// Configuration caching for safety and performance. Only rebuild when config_needs_rebuild_
|
||||
// is true to prevent use-after-free race condition when StringRef pointers reference
|
||||
// wake word strings during API message serialization, and to avoid wasteful rebuilding.
|
||||
Configuration config_{};
|
||||
bool config_needs_rebuild_{true};
|
||||
|
||||
#ifdef USE_MICRO_WAKE_WORD
|
||||
micro_wake_word::MicroWakeWord *micro_wake_word_{nullptr};
|
||||
|
||||
Reference in New Issue
Block a user