Skip to content

Playlist improvements #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Secure gPlayProperties more with the lock_guard
Aquire the lock before making write access to the gPlayProperties.
  • Loading branch information
laszloh committed Nov 29, 2023
commit 2e810d228a24a56e7ea46875e3c5a974fb2bc413
13 changes: 8 additions & 5 deletions src/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,15 +947,14 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
}
#endif

gPlayProperties.startAtFilePos = _lastPlayPos;
gPlayProperties.currentTrackNumber = _trackLastPlayed;
std::optional<std::unique_ptr<Playlist>> newPlaylist = std::nullopt;
bool error = false;

if (_playMode != WEBSTREAM) {
if (_playMode == RANDOM_SUBDIRECTORY_OF_DIRECTORY) {
auto tmp = SdCard_pickRandomSubdirectory(_itemToPlay); // get a random subdirectory
if (tmp) { // If error occured while extracting random subdirectory
if (tmp) {
// If no error occured while extracting random subdirectory
newPlaylist = SdCard_ReturnPlaylist(tmp.value().c_str(), _playMode); // Provide random subdirectory in order to enter regular playlist-generation
}
} else {
Expand All @@ -965,6 +964,9 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
newPlaylist = AudioPlayer_ReturnPlaylistFromWebstream(_itemToPlay);
}

// get the lock, since from here on we are modifying a shared variable between two Threads (IDLE & mp3play)
std::lock_guard guard(playlist_mutex);

// Catch if error occured (e.g. file not found)
gPlayProperties.playMode = BUSY; // Show @Neopixel, if uC is busy with creating playlist
if (!newPlaylist || !newPlaylist.value()->isValid()) {
Expand All @@ -981,6 +983,8 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
return;
}

gPlayProperties.startAtFilePos = _lastPlayPos;
gPlayProperties.currentTrackNumber = _trackLastPlayed;
gPlayProperties.playMode = _playMode;
gPlayProperties.numberOfTracks = newPlaylist.value()->size();
// Set some default-values
Expand All @@ -996,7 +1000,7 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
gPrefsSettings.putString("lastRfid", gCurrentRfidTagId);
#endif

switch (gPlayProperties.playMode) {
switch (_playMode) {
case SINGLE_TRACK: {
Log_Println(modeSingleTrack, LOGLEVEL_NOTICE);
break;
Expand Down Expand Up @@ -1082,7 +1086,6 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l

if (!error) {
// transfer ownership of the new playlist to the audio thread
std::lock_guard guard(playlist_mutex);
playlist = std::move(newPlaylist.value());
playlistChanged = true;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ template <class T, std::size_t N, std::size_t... I>
constexpr std::array<std::remove_cv_t<T>, N>
to_array_impl(T (&&a)[N], std::index_sequence<I...>) {
return {{std::move(a[I])...}};
} // namespace detail
}

} // namespace detail

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy