Skip to content

Commit

Permalink
Make stream reads orders of magnitude faster (fixes earlephilhower#38) (
Browse files Browse the repository at this point in the history
earlephilhower#44)

Fix by @h3ndrik 
* Use correct read for stream data on the ESP32 (fixes earlephilhower#38)
* Adjust types for read()
  • Loading branch information
h3ndrik authored and earlephilhower committed Feb 1, 2018
1 parent e7c2aba commit 05a78dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/AudioFileSourceHTTPStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool
if (avail == 0) return 0;
if (avail < len) len = avail;

int read = stream->readBytes(reinterpret_cast<uint8_t*>(data), len);
int read = stream->read(reinterpret_cast<uint8_t*>(data), len);
pos += read;
return read;
}
Expand Down
12 changes: 6 additions & 6 deletions src/AudioFileSourceICYStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class ICYMDReader {
char xxx[16];
if (saved>=0) avail--; // Throw away any unread bytes
while (avail > 16) {
stream->readBytes(xxx, 16);
stream->read(reinterpret_cast<uint8_t*>(xxx), 16);
avail -= 16;
}
stream->readBytes(xxx, avail);
stream->read(reinterpret_cast<uint8_t*>(xxx), avail);
}
int read(uint8_t *dest, int len) {
if (!len) return 0;
Expand All @@ -100,7 +100,7 @@ class ICYMDReader {
if ((avail>0) && (len>0)) {
ptr = 0;
int toRead = (sizeof(buff)>avail)? avail : sizeof(buff);
int read = stream->readBytes(buff, toRead);
int read = stream->read(buff, toRead);
if (read != toRead) return 0; // Error, short read!
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
// If the read would hit an ICY block, split it up...
if (((int)(icyByteCount + len) > (int)icyMetaInt) && (icyMetaInt > 0)) {
int beforeIcy = icyMetaInt - icyByteCount;
int ret = stream->readBytes(reinterpret_cast<uint8_t*>(data), beforeIcy);
int ret = stream->read(reinterpret_cast<uint8_t*>(data), beforeIcy);
read += ret;
pos += ret;
len -= ret;
Expand All @@ -173,7 +173,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
if (ret != beforeIcy) return read; // Partial read

uint8_t mdSize;
int mdret = stream->readBytes(&mdSize, 1);
int mdret = stream->read(&mdSize, 1);
if ((mdret == 1) && (mdSize > 0)) {
ICYMDReader mdr(stream, mdSize * 16);
// Break out (potentially multiple) NAME='xxxx'
Expand Down Expand Up @@ -224,7 +224,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
icyByteCount = 0;
}

int ret = stream->readBytes(reinterpret_cast<uint8_t*>(data), len);
int ret = stream->read(reinterpret_cast<uint8_t*>(data), len);
read += ret;
pos += ret;
icyByteCount += ret;
Expand Down

0 comments on commit 05a78dc

Please sign in to comment.