Fix crash when adjusting volume via button while Es8311 audio device is disabled (#1917)
* Initial plan * Fix crash when adjusting volume via button while audio device is disabled When both input and output are disabled, UpdateDeviceState() sets dev_ to nullptr. Pressing a volume button calls SetOutputVolume() which previously called esp_codec_dev_set_out_vol(dev_, volume) without null-checking dev_, causing a crash via ESP_ERROR_CHECK. Fix: Add null guard for dev_ and mutex lock for thread safety. The volume is still saved via AudioCodec::SetOutputVolume() and will be applied when the device is reopened by UpdateDeviceState(). Agent-Logs-Url: https://github.com/78/xiaozhi-esp32/sessions/945c653a-ed16-49af-aefe-5cfb473402c6 Co-authored-by: 78 <4488133+78@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 78 <4488133+78@users.noreply.github.com>
This commit is contained in:
@ -156,7 +156,10 @@ void Es8311AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Es8311AudioCodec::SetOutputVolume(int volume) {
|
void Es8311AudioCodec::SetOutputVolume(int volume) {
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(dev_, volume));
|
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||||
|
if (dev_ != nullptr) {
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(dev_, volume));
|
||||||
|
}
|
||||||
AudioCodec::SetOutputVolume(volume);
|
AudioCodec::SetOutputVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user