Guard audio pipeline file accesses

This commit is contained in:
jacqueline
2023-10-05 14:23:48 +11:00
parent ee8e523456
commit bf1fc5a2a0
2 changed files with 12 additions and 1 deletions
+8 -1
View File
@@ -32,6 +32,7 @@
#include "event_queue.hpp"
#include "fatfs_source.hpp"
#include "future_fetcher.hpp"
#include "spi.hpp"
#include "tag_parser.hpp"
#include "tasks.hpp"
#include "track.hpp"
@@ -127,7 +128,13 @@ auto FatfsAudioInput::OpenFile(const std::pmr::string& path) -> bool {
}
std::unique_ptr<FIL> file = std::make_unique<FIL>();
FRESULT res = f_open(file.get(), path.c_str(), FA_READ);
FRESULT res;
{
auto lock = drivers::acquire_spi();
res = f_open(file.get(), path.c_str(), FA_READ);
}
if (res != FR_OK) {
ESP_LOGE(kTag, "failed to open file! res: %i", res);
return false;
+4
View File
@@ -15,6 +15,7 @@
#include "audio_source.hpp"
#include "codec.hpp"
#include "spi.hpp"
#include "types.hpp"
namespace audio {
@@ -25,10 +26,12 @@ FatfsSource::FatfsSource(codecs::StreamType t, std::unique_ptr<FIL> file)
: IStream(t), file_(std::move(file)) {}
FatfsSource::~FatfsSource() {
auto lock = drivers::acquire_spi();
f_close(file_.get());
}
auto FatfsSource::Read(cpp::span<std::byte> dest) -> ssize_t {
auto lock = drivers::acquire_spi();
if (f_eof(file_.get())) {
return 0;
}
@@ -46,6 +49,7 @@ auto FatfsSource::CanSeek() -> bool {
}
auto FatfsSource::SeekTo(int64_t destination, SeekFrom from) -> void {
auto lock = drivers::acquire_spi();
switch (from) {
case SeekFrom::kStartOfStream:
f_lseek(file_.get(), destination);