1010#include <sof/audio/data_blob.h>
1111#include <sof/audio/format.h>
1212#include <sof/audio/pipeline.h>
13+ #include <sof/audio/sink_api.h>
14+ #include <sof/audio/source_api.h>
1315#include <sof/audio/ipc-config.h>
1416#include <sof/common.h>
1517#include <rtos/panic.h>
@@ -140,25 +142,63 @@ static int dcblock_set_config(struct processing_module *mod, uint32_t config_id,
140142
141143/**
142144 * \brief Copies and processes stream data.
143- * \param[in,out] dev DC Blocking Filter module.
145+ * \param[in,out] mod DC Blocking Filter module.
144146 * \return Error code.
145147 */
146148static int dcblock_process (struct processing_module * mod ,
147- struct input_stream_buffer * input_buffers ,
148- int num_input_buffers ,
149- struct output_stream_buffer * output_buffers ,
150- int num_output_buffers )
149+ struct sof_source * * sources , int num_of_sources ,
150+ struct sof_sink * * sinks , int num_of_sinks )
151151{
152152 struct comp_data * cd = module_get_private_data (mod );
153- struct audio_stream * source = input_buffers [0 ].data ;
154- struct audio_stream * sink = output_buffers [0 ].data ;
155- uint32_t frames = input_buffers [0 ].size ;
156-
157- comp_dbg (mod -> dev , "entry" );
158-
159- cd -> dcblock_func (cd , source , sink , frames );
153+ struct comp_dev * dev = mod -> dev ;
154+ struct sof_source * source = sources [0 ];
155+ struct sof_sink * sink = sinks [0 ];
156+ struct cir_buf_source source_buf ;
157+ struct cir_buf_sink sink_buf ;
158+ size_t source_frame_bytes = source_get_frame_bytes (source );
159+ size_t sink_frame_bytes = sink_get_frame_bytes (sink );
160+ size_t source_bytes , sink_bytes , bytes ;
161+ uint32_t frames = source_get_data_frames_available (source );
162+ uint32_t sink_frames = sink_get_free_frames (sink );
163+ int ret ;
164+
165+ comp_dbg (dev , "entry" );
166+
167+ frames = MIN (frames , sink_frames );
168+ frames = MIN (frames , dev -> frames );
169+ if (!frames )
170+ return 0 ;
171+
172+ source_bytes = frames * source_frame_bytes ;
173+ sink_bytes = frames * sink_frame_bytes ;
174+
175+ /* acquire the source and sink circular buffer views once */
176+ ret = source_get_data (source , source_bytes , & source_buf .ptr ,
177+ & source_buf .buf_start , & bytes );
178+ if (ret )
179+ return ret ;
180+ source_buf .buf_end = (const char * )source_buf .buf_start + bytes ;
181+
182+ ret = sink_get_buffer (sink , sink_bytes , & sink_buf .ptr ,
183+ & sink_buf .buf_start , & bytes );
184+ if (ret ) {
185+ source_release_data (source , 0 );
186+ return ret ;
187+ }
188+ sink_buf .buf_end = (char * )sink_buf .buf_start + bytes ;
189+
190+ ret = cd -> dcblock_func (cd , & source_buf , & sink_buf , frames );
191+ if (ret ) {
192+ /* Undo the acquire without consuming source data or
193+ * publishing partially-written output.
194+ */
195+ source_release_data (source , 0 );
196+ sink_commit_buffer (sink , 0 );
197+ return ret ;
198+ }
160199
161- module_update_buffer_position (& input_buffers [0 ], & output_buffers [0 ], frames );
200+ source_release_data (source , source_bytes );
201+ sink_commit_buffer (sink , sink_bytes );
162202 return 0 ;
163203}
164204
@@ -172,27 +212,35 @@ static int dcblock_prepare(struct processing_module *mod,
172212 struct sof_sink * * sinks , int num_of_sinks )
173213{
174214 struct comp_data * cd = module_get_private_data (mod );
175- struct comp_buffer * sourceb , * sinkb ;
176215 struct comp_dev * dev = mod -> dev ;
177216 size_t data_size ;
178217
179218 comp_info (dev , "entry" );
180219
181220 /* DC Filter component will only ever have one source and sink buffer */
182- sourceb = comp_dev_get_first_data_producer (dev );
183- sinkb = comp_dev_get_first_data_consumer (dev );
184- if (!sourceb || !sinkb ) {
185- comp_err (dev , "no source or sink buffer" );
186- return - ENOTCONN ;
221+ if (num_of_sources != 1 || num_of_sinks != 1 ) {
222+ comp_err (dev , "Invalid number of sources/sinks" );
223+ return - EINVAL ;
187224 }
188225
189226 dcblock_params (mod );
190227
191228 /* get source data format */
192- cd -> source_format = audio_stream_get_frm_fmt (& sourceb -> stream );
229+ cd -> source_format = source_get_frm_fmt (sources [0 ]);
230+
231+ /* get sink data format */
232+ cd -> sink_format = sink_get_frm_fmt (sinks [0 ]);
233+
234+ /* The processing uses a single channel count as the frame stride for
235+ * both source and sink, so they must match to avoid corrupt output.
236+ */
237+ if (source_get_channels (sources [0 ]) != sink_get_channels (sinks [0 ])) {
238+ comp_err (dev , "mismatch source/sink stream channels" );
239+ return - EINVAL ;
240+ }
193241
194- /* get sink data format and period bytes */
195- cd -> sink_format = audio_stream_get_frm_fmt ( & sinkb -> stream );
242+ /* get channel count for processing */
243+ cd -> channels = source_get_channels ( sources [ 0 ] );
196244
197245 dcblock_init_state (cd );
198246 cd -> dcblock_func = dcblock_find_func (cd -> source_format );
@@ -238,7 +286,7 @@ static int dcblock_reset(struct processing_module *mod)
238286static const struct module_interface dcblock_interface = {
239287 .init = dcblock_init ,
240288 .prepare = dcblock_prepare ,
241- .process_audio_stream = dcblock_process ,
289+ .process = dcblock_process ,
242290 .set_configuration = dcblock_set_config ,
243291 .get_configuration = dcblock_get_config ,
244292 .reset = dcblock_reset ,
0 commit comments