Skip to content

Commit

Permalink
sof_api: sink: source: Move sink/source api headers to sof_api
Browse files Browse the repository at this point in the history
Moved header files to the sof_api directory to separate an shared interface
used by sof and native loadable modules.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki committed Oct 23, 2023
1 parent c93f106 commit 9c25890
Show file tree
Hide file tree
Showing 16 changed files with 667 additions and 595 deletions.
86 changes: 0 additions & 86 deletions src/audio/sink_api_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,6 @@ void sink_init(struct sof_sink *sink, const struct sink_ops *ops,
sink->audio_stream_params = audio_stream_params;
}

size_t sink_get_free_size(struct sof_sink *sink)
{
return sink->ops->get_free_size(sink);
}

int sink_get_buffer(struct sof_sink *sink, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
{
int ret;

if (sink->requested_write_frag_size)
return -EBUSY;

ret = sink->ops->get_buffer(sink, req_size, data_ptr,
buffer_start, buffer_size);

if (!ret)
sink->requested_write_frag_size = req_size;
return ret;
}

int sink_commit_buffer(struct sof_sink *sink, size_t commit_size)
{
int ret;

/* check if there was a buffer obtained for writing by sink_get_buffer */
if (!sink->requested_write_frag_size)
return -ENODATA;

/* limit size of data to be committed to previously obtained size */
if (commit_size > sink->requested_write_frag_size)
commit_size = sink->requested_write_frag_size;

ret = sink->ops->commit_buffer(sink, commit_size);

if (!ret)
sink->requested_write_frag_size = 0;

sink->num_of_bytes_processed += commit_size;
return ret;
}

size_t sink_get_num_of_processed_bytes(struct sof_sink *sink)
{
Expand All @@ -66,45 +25,11 @@ void sink_reset_num_of_processed_bytes(struct sof_sink *sink)
sink->num_of_bytes_processed = 0;
}

enum sof_ipc_frame sink_get_frm_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->frame_fmt;
}

enum sof_ipc_frame sink_get_valid_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->valid_sample_fmt;
}

uint32_t sink_get_rate(struct sof_sink *sink)
{
return sink->audio_stream_params->rate;
}

uint32_t sink_get_channels(struct sof_sink *sink)
{
return sink->audio_stream_params->channels;
}

uint32_t sink_get_buffer_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->buffer_fmt;
}

bool sink_get_overrun(struct sof_sink *sink)
{
return sink->audio_stream_params->overrun_permitted;
}

int sink_set_frm_fmt(struct sof_sink *sink, enum sof_ipc_frame frame_fmt)
{
sink->audio_stream_params->frame_fmt = frame_fmt;

/* notify the implementation */
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_valid_fmt(struct sof_sink *sink,
enum sof_ipc_frame valid_sample_fmt)
Expand Down Expand Up @@ -147,17 +72,6 @@ int sink_set_overrun(struct sof_sink *sink, bool overrun_permitted)
return 0;
}

size_t sink_get_frame_bytes(struct sof_sink *sink)
{
return get_frame_bytes(sink_get_frm_fmt(sink),
sink_get_channels(sink));
}

size_t sink_get_free_frames(struct sof_sink *sink)
{
return sink_get_free_size(sink) /
sink_get_frame_bytes(sink);
}

int sink_set_params(struct sof_sink *sink,
struct sof_ipc_stream_params *params, bool force_update)
Expand Down
78 changes: 0 additions & 78 deletions src/audio/source_api_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,6 @@ void source_init(struct sof_source *source, const struct source_ops *ops,
source->audio_stream_params = audio_stream_params;
}

size_t source_get_data_available(struct sof_source *source)
{
return source->ops->get_data_available(source);
}

int source_get_data(struct sof_source *source, size_t req_size,
void const **data_ptr, void const **buffer_start, size_t *buffer_size)
{
int ret;

if (source->requested_read_frag_size)
return -EBUSY;

ret = source->ops->get_data(source, req_size, data_ptr, buffer_start, buffer_size);

if (!ret)
source->requested_read_frag_size = req_size;
return ret;
}

int source_release_data(struct sof_source *source, size_t free_size)
{
int ret;

/* Check if anything was obtained before for reading by source_get_data */
if (!source->requested_read_frag_size)
return -ENODATA;

/* limit size of data to be freed to previously obtained size */
if (free_size > source->requested_read_frag_size)
free_size = source->requested_read_frag_size;

ret = source->ops->release_data(source, free_size);

if (!ret)
source->requested_read_frag_size = 0;

source->num_of_bytes_processed += free_size;
return ret;
}

size_t source_get_num_of_processed_bytes(struct sof_source *source)
{
return source->num_of_bytes_processed;
Expand All @@ -66,31 +25,6 @@ void source_reset_num_of_processed_bytes(struct sof_source *source)
source->num_of_bytes_processed = 0;
}

enum sof_ipc_frame source_get_frm_fmt(struct sof_source *source)
{
return source->audio_stream_params->frame_fmt;
}

enum sof_ipc_frame source_get_valid_fmt(struct sof_source *source)
{
return source->audio_stream_params->valid_sample_fmt;
}

unsigned int source_get_rate(struct sof_source *source)
{
return source->audio_stream_params->rate;
}

unsigned int source_get_channels(struct sof_source *source)
{
return source->audio_stream_params->channels;
}

uint32_t source_get_buffer_fmt(struct sof_source *source)
{
return source->audio_stream_params->buffer_fmt;
}

bool source_get_underrun(struct sof_source *source)
{
return source->audio_stream_params->underrun_permitted;
Expand Down Expand Up @@ -137,18 +71,6 @@ int source_set_underrun(struct sof_source *source, bool underrun_permitted)
return 0;
}

size_t source_get_frame_bytes(struct sof_source *source)
{
return get_frame_bytes(source_get_frm_fmt(source),
source_get_channels(source));
}

size_t source_get_data_frames_available(struct sof_source *source)
{
return source_get_data_available(source) /
source_get_frame_bytes(source);
}

int source_set_params(struct sof_source *source,
struct sof_ipc_stream_params *params, bool force_update)
{
Expand Down
15 changes: 2 additions & 13 deletions src/include/ipc/stream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2018 Intel Corporation. All rights reserved.
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <[email protected]>
* Keyon Jie <[email protected]>
Expand All @@ -16,6 +16,7 @@
#ifndef __IPC_STREAM_H__
#define __IPC_STREAM_H__

#include <sof_api/ipc/stream.h>
#include <ipc/header.h>
#include <stdint.h>

Expand Down Expand Up @@ -48,18 +49,6 @@
/* generic PCM flags for runtime settings */
#define SOF_PCM_FLAG_XRUN_STOP (1 << 0) /**< Stop on any XRUN */

/* stream PCM frame format */
enum sof_ipc_frame {
SOF_IPC_FRAME_S16_LE = 0,
SOF_IPC_FRAME_S24_4LE,
SOF_IPC_FRAME_S32_LE,
SOF_IPC_FRAME_FLOAT,
/* other formats here */
SOF_IPC_FRAME_S24_3LE,
SOF_IPC_FRAME_S24_4LE_MSB,
SOF_IPC_FRAME_U8,
};

/* stream buffer format */
enum sof_ipc_buffer_format {
SOF_IPC_BUFFER_INTERLEAVED,
Expand Down
40 changes: 2 additions & 38 deletions src/include/sof/audio/audio_stream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2020 Intel Corporation. All rights reserved.
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Karol Trzcinski <[email protected]>
*/
Expand All @@ -26,6 +26,7 @@
#include <rtos/cache.h>
#include <ipc/stream.h>
#include <ipc4/base-config.h>
#include <sof_api/audio/audio_stream.h>

#include <stdbool.h>
#include <stdint.h>
Expand All @@ -34,43 +35,6 @@
* @{
*/

/**
* set of parameters describing audio stream
* this structure is shared between audio_stream.h and sink/source interface
* TODO: compressed formats
*/
struct sof_audio_stream_params {
enum sof_ipc_frame frame_fmt; /**< Sample data format */
enum sof_ipc_frame valid_sample_fmt;

uint32_t rate; /**< Number of data frames per second [Hz] */
uint16_t channels; /**< Number of samples in each frame */

/**
* align_frame_cnt indicates minimum number of frames that satisfies both byte
* align and frame align requirements. E.g: Consider an algorithm that processes
* in blocks of 3 frames configured to process 16-bit stereo using xtensa HiFi3
* SIMD. Therefore with 16-bit stereo we have a frame size of 4 bytes, and
* SIMD intrinsic requirement of 8 bytes(2 frames) for HiFi3 and an algorithim
* requirement of 3 frames. Hence the common processing block size has to align
* with frame(1), intrinsic(2) and algorithm (3) giving us an optimum processing
* block size of 6 frames.
*/
uint16_t align_frame_cnt;

/**
* the free/available bytes of sink/source right shift align_shift_idx, the result
* multiplied by align_frame_cnt is the frame count free/available that can meet
* the align requirement.
*/
uint16_t align_shift_idx;

bool overrun_permitted; /**< indicates whether overrun is permitted */
bool underrun_permitted; /**< indicates whether underrun is permitted */

uint32_t buffer_fmt; /**< enum sof_ipc_buffer_format */
};

/**
* 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,
Expand Down
38 changes: 2 additions & 36 deletions src/include/sof/audio/format.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2016 Intel Corporation. All rights reserved.
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Seppo Ingalsuo <[email protected]>
* Liam Girdwood <[email protected]>
Expand Down Expand Up @@ -28,6 +28,7 @@

#include <ipc/stream.h>
#include <stdint.h>
#include <sof_api/ipc/stream.h>

/* Maximum and minimum values for 24 bit */
#define INT24_MAXVALUE 8388607
Expand Down Expand Up @@ -165,39 +166,4 @@ static inline int32_t sign_extend_s24(int32_t x)
return (x << 8) >> 8;
}

static inline uint32_t get_sample_bytes(enum sof_ipc_frame fmt)
{
switch (fmt) {
case SOF_IPC_FRAME_S16_LE:
return 2;
case SOF_IPC_FRAME_S24_3LE:
return 3;
case SOF_IPC_FRAME_U8:
return 1;
default:
return 4;
}
}

static inline uint32_t get_sample_bitdepth(enum sof_ipc_frame fmt)
{
switch (fmt) {
case SOF_IPC_FRAME_S16_LE:
return 16;
case SOF_IPC_FRAME_S24_4LE:
case SOF_IPC_FRAME_S24_3LE:
return 24;
case SOF_IPC_FRAME_U8:
return 8;
default:
return 32;
}
}

static inline uint32_t get_frame_bytes(enum sof_ipc_frame fmt,
uint32_t channels)
{
return get_sample_bytes(fmt) * channels;
}

#endif /* __SOF_AUDIO_FORMAT_H__ */
Loading

0 comments on commit 9c25890

Please sign in to comment.