mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 20:47:08 +03:00
gap when changing queue workaround
This commit is contained in:
@@ -37,7 +37,6 @@ class TrackPlayer : bell::Task {
|
|||||||
typedef std::function<size_t(uint8_t*, size_t, std::string_view)>
|
typedef std::function<size_t(uint8_t*, size_t, std::string_view)>
|
||||||
DataCallback;
|
DataCallback;
|
||||||
typedef std::function<void()> EOFCallback;
|
typedef std::function<void()> EOFCallback;
|
||||||
typedef std::function<bool()> isAiringCallback;
|
|
||||||
|
|
||||||
TrackPlayer(std::shared_ptr<cspot::Context> ctx,
|
TrackPlayer(std::shared_ptr<cspot::Context> ctx,
|
||||||
std::shared_ptr<cspot::TrackQueue> trackQueue,
|
std::shared_ptr<cspot::TrackQueue> trackQueue,
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class QueuedTrack {
|
|||||||
|
|
||||||
uint32_t requestedPosition;
|
uint32_t requestedPosition;
|
||||||
std::string identifier;
|
std::string identifier;
|
||||||
|
bool loading = false;
|
||||||
|
|
||||||
// Will return nullptr if the track is not ready
|
// Will return nullptr if the track is not ready
|
||||||
std::shared_ptr<cspot::CDNAudioFile> getAudioFile();
|
std::shared_ptr<cspot::CDNAudioFile> getAudioFile();
|
||||||
@@ -100,7 +101,7 @@ class TrackQueue : public bell::Task {
|
|||||||
bool hasTracks();
|
bool hasTracks();
|
||||||
bool isFinished();
|
bool isFinished();
|
||||||
bool skipTrack(SkipDirection dir, bool expectNotify = true);
|
bool skipTrack(SkipDirection dir, bool expectNotify = true);
|
||||||
void updateTracks(uint32_t requestedPosition = 0, bool initial = false);
|
bool updateTracks(uint32_t requestedPosition = 0, bool initial = false);
|
||||||
TrackInfo getTrackInfo(std::string_view identifier);
|
TrackInfo getTrackInfo(std::string_view identifier);
|
||||||
std::shared_ptr<QueuedTrack> consumeTrack(
|
std::shared_ptr<QueuedTrack> consumeTrack(
|
||||||
std::shared_ptr<QueuedTrack> prevSong, int& offset);
|
std::shared_ptr<QueuedTrack> prevSong, int& offset);
|
||||||
|
|||||||
@@ -205,16 +205,18 @@ void SpircHandler::handleFrame(std::vector<uint8_t>& data) {
|
|||||||
playbackState->syncWithRemote();
|
playbackState->syncWithRemote();
|
||||||
|
|
||||||
// 1st track is the current one, but update the position
|
// 1st track is the current one, but update the position
|
||||||
trackQueue->updateTracks(
|
bool cleared = trackQueue->updateTracks(
|
||||||
playbackState->remoteFrame.state.position_ms +
|
playbackState->remoteFrame.state.position_ms +
|
||||||
ctx->timeProvider->getSyncedTimestamp() -
|
ctx->timeProvider->getSyncedTimestamp() -
|
||||||
playbackState->innerFrame.state.position_measured_at,
|
playbackState->innerFrame.state.position_measured_at);
|
||||||
false);
|
|
||||||
|
|
||||||
this->notify();
|
this->notify();
|
||||||
|
|
||||||
sendEvent(EventType::FLUSH);
|
// need to re-load all if streaming track is completed
|
||||||
trackPlayer->resetState();
|
if (cleared) {
|
||||||
|
sendEvent(EventType::FLUSH);
|
||||||
|
trackPlayer->resetState();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MessageType_kMessageTypeShuffle: {
|
case MessageType_kMessageTypeShuffle: {
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ void TrackPlayer::runTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eof = false;
|
eof = false;
|
||||||
|
track->loading = true;
|
||||||
|
|
||||||
CSPOT_LOG(info, "Playing");
|
CSPOT_LOG(info, "Playing");
|
||||||
|
|
||||||
@@ -255,6 +256,7 @@ void TrackPlayer::runTask() {
|
|||||||
|
|
||||||
// always move back to LOADING (ensure proper seeking after last track has been loaded)
|
// always move back to LOADING (ensure proper seeking after last track has been loaded)
|
||||||
currentTrackStream = nullptr;
|
currentTrackStream = nullptr;
|
||||||
|
track->loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eof) {
|
if (eof) {
|
||||||
|
|||||||
@@ -587,8 +587,9 @@ bool TrackQueue::isFinished() {
|
|||||||
return currentTracksIndex >= currentTracks.size() - 1;
|
return currentTracksIndex >= currentTracks.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackQueue::updateTracks(uint32_t requestedPosition, bool initial) {
|
bool TrackQueue::updateTracks(uint32_t requestedPosition, bool initial) {
|
||||||
std::scoped_lock lock(tracksMutex);
|
std::scoped_lock lock(tracksMutex);
|
||||||
|
bool cleared = true;
|
||||||
|
|
||||||
if (initial) {
|
if (initial) {
|
||||||
// Clear preloaded tracks
|
// Clear preloaded tracks
|
||||||
@@ -609,13 +610,28 @@ void TrackQueue::updateTracks(uint32_t requestedPosition, bool initial) {
|
|||||||
|
|
||||||
playableSemaphore->give();
|
playableSemaphore->give();
|
||||||
} else {
|
} else {
|
||||||
// Clear preloaded tracks
|
|
||||||
preloadedTracks.clear();
|
|
||||||
|
|
||||||
// Copy requested track list
|
// Copy requested track list
|
||||||
currentTracks = playbackState->remoteTracks;
|
currentTracks = playbackState->remoteTracks;
|
||||||
|
|
||||||
// Push a song on the preloaded queue
|
// try to not re-load track if we are still loading it
|
||||||
queueNextTrack(0, requestedPosition);
|
if (preloadedTracks[0]->loading) {
|
||||||
|
// remove everything except first track
|
||||||
|
preloadedTracks.erase(preloadedTracks.begin() + 1, preloadedTracks.end());
|
||||||
|
|
||||||
|
// Push a song on the preloaded queue
|
||||||
|
CSPOT_LOG(info, "Keeping current track");
|
||||||
|
queueNextTrack(1);
|
||||||
|
|
||||||
|
cleared = false;
|
||||||
|
} else {
|
||||||
|
// Clear preloaded tracks
|
||||||
|
preloadedTracks.clear();
|
||||||
|
|
||||||
|
// Push a song on the preloaded queue
|
||||||
|
CSPOT_LOG(info, "Re-loading current track");
|
||||||
|
queueNextTrack(0, requestedPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cleared;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user