Skip to content

Commit 1c28401

Browse files
buf: make pipeline management code using comp_buffer API
This commit make all pipeline management code using comp_buffer API. Since now, no access to comp_buffer internals should be performed by the SOF code (with exception of uint test) Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent 0b08e57 commit 1c28401

File tree

9 files changed

+87
-140
lines changed

9 files changed

+87
-140
lines changed

src/audio/buffers/comp_buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, u
212212
audio_stream_set_underrun(&buffer->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
213213
audio_stream_set_overrun(&buffer->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));
214214

215-
list_init(&buffer->source_list);
216-
list_init(&buffer->sink_list);
215+
comp_buffer_reset_source_list(buffer);
216+
comp_buffer_reset_sink_list(buffer);
217217

218218
return buffer;
219219
}

src/audio/module_adapter/module_adapter.c

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int module_adapter_prepare(struct comp_dev *dev)
230230
/* Get period_bytes first on prepare(). At this point it is guaranteed that the stream
231231
* parameter from sink buffer is settled, and still prior to all references to period_bytes.
232232
*/
233-
sink = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
233+
sink = comp_dev_get_first_data_consumer(dev);
234234

235235
mod->period_bytes = audio_stream_period_bytes(&sink->stream, dev->frames);
236236
comp_dbg(dev, "module_adapter_prepare(): got period_bytes = %u", mod->period_bytes);
@@ -621,17 +621,14 @@ static void module_adapter_process_output(struct comp_dev *dev)
621621

622622
/* copy from all output local buffers to sink buffers */
623623
i = 0;
624-
list_for_item(blist, &dev->bsink_list) {
625-
struct list_item *_blist;
624+
comp_dev_for_each_consumer(dev, sink) {
626625
int j = 0;
627626

628-
list_for_item(_blist, &mod->raw_data_buffers_list) {
627+
list_for_item(blist, &mod->raw_data_buffers_list) {
629628
if (i == j) {
630629
struct comp_buffer *source;
631630

632-
sink = container_of(blist, struct comp_buffer, source_list);
633-
source = container_of(_blist, struct comp_buffer, buffers_list);
634-
631+
source = container_of(blist, struct comp_buffer, buffers_list);
635632
module_copy_samples(dev, source, sink,
636633
mod->output_buffers[i].size);
637634

@@ -756,7 +753,7 @@ static int module_adapter_audio_stream_copy_1to1(struct comp_dev *dev)
756753
/* Note: Source buffer state is not checked to enable mixout to generate zero
757754
* PCM codes when source is not active.
758755
*/
759-
if (mod->sink_comp_buffer->sink->state == dev->state)
756+
if (comp_buffer_get_sink_state(mod->sink_comp_buffer) == dev->state)
760757
num_output_buffers = 1;
761758

762759
ret = module_process_legacy(mod, mod->input_buffers, 1,
@@ -783,10 +780,11 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev)
783780
{
784781
struct comp_buffer *sources[PLATFORM_MAX_STREAMS];
785782
struct comp_buffer *sinks[PLATFORM_MAX_STREAMS];
783+
struct comp_buffer *sink;
784+
struct comp_buffer *source;
786785
struct processing_module *mod = comp_mod(dev);
787-
struct list_item *blist;
788786
uint32_t num_input_buffers, num_output_buffers;
789-
int ret, i = 0;
787+
int ret, i;
790788

791789
/* handle special case of HOST/DAI type components */
792790
if (dev->ipc_config.type == SOF_COMP_HOST || dev->ipc_config.type == SOF_COMP_DAI)
@@ -796,25 +794,18 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev)
796794
return module_adapter_audio_stream_copy_1to1(dev);
797795

798796
/* acquire all sink and source buffers */
799-
list_for_item(blist, &dev->bsink_list) {
800-
struct comp_buffer *sink;
801-
802-
sink = container_of(blist, struct comp_buffer, source_list);
797+
i = 0;
798+
comp_dev_for_each_consumer(dev, sink)
803799
sinks[i++] = sink;
804-
}
805800
num_output_buffers = i;
806801
if (num_output_buffers > mod->max_sinks) {
807802
comp_err(dev, "Invalid number of sinks %d\n", num_output_buffers);
808803
return -EINVAL;
809804
}
810805

811806
i = 0;
812-
list_for_item(blist, &dev->bsource_list) {
813-
struct comp_buffer *source;
814-
815-
source = container_of(blist, struct comp_buffer, sink_list);
807+
comp_dev_for_each_producer(dev, source)
816808
sources[i++] = source;
817-
}
818809
num_input_buffers = i;
819810
if (num_input_buffers > mod->max_sources) {
820811
comp_err(dev, "Invalid number of sources %d\n", num_input_buffers);
@@ -824,11 +815,11 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev)
824815
/* setup active input/output buffers for processing */
825816
if (num_output_buffers == 1) {
826817
module_single_sink_setup(dev, sources, sinks);
827-
if (sinks[0]->sink->state != dev->state)
818+
if (comp_buffer_get_sink_state(sinks[0]) != dev->state)
828819
num_output_buffers = 0;
829820
} else if (num_input_buffers == 1) {
830821
module_single_source_setup(dev, sources, sinks);
831-
if (sources[0]->source->state != dev->state) {
822+
if (comp_buffer_get_source_state(sources[0]) != dev->state) {
832823
num_input_buffers = 0;
833824
}
834825
} else {
@@ -910,15 +901,13 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev)
910901
* This is an adapter, to be removed when pipeline2.0 is ready
911902
*/
912903
struct processing_module *mod = comp_mod(dev);
913-
struct list_item *blist;
904+
struct comp_buffer *buffer;
914905
int err;
915906

916-
list_for_item(blist, &dev->bsource_list) {
907+
comp_dev_for_each_producer(dev, buffer) {
917908
/* input - we need to copy data from audio_stream (as source)
918909
* to ring_buffer (as sink)
919910
*/
920-
struct comp_buffer *buffer =
921-
container_of(blist, struct comp_buffer, sink_list);
922911
err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, UINT_MAX);
923912

924913
if (err) {
@@ -930,7 +919,7 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev)
930919
if (mod->dp_startup_delay)
931920
return 0;
932921

933-
list_for_item(blist, &dev->bsink_list) {
922+
comp_dev_for_each_consumer(dev, buffer) {
934923
/* output - we need to copy data from ring_buffer (as source)
935924
* to audio_stream (as sink)
936925
*
@@ -943,8 +932,6 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev)
943932
*
944933
* FIX: copy only the following module's IBS in each LL cycle
945934
*/
946-
struct comp_buffer *buffer =
947-
container_of(blist, struct comp_buffer, source_list);
948935
struct sof_source *following_mod_data_source =
949936
audio_buffer_get_source(&buffer->audio_buffer);
950937

@@ -1021,14 +1008,12 @@ static int module_adapter_raw_data_type_copy(struct comp_dev *dev)
10211008
}
10221009

10231010
/* copy source samples into input buffer */
1024-
list_for_item(blist, &dev->bsource_list) {
1011+
comp_dev_for_each_producer(dev, source) {
10251012
uint32_t bytes_to_process;
10261013
int frames, source_frame_bytes;
10271014

1028-
source = container_of(blist, struct comp_buffer, sink_list);
1029-
10301015
/* check if the source dev is in the same state as the dev */
1031-
if (!source->source || source->source->state != dev->state)
1016+
if (comp_buffer_get_source_state(source) != dev->state)
10321017
continue;
10331018

10341019
frames = MIN(min_free_frames,
@@ -1061,10 +1046,7 @@ static int module_adapter_raw_data_type_copy(struct comp_dev *dev)
10611046

10621047
i = 0;
10631048
/* consume from all input buffers */
1064-
list_for_item(blist, &dev->bsource_list) {
1065-
1066-
source = container_of(blist, struct comp_buffer, sink_list);
1067-
1049+
comp_dev_for_each_producer(dev, source) {
10681050
comp_update_buffer_consume(source, mod->input_buffers[i].consumed);
10691051

10701052
bzero((__sparse_force void *)mod->input_buffers[i].data, size);

src/audio/module_adapter/module_adapter_ipc3.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ void module_adapter_check_data(struct processing_module *mod, struct comp_dev *d
121121
*/
122122
if (IS_PROCESSING_MODE_AUDIO_STREAM(mod) && mod->num_of_sources == 1 &&
123123
mod->num_of_sinks == 1) {
124-
mod->source_comp_buffer = list_first_item(&dev->bsource_list,
125-
struct comp_buffer, sink_list);
124+
mod->source_comp_buffer = comp_dev_get_first_data_producer(dev);
126125
mod->sink_comp_buffer = sink;
127126
mod->stream_copy_single_to_single = true;
128127
}
@@ -134,24 +133,20 @@ void module_adapter_set_params(struct processing_module *mod, struct sof_ipc_str
134133

135134
static int module_source_state_count(struct comp_dev *dev, uint32_t state)
136135
{
137-
struct list_item *blist;
138136
int count = 0;
137+
struct comp_buffer *source;
139138

140139
/* count source with state == status */
141-
list_for_item(blist, &dev->bsource_list) {
140+
comp_dev_for_each_producer(dev, source)
142141
/*
143142
* FIXME: this is racy, state can be changed by another core.
144143
* This is implicitly protected by serialised IPCs. Even when
145144
* IPCs are processed in the pipeline thread, the next IPC will
146145
* not be sent until the thread has processed and replied to the
147146
* current one.
148147
*/
149-
struct comp_buffer *source = container_of(blist, struct comp_buffer,
150-
sink_list);
151-
152-
if (source->source && source->source->state == state)
148+
if (comp_buffer_get_source_state(source) == state)
153149
count++;
154-
}
155150

156151
return count;
157152
}
@@ -324,25 +319,21 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s
324319
int module_adapter_sink_src_prepare(struct comp_dev *dev)
325320
{
326321
struct processing_module *mod = comp_mod(dev);
327-
struct list_item *blist;
322+
struct comp_buffer *sink_buffer;
323+
struct comp_buffer *source_buffer;
328324
int ret;
329325
int i;
330326

331327
/* acquire all sink and source buffers, get handlers to sink/source API */
332328
i = 0;
333-
list_for_item(blist, &dev->bsink_list) {
334-
struct comp_buffer *sink_buffer =
335-
container_of(blist, struct comp_buffer, source_list);
329+
comp_dev_for_each_consumer(dev, sink_buffer) {
336330
mod->sinks[i] = audio_buffer_get_sink(&sink_buffer->audio_buffer);
337331
i++;
338332
}
339333
mod->num_of_sinks = i;
340334

341335
i = 0;
342-
list_for_item(blist, &dev->bsource_list) {
343-
struct comp_buffer *source_buffer =
344-
container_of(blist, struct comp_buffer, sink_list);
345-
336+
comp_dev_for_each_producer(dev, source_buffer) {
346337
mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer);
347338
i++;
348339
}

src/audio/module_adapter/module_adapter_ipc4.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,20 @@ EXPORT_SYMBOL(module_adapter_get_attribute);
187187
static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev)
188188
{
189189
struct processing_module *mod = comp_mod(dev);
190-
struct list_item *blist;
190+
struct comp_buffer *sink_buffer;
191+
struct comp_buffer *source_buffer;
191192
int i;
192193

193194
/* acquire all sink and source buffers, get handlers to sink/source API */
194195
i = 0;
195-
list_for_item(blist, &dev->bsink_list) {
196-
struct comp_buffer *sink_buffer =
197-
container_of(blist, struct comp_buffer, source_list);
196+
comp_dev_for_each_consumer(dev, sink_buffer) {
198197
mod->sinks[i] = audio_buffer_get_sink(&sink_buffer->audio_buffer);
199198
i++;
200199
}
201200
mod->num_of_sinks = i;
202201

203202
i = 0;
204-
list_for_item(blist, &dev->bsource_list) {
205-
struct comp_buffer *source_buffer =
206-
container_of(blist, struct comp_buffer, sink_list);
207-
203+
comp_dev_for_each_producer(dev, source_buffer) {
208204
mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer);
209205
i++;
210206
}
@@ -216,9 +212,8 @@ static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev)
216212
return true;
217213

218214
/* re-assign the source/sink modules */
219-
mod->sink_comp_buffer = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
220-
mod->source_comp_buffer = list_first_item(&dev->bsource_list,
221-
struct comp_buffer, sink_list);
215+
mod->sink_comp_buffer = comp_dev_get_first_data_consumer(dev);
216+
mod->source_comp_buffer = comp_dev_get_first_data_producer(dev);
222217

223218
return false;
224219
}

src/audio/pipeline/pipeline-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ static void buffer_set_comp(struct comp_buffer *buffer, struct comp_dev *comp,
167167
int dir)
168168
{
169169
if (dir == PPL_CONN_DIR_COMP_TO_BUFFER)
170-
buffer->source = comp;
170+
comp_buffer_set_source_component(buffer, comp);
171171
else
172-
buffer->sink = comp;
172+
comp_buffer_set_sink_component(buffer, comp);
173173
}
174174

175175
int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,

src/ipc/ipc-helper.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ static void comp_update_params(uint32_t flag,
115115
int comp_verify_params(struct comp_dev *dev, uint32_t flag,
116116
struct sof_ipc_stream_params *params)
117117
{
118-
struct list_item *buffer_list;
119118
struct list_item *source_list;
120119
struct list_item *sink_list;
121-
struct list_item *clist;
122120
struct comp_buffer *sinkb;
123121
struct comp_buffer *buf;
124122
int dir = dev->direction;
@@ -136,13 +134,9 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
136134
*/
137135
if (list_is_empty(source_list) != list_is_empty(sink_list)) {
138136
if (list_is_empty(sink_list))
139-
buf = list_first_item(source_list,
140-
struct comp_buffer,
141-
sink_list);
137+
buf = comp_dev_get_first_data_producer(dev);
142138
else
143-
buf = list_first_item(sink_list,
144-
struct comp_buffer,
145-
source_list);
139+
buf = comp_dev_get_first_data_consumer(dev);
146140

147141
/* update specific pcm parameter with buffer parameter if
148142
* specific flag is set.
@@ -160,18 +154,22 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
160154
/* for other components we iterate over all downstream buffers
161155
* (for playback) or upstream buffers (for capture).
162156
*/
163-
buffer_list = comp_buffer_list(dev, dir);
164-
165-
list_for_item(clist, buffer_list) {
166-
buf = buffer_from_list(clist, dir);
167-
comp_update_params(flag, params, buf);
168-
buffer_set_params(buf, params, BUFFER_UPDATE_FORCE);
157+
if (dir == PPL_DIR_DOWNSTREAM) {
158+
comp_dev_for_each_consumer(dev, buf) {
159+
comp_update_params(flag, params, buf);
160+
buffer_set_params(buf, params,
161+
BUFFER_UPDATE_FORCE);
162+
}
163+
} else {
164+
comp_dev_for_each_producer(dev, buf) {
165+
comp_update_params(flag, params, buf);
166+
buffer_set_params(buf, params,
167+
BUFFER_UPDATE_FORCE);
168+
}
169169
}
170170

171171
/* fetch sink buffer in order to calculate period frames */
172-
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer,
173-
source_list);
174-
172+
sinkb = comp_dev_get_first_data_consumer(dev);
175173
component_set_nearest_period_frames(dev, audio_stream_get_rate(&sinkb->stream));
176174
}
177175

@@ -263,7 +261,8 @@ int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id)
263261
int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
264262
{
265263
struct ipc_comp_dev *icd;
266-
struct list_item *clist, *tmp;
264+
struct comp_buffer *buffer;
265+
struct comp_buffer *safe;
267266
uint32_t flags;
268267

269268
/* check whether component exists */
@@ -305,21 +304,18 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
305304
}
306305

307306
irq_local_disable(flags);
308-
list_for_item_safe(clist, tmp, &icd->cd->bsource_list) {
309-
struct comp_buffer *buffer = container_of(clist, struct comp_buffer, sink_list);
310-
311-
buffer->sink = NULL;
307+
comp_dev_for_each_producer_safe(icd->cd, buffer, safe) {
308+
comp_buffer_set_sink_component(buffer, NULL);
312309
/* This breaks the list, but we anyway delete all buffers */
313-
list_init(clist);
310+
comp_buffer_reset_sink_list(buffer);
314311
}
315312

316-
list_for_item_safe(clist, tmp, &icd->cd->bsink_list) {
317-
struct comp_buffer *buffer = container_of(clist, struct comp_buffer, source_list);
318-
319-
buffer->source = NULL;
313+
comp_dev_for_each_consumer_safe(icd->cd, buffer, safe) {
314+
comp_buffer_set_source_component(buffer, NULL);
320315
/* This breaks the list, but we anyway delete all buffers */
321-
list_init(clist);
316+
comp_buffer_reset_source_list(buffer);
322317
}
318+
323319
irq_local_enable(flags);
324320

325321
/* free component and remove from list */

0 commit comments

Comments
 (0)