Sound Open Firmware
Loading...
Searching...
No Matches
Audio Buffer & Stream Infrastructure

Interconnect buffers, circular stream buffers, abstract audio buffers, and lockless ring buffers. More...

Files

file  audio_buffer.h
 Audio buffer operations, descriptors, and unified audio buffer interfaces.
 
file  buffer.h
 Component interconnect buffer allocation and stream handling.
 
file  ring_buffer.h
 Lockless async circular ring buffer for cross-core audio processing.
 

Data Structures

struct  audio_buffer_ops
 Audio buffer virtual operations table. More...
 
struct  sof_audio_buffer
 Base class for all audio buffers. More...
 
struct  audio_stream
 Audio stream is a circular buffer aware of audio format of the data in the buffer so provides API for reading and writing not only bytes, but also samples and frames. More...
 
struct  cir_buf_ptr
 
struct  comp_buffer
 Audio component interconnect buffer connecting two pipeline components. More...
 
struct  buffer_cb_transact
 Transaction descriptor passed to buffer probe callbacks. More...
 
struct  ring_buffer
 Lockless asynchronous circular ring buffer structure. More...
 

Macros

#define audio_stream_read_frag(buffer, idx, size)    audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, size)
 Retrieves readable address of a sample at specified index (see versions of this macro specialized for various sample types).
 
#define audio_stream_read_frag_s16(buffer, idx)    audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, sizeof(int16_t))
 Retrieves readable address of a signed 16-bit sample at specified index.
 
#define audio_stream_read_frag_s32(buffer, idx)    audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, sizeof(int32_t))
 Retrieves readable address of a signed 32-bit sample at specified index.
 
#define audio_stream_write_frag(buffer, idx, size)    audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, size)
 Retrieves writeable address of a sample at specified index (see versions of this macro specialized for various sample types).
 
#define audio_stream_write_frag_s16(buffer, idx)    audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, sizeof(int16_t))
 Retrieves writeable address of a signed 16-bit sample at specified index.
 
#define audio_stream_write_frag_s32(buffer, idx)    audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, sizeof(int32_t))
 Retrieves writeable address of a signed 32-bit sample at specified index.
 
#define audio_stream_get_frag(buffer, ptr, idx, sample_size)    audio_stream_wrap(buffer, (char *)(ptr) + ((idx) * (sample_size)))
 Retrieves address of sample (space for sample) at specified index within the buffer.
 
#define buffer_from_list(ptr, dir)
 Retrieve enclosing comp_buffer from a list node depending on traversal direction.
 
#define buffer_set_cb(buffer, func, data, type)
 Set transaction callback on a component buffer.
 

Functions

static struct sof_sink * audio_buffer_get_sink (struct sof_audio_buffer *buffer)
 Return pointer to sink interface of audio buffer.
 
static struct sof_source * audio_buffer_get_source (struct sof_audio_buffer *buffer)
 Return pointer to source interface of audio buffer.
 
static bool audio_buffer_is_shared (struct sof_audio_buffer *buffer)
 Check if audio buffer is shared across cores.
 
static bool audio_buffer_hw_params_configured (struct sof_audio_buffer *buffer)
 Check if buffer hardware parameters are configured.
 
static void audio_buffer_set_hw_params_configured (struct sof_audio_buffer *buffer)
 Mark buffer hardware parameters as configured (state set to READY).
 
static void audio_buffer_reset_params (struct sof_audio_buffer *buffer)
 Reset buffer parameters state to initial.
 
static enum sof_audio_buffer_state audio_buffer_get_state (const struct sof_audio_buffer *buffer)
 Retrieve current buffer state.
 
static void audio_buffer_set_state (struct sof_audio_buffer *buffer, enum sof_audio_buffer_state state)
 Set buffer state.
 
static void audio_buffer_set_eos (struct sof_audio_buffer *buffer)
 Mark buffer state as end-of-stream (EOS).
 
static uint16_t audio_buffer_get_chmap (struct sof_audio_buffer *buffer, size_t index)
 Retrieve channel map value for a given channel index.
 
static void audio_buffer_set_chmap (struct sof_audio_buffer *buffer, size_t index, uint16_t value)
 Set channel map value for a given channel index.
 
static struct sof_audio_stream_params * audio_buffer_get_stream_params (struct sof_audio_buffer *buffer)
 Retrieve pointer to runtime stream parameters.
 
static struct sof_audio_buffer * sof_audio_buffer_from_sink (struct sof_sink *sink)
 Retrieve enclosing sof_audio_buffer from sink interface pointer.
 
static struct sof_audio_buffer * sof_audio_buffer_from_source (struct sof_source *source)
 Retrieve enclosing sof_audio_buffer from source interface pointer.
 
void audio_buffer_init (struct sof_audio_buffer *buffer, uint32_t buffer_type, bool is_shared, const struct source_ops *source_ops, const struct sink_ops *sink_ops, const struct audio_buffer_ops *audio_buffer_ops, struct sof_audio_stream_params *audio_stream_params)
 Initialize audio buffer structure and virtual operation tables.
 
void audio_buffer_free (struct sof_audio_buffer *buffer)
 Free audio buffer and all allocated resources.
 
static void audio_buffer_reset (struct sof_audio_buffer *buffer)
 Reset all buffer data and positions leaving configuration intact.
 
int audio_buffer_source_set_ipc_params (struct sof_source *source, struct sof_ipc_stream_params *params, bool force_update)
 Set IPC stream parameters via source interface wrapper.
 
int audio_buffer_source_on_audio_format_set (struct sof_source *source)
 Audio format set callback via source interface wrapper.
 
int audio_buffer_source_set_alignment_constants (struct sof_source *source, const uint32_t byte_align, const uint32_t frame_align_req)
 Set alignment constraints via source interface wrapper.
 
int audio_buffer_sink_set_ipc_params (struct sof_sink *sink, struct sof_ipc_stream_params *params, bool force_update)
 Set IPC stream parameters via sink interface wrapper.
 
int audio_buffer_sink_on_audio_format_set (struct sof_sink *sink)
 Audio format set callback via sink interface wrapper.
 
int audio_buffer_sink_set_alignment_constants (struct sof_sink *sink, const uint32_t byte_align, const uint32_t frame_align_req)
 Set alignment constraints via sink interface wrapper.
 
uint32_t audio_buffer_sink_get_lft (struct sof_sink *sink)
 Get linear free time (LFT) duration in microseconds from sink interface wrapper.
 
void audio_stream_recalc_align (struct audio_stream *stream)
 
static void * audio_stream_get_rptr (const struct audio_stream *buf)
 
static void * audio_stream_get_wptr (const struct audio_stream *buf)
 
static void * audio_stream_get_end_addr (const struct audio_stream *buf)
 
static void * audio_stream_get_addr (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_size (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_avail (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_free (const struct audio_stream *buf)
 
static enum sof_ipc_frame audio_stream_get_frm_fmt (const struct audio_stream *buf)
 
static enum sof_ipc_frame audio_stream_get_valid_fmt (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_rate (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_channels (const struct audio_stream *buf)
 
static bool audio_stream_get_underrun (const struct audio_stream *buf)
 
static uint32_t audio_stream_get_buffer_fmt (const struct audio_stream *buf)
 
static bool audio_stream_get_overrun (const struct audio_stream *buf)
 
static void audio_stream_set_rptr (struct audio_stream *buf, void *val)
 
static void audio_stream_set_wptr (struct audio_stream *buf, void *val)
 
static void audio_stream_set_end_addr (struct audio_stream *buf, void *val)
 
static void audio_stream_set_addr (struct audio_stream *buf, void *val)
 
static void audio_stream_set_size (struct audio_stream *buf, uint32_t val)
 
static void audio_stream_set_avail (struct audio_stream *buf, uint32_t val)
 
static void audio_stream_set_free (struct audio_stream *buf, uint32_t val)
 
static void audio_stream_set_frm_fmt (struct audio_stream *buf, enum sof_ipc_frame val)
 
static void audio_stream_set_valid_fmt (struct audio_stream *buf, enum sof_ipc_frame val)
 
static void audio_stream_set_rate (struct audio_stream *buf, uint32_t val)
 
static void audio_stream_set_channels (struct audio_stream *buf, uint16_t val)
 
static void audio_stream_set_underrun (struct audio_stream *buf, bool underrun_permitted)
 
static void audio_stream_set_overrun (struct audio_stream *buf, bool overrun_permitted)
 
static void audio_stream_set_buffer_fmt (struct audio_stream *buf, uint32_t buffer_fmt)
 
static uint32_t audio_stream_frame_bytes (const struct audio_stream *buf)
 Calculates period size in bytes based on component stream's parameters.
 
static uint32_t audio_stream_sample_bytes (const struct audio_stream *buf)
 Calculates sample size in bytes based on component stream's parameters.
 
void audio_stream_set_align (const uint32_t byte_align, const uint32_t frame_align_req, struct audio_stream *stream)
 Set processing alignment requirements.
 
static int audio_stream_set_params (struct audio_stream *buffer, struct sof_ipc_stream_params *params)
 Applies parameters to the buffer.
 
static uint32_t audio_stream_period_bytes (const struct audio_stream *buf, uint32_t frames)
 Calculates period size in bytes based on component stream's parameters.
 
static void * audio_stream_wrap (const struct audio_stream *buffer, void *ptr)
 Verifies the pointer and performs rollover when reached the end of the buffer.
 
static void * audio_stream_rewind_wrap (const struct audio_stream *buffer, void *ptr)
 Verifies the pointer and performs rollover when reached the end of the buffer.
 
static uint32_t audio_stream_get_avail_bytes (const struct audio_stream *stream)
 Calculates available data in bytes, handling underrun_permitted behaviour.
 
static uint32_t audio_stream_get_avail_samples (const struct audio_stream *stream)
 Calculates available data in samples, handling underrun_permitted behaviour.
 
static uint32_t audio_stream_get_avail_frames (const struct audio_stream *stream)
 Calculates available data in frames, handling underrun_permitted behaviour.
 
static uint32_t audio_stream_get_free_bytes (const struct audio_stream *stream)
 Calculates free space in bytes, handling overrun_permitted behaviour.
 
static uint32_t audio_stream_get_free_samples (const struct audio_stream *stream)
 Calculates free space in samples, handling overrun_permitted behaviour.
 
static uint32_t audio_stream_get_free_frames (const struct audio_stream *stream)
 Calculates free space in frames, handling overrun_permitted behaviour.
 
static int audio_stream_can_copy_bytes (const struct audio_stream *source, const struct audio_stream *sink, uint32_t bytes)
 Verifies whether specified number of bytes can be copied from source buffer to sink buffer.
 
static uint32_t audio_stream_get_copy_bytes (const struct audio_stream *source, const struct audio_stream *sink)
 Computes maximum number of bytes that can be copied from source buffer to sink buffer, verifying number of bytes available in source vs.
 
static uint32_t audio_stream_avail_frames (const struct audio_stream *source, const struct audio_stream *sink)
 Computes maximum number of frames that can be copied from source buffer to sink buffer, verifying number of available source frames vs.
 
static uint32_t audio_stream_align_frames_round_down (const struct audio_stream *stream, uint32_t frames)
 Rounds down a frame count to meet the alignment constraint of the stream.
 
static uint32_t audio_stream_align_frames_round_up (const struct audio_stream *stream, uint32_t frames)
 Rounds up a frame count to meet the alignment constraint of the stream.
 
static uint32_t audio_stream_align_frames_round_nearest (const struct audio_stream *stream, uint32_t frames)
 Rounds to nearest a frame count to meet the alignment constraint of the stream.
 
static uint32_t audio_stream_avail_frames_aligned (const struct audio_stream *source, const struct audio_stream *sink)
 Computes maximum number of frames aligned with source align criteria that can be copied from source buffer to sink buffer, verifying number of available source frames vs.
 
static void audio_stream_produce (struct audio_stream *buffer, uint32_t bytes)
 Updates the buffer state after writing to the buffer.
 
static void audio_stream_consume (struct audio_stream *buffer, uint32_t bytes)
 Updates the buffer state after reading from the buffer.
 
static void audio_stream_reset (struct audio_stream *buffer)
 Resets the buffer.
 
void audio_stream_init (struct audio_stream *audio_stream, void *buff_addr, uint32_t size)
 Initializes the buffer with specified memory block and size.
 
static void audio_stream_invalidate (struct audio_stream *buffer, uint32_t bytes)
 Invalidates (in DSP d-cache) the buffer in range [r_ptr, r_ptr+bytes], with rollover if necessary.
 
static void audio_stream_writeback (struct audio_stream *buffer, uint32_t bytes)
 Writes back (from DSP d-cache) the buffer in range [w_ptr, w_ptr+bytes], with rollover if necessary.
 
static int audio_stream_bytes_without_wrap (const struct audio_stream *source, const void *ptr)
 Calculates numbers of bytes to buffer wrap.
 
static int audio_stream_rewind_bytes_without_wrap (const struct audio_stream *source, const void *ptr)
 Calculates numbers of bytes to buffer wrap when reading stream backwards from current sample pointed by ptr towards begin.
 
static uint32_t * audio_stream_rewind_wptr_by_bytes (const struct audio_stream *source, const uint32_t bytes)
 Calculate position of write pointer to the position before the data was copied to source buffer.
 
static int audio_stream_samples_without_wrap_s16 (const struct audio_stream *source, const void *ptr)
 Calculates numbers of s16 samples to buffer wrap when buffer is read forward towards end address.
 
static int audio_stream_samples_without_wrap_s24 (const struct audio_stream *source, const void *ptr)
 Calculates numbers of s24 samples to buffer wrap when buffer is read forward towards end address.
 
static int audio_stream_samples_without_wrap_s32 (const struct audio_stream *source, const void *ptr)
 Calculates numbers of s32 samples to buffer wrap when buffer is read forward towards end address.
 
static uint32_t audio_stream_frames_without_wrap (const struct audio_stream *source, const void *ptr)
 Calculates numbers of frames to buffer wrap and return minimum of calculated value.
 
int audio_stream_copy (const struct audio_stream *source, uint32_t ioffset, struct audio_stream *sink, uint32_t ooffset, uint32_t samples)
 Copies data from source buffer to sink buffer.
 
void cir_buf_copy (const void *src, const void *src_addr, const void *src_end, void *dst, void *dst_addr, void *dst_end, size_t byte_size)
 Copies data from one circular buffer to another circular buffer.
 
void audio_stream_copy_from_linear (const void *linear_source, int ioffset, struct audio_stream *sink, int ooffset, unsigned int samples)
 Copies data from linear source buffer to circular sink buffer.
 
void audio_stream_copy_to_linear (const struct audio_stream *source, int ioffset, void *linear_sink, int ooffset, unsigned int samples)
 Copies data from circular source buffer to linear sink buffer.
 
static int audio_stream_set_zero (struct audio_stream *buffer, uint32_t bytes)
 Writes zeros in range [w_ptr, w_ptr+bytes], with rollover if necessary.
 
static void cir_buf_set_zero (void *ptr, void *buf_addr, void *buf_end, uint32_t bytes)
 Writes zeros to circular buffer in range [ptr, ptr+bytes] with rollover if necessary.
 
static int audio_stream_fmt_conversion (enum ipc4_bit_depth depth, enum ipc4_bit_depth valid, enum sof_ipc_frame *frame_fmt, enum sof_ipc_frame *valid_fmt, enum ipc4_sample_type type)
 
static struct comp_dev * comp_buffer_get_source_component (const struct comp_buffer *buffer)
 Get component providing data to the buffer.
 
static struct comp_dev * comp_buffer_get_sink_component (const struct comp_buffer *buffer)
 Get component consuming data from the buffer.
 
static void comp_buffer_set_source_component (struct comp_buffer *buffer, struct comp_dev *comp)
 Set component providing data to the buffer.
 
static void comp_buffer_set_sink_component (struct comp_buffer *buffer, struct comp_dev *comp)
 Set component consuming data from the buffer.
 
static void comp_buffer_reset_source_list (struct comp_buffer *buffer)
 Reset buffer source list node.
 
static void comp_buffer_reset_sink_list (struct comp_buffer *buffer)
 Reset buffer sink list node.
 
struct comp_buffer * buffer_alloc (struct mod_alloc_ctx *alloc, size_t size, uint32_t flags, uint32_t align, bool is_shared)
 Allocate a pipeline component audio buffer with explicit size and alignment.
 
struct comp_buffer * buffer_alloc_range (struct mod_alloc_ctx *alloc, size_t preferred_size, size_t minimum_size, uint32_t flags, uint32_t align, bool is_shared)
 Allocate a pipeline component buffer with an elastic size range.
 
struct comp_buffer * buffer_new (struct mod_alloc_ctx *alloc, const struct sof_ipc_buffer *desc, bool is_shared)
 Instantiate a pipeline component buffer from an IPC configuration descriptor.
 
int buffer_set_size (struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
 Resize an existing pipeline component buffer.
 
int buffer_set_size_range (struct comp_buffer *buffer, size_t preferred_size, size_t minimum_size, uint32_t alignment)
 Resize a pipeline component buffer within a preferred-to-minimum range.
 
static struct comp_buffer * comp_buffer_get_from_source (struct sof_source *source)
 Retrieve enclosing comp_buffer from an audio source interface pointer.
 
static struct comp_buffer * comp_buffer_get_from_sink (struct sof_sink *sink)
 Retrieve enclosing comp_buffer from an audio sink interface pointer.
 
static void buffer_free (struct comp_buffer *buffer)
 Free an interconnect component buffer and its underlying memory.
 
void buffer_zero (struct comp_buffer *buffer)
 Zero-fill the entire payload of an interconnect buffer.
 
void comp_update_buffer_produce (struct comp_buffer *buffer, uint32_t bytes)
 Notify buffer that audio data has been produced by a component.
 
void comp_update_buffer_consume (struct comp_buffer *buffer, uint32_t bytes)
 Notify buffer that audio data has been consumed by a component.
 
int buffer_set_params (struct comp_buffer *buffer, struct sof_ipc_stream_params *params, bool force_update)
 Set audio stream parameters on a component buffer.
 
bool buffer_params_match (struct comp_buffer *buffer, struct sof_ipc_stream_params *params, uint32_t flag)
 Test if buffer stream parameters match requested parameters.
 
static void buffer_stream_invalidate (struct comp_buffer *buffer, uint32_t bytes)
 Invalidate cache for a shared buffer stream if incoherent.
 
static void buffer_stream_writeback (struct comp_buffer *buffer, uint32_t bytes)
 Write back cache for a shared buffer stream if incoherent.
 
int buffer_attach (struct comp_buffer *buffer, struct list_item *head, int dir)
 Attach a new buffer at the beginning of a component buffer list.
 
void buffer_detach (struct comp_buffer *buffer, struct list_item *head, int dir)
 Detach a buffer from anywhere in a component buffer list.
 
static struct comp_dev * buffer_get_comp (struct comp_buffer *buffer, int dir)
 Get component connected to buffer in specified traversal direction.
 
static uint32_t buffer_pipeline_id (const struct comp_buffer *buffer)
 Retrieve pipeline ID associated with a component buffer.
 
static void buffer_init_stream (struct comp_buffer *buffer, size_t size)
 Initialize circular stream buffer descriptor for a component buffer.
 
struct ring_buffer * ring_buffer_create (struct comp_dev *dev, size_t min_available, size_t min_free_space, bool is_shared, uint32_t id)
 Create and allocate a lockless async circular ring buffer.
 

Trace macros

struct tr_ctx buffer_tr
 
#define buf_get_id(buf_ptr)   ((buf_ptr)->stream.runtime_stream_params.id)
 Retrieves subid (comp id) from the buffer.
 
#define trace_buf_get_tr_ctx(buf_ptr)   (&(buf_ptr)->tctx)
 Retrieves trace context from the buffer.
 
#define buf_err(buf_ptr, __e, ...)
 Trace error message from buffer.
 
#define buf_warn(buf_ptr, __e, ...)
 Trace warning message from buffer.
 
#define buf_info(buf_ptr, __e, ...)
 Trace info message from buffer.
 
#define buf_dbg(buf_ptr, __e, ...)
 Trace debug message from buffer.
 

Buffer type identifiers

#define BUFFER_TYPE_LEGACY_BUFFER   1
 Legacy comp_buffer type (pipeline 1.0)
 
#define BUFFER_TYPE_RING_BUFFER   2
 Lockless async circular ring buffer type (cross-core)
 

Buffer callback types

#define BUFF_CB_TYPE_PRODUCE   BIT(0)
 Callback triggered on buffer produce.
 
#define BUFF_CB_TYPE_CONSUME   BIT(1)
 Callback triggered on buffer consume.
 

Buffer parameter update modes

#define BUFFER_UPDATE_IF_UNSET   0
 Update buffer parameters only if currently unset.
 
#define BUFFER_UPDATE_FORCE   1
 Force update buffer parameters regardless of current state.
 

Buffer parameter bitmasks

#define BUFF_PARAMS_FRAME_FMT   BIT(0)
 Buffer parameter bitmask: frame format.
 
#define BUFF_PARAMS_BUFFER_FMT   BIT(1)
 Buffer parameter bitmask: buffer format.
 
#define BUFF_PARAMS_RATE   BIT(2)
 Buffer parameter bitmask: sample rate.
 
#define BUFF_PARAMS_CHANNELS   BIT(3)
 Buffer parameter bitmask: channels count.
 

Buffer memory sharing usage

#define BUFFER_USAGE_SHARED   true
 Buffer used by multiple DSP cores and/or HW blocks.
 
#define BUFFER_USAGE_NOT_SHARED   false
 Buffer only used by one HW block.
 

Detailed Description

Interconnect buffers, circular stream buffers, abstract audio buffers, and lockless ring buffers.

Macro Definition Documentation

◆ audio_stream_get_frag

#define audio_stream_get_frag (   buffer,
  ptr,
  idx,
  sample_size 
)     audio_stream_wrap(buffer, (char *)(ptr) + ((idx) * (sample_size)))

Retrieves address of sample (space for sample) at specified index within the buffer.

Index is interpreted as an offset relative to the specified pointer, rollover is ensured.

Parameters
bufferCircular buffer.
ptrPointer to start from, it may be either read or write pointer.
idxIndex of the sample.
sample_sizeSize of the sample in bytes.
Returns
Pointer to the sample.

◆ audio_stream_read_frag

#define audio_stream_read_frag (   buffer,
  idx,
  size 
)     audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, size)

Retrieves readable address of a sample at specified index (see versions of this macro specialized for various sample types).

Parameters
bufferBuffer.
idxIndex of sample.
sizeSize of sample in bytes.
Returns
Pointer to the sample.

Once the consumer finishes reading samples from the buffer, it should "commit" the operation and update the buffer state by calling audio_stream_consume().

Note
Components should call comp_update_buffer_consume().
See also
audio_stream_get_frag().
audio_stream_consume().
comp_update_buffer_consume().

◆ audio_stream_read_frag_s16

#define audio_stream_read_frag_s16 (   buffer,
  idx 
)     audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, sizeof(int16_t))

Retrieves readable address of a signed 16-bit sample at specified index.

Parameters
bufferBuffer.
idxIndex of sample.
Returns
Pointer to the sample.
See also
audio_stream_get_frag().

◆ audio_stream_read_frag_s32

#define audio_stream_read_frag_s32 (   buffer,
  idx 
)     audio_stream_get_frag(buffer, (buffer)->r_ptr, idx, sizeof(int32_t))

Retrieves readable address of a signed 32-bit sample at specified index.

Parameters
bufferBuffer.
idxIndex of sample.
Returns
Pointer to the sample.
See also
audio_stream_get_frag().

◆ audio_stream_write_frag

#define audio_stream_write_frag (   buffer,
  idx,
  size 
)     audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, size)

Retrieves writeable address of a sample at specified index (see versions of this macro specialized for various sample types).

Parameters
bufferBuffer.
idxIndex of sample.
sizeSize of sample in bytes.
Returns
Pointer to the space for sample.

Once the producer finishes writing samples to the buffer, it should "commit" the operation and update the buffer state by calling audio_stream_produce().

Note
Components should call comp_update_buffer_produce().
See also
audio_stream_get_frag().
audio_stream_produce().
comp_update_buffer_produce().

◆ audio_stream_write_frag_s16

#define audio_stream_write_frag_s16 (   buffer,
  idx 
)     audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, sizeof(int16_t))

Retrieves writeable address of a signed 16-bit sample at specified index.

Parameters
bufferBuffer.
idxIndex of sample.
Returns
Pointer to the space for sample.
See also
audio_stream_get_frag().

◆ audio_stream_write_frag_s32

#define audio_stream_write_frag_s32 (   buffer,
  idx 
)     audio_stream_get_frag(buffer, (buffer)->w_ptr, idx, sizeof(int32_t))

Retrieves writeable address of a signed 32-bit sample at specified index.

Parameters
bufferBuffer.
idxIndex of sample.
Returns
Pointer to the space for sample.
See also
audio_stream_get_frag().

◆ buf_dbg

#define buf_dbg (   buf_ptr,
  __e,
  ... 
)
Value:
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)
#define trace_buf_get_tr_ctx(buf_ptr)
Retrieves trace context from the buffer.
Definition buffer.h:79
#define buf_get_id(buf_ptr)
Retrieves subid (comp id) from the buffer.
Definition buffer.h:55
static uint32_t buffer_pipeline_id(const struct comp_buffer *buffer)
Retrieve pipeline ID associated with a component buffer.
Definition buffer.h:487
Audio component interconnect buffer connecting two pipeline components.
Definition buffer.h:150
#define trace_dev_dbg(get_ctx_m, get_id_m, get_subid_m, dev, fmt,...)
Trace from a device on dbg level.
Definition trace-soflogger.h:411

Trace debug message from buffer.

◆ buf_err

#define buf_err (   buf_ptr,
  __e,
  ... 
)
Value:
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)
#define trace_dev_err(get_ctx_m, get_id_m, get_subid_m, dev, fmt,...)
Trace from a device on err level.
Definition trace-soflogger.h:393

Trace error message from buffer.

◆ buf_get_id

#define buf_get_id (   buf_ptr)    ((buf_ptr)->stream.runtime_stream_params.id)

Retrieves subid (comp id) from the buffer.

◆ buf_info

#define buf_info (   buf_ptr,
  __e,
  ... 
)
Value:
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)
#define trace_dev_info(get_ctx_m, get_id_m, get_subid_m, dev, fmt,...)
Trace from a device on info level.
Definition trace-soflogger.h:405

Trace info message from buffer.

◆ buf_warn

#define buf_warn (   buf_ptr,
  __e,
  ... 
)
Value:
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)
#define trace_dev_warn(get_ctx_m, get_id_m, get_subid_m, dev, fmt,...)
Trace from a device on warning level.
Definition trace-soflogger.h:399

Trace warning message from buffer.

◆ BUFF_CB_TYPE_CONSUME

#define BUFF_CB_TYPE_CONSUME   BIT(1)

Callback triggered on buffer consume.

◆ BUFF_CB_TYPE_PRODUCE

#define BUFF_CB_TYPE_PRODUCE   BIT(0)

Callback triggered on buffer produce.

◆ BUFF_PARAMS_BUFFER_FMT

#define BUFF_PARAMS_BUFFER_FMT   BIT(1)

Buffer parameter bitmask: buffer format.

◆ BUFF_PARAMS_CHANNELS

#define BUFF_PARAMS_CHANNELS   BIT(3)

Buffer parameter bitmask: channels count.

◆ BUFF_PARAMS_FRAME_FMT

#define BUFF_PARAMS_FRAME_FMT   BIT(0)

Buffer parameter bitmask: frame format.

◆ BUFF_PARAMS_RATE

#define BUFF_PARAMS_RATE   BIT(2)

Buffer parameter bitmask: sample rate.

◆ buffer_from_list

#define buffer_from_list (   ptr,
  dir 
)
Value:
((dir) == PPL_DIR_DOWNSTREAM ? \
container_of(ptr, struct comp_buffer, source_list) : \
container_of(ptr, struct comp_buffer, sink_list))
#define container_of(ptr, type, member)
Definition common.h:117
#define PPL_DIR_DOWNSTREAM
Downstream playback/processing direction.
Definition pipeline.h:65

Retrieve enclosing comp_buffer from a list node depending on traversal direction.

Parameters
[in]ptrList item pointer.
[in]dirPipeline traversal direction (PPL_DIR_DOWNSTREAM or PPL_DIR_UPSTREAM).
Returns
Pointer to enclosing struct comp_buffer.

◆ buffer_set_cb

#define buffer_set_cb (   buffer,
  func,
  data,
  type 
)
Value:
do { \
buffer->cb = func; \
buffer->cb_data = data; \
buffer->cb_type = type; \
} while (0)
uint8_t data[0]
Binary byte payload for raw controls.
Definition header.h:5
uint32_t type
Message type, symmetric to the incoming request.
Definition header.h:8

Set transaction callback on a component buffer.

Parameters
[in,out]bufferTarget component buffer.
[in]funcCallback function pointer.
[in]dataCallback user data.
[in]typeCallback trigger type (BUFF_CB_TYPE_*).

◆ BUFFER_TYPE_LEGACY_BUFFER

#define BUFFER_TYPE_LEGACY_BUFFER   1

Legacy comp_buffer type (pipeline 1.0)

◆ BUFFER_TYPE_RING_BUFFER

#define BUFFER_TYPE_RING_BUFFER   2

Lockless async circular ring buffer type (cross-core)

◆ BUFFER_UPDATE_FORCE

#define BUFFER_UPDATE_FORCE   1

Force update buffer parameters regardless of current state.

◆ BUFFER_UPDATE_IF_UNSET

#define BUFFER_UPDATE_IF_UNSET   0

Update buffer parameters only if currently unset.

◆ BUFFER_USAGE_NOT_SHARED

#define BUFFER_USAGE_NOT_SHARED   false

Buffer only used by one HW block.

◆ BUFFER_USAGE_SHARED

#define BUFFER_USAGE_SHARED   true

Buffer used by multiple DSP cores and/or HW blocks.

◆ trace_buf_get_tr_ctx

#define trace_buf_get_tr_ctx (   buf_ptr)    (&(buf_ptr)->tctx)

Retrieves trace context from the buffer.

Function Documentation

◆ audio_buffer_free()

void audio_buffer_free ( struct sof_audio_buffer *  buffer)

Free audio buffer and all allocated resources.

Parameters
[in,out]bufferPointer to audio buffer to free.

◆ audio_buffer_get_chmap()

static uint16_t audio_buffer_get_chmap ( struct sof_audio_buffer *  buffer,
size_t  index 
)
inlinestatic

Retrieve channel map value for a given channel index.

Parameters
[in]bufferPointer to audio buffer.
[in]indexChannel index.
Returns
Channel map value.

◆ audio_buffer_get_sink()

static struct sof_sink * audio_buffer_get_sink ( struct sof_audio_buffer *  buffer)
inlinestatic

Return pointer to sink interface of audio buffer.

Parameters
[in]bufferPointer to audio buffer.
Returns
Pointer to sink interface.

◆ audio_buffer_get_source()

static struct sof_source * audio_buffer_get_source ( struct sof_audio_buffer *  buffer)
inlinestatic

Return pointer to source interface of audio buffer.

Parameters
[in]bufferPointer to audio buffer.
Returns
Pointer to source interface.

◆ audio_buffer_get_state()

static enum sof_audio_buffer_state audio_buffer_get_state ( const struct sof_audio_buffer *  buffer)
inlinestatic

Retrieve current buffer state.

Parameters
[in]bufferPointer to audio buffer.
Returns
Current buffer state (enum sof_audio_buffer_state).

◆ audio_buffer_get_stream_params()

static struct sof_audio_stream_params * audio_buffer_get_stream_params ( struct sof_audio_buffer *  buffer)
inlinestatic

Retrieve pointer to runtime stream parameters.

Parameters
[in]bufferPointer to audio buffer.
Returns
Pointer to runtime stream parameters.

◆ audio_buffer_hw_params_configured()

static bool audio_buffer_hw_params_configured ( struct sof_audio_buffer *  buffer)
inlinestatic

Check if buffer hardware parameters are configured.

Parameters
[in]bufferPointer to audio buffer.
Returns
True if configured, false otherwise.

◆ audio_buffer_init()

void audio_buffer_init ( struct sof_audio_buffer *  buffer,
uint32_t  buffer_type,
bool  is_shared,
const struct source_ops *  source_ops,
const struct sink_ops *  sink_ops,
const struct audio_buffer_ops *  audio_buffer_ops,
struct sof_audio_stream_params *  audio_stream_params 
)

Initialize audio buffer structure and virtual operation tables.

Parameters
[in,out]bufferPointer to audio buffer.
[in]buffer_typeBuffer type identifier (BUFFER_TYPE_*).
[in]is_sharedTrue if buffer is shared between cores.
[in]source_opsPointer to source operations table.
[in]sink_opsPointer to sink operations table.
[in]audio_buffer_opsPointer to audio buffer operations table.
[in,out]audio_stream_paramsPointer to audio stream parameters.

◆ audio_buffer_is_shared()

static bool audio_buffer_is_shared ( struct sof_audio_buffer *  buffer)
inlinestatic

Check if audio buffer is shared across cores.

Parameters
[in]bufferPointer to audio buffer.
Returns
True if shared, false otherwise.

◆ audio_buffer_reset()

static void audio_buffer_reset ( struct sof_audio_buffer *  buffer)
inlinestatic

Reset all buffer data and positions leaving configuration intact.

Parameters
[in,out]bufferPointer to audio buffer.

◆ audio_buffer_reset_params()

static void audio_buffer_reset_params ( struct sof_audio_buffer *  buffer)
inlinestatic

Reset buffer parameters state to initial.

Parameters
[in,out]bufferPointer to audio buffer.

◆ audio_buffer_set_chmap()

static void audio_buffer_set_chmap ( struct sof_audio_buffer *  buffer,
size_t  index,
uint16_t  value 
)
inlinestatic

Set channel map value for a given channel index.

Parameters
[in,out]bufferPointer to audio buffer.
[in]indexChannel index.
[in]valueChannel map value to set.

◆ audio_buffer_set_eos()

static void audio_buffer_set_eos ( struct sof_audio_buffer *  buffer)
inlinestatic

Mark buffer state as end-of-stream (EOS).

Parameters
[in,out]bufferPointer to audio buffer.

◆ audio_buffer_set_hw_params_configured()

static void audio_buffer_set_hw_params_configured ( struct sof_audio_buffer *  buffer)
inlinestatic

Mark buffer hardware parameters as configured (state set to READY).

Parameters
[in,out]bufferPointer to audio buffer.

◆ audio_buffer_set_state()

static void audio_buffer_set_state ( struct sof_audio_buffer *  buffer,
enum sof_audio_buffer_state  state 
)
inlinestatic

Set buffer state.

Parameters
[in,out]bufferPointer to audio buffer.
[in]stateNew state to assign.

◆ audio_buffer_sink_get_lft()

uint32_t audio_buffer_sink_get_lft ( struct sof_sink *  sink)

Get linear free time (LFT) duration in microseconds from sink interface wrapper.

Parameters
[in]sinkPointer to sink interface.
Returns
Buffered duration in microseconds (us_in_buffer) calculated from source available data and sample rate.

◆ audio_buffer_sink_on_audio_format_set()

int audio_buffer_sink_on_audio_format_set ( struct sof_sink *  sink)

Audio format set callback via sink interface wrapper.

Parameters
[in,out]sinkPointer to sink interface.
Returns
0 on success, or negative error code on failure.

◆ audio_buffer_sink_set_alignment_constants()

int audio_buffer_sink_set_alignment_constants ( struct sof_sink *  sink,
const uint32_t  byte_align,
const uint32_t  frame_align_req 
)

Set alignment constraints via sink interface wrapper.

Parameters
[in,out]sinkPointer to sink interface.
[in]byte_alignByte alignment requirement in bytes.
[in]frame_align_reqFrame alignment requirement in frames.
Returns
0 on success, or negative error code on failure.

◆ audio_buffer_sink_set_ipc_params()

int audio_buffer_sink_set_ipc_params ( struct sof_sink *  sink,
struct sof_ipc_stream_params *  params,
bool  force_update 
)

Set IPC stream parameters via sink interface wrapper.

Parameters
[in,out]sinkPointer to sink interface.
[in]paramsStream parameters to apply.
[in]force_updateIf true, overwrite parameters unconditionally.
Returns
0 on success, or negative error code on failure.

◆ audio_buffer_source_on_audio_format_set()

int audio_buffer_source_on_audio_format_set ( struct sof_source *  source)

Audio format set callback via source interface wrapper.

Parameters
[in,out]sourcePointer to source interface.
Returns
0 on success, or negative error code on failure.

◆ audio_buffer_source_set_alignment_constants()

int audio_buffer_source_set_alignment_constants ( struct sof_source *  source,
const uint32_t  byte_align,
const uint32_t  frame_align_req 
)

Set alignment constraints via source interface wrapper.

Parameters
[in,out]sourcePointer to source interface.
[in]byte_alignByte alignment requirement in bytes.
[in]frame_align_reqFrame alignment requirement in frames.
Returns
0 on success, or negative error code on failure.

◆ audio_buffer_source_set_ipc_params()

int audio_buffer_source_set_ipc_params ( struct sof_source *  source,
struct sof_ipc_stream_params *  params,
bool  force_update 
)

Set IPC stream parameters via source interface wrapper.

Parameters
[in,out]sourcePointer to source interface.
[in]paramsStream parameters to apply.
[in]force_updateIf true, overwrite parameters unconditionally.
Returns
0 on success, or negative error code on failure.

◆ audio_stream_align_frames_round_down()

static uint32_t audio_stream_align_frames_round_down ( const struct audio_stream *  stream,
uint32_t  frames 
)
inlinestatic

Rounds down a frame count to meet the alignment constraint of the stream.

Parameters
streamAudio stream with alignment requirements set.
framesFrame count to round down.
Returns
Largest aligned frame count less than or equal to frames.

◆ audio_stream_align_frames_round_nearest()

static uint32_t audio_stream_align_frames_round_nearest ( const struct audio_stream *  stream,
uint32_t  frames 
)
inlinestatic

Rounds to nearest a frame count to meet the alignment constraint of the stream.

Parameters
streamAudio stream with alignment requirements set.
framesFrame count to round to nearest.
Returns
Aligned frame count.

◆ audio_stream_align_frames_round_up()

static uint32_t audio_stream_align_frames_round_up ( const struct audio_stream *  stream,
uint32_t  frames 
)
inlinestatic

Rounds up a frame count to meet the alignment constraint of the stream.

Parameters
streamAudio stream with alignment requirements set.
framesFrame count to round up.
Returns
Smallest aligned frame count greater than or equal to frames.

◆ audio_stream_avail_frames()

static uint32_t audio_stream_avail_frames ( const struct audio_stream *  source,
const struct audio_stream *  sink 
)
inlinestatic

Computes maximum number of frames that can be copied from source buffer to sink buffer, verifying number of available source frames vs.

free space available in sink.

Parameters
sourceSource buffer.
sinkSink buffer.
Returns
Number of frames.

◆ audio_stream_avail_frames_aligned()

static uint32_t audio_stream_avail_frames_aligned ( const struct audio_stream *  source,
const struct audio_stream *  sink 
)
inlinestatic

Computes maximum number of frames aligned with source align criteria that can be copied from source buffer to sink buffer, verifying number of available source frames vs.

free space available in sink.

Parameters
sourceBuffer of source.
sinkBuffer of sink.
Returns
Number of frames.

◆ audio_stream_bytes_without_wrap()

static int audio_stream_bytes_without_wrap ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of bytes to buffer wrap.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of data samples to buffer wrap.

◆ audio_stream_can_copy_bytes()

static int audio_stream_can_copy_bytes ( const struct audio_stream *  source,
const struct audio_stream *  sink,
uint32_t  bytes 
)
inlinestatic

Verifies whether specified number of bytes can be copied from source buffer to sink buffer.

Parameters
sourceSource buffer.
sinkSink buffer.
bytesNumber of bytes to copy.
Returns
0 if there is enough data in source and enough free space in sink.
1 if there is not enough free space in sink.
-1 if there is not enough data in source.

◆ audio_stream_consume()

static void audio_stream_consume ( struct audio_stream *  buffer,
uint32_t  bytes 
)
inlinestatic

Updates the buffer state after reading from the buffer.

Parameters
bufferBuffer to update.
bytesNumber of read bytes.

◆ audio_stream_copy()

int audio_stream_copy ( const struct audio_stream *  source,
uint32_t  ioffset,
struct audio_stream *  sink,
uint32_t  ooffset,
uint32_t  samples 
)

Copies data from source buffer to sink buffer.

Parameters
sourceSource buffer.
ioffsetOffset (in samples) in source buffer to start reading from.
sinkSink buffer.
ooffsetOffset (in samples) in sink buffer to start writing to.
samplesNumber of samples to copy.
Returns
number of processed samples.

◆ audio_stream_copy_from_linear()

void audio_stream_copy_from_linear ( const void *  linear_source,
int  ioffset,
struct audio_stream *  sink,
int  ooffset,
unsigned int  samples 
)

Copies data from linear source buffer to circular sink buffer.

Parameters
linear_sourceSource buffer.
ioffsetOffset (in samples) in source buffer to start reading from.
sinkSink buffer.
ooffsetOffset (in samples) in sink buffer to start writing to.
samplesNumber of samples to copy.

◆ audio_stream_copy_to_linear()

void audio_stream_copy_to_linear ( const struct audio_stream *  source,
int  ioffset,
void *  linear_sink,
int  ooffset,
unsigned int  samples 
)

Copies data from circular source buffer to linear sink buffer.

Parameters
sourceSource buffer.
ioffsetOffset (in samples) in source buffer to start reading from.
linear_sinkSink buffer.
ooffsetOffset (in samples) in sink buffer to start writing to.
samplesNumber of samples to copy.

◆ audio_stream_fmt_conversion()

static int audio_stream_fmt_conversion ( enum ipc4_bit_depth  depth,
enum ipc4_bit_depth  valid,
enum sof_ipc_frame *  frame_fmt,
enum sof_ipc_frame *  valid_fmt,
enum ipc4_sample_type  type 
)
inlinestatic

◆ audio_stream_frame_bytes()

static uint32_t audio_stream_frame_bytes ( const struct audio_stream *  buf)
inlinestatic

Calculates period size in bytes based on component stream's parameters.

Parameters
bufComponent buffer.
Returns
Period size in bytes.

◆ audio_stream_frames_without_wrap()

static uint32_t audio_stream_frames_without_wrap ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of frames to buffer wrap and return minimum of calculated value.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of data frames to buffer wrap.

◆ audio_stream_get_addr()

static void * audio_stream_get_addr ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_avail()

static uint32_t audio_stream_get_avail ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_avail_bytes()

static uint32_t audio_stream_get_avail_bytes ( const struct audio_stream *  stream)
inlinestatic

Calculates available data in bytes, handling underrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of data available for processing in bytes

◆ audio_stream_get_avail_frames()

static uint32_t audio_stream_get_avail_frames ( const struct audio_stream *  stream)
inlinestatic

Calculates available data in frames, handling underrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of data available for processing in frames

◆ audio_stream_get_avail_samples()

static uint32_t audio_stream_get_avail_samples ( const struct audio_stream *  stream)
inlinestatic

Calculates available data in samples, handling underrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of data available for processing in samples

◆ audio_stream_get_buffer_fmt()

static uint32_t audio_stream_get_buffer_fmt ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_channels()

static uint32_t audio_stream_get_channels ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_copy_bytes()

static uint32_t audio_stream_get_copy_bytes ( const struct audio_stream *  source,
const struct audio_stream *  sink 
)
inlinestatic

Computes maximum number of bytes that can be copied from source buffer to sink buffer, verifying number of bytes available in source vs.

free space available in sink.

Parameters
sourceSource buffer.
sinkSink buffer.
Returns
Number of bytes.

◆ audio_stream_get_end_addr()

static void * audio_stream_get_end_addr ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_free()

static uint32_t audio_stream_get_free ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_free_bytes()

static uint32_t audio_stream_get_free_bytes ( const struct audio_stream *  stream)
inlinestatic

Calculates free space in bytes, handling overrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of space free in bytes

◆ audio_stream_get_free_frames()

static uint32_t audio_stream_get_free_frames ( const struct audio_stream *  stream)
inlinestatic

Calculates free space in frames, handling overrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of space free in frames

◆ audio_stream_get_free_samples()

static uint32_t audio_stream_get_free_samples ( const struct audio_stream *  stream)
inlinestatic

Calculates free space in samples, handling overrun_permitted behaviour.

Parameters
streamStream pointer
Returns
amount of space free in samples

◆ audio_stream_get_frm_fmt()

static enum sof_ipc_frame audio_stream_get_frm_fmt ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_overrun()

static bool audio_stream_get_overrun ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_rate()

static uint32_t audio_stream_get_rate ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_rptr()

static void * audio_stream_get_rptr ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_size()

static uint32_t audio_stream_get_size ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_underrun()

static bool audio_stream_get_underrun ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_valid_fmt()

static enum sof_ipc_frame audio_stream_get_valid_fmt ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_get_wptr()

static void * audio_stream_get_wptr ( const struct audio_stream *  buf)
inlinestatic

◆ audio_stream_init()

void audio_stream_init ( struct audio_stream *  audio_stream,
void *  buff_addr,
uint32_t  size 
)

Initializes the buffer with specified memory block and size.

Parameters
audio_streamthe audio_stream a to initialize.
buff_addrAddress of the memory block to assign.
sizeSize of the memory block in bytes.

◆ audio_stream_invalidate()

static void audio_stream_invalidate ( struct audio_stream *  buffer,
uint32_t  bytes 
)
inlinestatic

Invalidates (in DSP d-cache) the buffer in range [r_ptr, r_ptr+bytes], with rollover if necessary.

Parameters
bufferBuffer.
bytesSize of the fragment to invalidate.

◆ audio_stream_period_bytes()

static uint32_t audio_stream_period_bytes ( const struct audio_stream *  buf,
uint32_t  frames 
)
inlinestatic

Calculates period size in bytes based on component stream's parameters.

Parameters
bufComponent buffer.
framesNumber of processing frames.
Returns
Period size in bytes.

◆ audio_stream_produce()

static void audio_stream_produce ( struct audio_stream *  buffer,
uint32_t  bytes 
)
inlinestatic

Updates the buffer state after writing to the buffer.

Parameters
bufferBuffer to update.
bytesNumber of written bytes.

◆ audio_stream_recalc_align()

void audio_stream_recalc_align ( struct audio_stream *  stream)

◆ audio_stream_reset()

static void audio_stream_reset ( struct audio_stream *  buffer)
inlinestatic

Resets the buffer.

Parameters
bufferBuffer to reset.

◆ audio_stream_rewind_bytes_without_wrap()

static int audio_stream_rewind_bytes_without_wrap ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of bytes to buffer wrap when reading stream backwards from current sample pointed by ptr towards begin.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of bytes to buffer wrap. For number of samples calculate need to add size of sample to returned bytes count.

◆ audio_stream_rewind_wptr_by_bytes()

static uint32_t * audio_stream_rewind_wptr_by_bytes ( const struct audio_stream *  source,
const uint32_t  bytes 
)
inlinestatic

Calculate position of write pointer to the position before the data was copied to source buffer.

Parameters
sourceStream to get information from.
bytesNumber of bytes copied to source buffer.
Returns
Previous position of the write pointer.

◆ audio_stream_rewind_wrap()

static void * audio_stream_rewind_wrap ( const struct audio_stream *  buffer,
void *  ptr 
)
inlinestatic

Verifies the pointer and performs rollover when reached the end of the buffer.

Parameters
bufferBuffer accessed by the pointer.
ptrPointer
Returns
Pointer, adjusted if necessary.

◆ audio_stream_sample_bytes()

static uint32_t audio_stream_sample_bytes ( const struct audio_stream *  buf)
inlinestatic

Calculates sample size in bytes based on component stream's parameters.

Parameters
bufComponent buffer.
Returns
Size of sample in bytes.

◆ audio_stream_samples_without_wrap_s16()

static int audio_stream_samples_without_wrap_s16 ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of s16 samples to buffer wrap when buffer is read forward towards end address.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of data s16 samples until circular wrap need at end

◆ audio_stream_samples_without_wrap_s24()

static int audio_stream_samples_without_wrap_s24 ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of s24 samples to buffer wrap when buffer is read forward towards end address.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of data s24 samples until circular wrap need at end

◆ audio_stream_samples_without_wrap_s32()

static int audio_stream_samples_without_wrap_s32 ( const struct audio_stream *  source,
const void *  ptr 
)
inlinestatic

Calculates numbers of s32 samples to buffer wrap when buffer is read forward towards end address.

Parameters
sourceStream to get information from.
ptrRead or write pointer from source
Returns
Number of data s32 samples until circular wrap need at end

◆ audio_stream_set_addr()

static void audio_stream_set_addr ( struct audio_stream *  buf,
void *  val 
)
inlinestatic

◆ audio_stream_set_align()

void audio_stream_set_align ( const uint32_t  byte_align,
const uint32_t  frame_align_req,
struct audio_stream *  stream 
)

Set processing alignment requirements.

Sets the sample byte alignment and aligned frame count required for processing done on this stream. This function may be called at any time, the internal constants are recalculated if the frame/sample size changes.

See also
audio_stream_avail_frames_aligned().
Parameters
byte_alignProcessing byte alignment requirement.
frame_align_reqProcessing frames alignment requirement.
streamSink or source stream structure which to be set.

◆ audio_stream_set_avail()

static void audio_stream_set_avail ( struct audio_stream *  buf,
uint32_t  val 
)
inlinestatic

◆ audio_stream_set_buffer_fmt()

static void audio_stream_set_buffer_fmt ( struct audio_stream *  buf,
uint32_t  buffer_fmt 
)
inlinestatic

◆ audio_stream_set_channels()

static void audio_stream_set_channels ( struct audio_stream *  buf,
uint16_t  val 
)
inlinestatic

◆ audio_stream_set_end_addr()

static void audio_stream_set_end_addr ( struct audio_stream *  buf,
void *  val 
)
inlinestatic

◆ audio_stream_set_free()

static void audio_stream_set_free ( struct audio_stream *  buf,
uint32_t  val 
)
inlinestatic

◆ audio_stream_set_frm_fmt()

static void audio_stream_set_frm_fmt ( struct audio_stream *  buf,
enum sof_ipc_frame  val 
)
inlinestatic

◆ audio_stream_set_overrun()

static void audio_stream_set_overrun ( struct audio_stream *  buf,
bool  overrun_permitted 
)
inlinestatic

◆ audio_stream_set_params()

static int audio_stream_set_params ( struct audio_stream *  buffer,
struct sof_ipc_stream_params *  params 
)
inlinestatic

Applies parameters to the buffer.

Parameters
bufferAudio stream buffer.
paramsParameters (frame format, rate, number of channels).
Returns
0 if succeeded, error code otherwise.

◆ audio_stream_set_rate()

static void audio_stream_set_rate ( struct audio_stream *  buf,
uint32_t  val 
)
inlinestatic

◆ audio_stream_set_rptr()

static void audio_stream_set_rptr ( struct audio_stream *  buf,
void *  val 
)
inlinestatic

◆ audio_stream_set_size()

static void audio_stream_set_size ( struct audio_stream *  buf,
uint32_t  val 
)
inlinestatic

◆ audio_stream_set_underrun()

static void audio_stream_set_underrun ( struct audio_stream *  buf,
bool  underrun_permitted 
)
inlinestatic

◆ audio_stream_set_valid_fmt()

static void audio_stream_set_valid_fmt ( struct audio_stream *  buf,
enum sof_ipc_frame  val 
)
inlinestatic

◆ audio_stream_set_wptr()

static void audio_stream_set_wptr ( struct audio_stream *  buf,
void *  val 
)
inlinestatic

◆ audio_stream_set_zero()

static int audio_stream_set_zero ( struct audio_stream *  buffer,
uint32_t  bytes 
)
inlinestatic

Writes zeros in range [w_ptr, w_ptr+bytes], with rollover if necessary.

Parameters
bufferBuffer.
bytesSize of the fragment to write zero.
Returns
0 if there is enough free space in buffer.
1 if there is not enough free space in buffer.

◆ audio_stream_wrap()

static void * audio_stream_wrap ( const struct audio_stream *  buffer,
void *  ptr 
)
inlinestatic

Verifies the pointer and performs rollover when reached the end of the buffer.

Parameters
bufferBuffer accessed by the pointer.
ptrPointer
Returns
Pointer, adjusted if necessary.

◆ audio_stream_writeback()

static void audio_stream_writeback ( struct audio_stream *  buffer,
uint32_t  bytes 
)
inlinestatic

Writes back (from DSP d-cache) the buffer in range [w_ptr, w_ptr+bytes], with rollover if necessary.

Parameters
bufferBuffer.
bytesSize of the fragment to write back.

◆ buffer_alloc()

struct comp_buffer * buffer_alloc ( struct mod_alloc_ctx *  alloc,
size_t  size,
uint32_t  flags,
uint32_t  align,
bool  is_shared 
)

Allocate a pipeline component audio buffer with explicit size and alignment.

Parameters
[in,out]allocAllocation context (heap and optional vregion).
[in]sizeRequired buffer capacity in bytes.
[in]flagsMemory allocation flags (SOF_MEM_FLAG_...).
[in]alignMemory alignment requirement in bytes.
[in]is_sharedTrue if the buffer memory is shared across processing domains.
Returns
Pointer to allocated comp_buffer, or NULL on failure.

◆ buffer_alloc_range()

struct comp_buffer * buffer_alloc_range ( struct mod_alloc_ctx *  alloc,
size_t  preferred_size,
size_t  minimum_size,
uint32_t  flags,
uint32_t  align,
bool  is_shared 
)

Allocate a pipeline component buffer with an elastic size range.

Parameters
[in,out]allocAllocation context.
[in]preferred_sizeDesired optimal buffer capacity in bytes.
[in]minimum_sizeMinimum acceptable buffer capacity in bytes.
[in]flagsMemory allocation flags (SOF_MEM_FLAG_...).
[in]alignMemory alignment requirement in bytes.
[in]is_sharedTrue if the buffer memory is shared across processing domains.
Returns
Pointer to allocated comp_buffer, or NULL on failure.

◆ buffer_attach()

int buffer_attach ( struct comp_buffer *  buffer,
struct list_item *  head,
int  dir 
)

Attach a new buffer at the beginning of a component buffer list.

Locking: Must be called with interrupts disabled (or userspace LL system mutex held). The caller takes care to protect list heads. "head" must really be the head of the list, not a list node within another buffer, as its cache is not synchronized and must not be embedded in an object using the coherent API.

Parameters
[in,out]bufferComponent buffer to attach.
[in,out]headList head to prepend buffer to.
[in]dirTraversal direction (PPL_DIR_DOWNSTREAM or PPL_DIR_UPSTREAM).
Returns
0 on success, or -EALREADY if the buffer is already linked in this direction.

◆ buffer_detach()

void buffer_detach ( struct comp_buffer *  buffer,
struct list_item *  head,
int  dir 
)

Detach a buffer from anywhere in a component buffer list.

Locking: Must be called with interrupts disabled (or userspace LL system mutex held). "head" is the head of the list, assumed not to require cache synchronization. The caller takes care to protect list heads.

Parameters
[in,out]bufferComponent buffer to detach.
[in,out]headList head buffer is attached to.
[in]dirTraversal direction (PPL_DIR_DOWNSTREAM or PPL_DIR_UPSTREAM).

◆ buffer_free()

static void buffer_free ( struct comp_buffer *  buffer)
inlinestatic

Free an interconnect component buffer and its underlying memory.

Parameters
[in,out]bufferComponent buffer to free.

◆ buffer_get_comp()

static struct comp_dev * buffer_get_comp ( struct comp_buffer *  buffer,
int  dir 
)
inlinestatic

Get component connected to buffer in specified traversal direction.

Parameters
[in]bufferComponent buffer.
[in]dirTraversal direction (PPL_DIR_DOWNSTREAM or PPL_DIR_UPSTREAM).
Returns
Pointer to connected component device.

◆ buffer_init_stream()

static void buffer_init_stream ( struct comp_buffer *  buffer,
size_t  size 
)
inlinestatic

Initialize circular stream buffer descriptor for a component buffer.

Parameters
[in,out]bufferComponent buffer to initialize stream for.
[in]sizeCapacity of the circular stream in bytes.

◆ buffer_new()

struct comp_buffer * buffer_new ( struct mod_alloc_ctx *  alloc,
const struct sof_ipc_buffer *  desc,
bool  is_shared 
)

Instantiate a pipeline component buffer from an IPC configuration descriptor.

Parameters
[in,out]allocAllocation context.
[in]descIPC buffer descriptor containing size, flags, and configuration.
[in]is_sharedTrue if the buffer memory is shared across processing domains.
Returns
Pointer to newly instantiated comp_buffer, or NULL on failure.

◆ buffer_params_match()

bool buffer_params_match ( struct comp_buffer *  buffer,
struct sof_ipc_stream_params *  params,
uint32_t  flag 
)

Test if buffer stream parameters match requested parameters.

Parameters
[in]bufferComponent buffer to check.
[in]paramsStream parameters to compare.
[in]flagBitmask specifying which parameters to check (BUFF_PARAMS_*).
Returns
True if matching, false otherwise.

◆ buffer_pipeline_id()

static uint32_t buffer_pipeline_id ( const struct comp_buffer *  buffer)
inlinestatic

Retrieve pipeline ID associated with a component buffer.

Parameters
[in]bufferComponent buffer.
Returns
Pipeline ID.

◆ buffer_set_params()

int buffer_set_params ( struct comp_buffer *  buffer,
struct sof_ipc_stream_params *  params,
bool  force_update 
)

Set audio stream parameters on a component buffer.

Parameters
[in,out]bufferComponent buffer to configure.
[in]paramsStream parameters to apply.
[in]force_updateIf true, overwrite existing parameters unconditionally.
Returns
0 on success, or negative error code on failure.

◆ buffer_set_size()

int buffer_set_size ( struct comp_buffer *  buffer,
uint32_t  size,
uint32_t  alignment 
)

Resize an existing pipeline component buffer.

Parameters
[in,out]bufferPointer to comp_buffer to resize.
[in]sizeNew buffer capacity in bytes.
[in]alignmentRequired memory alignment in bytes.
Returns
0 on success, or negative error code on failure.

◆ buffer_set_size_range()

int buffer_set_size_range ( struct comp_buffer *  buffer,
size_t  preferred_size,
size_t  minimum_size,
uint32_t  alignment 
)

Resize a pipeline component buffer within a preferred-to-minimum range.

Parameters
[in,out]bufferPointer to comp_buffer to resize.
[in]preferred_sizeDesired optimal buffer capacity in bytes.
[in]minimum_sizeMinimum acceptable buffer capacity in bytes.
[in]alignmentRequired memory alignment in bytes.
Returns
0 on success, or negative error code on failure.

◆ buffer_stream_invalidate()

static void buffer_stream_invalidate ( struct comp_buffer *  buffer,
uint32_t  bytes 
)
inlinestatic

Invalidate cache for a shared buffer stream if incoherent.

Parameters
[in,out]bufferComponent buffer.
[in]bytesNumber of bytes to invalidate.

◆ buffer_stream_writeback()

static void buffer_stream_writeback ( struct comp_buffer *  buffer,
uint32_t  bytes 
)
inlinestatic

Write back cache for a shared buffer stream if incoherent.

Parameters
[in]bufferComponent buffer.
[in]bytesNumber of bytes to write back.

◆ buffer_zero()

void buffer_zero ( struct comp_buffer *  buffer)

Zero-fill the entire payload of an interconnect buffer.

Parameters
[in,out]bufferComponent buffer to zero.

◆ cir_buf_copy()

void cir_buf_copy ( const void *  src,
const void *  src_addr,
const void *  src_end,
void *  dst,
void *  dst_addr,
void *  dst_end,
size_t  byte_size 
)

Copies data from one circular buffer to another circular buffer.

Parameters
srcSource pointer of source circular buffer.
src_addrStart address of source circular buffer.
src_endEnd address of source circular buffer.
dstSink pointer of source circular buffer.
dst_addrStart address of sink circular buffer
dst_endEnd address of sink circular buffer.
byte_sizeNumber of bytes to copy.

◆ cir_buf_set_zero()

static void cir_buf_set_zero ( void *  ptr,
void *  buf_addr,
void *  buf_end,
uint32_t  bytes 
)
inlinestatic

Writes zeros to circular buffer in range [ptr, ptr+bytes] with rollover if necessary.

Parameters
ptrPointer inside circular biffer to start writing from.
buf_addrStart of the circular buffer.
buf_endEnd of the circular buffer.
bytesSize of the fragment to write zeros.

◆ comp_buffer_get_from_sink()

static struct comp_buffer * comp_buffer_get_from_sink ( struct sof_sink *  sink)
inlinestatic

Retrieve enclosing comp_buffer from an audio sink interface pointer.

Parameters
[in]sinkPointer to audio sink interface.
Returns
Pointer to enclosing struct comp_buffer.

◆ comp_buffer_get_from_source()

static struct comp_buffer * comp_buffer_get_from_source ( struct sof_source *  source)
inlinestatic

Retrieve enclosing comp_buffer from an audio source interface pointer.

Parameters
[in]sourcePointer to audio source interface.
Returns
Pointer to enclosing struct comp_buffer.

◆ comp_buffer_get_sink_component()

static struct comp_dev * comp_buffer_get_sink_component ( const struct comp_buffer *  buffer)
inlinestatic

Get component consuming data from the buffer.

Parameters
[in]bufferInterconnect buffer.
Returns
Pointer to sink component device, or NULL if none.

◆ comp_buffer_get_source_component()

static struct comp_dev * comp_buffer_get_source_component ( const struct comp_buffer *  buffer)
inlinestatic

Get component providing data to the buffer.

Parameters
[in]bufferInterconnect buffer.
Returns
Pointer to source component device, or NULL if none.

◆ comp_buffer_reset_sink_list()

static void comp_buffer_reset_sink_list ( struct comp_buffer *  buffer)
inlinestatic

Reset buffer sink list node.

Parameters
[in,out]bufferInterconnect buffer.

◆ comp_buffer_reset_source_list()

static void comp_buffer_reset_source_list ( struct comp_buffer *  buffer)
inlinestatic

Reset buffer source list node.

Parameters
[in,out]bufferInterconnect buffer.

◆ comp_buffer_set_sink_component()

static void comp_buffer_set_sink_component ( struct comp_buffer *  buffer,
struct comp_dev *  comp 
)
inlinestatic

Set component consuming data from the buffer.

Parameters
[in,out]bufferInterconnect buffer.
[in]compSink component device.

◆ comp_buffer_set_source_component()

static void comp_buffer_set_source_component ( struct comp_buffer *  buffer,
struct comp_dev *  comp 
)
inlinestatic

Set component providing data to the buffer.

Parameters
[in,out]bufferInterconnect buffer.
[in]compSource component device.

◆ comp_update_buffer_consume()

void comp_update_buffer_consume ( struct comp_buffer *  buffer,
uint32_t  bytes 
)

Notify buffer that audio data has been consumed by a component.

Parameters
[in,out]bufferComponent buffer read from.
[in]bytesNumber of bytes consumed.

◆ comp_update_buffer_produce()

void comp_update_buffer_produce ( struct comp_buffer *  buffer,
uint32_t  bytes 
)

Notify buffer that audio data has been produced by a component.

Parameters
[in,out]bufferComponent buffer written to.
[in]bytesNumber of bytes produced.

◆ ring_buffer_create()

struct ring_buffer * ring_buffer_create ( struct comp_dev *  dev,
size_t  min_available,
size_t  min_free_space,
bool  is_shared,
uint32_t  id 
)

Create and allocate a lockless async circular ring buffer.

Parameters
[in,out]devPointer to component device creating this buffer.
[in]min_availableMinimum data available required by source API consumer.
[in]min_free_spaceMinimum buffer space required by sink API producer.
[in]is_sharedTrue if buffer memory is shared across processing cores.
[in]idStream identifier accessible via sink/source interface.
Returns
Pointer to newly allocated ring_buffer, or NULL on failure.

◆ sof_audio_buffer_from_sink()

static struct sof_audio_buffer * sof_audio_buffer_from_sink ( struct sof_sink *  sink)
inlinestatic

Retrieve enclosing sof_audio_buffer from sink interface pointer.

NOTE: Ensure that sink is really embedded within a sof_audio_buffer; otherwise an invalid derived pointer will be returned.

Parameters
[in]sinkPointer to sink interface.
Returns
Pointer to enclosing struct sof_audio_buffer.

◆ sof_audio_buffer_from_source()

static struct sof_audio_buffer * sof_audio_buffer_from_source ( struct sof_source *  source)
inlinestatic

Retrieve enclosing sof_audio_buffer from source interface pointer.

NOTE: Ensure that source is really embedded within a sof_audio_buffer; otherwise an invalid derived pointer will be returned.

Parameters
[in]sourcePointer to source interface.
Returns
Pointer to enclosing struct sof_audio_buffer.

Variable Documentation

◆ buffer_tr

struct tr_ctx buffer_tr
extern