ESP8266Audio icon indicating copy to clipboard operation
ESP8266Audio copied to clipboard

Lot of disconnects and mp3 errors in AudioFileSourceICYStream

Open pe0fko opened this issue 3 years ago • 0 comments

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

pe0fko avatar Oct 20 '22 13:10 pe0fko