Skip to content

Commit d8ff239

Browse files
Added 'bufferStatus(&used, &capacity)' (#28)
1 parent f28154e commit d8ff239

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,18 @@ Returns `0` if the stream is a radio stream.
280280

281281
### Get the buffer fill status
282282
```c++
283-
const char *bufferStatus();
283+
const char *bufferStatus()
284284
```
285285

286-
Returns `0/0` if there is no buffer.<br>Otherwise returns something like `4096/65536` which means 4kB waiting in a 64kB buffer.<br>A buffer will only be allocated if there is enough free psram.
286+
Returns `0/0` if there is no buffer.<br>Otherwise returns something like `4096/65536` which means 4kB waiting in a 64kB buffer.
287+
288+
```c++
289+
void bufferStatus(size_t &used, size_t &capacity)
290+
```
291+
292+
There is also a version that takes two `size_t` variables by reference.<br>Works the same as the `const char *` version.
293+
294+
A buffer will only be allocated if there is enough free psram.
287295
288296
<hr>
289297

src/ESP32_VS1053_Stream.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ void ESP32_VS1053_Stream::_playFromRingBuffer()
402402
while (_remainingBytes && _vs1053->data_request() && millis() - start < MAX_TIME_MS)
403403
{
404404
size_t size = 0;
405-
//portDISABLE_INTERRUPTS();
406405
uint8_t *data = (uint8_t *)xRingbufferReceiveUpTo(_ringbuffer_handle, &size, pdMS_TO_TICKS(0), VS1053_PLAYBUFFER_SIZE);
407-
//portENABLE_INTERRUPTS();
408406
static auto ringbufferEmpty = 0;
409407
if (!data)
410408
{
@@ -447,9 +445,7 @@ void ESP32_VS1053_Stream::_streamToRingBuffer(WiFiClient *const stream)
447445
break;
448446

449447
const int BYTES_IN_BUFFER = stream->readBytes(_localbuffer, BYTES_TO_READ);
450-
//portDISABLE_INTERRUPTS();
451448
const BaseType_t result = xRingbufferSend(_ringbuffer_handle, _localbuffer, BYTES_IN_BUFFER, pdMS_TO_TICKS(0));
452-
//portENABLE_INTERRUPTS();
453449
if (result == pdFALSE)
454450
{
455451
log_e("ringbuffer failed to receive %i bytes. Closing stream.");
@@ -534,9 +530,7 @@ void ESP32_VS1053_Stream::_chunkedStreamToRingBuffer(WiFiClient *const stream)
534530
break;
535531

536532
const int BYTES_IN_BUFFER = stream->readBytes(_localbuffer, BYTES_TO_READ);
537-
//portDISABLE_INTERRUPTS();
538533
const BaseType_t result = xRingbufferSend(_ringbuffer_handle, _localbuffer, BYTES_IN_BUFFER, pdMS_TO_TICKS(0));
539-
//portENABLE_INTERRUPTS();
540534
if (result == pdFALSE)
541535
{
542536
log_e("ringbuffer failed to receive %i bytes. Closing stream.");
@@ -716,7 +710,7 @@ void ESP32_VS1053_Stream::loop()
716710
stream->setTimeout(0);
717711
stream->setNoDelay(true);
718712
}
719-
713+
720714
if (_remainingBytes && _vs1053->data_request())
721715
{
722716
if (_chunkedResponse)
@@ -809,3 +803,9 @@ const char *ESP32_VS1053_Stream::bufferStatus()
809803
snprintf(ringbuffer_status, sizeof(ringbuffer_status), "%u/%u", VS1053_PSRAM_BUFFER_SIZE - xRingbufferGetCurFreeSize(_ringbuffer_handle), VS1053_PSRAM_BUFFER_SIZE);
810804
return ringbuffer_status;
811805
}
806+
807+
void ESP32_VS1053_Stream::bufferStatus(size_t &used, size_t &capacity)
808+
{
809+
used = _ringbuffer_handle ? VS1053_PSRAM_BUFFER_SIZE - xRingbufferGetCurFreeSize(_ringbuffer_handle) : 0;
810+
capacity = _ringbuffer_handle ? VS1053_PSRAM_BUFFER_SIZE : 0;
811+
}

src/ESP32_VS1053_Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ESP32_VS1053_Stream
6161
size_t position();
6262
uint32_t bitrate();
6363
const char *bufferStatus();
64+
void bufferStatus(size_t &used, size_t &capacity);
6465

6566
private:
6667
VS1053 *_vs1053;

0 commit comments

Comments
 (0)