diff options
| author | ailurux <ailuruxx@gmail.com> | 2023-07-08 12:58:07 +1000 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2023-07-08 12:58:07 +1000 |
| commit | 3de310f6e4c170c4c4bfb789cb07ca10e5ab17b8 (patch) | |
| tree | 0d13d6efa758b8c029a35c73405529dcadde3788 /src/audio/fatfs_audio_input.cpp | |
| parent | daa3013836d619d920db3a9dc1f9cc988047a4b4 (diff) | |
| parent | 8f8bc1f088b389a683735d626cbce9adb1f6dc17 (diff) | |
| download | tangara-fw-3de310f6e4c170c4c4bfb789cb07ca10e5ab17b8.tar.gz | |
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'src/audio/fatfs_audio_input.cpp')
| -rw-r--r-- | src/audio/fatfs_audio_input.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index 894ac842..da605a40 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -56,6 +56,7 @@ auto FatfsAudioInput::OpenFile(std::future<std::optional<std::string>>&& path) } auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { + current_path_.reset(); if (is_file_open_) { f_close(¤t_file_); is_file_open_ = false; @@ -68,6 +69,11 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { ESP_LOGI(kTag, "opening file %s", path.c_str()); + FILINFO info; + if (f_stat(path.c_str(), &info) != FR_OK) { + ESP_LOGE(kTag, "failed to stat file"); + } + database::TagParserImpl tag_parser; database::TrackTags tags; if (!tag_parser.ReadAndParseTags(path, &tags)) { @@ -95,7 +101,10 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { .sample_rate = static_cast<uint32_t>(*tags.sample_rate), }; } else { - current_format_ = StreamInfo::Encoded{*stream_type}; + current_format_ = StreamInfo::Encoded{ + .type = *stream_type, + .duration_bytes = info.fsize, + }; } FRESULT res = f_open(¤t_file_, path.c_str(), FA_READ); @@ -104,7 +113,8 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> bool { return false; } - events::Dispatch<InputFileOpened, AudioState>({}); + events::Dispatch<internal::InputFileOpened, AudioState>({}); + current_path_ = path; is_file_open_ = true; return true; } @@ -124,9 +134,10 @@ auto FatfsAudioInput::Process(const std::vector<InputStream>& inputs, if (pending_path_->wait_for(std::chrono::seconds(0)) == std::future_status::ready) { auto result = pending_path_->get(); - if (result) { + if (result && result != current_path_) { OpenFile(*result); } + pending_path_ = {}; } } } @@ -173,10 +184,11 @@ auto FatfsAudioInput::Process(const std::vector<InputStream>& inputs, f_close(¤t_file_); is_file_open_ = false; + current_path_.reset(); has_prepared_output_ = false; output->mark_producer_finished(); - events::Dispatch<InputFileFinished, AudioState>({}); + events::Dispatch<internal::InputFileClosed, AudioState>({}); } } |
