|
9 | 9 | #include <sof/audio/audio_buffer.h> |
10 | 10 | #include <sof/audio/buffer.h> |
11 | 11 |
|
12 | | -static size_t audio_stream_get_free_size(struct sof_sink *sink) |
13 | | -{ |
14 | | - struct audio_stream *audio_stream = container_of(sink, struct audio_stream, _sink_api); |
15 | | - |
16 | | - return audio_stream_get_free_bytes(audio_stream); |
17 | | -} |
18 | | - |
19 | | -static int audio_stream_get_buffer(struct sof_sink *sink, size_t req_size, |
20 | | - void **data_ptr, void **buffer_start, size_t *buffer_size) |
21 | | -{ |
22 | | - struct audio_stream *audio_stream = container_of(sink, struct audio_stream, _sink_api); |
23 | | - |
24 | | - if (req_size > audio_stream_get_free_size(sink)) |
25 | | - return -ENODATA; |
26 | | - |
27 | | - /* get circular buffer parameters */ |
28 | | - *data_ptr = audio_stream->w_ptr; |
29 | | - *buffer_start = audio_stream->addr; |
30 | | - *buffer_size = audio_stream->size; |
31 | | - return 0; |
32 | | -} |
33 | | - |
34 | | -static int audio_stream_commit_buffer(struct sof_sink *sink, size_t commit_size) |
35 | | -{ |
36 | | - struct audio_stream *audio_stream = container_of(sink, struct audio_stream, _sink_api); |
37 | | - struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream); |
38 | | - |
39 | | - if (commit_size) { |
40 | | - buffer_stream_writeback(buffer, commit_size); |
41 | | - audio_stream_produce(audio_stream, commit_size); |
42 | | - } |
43 | | - |
44 | | - return 0; |
45 | | -} |
46 | | - |
47 | | -static size_t audio_stream_get_data_available(struct sof_source *source) |
48 | | -{ |
49 | | - struct audio_stream *audio_stream = container_of(source, struct audio_stream, _source_api); |
50 | | - |
51 | | - return audio_stream_get_avail_bytes(audio_stream); |
52 | | -} |
53 | | - |
54 | | -static int audio_stream_get_data(struct sof_source *source, size_t req_size, |
55 | | - void const **data_ptr, void const **buffer_start, |
56 | | - size_t *buffer_size) |
57 | | -{ |
58 | | - struct audio_stream *audio_stream = container_of(source, struct audio_stream, _source_api); |
59 | | - struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream); |
60 | | - |
61 | | - if (req_size > audio_stream_get_data_available(source)) |
62 | | - return -ENODATA; |
63 | | - |
64 | | - buffer_stream_invalidate(buffer, req_size); |
65 | | - |
66 | | - /* get circular buffer parameters */ |
67 | | - *data_ptr = audio_stream->r_ptr; |
68 | | - *buffer_start = audio_stream->addr; |
69 | | - *buffer_size = audio_stream->size; |
70 | | - return 0; |
71 | | -} |
72 | | - |
73 | 12 | static uint32_t audio_stream_frame_align_get(const uint32_t byte_align, |
74 | 13 | const uint32_t frame_align_req, |
75 | 14 | uint32_t frame_size) |
@@ -105,132 +44,12 @@ void audio_stream_set_align(const uint32_t byte_align, |
105 | 44 | audio_stream_recalc_align(stream); |
106 | 45 | } |
107 | 46 | EXPORT_SYMBOL(audio_stream_set_align); |
108 | | - |
109 | | -static int audio_stream_release_data(struct sof_source *source, size_t free_size) |
110 | | -{ |
111 | | - struct audio_stream *audio_stream = container_of(source, struct audio_stream, _source_api); |
112 | | - |
113 | | - if (free_size) |
114 | | - audio_stream_consume(audio_stream, free_size); |
115 | | - |
116 | | - return 0; |
117 | | -} |
118 | | - |
119 | | -static int audio_stream_set_ipc_params_source(struct sof_source *source, |
120 | | - struct sof_ipc_stream_params *params, |
121 | | - bool force_update) |
122 | | -{ |
123 | | - struct audio_stream *audio_stream = container_of(source, struct audio_stream, _source_api); |
124 | | - struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream); |
125 | | - |
126 | | - return buffer_set_params(buffer, params, force_update); |
127 | | -} |
128 | | - |
129 | | -static int audio_stream_set_ipc_params_sink(struct sof_sink *sink, |
130 | | - struct sof_ipc_stream_params *params, |
131 | | - bool force_update) |
132 | | -{ |
133 | | - struct audio_stream *audio_stream = container_of(sink, struct audio_stream, _sink_api); |
134 | | - struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream); |
135 | | - |
136 | | - return buffer_set_params(buffer, params, force_update); |
137 | | -} |
138 | | - |
139 | | -static int audio_stream_source_set_alignment_constants(struct sof_source *source, |
140 | | - const uint32_t byte_align, |
141 | | - const uint32_t frame_align_req) |
142 | | -{ |
143 | | - struct audio_stream *audio_stream = container_of(source, struct audio_stream, _source_api); |
144 | | - |
145 | | - audio_stream_set_align(byte_align, frame_align_req, audio_stream); |
146 | | - |
147 | | - return 0; |
148 | | -} |
149 | | - |
150 | | -static int audio_stream_sink_set_alignment_constants(struct sof_sink *sink, |
151 | | - const uint32_t byte_align, |
152 | | - const uint32_t frame_align_req) |
153 | | -{ |
154 | | - struct audio_stream *audio_stream = container_of(sink, struct audio_stream, _sink_api); |
155 | | - |
156 | | - audio_stream_set_align(byte_align, frame_align_req, audio_stream); |
157 | | - |
158 | | - return 0; |
159 | | -} |
160 | | - |
161 | | -static int source_format_set(struct sof_source *source) |
162 | | -{ |
163 | | - struct audio_stream *s = container_of(source, struct audio_stream, _source_api); |
164 | | - |
165 | | - audio_stream_recalc_align(s); |
166 | | - return 0; |
167 | | -} |
168 | | - |
169 | | -static int sink_format_set(struct sof_sink *sink) |
170 | | -{ |
171 | | - struct audio_stream *s = container_of(sink, struct audio_stream, _sink_api); |
172 | | - |
173 | | - audio_stream_recalc_align(s); |
174 | | - return 0; |
175 | | -} |
176 | | - |
177 | | -static const struct source_ops audio_stream_source_ops = { |
178 | | - .get_data_available = audio_stream_get_data_available, |
179 | | - .get_data = audio_stream_get_data, |
180 | | - .release_data = audio_stream_release_data, |
181 | | - .audio_set_ipc_params = audio_stream_set_ipc_params_source, |
182 | | - .on_audio_format_set = source_format_set, |
183 | | - .set_alignment_constants = audio_stream_source_set_alignment_constants |
184 | | -}; |
185 | | - |
186 | | -static const struct sink_ops audio_stream_sink_ops = { |
187 | | - .get_free_size = audio_stream_get_free_size, |
188 | | - .get_buffer = audio_stream_get_buffer, |
189 | | - .commit_buffer = audio_stream_commit_buffer, |
190 | | - .audio_set_ipc_params = audio_stream_set_ipc_params_sink, |
191 | | - .on_audio_format_set = sink_format_set, |
192 | | - .set_alignment_constants = audio_stream_sink_set_alignment_constants |
193 | | -}; |
194 | | - |
195 | 47 | void audio_stream_init(struct audio_stream *audio_stream, void *buff_addr, uint32_t size) |
196 | 48 | { |
197 | 49 | audio_stream->size = size; |
198 | 50 | audio_stream->addr = buff_addr; |
199 | 51 | audio_stream->end_addr = (char *)audio_stream->addr + size; |
200 | 52 |
|
201 | 53 | audio_stream_set_align(1, 1, audio_stream); |
202 | | - source_init(audio_stream_get_source(audio_stream), &audio_stream_source_ops, |
203 | | - &audio_stream->runtime_stream_params); |
204 | | - sink_init(audio_stream_get_sink(audio_stream), &audio_stream_sink_ops, |
205 | | - &audio_stream->runtime_stream_params); |
206 | 54 | audio_stream_reset(audio_stream); |
207 | 55 | } |
208 | | - |
209 | | -/* get a handler to source API */ |
210 | | -#if CONFIG_PIPELINE_2_0 |
211 | | -struct sof_source *audio_stream_get_source(struct audio_stream *audio_stream) |
212 | | -{ |
213 | | - return audio_stream->secondary_buffer_source ? |
214 | | - audio_buffer_get_source(audio_stream->secondary_buffer_source) : |
215 | | - &audio_stream->_source_api; |
216 | | -} |
217 | | - |
218 | | -struct sof_sink *audio_stream_get_sink(struct audio_stream *audio_stream) |
219 | | -{ |
220 | | - return audio_stream->secondary_buffer_sink ? |
221 | | - audio_buffer_get_sink(audio_stream->secondary_buffer_sink) : |
222 | | - &audio_stream->_sink_api; |
223 | | -} |
224 | | - |
225 | | -#else /* CONFIG_PIPELINE_2_0 */ |
226 | | - |
227 | | -struct sof_source *audio_stream_get_source(struct audio_stream *audio_stream) |
228 | | -{ |
229 | | - return &audio_stream->_source_api; |
230 | | -} |
231 | | - |
232 | | -struct sof_sink *audio_stream_get_sink(struct audio_stream *audio_stream) |
233 | | -{ |
234 | | - return &audio_stream->_sink_api; |
235 | | -} |
236 | | -#endif /* CONFIG_PIPELINE_2_0 */ |
0 commit comments