BT/RAOP switch improvments + pin tasks to core 1 (pthread)

This commit is contained in:
Philippe G
2021-12-21 23:19:02 -08:00
parent 29b3eee5b6
commit efc2c9515c
4 changed files with 12 additions and 5 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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); \

View File

@@ -138,6 +138,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");
} }
@@ -282,6 +283,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);