Skip to content

Commit 7629c56

Browse files
move to audio_buffer
1 parent 571f10b commit 7629c56

6 files changed

Lines changed: 123 additions & 87 deletions

File tree

src/audio/buffers/comp_buffer.c

Lines changed: 2 additions & 33 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-
comp_buffer_reset_source_list(buffer);
216-
comp_buffer_reset_sink_list(buffer);
215+
audio_buffer_reset_source_list(&buffer->audio_buffer);
216+
audio_buffer_reset_sink_list(&buffer->audio_buffer);
217217

218218
return buffer;
219219
}
@@ -533,34 +533,3 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
533533
(char *)audio_stream_get_addr(&buffer->stream)));
534534
#endif
535535
}
536-
537-
static inline struct list_item *buffer_comp_list(struct comp_buffer *buffer,
538-
int dir)
539-
{
540-
return dir == PPL_DIR_DOWNSTREAM ?
541-
&buffer->source_list : &buffer->sink_list;
542-
}
543-
544-
/*
545-
* Locking: must be called with interrupts disabled! Serialized IPCs protect us
546-
* from racing attach / detach calls, but the scheduler can interrupt the IPC
547-
* thread and begin using the buffer for streaming. FIXME: this is still a
548-
* problem with different cores.
549-
*/
550-
void buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir)
551-
{
552-
struct list_item *list = buffer_comp_list(buffer, dir);
553-
CORE_CHECK_STRUCT(&buffer->audio_buffer);
554-
list_item_prepend(list, head);
555-
}
556-
557-
/*
558-
* Locking: must be called with interrupts disabled! See buffer_attach() above
559-
* for details
560-
*/
561-
void buffer_detach(struct comp_buffer *buffer, struct list_item *head, int dir)
562-
{
563-
struct list_item *buf_list = buffer_comp_list(buffer, dir);
564-
CORE_CHECK_STRUCT(&buffer->audio_buffer);
565-
list_item_del(buf_list);
566-
}

src/audio/pipeline/pipeline-graph.c

Lines changed: 4 additions & 4 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-
comp_buffer_set_source_component(buffer, comp);
170+
audio_buffer_set_source_component(&buffer->audio_buffer, comp);
171171
else
172-
comp_buffer_set_sink_component(buffer, comp);
172+
audio_buffer_set_sink_component(&buffer->audio_buffer, comp);
173173
}
174174

175175
int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
@@ -186,7 +186,7 @@ int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
186186
irq_local_disable(flags);
187187

188188
comp_list = comp_buffer_list(comp, dir);
189-
buffer_attach(buffer, comp_list, dir);
189+
audio_buffer_attach(&buffer->audio_buffer, comp_list, dir); //msz bez funkcji
190190
buffer_set_comp(buffer, comp, dir);
191191

192192
irq_local_enable(flags);
@@ -207,7 +207,7 @@ void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int
207207
irq_local_disable(flags);
208208

209209
comp_list = comp_buffer_list(comp, dir);
210-
buffer_detach(buffer, comp_list, dir);
210+
audio_buffer_detach(&buffer->audio_buffer, comp_list, dir); //msz bez funkcji
211211
buffer_set_comp(buffer, NULL, dir);
212212

213213
irq_local_enable(flags);

src/include/sof/audio/audio_buffer.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ struct sof_audio_buffer {
6969

7070
bool is_shared; /* buffer structure is shared between 2 cores */
7171

72+
/* connected components */
73+
struct comp_dev *Xsource; /* source component */
74+
struct comp_dev *Xsink; /* sink component */
75+
76+
/* lists */
77+
struct list_item Xsource_list; /* list in comp buffers */
78+
struct list_item Xsink_list; /* list in comp buffers */
79+
7280
#if CONFIG_PIPELINE_2_0
7381
/**
7482
* sink API of an additional buffer
@@ -307,4 +315,60 @@ void audio_buffer_reset(struct sof_audio_buffer *buffer)
307315
buffer->ops->reset(buffer);
308316
}
309317

318+
static inline
319+
struct comp_dev *audio_buffer_get_source_component(const struct sof_audio_buffer *buffer)
320+
{
321+
return buffer->Xsource;
322+
}
323+
324+
static inline
325+
struct comp_dev *audio_buffer_get_sink_component(const struct sof_audio_buffer *buffer)
326+
{
327+
return buffer->Xsink;
328+
}
329+
330+
static inline
331+
void audio_buffer_set_source_component(struct sof_audio_buffer *buffer, struct comp_dev *comp)
332+
{
333+
buffer->Xsource = comp;
334+
}
335+
336+
static inline
337+
void audio_buffer_set_sink_component(struct sof_audio_buffer *buffer, struct comp_dev *comp)
338+
{
339+
buffer->Xsink = comp;
340+
}
341+
static inline void audio_buffer_reset_source_list(struct sof_audio_buffer *buffer)
342+
{
343+
list_init(&buffer->Xsource_list);
344+
}
345+
346+
static inline void audio_buffer_reset_sink_list(struct sof_audio_buffer *buffer)
347+
{
348+
list_init(&buffer->Xsink_list);
349+
}
350+
351+
#define audio_buffer_from_list(ptr, dir) \
352+
((dir) == PPL_DIR_DOWNSTREAM ? \
353+
container_of(ptr, struct sof_audio_buffer, Xsource_list) : \
354+
container_of(ptr, struct sof_audio_buffer, Xsink_list))
355+
356+
/*
357+
* Attach a new buffer at the beginning of the list. Note, that "head" must
358+
* really be the head of the list, not a list head within another buffer. We
359+
* don't Synchronize its cache, so it must not be embedded in an object, using
360+
* the coherent API. The caller takes care to protect list heads.
361+
*/
362+
void audio_buffer_attach(struct sof_audio_buffer *buffer, struct list_item *head, int dir);
363+
364+
/*
365+
* Detach a buffer from anywhere in the list. "head" is again the head of the
366+
* list, we need it to verify, whether this buffer was the first or the last on
367+
* the list. Again it is assumed that the head's cache doesn't need to be
368+
* synchronized. The caller takes care to protect list heads.
369+
*/
370+
void audio_buffer_detach(struct sof_audio_buffer *buffer, struct list_item *head, int dir);
371+
372+
373+
310374
#endif /* __SOF_AUDIO_BUFFER__ */

src/include/sof/audio/buffer.h

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,54 +134,52 @@ struct comp_buffer {
134134
uint32_t core;
135135
struct tr_ctx tctx; /* trace settings */
136136

137-
/* connected components */
138-
struct comp_dev *source; /* source component */
139-
struct comp_dev *sink; /* sink component */
140-
141-
/* lists */
142-
struct list_item source_list; /* list in comp buffers */
143-
struct list_item sink_list; /* list in comp buffers */
144-
145137
/* list of buffers, to be used i.e. in raw data processing mode*/
146138
struct list_item buffers_list;
147139
};
148140

149141
/*
150142
* get a component providing data to the buffer
151143
*/
144+
//msz
152145
static inline struct comp_dev *comp_buffer_get_source_component(const struct comp_buffer *buffer)
153146
{
154-
return buffer->source;
147+
return audio_buffer_get_source_component(&buffer->audio_buffer);
155148
}
156149

157150
/*
158151
* get a component consuming data from the buffer
159152
*/
153+
//msz
160154
static inline struct comp_dev *comp_buffer_get_sink_component(const struct comp_buffer *buffer)
161155
{
162-
return buffer->sink;
156+
return audio_buffer_get_sink_component(&buffer->audio_buffer);
163157
}
164158

159+
//msz
165160
static inline
166161
void comp_buffer_set_source_component(struct comp_buffer *buffer, struct comp_dev *comp)
167162
{
168-
buffer->source = comp;
163+
audio_buffer_set_source_component(&buffer->audio_buffer, comp);
169164
}
170165

171166
static inline
172-
void comp_buffer_set_sink_component(struct comp_buffer *buffer, struct comp_dev *comp)
167+
struct comp_buffer *comp_buffer_from_audio_buffer(struct sof_audio_buffer *audio_buffer)
173168
{
174-
buffer->sink = comp;
169+
return container_of(audio_buffer, struct comp_buffer, audio_buffer);
175170
}
176171

177-
static inline void comp_buffer_reset_source_list(struct comp_buffer *buffer)
172+
static inline
173+
void comp_buffer_set_sink_component(struct comp_buffer *buffer, struct comp_dev *comp)
178174
{
179-
list_init(&buffer->source_list);
175+
audio_buffer_set_sink_component(&buffer->audio_buffer, comp);
180176
}
181177

182-
static inline void comp_buffer_reset_sink_list(struct comp_buffer *buffer)
178+
static inline
179+
struct comp_buffer *buffer_from_list(struct list_item *ptr, int dir)
183180
{
184-
list_init(&buffer->sink_list);
181+
struct sof_audio_buffer *audio_buffer = audio_buffer_from_list(ptr, dir);
182+
return comp_buffer_from_audio_buffer(audio_buffer);
185183
}
186184

187185
/* Only to be used for synchronous same-core notifications! */
@@ -195,11 +193,6 @@ struct buffer_cb_free {
195193
struct comp_buffer *buffer;
196194
};
197195

198-
#define buffer_from_list(ptr, dir) \
199-
((dir) == PPL_DIR_DOWNSTREAM ? \
200-
container_of(ptr, struct comp_buffer, source_list) : \
201-
container_of(ptr, struct comp_buffer, sink_list))
202-
203196
#define buffer_set_cb(buffer, func, data, type) \
204197
do { \
205198
buffer->cb = func; \
@@ -270,23 +263,6 @@ static inline void buffer_stream_writeback(struct comp_buffer *buffer, uint32_t
270263
#endif
271264
}
272265

273-
274-
/*
275-
* Attach a new buffer at the beginning of the list. Note, that "head" must
276-
* really be the head of the list, not a list head within another buffer. We
277-
* don't synchronise its cache, so it must not be embedded in an object, using
278-
* the coherent API. The caller takes care to protect list heads.
279-
*/
280-
void buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir);
281-
282-
/*
283-
* Detach a buffer from anywhere in the list. "head" is again the head of the
284-
* list, we need it to verify, whether this buffer was the first or the last on
285-
* the list. Again it is assumed that the head's cache doesn't need to be
286-
* synchronized. The caller takes care to protect list heads.
287-
*/
288-
void buffer_detach(struct comp_buffer *buffer, struct list_item *head, int dir);
289-
290266
static inline struct comp_dev *buffer_get_comp(struct comp_buffer *buffer, int dir)
291267
{
292268
struct comp_dev *comp = (dir == PPL_DIR_DOWNSTREAM) ?

src/include/sof/audio/component.h

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,22 +640,35 @@ struct comp_dev {
640640
* Get a pointer to the first comp_buffer object providing data to the component
641641
* The function will return NULL if there's no data provider
642642
*/
643-
static inline struct comp_buffer *comp_dev_get_first_data_producer(struct comp_dev *component)
643+
static inline struct sof_audio_buffer *Xcomp_dev_get_first_data_producer(struct comp_dev *component)
644644
{
645645
return list_is_empty(&component->bsource_list) ? NULL :
646-
list_first_item(&component->bsource_list, struct comp_buffer, sink_list);
646+
list_first_item(&component->bsource_list, struct sof_audio_buffer, Xsink_list);
647+
}
648+
649+
static inline struct comp_buffer *comp_dev_get_first_data_producer(struct comp_dev *component)
650+
{
651+
struct sof_audio_buffer *audio_buffer = Xcomp_dev_get_first_data_producer(component);
652+
return comp_buffer_from_audio_buffer(audio_buffer);
647653
}
648654

649655
/**
650656
* Get a pointer to the next comp_buffer object providing data to the component
651657
* The function will return NULL if there're no more data providers
652658
* _save version also checks if producer != NULL
653659
*/
660+
static inline struct sof_audio_buffer *Xcomp_dev_get_next_data_producer(struct comp_dev *component,
661+
struct sof_audio_buffer *producer)
662+
{
663+
return producer->Xsink_list.next == &component->bsource_list ? NULL :
664+
list_item(producer->Xsink_list.next, struct sof_audio_buffer, Xsink_list);
665+
return NULL;
666+
}
654667
static inline struct comp_buffer *comp_dev_get_next_data_producer(struct comp_dev *component,
655668
struct comp_buffer *producer)
656669
{
657-
return producer->sink_list.next == &component->bsource_list ? NULL :
658-
list_item(producer->sink_list.next, struct comp_buffer, sink_list);
670+
struct sof_audio_buffer *audio_buffer = Xcomp_dev_get_next_data_producer(component, &producer->audio_buffer);
671+
return comp_buffer_from_audio_buffer(audio_buffer);
659672
}
660673

661674
static inline struct comp_buffer *comp_dev_get_next_data_producer_safe(struct comp_dev *component,
@@ -668,22 +681,36 @@ static inline struct comp_buffer *comp_dev_get_next_data_producer_safe(struct co
668681
* Get a pointer to the first comp_buffer object receiving data from the component
669682
* The function will return NULL if there's no data consumers
670683
*/
671-
static inline struct comp_buffer *comp_dev_get_first_data_consumer(struct comp_dev *component)
684+
static inline struct sof_audio_buffer *Xcomp_dev_get_first_data_consumer(struct comp_dev *component)
672685
{
673686
return list_is_empty(&component->bsink_list) ? NULL :
674-
list_first_item(&component->bsink_list, struct comp_buffer, source_list);
687+
list_first_item(&component->bsink_list, struct sof_audio_buffer, Xsource_list);
675688
}
676689

690+
static inline struct comp_buffer *comp_dev_get_first_data_consumer(struct comp_dev *component)
691+
{
692+
struct sof_audio_buffer *audio_buffer = Xcomp_dev_get_first_data_consumer(component);
693+
return comp_buffer_from_audio_buffer(audio_buffer);
694+
}
695+
696+
677697
/**
678698
* Get a pointer to the next comp_buffer object receiving data from the component
679699
* The function will return NULL if there're no more data consumers
680700
* _safe version also checks if consumer is != NULL
681701
*/
702+
static inline struct sof_audio_buffer *Xcomp_dev_get_next_data_consumer(struct comp_dev *component,
703+
struct sof_audio_buffer *consumer)
704+
{
705+
return consumer->Xsource_list.next == &component->bsink_list ? NULL :
706+
list_item(consumer->Xsource_list.next, struct sof_audio_buffer, Xsource_list);
707+
}
708+
682709
static inline struct comp_buffer *comp_dev_get_next_data_consumer(struct comp_dev *component,
683710
struct comp_buffer *consumer)
684711
{
685-
return consumer->source_list.next == &component->bsink_list ? NULL :
686-
list_item(consumer->source_list.next, struct comp_buffer, source_list);
712+
struct sof_audio_buffer *audio_buffer = Xcomp_dev_get_next_data_consumer(component, &consumer->audio_buffer);
713+
return comp_buffer_from_audio_buffer(audio_buffer);
687714
}
688715

689716
static inline struct comp_buffer *comp_dev_get_next_data_consumer_safe(struct comp_dev *component,

src/ipc/ipc-helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
305305

306306
irq_local_disable(flags);
307307
comp_dev_for_each_producer_safe(icd->cd, buffer, safe) {
308-
comp_buffer_set_sink_component(buffer, NULL);
308+
audio_buffer_set_sink_component(&buffer->audio_buffer, NULL);
309309
/* This breaks the list, but we anyway delete all buffers */
310-
comp_buffer_reset_sink_list(buffer);
310+
audio_buffer_reset_sink_list(&buffer->audio_buffer);
311311
}
312312

313313
comp_dev_for_each_consumer_safe(icd->cd, buffer, safe) {
314314
comp_buffer_set_source_component(buffer, NULL);
315315
/* This breaks the list, but we anyway delete all buffers */
316-
comp_buffer_reset_source_list(buffer);
316+
audio_buffer_reset_source_list(&buffer->audio_buffer);
317317
}
318318

319319
irq_local_enable(flags);

0 commit comments

Comments
 (0)