Skip to content

Commit 38b3249

Browse files
Wait for enough data before parsing streamTitle.
Set stream timeout to 0.
1 parent 3231846 commit 38b3249

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ESP32_VS1053_Stream.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ void ESP32_VS1053_Stream::_handleStream(WiFiClient *const stream)
483483

484484
if (stream && stream->available() && _metaDataStart && _musicDataPosition == _metaDataStart)
485485
{
486+
const auto DATA_NEEDED = stream->peek() * 16 + 1;
487+
if (stream->available() < DATA_NEEDED)
488+
return;
489+
486490
const auto METALENGTH = stream->read() * 16;
487491
if (METALENGTH)
488492
{
@@ -573,8 +577,12 @@ void ESP32_VS1053_Stream::_handleChunkedStream(WiFiClient *const stream)
573577
log_d("spend %lu ms stuffing %i bytes in decoder", millis() - start, bytesToDecoder);
574578
}
575579

576-
if (_metaDataStart && _musicDataPosition == _metaDataStart && _bytesLeftInChunk)
580+
if (stream && stream->available() && _metaDataStart && _musicDataPosition == _metaDataStart && _bytesLeftInChunk)
577581
{
582+
const auto DATA_NEEDED = stream->peek() * 16 + 1;
583+
if (stream->available() < DATA_NEEDED)
584+
return;
585+
578586
const auto METALENGTH = stream->read() * 16;
579587
_bytesLeftInChunk--;
580588
if (METALENGTH)
@@ -678,6 +686,9 @@ void ESP32_VS1053_Stream::loop()
678686
}
679687
}
680688

689+
if (stream)
690+
stream->setTimeout(0);
691+
681692
if (_remainingBytes && _vs1053->data_request())
682693
{
683694
if (_chunkedResponse)

0 commit comments

Comments
 (0)