Repository navigation
Expand file tree
/
Copy pathsink_source_utils.h
More file actions
78 lines (69 loc) · 2.39 KB
/
Copy pathsink_source_utils.h
File metadata and controls
78 lines (69 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 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>
#include <sof/math/numbers.h>
/**
* release processed data from source and commit produced data to sink
*
* @param source the data source to release data from
* @param free_size number of bytes to be released (freed) from the source
* @param sink the data target to commit data to
* @param commit_size number of bytes to be committed to the sink
*
* @return 0 on success;
* on error, the error code returned by source_release_data() takes
* precedence, otherwise the error code returned by sink_commit_buffer()
* is returned. The sink is always committed regardless of the source
* release result.
*/
int release_source_and_commit_sink(struct sof_source *source, size_t free_size,
struct sof_sink *sink, size_t commit_size);
/**
* 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 *source,
struct sof_sink *sink, bool free, size_t size);
/**
* fill sink with silence (zeros)
*
* @param sink the target to be filled with silence
* @param size number of bytes to be filled
*/
int sink_fill_with_silence(struct sof_sink *sink, size_t size);
/**
* drop data from source
*
* @param source the source of data to be dropped
* @param size number of bytes to be dropped
*/
int source_drop_data(struct sof_source *source, size_t size);
/**
* Computes maximum number of frames aligned with the source align criteria
* that can be copied from source to sink, verifying the number of available
* source frames vs. free space available in sink.
*
* @param source the data source
* @param sink the data sink
* @return Number of aligned frames available for processing.
*/
static inline size_t source_sink_avail_frames_aligned(struct sof_source *source,
struct sof_sink *sink)
{
size_t src_frames = source_get_data_frames_available(source);
size_t sink_frames = sink_get_free_frames(sink);
size_t n = MIN(src_frames, sink_frames);
return source_align_frames_round_down(source, n);
}
#endif /* SINK_SOURCE_UTILS_H */