Skip to content

Commit 8dc0832

Browse files
committed
added readBytes function to UDPStream
Added readBytes fixed issues when using UDPStream with AudioEffects and GeneratorFromStream
1 parent f5b5f7c commit 8dc0832

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/AudioLibs/Communication.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class ESPNowStream : public AudioStreamX {
348348
}
349349

350350
static void default_recv_cb(const uint8_t *mac_addr, const uint8_t *data,
351-
int data_len) {
351+
int data_len) {
352352
LOGD("rec_cb: %d", data_len);
353353
// make sure that the receive buffer is available - moved from begin to make sure that it is only allocated when needed
354354
ESPNowStreamSelf->setupReceiveBuffer();
@@ -459,6 +459,17 @@ class UDPStream : public WiFiUDP {
459459
endPacket();
460460
return result;
461461
}
462+
// Reads bytes using WiFi::readBytes
463+
size_t readBytes(uint8_t *buffer, size_t length) override {
464+
LOGD(LOG_METHOD);
465+
size_t len = available();
466+
size_t bytes_read = 0;
467+
if (len>0){
468+
// get the data now
469+
bytes_read = WiFiUDP::readBytes((uint8_t*)buffer, length);
470+
}
471+
return bytes_read;
472+
}
462473

463474
protected:
464475
uint16_t remote_port_ext;
@@ -474,8 +485,8 @@ class UDPStream : public WiFiUDP {
474485
delay(500);
475486
}
476487
}
477-
478-
// Performance Hack
488+
489+
// Performance Hack
479490
//client.setNoDelay(true);
480491
esp_wifi_set_ps(WIFI_PS_NONE);
481492

0 commit comments

Comments
 (0)