From 655af81a974369807cd648776a577a9b88947135 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 23 Aug 2019 20:25:13 -0700 Subject: [PATCH] fix AirPlay playback with SPDIF --- components/raop/rtp.c | 2 +- components/squeezelite/decode_external.c | 5 +++-- components/squeezelite/output_i2s.c | 23 ++++++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/components/raop/rtp.c b/components/raop/rtp.c index 2168c48d..9b797116 100644 --- a/components/raop/rtp.c +++ b/components/raop/rtp.c @@ -263,7 +263,7 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv, #ifdef WIN32 pthread_create(&ctx->rtp_thread, NULL, rtp_thread_func, (void *) ctx); #else - xTaskCreate((TaskFunction_t) rtp_thread_func, "RTP_thread", 4096, ctx, configMAX_PRIORITIES - 3, &ctx->rtp_thread); + xTaskCreate((TaskFunction_t) rtp_thread_func, "RTP_thread", 4096, ctx, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT , &ctx->rtp_thread); #endif } else { rtp_end(ctx); diff --git a/components/squeezelite/decode_external.c b/components/squeezelite/decode_external.c index f2abb73d..122c45e1 100644 --- a/components/squeezelite/decode_external.c +++ b/components/squeezelite/decode_external.c @@ -184,13 +184,14 @@ void raop_sink_cmd_handler(raop_event_t event, void *param) // how many ms have we really played ms = now - output.updated + ((u64_t) (output.frames_played_dmp - output.device_frames) * 1000) / RAOP_SAMPLE_RATE; error = ms - (now - raop_sync.start_time); - LOG_INFO("backend played %u, desired %u, (delta:%d)", ms, now - raop_sync.start_time, error); + LOG_DEBUG("backend played %u, desired %u, (delta:%d)", ms, now - raop_sync.start_time, error); if (abs(error) < 10 && abs(raop_sync.error) < 10) raop_sync.start = false; } else { // in how many ms will the most recent block play ms = ((u64_t) ((_buf_used(outputbuf) - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + output.frames_in_process) * 1000) / RAOP_SAMPLE_RATE - (now - output.updated); error = (raop_sync.playtime - now) - ms; - LOG_INFO("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error); + LOG_DEBUG("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error); + LOG_DEBUG("obuf:%u, sync_len:%u, devframes:%u, inproc:%u", _buf_used(outputbuf), raop_sync.len, output.device_frames, output.frames_in_process); } if (error < -10 && raop_sync.error < -10) { diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 90c884a4..0cef203c 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -41,6 +41,7 @@ sure that using rate_delay would fix that */ #include "squeezelite.h" +#include "esp_pthread.h" #include "driver/i2s.h" #include "driver/i2c.h" #include "driver/gpio.h" @@ -315,16 +316,20 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch dac_cmd(DAC_OFF); - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + OUTPUT_THREAD_STACK_SIZE); - pthread_create_name(&thread, &attr, output_thread_i2s, NULL, "output_i2s"); - - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 2048); - pthread_create_name(&stats_thread, NULL, output_thread_i2s_stats, NULL, "output_i2s_sts"); + esp_pthread_cfg_t cfg = esp_pthread_get_default_config(); - pthread_attr_destroy(&attr); + cfg.thread_name= "output_i2s"; + cfg.inherit_cfg = false; + cfg.prio = CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1; + cfg.stack_size = PTHREAD_STACK_MIN + OUTPUT_THREAD_STACK_SIZE; + esp_pthread_set_cfg(&cfg); + pthread_create(&thread, NULL, output_thread_i2s, NULL); + + cfg.thread_name= "output_i2s_sts"; + cfg.prio = CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT - 1; + cfg.stack_size = 2048; + esp_pthread_set_cfg(&cfg); + pthread_create(&stats_thread, NULL, output_thread_i2s_stats, NULL); }