bugfix: webradio crash with invalid url (#21446)

This commit is contained in:
Christian Baars 2024-05-20 09:12:14 +02:00 committed by GitHub
parent 62af6f3a7c
commit e7f69ebc5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 19 deletions

View File

@ -45,17 +45,15 @@ bool AudioFileSourceICYStream::open(const char *url)
{
static const char *hdr[] = { "icy-metaint", "icy-name", "icy-genre", "icy-br" };
pos = 0;
http.begin(client, url);
if (!http.begin(client, url)) {
cb.st(STATUS_HTTPFAIL, PSTR("Can't connect to url"));
return false;
}
http.addHeader("Icy-MetaData", "1");
http.collectHeaders( hdr, 4 );
http.setReuse(true);
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
int code = http.GET();
if (code != HTTP_CODE_OK) {
http.end();
cb.st(STATUS_HTTPFAIL, PSTR("Can't open HTTP request"));
return false;
}
if (http.hasHeader(hdr[0])) {
String ret = http.header(hdr[0]);
icyMetaInt = ret.toInt();

View File

@ -847,7 +847,6 @@ void I2sMp3WrTask(void *arg){
if (audio_i2s_mp3.decoder && audio_i2s_mp3.decoder->isRunning()) {
if (!audio_i2s_mp3.decoder->loop()) {
audio_i2s_mp3.task_running = false;
//retryms = millis() + 2000;
}
vTaskDelay(pdMS_TO_TICKS(1));
}

View File

@ -27,7 +27,6 @@ struct AUDIO_I2S_WEBRADIO_t {
char wr_title[64];
void *preallocateBuffer = NULL;
void *preallocateCodec = NULL;
uint32_t retryms = 0;
} Audio_webradio;
void I2sMDCallback(void *cbData, const char *type, bool isUnicode, const char *str) {
@ -43,6 +42,10 @@ void I2sMDCallback(void *cbData, const char *type, bool isUnicode, const char *s
}
}
void I2SWrStatusCB(void *cbData, int code, const char *str){
AddLog(LOG_LEVEL_INFO, "I2S: status: %s",str);
}
void Webradio(const char *url) {
// allocate buffers if not already done
if (Audio_webradio.preallocateBuffer == NULL) {
@ -65,21 +68,22 @@ void Webradio(const char *url) {
return;
}
// if (audio_i2s_mp3.decoder || audio_i2s_mp3.mp3) return;
if (!audio_i2s.out) return;
I2SAudioPower(true);
Audio_webradio.ifile = new AudioFileSourceICYStream(url);
Audio_webradio.ifile = new AudioFileSourceICYStream();
Audio_webradio.ifile->RegisterMetadataCB(I2sMDCallback, NULL);
Audio_webradio.ifile->RegisterStatusCB(I2SWrStatusCB, NULL);
if(!Audio_webradio.ifile->open(url)){
I2sWebRadioStopPlaying();
return;
}
I2SAudioPower(true);
Audio_webradio.buff = new AudioFileSourceBuffer(Audio_webradio.ifile, Audio_webradio.preallocateBuffer, preallocateBufferSize);
Audio_webradio.buff->RegisterStatusCB(I2sStatusCallback, NULL);
audio_i2s_mp3.decoder = new AudioGeneratorMP3(Audio_webradio.preallocateCodec, preallocateCodecSize);
audio_i2s_mp3.decoder->RegisterStatusCB(I2sStatusCallback, NULL);
audio_i2s_mp3.decoder->begin(Audio_webradio.buff, audio_i2s.out);
if (!audio_i2s_mp3.decoder->isRunning()) {
// Serial.printf_P(PSTR("Can't connect to URL"));
I2sStopPlaying();
// strcpy_P(status, PSTR("Unable to connect to URL"));
Audio_webradio.retryms = millis() + 2000;
}
AddLog(LOG_LEVEL_DEBUG,PSTR("I2S: will launch webradio task"));
@ -102,11 +106,8 @@ void I2sWrShow(bool json) {
#endif // USE_WEBSERVER
void CmndI2SWebRadio(void) {
if (!audio_i2s.out) return;
if (I2SPrepareTx() != I2S_OK) return;
if (audio_i2s_mp3.decoder) {
I2sStopPlaying();
}
if (XdrvMailbox.data_len > 0) {
Webradio(XdrvMailbox.data);
ResponseCmndChar(XdrvMailbox.data);