1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2019 Intel Corporation. All rights reserved.
4 //
5 // Author: Daniel Bogdzia <danielx.bogdzia@linux.intel.com>
6 //         Janusz Jankowski <janusz.jankowski@linux.intel.com>
7 
8 #include <rtos/sof.h>
9 #include <sof/audio/component.h>
10 #include <rtos/alloc.h>
11 
12 #include <stdlib.h>
13 
create_test_sink(struct comp_dev * dev,uint32_t pipeline_id,uint32_t frame_fmt,uint16_t channels,uint16_t buffer_size)14 static inline struct comp_buffer *create_test_sink(struct comp_dev *dev,
15 						   uint32_t pipeline_id,
16 						   uint32_t frame_fmt,
17 						   uint16_t channels,
18 						   uint16_t buffer_size)
19 {
20 	struct sof_ipc_buffer desc = {
21 		.comp = {
22 			.pipeline_id = pipeline_id,
23 		},
24 		.size = buffer_size,
25 	};
26 	struct comp_buffer *buffer = buffer_new(&desc);
27 
28 	memset(buffer->stream.addr, 0, buffer_size);
29 
30 	/* set bsink list */
31 	if (dev)
32 		list_item_append(&buffer->source_list, &dev->bsink_list);
33 
34 	/* alloc sink and set default parameters */
35 	buffer->sink = calloc(1, sizeof(struct comp_dev));
36 	buffer->sink->state = COMP_STATE_PREPARE;
37 	buffer->stream.frame_fmt = frame_fmt;
38 	buffer->stream.channels = channels;
39 
40 	return buffer;
41 }
42 
free_test_sink(struct comp_buffer * buffer)43 static inline void free_test_sink(struct comp_buffer *buffer)
44 {
45 	free(buffer->sink);
46 	buffer_free(buffer);
47 }
48 
create_test_source(struct comp_dev * dev,uint32_t pipeline_id,uint32_t frame_fmt,uint16_t channels,uint16_t buffer_size)49 static inline struct comp_buffer *create_test_source(struct comp_dev *dev,
50 						     uint32_t pipeline_id,
51 						     uint32_t frame_fmt,
52 						     uint16_t channels,
53 						     uint16_t buffer_size)
54 {
55 	struct sof_ipc_buffer desc = {
56 		.comp = {
57 			.pipeline_id = pipeline_id,
58 		},
59 		.size = buffer_size,
60 	};
61 	struct comp_buffer *buffer = buffer_new(&desc);
62 
63 	memset(buffer->stream.addr, 0, buffer_size);
64 
65 	/*set bsource list */
66 	if (dev)
67 		list_item_append(&buffer->sink_list, &dev->bsource_list);
68 
69 	/* alloc source and set default parameters */
70 	buffer->source = calloc(1, sizeof(struct comp_dev));
71 	buffer->source->state = COMP_STATE_PREPARE;
72 	buffer->stream.frame_fmt = frame_fmt;
73 	buffer->stream.channels = channels;
74 
75 	return buffer;
76 }
77 
free_test_source(struct comp_buffer * buffer)78 static inline void free_test_source(struct comp_buffer *buffer)
79 {
80 	free(buffer->source);
81 	buffer_free(buffer);
82 }
83