ESPHome  2025.2.0
Public Member Functions | Static Public Member Functions
esphome::audio::AudioSourceTransferBuffer Class Reference

#include <audio_transfer_buffer.h>

Inheritance diagram for esphome::audio::AudioSourceTransferBuffer:
esphome::audio::AudioTransferBuffer

Public Member Functions

size_t transfer_data_from_source (TickType_t ticks_to_wait)
 Reads any available data from the sink into the transfer buffer. More...
 
void set_source (const std::weak_ptr< RingBuffer > &ring_buffer)
 Adds a ring buffer as the transfer buffer's source. More...
 
- Public Member Functions inherited from esphome::audio::AudioTransferBuffer
 ~AudioTransferBuffer ()
 Destructor that deallocates the transfer buffer. More...
 
uint8_t * get_buffer_start () const
 Returns a pointer to the start of the transfer buffer where available() bytes of exisiting data can be read. More...
 
uint8_t * get_buffer_end () const
 Returns a pointer to the end of the transfer buffer where free() bytes of new data can be written. More...
 
void decrease_buffer_length (size_t bytes)
 Updates the internal state of the transfer buffer. More...
 
void increase_buffer_length (size_t bytes)
 Updates the internal state of the transfer buffer. More...
 
size_t available () const
 Returns the transfer buffer's currently available bytes to read. More...
 
size_t capacity () const
 Returns the transfer buffers allocated bytes. More...
 
size_t free () const
 Returns the transfer buffer's currrently free bytes available to write. More...
 
virtual void clear_buffered_data ()
 Clears data in the transfer buffer and, if possible, the source/sink. More...
 
virtual bool has_buffered_data () const
 Tests if there is any data in the tranfer buffer or the source/sink. More...
 
bool reallocate (size_t new_buffer_size)
 

Static Public Member Functions

static std::unique_ptr< AudioSourceTransferBuffercreate (size_t buffer_size)
 Creates a new source transfer buffer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from esphome::audio::AudioTransferBuffer
bool allocate_buffer_ (size_t buffer_size)
 Allocates the transfer buffer in external memory, if available. More...
 
void deallocate_buffer_ ()
 Deallocates the buffer and resets the class variables. More...
 
- Protected Attributes inherited from esphome::audio::AudioTransferBuffer
std::shared_ptr< RingBufferring_buffer_
 
uint8_t * buffer_ {nullptr}
 
uint8_t * data_start_ {nullptr}
 
size_t buffer_size_ {0}
 
size_t buffer_length_ {0}
 

Detailed Description

Definition at line 115 of file audio_transfer_buffer.h.

Member Function Documentation

◆ create()

std::unique_ptr< AudioSourceTransferBuffer > esphome::audio::AudioSourceTransferBuffer::create ( size_t  buffer_size)
static

Creates a new source transfer buffer.

Parameters
buffer_sizeSize of the transfer buffer in bytes.
Returns
unique_ptr if successfully allocated, nullptr otherwise

Definition at line 22 of file audio_transfer_buffer.cpp.

◆ set_source()

void esphome::audio::AudioSourceTransferBuffer::set_source ( const std::weak_ptr< RingBuffer > &  ring_buffer)
inline

Adds a ring buffer as the transfer buffer's source.

Parameters
ring_bufferweak_ptr to the allocated ring buffer

Definition at line 133 of file audio_transfer_buffer.h.

◆ transfer_data_from_source()

size_t esphome::audio::AudioSourceTransferBuffer::transfer_data_from_source ( TickType_t  ticks_to_wait)

Reads any available data from the sink into the transfer buffer.

Parameters
ticks_to_waitFreeRTOS ticks to block while waiting for the source to have enough data
Returns
Number of bytes read

Definition at line 109 of file audio_transfer_buffer.cpp.


The documentation for this class was generated from the following files: