Skip to content

Commit 05a78dc

Browse files
h3ndrikearlephilhower
authored andcommitted
Make stream reads orders of magnitude faster (fixes earlephilhower#38) (earlephilhower#44)
Fix by @h3ndrik * Use correct read for stream data on the ESP32 (fixes earlephilhower#38) * Adjust types for read()
1 parent e7c2aba commit 05a78dc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/AudioFileSourceHTTPStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool
116116
if (avail == 0) return 0;
117117
if (avail < len) len = avail;
118118

119-
int read = stream->readBytes(reinterpret_cast<uint8_t*>(data), len);
119+
int read = stream->read(reinterpret_cast<uint8_t*>(data), len);
120120
pos += read;
121121
return read;
122122
}

src/AudioFileSourceICYStream.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ class ICYMDReader {
7979
char xxx[16];
8080
if (saved>=0) avail--; // Throw away any unread bytes
8181
while (avail > 16) {
82-
stream->readBytes(xxx, 16);
82+
stream->read(reinterpret_cast<uint8_t*>(xxx), 16);
8383
avail -= 16;
8484
}
85-
stream->readBytes(xxx, avail);
85+
stream->read(reinterpret_cast<uint8_t*>(xxx), avail);
8686
}
8787
int read(uint8_t *dest, int len) {
8888
if (!len) return 0;
@@ -100,7 +100,7 @@ class ICYMDReader {
100100
if ((avail>0) && (len>0)) {
101101
ptr = 0;
102102
int toRead = (sizeof(buff)>avail)? avail : sizeof(buff);
103-
int read = stream->readBytes(buff, toRead);
103+
int read = stream->read(buff, toRead);
104104
if (read != toRead) return 0; // Error, short read!
105105
}
106106
}
@@ -164,7 +164,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
164164
// If the read would hit an ICY block, split it up...
165165
if (((int)(icyByteCount + len) > (int)icyMetaInt) && (icyMetaInt > 0)) {
166166
int beforeIcy = icyMetaInt - icyByteCount;
167-
int ret = stream->readBytes(reinterpret_cast<uint8_t*>(data), beforeIcy);
167+
int ret = stream->read(reinterpret_cast<uint8_t*>(data), beforeIcy);
168168
read += ret;
169169
pos += ret;
170170
len -= ret;
@@ -173,7 +173,7 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n
173173
if (ret != beforeIcy) return read; // Partial read
174174

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

227-
int ret = stream->readBytes(reinterpret_cast<uint8_t*>(data), len);
227+
int ret = stream->read(reinterpret_cast<uint8_t*>(data), len);
228228
read += ret;
229229
pos += ret;
230230
icyByteCount += ret;

0 commit comments

Comments
 (0)