mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
alignment to 4.0 + misc cspot fixes
This commit is contained in:
@@ -16,7 +16,7 @@ add_definitions(-DHIERARCHICAL_STATES=1)
|
|||||||
#add_definitions(-DNETWORK_HANDLERS_LOG_LEVEL=ESP_LOG_DEBUG)
|
#add_definitions(-DNETWORK_HANDLERS_LOG_LEVEL=ESP_LOG_DEBUG)
|
||||||
#add_definitions(-DNETWORK_WIFI_LOG_LEVEL=ESP_LOG_DEBUG)
|
#add_definitions(-DNETWORK_WIFI_LOG_LEVEL=ESP_LOG_DEBUG)
|
||||||
#add_definitions(-DNETWORK_MANAGER_LOG_LEVEL=ESP_LOG_DEBUG)
|
#add_definitions(-DNETWORK_MANAGER_LOG_LEVEL=ESP_LOG_DEBUG)
|
||||||
add_definitions(-DNETWORK_HTTP_SERVER_LOG_LEVEL=ESP_LOG_DEBUG)
|
#add_definitions(-DNETWORK_HTTP_SERVER_LOG_LEVEL=ESP_LOG_DEBUG)
|
||||||
|
|
||||||
if(NOT DEFINED DEPTH)
|
if(NOT DEFINED DEPTH)
|
||||||
set(DEPTH "16")
|
set(DEPTH "16")
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
|
|||||||
id[63] = '\0';
|
id[63] = '\0';
|
||||||
ctx->svc = mdnsd_register_svc(ctx->svr, id, "_raop._tcp.local", ctx->port, NULL, (const char**) txt);
|
ctx->svc = mdnsd_register_svc(ctx->svr, id, "_raop._tcp.local", ctx->port, NULL, (const char**) txt);
|
||||||
pthread_create(&ctx->thread, NULL, &rtsp_thread, ctx);
|
pthread_create(&ctx->thread, NULL, &rtsp_thread, ctx);
|
||||||
|
|
||||||
|
#else
|
||||||
LOG_INFO("starting mDNS with %s", id);
|
LOG_INFO("starting mDNS with %s", id);
|
||||||
ESP_ERROR_CHECK( mdns_service_add(id, "_raop", "_tcp", ctx->port, txt, sizeof(txt) / sizeof(mdns_txt_item_t)) );
|
ESP_ERROR_CHECK( mdns_service_add(id, "_raop", "_tcp", ctx->port, txt, sizeof(txt) / sizeof(mdns_txt_item_t)) );
|
||||||
|
|
||||||
@@ -518,7 +519,9 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
|||||||
if ((buf = kd_lookup(headers, "Active-Remote")) != NULL) strcpy(ctx->active_remote.id, buf);
|
if ((buf = kd_lookup(headers, "Active-Remote")) != NULL) strcpy(ctx->active_remote.id, buf);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
ctx->active_remote.handle = init_mDNS(false, ctx->host);
|
ctx->active_remote.handle = init_mDNS(false, ctx->host);
|
||||||
|
pthread_create(&ctx->active_remote.thread, NULL, &search_remote, ctx);
|
||||||
|
#else
|
||||||
ctx->active_remote.running = true;
|
ctx->active_remote.running = true;
|
||||||
ctx->active_remote.destroy_mutex = xSemaphoreCreateBinary();
|
ctx->active_remote.destroy_mutex = xSemaphoreCreateBinary();
|
||||||
ctx->active_remote.xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
ctx->active_remote.xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
|
|||||||
@@ -281,8 +281,9 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv,
|
|||||||
pthread_create(&ctx->thread, NULL, rtp_thread_func, (void *) ctx);
|
pthread_create(&ctx->thread, NULL, rtp_thread_func, (void *) ctx);
|
||||||
#else
|
#else
|
||||||
ctx->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
ctx->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
ctx->thread = xTaskCreateStatic( (TaskFunction_t) rtp_thread_func, "RTP_thread", RTP_STACK_SIZE, ctx,
|
ctx->thread = xTaskCreateStaticPinnedToCore( (TaskFunction_t) rtp_thread_func, "RTP_thread", RTP_STACK_SIZE, ctx,
|
||||||
CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1, ctx->xStack, ctx->xTaskBuffer );
|
CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1, ctx->xStack, ctx->xTaskBuffer,
|
||||||
|
CONFIG_PTHREAD_TASK_CORE_DEFAULT );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// cleanup everything if we failed
|
// cleanup everything if we failed
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ char *strlwr(char *str);
|
|||||||
char *strlwr(char *str);
|
char *strlwr(char *str);
|
||||||
|
|
||||||
// reason is that TCB might be cleanup in idle task
|
// reason is that TCB might be cleanup in idle task
|
||||||
#define SAFE_PTR_FREE(P) \
|
#define SAFE_PTR_FREE(P) \
|
||||||
do { \
|
do { \
|
||||||
TimerHandle_t timer = xTimerCreate("cleanup", pdMS_TO_TICKS(10000), pdFALSE, P, _delayed_free); \
|
TimerHandle_t timer = xTimerCreate("cleanup", pdMS_TO_TICKS(10000), pdFALSE, P, _delayed_free); \
|
||||||
xTimerStart(timer, portMAX_DELAY); \
|
xTimerStart(timer, portMAX_DELAY); \
|
||||||
|
|||||||
@@ -107,10 +107,7 @@ static void cspotTask(void *pvParameters) {
|
|||||||
ESP_LOGI(TAG, "Creating Spotify(CSpot) player");
|
ESP_LOGI(TAG, "Creating Spotify(CSpot) player");
|
||||||
|
|
||||||
// Auth successful
|
// Auth successful
|
||||||
if (token.size() > 0) {
|
if (token.size() > 0 && cspot.cHandler(CSPOT_SETUP, 44100)) {
|
||||||
// tell sink that we are taking over
|
|
||||||
cspot.cHandler(CSPOT_SETUP, 44100);
|
|
||||||
|
|
||||||
auto audioSink = std::make_shared<ShimAudioSink>();
|
auto audioSink = std::make_shared<ShimAudioSink>();
|
||||||
|
|
||||||
// @TODO Actually store this token somewhere
|
// @TODO Actually store this token somewhere
|
||||||
@@ -137,7 +134,6 @@ static void cspotTask(void *pvParameters) {
|
|||||||
break;
|
break;
|
||||||
case CSpotEventType::DISC:
|
case CSpotEventType::DISC:
|
||||||
cspot.cHandler(CSPOT_DISC);
|
cspot.cHandler(CSPOT_DISC);
|
||||||
spircController->stopPlayer();
|
|
||||||
mercuryManager->stop();
|
mercuryManager->stop();
|
||||||
break;
|
break;
|
||||||
case CSpotEventType::PREV:
|
case CSpotEventType::PREV:
|
||||||
@@ -163,11 +159,13 @@ static void cspotTask(void *pvParameters) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
mercuryManager->handleQueue();
|
mercuryManager->handleQueue();
|
||||||
}
|
|
||||||
|
|
||||||
// release all ownership
|
// release controllers
|
||||||
mercuryManager.reset();
|
mercuryManager.reset();
|
||||||
spircController.reset();
|
spircController.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// release auth blob
|
||||||
cspot.blob.reset();
|
cspot.blob.reset();
|
||||||
|
|
||||||
// flush files
|
// 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
|
* Commands sent by local buttons/actions
|
||||||
*/
|
*/
|
||||||
bool cspot_cmd(struct cspot_s* ctx, cspot_event_t event, void *param) {
|
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) {
|
switch(event) {
|
||||||
case CSPOT_PREV:
|
case CSPOT_PREV:
|
||||||
spircController->prevSong();
|
spircController->prevSong();
|
||||||
@@ -217,8 +218,7 @@ bool cspot_cmd(struct cspot_s* ctx, cspot_event_t event, void *param) {
|
|||||||
spircController->setPause(false);
|
spircController->setPause(false);
|
||||||
break;
|
break;
|
||||||
case CSPOT_DISC:
|
case CSPOT_DISC:
|
||||||
spircController->stopPlayer();
|
spircController->disconnect();
|
||||||
mercuryManager->stop();
|
|
||||||
break;
|
break;
|
||||||
case CSPOT_STOP:
|
case CSPOT_STOP:
|
||||||
spircController->stopPlayer();
|
spircController->stopPlayer();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace bell
|
|||||||
|
|
||||||
|
|
||||||
bool hasFixedSize = false;
|
bool hasFixedSize = false;
|
||||||
|
std::vector<uint8_t> remainingData;
|
||||||
size_t contentLength = -1;
|
size_t contentLength = -1;
|
||||||
size_t currentPos = -1;
|
size_t currentPos = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ size_t bell::HTTPStream::read(uint8_t *buf, size_t nbytes)
|
|||||||
|
|
||||||
if (nread < nbytes)
|
if (nread < nbytes)
|
||||||
{
|
{
|
||||||
return read(buf + nread, nbytes - nread);
|
return nread + read(buf + nread, nbytes - nread);
|
||||||
}
|
}
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,11 @@ public:
|
|||||||
void nextSong();
|
void nextSong();
|
||||||
void setEventHandler(cspotEventHandler handler);
|
void setEventHandler(cspotEventHandler handler);
|
||||||
void stopPlayer();
|
void stopPlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disconnect players and notify
|
||||||
|
*/
|
||||||
|
void disconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ std::string ApResolve::getApList()
|
|||||||
jsonData += cur;
|
jsonData += cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sockFd);
|
||||||
|
|
||||||
return jsonData;
|
return jsonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ void MercuryManager::stop() {
|
|||||||
isRunning = false;
|
isRunning = false;
|
||||||
audioChunkManager->close();
|
audioChunkManager->close();
|
||||||
std::scoped_lock(audioChunkManager->runningMutex, this->runningMutex);
|
std::scoped_lock(audioChunkManager->runningMutex, this->runningMutex);
|
||||||
this->session->close();
|
|
||||||
CSPOT_LOG(debug, "mercury stopped");
|
CSPOT_LOG(debug, "mercury stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ size_t PlainConnection::writeBlock(const std::vector<uint8_t> &data)
|
|||||||
|
|
||||||
void PlainConnection::closeSocket()
|
void PlainConnection::closeSocket()
|
||||||
{
|
{
|
||||||
CSPOT_LOG(info, "Closing socket...");
|
CSPOT_LOG(info, "Closing socket...");
|
||||||
shutdown(this->apSock, SHUT_RDWR);
|
shutdown(this->apSock, SHUT_RDWR);
|
||||||
close(this->apSock);
|
close(this->apSock);
|
||||||
|
this->apSock = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,20 @@ void SpircController::setPause(bool isPaused, bool notifyPlayer) {
|
|||||||
CSPOT_LOG(debug, "External pause command");
|
CSPOT_LOG(debug, "External pause command");
|
||||||
if (notifyPlayer) player->pause();
|
if (notifyPlayer) player->pause();
|
||||||
state->setPlaybackState(PlaybackState::Paused);
|
state->setPlaybackState(PlaybackState::Paused);
|
||||||
notify();
|
|
||||||
} else {
|
} else {
|
||||||
CSPOT_LOG(debug, "External play command");
|
CSPOT_LOG(debug, "External play command");
|
||||||
if (notifyPlayer) player->play();
|
if (notifyPlayer) player->play();
|
||||||
state->setPlaybackState(PlaybackState::Playing);
|
state->setPlaybackState(PlaybackState::Playing);
|
||||||
notify();
|
|
||||||
}
|
}
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpircController::disconnect(void) {
|
||||||
|
player->cancelCurrentTrack();
|
||||||
|
stopPlayer();
|
||||||
|
state->setActive(false);
|
||||||
|
notify();
|
||||||
|
sendEvent(CSpotEventType::DISC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpircController::playToggle() {
|
void SpircController::playToggle() {
|
||||||
@@ -104,10 +111,7 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
|||||||
// Pause the playback if another player took control
|
// Pause the playback if another player took control
|
||||||
if (state->isActive() &&
|
if (state->isActive() &&
|
||||||
state->remoteFrame.device_state->is_active.value()) {
|
state->remoteFrame.device_state->is_active.value()) {
|
||||||
sendEvent(CSpotEventType::DISC);
|
disconnect();
|
||||||
state->setActive(false);
|
|
||||||
notify();
|
|
||||||
player->cancelCurrentTrack();
|
|
||||||
}
|
}
|
||||||
break;
|
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) {
|
void cspot_disconnect(void) {
|
||||||
ESP_LOGI(TAG, "forced disconnection");
|
ESP_LOGI(TAG, "forced disconnection");
|
||||||
displayer_control(DISPLAYER_SHUTDOWN);
|
displayer_control(DISPLAYER_SHUTDOWN);
|
||||||
cspot_cmd(cspot, CSPOT_FLUSH, NULL);
|
cspot_cmd(cspot, CSPOT_DISC, NULL);
|
||||||
actrls_unset();
|
actrls_unset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ static bool bt_sink_cmd_handler(bt_sink_cmd_t cmd, va_list args)
|
|||||||
case BT_SINK_AUDIO_STOPPED:
|
case BT_SINK_AUDIO_STOPPED:
|
||||||
if (output.external == DECODE_BT) {
|
if (output.external == DECODE_BT) {
|
||||||
if (output.state > OUTPUT_STOPPED) output.state = OUTPUT_STOPPED;
|
if (output.state > OUTPUT_STOPPED) output.state = OUTPUT_STOPPED;
|
||||||
|
output.external = 0;
|
||||||
output.stop_time = gettime_ms();
|
output.stop_time = gettime_ms();
|
||||||
LOG_INFO("BT sink stopped");
|
LOG_INFO("BT sink stopped");
|
||||||
}
|
}
|
||||||
@@ -287,6 +288,8 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
|||||||
output.next_sample_rate = output.current_sample_rate = RAOP_SAMPLE_RATE;
|
output.next_sample_rate = output.current_sample_rate = RAOP_SAMPLE_RATE;
|
||||||
break;
|
break;
|
||||||
case RAOP_STOP:
|
case RAOP_STOP:
|
||||||
|
output.external = 0;
|
||||||
|
__attribute__ ((fallthrough));
|
||||||
case RAOP_FLUSH:
|
case RAOP_FLUSH:
|
||||||
LOG_INFO("%s", event == RAOP_FLUSH ? "Flush" : "Stop");
|
LOG_INFO("%s", event == RAOP_FLUSH ? "Flush" : "Stop");
|
||||||
_buf_flush(outputbuf);
|
_buf_flush(outputbuf);
|
||||||
@@ -355,6 +358,7 @@ static bool cspot_cmd_handler(cspot_event_t cmd, va_list args)
|
|||||||
case CSPOT_DISC:
|
case CSPOT_DISC:
|
||||||
_buf_flush(outputbuf);
|
_buf_flush(outputbuf);
|
||||||
abort_sink = true;
|
abort_sink = true;
|
||||||
|
output.external = 0;
|
||||||
output.state = OUTPUT_STOPPED;
|
output.state = OUTPUT_STOPPED;
|
||||||
output.stop_time = gettime_ms();
|
output.stop_time = gettime_ms();
|
||||||
LOG_INFO("CSpot disconnected");
|
LOG_INFO("CSpot disconnected");
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ bool sb_displayer_init(void) {
|
|||||||
|
|
||||||
// create displayer management task
|
// create displayer management task
|
||||||
displayer.mutex = xSemaphoreCreateMutex();
|
displayer.mutex = xSemaphoreCreateMutex();
|
||||||
displayer.task = xTaskCreateStatic( (TaskFunction_t) displayer_task, "squeeze_displayer", SCROLL_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN + 1, xStack, &xTaskBuffer);
|
displayer.task = xTaskCreateStatic( (TaskFunction_t) displayer_task, "sb_displayer", SCROLL_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN + 1, xStack, &xTaskBuffer);
|
||||||
|
|
||||||
// chain handlers
|
// chain handlers
|
||||||
slimp_handler_chain = slimp_handler;
|
slimp_handler_chain = slimp_handler;
|
||||||
@@ -1315,6 +1315,7 @@ static void displayer_task(void *args) {
|
|||||||
|
|
||||||
// need to make sure we own display
|
// need to make sure we own display
|
||||||
if (display && displayer.owned) GDS_Update(display);
|
if (display && displayer.owned) GDS_Update(display);
|
||||||
|
else if (!led_display) displayer.wake = LONG_WAKE;
|
||||||
|
|
||||||
// release semaphore and sleep what's needed
|
// release semaphore and sleep what's needed
|
||||||
xSemaphoreGive(displayer.mutex);
|
xSemaphoreGive(displayer.mutex);
|
||||||
|
|||||||
@@ -387,11 +387,14 @@ static void process_strm(u8_t *pkt, int len) {
|
|||||||
}
|
}
|
||||||
sendSTAT("STMc", 0);
|
sendSTAT("STMc", 0);
|
||||||
sentSTMu = sentSTMo = sentSTMl = false;
|
sentSTMu = sentSTMo = sentSTMl = false;
|
||||||
LOCK_O;
|
|
||||||
#if EMBEDDED
|
#if EMBEDDED
|
||||||
|
// not protected so that restore can call synchronously sink handlers
|
||||||
if (output.external) decode_restore(output.external);
|
if (output.external) decode_restore(output.external);
|
||||||
|
LOCK_O;
|
||||||
output.external = 0;
|
output.external = 0;
|
||||||
_buf_limit(outputbuf, 0);
|
_buf_limit(outputbuf, 0);
|
||||||
|
#else
|
||||||
|
LOCK_O;
|
||||||
#endif
|
#endif
|
||||||
output.threshold = strm->output_threshold;
|
output.threshold = strm->output_threshold;
|
||||||
output.next_replay_gain = unpackN(&strm->replay_gain);
|
output.next_replay_gain = unpackN(&strm->replay_gain);
|
||||||
|
|||||||
15
sdkconfig
15
sdkconfig
@@ -277,31 +277,26 @@ CONFIG_ROTARY_ENCODER=""
|
|||||||
#
|
#
|
||||||
# LED configuration
|
# LED configuration
|
||||||
#
|
#
|
||||||
CONFIG_LED_GREEN_GPIO=12
|
CONFIG_LED_GREEN_GPIO=-1
|
||||||
CONFIG_LED_GREEN_GPIO_LEVEL=0
|
CONFIG_LED_RED_GPIO=-1
|
||||||
CONFIG_LED_RED_GPIO=13
|
|
||||||
CONFIG_LED_RED_GPIO_LEVEL=0
|
|
||||||
# end of LED configuration
|
# end of LED configuration
|
||||||
|
|
||||||
#
|
#
|
||||||
# Audio JACK
|
# Audio JACK
|
||||||
#
|
#
|
||||||
CONFIG_JACK_GPIO=34
|
CONFIG_JACK_GPIO=-1
|
||||||
CONFIG_JACK_GPIO_LEVEL=0
|
|
||||||
# end of Audio JACK
|
# end of Audio JACK
|
||||||
|
|
||||||
#
|
#
|
||||||
# Speaker Fault
|
# Speaker Fault
|
||||||
#
|
#
|
||||||
CONFIG_SPKFAULT_GPIO=2
|
CONFIG_SPKFAULT_GPIO=-1
|
||||||
CONFIG_SPKFAULT_GPIO_LEVEL=0
|
|
||||||
# end of Speaker Fault
|
# end of Speaker Fault
|
||||||
|
|
||||||
#
|
#
|
||||||
# Battery measure
|
# Battery measure
|
||||||
#
|
#
|
||||||
CONFIG_BAT_CHANNEL=7
|
CONFIG_BAT_CHANNEL=-1
|
||||||
CONFIG_BAT_SCALE="20.24"
|
|
||||||
# end of Battery measure
|
# end of Battery measure
|
||||||
|
|
||||||
CONFIG_DEFAULT_COMMAND_LINE="squeezelite -o I2S -b 500:2000 -d all=info -C 30 -W"
|
CONFIG_DEFAULT_COMMAND_LINE="squeezelite -o I2S -b 500:2000 -d all=info -C 30 -W"
|
||||||
|
|||||||
Reference in New Issue
Block a user