earlephilhower / ESP8266Audio

Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.03k stars 432 forks source link

Lot of disconnects and mp3 errors in AudioFileSourceICYStream #577

Open pe0fko opened 1 year ago

pe0fko commented 1 year ago

Hi there,

I did get a lot of disconnects and reconnects on slow ICY servers in the AudioFileSourceICYStream class. Found the problem in readInternal(...) function, when there is no data available (in blocking mode) in the stream the code will do a retry. Only, in the retry loop, it call's http.end() to disconnect the stream, that is not OK, keep the stream open and retry will work...

  size_t avail = stream->available();
  if (!nonBlock && !avail) {
    cb.st(STATUS_NODATA, PSTR("No stream data available"));
// Wrong, don't terminate the stream when there is no data yet!
//    http.end();
    goto retry;
  }

Also add some more ICY header tokens, like it:

AudioFileSourceICYStream.cpp.diff 
47c47
<   static const char *hdr[] = { "icy-metaint", "icy-name", "icy-genre", "icy-br" };
---
>   static const char *hdr[] = { "icy-metaint", "icy-name", "icy-genre", "icy-br", "icy-description", "icy-url" };
51c51
<   http.collectHeaders( hdr, 4 );
---
>   http.collectHeaders( hdr, 6 );
68c68
< //    cb.md("SiteName", false, ret.c_str());
---
>     cb.md("SiteName", false, ret.c_str());
72c72
< //    cb.md("Genre", false, ret.c_str());
---
>     cb.md("Genre", false, ret.c_str());
76c76,84
< //    cb.md("Bitrate", false, ret.c_str());
---
>     cb.md("Bitrate", false, ret.c_str());
>   }
>   if (http.hasHeader(hdr[4])) {
>     String ret = http.header(hdr[4]);
>     cb.md("Description", false, ret.c_str());
>   }
>   if (http.hasHeader(hdr[5])) {
>     String ret = http.header(hdr[5]);
>     cb.md("URL", false, ret.c_str());
131c139,140
<     http.end();
---
> // Wrong, don't terminate the stream when there is no data yet!
> //    http.end();

73