Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2S bugfix: webradio crash with invalid url #21446

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/lib_audio/ESP8266Audio/src/AudioFileSourceICYStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio_idf51.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
25 changes: 13 additions & 12 deletions tasmota/tasmota_xdrv_driver/xdrv_42_7_i2s_webradio_idf51.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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"));
Expand All @@ -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);
Expand Down