Skip to content

Commit 22ecaa4

Browse files
singalsulgirdwood
authored andcommitted
Component: Add comp_get_copy_limits() function for copy() preparations
This patch adds into component.c/h an utility function and a data structure to simplify audio component's copy() method code. The do-nothing function pipeline_xrun() is added to avoid cmocka test fail due to adding function comp_get_copy_limits(). Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent ed97bb9 commit 22ecaa4

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/audio/component.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,36 @@ void sys_comp_init(void)
248248
((void(*)(void))(*comp_init))();
249249
}
250250
}
251+
252+
int comp_get_copy_limits(struct comp_dev *dev, struct comp_copy_limits *cl)
253+
{
254+
/* Get source and sink buffer addresses */
255+
cl->source = list_first_item(&dev->bsource_list, struct comp_buffer,
256+
sink_list);
257+
cl->sink = list_first_item(&dev->bsink_list, struct comp_buffer,
258+
source_list);
259+
260+
/* check for underrun */
261+
if (cl->source->avail == 0) {
262+
trace_comp_error("comp_get_copy_limits() error: "
263+
"source component buffer"
264+
" has not enough data available");
265+
comp_underrun(dev, cl->source, 0, 0);
266+
return -EIO;
267+
}
268+
269+
/* check for overrun */
270+
if (cl->sink->free == 0) {
271+
trace_comp_error("comp_get_copy_limits() error: "
272+
"sink component buffer"
273+
" has not enough free bytes for copy");
274+
comp_overrun(dev, cl->sink, 0, 0);
275+
return -EIO;
276+
}
277+
278+
cl->frames = comp_avail_frames(cl->source, cl->sink);
279+
cl->source_bytes = cl->frames * comp_frame_bytes(cl->source->source);
280+
cl->sink_bytes = cl->frames * comp_frame_bytes(cl->sink->sink);
281+
282+
return 0;
283+
}

src/include/sof/audio/component.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ struct comp_dev {
272272
* @{
273273
*/
274274

275+
/** \brief Struct for use with comp_get_copy_limits() function. */
276+
struct comp_copy_limits {
277+
struct comp_buffer *sink;
278+
struct comp_buffer *source;
279+
int frames;
280+
int source_bytes;
281+
int sink_bytes;
282+
};
283+
275284
/** \brief Computes size of the component device including ipc config. */
276285
#define COMP_SIZE(x) \
277286
(sizeof(struct comp_dev) - sizeof(struct sof_ipc_comp) + sizeof(x))
@@ -697,6 +706,13 @@ static inline void comp_overrun(struct comp_dev *dev, struct comp_buffer *sink,
697706
pipeline_xrun(dev->pipeline, dev, (int32_t)copy_bytes - sink->free);
698707
}
699708

709+
/**
710+
* Called by component in copy.
711+
* @param dev Component device.
712+
* @param cl Struct of parameters for use in copy function.
713+
*/
714+
int comp_get_copy_limits(struct comp_dev *dev, struct comp_copy_limits *cl);
715+
700716
/** @}*/
701717

702718
/** @}*/

test/cmocka/src/audio/component/mock.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ void *rzalloc(int zone, uint32_t caps, size_t bytes)
4848
return calloc(bytes, 1);
4949
}
5050

51+
void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes)
52+
{
53+
}
54+
5155
#endif

0 commit comments

Comments
 (0)