Explicitly close the playlist files in the queue on storage unmount

custom
ailurux 7 months ago
parent 39a5d062fc
commit 7cc6f198cf
  1. 16
      src/tangara/audio/playlist.cpp
  2. 1
      src/tangara/audio/playlist.hpp
  3. 7
      src/tangara/audio/track_queue.cpp
  4. 5
      src/tangara/audio/track_queue.hpp
  5. 1
      src/tangara/system_fsm/running.cpp

@ -33,6 +33,10 @@ Playlist::Playlist(const std::string& playlistFilepath)
auto Playlist::open() -> bool {
std::unique_lock<std::mutex> lock(mutex_);
if (file_open_) {
return true;
}
FRESULT res =
f_open(&file_, filepath_.c_str(), FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if (res != FR_OK) {
@ -194,6 +198,14 @@ auto Playlist::deserialiseCache() -> bool {
return true;
}
auto Playlist::close() -> void {
if (file_open_) {
f_close(&file_);
file_open_ = false;
file_error_ = false;
}
}
auto Playlist::skipToLocked(size_t position) -> void {
if (!file_open_ || file_error_) {
return;
@ -306,6 +318,10 @@ MutablePlaylist::MutablePlaylist(const std::string& playlistFilepath)
auto MutablePlaylist::open() -> bool {
std::unique_lock<std::mutex> lock(mutex_);
if (file_open_) {
return true;
}
FRESULT res =
f_open(&file_, filepath_.c_str(), FA_READ | FA_WRITE | FA_OPEN_ALWAYS);

@ -47,6 +47,7 @@ class Playlist {
auto serialiseCache() -> bool;
auto deserialiseCache() -> bool;
auto close() -> void;
protected:
const std::string filepath_;

@ -159,6 +159,13 @@ auto TrackQueue::open() -> bool {
return playlist_.open();
}
auto TrackQueue::close() -> void {
playlist_.close();
if (opened_playlist_) {
opened_playlist_->close();
}
}
auto TrackQueue::openPlaylist(const std::string& playlist_file, bool notify)
-> bool {
opened_playlist_.emplace(playlist_file);

@ -76,8 +76,9 @@ class TrackQueue {
auto currentPosition(size_t position) -> bool;
auto totalSize() const -> size_t;
auto open() -> bool;
auto openPlaylist(const std::string& playlist_file, bool notify = true)
-> bool;
auto close() -> void;
auto openPlaylist(const std::string& playlist_file,
bool notify = true) -> bool;
auto playFromPosition(const std::string& filepath, uint32_t position) -> void;
using Item =

@ -214,6 +214,7 @@ void Running::react(const internal::Mount& ev) {
auto Running::unmountStorage() -> void {
ESP_LOGW(kTag, "unmounting storage");
sServices->track_queue().close();
sServices->database({});
sStorage.reset();
updateSdState(drivers::SdState::kNotMounted);

Loading…
Cancel
Save