Skip to content

Commit b3605cf

Browse files
committed
Correct inconsistent handling in BufferedTaskStream
1 parent 7a5f821 commit b3605cf

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/AudioHttp/URLStreamESP32.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BufferedTaskStream : public AudioStream {
6666

6767
/// reads a byte - to be avoided
6868
virtual int read() override {
69-
if (!ready) return -1;
69+
//if (!ready) return -1;
7070
int result = -1;
7171
xSemaphoreTake(mutex, portMAX_DELAY);
7272
result = buffers.read();
@@ -76,7 +76,7 @@ class BufferedTaskStream : public AudioStream {
7676

7777
/// peeks a byte - to be avoided
7878
virtual int peek() override {
79-
if (!ready) return -1;
79+
//if (!ready) return -1;
8080
int result = -1;
8181
xSemaphoreTake(mutex, portMAX_DELAY);
8282
result = buffers.peek();
@@ -86,7 +86,7 @@ class BufferedTaskStream : public AudioStream {
8686

8787
/// Use this method !!
8888
virtual size_t readBytes( uint8_t *data, size_t length) override {
89-
if (!ready) return 0;
89+
//if (!ready) return 0;
9090
size_t result = 0;
9191
xSemaphoreTake(mutex, portMAX_DELAY);
9292
result = buffers.readArray(data, length);
@@ -99,7 +99,7 @@ class BufferedTaskStream : public AudioStream {
9999

100100
/// Returns the available bytes in the buffer: to be avoided
101101
virtual int available() override {
102-
if (!ready) return 0;
102+
//if (!ready) return 0;
103103
int result = 0;
104104
xSemaphoreTake(mutex, portMAX_DELAY);
105105
result = buffers.available();

src/AudioTools/AudioCopy.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,22 @@ class StreamCopyT {
176176
}
177177

178178
/// copies all data - returns true if we copied anything
179-
bool copyAll(int delayMs=5){
179+
bool copyAll(int delayWithDataMs=5, int delayNoDataMs=1000){
180180
LOGD(LOG_METHOD);
181181
bool result = false;
182182
if (from==nullptr || to == nullptr)
183183
return result;
184184

185-
while(copy()){
186-
result = true;
187-
delay(delayMs);
185+
// copy whily source has data available
186+
size_t available = 1024;
187+
while(available){
188+
if (copy()) {
189+
result = true;
190+
delay(delayWithDataMs);
191+
} else {
192+
delay(delayNoDataMs);
193+
}
194+
available = from->available();
188195
}
189196
return result;
190197
}

0 commit comments

Comments
 (0)