pipeline2.0: introduce sink/source utilities

There are many operations on sink/source that may be put into a
common library. This is the place for it.

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
This commit is contained in:
Marcin Szkudlinski 2023-04-17 15:41:00 +02:00 committed by Michal Wasko
parent 7462552f12
commit 305f8a2088
15 changed files with 116 additions and 0 deletions

View File

@ -13,6 +13,7 @@ if((NOT CONFIG_LIBRARY) OR CONFIG_LIBRARY_STATIC)
buffer.c
source_api_helper.c
sink_api_helper.c
sink_source_utils.c
channel_map.c
)
if(CONFIG_COMP_BLOB)

View File

@ -0,0 +1,73 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
#include <sof/audio/sink_source_utils.h>
#include <sof/audio/sink_api.h>
#include <sof/audio/source_api.h>
#include <sof/common.h>
#include <rtos/panic.h>
#include <rtos/string.h>
#include <sof/math/numbers.h>
#include <limits.h>
int source_to_sink_copy(struct sof_source __sparse_cache *source,
struct sof_sink __sparse_cache *sink, bool free, size_t size)
{
uint8_t *src_ptr;
uint8_t *src_begin;
uint8_t *src_end;
uint8_t *dst_ptr;
uint8_t *dst_begin;
uint8_t *dst_end;
size_t src_size, dst_size;
int ret;
if (!size)
return 0;
if (size > source_get_data_available(source))
return -EFBIG;
if (size > sink_get_free_size(sink))
return -ENOSPC;
ret = source_get_data(source, size,
(void **)&src_ptr,
(void **)&src_begin,
&src_size);
if (ret)
return ret;
ret = sink_get_buffer(sink, size,
(void **)&dst_ptr,
(void **)&dst_begin,
&dst_size);
if (ret) {
source_release_data(source, 0);
return ret;
}
src_end = src_begin + src_size;
dst_end = dst_begin + dst_size;
while (size) {
uint32_t src_to_buf_overlap = (uintptr_t)src_end - (uintptr_t)src_ptr;
uint32_t dst_to_buf_overlap = (uintptr_t)dst_end - (uintptr_t)dst_ptr;
uint32_t to_copy = MIN(src_to_buf_overlap, dst_to_buf_overlap);
to_copy = MIN(to_copy, size);
ret = memcpy_s(dst_ptr, dst_to_buf_overlap, src_ptr, to_copy);
assert(!ret);
size -= to_copy;
src_ptr += to_copy;
dst_ptr += to_copy;
if (to_copy == src_to_buf_overlap)
src_ptr = src_begin;
if (to_copy == dst_to_buf_overlap)
dst_ptr = dst_begin;
}
source_release_data(source, free ? INT_MAX : 0);
sink_commit_buffer(sink, INT_MAX);
return 0;
}

View File

@ -0,0 +1,25 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
*/
#ifndef SINK_SOURCE_UTILS_H
#define SINK_SOURCE_UTILS_H
#include <sof/audio/sink_api.h>
#include <sof/audio/source_api.h>
/**
* copy bytes from source to sink
*
* @param source the data source
* @param sink the data target
* @param free if true, data from source will be freed
* if false, data will remain in the source
* @param size number of bytes to be copied
*/
int source_to_sink_copy(struct sof_source __sparse_cache *source,
struct sof_sink __sparse_cache *sink, bool free, size_t size);
#endif /* SINK_SOURCE_UTILS_H */

View File

@ -6,6 +6,7 @@ cmocka_test(buffer_copy
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
@ -26,6 +27,7 @@ cmocka_test(buffer_new
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
@ -45,6 +47,7 @@ cmocka_test(buffer_wrap
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
@ -64,6 +67,7 @@ cmocka_test(buffer_write
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c

View File

@ -12,6 +12,7 @@ cmocka_test(comp_set_state
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-schedule.c

View File

@ -25,6 +25,7 @@ add_library(audio_for_eq_fir STATIC
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/audio/component.c
${PROJECT_SOURCE_DIR}/src/audio/data_blob.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c

View File

@ -25,6 +25,7 @@ add_library(audio_for_eq_iir STATIC
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/audio/component.c
${PROJECT_SOURCE_DIR}/src/audio/data_blob.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c

View File

@ -15,6 +15,7 @@ cmocka_test(mixer
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/audio/component.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c

View File

@ -16,6 +16,7 @@ add_library(
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/math/numbers.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c

View File

@ -9,6 +9,7 @@ if(CONFIG_FORMAT_FLOAT)
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/audio/component.c
${PROJECT_SOURCE_DIR}/src/audio/data_blob.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c

View File

@ -27,6 +27,7 @@ cmocka_test(pipeline_new
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c
@ -47,6 +48,7 @@ cmocka_test(pipeline_connect_upstream
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c
@ -67,6 +69,7 @@ cmocka_test(pipeline_free
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-graph.c
${PROJECT_SOURCE_DIR}/src/audio/pipeline/pipeline-params.c

View File

@ -18,6 +18,7 @@ add_library(audio_for_selector STATIC
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c

View File

@ -22,6 +22,7 @@ add_library(audio_for_volume STATIC
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c

View File

@ -10,6 +10,7 @@ cmocka_test(fft
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_api_helper.c
${PROJECT_SOURCE_DIR}/src/audio/sink_source_utils.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c

View File

@ -396,6 +396,7 @@ zephyr_library_sources(
${SOF_AUDIO_PATH}/buffer.c
${SOF_AUDIO_PATH}/source_api_helper.c
${SOF_AUDIO_PATH}/sink_api_helper.c
${SOF_AUDIO_PATH}/sink_source_utils.c
${SOF_AUDIO_PATH}/component.c
${SOF_AUDIO_PATH}/pipeline/pipeline-graph.c
${SOF_AUDIO_PATH}/pipeline/pipeline-params.c