Because we are allocating objects totaling over 80% of the ESP8266 memory
space, we are very sensitive to memory fragmentation. While we can control
our own allocs, the IP and SDK can allocate any size, at any time, which
can cause us to not be able to find the large contiguous memory areas we need
for the codes.
Work around this by preallocating, before anything else, buffer memory and
never freeing it. Pass this memory into the codec and it will allocate from
this block and be guaranteed to always succeed.
This may fix the last of the hangs on the webradio/http streaming, which only
seemed to happen after a stop/start cycle.
Check for NULL input data buffers and set values to NULL after freeing()
local variables to avoid memory corruption on use-after-freee.
Add lots of error injection in the host testing to help find bugs on
the PC where they're easier to debug.
All objects can have a metadata and/or status report callback once created.
They will call the source program with the parsed ID3 tag, ICY StreamTitle,
or text and numeric error ID of any interesting event. It is up to the end
application to figure out what to do with this. Normally, you'd just print
it to the LCD or Serial port. But it is possible to detect, say, a buffer
overflow and then switch to a lower bitrate stream for example.
Add a subclass of the HTTPStream that can extract the ICY metadata.
Needs to implement a callback function or parse it internally and expose
a class variable to let the UI see the current stream information.
The buffer class seems to work very well to avoid hiccups while
streaming from the web, so add it by default to the example to
make it easier for users to cut-n-paste and make it work.
AudioFileSourceBuffer allows system RAM to be used to buffer an
input file (normally just a HTTP Stream) to help avoid hiccups.
This could also be subclassed to use an external SRAM, at some
soint.
HTTPStreamer assumed the server would drop the connection when no more
data was available to be transferred from the source file.
For individual files, though, the web server will send the expected length
in the headers and leave the connection open (i.e. to recycle the connection
and accelerate web browsing). In this case, the streamer would effectively
hang waiting for more data than was being transmitted.
Now check the read data against the expected data, and also add a 0.5s
timeout no matter what to the reading.
Tested on streaming and served files, seems to work fine.
Implements a simple and stupid HTTP stream reader to allow for ShoutCast
and other MP3 radio streaming to happen. Presently seems to stutter on
128K, 44.1KHz streams, but may be better on lower bitrates.