-
Notifications
You must be signed in to change notification settings - Fork 437
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
Adding support for Tranfer-Encoding: chunked streams #394
base: master
Are you sure you want to change the base?
Conversation
Hi @earlephilhower , did have the chance having a look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Sorry for the delay, I've been quite busy this past week. A few changes would make it a very good addition, I think!
@@ -52,14 +56,42 @@ class AudioFileSourceHTTPStream : public AudioFileSource | |||
enum { STATUS_HTTPFAIL=2, STATUS_DISCONNECTED, STATUS_RECONNECTING, STATUS_RECONNECTED, STATUS_NODATA }; | |||
|
|||
private: | |||
virtual uint32_t readInternal(void *data, uint32_t len, bool nonBlock); | |||
bool is_chunked; | |||
std::size_t next_chunk; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the reason for std::size_t
vs. the well-known stdint.h size_t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really matter?
WiFiClient client; | ||
HTTPClient http; | ||
int pos; | ||
int size; | ||
int reconnectTries; | ||
int reconnectDelayMs; | ||
char saveURL[128]; | ||
uint32_t (AudioFileSourceHTTPStream::*readImpl)(void *data, uint32_t len, bool nonBlock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the AudioFileSourceHTTPStream::
is superfluous here. We're already in class AudioFileSourceHTTPStream
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've checked, this is how it can be used. You're welcomed to further check it yourself.
142f036
to
a6bd1c6
Compare
Hi @earlephilhower, fixed all needed to be fixed, please review |
@yoav-klein Thanks for providing the improvement. Just report 2 bugs I found:
after some tweak, here is my improvement. No loop in the function.
|
And here are my functional AudioFileSourceICYStream, it can deal with both chunked or regular stream. |
@DeqingSun i tested your code on ESP8266, it works but cuts off the end of the word |
HI @DeqingSun , thanks for the improvement! I actually also experiencing some hiccups and also restarts every now and then. When I say now and then I mean it could go smooth for hours, but there are times that it's more frequent. I didn't get the chance to look deeply into why exactly this happens, but maybe it has something to do with what you're pointing at. Although I find it hard to believe. It's not fresh in my memory, but as far as I remember, the reads in the original code are only one MP3 frame at a time, so how did you get to a point where the And I'll be pleased to know that - how do you know what function causes a reset? Would love if you could share with me some debugging skills so I could understand why I get all these hiccups and restarts. |
HI @yoav-klein, For exceptions reset, ESP will print a Backtrace in 115200. And such info can be decoded by EspExceptionDecoder. However, it can not give useful info when you forget you return a value in function, WDT reset etc. What I did was adding tons of print in every suspicious function, on the entry and exit part, and any point I feel suspicious. Also the print can carry info of the parameters and variables. With a lot of prints, you can see how the code flows, and see where it stuck. If your code runs for hours before a bug, it might be helpful to get a serial logger like this one. I always want to get one but never get a chance to debug such a bug. For the 16K problem, I think the read function in AudioFileSourceBuffer will try to fill the buffer in the first read. My code may break the read casually and return a significantly shorter response and may cause a longer delay at the beginning. |
@sh-user The key to solve the problem is to load the data as much as possible at the beginning and stop when the data stream stops. So some change to the read, the getChunkSize, needs to be done. Try this version and use the AudioFileSourceICYStream class |
checked, there is no longer a big delay after playback, but the last word is cut off. I noticed that if you send the text longer, then everything works fine |
@sh-user I tested on ESP32 with 16K buffer. That might be a reason. |
Included changes from yoav-klein and DeqingSun to manage correctly Google TTS. See here for details : earlephilhower#394
Resolve Google TTS problems thanks to adding support for "Tranfer-Encoding: chunked streams" Included changes from yoav-klein and DeqingSun to manage correctly Google TTS. See here for details : earlephilhower/ESP8266Audio#394
I confirm this behavior with Google TTS :
Still a lot better than before (with the current dev version it hangs during few minutes!) |
@yoav-klein Another thing worth improving: The getChunkSize() using readStringUntil which is blocking. In the following case it may corrupt a lot of data.
When they all happens, the getChunkSize() may takes a long time to respond, and it will create a lot of hiccup and eventually kill the stream. I'll see if I can improve it. |
Thank you @DeqingSun, your version seems to runs really well. I modified it to support https (through |
Hi @rebane2001 , Will your support for HTTPS will also work on ESP8266? |
I'm not sure as I don't have an ESP8266 to test on, but you can see what I did in #628 if you want to try it yourself. |
@rebane2001 , can I pull your code from somewhere? Additionally, on what version of @DeqingSun were you talking about? Can you share the unified versions? |
I used the version initially posted ( Fyi I've only tested/used this for http, not icy. |
minor: add CMakeLists.txt for usage in ESP-idf; code changes to pass the compile most changes from earlephilhower#394 (comment) by @DeqingSun
thanks |
Howdy Earl !
I first started using your great library just a while ago. I wanted to have a ESP8266 as a Radio player in my home since my radio reception in my home is not that good. So I did all the setup, but then I always got the
lost synchronization..
error.First googling, all I could find is "Try encrementing your buffer size", with no help.
After some research, I realized that the stream of my favorite radio station is using a
Transfer-Encoding: chunked
, and that what caused the loss of synchronization.So I pulled up my sleeves and added support in the
AudioFileSourceHTTPStream
class to chunked Transfer-Encoding.This could be also implemented in the ICY class as well, but for me it wasn't all that important and all the ICY thing was quite complex, so I didn't get to it.
Hope it will solve some other folks' same problem as well.
This is the radio stream I'm using if you want to check it out.
http://kanliveicy.media.kan.org.il/icy/749624_mp3