Guard audio pipeline file accesses

custom
jacqueline 2 years ago
parent ee8e523456
commit bf1fc5a2a0
  1. 9
      src/audio/fatfs_audio_input.cpp
  2. 4
      src/audio/fatfs_source.cpp

@ -32,6 +32,7 @@
#include "event_queue.hpp" #include "event_queue.hpp"
#include "fatfs_source.hpp" #include "fatfs_source.hpp"
#include "future_fetcher.hpp" #include "future_fetcher.hpp"
#include "spi.hpp"
#include "tag_parser.hpp" #include "tag_parser.hpp"
#include "tasks.hpp" #include "tasks.hpp"
#include "track.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>(); 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) { if (res != FR_OK) {
ESP_LOGE(kTag, "failed to open file! res: %i", res); ESP_LOGE(kTag, "failed to open file! res: %i", res);
return false; return false;

@ -15,6 +15,7 @@
#include "audio_source.hpp" #include "audio_source.hpp"
#include "codec.hpp" #include "codec.hpp"
#include "spi.hpp"
#include "types.hpp" #include "types.hpp"
namespace audio { namespace audio {
@ -25,10 +26,12 @@ FatfsSource::FatfsSource(codecs::StreamType t, std::unique_ptr<FIL> file)
: IStream(t), file_(std::move(file)) {} : IStream(t), file_(std::move(file)) {}
FatfsSource::~FatfsSource() { FatfsSource::~FatfsSource() {
auto lock = drivers::acquire_spi();
f_close(file_.get()); f_close(file_.get());
} }
auto FatfsSource::Read(cpp::span<std::byte> dest) -> ssize_t { auto FatfsSource::Read(cpp::span<std::byte> dest) -> ssize_t {
auto lock = drivers::acquire_spi();
if (f_eof(file_.get())) { if (f_eof(file_.get())) {
return 0; return 0;
} }
@ -46,6 +49,7 @@ auto FatfsSource::CanSeek() -> bool {
} }
auto FatfsSource::SeekTo(int64_t destination, SeekFrom from) -> void { auto FatfsSource::SeekTo(int64_t destination, SeekFrom from) -> void {
auto lock = drivers::acquire_spi();
switch (from) { switch (from) {
case SeekFrom::kStartOfStream: case SeekFrom::kStartOfStream:
f_lseek(file_.get(), destination); f_lseek(file_.get(), destination);

Loading…
Cancel
Save