player_queue_099

This commit is contained in:
e2002
2023-03-16 17:55:06 +03:00
parent 563770a825
commit cc874054b6
19 changed files with 90 additions and 58 deletions

View File

@@ -95,7 +95,7 @@ static uint32_t _closed_index = []() {
static inline bool _init_async_event_queue(){
if(!_async_queue){
_async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));
_async_queue = xQueueCreate(XQUEUE_SIZE, sizeof(lwip_event_packet_t *));
if(!_async_queue){
return false;
}

View File

@@ -32,12 +32,21 @@ extern "C" {
//If core is not defined, then we are running in Arduino or PIO
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 //any available core
#define CONFIG_ASYNC_TCP_USE_WDT 1 //if enabled, adds between 33us and 200us per event
#define CONFIG_ASYNC_TCP_RUNNING_CORE 0 //any available core (-1)
#endif
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
#define CONFIG_ASYNC_TCP_USE_WDT 0 //if enabled, adds between 33us and 200us per event (1)
#endif
#ifndef XTASK_MEM_SIZE
#define XTASK_MEM_SIZE 8192 / 2
#endif
#ifndef XQUEUE_SIZE
#define XQUEUE_SIZE 128 // (32)
#endif
class AsyncClient;
#define ASYNC_MAX_ACK_TIME 5000

View File

@@ -736,7 +736,7 @@ uint16_t AsyncMqttClient::unsubscribe(const char* topic) {
}
uint16_t AsyncMqttClient::publish(const char* topic, uint8_t qos, bool retain, const char* payload, size_t length, bool dup, uint16_t message_id) {
if (_state != CONNECTED || GET_FREE_MEMORY() < MQTT_MIN_FREE_MEMORY) return 0;
if (_state != CONNECTED/* || GET_FREE_MEMORY() < MQTT_MIN_FREE_MEMORY*/) return 0;
log_i("PUBLISH");
AsyncMqttClientInternals::OutPacket* msg = new AsyncMqttClientInternals::PublishOutPacket(topic, qos, retain, payload, length);

View File

@@ -22,6 +22,9 @@ fs::SDFATFS SD_SDFAT;
#ifndef DMA_BUFCOUNT
#define DMA_BUFCOUNT 8
#endif
#ifndef DMA_BUFLEN
#define DMA_BUFLEN 512 // (512)
#endif
//---------------------------------------------------------------------------------------------------------------------
AudioBuffer::AudioBuffer(size_t maxBlockSize) {
// if maxBlockSize isn't set use defaultspace (1600 bytes) is enough for aac and mp3 player
@@ -182,7 +185,7 @@ Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_DAC
#else
m_i2s_config.dma_buf_count = psramInit()?16:DMA_BUFCOUNT;
#endif
m_i2s_config.dma_buf_len = 512;
m_i2s_config.dma_buf_len = psramInit()?512:DMA_BUFLEN;
m_i2s_config.use_apll = APLL_DISABLE; // must be disabled in V2.0.1-RC1
m_i2s_config.tx_desc_auto_clear = true; // new in V1.0.1
m_i2s_config.fixed_mclk = I2S_PIN_NO_CHANGE;
@@ -374,6 +377,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
if(host == NULL) {
AUDIO_INFO("Hostaddress is empty");
if(audio_error) audio_error("Hostaddress is empty");
return false;
}
@@ -381,6 +385,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
if(lenHost >= 512 - 10) {
AUDIO_INFO("Hostaddress is too long");
if(audio_error) audio_error("Hostaddress is too long");
return false;
}
@@ -463,7 +468,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
strcat(rqh, "User-Agent: Mozilla/5.0\r\n");
strcat(rqh, "Connection: keep-alive\r\n\r\n");
if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH >= 3){
if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH >= 3 && MAX_AUDIO_SOCKET_TIMEOUT){
m_timeout_ms_ssl = UINT16_MAX; // bug in v2.0.3 if hostwoext is a IPaddr not a name
m_timeout_ms = UINT16_MAX; // [WiFiClient.cpp:253] connect(): select returned due to timeout 250 ms for fd 48
}
@@ -503,6 +508,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
}
else{
AUDIO_INFO("Request %s failed!", l_host);
AUDIO_ERROR("Request %s failed!", l_host);
if(audio_showstation) audio_showstation("");
if(audio_showstreamtitle) audio_showstreamtitle("");
if(audio_icydescription) audio_icydescription("");
@@ -722,8 +728,10 @@ cardLock(false);
if(endsWith(afn, ".wav")) m_codec = CODEC_WAV;
if(endsWith(afn, ".flac")) m_codec = CODEC_FLAC;
if(m_codec == CODEC_NONE) AUDIO_INFO("The %s format is not supported", afn + dotPos);
if(m_codec == CODEC_NONE) {
AUDIO_INFO("The %s format is not supported", afn + dotPos);
AUDIO_ERROR("The %s format is not supported", afn + dotPos);
}
if(afn) {free(afn); afn = NULL;}
bool ret = initializeDecoder();
@@ -3807,6 +3815,7 @@ bool Audio:: initializeDecoder(){
case CODEC_OGG:
m_codec = CODEC_OGG;
AUDIO_INFO("ogg not supported");
AUDIO_ERROR("ogg not supported");
goto exit;
break;
default:
@@ -3919,6 +3928,7 @@ bool Audio::parseContentType(char* ct) {
else if(ct_val == CT_NONE){
AUDIO_INFO("ContentType %s not supported", ct);
AUDIO_ERROR("ContentType %s not supported", ct);
return false; // nothing valid had been seen
}
else {;}

View File

@@ -90,9 +90,10 @@ extern __attribute__((weak)) void audio_eof_speech(const char*);
extern __attribute__((weak)) void audio_eof_stream(const char*); // The webstream comes to an end
extern __attribute__((weak)) void audio_process_extern(int16_t* buff, uint16_t len, bool *continueI2S); // record audiodata or send via BT
extern __attribute__((weak)) void audio_progress(uint32_t startpos, uint32_t endpos);
extern __attribute__((weak)) void audio_error(const char*);
#define AUDIO_INFO(...) {char buff[512 + 64]; sprintf(buff,__VA_ARGS__); if(audio_info) audio_info(buff);}
#define AUDIO_ERROR(...) {char buff[512 + 64]; sprintf(buff,__VA_ARGS__); if(audio_error) audio_error(buff);}
//----------------------------------------------------------------------------------------------------------------------
class AudioBuffer {

View File

@@ -1520,6 +1520,7 @@ bool Audio::parseContentType(char* ct) {
else if(ct_val == CT_NONE){
AUDIO_INFO("ContentType %s not supported", ct);
AUDIO_ERROR("ContentType %s not supported", ct);
return false; // nothing valid had been seen
}
else {;}
@@ -1701,6 +1702,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
if(host == NULL) {
AUDIO_INFO("Hostaddress is empty");
if(audio_error) audio_error("Hostaddress is empty");
return false;
}
@@ -1708,6 +1710,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
if(lenHost >= 512 - 10) {
AUDIO_INFO("Hostaddress is too long");
if(audio_error) audio_error("Hostaddress is too long");
return false;
}
@@ -1790,7 +1793,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
strcat(rqh, "User-Agent: Mozilla/5.0\r\n");
strcat(rqh, "Connection: keep-alive\r\n\r\n");
if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH >= 3){
if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH >= 3 && MAX_AUDIO_SOCKET_TIMEOUT){
m_timeout_ms_ssl = UINT16_MAX; // bug in v2.0.3 if hostwoext is a IPaddr not a name
m_timeout_ms = UINT16_MAX; // [WiFiClient.cpp:253] connect(): select returned due to timeout 250 ms for fd 48
}
@@ -1832,6 +1835,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
}
else{
AUDIO_INFO("Request %s failed!", l_host);
AUDIO_ERROR("Request %s failed!", l_host);
if(audio_showstation) audio_showstation("");
if(audio_showstreamtitle) audio_showstreamtitle("");
if(audio_icydescription) audio_icydescription("");
@@ -1994,6 +1998,7 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) {
sprintf(chbuf, "The %s format is not supported", afn + dotPos);
if(audio_info) audio_info(chbuf);
if(audio_error) audio_error(chbuf);
cardLock(true); audiofile.close(); cardLock(false);
if(afn) free(afn);
return false;

View File

@@ -50,8 +50,10 @@ extern __attribute__((weak)) void audio_icydescription(const char*);
extern __attribute__((weak)) void audio_lasthost(const char*);
extern __attribute__((weak)) void audio_eof_stream(const char*); // The webstream comes to an end
extern __attribute__((weak)) void audio_progress(uint32_t start, uint32_t durarion);
extern __attribute__((weak)) void audio_error(const char*);
#define AUDIO_INFO(...) {char buff[512 + 64]; sprintf(buff,__VA_ARGS__); if(audio_info) audio_info(buff);}
#define AUDIO_ERROR(...) {char buff[512 + 64]; sprintf(buff,__VA_ARGS__); if(audio_error) audio_error(buff);}
//----------------------------------------------------------------------------------------------------------------------

View File

@@ -345,7 +345,7 @@ void Display::_layoutChange(bool played){
}
}
#ifndef DSP_QUEUE_TICKS
#define DSP_QUEUE_TICKS 8
#define DSP_QUEUE_TICKS 0
#endif
void Display::loop() {
if(_bootStep==0) {
@@ -483,9 +483,12 @@ void Display::_title() {
}
void Display::_time(bool redraw) {
#if LIGHT_SENSOR!=255
if(config.store.dspon) {
config.store.brightness = AUTOBACKLIGHT(analogRead(LIGHT_SENSOR));
config.setBrightness();
}
#endif
_clock.draw();
/*#ifdef USE_NEXTION

View File

@@ -187,7 +187,7 @@ void NetServer::chunkedHtmlPage(const String& contentType, AsyncWebServerRequest
#endif
#ifndef NS_QUEUE_TICKS
#define NS_QUEUE_TICKS 2
#define NS_QUEUE_TICKS 0
#endif
char wsbuf[BUFLEN * 2];

View File

@@ -1,7 +1,7 @@
#ifndef options_h
#define options_h
#define YOVERSION "0.9.090"
#define YOVERSION "0.9.099"
/*******************************************************
DO NOT EDIT THIS FILE.
@@ -299,6 +299,9 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
#ifndef CLOCKFONT_MONO
#define CLOCKFONT_MONO true // monospace clock font
#endif
#ifndef MAX_AUDIO_SOCKET_TIMEOUT
#define MAX_AUDIO_SOCKET_TIMEOUT false // max audio socket timeout?
#endif
/*
*** ST7735 display submodel ***
INITR_BLACKTAB // 1.8' https://aliexpress.ru/item/1005002822797745.html

View File

@@ -63,6 +63,7 @@ void Player::init() {
forceMono(true);
#endif
_loadVol(config.store.volume);
setConnectionTimeout(1700, 3700);
Serial.println("done");
}
@@ -78,7 +79,7 @@ void Player::stopInfo() {
requestToStart = true;
}
void Player::_stop(){
void Player::_stop(bool alreadyStopped){
if(config.store.play_mode==PM_SDCARD) config.sdResumePos = player.getFilePos();
_status = STOPPED;
setOutputPins(false);
@@ -90,10 +91,8 @@ void Player::_stop(){
netserver.requestOnChange(BITRATE, 0);
display.putRequest(DBITRATE);
display.putRequest(PSTOP);
#ifdef CLEAR_BUFFERS
setDefaults();
#endif
stopSong();
if(!alreadyStopped) stopSong();
stopInfo();
if (player_on_stop_play) player_on_stop_play();
}
@@ -108,7 +107,7 @@ void Player::initHeaders(const char *file) {
}
#ifndef PL_QUEUE_TICKS
#define PL_QUEUE_TICKS 2
#define PL_QUEUE_TICKS 0
#endif
void Player::loop() {
@@ -136,7 +135,7 @@ void Player::loop() {
xSemaphoreTake(playmutex, portMAX_DELAY);
Audio::loop();
xSemaphoreGive(playmutex);
if(!isRunning() && _status==PLAYING) _stop(true);
if(_volTimer){
if((millis()-_volTicks)>3000){
config.saveVolume();
@@ -166,10 +165,12 @@ void Player::_play(uint16_t stationId) {
_loadVol(config.store.volume);
display.putRequest(NEWSTATION);
netserver.requestOnChange(STATION, 0);
netserver.loop();
netserver.loop();
if (config.store.play_mode==PM_WEB?connecttohost(config.station.url):connecttoFS(SD,config.station.url,config.sdResumePos==0?_resumeFilePos:config.sdResumePos-player.sd_min)) {
_status = PLAYING;
if(config.store.play_mode==PM_SDCARD) config.sdResumePos = 0;
config.setTitle("");
//config.setTitle("");
config.setSmartStart(1);
netserver.requestOnChange(MODE, 0);
setOutputPins(true);
@@ -178,6 +179,7 @@ void Player::_play(uint16_t stationId) {
if (player_on_start_play) player_on_start_play();
}else{
telnet.printf("##ERROR#:\tError connecting to %s\n", config.station.url);
_stop(true);
};
}
@@ -200,6 +202,7 @@ void Player::browseUrl(){
if (player_on_start_play) player_on_start_play();
}else{
telnet.printf("##ERROR#:\tError connecting to %s\n", burl);
_stop(true);
}
memset(burl, 0, MQTT_BURL_SIZE);
}

View File

@@ -28,7 +28,7 @@ class Player: public Audio {
uint32_t _resumeFilePos;
plStatus_e _status;
private:
void _stop();
void _stop(bool alreadyStopped = false);
void _play(uint16_t stationId);
void _loadVol(uint8_t volume);
public:

View File

@@ -124,7 +124,8 @@ void Telnet::printf(const char *format, ...) {
clients[id].print(buf);
}
}
if(strstr(buf,"> ")==NULL) Serial.print(buf);
if (strcmp(buf, "> ") == 0) return;
if(strstr(buf,"\n> ")==NULL) Serial.print(buf);
}
void Telnet::printf(byte id, const char *format, ...) {

View File

@@ -49,7 +49,7 @@ const WidgetConfig bootWdtConf PROGMEM = { 0, 216, 1, WA_CENTER };
const ProgressConfig bootPrgConf PROGMEM = { 90, 14, 4 };
/* BANDS */ /* { onebandwidth, onebandheight, bandsHspace, bandsVspace, numofbands, fadespeed } */
const VUBandsConfig bandsConf PROGMEM = { 32, 130, 4, 2, 10, 6 };
const VUBandsConfig bandsConf PROGMEM = { 32, 130, 4, 2, 10, 3 };
/* STRINGS */
const char numtxtFmt[] PROGMEM = "%d";

View File

@@ -20,7 +20,7 @@ typedef GFXcanvas16 Canvas;
#include "widgets/widgets.h"
#include "widgets/pages.h"
#if __has_include("conf/displayST7796conf_custom.h")
#if __has_include("conf/displayILI9488conf_custom.h")
#include "conf/displayILI9488conf_custom.h"
#else
#include "conf/displayILI9488conf.h"

View File

@@ -1,5 +1,5 @@
#ifndef displaySSD1305_h
#define displaySSD1305_h
#ifndef displaySSD1322_h
#define displaySSD1322_h
#include "../core/options.h"
#include "Arduino.h"
@@ -22,7 +22,7 @@ typedef GFXcanvas1 Canvas;
#include "widgets/widgets.h"
#include "widgets/pages.h"
#if __has_include("conf/displaySSD1305conf_custom.h")
#if __has_include("conf/displaySSD1322conf_custom.h")
#include "conf/displaySSD1322conf_custom.h"
#else
#include "conf/displaySSD1322conf.h"

View File

@@ -1,5 +1,5 @@
#ifndef displayST7789_h
#define displayST7789_h
#ifndef displayST7796_h
#define displayST7796_h
#include "../core/options.h"
#include "Arduino.h"

View File

@@ -1,5 +1,5 @@
#ifndef displaySSD1305_h
#define displaySSD1305_h
#ifndef displayST7920_h
#define displayST7920_h
#include "../core/options.h"
#include "Arduino.h"

View File

@@ -100,10 +100,8 @@ void audio_info(const char *info) {
nextion.audioinfo(info);
#endif
if (strstr(info, "skip metadata") != NULL) config.setTitle(config.station.name);
if (strstr(info, "failed!") != NULL || strstr(info, "address is empty") != NULL || strstr(info, "not supported") != NULL || strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) {
//config.setTitle(info);
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) {
telnet.printf("##ERROR#:\t%s\n", info);
player.sendCommand({PR_STOP, 0});
}
char* ici; char b[20]={0};
if ((ici = strstr(info, "BitRate: ")) != NULL) {
@@ -134,8 +132,7 @@ bool printable(const char *info) {
}
void audio_showstation(const char *info) {
if (strlen(info) > 0) {
bool p = printable(info);
bool p = printable(info) && (strlen(info) > 0);
config.setTitle(p?info:config.station.name);
if(player.remoteStationName){
config.setStation(p?info:config.station.name);
@@ -143,31 +140,29 @@ void audio_showstation(const char *info) {
netserver.requestOnChange(STATION, 0);
}
}
}
void audio_showstreamtitle(const char *info) {
DBGH();
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL){
//config.setTitle(info);
telnet.printf("##ERROR#:\t%s\n", info);
player.sendCommand({PR_STOP, 0});
return;
}
if (strlen(info) > 0) {
bool p = printable(info);
bool p = printable(info) && (strlen(info) > 0);
#ifdef DEBUG_TITLES
config.setTitle(DEBUG_TITLES);
#else
config.setTitle(p?info:config.station.name);
#endif
}
void audio_error(const char *info) {
config.setTitle(info);
telnet.printf("##ERROR#:\t%s\n", info);
}
void audio_id3artist(const char *info){
if(printable(info)) config.setStation(info);
display.putRequest(NEWSTATION);
netserver.requestOnChange(STATION, 0);
}
void audio_id3album(const char *info){