diff --git a/components/platform_console/app_squeezelite/cmd_squeezelite.c b/components/platform_console/app_squeezelite/cmd_squeezelite.c index 5d1cdfba..c989e598 100644 --- a/components/platform_console/app_squeezelite/cmd_squeezelite.c +++ b/components/platform_console/app_squeezelite/cmd_squeezelite.c @@ -3,7 +3,6 @@ #include "application_name.h" #include "esp_log.h" #include "esp_console.h" -#include "esp_pthread.h" #include "../cmd_system.h" #include "argtable3/argtable3.h" #include "freertos/FreeRTOS.h" @@ -14,9 +13,7 @@ #include "esp_app_format.h" extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length); static const char * TAG = "squeezelite_cmd"; -#define SQUEEZELITE_THREAD_STACK_SIZE (4*1024) - - +#define SQUEEZELITE_THREAD_STACK_SIZE (8*1024) const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { @@ -42,8 +39,7 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { extern int main(int argc, char **argv); static int launchsqueezelite(int argc, char **argv); -pthread_t thread_squeezelite; -pthread_t thread_squeezelite_runner; + /** Arguments used by 'squeezelite' function */ static struct { struct arg_str *parameters; @@ -53,57 +49,47 @@ static struct { int argc; char ** argv; } thread_parms ; -static void * squeezelite_runner_thread(){ - ESP_LOGI(TAG ,"Calling squeezelite"); - main(thread_parms.argc,thread_parms.argv); - return NULL; -} + #define ADDITIONAL_SQUEEZELITE_ARGS 5 -static void * squeezelite_thread(){ - int * exit_code; - static bool isRunning=false; - if(isRunning) { - ESP_LOGE(TAG,"Squeezelite already running. Exiting!"); - return NULL; - } - isRunning=true; +static void squeezelite_thread(void *arg){ ESP_LOGV(TAG ,"Number of args received: %u",thread_parms.argc ); ESP_LOGV(TAG ,"Values:"); for(int i = 0;i", "command line for squeezelite. -h for help, --defaults to launch with default values."); squeezelite_args.end = arg_end(1); const esp_console_cmd_t launch_squeezelite = { @@ -148,10 +132,9 @@ void register_squeezelite(){ .argtable = &squeezelite_args }; ESP_ERROR_CHECK( esp_console_cmd_register(&launch_squeezelite) ); - } -esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) -{ + +esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) { if(!bin_url){ ESP_LOGE(TAG,"missing URL parameter. Unable to start OTA"); return ESP_ERR_INVALID_ARG; @@ -169,5 +152,4 @@ esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) ESP_LOGW(TAG, "Rebooting to recovery to complete the installation"); return guided_factory(); return ESP_OK; - } diff --git a/components/platform_console/platform_console.c b/components/platform_console/platform_console.c index a4c96e7f..f3395a37 100644 --- a/components/platform_console/platform_console.c +++ b/components/platform_console/platform_console.c @@ -297,11 +297,10 @@ void initialize_console() { xRingbufferAddToQueueSetRead(stdin_redir.handle, stdin_redir.queue_set); xQueueAddToSet(uart_queue, stdin_redir.queue_set); - const esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, - .open = stdin_dummy, - .read = stdin_read, - }; + esp_vfs_t vfs = { }; + vfs.flags = ESP_VFS_FLAG_DEFAULT; + vfs.open = stdin_dummy; + vfs.read = stdin_read; ESP_ERROR_CHECK(esp_vfs_register("/dev/console", &vfs, NULL)); freopen("/dev/console", "r", stdin); @@ -398,9 +397,9 @@ void console_start() { esp_pthread_cfg_t cfg = esp_pthread_get_default_config(); cfg.thread_name= "console"; cfg.inherit_cfg = true; + cfg.stack_size = 4*1024; if(is_recovery_running){ prompt = recovery_prompt; - cfg.stack_size = 4096 ; } esp_pthread_set_cfg(&cfg); pthread_create(&thread_console, NULL, console_thread, NULL); diff --git a/components/squeezelite/decode_external.c b/components/squeezelite/decode_external.c index 1431177d..998f60e5 100644 --- a/components/squeezelite/decode_external.c +++ b/components/squeezelite/decode_external.c @@ -9,9 +9,14 @@ * */ +#include +#ifdef ESP_PLATFORM +#include "freertos/FreeRTOS.h" +#include "freertos/timers.h" +#endif #include "platform_config.h" #include "squeezelite.h" -#include + #if CONFIG_BT_SINK #include "bt_app_sink.h" @@ -315,9 +320,26 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args) } #endif +/**************************************************************************************** + /**************************************************************************************** * We provide the generic codec register option */ + +#if defined(ESP_PLATFORM) && defined(CONFIG_BT_SINK) +void bt_delay_start(TimerHandle_t xTimer) { + xTimerDelete(xTimer, portMAX_DELAY); + bt_sink_init(bt_sink_cmd_handler, sink_data_handler); + LOG_INFO("Initializing BT sink"); +} + +void bt_delay_stop(TimerHandle_t xTimer) { + xTimerDelete(xTimer, portMAX_DELAY); + bt_sink_deinit(); + LOG_INFO("Stopping BT sink"); +} +#endif + void register_external(void) { char *p; @@ -338,8 +360,13 @@ void register_external(void) { #if CONFIG_BT_SINK if (!strcasestr(output.device, "BT ") ) { if(enable_bt_sink){ +#ifdef ESP_PLATFORM + // we need to delay the start because current task is in spiram + TimerHandle_t timer = xTimerCreate("delay", 1, pdFALSE, NULL, bt_delay_start); + xTimerStart(timer, portMAX_DELAY); +#else bt_sink_init(bt_sink_cmd_handler, sink_data_handler); - LOG_INFO("Initializing BT sink"); +#endif } } else { LOG_WARN("Cannot be a BT sink and source"); @@ -358,10 +385,16 @@ void register_external(void) { void deregister_external(void) { #if CONFIG_BT_SINK if (!strcasestr(output.device, "BT ") && enable_bt_sink) { - LOG_INFO("Stopping BT sink"); +#ifdef ESP_PLATFORM + // we need to delay the stop because current task is in spiram + TimerHandle_t timer = xTimerCreate("delay", 1, pdFALSE, NULL, bt_delay_stop); + xTimerStart(timer, portMAX_DELAY); +#else bt_sink_deinit(); +#endif } #endif + #if CONFIG_AIRPLAY_SINK if (enable_airplay){ LOG_INFO("Stopping AirPlay sink"); diff --git a/components/telnet/telnet.c b/components/telnet/telnet.c index 64a5cdae..28839566 100644 --- a/components/telnet/telnet.c +++ b/components/telnet/telnet.c @@ -58,14 +58,14 @@ struct telnetUserData { }; const static char TAG[] = "telnet"; -static int uart_fd=0; +static int uart_fd; static RingbufHandle_t buf_handle; static size_t send_chunk = 512; static size_t log_buf_size = 4*1024; static bool bIsEnabled=false; -static int partnerSocket=0; +static int partnerSocket; static telnet_t *tnHandle; -static bool bMirrorToUART=false; +static bool bMirrorToUART; /************************************ * Forward declarations @@ -87,7 +87,6 @@ void init_telnet(){ } // if wifi manager is bypassed, there will possibly be no wifi available - // bMirrorToUART = (strcasestr("D",val)!=NULL); if(!bMirrorToUART && bypass_wifi_manager){ // This isn't supposed to happen, as telnet won't start if wifi manager isn't @@ -121,20 +120,17 @@ void init_telnet(){ } ESP_LOGI(TAG, "***Redirecting log output to telnet"); - const esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT, - .write = &stdout_write, - .open = &stdout_open, - .fstat = &stdout_fstat, - }; + esp_vfs_t vfs = { }; + vfs.flags = ESP_VFS_FLAG_DEFAULT; + vfs.write = &stdout_write; + vfs.open = &stdout_open; + vfs.fstat = &stdout_fstat; - if(bMirrorToUART){ - uart_fd=open("/dev/uart/0", O_RDWR); - } + if (bMirrorToUART) uart_fd = open("/dev/uart/0", O_RDWR); ESP_ERROR_CHECK(esp_vfs_register("/dev/pkspstdout", &vfs, NULL)); - freopen("/dev/pkspstdout", "w", stdout); - freopen("/dev/pkspstdout", "w", stderr); + freopen("/dev/pkspstdout", "wb", stdout); + freopen("/dev/pkspstdout", "wb", stderr); bIsEnabled=true; } @@ -293,17 +289,14 @@ static void handle_telnet_conn() { // ******************* stdout/stderr Redirection to ringbuffer static ssize_t stdout_write(int fd, const void * data, size_t size) { - // #1 Write to ringbuffer - if (buf_handle == NULL) { - printf("%s() ABORT. file handle _log_remote_fp is NULL\n", - __FUNCTION__); - } else { - // flush the buffer if needed and send item + // flush the buffer and send item + if (buf_handle) { process_logs(size, true); xRingbufferSend(buf_handle, data, size, 0); - } - return bMirrorToUART ? write(uart_fd, data, size) : size; + + // mirror to uart if required + return (bMirrorToUART || !buf_handle) ? write(uart_fd, data, size) : size; } static int stdout_open(const char * path, int flags, int mode) {