mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
try to fix misc cspot issues + silence network manager log
This commit is contained in:
@@ -126,9 +126,12 @@ static void cspotTask(void *pvParameters) {
|
||||
case CSpotEventType::PLAY_PAUSE: {
|
||||
bool isPaused = std::get<bool>(event.data);
|
||||
if (isPaused) cspot.cHandler(CSPOT_PAUSE);
|
||||
else cspot.cHandler(CSPOT_PLAY);
|
||||
else cspot.cHandler(CSPOT_PLAY, false);
|
||||
break;
|
||||
}
|
||||
case CSpotEventType::PLAYBACK_START:
|
||||
cspot.cHandler(CSPOT_PLAY, (int) std::get<bool>(event.data));
|
||||
break;
|
||||
case CSpotEventType::LOAD:
|
||||
cspot.cHandler(CSPOT_LOAD, std::get<int>(event.data), -1);
|
||||
break;
|
||||
@@ -347,7 +350,7 @@ void ShimHTTPServer::registerHandler(bell::RequestType requestType, const std::s
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
|
||||
// find athe first free spot and register handler
|
||||
// find the first free spot and register handler
|
||||
for (int i = 0; i < sizeof(uriHandlers)/sizeof(bell::httpHandler); i++) {
|
||||
if (!uriHandlers[i]) {
|
||||
uriHandlers[i] = handler;
|
||||
|
||||
@@ -32,19 +32,19 @@ public:
|
||||
std::function<void()> endOfFileCallback;
|
||||
int volume = 255;
|
||||
uint32_t logVolume;
|
||||
bool needFlush = false;
|
||||
std::atomic<bool> isRunning = false;
|
||||
trackChangedCallback trackChanged;
|
||||
std::mutex runningMutex;
|
||||
|
||||
void setVolume(uint32_t volume);
|
||||
void handleLoad(std::shared_ptr<TrackReference> track, std::function<void()> &trackLoadedCallback, uint32_t position_ms, bool isPaused);
|
||||
void handleLoad(std::shared_ptr<TrackReference> track, std::function<void(bool)> &trackLoadedCallback, uint32_t position_ms, bool isPaused);
|
||||
void pause();
|
||||
void cancelCurrentTrack();
|
||||
void seekMs(size_t positionMs);
|
||||
void feedPCM(uint8_t *data, size_t len);
|
||||
void play();
|
||||
void stop();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,8 +5,13 @@
|
||||
static size_t vorbisReadCb(void *ptr, size_t size, size_t nmemb, ChunkedAudioStream *self)
|
||||
{
|
||||
size_t readSize = 0;
|
||||
while (readSize < nmemb * size && self->byteStream->position() < self->byteStream->size()) {
|
||||
readSize += self->byteStream->read((uint8_t *) ptr + readSize, (size * nmemb) - readSize);
|
||||
while (readSize < nmemb * size && self->byteStream->position() < self->byteStream->size() && self->isRunning) {
|
||||
size_t bytes = self->byteStream->read((uint8_t *) ptr + readSize, (size * nmemb) - readSize);
|
||||
if (bytes <= 0) {
|
||||
CSPOT_LOG(info, "unexpected end/error of stream");
|
||||
return readSize;
|
||||
}
|
||||
readSize += bytes;
|
||||
}
|
||||
return readSize;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,6 @@ std::shared_ptr<AudioChunk> MercuryManager::fetchAudioChunk(std::vector<uint8_t>
|
||||
this->session->shanConn->sendPacket(static_cast<uint8_t>(MercuryType::AUDIO_CHUNK_REQUEST_COMMAND), buffer);
|
||||
|
||||
// Used for broken connection detection
|
||||
CSPOT_LOG(info, "requesting Chunk %hu", this->audioChunkSequence - 1);
|
||||
this->lastRequestTimestamp = this->timeProvider->getSyncedTimestamp();
|
||||
return this->audioChunkManager->registerNewChunk(this->audioChunkSequence - 1, audioKey, startPos, endPos);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ void Player::runTask()
|
||||
}
|
||||
else
|
||||
{
|
||||
usleep(10000);
|
||||
usleep(20000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -147,7 +147,7 @@ void Player::cancelCurrentTrack()
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleLoad(std::shared_ptr<TrackReference> trackReference, std::function<void()>& trackLoadedCallback, uint32_t position_ms, bool isPaused)
|
||||
void Player::handleLoad(std::shared_ptr<TrackReference> trackReference, std::function<void(bool)>& trackLoadedCallback, uint32_t position_ms, bool isPaused)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(loadTrackMutex);
|
||||
|
||||
@@ -166,7 +166,9 @@ void Player::handleLoad(std::shared_ptr<TrackReference> trackReference, std::fun
|
||||
|
||||
this->nextTrack->trackInfoReceived = this->trackChanged;
|
||||
this->nextTrack->loadedTrackCallback = [this, framesCallback, trackLoadedCallback]() {
|
||||
trackLoadedCallback();
|
||||
bool needFlush = currentTrack != nullptr && currentTrack->audioStream != nullptr && currentTrack->audioStream->isRunning;
|
||||
cancelCurrentTrack();
|
||||
trackLoadedCallback(needFlush);
|
||||
|
||||
this->nextTrackMutex.lock();
|
||||
this->nextTrack->audioStream->streamFinishedCallback = this->endOfFileCallback;
|
||||
@@ -175,7 +177,6 @@ void Player::handleLoad(std::shared_ptr<TrackReference> trackReference, std::fun
|
||||
this->nextTrack->loaded = true;
|
||||
this->nextTrackMutex.unlock();
|
||||
|
||||
cancelCurrentTrack();
|
||||
};
|
||||
this->nextTrackMutex.unlock();
|
||||
}
|
||||
|
||||
@@ -190,10 +190,10 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
||||
void SpircController::loadTrack(uint32_t position_ms, bool isPaused) {
|
||||
sendEvent(CSpotEventType::LOAD, (int) position_ms);
|
||||
state->setPlaybackState(PlaybackState::Loading);
|
||||
std::function<void()> loadedLambda = [=]() {
|
||||
std::function<void(bool)> loadedLambda = [=](bool needFlush) {
|
||||
// Loading finished, notify that playback started
|
||||
setPause(isPaused, false);
|
||||
sendEvent(CSpotEventType::PLAYBACK_START);
|
||||
sendEvent(CSpotEventType::PLAYBACK_START, needFlush);
|
||||
};
|
||||
|
||||
player->handleLoad(state->getCurrentTrack(), loadedLambda, position_ms,
|
||||
|
||||
@@ -106,7 +106,7 @@ void SpotifyTrack::trackInformationCallback(std::unique_ptr<MercuryResponse> res
|
||||
altIndex++;
|
||||
CSPOT_LOG(info, "Trying alternative %d", altIndex);
|
||||
|
||||
if(altIndex > trackInfo.alternative_count) {
|
||||
if(altIndex >= trackInfo.alternative_count) {
|
||||
// no alternatives for song
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user