mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
move some staks to external memory
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
TODO
|
||||
- when IP changes, best is to reboot at this point
|
||||
|
||||
MOST IMPORTANT: create the right default config file
|
||||
- make defconfig
|
||||
Then adapt the config file to your wifi/BT/I2C device (can alos be done on the command line)
|
||||
|
||||
@@ -412,6 +412,21 @@ void bt_sink_init(bt_cmd_cb_t cmd_cb, bt_data_cb_t data_cb)
|
||||
|
||||
}
|
||||
|
||||
void bt_sink_deinit(void)
|
||||
{
|
||||
/* this still does not work, can't figure out how to stop properly this BT stack */
|
||||
bt_app_task_shut_down();
|
||||
ESP_LOGI(BT_AV_TAG, "bt_app_task shutdown successfully");
|
||||
if (esp_bluedroid_disable() != ESP_OK) return;
|
||||
ESP_LOGI(BT_AV_TAG, "esp_bluedroid_disable called successfully");
|
||||
if (esp_bluedroid_deinit() != ESP_OK) return;
|
||||
ESP_LOGI(BT_AV_TAG, "esp_bluedroid_deinit called successfully");
|
||||
if (esp_bt_controller_disable() != ESP_OK) return;
|
||||
ESP_LOGI(BT_AV_TAG, "esp_bt_controller_disable called successfully");
|
||||
if (esp_bt_controller_deinit() != ESP_OK) return;
|
||||
ESP_LOGI(BT_AV_TAG, "bt stopped successfully");
|
||||
}
|
||||
|
||||
static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
|
||||
{
|
||||
switch (event) {
|
||||
|
||||
@@ -22,6 +22,11 @@ typedef void (*bt_data_cb_t)(const uint8_t *data, uint32_t len);
|
||||
*/
|
||||
void bt_sink_init(bt_cmd_cb_t cmd_cb, bt_data_cb_t data_cb);
|
||||
|
||||
/**
|
||||
* @brief deinit sink mode (need to be provided)
|
||||
*/
|
||||
void bt_sink_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief local command mode (stop, play, volume ...)
|
||||
*/
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include "dmap_parser.h"
|
||||
#include "log_util.h"
|
||||
|
||||
#define RTSP_STACK_SIZE (8*1024)
|
||||
|
||||
typedef struct raop_ctx_s {
|
||||
#ifdef WIN32
|
||||
struct mdns_service *svc;
|
||||
@@ -57,6 +59,8 @@ typedef struct raop_ctx_s {
|
||||
pthread_t thread, search_thread;
|
||||
#else
|
||||
TaskHandle_t thread, search_thread, joiner;
|
||||
StaticTask_t *xTaskBuffer;
|
||||
StackType_t *xStack;
|
||||
#endif
|
||||
unsigned char mac[6];
|
||||
int latency;
|
||||
@@ -179,7 +183,13 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
|
||||
|
||||
#ifdef WIN32
|
||||
// seems that Windows snprintf does not add NULL char if actual size > max
|
||||
id[63] = '\0';
|
||||
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);
|
||||
|
||||
#else
|
||||
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)) );
|
||||
|
||||
/*
|
||||
xTaskCreate((TaskFunction_t) rtsp_thread, "RTSP_thread", 8*1024, ctx, ESP_TASK_PRIO_MIN + 1, &ctx->thread);
|
||||
@@ -194,6 +204,10 @@ void raop_delete(struct raop_ctx_s *ctx) {
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void raop_delete(struct raop_ctx_s *ctx) {
|
||||
int sock;
|
||||
struct sockaddr addr;
|
||||
socklen_t nlen = sizeof(struct sockaddr);
|
||||
|
||||
if (!ctx) return;
|
||||
|
||||
@@ -205,8 +219,9 @@ void raop_delete(struct raop_ctx_s *ctx) {
|
||||
|
||||
// wake-up thread by connecting socket, needed for freeBSD
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
getsockname(ctx->sock, (struct sockaddr *) &addr, &nlen);
|
||||
getsockname(ctx->sock, (struct sockaddr *) &addr, &nlen);
|
||||
connect(sock, (struct sockaddr*) &addr, sizeof(addr));
|
||||
closesocket(sock);
|
||||
|
||||
#ifdef WIN32
|
||||
pthread_join(ctx->thread, NULL);
|
||||
@@ -234,6 +249,8 @@ void raop_delete(struct raop_ctx_s *ctx) {
|
||||
*/
|
||||
|
||||
NFREE(ctx->rtsp.aeskey);
|
||||
NFREE(ctx->rtsp.aesiv);
|
||||
NFREE(ctx->rtsp.fmtp);
|
||||
|
||||
// stop broadcasting devices
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -31,6 +31,14 @@ log_level util_loglevel;
|
||||
static log_level *loglevel = &raop_loglevel;
|
||||
static struct raop_ctx_s *raop;
|
||||
|
||||
/****************************************************************************************
|
||||
* Airplay sink de-initialization
|
||||
*/
|
||||
void raop_sink_deinit(void) {
|
||||
raop_delete(raop);
|
||||
mdns_free();
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Airplay sink initialization
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,12 @@ typedef void (*raop_data_cb_t)(const u8_t *data, size_t len, u32_t playtime);
|
||||
|
||||
void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb);
|
||||
|
||||
/**
|
||||
* @brief deinit sink mode (need to be provided)
|
||||
*/
|
||||
|
||||
void raop_sink_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief init sink mode (need to be provided)
|
||||
*/
|
||||
|
||||
@@ -75,6 +75,8 @@
|
||||
#define BUFFER_FRAMES ( (150 * RAOP_SAMPLE_RATE * 2) / (352 * 100) )
|
||||
#define MAX_PACKET 1408
|
||||
#define MIN_LATENCY 11025
|
||||
#define MAX_LATENCY ( (120 * RAOP_SAMPLE_RATE * 2) / 100 )
|
||||
|
||||
#define RTP_STACK_SIZE (4*1024)
|
||||
|
||||
#define RTP_SYNC (0x01)
|
||||
@@ -133,9 +135,11 @@ typedef struct rtp_s {
|
||||
u32_t discarded;
|
||||
abuf_t audio_buffer[BUFFER_FRAMES];
|
||||
seq_t ab_read, ab_write;
|
||||
pthread_mutex_t ab_mutex;
|
||||
pthread_mutex_t ab_mutex;
|
||||
#ifdef WIN32
|
||||
pthread_t rtp_thread;
|
||||
pthread_t thread;
|
||||
#else
|
||||
TaskHandle_t thread, joiner;
|
||||
StaticTask_t *xTaskBuffer;
|
||||
StackType_t *xStack;
|
||||
#endif
|
||||
@@ -259,9 +263,13 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv,
|
||||
resp.aport = ctx->rtp_sockets[DATA].lport;
|
||||
|
||||
if (rc) {
|
||||
ctx->running = true;
|
||||
ctx->running = true;
|
||||
#ifdef WIN32
|
||||
pthread_create(&ctx->rtp_thread, NULL, rtp_thread_func, (void *) ctx);
|
||||
pthread_create(&ctx->thread, NULL, rtp_thread_func, (void *) ctx);
|
||||
#else
|
||||
// xTaskCreate((TaskFunction_t) rtp_thread_func, "RTP_thread", RTP_TASK_SIZE, ctx, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1 , &ctx->thread);
|
||||
ctx->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
ctx->xStack = (StackType_t*) malloc(RTP_STACK_SIZE);
|
||||
ctx->thread = xTaskCreateStatic( (TaskFunction_t) rtp_thread_func, "RTP_thread", RTP_STACK_SIZE, ctx,
|
||||
CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1, ctx->xStack, ctx->xTaskBuffer );
|
||||
#endif
|
||||
@@ -281,14 +289,19 @@ void rtp_end(rtp_t *ctx)
|
||||
int i;
|
||||
|
||||
if (!ctx) return;
|
||||
|
||||
if (ctx->running) {
|
||||
#if !defined WIN32
|
||||
ctx->joiner = xTaskGetCurrentTaskHandle();
|
||||
#endif
|
||||
ctx->running = false;
|
||||
#ifdef WIN32
|
||||
pthread_join(ctx->rtp_thread, NULL);
|
||||
pthread_join(ctx->rtp_thread, NULL);
|
||||
#else
|
||||
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
||||
free(ctx->xStack);
|
||||
heap_caps_free(ctx->xTaskBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) closesocket(ctx->rtp_sockets[i].sock);
|
||||
|
||||
@@ -117,6 +117,10 @@ static void *decode_thread() {
|
||||
}
|
||||
}
|
||||
|
||||
#if EMBEDDED
|
||||
deregister_external();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -284,3 +284,16 @@ void register_external(void) {
|
||||
LOG_INFO("Initializing AirPlay sink");
|
||||
#endif
|
||||
}
|
||||
|
||||
void deregister_external(void) {
|
||||
#ifdef CONFIG_BT_SINK
|
||||
if (!strcasestr(output.device, "BT ")) {
|
||||
bt_sink_deinit();
|
||||
LOG_INFO("Stopping BT sink");
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_AIRPLAY_SINK
|
||||
raop_sink_deinit();
|
||||
LOG_INFO("Stopping AirPlay sink");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -37,8 +37,12 @@ typedef unsigned long long u64_t;
|
||||
#define mutex_create_p(m) mutex_create(m)
|
||||
|
||||
uint32_t _gettime_ms_(void);
|
||||
|
||||
int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
|
||||
void *(*start_routine)( void * ), void *arg, char *name);
|
||||
|
||||
// these are here as they can be #define to nothing
|
||||
void register_external(void);
|
||||
void deregister_external(void);
|
||||
|
||||
#endif // EMBEDDED_H
|
||||
|
||||
@@ -631,7 +631,6 @@ static void slimproto_run() {
|
||||
#endif
|
||||
last = now;
|
||||
|
||||
|
||||
LOCK_S;
|
||||
status.stream_full = _buf_used(streambuf);
|
||||
status.stream_size = streambuf->size;
|
||||
|
||||
@@ -80,6 +80,7 @@ CONFIG_SPIRAM_CACHE_WORKAROUND=y
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=256
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536
|
||||
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
|
||||
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
|
||||
CONFIG_SPIRAM_OCCUPY_VSPI_HOST=y
|
||||
CONFIG_SPIRAM_BANKSWITCH_ENABLE=n
|
||||
CONFIG_D0WD_PSRAM_CLK_IO=17
|
||||
|
||||
Reference in New Issue
Block a user