Give some love to AIrPlay/BT screens + better "safe TCB release" - release

This commit is contained in:
Philippe G
2021-12-18 15:20:22 -08:00
parent f872623785
commit 975f34f01b
9 changed files with 92 additions and 34 deletions

View File

@@ -255,7 +255,7 @@ void raop_delete(struct raop_ctx_s *ctx) {
// brute-force exit of accept()
shutdown(ctx->sock, SHUT_RDWR);
closesocket(ctx->sock);
closesocket(ctx->sock);
// wait to make sure LWIP if scheduled (avoid issue with NotifyTake)
vTaskDelay(100 / portTICK_PERIOD_MS);
@@ -607,7 +607,6 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
volume = (volume == -144.0) ? 0 : (1 + volume / 30);
success = ctx->cmd_cb(RAOP_VOLUME, volume);
} else if (body && (p = strcasestr(body, "progress")) != NULL) {
int start, current, stop = 0;
int start, current, stop = 0;
// we want ms, not s
@@ -674,7 +673,7 @@ void cleanup_rtsp(raop_ctx_t *ctx, bool abort) {
if (ctx->active_remote.running) {
#ifdef WIN32
pthread_join(ctx->active_remote.thread, NULL);
close_mDNS(ctx->active_remote.handle);
close_mDNS(ctx->active_remote.handle);
#else
// need to make sure no search is on-going and reclaim task memory
ctx->active_remote.running = false;

View File

@@ -313,7 +313,7 @@ void rtp_end(rtp_t *ctx)
#else
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
vTaskDelete(ctx->thread);
SAFE_TCB_FREE(ctx->xTaskBuffer);
SAFE_PTR_FREE(ctx->xTaskBuffer);
#endif
}

View File

@@ -18,6 +18,11 @@
#include "platform.h"
#include "pthread.h"
#ifndef WIN32
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#endif
#define NFREE(p) if (p) { free(p); p = NULL; }
typedef struct metadata_s {
@@ -46,19 +51,21 @@ char *strndup(const char *s, size_t n);
char *strndup(const char *s, size_t n);
int asprintf(char **strp, const char *fmt, ...);
void winsock_init(void);
void winsock_close(void);
void winsock_close(void);
#define SAFE_PTR_FREE(P) free(P)
#else
char *strlwr(char *str);
// reason is that TCB might be cleanup in idle task
#define SAFE_TCB_FREE(T) \
do { \
int priority = uxTaskPriorityGet(NULL); \
vTaskPrioritySet(NULL, tskIDLE_PRIORITY); \
vTaskDelay(1); \
vTaskPrioritySet(NULL, priority); \
#define SAFE_PTR_FREE(P) \
do { \
TimerHandle_t timer = xTimerCreate("cleanup", pdMS_TO_TICKS(5000), pdFALSE, P, _delayed_free); \
xTimerStart(timer, portMAX_DELAY); \
} while (0)
static void inline _delayed_free(TimerHandle_t xTimer) {
free(pvTimerGetTimerID(xTimer));
xTimerDelete(xTimer, portMAX_DELAY);
}
#endif
char* strextract(char *s1, char *beg, char *end);