ESPHome  2025.2.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
esphome::speaker::AudioPipeline Class Reference

#include <audio_pipeline.h>

Public Member Functions

 AudioPipeline (speaker::Speaker *speaker, size_t buffer_size, bool task_stack_in_psram, std::string base_name, UBaseType_t priority)
 
void start_url (const std::string &uri)
 Starts an audio pipeline given a media url. More...
 
void start_file (audio::AudioFile *audio_file)
 Starts an audio pipeline given a AudioFile pointer. More...
 
esp_err_t stop ()
 Stops the pipeline. More...
 
AudioPipelineState process_state ()
 Processes the state of the audio pipeline based on the info_error_queue_ and event_group_. More...
 
void suspend_tasks ()
 Suspends any running tasks. More...
 
void resume_tasks ()
 Resumes any running tasks. More...
 
uint32_t get_playback_ms ()
 
void set_pause_state (bool pause_state)
 

Protected Member Functions

esp_err_t allocate_communications_ ()
 Allocates the event group and info error queue. More...
 
esp_err_t start_tasks_ ()
 Common start code for the pipeline, regardless if the source is a file or url. More...
 
void delete_tasks_ ()
 Resets the task related pointers and deallocates their stacks. More...
 

Static Protected Member Functions

static void read_task (void *params)
 
static void decode_task (void *params)
 

Protected Attributes

std::string base_name_
 
UBaseType_t priority_
 
uint32_t playback_ms_ {0}
 
bool hard_stop_ {false}
 
bool is_playing_ {false}
 
bool pause_state_ {false}
 
bool task_stack_in_psram_
 
bool pending_url_ {false}
 
bool pending_file_ {false}
 
speaker::Speakerspeaker_ {nullptr}
 
std::string current_uri_ {}
 
audio::AudioFilecurrent_audio_file_ {nullptr}
 
audio::AudioFileType current_audio_file_type_
 
audio::AudioStreamInfo current_audio_stream_info_
 
size_t buffer_size_
 
size_t transfer_buffer_size_
 
std::weak_ptr< RingBufferraw_file_ring_buffer_
 
EventGroupHandle_t event_group_ {nullptr}
 
QueueHandle_t info_error_queue_ {nullptr}
 
TaskHandle_t read_task_handle_ {nullptr}
 
StaticTask_t read_task_stack_
 
StackType_t * read_task_stack_buffer_ {nullptr}
 
TaskHandle_t decode_task_handle_ {nullptr}
 
StaticTask_t decode_task_stack_
 
StackType_t * decode_task_stack_buffer_ {nullptr}
 

Detailed Description

Definition at line 60 of file audio_pipeline.h.

Constructor & Destructor Documentation

◆ AudioPipeline()

esphome::speaker::AudioPipeline::AudioPipeline ( speaker::Speaker speaker,
size_t  buffer_size,
bool  task_stack_in_psram,
std::string  base_name,
UBaseType_t  priority 
)
Parameters
speakerESPHome speaker component for pipeline's audio output
buffer_sizeSize of the buffer in bytes between the reader and decoder
task_stack_in_psramTrue if the task stack should be allocated in PSRAM, false otherwise
task_nameFreeRTOS task base name
priorityFreeRTOS task priority

Definition at line 46 of file audio_pipeline.cpp.

Member Function Documentation

◆ allocate_communications_()

esp_err_t esphome::speaker::AudioPipeline::allocate_communications_ ( )
protected

Allocates the event group and info error queue.

Returns
ESP_OK if successful or ESP_ERR_NO_MEM if it is unable to allocate all parts

Definition at line 230 of file audio_pipeline.cpp.

◆ decode_task()

void esphome::speaker::AudioPipeline::decode_task ( void *  params)
staticprotected

Definition at line 430 of file audio_pipeline.cpp.

◆ delete_tasks_()

void esphome::speaker::AudioPipeline::delete_tasks_ ( )
protected

Resets the task related pointers and deallocates their stacks.

Definition at line 303 of file audio_pipeline.cpp.

◆ get_playback_ms()

uint32_t esphome::speaker::AudioPipeline::get_playback_ms ( )
inline

Definition at line 94 of file audio_pipeline.h.

◆ process_state()

AudioPipelineState esphome::speaker::AudioPipeline::process_state ( )

Processes the state of the audio pipeline based on the info_error_queue_ and event_group_.

Handles creating and stopping the pipeline tasks. Needs to be regularly called to update the internal pipeline state.

Returns
AudioPipelineState

Definition at line 102 of file audio_pipeline.cpp.

◆ read_task()

void esphome::speaker::AudioPipeline::read_task ( void *  params)
staticprotected

Definition at line 339 of file audio_pipeline.cpp.

◆ resume_tasks()

void esphome::speaker::AudioPipeline::resume_tasks ( )

Resumes any running tasks.

Definition at line 93 of file audio_pipeline.cpp.

◆ set_pause_state()

void esphome::speaker::AudioPipeline::set_pause_state ( bool  pause_state)

Definition at line 78 of file audio_pipeline.cpp.

◆ start_file()

void esphome::speaker::AudioPipeline::start_file ( audio::AudioFile audio_file)

Starts an audio pipeline given a AudioFile pointer.

Parameters
audio_filepointer to an AudioFile object
Returns
ESP_OK if successful or an appropriate error if not

Definition at line 65 of file audio_pipeline.cpp.

◆ start_tasks_()

esp_err_t esphome::speaker::AudioPipeline::start_tasks_ ( )
protected

Common start code for the pipeline, regardless if the source is a file or url.

Returns
ESP_OK if successful or an appropriate error if not

Definition at line 247 of file audio_pipeline.cpp.

◆ start_url()

void esphome::speaker::AudioPipeline::start_url ( const std::string &  uri)

Starts an audio pipeline given a media url.

Parameters
urimedia file url
Returns
ESP_OK if successful or an appropriate error if not

Definition at line 57 of file audio_pipeline.cpp.

◆ stop()

esp_err_t esphome::speaker::AudioPipeline::stop ( )

Stops the pipeline.

Sends a stop signal to each task (if running) and clears the ring buffers.

Returns
ESP_OK if successful or ESP_ERR_TIMEOUT if the tasks did not indicate they stopped

Definition at line 73 of file audio_pipeline.cpp.

◆ suspend_tasks()

void esphome::speaker::AudioPipeline::suspend_tasks ( )

Suspends any running tasks.

Definition at line 84 of file audio_pipeline.cpp.

Field Documentation

◆ base_name_

std::string esphome::speaker::AudioPipeline::base_name_
protected

Definition at line 110 of file audio_pipeline.h.

◆ buffer_size_

size_t esphome::speaker::AudioPipeline::buffer_size_
protected

Definition at line 132 of file audio_pipeline.h.

◆ current_audio_file_

audio::AudioFile* esphome::speaker::AudioPipeline::current_audio_file_ {nullptr}
protected

Definition at line 127 of file audio_pipeline.h.

◆ current_audio_file_type_

audio::AudioFileType esphome::speaker::AudioPipeline::current_audio_file_type_
protected

Definition at line 129 of file audio_pipeline.h.

◆ current_audio_stream_info_

audio::AudioStreamInfo esphome::speaker::AudioPipeline::current_audio_stream_info_
protected

Definition at line 130 of file audio_pipeline.h.

◆ current_uri_

std::string esphome::speaker::AudioPipeline::current_uri_ {}
protected

Definition at line 126 of file audio_pipeline.h.

◆ decode_task_handle_

TaskHandle_t esphome::speaker::AudioPipeline::decode_task_handle_ {nullptr}
protected

Definition at line 151 of file audio_pipeline.h.

◆ decode_task_stack_

StaticTask_t esphome::speaker::AudioPipeline::decode_task_stack_
protected

Definition at line 152 of file audio_pipeline.h.

◆ decode_task_stack_buffer_

StackType_t* esphome::speaker::AudioPipeline::decode_task_stack_buffer_ {nullptr}
protected

Definition at line 153 of file audio_pipeline.h.

◆ event_group_

EventGroupHandle_t esphome::speaker::AudioPipeline::event_group_ {nullptr}
protected

Definition at line 138 of file audio_pipeline.h.

◆ hard_stop_

bool esphome::speaker::AudioPipeline::hard_stop_ {false}
protected

Definition at line 115 of file audio_pipeline.h.

◆ info_error_queue_

QueueHandle_t esphome::speaker::AudioPipeline::info_error_queue_ {nullptr}
protected

Definition at line 141 of file audio_pipeline.h.

◆ is_playing_

bool esphome::speaker::AudioPipeline::is_playing_ {false}
protected

Definition at line 116 of file audio_pipeline.h.

◆ pause_state_

bool esphome::speaker::AudioPipeline::pause_state_ {false}
protected

Definition at line 117 of file audio_pipeline.h.

◆ pending_file_

bool esphome::speaker::AudioPipeline::pending_file_ {false}
protected

Definition at line 122 of file audio_pipeline.h.

◆ pending_url_

bool esphome::speaker::AudioPipeline::pending_url_ {false}
protected

Definition at line 121 of file audio_pipeline.h.

◆ playback_ms_

uint32_t esphome::speaker::AudioPipeline::playback_ms_ {0}
protected

Definition at line 113 of file audio_pipeline.h.

◆ priority_

UBaseType_t esphome::speaker::AudioPipeline::priority_
protected

Definition at line 111 of file audio_pipeline.h.

◆ raw_file_ring_buffer_

std::weak_ptr<RingBuffer> esphome::speaker::AudioPipeline::raw_file_ring_buffer_
protected

Definition at line 135 of file audio_pipeline.h.

◆ read_task_handle_

TaskHandle_t esphome::speaker::AudioPipeline::read_task_handle_ {nullptr}
protected

Definition at line 145 of file audio_pipeline.h.

◆ read_task_stack_

StaticTask_t esphome::speaker::AudioPipeline::read_task_stack_
protected

Definition at line 146 of file audio_pipeline.h.

◆ read_task_stack_buffer_

StackType_t* esphome::speaker::AudioPipeline::read_task_stack_buffer_ {nullptr}
protected

Definition at line 147 of file audio_pipeline.h.

◆ speaker_

speaker::Speaker* esphome::speaker::AudioPipeline::speaker_ {nullptr}
protected

Definition at line 124 of file audio_pipeline.h.

◆ task_stack_in_psram_

bool esphome::speaker::AudioPipeline::task_stack_in_psram_
protected

Definition at line 118 of file audio_pipeline.h.

◆ transfer_buffer_size_

size_t esphome::speaker::AudioPipeline::transfer_buffer_size_
protected

Definition at line 133 of file audio_pipeline.h.


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