mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 03:57:07 +03:00
alignment to 4.0 + misc cspot fixes
This commit is contained in:
@@ -107,10 +107,7 @@ static void cspotTask(void *pvParameters) {
|
||||
ESP_LOGI(TAG, "Creating Spotify(CSpot) player");
|
||||
|
||||
// Auth successful
|
||||
if (token.size() > 0) {
|
||||
// tell sink that we are taking over
|
||||
cspot.cHandler(CSPOT_SETUP, 44100);
|
||||
|
||||
if (token.size() > 0 && cspot.cHandler(CSPOT_SETUP, 44100)) {
|
||||
auto audioSink = std::make_shared<ShimAudioSink>();
|
||||
|
||||
// @TODO Actually store this token somewhere
|
||||
@@ -137,7 +134,6 @@ static void cspotTask(void *pvParameters) {
|
||||
break;
|
||||
case CSpotEventType::DISC:
|
||||
cspot.cHandler(CSPOT_DISC);
|
||||
spircController->stopPlayer();
|
||||
mercuryManager->stop();
|
||||
break;
|
||||
case CSpotEventType::PREV:
|
||||
@@ -163,11 +159,13 @@ static void cspotTask(void *pvParameters) {
|
||||
};
|
||||
|
||||
mercuryManager->handleQueue();
|
||||
}
|
||||
|
||||
// release controllers
|
||||
mercuryManager.reset();
|
||||
spircController.reset();
|
||||
}
|
||||
|
||||
// release all ownership
|
||||
mercuryManager.reset();
|
||||
spircController.reset();
|
||||
// release auth blob
|
||||
cspot.blob.reset();
|
||||
|
||||
// flush files
|
||||
@@ -200,6 +198,9 @@ struct cspot_s* cspot_create(const char *name, cspot_cmd_cb_t cmd_cb, cspot_data
|
||||
* Commands sent by local buttons/actions
|
||||
*/
|
||||
bool cspot_cmd(struct cspot_s* ctx, cspot_event_t event, void *param) {
|
||||
// we might have not controller left
|
||||
if (!spircController.use_count()) return false;
|
||||
|
||||
switch(event) {
|
||||
case CSPOT_PREV:
|
||||
spircController->prevSong();
|
||||
@@ -217,8 +218,7 @@ bool cspot_cmd(struct cspot_s* ctx, cspot_event_t event, void *param) {
|
||||
spircController->setPause(false);
|
||||
break;
|
||||
case CSPOT_DISC:
|
||||
spircController->stopPlayer();
|
||||
mercuryManager->stop();
|
||||
spircController->disconnect();
|
||||
break;
|
||||
case CSPOT_STOP:
|
||||
spircController->stopPlayer();
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace bell
|
||||
|
||||
|
||||
bool hasFixedSize = false;
|
||||
std::vector<uint8_t> remainingData;
|
||||
size_t contentLength = -1;
|
||||
size_t currentPos = -1;
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ size_t bell::HTTPStream::read(uint8_t *buf, size_t nbytes)
|
||||
|
||||
if (nread < nbytes)
|
||||
{
|
||||
return read(buf + nread, nbytes - nread);
|
||||
return nread + read(buf + nread, nbytes - nread);
|
||||
}
|
||||
return nread;
|
||||
}
|
||||
|
||||
@@ -99,6 +99,11 @@ public:
|
||||
void nextSong();
|
||||
void setEventHandler(cspotEventHandler handler);
|
||||
void stopPlayer();
|
||||
|
||||
/**
|
||||
* @brief Disconnect players and notify
|
||||
*/
|
||||
void disconnect();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,8 @@ std::string ApResolve::getApList()
|
||||
jsonData += cur;
|
||||
}
|
||||
|
||||
close(sockFd);
|
||||
|
||||
return jsonData;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,7 +192,6 @@ void MercuryManager::stop() {
|
||||
isRunning = false;
|
||||
audioChunkManager->close();
|
||||
std::scoped_lock(audioChunkManager->runningMutex, this->runningMutex);
|
||||
this->session->close();
|
||||
CSPOT_LOG(debug, "mercury stopped");
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,8 @@ size_t PlainConnection::writeBlock(const std::vector<uint8_t> &data)
|
||||
|
||||
void PlainConnection::closeSocket()
|
||||
{
|
||||
CSPOT_LOG(info, "Closing socket...");
|
||||
shutdown(this->apSock, SHUT_RDWR);
|
||||
close(this->apSock);
|
||||
CSPOT_LOG(info, "Closing socket...");
|
||||
shutdown(this->apSock, SHUT_RDWR);
|
||||
close(this->apSock);
|
||||
this->apSock = -1;
|
||||
}
|
||||
|
||||
@@ -43,13 +43,20 @@ void SpircController::setPause(bool isPaused, bool notifyPlayer) {
|
||||
CSPOT_LOG(debug, "External pause command");
|
||||
if (notifyPlayer) player->pause();
|
||||
state->setPlaybackState(PlaybackState::Paused);
|
||||
notify();
|
||||
} else {
|
||||
CSPOT_LOG(debug, "External play command");
|
||||
if (notifyPlayer) player->play();
|
||||
state->setPlaybackState(PlaybackState::Playing);
|
||||
notify();
|
||||
}
|
||||
notify();
|
||||
}
|
||||
|
||||
void SpircController::disconnect(void) {
|
||||
player->cancelCurrentTrack();
|
||||
stopPlayer();
|
||||
state->setActive(false);
|
||||
notify();
|
||||
sendEvent(CSpotEventType::DISC);
|
||||
}
|
||||
|
||||
void SpircController::playToggle() {
|
||||
@@ -104,10 +111,7 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
||||
// Pause the playback if another player took control
|
||||
if (state->isActive() &&
|
||||
state->remoteFrame.device_state->is_active.value()) {
|
||||
sendEvent(CSpotEventType::DISC);
|
||||
state->setActive(false);
|
||||
notify();
|
||||
player->cancelCurrentTrack();
|
||||
disconnect();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,6 @@ void cspot_sink_init(cspot_cmd_vcb_t cmd_cb, cspot_data_cb_t data_cb) {
|
||||
void cspot_disconnect(void) {
|
||||
ESP_LOGI(TAG, "forced disconnection");
|
||||
displayer_control(DISPLAYER_SHUTDOWN);
|
||||
cspot_cmd(cspot, CSPOT_FLUSH, NULL);
|
||||
cspot_cmd(cspot, CSPOT_DISC, NULL);
|
||||
actrls_unset();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user