mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
AirPlay co-existence improvements, couple of display issues
This commit is contained in:
@@ -46,7 +46,7 @@ static bool enable_airplay;
|
||||
#define SYNC_NB 5
|
||||
|
||||
static raop_event_t raop_state;
|
||||
static bool raop_expect_stop = false;
|
||||
|
||||
static struct {
|
||||
bool enabled, start;
|
||||
s32_t error[SYNC_NB];
|
||||
@@ -123,9 +123,8 @@ static bool bt_sink_cmd_handler(bt_sink_cmd_t cmd, va_list args)
|
||||
LOG_INFO("BT sink started");
|
||||
break;
|
||||
case BT_SINK_AUDIO_STOPPED:
|
||||
// do we still need that?
|
||||
if (output.external == DECODE_BT) {
|
||||
output.state = OUTPUT_OFF;
|
||||
if (output.state > OUTPUT_STOPPED) output.state = OUTPUT_STOPPED;
|
||||
LOG_INFO("BT sink stopped");
|
||||
}
|
||||
break;
|
||||
@@ -136,6 +135,7 @@ static bool bt_sink_cmd_handler(bt_sink_cmd_t cmd, va_list args)
|
||||
case BT_SINK_STOP:
|
||||
_buf_flush(outputbuf);
|
||||
output.state = OUTPUT_STOPPED;
|
||||
output.stop_time = gettime_ms();
|
||||
LOG_INFO("BT sink stopped");
|
||||
break;
|
||||
case BT_SINK_PAUSE:
|
||||
@@ -253,18 +253,14 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
||||
output.next_sample_rate = output.current_sample_rate = RAOP_SAMPLE_RATE;
|
||||
break;
|
||||
case RAOP_STOP:
|
||||
LOG_INFO("Stop", NULL);
|
||||
output.state = OUTPUT_OFF;
|
||||
output.frames_played = 0;
|
||||
raop_state = event;
|
||||
break;
|
||||
case RAOP_FLUSH:
|
||||
LOG_INFO("Flush", NULL);
|
||||
raop_expect_stop = true;
|
||||
if (event == RAOP_FLUSH) { LOG_INFO("Flush", NULL); }
|
||||
else { LOG_INFO("Stop", NULL); }
|
||||
raop_state = event;
|
||||
_buf_flush(outputbuf);
|
||||
output.state = OUTPUT_STOPPED;
|
||||
if (output.state > OUTPUT_STOPPED) output.state = OUTPUT_STOPPED;
|
||||
output.frames_played = 0;
|
||||
output.stop_time = gettime_ms();
|
||||
break;
|
||||
case RAOP_PLAY: {
|
||||
LOG_INFO("Play", NULL);
|
||||
|
||||
@@ -84,7 +84,10 @@ extern struct outputstate output;
|
||||
static struct {
|
||||
TaskHandle_t task;
|
||||
SemaphoreHandle_t mutex;
|
||||
} displayer;
|
||||
int width, height;
|
||||
bool dirty;
|
||||
bool owned;
|
||||
} displayer = { .dirty = true, .owned = true };
|
||||
|
||||
#define LONG_WAKE (10*1000)
|
||||
#define SB_HEIGHT 32
|
||||
@@ -147,26 +150,28 @@ static u8_t SETD_width;
|
||||
#define LINELEN 40
|
||||
|
||||
static log_level loglevel = lINFO;
|
||||
|
||||
static bool (*slimp_handler_chain)(u8_t *data, int len);
|
||||
static void (*slimp_loop_chain)(void);
|
||||
static void (*notify_chain)(in_addr_t ip, u16_t hport, u16_t cport);
|
||||
static int display_width, display_height;
|
||||
static bool display_dirty = true;
|
||||
static bool (*display_bus_chain)(void *from, enum display_bus_cmd_e cmd);
|
||||
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
static void server(in_addr_t ip, u16_t hport, u16_t cport);
|
||||
static void send_server(void);
|
||||
static bool handler(u8_t *data, int len);
|
||||
static bool display_bus_handler(void *from, enum display_bus_cmd_e cmd);
|
||||
static void vfdc_handler( u8_t *_data, int bytes_read);
|
||||
static void grfe_handler( u8_t *data, int len);
|
||||
static void grfb_handler(u8_t *data, int len);
|
||||
static void grfs_handler(u8_t *data, int len);
|
||||
static void grfg_handler(u8_t *data, int len);
|
||||
static void visu_handler( u8_t *data, int len);
|
||||
static void visu_handler(u8_t *data, int len);
|
||||
|
||||
static void displayer_task(void* arg);
|
||||
|
||||
|
||||
/* scrolling undocumented information
|
||||
grfs
|
||||
B: screen number
|
||||
@@ -208,8 +213,8 @@ bool sb_display_init(void) {
|
||||
}
|
||||
|
||||
// need to force height to 32 maximum
|
||||
display_width = display->width;
|
||||
display_height = min(display->height, SB_HEIGHT);
|
||||
displayer.width = display->width;
|
||||
displayer.height = min(display->height, SB_HEIGHT);
|
||||
SETD_width = display->width;
|
||||
|
||||
// create visu configuration
|
||||
@@ -223,10 +228,10 @@ bool sb_display_init(void) {
|
||||
displayer.task = xTaskCreateStatic( (TaskFunction_t) displayer_task, "displayer_thread", SCROLL_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN + 1, xStack, &xTaskBuffer);
|
||||
|
||||
// size scroller
|
||||
scroller.scroll.max = (display_width * display_height / 8) * 10;
|
||||
scroller.scroll.max = (displayer.width * displayer.height / 8) * 10;
|
||||
scroller.scroll.frame = malloc(scroller.scroll.max);
|
||||
scroller.back.frame = malloc(display_width * display_height / 8);
|
||||
scroller.frame = malloc(display_width * display_height / 8);
|
||||
scroller.back.frame = malloc(displayer.width * displayer.height / 8);
|
||||
scroller.frame = malloc(displayer.width * displayer.height / 8);
|
||||
|
||||
// chain handlers
|
||||
slimp_handler_chain = slimp_handler;
|
||||
@@ -238,9 +243,39 @@ bool sb_display_init(void) {
|
||||
notify_chain = server_notify;
|
||||
server_notify = server;
|
||||
|
||||
display_bus_chain = display_bus;
|
||||
display_bus = display_bus_handler;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Receive display bus commands
|
||||
*/
|
||||
static bool display_bus_handler(void *from, enum display_bus_cmd_e cmd) {
|
||||
// don't answer to own requests
|
||||
if (from == &displayer) return false ;
|
||||
|
||||
LOG_INFO("Display bus command %d", cmd);
|
||||
|
||||
xSemaphoreTake(displayer.mutex, portMAX_DELAY);
|
||||
|
||||
switch (cmd) {
|
||||
case DISPLAY_BUS_TAKE:
|
||||
displayer.owned = false;
|
||||
break;
|
||||
case DISPLAY_BUS_GIVE:
|
||||
displayer.owned = true;
|
||||
break;
|
||||
}
|
||||
|
||||
xSemaphoreGive(displayer.mutex);
|
||||
|
||||
if (display_bus_chain) return (*display_bus_chain)(from, cmd);
|
||||
else return true;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Send message to server (ANIC at that time)
|
||||
*/
|
||||
@@ -289,9 +324,9 @@ static void send_server(void) {
|
||||
static void server(in_addr_t ip, u16_t hport, u16_t cport) {
|
||||
char msg[32];
|
||||
sprintf(msg, "%s:%hu", inet_ntoa(ip), hport);
|
||||
display->text(DISPLAY_FONT_DEFAULT, DISPLAY_CENTERED, DISPLAY_CLEAR | DISPLAY_UPDATE, msg);
|
||||
if (displayer.owned) display->text(DISPLAY_FONT_DEFAULT, DISPLAY_CENTERED, DISPLAY_CLEAR | DISPLAY_UPDATE, msg);
|
||||
SETD_width = display->width;
|
||||
display_dirty = true;
|
||||
displayer.dirty = true;
|
||||
if (notify_chain) (*notify_chain)(ip, hport, cport);
|
||||
}
|
||||
|
||||
@@ -301,24 +336,21 @@ static void server(in_addr_t ip, u16_t hport, u16_t cport) {
|
||||
static bool handler(u8_t *data, int len){
|
||||
bool res = true;
|
||||
|
||||
// don't do anything if we dont own the display (no lock needed)
|
||||
if (!output.external || output.state < OUTPUT_STOPPED) {
|
||||
if (!strncmp((char*) data, "vfdc", 4)) {
|
||||
vfdc_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfe", 4)) {
|
||||
grfe_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfb", 4)) {
|
||||
grfb_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfs", 4)) {
|
||||
grfs_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfg", 4)) {
|
||||
grfg_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "visu", 4)) {
|
||||
visu_handler(data, len);
|
||||
} else {
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
if (!strncmp((char*) data, "vfdc", 4)) {
|
||||
vfdc_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfe", 4)) {
|
||||
grfe_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfb", 4)) {
|
||||
grfb_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfs", 4)) {
|
||||
grfs_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "grfg", 4)) {
|
||||
grfg_handler(data, len);
|
||||
} else if (!strncmp((char*) data, "visu", 4)) {
|
||||
visu_handler(data, len);
|
||||
} else {
|
||||
res = false;
|
||||
}
|
||||
|
||||
// chain protocol handlers (bitwise or is fine)
|
||||
if (*slimp_handler_chain) res |= (*slimp_handler_chain)(data, len);
|
||||
@@ -448,20 +480,23 @@ static void grfe_handler( u8_t *data, int len) {
|
||||
|
||||
scroller.active = false;
|
||||
|
||||
// if we are displaying visu on a small screen, do not do screen update
|
||||
// we are not in control or we are displaying visu on a small screen, do not do screen update
|
||||
if (visu.mode && !visu.col && visu.row < SB_HEIGHT) {
|
||||
xSemaphoreGive(displayer.mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
// did we have something that might have write on the bottom of a SB_HEIGHT+ display
|
||||
if (display_dirty) {
|
||||
display->clear(true);
|
||||
display_dirty = false;
|
||||
}
|
||||
if (displayer.owned) {
|
||||
// did we have something that might have write on the bottom of a SB_HEIGHT+ display
|
||||
if (displayer.dirty) {
|
||||
display->clear(true);
|
||||
displayer.dirty = false;
|
||||
}
|
||||
|
||||
display->draw_cbr(data + sizeof(struct grfe_packet), display_width, display_height);
|
||||
display->update();
|
||||
// draw new frame
|
||||
display->draw_cbr(data + sizeof(struct grfe_packet), displayer.width, displayer.height);
|
||||
display->update();
|
||||
}
|
||||
|
||||
xSemaphoreGive(displayer.mutex);
|
||||
|
||||
@@ -518,7 +553,7 @@ static void grfs_handler(u8_t *data, int len) {
|
||||
scroller.first = true;
|
||||
|
||||
// background excludes space taken by visu (if any)
|
||||
scroller.back.width = display_width - ((visu.mode && visu.row < SB_HEIGHT) ? visu.width : 0);
|
||||
scroller.back.width = displayer.width - ((visu.mode && visu.row < SB_HEIGHT) ? visu.width : 0);
|
||||
|
||||
// set scroller steps & beginning
|
||||
if (pkt->direction == 1) {
|
||||
@@ -557,10 +592,14 @@ static void grfg_handler(u8_t *data, int len) {
|
||||
memcpy(scroller.back.frame, data + sizeof(struct grfg_packet), len - sizeof(struct grfg_packet));
|
||||
|
||||
// update display asynchronously (frames are oganized by columns)
|
||||
memcpy(scroller.frame, scroller.back.frame, scroller.back.width * display_height / 8);
|
||||
for (int i = 0; i < scroller.width * display_height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * display_height / 8 + i];
|
||||
display->draw_cbr(scroller.frame, scroller.back.width, display_height);
|
||||
display->update();
|
||||
memcpy(scroller.frame, scroller.back.frame, scroller.back.width * displayer.height / 8);
|
||||
for (int i = 0; i < scroller.width * displayer.height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * displayer.height / 8 + i];
|
||||
|
||||
// can only write if we really own display
|
||||
if (displayer.owned) {
|
||||
display->draw_cbr(scroller.frame, scroller.back.width, displayer.height);
|
||||
display->update();
|
||||
}
|
||||
|
||||
// now we can active scrolling, but only if we are not on a small screen
|
||||
if (!visu.mode || visu.col || visu.row >= SB_HEIGHT) scroller.active = true;
|
||||
@@ -578,6 +617,7 @@ static void grfg_handler(u8_t *data, int len) {
|
||||
* Update visualization bars
|
||||
*/
|
||||
static void visu_update(void) {
|
||||
// no need to protect against no woning the display as we are playing
|
||||
if (pthread_mutex_trylock(&visu_export.mutex)) return;
|
||||
|
||||
// not enough samples
|
||||
@@ -731,6 +771,7 @@ static void visu_handler( u8_t *data, int len) {
|
||||
// give up if not enough space
|
||||
if (visu.bar_width < 0) {
|
||||
visu.mode = VISU_BLANK;
|
||||
LOG_WARN("Not enough room for displaying visu");
|
||||
} else {
|
||||
// de-activate scroller if we are taking main screen
|
||||
if (visu.row < SB_HEIGHT) scroller.active = false;
|
||||
@@ -781,10 +822,10 @@ static void displayer_task(void *args) {
|
||||
|
||||
// do we have more to scroll (scroll.width is the last column from which we havea full zone)
|
||||
if (scroller.by > 0 ? (scroller.scrolled <= scroller.scroll.width) : (scroller.scrolled >= 0)) {
|
||||
memcpy(scroller.frame, scroller.back.frame, scroller.back.width * display_height / 8);
|
||||
for (int i = 0; i < scroller.width * display_height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * display_height / 8 + i];
|
||||
memcpy(scroller.frame, scroller.back.frame, scroller.back.width * displayer.height / 8);
|
||||
for (int i = 0; i < scroller.width * displayer.height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * displayer.height / 8 + i];
|
||||
scroller.scrolled += scroller.by;
|
||||
display->draw_cbr(scroller.frame, scroller.width, display_height);
|
||||
if (displayer.owned) display->draw_cbr(scroller.frame, scroller.width, displayer.height);
|
||||
|
||||
// short sleep & don't need background update
|
||||
scroller.wake = scroller.speed;
|
||||
@@ -813,7 +854,8 @@ static void displayer_task(void *args) {
|
||||
visu.wake = 100;
|
||||
}
|
||||
|
||||
display->update();
|
||||
// need to make sure we own display
|
||||
if (displayer.owned) display->update();
|
||||
|
||||
// release semaphore and sleep what's needed
|
||||
xSemaphoreGive(displayer.mutex);
|
||||
|
||||
@@ -690,46 +690,47 @@ static void slimproto_run() {
|
||||
UNLOCK_D;
|
||||
|
||||
LOCK_O;
|
||||
status.output_full = _buf_used(outputbuf);
|
||||
status.output_size = outputbuf->size;
|
||||
status.frames_played = output.frames_played_dmp;
|
||||
status.current_sample_rate = output.current_sample_rate;
|
||||
status.updated = output.updated;
|
||||
status.device_frames = output.device_frames;
|
||||
|
||||
if (output.track_started) {
|
||||
_sendSTMs = true;
|
||||
output.track_started = false;
|
||||
status.stream_start = output.track_start_time;
|
||||
}
|
||||
if (!output.external) {
|
||||
status.output_full = _buf_used(outputbuf);
|
||||
status.output_size = outputbuf->size;
|
||||
status.frames_played = output.frames_played_dmp;
|
||||
status.current_sample_rate = output.current_sample_rate;
|
||||
status.updated = output.updated;
|
||||
status.device_frames = output.device_frames;
|
||||
|
||||
if (output.track_started) {
|
||||
_sendSTMs = true;
|
||||
output.track_started = false;
|
||||
status.stream_start = output.track_start_time;
|
||||
}
|
||||
#if PORTAUDIO
|
||||
if (output.pa_reopen) {
|
||||
_pa_open();
|
||||
output.pa_reopen = false;
|
||||
}
|
||||
if (output.pa_reopen) {
|
||||
_pa_open();
|
||||
output.pa_reopen = false;
|
||||
}
|
||||
#endif
|
||||
if (_start_output && (output.state == OUTPUT_STOPPED || output.state == OUTPUT_OFF)) {
|
||||
output.state = OUTPUT_BUFFER;
|
||||
}
|
||||
if (!output.external && output.state == OUTPUT_RUNNING && !sentSTMu && status.output_full == 0 && status.stream_state <= DISCONNECT &&
|
||||
_decode_state == DECODE_STOPPED) {
|
||||
if (_start_output && (output.state == OUTPUT_STOPPED || output.state == OUTPUT_OFF)) {
|
||||
output.state = OUTPUT_BUFFER;
|
||||
}
|
||||
if (output.state == OUTPUT_RUNNING && !sentSTMu && status.output_full == 0 && status.stream_state <= DISCONNECT &&
|
||||
_decode_state == DECODE_STOPPED) {
|
||||
|
||||
_sendSTMu = true;
|
||||
sentSTMu = true;
|
||||
LOG_DEBUG("output underrun");
|
||||
output.state = OUTPUT_STOPPED;
|
||||
output.stop_time = now;
|
||||
}
|
||||
if (output.state == OUTPUT_RUNNING && !sentSTMo && status.output_full == 0 && status.stream_state == STREAMING_HTTP) {
|
||||
|
||||
_sendSTMo = true;
|
||||
sentSTMo = true;
|
||||
}
|
||||
_sendSTMu = true;
|
||||
sentSTMu = true;
|
||||
LOG_DEBUG("output underrun");
|
||||
output.state = OUTPUT_STOPPED;
|
||||
output.stop_time = now;
|
||||
}
|
||||
if (output.state == OUTPUT_RUNNING && !sentSTMo && status.output_full == 0 && status.stream_state == STREAMING_HTTP) {
|
||||
_sendSTMo = true;
|
||||
sentSTMo = true;
|
||||
}
|
||||
}
|
||||
if (output.state == OUTPUT_STOPPED && output.idle_to && (now - output.stop_time > output.idle_to)) {
|
||||
output.state = OUTPUT_OFF;
|
||||
LOG_DEBUG("output timeout");
|
||||
}
|
||||
if (!output.external && output.state == OUTPUT_RUNNING && now - status.last > 1000) {
|
||||
}
|
||||
if (output.state == OUTPUT_RUNNING && now - status.last > 1000) {
|
||||
_sendSTMt = true;
|
||||
status.last = now;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user