55// Author: Sebastiano Carlucci <scarlucci@google.com>
66
77#include <sof/audio/module_adapter/module/generic.h>
8+ #include <sof/audio/audio_buffer.h>
89#include <sof/audio/buffer.h>
910#include <sof/audio/component.h>
1011#include <sof/audio/data_blob.h>
1112#include <sof/audio/format.h>
1213#include <sof/audio/pipeline.h>
14+ #include <sof/audio/sink_api.h>
15+ #include <sof/audio/source_api.h>
1316#include <sof/audio/ipc-config.h>
1417#include <module/crossover/crossover_common.h>
1518#include <sof/common.h>
@@ -84,37 +87,36 @@ int crossover_get_stream_index(struct processing_module *mod,
8487 * Refer to sof/src/include/sof/crossover.h for more information on assigning
8588 * sinks to an output.
8689 *
87- * \param[out] sinks array where the sinks are assigned
90+ * \param[in] sinks array of sink handles passed to the module .process op
91+ * \param[in] num_of_sinks number of entries in the sinks array
92+ * \param[out] assigned_sinks array where the sinks are assigned, indexed by
93+ * the configured band (stream) index
8894 * \return number of sinks assigned. This number should be equal to
8995 * config->num_sinks if no errors were found.
9096 */
9197static int crossover_assign_sinks (struct processing_module * mod ,
92- struct output_stream_buffer * output_buffers ,
93- struct output_stream_buffer * * assigned_obufs ,
94- bool * enabled )
98+ struct sof_sink * * sinks , int num_of_sinks ,
99+ struct sof_sink * * assigned_sinks )
95100{
96101 struct comp_data * cd = module_get_private_data (mod );
97102 struct sof_crossover_config * config = cd -> config ;
98103 struct comp_dev * dev = mod -> dev ;
99- struct comp_buffer * sink ;
100104 int num_sinks = 0 ;
101105 int i ;
102- int j = 0 ;
106+ int j ;
103107
104- comp_dev_for_each_consumer (dev , sink ) {
108+ for (j = 0 ; j < num_of_sinks ; j ++ ) {
109+ struct sof_sink * snk = sinks [j ];
105110 unsigned int sink_id , state ;
106111
107- sink_id = crossover_get_sink_id (cd , buffer_pipeline_id (sink ), j );
108- state = comp_buffer_get_sink_state (sink );
109- if (state != dev -> state ) {
110- j ++ ;
112+ sink_id = crossover_get_sink_id (cd , sink_get_pipeline_id (snk ), j );
113+ state = comp_buffer_get_sink_state (comp_buffer_get_from_sink (snk ));
114+ if (state != dev -> state )
111115 continue ;
112- }
113116
114117 /* If no config is set, then assign the sinks in order */
115118 if (!config ) {
116- assigned_obufs [num_sinks ++ ] = & output_buffers [j ];
117- enabled [j ++ ] = true;
119+ assigned_sinks [num_sinks ++ ] = snk ;
118120 continue ;
119121 }
120122
@@ -130,15 +132,14 @@ static int crossover_assign_sinks(struct processing_module *mod,
130132 break ;
131133 }
132134
133- if (assigned_obufs [i ]) {
135+ if (assigned_sinks [i ]) {
134136 comp_err (dev ,
135137 "multiple sinks with id %d are assigned" ,
136138 sink_id );
137139 break ;
138140 }
139141
140- assigned_obufs [i ] = & output_buffers [j ];
141- enabled [j ++ ] = true;
142+ assigned_sinks [i ] = snk ;
142143 num_sinks ++ ;
143144 }
144145
@@ -460,29 +461,22 @@ static int crossover_get_config(struct processing_module *mod,
460461
461462/**
462463 * \brief Copies and processes stream data.
463- * \param[in,out] dev Crossover Filter base component device .
464+ * \param[in,out] mod Crossover Filter processing module .
464465 * \return Error code.
465466 */
466- static int crossover_process_audio_stream (struct processing_module * mod ,
467- struct input_stream_buffer * input_buffers ,
468- int num_input_buffers ,
469- struct output_stream_buffer * output_buffers ,
470- int num_output_buffers )
467+ static int crossover_process (struct processing_module * mod ,
468+ struct sof_source * * sources ,
469+ int num_of_sources ,
470+ struct sof_sink * * sinks ,
471+ int num_of_sinks )
471472{
472- struct output_stream_buffer * assigned_obufs [SOF_CROSSOVER_MAX_STREAMS ] = { NULL };
473- bool enabled_buffers [PLATFORM_MAX_STREAMS ] = { false };
473+ struct sof_sink * assigned_sinks [SOF_CROSSOVER_MAX_STREAMS ] = { NULL };
474474 struct comp_data * cd = module_get_private_data (mod );
475475 struct comp_dev * dev = mod -> dev ;
476- struct audio_stream * source = input_buffers [0 ]. data ;
476+ struct sof_source * source = sources [0 ];
477477 uint32_t num_sinks ;
478478 uint32_t num_assigned_sinks = 0 ;
479- /* The frames count to process from module adapter applies for source buffer and
480- * all sink buffers. The function module_single_source_setup() checks the frames
481- * avail/free from all source and sink combinations.
482- */
483- uint32_t frames = input_buffers [0 ].size ;
484- uint32_t frame_bytes = audio_stream_frame_bytes (input_buffers [0 ].data );
485- uint32_t processed_bytes ;
479+ uint32_t frames ;
486480 struct sof_crossover_config * prev_config ;
487481 uint32_t prev_num_sinks ;
488482 size_t cfg_size ;
@@ -513,7 +507,7 @@ static int crossover_process_audio_stream(struct processing_module *mod,
513507 return - EINVAL ;
514508 }
515509
516- ret = crossover_setup (mod , audio_stream_get_channels (source ));
510+ ret = crossover_setup (mod , source_get_channels (source ));
517511 if (ret < 0 ) {
518512 comp_err (dev , "failed Crossover setup" );
519513 return ret ;
@@ -524,12 +518,11 @@ static int crossover_process_audio_stream(struct processing_module *mod,
524518 * the output to the corresponding sinks.
525519 * It is possible for an assigned sink to be in a different
526520 * state than the component. Therefore not all sinks are guaranteed
527- * to be assigned: sink [i] can be NULL, 0 <= i <= config->num_sinks
521+ * to be assigned: assigned_sinks [i] can be NULL, 0 <= i < config->num_sinks
528522 */
529- num_assigned_sinks = crossover_assign_sinks (mod , output_buffers , assigned_obufs ,
530- enabled_buffers );
523+ num_assigned_sinks = crossover_assign_sinks (mod , sinks , num_of_sinks , assigned_sinks );
531524 if (cd -> config && num_assigned_sinks != cd -> config -> num_sinks )
532- comp_dbg (dev , "crossover_copy(), number of assigned sinks (%i) does not match number of sinks in config (%i)." ,
525+ comp_dbg (dev , "number of assigned sinks (%i) does not match number of sinks in config (%i)." ,
533526 num_assigned_sinks , cd -> config -> num_sinks );
534527
535528 /* If no config is set then assign the number of sinks to the number
@@ -540,20 +533,21 @@ static int crossover_process_audio_stream(struct processing_module *mod,
540533 else
541534 num_sinks = num_assigned_sinks ;
542535
536+ /* The number of frames to process is bound by the source data available
537+ * and the free space in every assigned sink.
538+ */
539+ frames = source_get_data_frames_available (source );
540+ for (i = 0 ; i < num_sinks ; i ++ ) {
541+ if (assigned_sinks [i ])
542+ frames = MIN (frames , sink_get_free_frames (assigned_sinks [i ]));
543+ }
544+ frames = MIN (frames , dev -> frames );
545+
543546 /* Process crossover */
544547 if (!frames )
545- return - ENODATA ;
546-
547- cd -> crossover_process (cd , input_buffers , assigned_obufs , num_sinks , frames );
548+ return 0 ;
548549
549- processed_bytes = frames * frame_bytes ;
550- mod -> input_buffers [0 ].consumed = processed_bytes ;
551- for (i = 0 ; i < num_output_buffers ; i ++ ) {
552- if (enabled_buffers [i ])
553- mod -> output_buffers [i ].size = processed_bytes ;
554- }
555-
556- return 0 ;
550+ return cd -> crossover_process (cd , source , assigned_sinks , num_sinks , frames );
557551}
558552
559553/**
@@ -668,7 +662,7 @@ static int crossover_reset(struct processing_module *mod)
668662static const struct module_interface crossover_interface = {
669663 .init = crossover_init ,
670664 .prepare = crossover_prepare ,
671- .process_audio_stream = crossover_process_audio_stream ,
665+ .process = crossover_process ,
672666 .set_configuration = crossover_set_config ,
673667 .get_configuration = crossover_get_config ,
674668 .reset = crossover_reset ,
0 commit comments