Extract PlaylistLoader from MusicManager

Move the async, streaming playlist-load orchestration (the background load
thread, loading/loaded/total counters, and the getPlaylistStreaming wiring)
into a PlaylistLoader class. It enqueues resolved tracks via an injected
callback (-> queueTrack) and asks the owner to start playback on the first
track via requestPlaybackStart() — the single seam back to the audio loop,
which still owns the auto-start thread + cv_ poke. loadPlaylist() now just
delegates. Behavior preserved; build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-24 01:07:00 +03:00
1 parent 0e090168e8
commit 622335260f
4 files changed
+243 -145

No files matched your search

+9 -8
View File
@@ -3,6 +3,7 @@
#include "AudioDecoder.hpp"
#include "Database.hpp"
#include "NetworkClient.hpp"
#include "PlaylistLoader.hpp"
#include "RpcTypes.hpp"
#include "SubscriptionManager.hpp"
#include "YouTubeClient.hpp"
@@ -77,11 +78,11 @@ namespace Echoion::Core
uint64_t clientId);
[[nodiscard]] bool isPlaylistLoading() const
{
return playlistLoading_.load();
return playlistLoader_ && playlistLoader_->isLoading();
}
[[nodiscard]] size_t getPlaylistLoadProgress() const
{
return playlistLoadedCount_.load();
return playlistLoader_ ? playlistLoader_->loadedCount() : 0;
}
[[nodiscard]] Api::Result<std::vector<Api::PlaylistInfo>>
getPlaylists() const;
@@ -179,6 +180,8 @@ namespace Echoion::Core
}
void playbackThread();
// Auto-start the playback loop when a playlist's first track lands.
void requestPlaybackStart();
[[nodiscard]] Api::Result<Api::TrackInfo>
resolveQuery(const std::string& query);
[[nodiscard]] Api::Result<std::string>
@@ -218,13 +221,11 @@ namespace Echoion::Core
std::optional<std::string> prefetchedUrl;
} prefetchState_;
// Async playlist loading state
std::thread playlistLoadThread_;
std::atomic<bool> playlistLoading_{false};
std::atomic<size_t> playlistLoadedCount_{0};
std::atomic<size_t> playlistTotalCount_{0};
// Async playlist loading (background thread owned by the loader).
std::unique_ptr<PlaylistLoader> playlistLoader_;
// Auto-start thread for playlist (must be joined, not detached)
// Auto-start thread: pokes the playback loop when a playlist's
// first track lands. Owned here because it touches the audio loop.
std::thread playlistAutoStartThread_;
std::shared_ptr<NetworkClient> networkClient_;