ESPHome  2025.3.3
Public Member Functions | Static Public Member Functions | Protected Attributes
esphome::audio::AudioSinkTransferBuffer Class Reference

#include <audio_transfer_buffer.h>

Inheritance diagram for esphome::audio::AudioSinkTransferBuffer:
esphome::audio::AudioTransferBuffer

Public Member Functions

size_t transfer_data_to_sink (TickType_t ticks_to_wait, bool post_shift=true)
 Writes any available data in the transfer buffer to the sink. More...
 
void set_sink (const std::weak_ptr< RingBuffer > &ring_buffer)
 Adds a ring buffer as the transfer buffer's sink. More...
 
void set_sink (speaker::Speaker *speaker)
 Adds a speaker as the transfer buffer's sink. More...
 
void clear_buffered_data () override
 
bool has_buffered_data () const override
 
- 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...
 
bool reallocate (size_t new_buffer_size)
 

Static Public Member Functions

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

Protected Attributes

speaker::Speakerspeaker_ {nullptr}
 
- 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}
 

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...
 

Detailed Description

Definition at line 80 of file audio_transfer_buffer.h.

Member Function Documentation

◆ clear_buffered_data()

void esphome::audio::AudioSinkTransferBuffer::clear_buffered_data ( )
overridevirtual

Reimplemented from esphome::audio::AudioTransferBuffer.

Definition at line 58 of file audio_transfer_buffer.cpp.

◆ create()

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

Creates a new sink transfer buffer.

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

Definition at line 12 of file audio_transfer_buffer.cpp.

◆ has_buffered_data()

bool esphome::audio::AudioSinkTransferBuffer::has_buffered_data ( ) const
overridevirtual

Reimplemented from esphome::audio::AudioTransferBuffer.

Definition at line 160 of file audio_transfer_buffer.cpp.

◆ set_sink() [1/2]

void esphome::audio::AudioSinkTransferBuffer::set_sink ( const std::weak_ptr< RingBuffer > &  ring_buffer)
inline

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

Parameters
ring_bufferweak_ptr to the allocated ring buffer

Definition at line 100 of file audio_transfer_buffer.h.

◆ set_sink() [2/2]

void esphome::audio::AudioSinkTransferBuffer::set_sink ( speaker::Speaker speaker)
inline

Adds a speaker as the transfer buffer's sink.

Parameters
speakerPointer to the speaker component

Definition at line 105 of file audio_transfer_buffer.h.

◆ transfer_data_to_sink()

size_t esphome::audio::AudioSinkTransferBuffer::transfer_data_to_sink ( TickType_t  ticks_to_wait,
bool  post_shift = true 
)

Writes any available data in the transfer buffer to the sink.

Parameters
ticks_to_waitFreeRTOS ticks to block while waiting for the sink to have enough space
post_shiftIf true, all remaining data is moved to the start of the buffer after transferring to the sink. Defaults to true.
Returns
Number of bytes written

Definition at line 135 of file audio_transfer_buffer.cpp.

Field Documentation

◆ speaker_

speaker::Speaker* esphome::audio::AudioSinkTransferBuffer::speaker_ {nullptr}
protected

Definition at line 114 of file audio_transfer_buffer.h.


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