-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sink / source API #7622
Merged
mwasko
merged 10 commits into
thesofproject:main
from
marcinszkudlinski:sink-src-public
Jun 19, 2023
+1,922
−474
Merged
sink / source API #7622
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e153d75
buffer: don't access stream internals
marcinszkudlinski d92202b
stream: move all stream runtime parameters to a structure
marcinszkudlinski b6a10bb
buffer: external modules use API to access buffer_fmt
marcinszkudlinski d93b0a4
pipeline2.0: introduce a source API
marcinszkudlinski b11045c
pipeline2.0: introduce a sink API
marcinszkudlinski 8e4ec75
pipeline2.0: introduce sink/source utilities
marcinszkudlinski 0c025db
pipeline2.0: add source/sink api to audio_stream
marcinszkudlinski 88af408
Pipeline2.0: change module API to use various data
marcinszkudlinski 5fdf11e
pipeline2.0: change module prepare API to use sink/src.c
marcinszkudlinski b900d5e
src: POC - change src module to use sink/source API
marcinszkudlinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// Copyright(c) 2023 Intel Corporation. All rights reserved. | ||
// | ||
|
||
#include <sof/audio/audio_stream.h> | ||
#include <sof/audio/buffer.h> | ||
|
||
static size_t audio_stream_get_free_size(struct sof_sink __sparse_cache *sink) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(sink, struct audio_stream __sparse_cache, | ||
sink_api, __sparse_cache); | ||
|
||
return audio_stream_get_free_bytes(audio_stream); | ||
} | ||
|
||
static int audio_stream_get_buffer(struct sof_sink __sparse_cache *sink, size_t req_size, | ||
void **data_ptr, void **buffer_start, size_t *buffer_size) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(sink, struct audio_stream __sparse_cache, | ||
sink_api, __sparse_cache); | ||
|
||
if (req_size > audio_stream_get_free_size(sink)) | ||
return -ENODATA; | ||
|
||
/* get circular buffer parameters */ | ||
*data_ptr = audio_stream->w_ptr; | ||
*buffer_start = audio_stream->addr; | ||
*buffer_size = audio_stream->size; | ||
return 0; | ||
} | ||
|
||
static int audio_stream_commit_buffer(struct sof_sink __sparse_cache *sink, size_t commit_size) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(sink, struct audio_stream __sparse_cache, | ||
sink_api, __sparse_cache); | ||
|
||
if (commit_size) | ||
audio_stream_produce(audio_stream, commit_size); | ||
|
||
return 0; | ||
} | ||
|
||
static size_t audio_stream_get_data_available(struct sof_source __sparse_cache *source) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(source, struct audio_stream __sparse_cache, | ||
source_api, __sparse_cache); | ||
|
||
return audio_stream_get_avail_bytes(audio_stream); | ||
} | ||
|
||
static int audio_stream_get_data(struct sof_source __sparse_cache *source, size_t req_size, | ||
void **data_ptr, void **buffer_start, size_t *buffer_size) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(source, struct audio_stream __sparse_cache, | ||
source_api, __sparse_cache); | ||
|
||
if (req_size > audio_stream_get_data_available(source)) | ||
return -ENODATA; | ||
|
||
/* get circular buffer parameters */ | ||
*data_ptr = audio_stream->r_ptr; | ||
*buffer_start = audio_stream->addr; | ||
*buffer_size = audio_stream->size; | ||
return 0; | ||
} | ||
|
||
static int audio_stream_release_data(struct sof_source __sparse_cache *source, size_t free_size) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(source, struct audio_stream __sparse_cache, | ||
source_api, __sparse_cache); | ||
|
||
if (free_size) | ||
audio_stream_consume(audio_stream, free_size); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_stream_set_ipc_params_source(struct sof_source __sparse_cache *source, | ||
struct sof_ipc_stream_params *params, | ||
bool force_update) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(source, struct audio_stream __sparse_cache, | ||
source_api, __sparse_cache); | ||
struct comp_buffer __sparse_cache *buffer = | ||
attr_container_of(audio_stream, struct comp_buffer __sparse_cache, | ||
stream, __sparse_cache); | ||
|
||
return buffer_set_params(buffer, params, force_update); | ||
} | ||
|
||
static int audio_stream_set_ipc_params_sink(struct sof_sink __sparse_cache *sink, | ||
struct sof_ipc_stream_params *params, | ||
bool force_update) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(sink, struct audio_stream __sparse_cache, | ||
sink_api, __sparse_cache); | ||
struct comp_buffer __sparse_cache *buffer = | ||
attr_container_of(audio_stream, struct comp_buffer __sparse_cache, | ||
stream, __sparse_cache); | ||
|
||
return buffer_set_params(buffer, params, force_update); | ||
} | ||
|
||
static int audio_stream_source_set_alignment_constants(struct sof_source __sparse_cache *source, | ||
const uint32_t byte_align, | ||
const uint32_t frame_align_req) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(source, struct audio_stream __sparse_cache, | ||
source_api, __sparse_cache); | ||
|
||
audio_stream_init_alignment_constants(byte_align, frame_align_req, audio_stream); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_stream_sink_set_alignment_constants(struct sof_sink __sparse_cache *sink, | ||
const uint32_t byte_align, | ||
const uint32_t frame_align_req) | ||
{ | ||
struct audio_stream __sparse_cache *audio_stream = | ||
attr_container_of(sink, struct audio_stream __sparse_cache, | ||
sink_api, __sparse_cache); | ||
|
||
audio_stream_init_alignment_constants(byte_align, frame_align_req, audio_stream); | ||
|
||
return 0; | ||
} | ||
|
||
static const struct source_ops audio_stream_source_ops = { | ||
.get_data_available = audio_stream_get_data_available, | ||
.get_data = audio_stream_get_data, | ||
.release_data = audio_stream_release_data, | ||
.audio_set_ipc_params = audio_stream_set_ipc_params_source, | ||
.set_alignment_constants = audio_stream_source_set_alignment_constants | ||
}; | ||
|
||
static const struct sink_ops audio_stream_sink_ops = { | ||
.get_free_size = audio_stream_get_free_size, | ||
.get_buffer = audio_stream_get_buffer, | ||
.commit_buffer = audio_stream_commit_buffer, | ||
.audio_set_ipc_params = audio_stream_set_ipc_params_sink, | ||
.set_alignment_constants = audio_stream_sink_set_alignment_constants | ||
}; | ||
|
||
void audio_stream_init(struct audio_stream __sparse_cache *audio_stream, | ||
void *buff_addr, uint32_t size) | ||
{ | ||
audio_stream->size = size; | ||
audio_stream->addr = buff_addr; | ||
audio_stream->end_addr = (char *)audio_stream->addr + size; | ||
|
||
/* set the default alignment info. | ||
* set byte_align as 1 means no alignment limit on byte. | ||
* set frame_align as 1 means no alignment limit on frame. | ||
*/ | ||
audio_stream_init_alignment_constants(1, 1, audio_stream); | ||
|
||
source_init(audio_stream_get_source(audio_stream), &audio_stream_source_ops, | ||
(__sparse_force struct sof_audio_stream_params *) | ||
&audio_stream->runtime_stream_params); | ||
sink_init(audio_stream_get_sink(audio_stream), &audio_stream_sink_ops, | ||
(__sparse_force struct sof_audio_stream_params *) | ||
&audio_stream->runtime_stream_params); | ||
audio_stream_reset(audio_stream); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea what this means either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a limited calculation frame number function audio_stream_avail_frames_aligned, it use shift to replace division, the byte_align and frame_align is for shift index calculation.