-
Notifications
You must be signed in to change notification settings - Fork 325
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
Pipeline2.0 STEP2 - move hybrid buffering logic from comp_buffer to audio_buffer and partially place comp_buffer on top of audio_buffer #9299
Merged
lgirdwood
merged 6 commits into
thesofproject:main
from
marcinszkudlinski:pipeline2_0_002
Sep 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1999dba
bug: missed fixes when CONFIG_INCOHERENT=0
marcinszkudlinski e7a4998
buf: add secondary buffer support to struct audio_buffer
marcinszkudlinski 5affb69
buf: introduce ops instead of a single free function
marcinszkudlinski b787a71
buf: rename buffer.c to comp_buffer.c and move to buffers
marcinszkudlinski e8b3f66
buf: make comp_buffer use sof_audio_buffer base
marcinszkudlinski 04bea35
buf: missing dp_queue rename to ring_buffer
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,97 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// Copyright(c) 2024 Intel Corporation. All rights reserved. | ||
// | ||
// Author: Marcin Szkudlinski <[email protected]> | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <errno.h> | ||
#include <rtos/alloc.h> | ||
#include <sof/audio/audio_buffer.h> | ||
#include <sof/audio/sink_api.h> | ||
#include <sof/audio/source_api.h> | ||
#include <sof/audio/sink_source_utils.h> | ||
|
||
#if CONFIG_PIPELINE_2_0 | ||
|
||
int audio_buffer_attach_secondary_buffer(struct sof_audio_buffer *buffer, bool at_input, | ||
struct sof_audio_buffer *secondary_buffer) | ||
{ | ||
if (buffer->secondary_buffer_sink || buffer->secondary_buffer_source) | ||
return -EINVAL; | ||
|
||
/* secondary buffer must share audio params with the primary buffer */ | ||
secondary_buffer->audio_stream_params = buffer->audio_stream_params; | ||
/* for performance reasons pointers to params are also kept in sink/src structures */ | ||
secondary_buffer->_sink_api.audio_stream_params = buffer->audio_stream_params; | ||
secondary_buffer->_source_api.audio_stream_params = buffer->audio_stream_params; | ||
|
||
if (at_input) | ||
buffer->secondary_buffer_sink = secondary_buffer; | ||
else | ||
buffer->secondary_buffer_source = secondary_buffer; | ||
|
||
return 0; | ||
} | ||
|
||
int audio_buffer_sync_secondary_buffer(struct sof_audio_buffer *buffer, size_t limit) | ||
{ | ||
int err; | ||
|
||
struct sof_source *data_src; | ||
struct sof_sink *data_dst; | ||
|
||
if (buffer->secondary_buffer_sink) { | ||
/* | ||
* audio_buffer sink API is shadowed, that means there's a secondary_buffer | ||
* at data input | ||
* get data from secondary_buffer (use source API) | ||
* copy to primary buffer (use sink API) | ||
* note! can't use audio_buffer_get_sink because it will provide a shadowed | ||
* sink handler (to a secondary buffer). | ||
*/ | ||
data_src = audio_buffer_get_source(buffer->secondary_buffer_sink); | ||
data_dst = &buffer->_sink_api; /* primary buffer's sink API */ | ||
} else if (buffer->secondary_buffer_source) { | ||
/* | ||
* comp_buffer source API is shadowed, that means there's a secondary_buffer | ||
* at data output | ||
* get data from comp_buffer (use source API) | ||
* copy to secondary_buffer (use sink API) | ||
*/ | ||
data_src = &buffer->_source_api; | ||
data_dst = audio_buffer_get_sink(buffer->secondary_buffer_source); | ||
|
||
} else { | ||
return -EINVAL; | ||
} | ||
|
||
/* | ||
* keep data_available and free_size in local variables to avoid check_time/use_time | ||
* race in MIN macro | ||
*/ | ||
size_t data_available = source_get_data_available(data_src); | ||
size_t free_size = sink_get_free_size(data_dst); | ||
size_t to_copy = MIN(MIN(data_available, free_size), limit); | ||
|
||
err = source_to_sink_copy(data_src, data_dst, true, to_copy); | ||
return err; | ||
} | ||
|
||
#endif /* CONFIG_PIPELINE_2_0 */ | ||
|
||
void audio_buffer_free(struct sof_audio_buffer *buffer) | ||
{ | ||
if (!buffer) | ||
return; | ||
|
||
CORE_CHECK_STRUCT(buffer); | ||
#if CONFIG_PIPELINE_2_0 | ||
audio_buffer_free(buffer->secondary_buffer_sink); | ||
audio_buffer_free(buffer->secondary_buffer_source); | ||
#endif /* CONFIG_PIPELINE_2_0 */ | ||
if (buffer->free) | ||
buffer->free(buffer); | ||
rfree(buffer); | ||
} |
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.
this seems to make 3 copies of stream parameters, so now we have 4 of them on the total? This seems really redundant. Is this a temporary situation until buffers are migrated to the new API? Maybe make one of them where it finally should be and use pointers at all other locations? TBH I'm a bit confused about the roadmap of the migration, how far we're into it and what is still left to do. @marcinszkudlinski maybe you could make a "feature" to explain the steps made so far, the current configuration (what types of buffers we currently have, what copying is done, etc.) and the roadmap?