Audio Pipeline

Dynamic combination of a group of linked Elements is done using the Audio Pipeline. You do not deal with the individual elements but with just one audio pipeline. Every element is connected by a ringbuffer. The Audio Pipeline also takes care of forwarding messages from the element tasks to an application.

A diagram below presents organization of three elements, HTTP reader stream, MP3 decoder and I2S writer stream, in the Audio Pipeline, that has been used in player/pipeline_http_mp3 example.

Sample Organization of Elements in Audio Pipeline

API Reference

Header File

Functions

audio_pipeline_handle_t audio_pipeline_init(audio_pipeline_cfg_t *config)

Initialize audio_pipeline_handle_t object audio_pipeline is responsible for controlling the audio data stream and connecting the audio elements with the ringbuffer It will connect and start the audio element in order, responsible for retrieving the data from the previous element and passing it to the element after it. Also get events from each element, process events or pass it to a higher layer.

Parameters

config – The configuration - audio_pipeline_cfg_t

Returns

  • audio_pipeline_handle_t on success

  • NULL when any errors

esp_err_t audio_pipeline_deinit(audio_pipeline_handle_t pipeline)

This function removes all of the element’s links in audio_pipeline, cancels the registration of all events, invokes the destroy functions of the registered elements, and frees the memory allocated by the init function. Briefly, frees all memory.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

ESP_OK

esp_err_t audio_pipeline_register(audio_pipeline_handle_t pipeline, audio_element_handle_t el, const char *name)

Registering an element for audio_pipeline, each element can be registered multiple times, but name (as String) must be unique in audio_pipeline, which is used to identify the element for link creation mentioned in the audio_pipeline_link

Note

Because of stop pipeline or pause pipeline depend much on register order. Please register element strictly in the following order: input element first, process middle, output element last.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • el[in] The Audio Element Handle

  • name[in] The name identifier of the audio_element in this audio_pipeline

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_unregister(audio_pipeline_handle_t pipeline, audio_element_handle_t el)

Unregister the audio_element in audio_pipeline, remove it from the list.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • el[in] The Audio Element Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_run(audio_pipeline_handle_t pipeline)

Start Audio Pipeline.

      With this function audio_pipeline will create tasks for all elements,
      that have been linked using the linking functions.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_terminate(audio_pipeline_handle_t pipeline)

Stop Audio Pipeline.

      With this function audio_pipeline will destroy tasks of all elements,
      that have been linked using the linking functions.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_terminate_with_ticks(audio_pipeline_handle_t pipeline, TickType_t ticks_to_wait)

Stop Audio Pipeline with specific ticks for timeout.

      With this function audio_pipeline will destroy tasks of all elements,
      that have been linked using the linking functions.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • ticks_to_wait[in] The maximum amount of time to block wait for element destroy

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_pipeline_resume(audio_pipeline_handle_t pipeline)

This function will set all the elements to the RUNNING state and process the audio data as an inherent feature of audio_pipeline.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_pause(audio_pipeline_handle_t pipeline)

This function will set all the elements to the PAUSED state. Everything remains the same except the data processing is stopped.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_stop(audio_pipeline_handle_t pipeline)

Stop all of the linked elements. Used with audio_pipeline_wait_for_stop to keep in sync. The link state of the elements in the pipeline is kept, events are still registered. The stopped audio_pipeline restart by audio_pipeline_resume.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_wait_for_stop(audio_pipeline_handle_t pipeline)

The audio_pipeline_stop function sends requests to the elements and exits. But they need time to get rid of time-blocking tasks. This function will wait portMAX_DELAY until all the Elements in the pipeline actually stop.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_wait_for_stop_with_ticks(audio_pipeline_handle_t pipeline, TickType_t ticks_to_wait)

The audio_pipeline_stop function sends requests to the elements and exits. But they need time to get rid of time-blocking tasks. This function will wait ticks_to_wait until all the Elements in the pipeline actually stop.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • ticks_to_wait[in] The maximum amount of time to block wait for stop

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_link(audio_pipeline_handle_t pipeline, const char *link_tag[], int link_num)

The audio_element added to audio_pipeline will be unconnected before it is called by this function. Based on element’s name already registered by audio_pipeline_register, the path of the data will be linked in the order of the link_tag. Element at index 0 is first, and index link_num -1 is final. As well as audio_pipeline will subscribe all element’s events.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • link_tag – Array of element name was registered by audio_pipeline_register

  • link_num[in] Total number of elements of the link_tag array

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_unlink(audio_pipeline_handle_t pipeline)

Removes the connection of the elements, as well as unsubscribe events.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

audio_element_handle_t audio_pipeline_get_el_by_tag(audio_pipeline_handle_t pipeline, const char *tag)

Find un-kept element from registered pipeline by tag.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • tag[in] A char pointer

Returns

  • NULL when any errors

  • Others on success

audio_element_handle_t audio_pipeline_get_el_once(audio_pipeline_handle_t pipeline, const audio_element_handle_t start_el, const char *tag)

Based on beginning element to find un-kept element from registered pipeline by tag.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • start_el[in] Specific beginning element

  • tag[in] A char pointer

Returns

  • NULL when any errors

  • Others on success

esp_err_t audio_pipeline_remove_listener(audio_pipeline_handle_t pipeline)

Remove event listener from this audio_pipeline.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_set_listener(audio_pipeline_handle_t pipeline, audio_event_iface_handle_t evt)

Set event listner for this audio_pipeline, any event from this pipeline can be listen to by evt

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • evt[in] The Event Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

audio_event_iface_handle_t audio_pipeline_get_event_iface(audio_pipeline_handle_t pipeline)

Get the event iface using by this pipeline.

Parameters

pipeline[in] The pipeline

Returns

The Event Handle

Insert the specific audio_element to audio_pipeline, previous element connect to the next element by ring buffer.

Parameters
  • pipeline[in] The audio pipeline handle

  • first[in] Previous element is first input element, need to set true

  • prev[in] Previous element

  • conect_rb[in] Connect ring buffer

  • next[in] Next element

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_pipeline_register_more(audio_pipeline_handle_t pipeline, audio_element_handle_t element_1, ...)

Register a NULL-terminated list of elements to audio_pipeline.

Parameters
  • pipeline[in] The audio pipeline handle

  • element_1[in] The element to add to the audio_pipeline.

  • ...[in] Additional elements to add to the audio_pipeline.

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_pipeline_unregister_more(audio_pipeline_handle_t pipeline, audio_element_handle_t element_1, ...)

Unregister a NULL-terminated list of elements to audio_pipeline.

Parameters
  • pipeline[in] The audio pipeline handle

  • element_1[in] The element to add to the audio_pipeline.

  • ...[in] Additional elements to add to the audio_pipeline.

Returns

  • ESP_OK

  • ESP_FAIL

Adds a NULL-terminated list of elements to audio_pipeline.

Parameters
  • pipeline[in] The audio pipeline handle

  • element_1[in] The element to add to the audio_pipeline.

  • ...[in] Additional elements to add to the audio_pipeline.

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_pipeline_listen_more(audio_pipeline_handle_t pipeline, audio_element_handle_t element_1, ...)

Subscribe a NULL-terminated list of element’s events to audio_pipeline.

Parameters
  • pipeline[in] The audio pipeline handle

  • element_1[in] The element event to subscribe to the audio_pipeline.

  • ...[in] Additional elements event to subscribe to the audio_pipeline.

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_pipeline_check_items_state(audio_pipeline_handle_t pipeline, audio_element_handle_t dest_el, audio_element_status_t status)

Update the destination element state and check the all of linked elements state are same.

Parameters
  • pipeline[in] The audio pipeline handle

  • dest_el[in] Destination element

  • status[in] The new status

Returns

  • ESP_OK All linked elements state are same.

  • ESP_FAIL All linked elements state are not same.

esp_err_t audio_pipeline_reset_items_state(audio_pipeline_handle_t pipeline)

Reset pipeline element items state to AEL_STATUS_NONE

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_reset_ringbuffer(audio_pipeline_handle_t pipeline)

Reset pipeline element ringbuffer.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_reset_elements(audio_pipeline_handle_t pipeline)

Reset Pipeline linked elements state.

Parameters

pipeline[in] The Audio Pipeline Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_reset_kept_state(audio_pipeline_handle_t pipeline, audio_element_handle_t el)

Reset the specific element kept state.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • el[in] The Audio element Handle

Returns

  • ESP_OK on success

  • ESP_FAIL when any errors

esp_err_t audio_pipeline_breakup_elements(audio_pipeline_handle_t pipeline, audio_element_handle_t kept_ctx_el)

Break up all the linked elements of specific pipeline. The include and before kept_ctx_el working (AEL_STATE_RUNNING or AEL_STATE_PAUSED) elements and connected ringbuffer will be reserved.

Note

There is no element reserved when kept_ctx_el is NULL. This function will unsubscribe all element’s events.

Parameters
  • pipeline[in] The audio pipeline handle

  • kept_ctx_el[in] Destination keep elements

Returns

  • ESP_OK All linked elements state are same.

  • ESP_ERR_INVALID_ARG Invalid parameters.

esp_err_t audio_pipeline_relink(audio_pipeline_handle_t pipeline, const char *link_tag[], int link_num)

Basing on element’s name already registered by audio_pipeline_register, relink the pipeline following the order of names in the `link_tag.

Note

If the ringbuffer is not enough to connect the new pipeline will create new ringbuffer.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • link_tag – Array of elements name that was registered by audio_pipeline_register

  • link_num[in] Total number of elements of the link_tag array

Returns

  • ESP_OK All linked elements state are same.

  • ESP_FAIL Error.

  • ESP_ERR_INVALID_ARG Invalid parameters.

Adds a NULL-terminated list of elements to audio_pipeline.

Note

If the ringbuffer is not enough to connect the new pipeline will create new ringbuffer.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • element_1[in] The element to add to the audio_pipeline.

  • ...[in] Additional elements to add to the audio_pipeline.

Returns

  • ESP_OK All linked elements state are same.

  • ESP_FAIL Error.

  • ESP_ERR_INVALID_ARG Invalid parameters.

esp_err_t audio_pipeline_change_state(audio_pipeline_handle_t pipeline, audio_element_state_t new_state)

Set the pipeline state.

Parameters
  • pipeline[in] The Audio Pipeline Handle

  • new_state[in] The new state will be set

Returns

  • ESP_OK All linked elements state are same.

  • ESP_FAIL Error.

Structures

struct audio_pipeline_cfg

Audio Pipeline configurations.

Public Members

int rb_size

Audio Pipeline ringbuffer size

Macros

DEFAULT_PIPELINE_RINGBUF_SIZE
DEFAULT_AUDIO_PIPELINE_CONFIG()

Type Definitions

typedef struct audio_pipeline *audio_pipeline_handle_t
typedef struct audio_pipeline_cfg audio_pipeline_cfg_t

Audio Pipeline configurations.