mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
big merge
This commit is contained in:
@@ -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);
|
||||
@@ -525,15 +525,17 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
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.thread = xTaskCreateStatic( (TaskFunction_t) search_remote, "search_remote", SEARCH_STACK_SIZE, ctx, ESP_TASK_PRIO_MIN + 2, ctx->active_remote.xStack, ctx->active_remote.xTaskBuffer);
|
||||
#endif
|
||||
|
||||
} else if (!strcmp(method, "SETUP") && ((buf = kd_lookup(headers, "Transport")) != NULL)) {
|
||||
|
||||
} else if (!strcmp(method, "SETUP") && ((buf = kd_lookup(headers, "Transport")) != NULL)) {
|
||||
char *p;
|
||||
rtp_resp_t rtp = { 0 };
|
||||
short unsigned tport = 0, cport = 0;
|
||||
uint8_t *buffer = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
// we are about to stream, do something if needed and optionally give buffers to play with
|
||||
success = ctx->cmd_cb(RAOP_SETUP);
|
||||
success = ctx->cmd_cb(RAOP_SETUP, &buffer, &size);
|
||||
|
||||
if ((p = strcasestr(buf, "timing_port")) != NULL) sscanf(p, "%*[^=]=%hu", &tport);
|
||||
if ((p = strcasestr(buf, "control_port")) != NULL) sscanf(p, "%*[^=]=%hu", &cport);
|
||||
@@ -605,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
|
||||
@@ -672,9 +673,8 @@ 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);
|
||||
#else
|
||||
#else
|
||||
// need to make sure no search is on-going and reclaim task memory
|
||||
// need to make sure no search is on-going and reclaim task memory
|
||||
ctx->active_remote.running = false;
|
||||
xSemaphoreTake(ctx->active_remote.destroy_mutex, portMAX_DELAY);
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
/*
|
||||
* AirCast: Chromecast to AirPlay
|
||||
*
|
||||
* (c) Philippe 2016-2017, philippe_44@outlook.com
|
||||
* (c) Philippe 2020, philippe_44@outlook.com
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __RAOP_H
|
||||
#define __RAOP_H
|
||||
#pragma once
|
||||
|
||||
#include "platform.h"
|
||||
#include "raop_sink.h"
|
||||
@@ -20,4 +17,3 @@ void raop_delete(struct raop_ctx_s *ctx);
|
||||
void raop_abort(struct raop_ctx_s *ctx);
|
||||
bool raop_cmd(struct raop_ctx_s *ctx, raop_event_t event, void *param);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
#include "audio_controls.h"
|
||||
#include "display.h"
|
||||
#include "accessors.h"
|
||||
|
||||
#include "log_util.h"
|
||||
#include "trace.h"
|
||||
|
||||
#ifndef CONFIG_AIRPLAY_NAME
|
||||
#define CONFIG_AIRPLAY_NAME "ESP32-AirPlay"
|
||||
@@ -184,7 +182,7 @@ static bool raop_sink_start(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
|
||||
ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
|
||||
|
||||
char * sink_name_buffer= (char *)config_alloc_get(NVS_TYPE_STR,"airplay_name");
|
||||
if(sink_name_buffer != NULL){
|
||||
if (sink_name_buffer != NULL){
|
||||
memset(sink_name, 0x00, sizeof(sink_name));
|
||||
strncpy(sink_name,sink_name_buffer,sizeof(sink_name)-1 );
|
||||
free(sink_name_buffer);
|
||||
@@ -219,7 +217,7 @@ void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
|
||||
raop_cbs.data = data_cb;
|
||||
TimerHandle_t timer = xTimerCreate("raopStart", 5000 / portTICK_RATE_MS, pdTRUE, NULL, raop_start_handler);
|
||||
xTimerStart(timer, portMAX_DELAY);
|
||||
LOG_INFO( "delaying AirPlay start");
|
||||
LOG_INFO( "Delaying AirPlay start");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@
|
||||
#define MS2TS(ms, rate) ((((u64_t) (ms)) * (rate)) / 1000)
|
||||
#define TS2MS(ts, rate) NTP2MS(TS2NTP(ts,rate))
|
||||
|
||||
|
||||
extern log_level raop_loglevel;
|
||||
extern log_level raop_loglevel;
|
||||
static log_level *loglevel = &raop_loglevel;
|
||||
|
||||
//#define __RTP_STORE
|
||||
|
||||
@@ -93,6 +93,7 @@ typedef struct audio_buffer_entry { // decoded audio packets
|
||||
u32_t rtptime, last_resend;
|
||||
s16_t *data;
|
||||
int len;
|
||||
bool allocated;
|
||||
} abuf_t;
|
||||
|
||||
typedef struct rtp_s {
|
||||
@@ -152,7 +153,7 @@ typedef struct rtp_s {
|
||||
|
||||
|
||||
#define BUFIDX(seqno) ((seq_t)(seqno) % BUFFER_FRAMES)
|
||||
|
||||
static void buffer_alloc(abuf_t *audio_buffer, int size, uint8_t *buf, size_t buf_size);
|
||||
static void buffer_release(abuf_t *audio_buffer);
|
||||
static void buffer_reset(abuf_t *audio_buffer);
|
||||
static void buffer_push_packet(rtp_t *ctx);
|
||||
@@ -208,6 +209,7 @@ static struct alac_codec_s* alac_init(int fmtp[32]) {
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv, char *fmtpstr,
|
||||
short unsigned pCtrlPort, short unsigned pTimingPort,
|
||||
uint8_t *buffer, size_t size,
|
||||
raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -260,7 +262,7 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv,
|
||||
ctx->alac_codec = alac_init(fmtp);
|
||||
rc &= ctx->alac_codec != NULL;
|
||||
|
||||
rc &= ctx->alac_codec != NULL;
|
||||
buffer_alloc(ctx->audio_buffer, ctx->frame_size*4, buffer, size);
|
||||
|
||||
// create rtp ports
|
||||
for (i = 0; i < 3; i++) {
|
||||
@@ -311,7 +313,7 @@ void rtp_end(rtp_t *ctx)
|
||||
#else
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
vTaskDelete(ctx->thread);
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
SAFE_PTR_FREE(ctx->xTaskBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -369,10 +371,18 @@ void rtp_record(rtp_t *ctx, unsigned short seqno, unsigned rtptime) {
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void buffer_alloc(abuf_t *audio_buffer, int size, uint8_t *buf, size_t buf_size) {
|
||||
int i;
|
||||
for (i = 0; i < BUFFER_FRAMES; i++) {
|
||||
int i;
|
||||
if (buf && buf_size >= size) {
|
||||
audio_buffer[i].data = (s16_t*) buf;
|
||||
audio_buffer[i].allocated = false;
|
||||
buf += size;
|
||||
buf_size -= size;
|
||||
} else {
|
||||
audio_buffer[i].allocated = true;
|
||||
audio_buffer[i].data = malloc(size);
|
||||
}
|
||||
audio_buffer[i].ready = 0;
|
||||
}
|
||||
}
|
||||
@@ -381,7 +391,7 @@ static void buffer_alloc(abuf_t *audio_buffer, int size) {
|
||||
static void buffer_release(abuf_t *audio_buffer) {
|
||||
int i;
|
||||
for (i = 0; i < BUFFER_FRAMES; i++) {
|
||||
int i;
|
||||
if (audio_buffer[i].allocated) free(audio_buffer[i].data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ typedef struct {
|
||||
rtp_resp_t rtp_init(struct in_addr host, int latency,
|
||||
char *aeskey, char *aesiv, char *fmtpstr,
|
||||
short unsigned pCtrlPort, short unsigned pTimingPort,
|
||||
uint8_t *buffer, size_t size,
|
||||
raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb);
|
||||
void rtp_end(struct rtp_s *ctx);
|
||||
bool rtp_flush(struct rtp_s *ctx, unsigned short seqno, unsigned rtptime, bool exit_locked);
|
||||
|
||||
@@ -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,9 +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_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);
|
||||
@@ -67,5 +84,6 @@ char* kd_dump(key_data_t *kd);
|
||||
char* http_send(int sock, char *method, key_data_t *rkd);
|
||||
|
||||
char* kd_lookup(key_data_t *kd, char *key);
|
||||
bool kd_add(key_data_t *kd, char *key, char *value);
|
||||
bool kd_add(key_data_t *kd, char *key, char *value);
|
||||
char* kd_dump(key_data_t *kd);
|
||||
void kd_free(key_data_t *kd);
|
||||
|
||||
Reference in New Issue
Block a user