Skip to content

Commit 0041534

Browse files
committed
ICYStream
1 parent e91c22e commit 0041534

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/AudioHttp/ICYStream.h

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,20 @@ class ICYStreamDefault : public AbstractURLStream {
8282
virtual size_t readBytes(uint8_t* buffer, size_t len) override {
8383
size_t result = 0;
8484
if (icy.hasMetaData()){
85-
CHECK_MEMORY();
86-
// wait for data
87-
while(url->available()<len){
88-
delay(100);
89-
}
90-
91-
// access using state engine
92-
for (size_t j=0; j<len; j++){
93-
int ch = read();
94-
if (ch==-1){
95-
break;
85+
// get data
86+
int read = url->readBytes(buffer, len);
87+
// remove metadata from data
88+
int pos = 0;
89+
for (int j=0; j<read; j++){
90+
icy.processChar(buffer[j]);
91+
if (icy.isData()){
92+
buffer[pos++] = buffer[j];
9693
}
97-
result = j+1;
98-
buffer[j] = ch;
99-
}
100-
CHECK_MEMORY();
94+
}
95+
result = pos;
10196
} else {
102-
// fast access if there is no metadata
103-
result = url->readBytes(buffer, len);
97+
// fast access if there is no metadata
98+
result = url->readBytes(buffer, len);
10499
}
105100
LOGD("%s: %zu -> %zu", LOG_METHOD, len, result);
106101
return result;
@@ -116,6 +111,7 @@ class ICYStreamDefault : public AbstractURLStream {
116111
// Read character and processes using the MetaDataICY state engine
117112
virtual int read() override {
118113
int ch = -1;
114+
if (url==nullptr) return -1;
119115

120116
// get next data byte
121117
do {
@@ -125,7 +121,6 @@ class ICYStreamDefault : public AbstractURLStream {
125121
}
126122

127123
icy.processChar(ch);
128-
//yield();
129124
} while (!icy.isData());
130125
return ch;
131126
}

src/AudioTools/AudioCopy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class StreamCopyT {
202202

203203
// blocking write - until everything is processed
204204
size_t write(size_t len, size_t &delayCount ){
205+
if (buffer==nullptr) return 0;
205206
size_t total = 0;
206207
int retry = 0;
207208
while(total<len){

0 commit comments

Comments
 (0)