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.07k stars 439 forks source link

Decoding error 0x0235 (bad main_data_begin pointer) at byte offset #9

Closed gerardwr closed 7 years ago

gerardwr commented 7 years ago

This looks like an excellent library to stream internet-radio.

The StreamMP3FromHTTP sketch compiles (Arduino 1.8.1 and ESP8266 2.3.0), but with dozens of "red" warnings.

Upload to a Wemos D1 Mini (160Mhz)results in the errors below.

Any suggestions what to do?

�:�������a�����aV������qEc��S�aEc�i...Connecting to WiFi
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 0
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 418
Decoding error 0x0101 (lost synchronization) at byte offset 57774
Decoding error 0x0104 (reserved sample frequency value) at byte offset 58011
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 58097
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 58515
Decoding error 0x0101 (lost synchronization) at byte offset 108874
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 109088
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 109506
Decoding error 0x0101 (lost synchronization) at byte offset 161434
Decoding error 0x0101 (lost synchronization) at byte offset 161467
Decoding error 0x0104 (reserved sample frequency value) at byte offset 161647
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 161751
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 162169
Decoding error 0x0101 (lost synchronization) at byte offset 209614
Decoding error 0x0104 (reserved sample frequency value) at byte offset 209700
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 209816
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 210234
Decoding error 0x0101 (lost synchronization) at byte offset 298674
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 298841
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 299259
Decoding error 0x0101 (lost synchronization) at byte offset 336215
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 336875
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 337293
Decoding error 0x0101 (lost synchronization) at byte offset 380434
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 380761
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 381179
Decoding error 0x0101 (lost synchronization) at byte offset 422774
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 422975
Decoding error 0x0101 (lost synchronization) at byte offset 440918
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 441783
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 442201
Decoding error 0x0101 (lost synchronization) at byte offset 638854
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 639060
gerardwr commented 7 years ago

Yep, it's on 160Mhz.

gerardwr commented 7 years ago

And tried 3 different ESP8266 modules, just to make sure.

armSeb commented 7 years ago

Strange. It seems something corrupts the mp3 stream.

armSeb commented 7 years ago

Maybe a wifi connection Issue ? Are you far from your box/router ? It may have many people on the same wifi channel.

gerardwr commented 7 years ago

Distance between ESP and router is 3 meters, so that's not likely to be the problem.

Connected my desktop to my wifi router and pinged, no obvious issue there


64 bytes from 192.168.0.2: icmp_seq=21 ttl=64 time=0.584 ms
64 bytes from 192.168.0.2: icmp_seq=22 ttl=64 time=0.606 ms
64 bytes from 192.168.0.2: icmp_seq=23 ttl=64 time=1.053 ms
64 bytes from 192.168.0.2: icmp_seq=24 ttl=64 time=0.603 ms
64 bytes from 192.168.0.2: icmp_seq=25 ttl=64 time=0.599 ms
64 bytes from 192.168.0.2: icmp_seq=26 ttl=64 time=0.570 ms
64 bytes from 192.168.0.2: icmp_seq=27 ttl=64 time=0.564 ms
64 bytes from 192.168.0.2: icmp_seq=28 ttl=64 time=0.595 ms
64 bytes from 192.168.0.2: icmp_seq=29 ttl=64 time=0.598 ms
64 bytes from 192.168.0.2: icmp_seq=30 ttl=64 time=1.431 ms
64 bytes from 192.168.0.2: icmp_seq=31 ttl=64 time=1.416 ms
64 bytes from 192.168.0.2: icmp_seq=32 ttl=64 time=1.389 ms
armSeb commented 7 years ago

Can you add this snippet in your setup routine:

Serial.println(ESP.getFreeHeap());

Can you show me your sketch (without wifi credentials) ?

armSeb commented 7 years ago

Here is my sketch:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "AudioFileSourceHTTPStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SDAC.h"
#include <WiFiManager.h>

// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.

const char PROGMEM *URL="http://stream.morow.com:8000/morow.mp3";

AudioGeneratorMP3 *mp3;
AudioFileSourceHTTPStream *file;
AudioFileSourceBuffer *buf;
AudioOutputI2SDAC *out;

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("Connecting to WiFi");
  WiFiManager wifiManager;
  wifiManager.autoConnect("WebRadioSeb");

  startPlayer(URL);

  Serial.println(ESP.getFreeHeap());

}

void loop()
{
  if (mp3->isRunning()) {
    if (!mp3->loop()) mp3->stop();
  } else {
    Serial.println("MP3 done");
    delay(1000);
  }
}

void startPlayer(const char *url) {
  file = new AudioFileSourceHTTPStream(url);
  buf = new AudioFileSourceBuffer(file, 4096);
  out = new AudioOutputI2SDAC();
  out->SetGain(0.05);
  mp3 = new AudioGeneratorMP3();
  mp3->begin(buf, out);  
}

void stopPlayer() {
  mp3->stop();
  delete(file);
  delete(buf);
  delete(mp3);
  delete(out);
}
gerardwr commented 7 years ago

I'm sticking to the example sketch in the Git repo, adding my test-URL's and buffersize 4096.


#include <ESP8266WiFi.h>
#include "AudioFileSourceHTTPStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"

// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.

// Enter your WiFi setup here:
const char *SSID = "....";
const char *PASSWORD = ".....";

// Randomly picked URL
// const char *URL="http://streaming.shoutcast.com/80sPlanet?lang=en-US"; // 80sPlanet radio, 128kbps 44.1 kHz : works, only occasional a hickup
// const char *URL="http://icecast.omroep.nl/radio1-bb-mp3";              // Dutch Radio 1, 128kbps 48.0 kHz : works with severy hickups due to high sample freq)
// const char *URL="http://91.221.151.155:80/;?.mp3";                     // Arrow Classick Rock, 128kbps 44.1 kHz : works, only occasional a hickup
 const char *URL="http://stream.morow.com:8000/morow.mp3";                 // Morow Radio, 128kbps 44.1 kHz : works, only occasional a hickup
// const char *URL="http://192.168.0.44:8000/a2002011001-e02-128k.mp3";                 // Morow Radio, 128kbps 44.1 kHz : works, only occasional a hickup

AudioGeneratorMP3 *mp3;
AudioFileSourceHTTPStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2SNoDAC *out;

void setup()
{
  Serial.begin(115200);
  delay(1000);

  Serial.println(ESP.getFreeHeap());

  Serial.println("Connecting to WiFi");

  WiFi.disconnect();
  WiFi.softAPdisconnect(true);
  WiFi.mode(WIFI_STA);

  WiFi.hostname("melody");

  byte zero[] = {0,0,0,0};
  WiFi.config(zero, zero, zero, zero);

  WiFi.begin(SSID, PASSWORD);

  // Try forever
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("...Connecting to WiFi");
    delay(1000);
  }

  file = new AudioFileSourceHTTPStream(URL);
  buff = new AudioFileSourceBuffer(file, 4096);
  out = new AudioOutputI2SNoDAC();
  mp3 = new AudioGeneratorMP3();
  mp3->begin(buff, out);
}

void loop()
{
  if (mp3->isRunning()) {
    if (!mp3->loop()) mp3->stop();
  } else {
    Serial.printf("MP3 done\n");
    delay(1000);
  }
}
gerardwr commented 7 years ago

@armSeb

Your sketch results in the output below, same sound output as my sketch, "Buffering" and related hickup every second.

Another problem cause eliminated.

*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.0.45
18104
Buffering...
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 0
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 418
Buffering...
Buffering...
Buffering...
Buffering...
armSeb commented 7 years ago

Definitively there is a problem with the wireless connection, the buffer keeps filling, and the network jitter is too high. Try to change your AP channel...

gerardwr commented 7 years ago

OK, will try that.

For good measure my Arduino config:


Flash Size 4M (3M SPIFFS)
lwIP variant "v2"
CPU Freqency 160 Mhz
...
armSeb commented 7 years ago

How did you obtain the config ? In particular the lwip variant ?

gerardwr commented 7 years ago

From the Arduino 1.8.4 menu "tools".

Just retype the "interesting" ones here, left out things like "Board", "Upload speed", "port", etc.

lwip variants to choose from are:

V2
Prebuilt source (gcc)
Espressif (xcc)
Open Source (gcc)

OMG, I hate retyping ;-)

BTW : I have also installed Arduino for ESP32.

armSeb commented 7 years ago

Ah I have Arduino 1.8.0 ;) Without the ESP32 lib.

gerardwr commented 7 years ago

Changed Wifi channel of my router, made no difference :-(

Have an Arduino 1.8.1 handy so could try that.

Using the latest Git repo from ESP8266/Arduino , right?

Nearly midnight here, will do a fresh install of my Arduino environment tomorrow. Thanks for your help!

If that does not help, I'll try another Wifi router.

If all fails, I'll have to look for an other hobby ;-)

armSeb commented 7 years ago

I updated to Arduino 1.8.5 to try. I don't know if I am on the latest ESP8266 update.

I am using arduino on Mac OSX (and on Linux at work)

gerardwr commented 7 years ago

And I'm developing on Mac OS X.

armSeb commented 7 years ago

I'm using the stable version :

http://arduino.esp8266.com/stable/package_esp8266com_index.json Maybe you can try different lwip variants...

gerardwr commented 7 years ago

Switched to another Wifi Router, no change :-(

This IS a tough one!

armSeb commented 7 years ago

StreamMP3FromHTTP.ino.nodemcu.bin.zip

Please try this precompiled binary to eliminate the environment issue.

gerardwr commented 7 years ago

Thanks for bin, not sure yet how to exactly get esptool to upload it, but hey we're learning!

I updated ESP8266/Arduino release 2.3.0 to 2.4.0-rc2 a few weeks ago. Never gave me any trouble so far, maybe this is the first time.

Tomorrow Arduino 1.8.1 + stable 2.3.0.

gerardwr commented 7 years ago

HOLD THE PHONE!

Desperate attempt changing default "lwip variant V2" to "Prebuilt source (gcc)".

Crystal clear sound from Morow Radio MP3 stream, no hickups, no crackles, no hisses, PERFECT!

!@#$%^&()_!@#$%^&()

@armSeb : One of your many suggestions was "Maybe you can try different lwip variants...", I was desperate enough to give it a go. Nailed it! Thanks a lot for sticking with me, is greatly appreciated.

Tomorrow tidy-ing things up, clear my head, and think of the next steps to take. I have a working Morow Radio streamer with a "good enough" SW DAC sound", excellent!

See you, hopefully in another "issue" ;-)

Good night!

armSeb commented 7 years ago

Haha great !

IT seems the lwip2 is a more user-friendly ip stack for esp8266 (as it's described).

I'll go to sleep too, Good night !

gerardwr commented 7 years ago

Intoxicated by success, I tested playing the AAC stream of Morow Radio.

Stream plays continuously, no hickups or dropouts, nice!

But the earlier reported whistles/hisses that occurs every few secs remain. It sounds as if there's occasionally another sound "mixed" with the original stream.

But that's another "issue" I guess.

gerardwr commented 7 years ago

@armSeb : "lwip2 a more user-friendly ip stack", not for me it wasn't ;-)

armSeb commented 7 years ago

lwip2 seems less optimized than lwip1. But using lwip1 from the latest esp8266 git repo seems to be better than the stable version (more stable, more performant).

gerardwr commented 7 years ago

lwip variants you can choose in the Arduino IDE are:

V2 - this is the default
Prebuilt source (gcc)
Espressif (xcc)
Open Source (gcc)

The V2 default resulted in a lot of connection trouble i.c.w. ESP8266AUDIO, setting the lwip variant to Prebuilt source (gcc) solved these problems. Did not try the other variants to choose from, yet.

The lwip variants for the IDE are defined in BOARDS.TXT, but did no further investigation

https://github.com/esp8266/Arduino/blob/7315095e464397ae3f4dc9f1d231278e61242b04/boards.txt


generic.menu.LwIPVariant.open.build.lwip_include=lwip2/include
generic.menu.LwIPVariant.open.build.lwip_lib=-llwip2
generic.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
generic.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
generic.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC
generic.menu.LwIPVariant.Espressif=Espressif (xcc)
generic.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
generic.menu.LwIPVariant.Espressif.build.lwip_flags=-DLWIP_MAYBE_XCC
generic.menu.LwIPVariant.OpenSource=Open Source (gcc)
generic.menu.LwIPVariant.OpenSource.build.lwip_lib=-llwip_src
generic.menu.LwIPVariant.OpenSource.build.lwip_flags=-DLWIP_OPEN_SRC
armSeb commented 7 years ago

I choose the Open Source variant ;)

gerardwr commented 7 years ago

Agreed, will do that to, hopefully without any regrets.

d-a-v commented 7 years ago

Guys, I am the author of lwip2, and also very interested in this project. @earlephilhower does cool stuff :) I don't have the hardware yet, but I am now even more interested since lwip2 should be working better than lwip1.4 (it has so far always worked better and solved number tcp issues lwip1 had). Is StreamMP3FromHTTP the example to compile, with master version of this library or does the problem appears with a specific release ?

I read above that you have buffers problem. There's something you can try with lwip2, it is to change MSS size. It is by default 1460 in lwip1, and I changed it to 536 (the minimum legal in RFCs) so to release memory for the esp8266. Since you have lwip2, you are using esp8266/Arduino's master. If you are under linux/macos, you can

esp8266$ cd tools/sdk/lwip2
lwip2$ make install  (this will download lwip2 sources)
lwip2$ cd builder/glue-lwip/arduino

edit lwipopts.h and find TCP_MSS, change 536 to 1460

arduino$ cd ../../../
lwip2$ make install

then recompile your sketch selecting lwip-v2 and please report back. I predict performances are at least the same as with lwip-v1.4.

gerardwr commented 7 years ago

Unexpected Compile error using setting lwip variant to "Open Source (gcc)", and the compilation stops.

It complains (in Dutch) about multiple SD libraries, huh? Is probably rigth, but I see no relation to "lwip".

When reverting to lwip variant "Prebuilt Source" the error is gone! So using that for now ;-)


Arduino: 1.8.4 (Mac OS X), Board:"WeMos D1 R2 & mini, 160 MHz, 4M (3M SPIFFS), Open Source (gcc), Disabled, None, 230400"

Build-opties gewijzigd, alles wordt opnieuw gebuild
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [build/api/api_lib.o] Error 2
Meerdere bibliotheken gevonden voor "SD.h"
Gebruikt: /Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/libraries/SD
Niet gebruikt: /Applications/Arduino1.8.4.app/Contents/Java/libraries/SD
exit status 2
Fout bij het compileren voor board WeMos D1 R2 & mini
gerardwr commented 7 years ago

@d-a-v

Hi,

Thanks for joining this wonderfull topic ;-)

I'm the guy with the major errors using "lwip variant V2". Errors were gone when I switched to "Prebuilt source (gcc)".

Gave updating lwip2 using your recipe a try but it runs into an error.

Tell me if I made a stupid mistake, and I'll try again.

BTW : I'm on a Mac.


imac-van-gerard:lwip2 gerard$ pwd
/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk/lwip2
imac-van-gerard:lwip2 gerard$ make install
git submodule update --init --recursive builder
Submodule 'lwip2' (https://github.com/d-a-v/esp82xx-nonos-linklayer.git) registered for path 'tools/sdk/lwip2/tools/sdk/lwip2/builder'
Cloning into '/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk/lwip2/builder'...
Submodule path 'builder': checked out '9b6966aea4c66ff5d1c6c077dee2641f848c4fdb'
Submodule 'lwip2-src' (https://git.savannah.nongnu.org/git/lwip.git) registered for path 'builder/lwip2-src'
Cloning into '/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk/lwip2/builder/lwip2-src'...
Submodule path 'builder/lwip2-src': checked out '92f23d6ca0971a32f2085b9480e738d34174417b'
make -C builder -f Makefile.arduino install
make -f makefiles/Makefile.build-lwip2 \
            target=arduino \
            SDK=/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk \
            LWIP_ESP=/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk/lwip/include \
            LWIP_LIB=liblwip2.a \
            LWIP_LIB_RELEASE=../../lib/liblwip2.a \
            LWIP_INCLUDES_RELEASE=../include \
            TOOLS=/Users/gerard/Documents/My Data/ArduinoESP/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf- \
            install
make[2]: *** No rule to make target `Data/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk'.  Stop.
make[1]: *** [install] Error 2
make: *** [install] Error 2
imac-van-gerard:lwip2 gerard$ 
d-a-v commented 7 years ago

It's the My<SPACE>Data :) I'll try to fix scripts to handle spaces in paths. In the meantime I can propose you to

gerardwr commented 7 years ago

@d-a-v Haha, the space in "My Data" has already caused many joys in the past ;-)

Removed the space temporarily, and tried again.

Here's the output:


imac-van-gerard:lwip2 gerard$ pwd
/Users/gerard/Documents/MyData/ArduinoESP/hardware/esp8266com/esp8266/tools/sdk/lwip2
imac-van-gerard:lwip2 gerard$ make install
make -C builder -f Makefile.arduino install
<snip>
---- moving sntp_get_current_timestamp in IRAM
---- moving millis in IRAM
rm -rf ../include
mkdir -p ../include
cp -a lwip2-src/src/include/* ../include
cp -a glue/gluedebug.h glue-lwip/lwip-git-hash.h glue-lwip/lwip-err-t.h glue-lwip/arch ../include
echo "// this file will be overwritten upon lwip2 rebuild" > ../include/lwipopts.h
echo "#ifndef __CUSTOM_EXTRA_DEFINES__" >> ../include/lwipopts.h
echo "#define __CUSTOM_EXTRA_DEFINES__" >> ../include/lwipopts.h
echo "" >> ../include/lwipopts.h
echo "#endif" >> ../include/lwipopts.h
cat glue-lwip/lwipopts.h >> ../include/lwipopts.h
echo "warning: this directory is re/over/written from lwip2 builder upon lwip2 rebuild" > ../include/README.md
touch ../include/espconn.h
imac-van-gerard:lwip2 gerard$ cd builder/glue-lwip/arduino
-bash: cd: builder/glue-lwip/arduino: No such file or directory
imac-van-gerard:lwip2 gerard$ cd builder/glue-lwip
imac-van-gerard:glue-lwip gerard$ ls
arch            esp-millis.c        esp-sntp.c      lwip            lwip-git-hash.h     lwip-helper.h
esp-dhcpserver.c    esp-millis.h        esp-time.c      lwip-err-t.h        lwip-git.c      lwipopts.h
imac-van-gerard:glue-lwip gerard$ 
d-a-v commented 7 years ago

It's because you are not in latest master. So either you pull and synchronize lwip2 subrepo, but it is easier to modify lwipopts.h in lwip-git/ dir.

-- on mobile

armSeb commented 7 years ago

Maybe you can remove all the esp8266 dir and make a clean install from git repo.

@d-a-v Thanks for the suggestion, I am now compiling with the MSS modification, I keep you updated :)

armSeb commented 7 years ago

I am now disconnected immediatly from the server:

Connecting to WiFi
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Already connected. Bailing out.
*WM: IP Address:
*WM: 192.168.1.215
ICY metaint = 16384
Stream size: -1
18056
Buffering...
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 0
MP3 done

With MSS to 1200 it seems to work, but after a while I am disconnected too.

armSeb commented 7 years ago

With some debugs (with MSS defined to 1460):

Connecting to WiFi
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Already connected. Bailing out.
*WM: IP Address:
*WM: 192.168.1.215
[HTTP-Client][begin] url: http://213.251.190.165/pulsHD.mp3
[HTTP-Client][begin] host: 213.251.190.165 port: 80 url: /pulsHD.mp3
[HTTP-Client] connected to 213.251.190.165:80
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.0 200 OK'
[HTTP-Client][handleHeaderResponse] RX: 'icy-notice1:<BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>'
[HTTP-Client][handleHeaderResponse] RX: 'icy-notice2:SHOUTcast DNAS/posix(linux x64) v2.5.5.732<BR>'
[HTTP-Client][handleHeaderResponse] RX: 'Accept-Ranges:none'
[HTTP-Client][handleHeaderResponse] RX: 'Access-Control-Allow-Origin:*'
[HTTP-Client][handleHeaderResponse] RX: 'Cache-Control:no-cache,no-store,must-revalidate,max-age=0'
[HTTP-Client][handleHeaderResponse] RX: 'Connection:close'
[HTTP-Client][handleHeaderResponse] RX: 'icy-name:PulsRadio DANCE'
[HTTP-Client][handleHeaderResponse] RX: 'icy-genre:Dance, Trance, Electronic, Lounge, Techno'
[HTTP-Client][handleHeaderResponse] RX: 'icy-br:192'
[HTTP-Client][handleHeaderResponse] RX: 'icy-sr:44100'
[HTTP-Client][handleHeaderResponse] RX: 'icy-url:https://www.pulsradio.com/dance'
[HTTP-Client][handleHeaderResponse] RX: 'icy-pub:1'
[HTTP-Client][handleHeaderResponse] RX: 'content-type:audio/mpeg'
[HTTP-Client][handleHeaderResponse] RX: 'icy-metaint:16384'
[HTTP-Client][handleHeaderResponse] RX: 'X-Clacks-Overhead:GNU Terry Pratchett'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 200
ICY metaint = 16384
Stream size: -1
15192
Buffering...
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 0
[HTTP-Client][end] still data in buffer (658), clean up.
[HTTP-Client][end] tcp stop
MP3 done
MP3 done
MP3 done
earlephilhower commented 7 years ago

+1 for the Pratchett header in the server response!

Anyway, I've been tweaking the ICY and HTTP readers. They can now automatically reconnect on 0-byte reads a user-specified number of times. Last night I had about 2.5hrs streaming before it couldn't reconnect (and at that point there was a internet or server issue because it tried 3 times over the span of 3 seconds to reconnect before giving up). @armSeb and @gerardwr , I'd suggest pulling the changes and adding a "file->SetReconnect(3, 500)" before you start a stream to enable it.

To avoid the issue of LWIP settings, you may want to try using the GIT I've got (by sheer luck) for the Arduino core. I couldn't tell you what LWIP it's running, only that it works and my only change has been addition of the HTTPS server pull request (3001 in the Arduino repo).

commit 5c01841430d5f93d5334c56f3b708995912a8675
Author: Ivan Grokhotkov <ivan@espressif.com>
Date:   Tue Oct 31 02:05:40 2017 +0800

    sdk: update to v2.1.0-14-g33f234f

    https://github.com/espressif/ESP8266_NONOS_SDK/commit/33f234f4a6defafec2f9442dcc0bb1ebdb80c42f

@d-a-v Forgive my TCP ignorance, but for some reason my Master's networking all involved ATM and its ilk, not TCP. If MSS = 600 and I do a http.read (1000) will I get a short read each time, or will it recombine multiple segments before sending it back to me? The algorithm can try combining multiple reads on short reads, but doesn't now, as before the max segment was >> than any MP3 or ADTS frame.

armSeb commented 7 years ago

I think the MSS=536 is a bad setting, as it forces the router to fragment packets and causes several latencies.

I guess that the socket buffer re-assemble all chunks.

Keeping MSS to 1460 seems (in my opinion) to be the best choice.

gerardwr commented 7 years ago

@d-a-v Updated to latest ESP8266/Arduino Master, changed MSS from 536 to 1460 acc. your recipy, and compiled StreamMP3FromHTTP sketch using lwip v2.

Playing MP3 stream with MSS=536 was not working for me with "decoding errors" every sec, better with MSS=1460, but most of the time the streaming stops ("Mp3 done") within several seconds.

When using variant "Prebuild source (gcc)" an Mp3 stream plays for "hours" without interruption.

gerardwr commented 7 years ago

@earlephilhower

Final question : Sometimes the former version stopped streaming with "MP3 done" after some hours. Should I expect the latest version to play "forever"?

gerardwr commented 7 years ago

@earlephilhower Started streaming AAC stream overnight (latest repo + Setreconnect) and the stream was still running OK this morning (> 10 hours). Could not check for messages in the serial monitor, Mac was off :-)

Excellent!

earlephilhower commented 7 years ago

Great news. If there are no network hiccups greater than (retries * delay) it should play indefinitely. For me, I think I'm on the wrong side of the Atlantic for the streamer I was using and did have real disconnects lasting > 1.5 seconds every few hours, but there's nothing to be done for that, really.

gerardwr commented 7 years ago

I'm really happy with the library playing my favorite Mp3 stream all day, too bad that the AAC stream has artefacts :-( (ref. issue #12).

Many thanks for sharing the library and the provided support.

armSeb commented 7 years ago

Hello,

With the improved code I am now able to play the 48000Hz stream: http://icecast.omroep.nl/radio1-bb-mp3

gerardwr commented 7 years ago

I replied earlier that the latest repo performed worse, but I deleted this reply because accidentily tested with a 80Mhz CPU i.o. 160Mhz.

Installed the latest repo, and tested the 48kHz MP3 stream : Stream runs but has quite some disturbances like "speckles".

Maybe due to a temporary stream issue, as I got "reconnects after a while. Will try again later.


...Connecting to WiFi
...Connecting to WiFi
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 0
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 140
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 935908
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 936140
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 941748
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 941900
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 951756
Decoding error 0x0102 (reserved header layer value) at byte offset 951796
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 955708
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 961548
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 965928
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 971340
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 975947
No stream data available
Stream disconnected

Attempting to reconnect, try 0
Attempting to reconnect, try 1
Attempting to reconnect, try 2
Unable to reconnect
Stream disconnected

Attempting to reconnect, try 0
Attempting to reconnect, try 1
Attempting to reconnect, try 2
Unable to reconnect
Stream disconnected

Attempting to reconnect, try 0
Attempting to reconnect, try 1
Attempting to reconnect, try 2
Unable to reconnect
Stream disconnected

Attempting to reconnect, try 0
gerardwr commented 7 years ago

I ran the 48K stream overnight, was still running this morning :-) so seems "bulletproof".

But the sream is still spoiled by the continuous "speckles", as if as motorcycle with a bad ignition coil is running nearby.

Restarted the ESP, but the speckles remain. Sometimes the ESP resets, but the stream is resumed automagically.


Decoding error 0x0101 (lost synchronization) at byte offset 7810340
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 7810476
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 7836939
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 7836972
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 7855138

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
vffffffff
~ld
Connecting to WiFi
...Connecting to WiFi
...Connecting to WiFi
...Connecting to WiFi
...Connecting to WiFi
...Connecting to WiFi
Buffering...
Decoding error 0x0101 (lost synchronization) at byte offset 0
Decoding error 0x0104 (reserved sample frequency value) at byte offset 51
Decoding error 0x0103 (forbidden bitrate value) at byte offset 552
Decoding error 0x0235 (bad main_data_begin pointer) at byte offset 553
gerardwr commented 7 years ago

Just to make sure, with the latest the 48K Radio1 stream has "speckles" BUT the Morow 44K MP3 stream is absolutely clean. Nice!

earlephilhower commented 7 years ago

Any reason to keep this open? I think we're tracking all the other things in other active issues.