Sound Open Firmware
Loading...
Searching...
No Matches
source_api.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2023 Intel Corporation. All rights reserved.
4 *
5 */
6
13#ifndef __MODULE_AUDIO_SOURCE_API_H__
14#define __MODULE_AUDIO_SOURCE_API_H__
15
16#include <errno.h>
17#include <stdint.h>
18#include <stdbool.h>
19#include <stddef.h>
20
21#include <sof/math/numbers.h>
22
23#include "audio_stream.h"
24#include "format.h"
25
58 /* forward def */
59struct sof_source;
63
71struct source_ops {
75 size_t (*get_data_available)(struct sof_source *source);
76
80 int (*get_data)(struct sof_source *source, size_t req_size,
81 void const **data_ptr, void const **buffer_start, size_t *buffer_size);
82
86 int (*release_data)(struct sof_source *source, size_t free_size);
87
93 int (*get_state)(struct sof_source *source);
94
104 int (*on_audio_format_set)(struct sof_source *source);
105
110 int (*audio_set_ipc_params)(struct sof_source *source,
111 struct sof_ipc_stream_params *params, bool force_update);
112
117 int (*set_alignment_constants)(struct sof_source *source,
118 const uint32_t byte_align,
119 const uint32_t frame_align_req);
120
125 int (*set_size)(struct sof_source *source, size_t size);
126
132 int (*on_bind)(struct sof_source *source, struct processing_module *module);
133 int (*on_unbind)(struct sof_source *source);
134};
135
138 const struct source_ops *ops;
139 size_t requested_read_frag_size; /* keeps size of data obtained by get_data() */
140 size_t num_of_bytes_processed; /* processed bytes counter */
141 size_t min_available; /* minimum data available required by the module using
142 * source
143 * it is module's IBS as declared in module bind IPC
144 */
145 struct processing_module *bound_module; /* a pointer module that is using source API */
147};
148
159static inline size_t source_get_data_available(struct sof_source *source)
160{
161 return source->ops->get_data_available(source);
162}
163
169static inline size_t source_get_aligned_frames_available(struct sof_source *source)
170{
173}
174
175static inline enum sof_ipc_frame source_get_frm_fmt(struct sof_source *source)
176{
177 return source->audio_stream_params->frame_fmt;
178}
179
180static inline unsigned int source_get_channels(struct sof_source *source)
181{
182 return source->audio_stream_params->channels;
183}
184
186size_t source_get_frame_bytes(struct sof_source *source);
187
193
225int source_get_data(struct sof_source *source, size_t req_size, void const **data_ptr,
226 void const **buffer_start, size_t *buffer_size);
227
243int source_get_data_s16(struct sof_source *source, size_t req_size, int16_t const **data_ptr,
244 int16_t const **buffer_start, size_t *buffer_samples);
245
261int source_get_data_s32(struct sof_source *source, size_t req_size, int32_t const **data_ptr,
262 int32_t const **buffer_start, size_t *buffer_samples);
263
278int source_release_data(struct sof_source *source, size_t free_size);
279
287int source_set_size(struct sof_source *source, size_t size);
288
290static inline enum sof_ipc_frame source_get_valid_fmt(struct sof_source *source)
291{
293}
294
295static inline unsigned int source_get_rate(struct sof_source *source)
296{
297 return source->audio_stream_params->rate;
298}
299
300static inline uint32_t source_get_buffer_fmt(struct sof_source *source)
301{
302 return source->audio_stream_params->buffer_fmt;
303}
304
305static inline size_t source_get_min_available(struct sof_source *source)
306{
307 return source->min_available;
308}
309
310static inline uint32_t source_get_id(struct sof_source *source)
311{
312 return source->audio_stream_params->id;
313}
314
315static inline uint32_t source_get_pipeline_id(struct sof_source *source)
316{
317 return source->audio_stream_params->pipeline_id;
318}
319
325static inline int source_bind(struct sof_source *source, struct processing_module *module)
326{
327 int ret = 0;
328
329 if (source->bound_module)
330 return -EBUSY;
331
332 if (source->ops->on_bind)
333 ret = source->ops->on_bind(source, module);
334
335 if (!ret)
336 source->bound_module = module;
337
338 return ret;
339}
340
346static inline int source_unbind(struct sof_source *source)
347{
348 int ret = 0;
349
350 if (!source->bound_module)
351 return -EINVAL;
352
353 if (source->ops->on_unbind)
354 ret = source->ops->on_unbind(source);
355
356 if (!ret)
357 source->bound_module = NULL;
358
359 return ret;
360}
361
362static inline struct processing_module *source_get_bound_module(struct sof_source *source)
363{
364 return source->bound_module;
365}
366
367static inline enum sof_audio_buffer_state source_get_state(const struct sof_source *source)
368{
369 return source->audio_stream_params->state;
370}
371
383static inline int source_get_comp_state(struct sof_source *source)
384{
385 if (!source->ops->get_state)
386 return 0; /* COMP_STATE_NOT_EXIST */
387
388 return source->ops->get_state(source);
389}
390
391static inline uint32_t source_align_frames_round_up(struct sof_source *source, uint32_t frames)
392{
393 uint16_t align = source->audio_stream_params->align_frame_cnt;
394
395 if (align <= 1)
396 return frames;
397
398 return ROUND_UP(frames, align);
399}
400
401static inline uint32_t source_align_frames_round_down(struct sof_source *source, uint32_t frames)
402{
403 uint16_t align = source->audio_stream_params->align_frame_cnt;
404
405 if (align <= 1)
406 return frames;
407
408 return ROUND_DOWN(frames, align);
409}
410
411static inline uint32_t source_align_frames_round_nearest(struct sof_source *source, uint32_t frames)
412{
413 uint16_t align = source->audio_stream_params->align_frame_cnt;
414
415 if (!align)
416 return frames;
417
418 return ROUND_DOWN(frames + (align >> 1), align);
419}
420
421#endif /* __MODULE_AUDIO_SOURCE_API_H__ */
sof_audio_buffer_state
Define states of an audio stream buffer connecting two components.
Definition audio_stream.h:35
static unsigned int source_get_channels(struct sof_source *source)
Definition source_api.h:180
static uint32_t source_align_frames_round_up(struct sof_source *source, uint32_t frames)
Definition source_api.h:391
static int source_bind(struct sof_source *source, struct processing_module *module)
hook to be called when a module connects to the API
Definition source_api.h:325
static uint32_t source_get_id(struct sof_source *source)
Definition source_api.h:310
size_t source_get_data_frames_available(struct sof_source *source)
Retrieves size of available data (in frames) return number of frames that are available for immediate...
static unsigned int source_get_rate(struct sof_source *source)
Definition source_api.h:295
static int source_unbind(struct sof_source *source)
hook to be called when a module disconnects from the API
Definition source_api.h:346
static enum sof_ipc_frame source_get_frm_fmt(struct sof_source *source)
Definition source_api.h:175
int source_get_data(struct sof_source *source, size_t req_size, void const **data_ptr, void const **buffer_start, size_t *buffer_size)
Retrieves a fragment of circular data to be used by the caller (to read) After calling get_data,...
static uint32_t source_align_frames_round_nearest(struct sof_source *source, uint32_t frames)
Definition source_api.h:411
int source_set_size(struct sof_source *source, size_t size)
Resize the buffer backing the source.
size_t source_get_frame_bytes(struct sof_source *source)
get size of a single audio frame (in bytes)
static struct processing_module * source_get_bound_module(struct sof_source *source)
Definition source_api.h:362
int source_get_data_s16(struct sof_source *source, size_t req_size, int16_t const **data_ptr, int16_t const **buffer_start, size_t *buffer_samples)
Retrieves a fragment of circular data (to read)
static uint32_t source_get_pipeline_id(struct sof_source *source)
Definition source_api.h:315
static size_t source_get_aligned_frames_available(struct sof_source *source)
Retrieves number of available data frames aligned to the alignment constants set by source_set_alignm...
Definition source_api.h:169
static uint32_t source_get_buffer_fmt(struct sof_source *source)
Definition source_api.h:300
static uint32_t source_align_frames_round_down(struct sof_source *source, uint32_t frames)
Definition source_api.h:401
int source_release_data(struct sof_source *source, size_t free_size)
Releases fragment previously obtained by source_get_data() Once called, the data are no longer availa...
static size_t source_get_data_available(struct sof_source *source)
Public functions.
Definition source_api.h:159
static enum sof_ipc_frame source_get_valid_fmt(struct sof_source *source)
set of functions for retrieve audio parameters
Definition source_api.h:290
static size_t source_get_min_available(struct sof_source *source)
Definition source_api.h:305
static enum sof_audio_buffer_state source_get_state(const struct sof_source *source)
Definition source_api.h:367
int source_get_data_s32(struct sof_source *source, size_t req_size, int32_t const **data_ptr, int32_t const **buffer_start, size_t *buffer_samples)
Retrieves a fragment of circular data (to read)
static int source_get_comp_state(struct sof_source *source)
get the state of the component producing data to this source
Definition source_api.h:383
sof_ipc_frame
Definition stream.h:16
Fixed-point arithmetic, saturation, rounding, and number format conversions.
Audio Stream API definition.
Definition base.h:103
set of parameters describing audio stream this structure is shared between audio_stream....
Definition audio_stream.h:49
uint16_t align_shift_idx
the free/available bytes of sink/source right shift align_shift_idx, the result multiplied by align_f...
Definition audio_stream.h:75
enum sof_ipc_frame frame_fmt
Sample data format.
Definition audio_stream.h:52
uint32_t buffer_fmt
enum sof_ipc_buffer_format
Definition audio_stream.h:80
uint32_t pipeline_id
Definition audio_stream.h:51
uint16_t align_frame_cnt
align_frame_cnt indicates minimum number of frames that satisfies both byte align and frame align req...
Definition audio_stream.h:68
uint32_t rate
Number of data frames per second [Hz].
Definition audio_stream.h:55
enum sof_audio_buffer_state state
audio stream state
Definition audio_stream.h:84
enum sof_ipc_frame valid_sample_fmt
Definition audio_stream.h:53
uint16_t channels
Number of samples in each frame.
Definition audio_stream.h:56
uint32_t id
Definition audio_stream.h:50
Definition stream.h:71
internals of source API.
Definition source_api.h:137
const struct source_ops * ops
Definition source_api.h:138
size_t num_of_bytes_processed
Definition source_api.h:140
struct sof_audio_stream_params * audio_stream_params
Definition source_api.h:146
size_t requested_read_frag_size
Definition source_api.h:139
struct processing_module * bound_module
Definition source_api.h:145
size_t min_available
Definition source_api.h:141
this is a definition of internals of source API
Definition source_api.h:71
int(* get_state)(struct sof_source *source)
OPTIONAL: get the state of the component producing data to this source.
Definition source_api.h:93
int(* set_size)(struct sof_source *source, size_t size)
OPTIONAL see comment for source_set_size.
Definition source_api.h:125
int(* on_unbind)(struct sof_source *source)
Definition source_api.h:133
int(* audio_set_ipc_params)(struct sof_source *source, struct sof_ipc_stream_params *params, bool force_update)
OPTIONAL see source_set_params comments.
Definition source_api.h:110
int(* on_bind)(struct sof_source *source, struct processing_module *module)
OPTIONAL events called when a module is starting / finishing using of the API on the core that the mo...
Definition source_api.h:132
int(* get_data)(struct sof_source *source, size_t req_size, void const **data_ptr, void const **buffer_start, size_t *buffer_size)
see comment of source_get_data_available()
Definition source_api.h:80
int(* set_alignment_constants)(struct sof_source *source, const uint32_t byte_align, const uint32_t frame_align_req)
OPTIONAL see comment for source_set_alignment_constants.
Definition source_api.h:117
size_t(* get_data_available)(struct sof_source *source)
see comment of source_get_data_available()
Definition source_api.h:75
int(* release_data)(struct sof_source *source, size_t free_size)
see comment of source_release_data()
Definition source_api.h:86
int(* on_audio_format_set)(struct sof_source *source)
OPTIONAL: Notification to the source implementation about changes in audio format.
Definition source_api.h:104