mirror of https://github.com/thesofproject/sof.git
codec_adapter: Modify the process API signature
Modify the signature of the process API in the module interface to pass the input/output buffers along with the counts of the number of input and output buffers. Please note that the pass input/output buffers are not used at this point. The codec implementations will be modified in the follow-up patches to use them. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This commit is contained in:
parent
8bcfd6fa20
commit
07d5432d5c
|
@ -498,10 +498,13 @@ free:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int cadence_codec_process(struct comp_dev *dev)
|
||||
static int
|
||||
cadence_codec_process(struct processing_module *mod,
|
||||
struct input_stream_buffer *input_buffers, int num_input_buffers,
|
||||
struct output_stream_buffer *output_buffers, int num_output_buffers)
|
||||
{
|
||||
struct processing_module *mod = comp_get_drvdata(dev);
|
||||
struct comp_buffer *local_buff = mod->local_buff;
|
||||
struct comp_dev *dev = mod->dev;
|
||||
struct module_data *codec = comp_get_module_data(dev);
|
||||
struct cadence_codec_data *cd = codec->private;
|
||||
int ret;
|
||||
|
|
|
@ -217,9 +217,13 @@ static int dts_codec_init_process(struct comp_dev *dev)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int dts_codec_process(struct comp_dev *dev)
|
||||
static int
|
||||
dts_codec_process(struct processing_module *mod,
|
||||
struct input_stream_buffer *input_buffers, int num_input_buffers,
|
||||
struct output_stream_buffer *output_buffers, int num_output_buffers)
|
||||
{
|
||||
int ret;
|
||||
struct comp_dev *dev = mod->dev;
|
||||
struct module_data *codec = comp_get_module_data(dev);
|
||||
DtsSofInterfaceResult dts_result;
|
||||
unsigned int bytes_processed = 0;
|
||||
|
|
|
@ -223,11 +223,13 @@ int module_prepare(struct processing_module *mod)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int module_process(struct comp_dev *dev)
|
||||
int module_process(struct processing_module *mod, struct input_stream_buffer *input_buffers,
|
||||
int num_input_buffers, struct output_stream_buffer *output_buffers,
|
||||
int num_output_buffers)
|
||||
{
|
||||
struct comp_dev *dev = mod->dev;
|
||||
int ret;
|
||||
|
||||
struct processing_module *mod = comp_get_drvdata(dev);
|
||||
struct module_data *md = &mod->priv;
|
||||
|
||||
comp_dbg(dev, "module_process() start");
|
||||
|
@ -241,7 +243,8 @@ int module_process(struct comp_dev *dev)
|
|||
/* set state to processing */
|
||||
md->state = MODULE_PROCESSING;
|
||||
|
||||
ret = md->ops->process(dev);
|
||||
ret = md->ops->process(mod, input_buffers, num_input_buffers, output_buffers,
|
||||
num_output_buffers);
|
||||
if (ret && ret != -ENOSPC) {
|
||||
comp_err(dev, "module_process() error %d: for comp %d",
|
||||
ret, dev_comp_id(dev));
|
||||
|
|
|
@ -57,10 +57,13 @@ static int passthrough_codec_init_process(struct comp_dev *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int passthrough_codec_process(struct comp_dev *dev)
|
||||
static int
|
||||
passthrough_codec_process(struct processing_module *mod,
|
||||
struct input_stream_buffer *input_buffers, int num_input_buffers,
|
||||
struct output_stream_buffer *output_buffers, int num_output_buffers)
|
||||
{
|
||||
struct comp_dev *dev = mod->dev;
|
||||
struct module_data *codec = comp_get_module_data(dev);
|
||||
struct processing_module *mod = comp_get_drvdata(dev);
|
||||
|
||||
if (!codec->mpd.init_done)
|
||||
return passthrough_codec_init_process(dev);
|
||||
|
|
|
@ -705,9 +705,13 @@ static int waves_codec_init_process(struct comp_dev *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int waves_codec_process(struct comp_dev *dev)
|
||||
static int
|
||||
waves_codec_process(struct processing_module *mod,
|
||||
struct input_stream_buffer *input_buffers, int num_input_buffers,
|
||||
struct output_stream_buffer *output_buffers, int num_output_buffers)
|
||||
{
|
||||
int ret;
|
||||
struct comp_dev *dev = mod->dev;
|
||||
struct module_data *codec = comp_get_module_data(dev);
|
||||
struct waves_codec_data *waves_codec = codec->private;
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ int codec_adapter_prepare(struct comp_dev *dev)
|
|||
int ret;
|
||||
struct processing_module *mod = comp_get_drvdata(dev);
|
||||
struct module_data *md = &mod->priv;
|
||||
struct list_item *blist;
|
||||
uint32_t buff_periods;
|
||||
uint32_t buff_size; /* size of local buffer */
|
||||
|
||||
|
@ -178,6 +179,19 @@ int codec_adapter_prepare(struct comp_dev *dev)
|
|||
*/
|
||||
buff_size = MAX(mod->period_bytes, md->mpd.out_buff_size) * buff_periods;
|
||||
|
||||
/* compute number of input buffers */
|
||||
list_for_item(blist, &dev->bsource_list)
|
||||
mod->num_input_buffers++;
|
||||
|
||||
/* compute number of output buffers */
|
||||
list_for_item(blist, &dev->bsink_list)
|
||||
mod->num_output_buffers++;
|
||||
|
||||
if (!mod->num_input_buffers || !mod->num_output_buffers) {
|
||||
comp_err(dev, "codec_adapter_prepare(): invalid number of source/sink buffers");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Allocate local buffer */
|
||||
if (mod->local_buff) {
|
||||
ret = buffer_set_size(mod->local_buff, buff_size);
|
||||
|
@ -314,6 +328,10 @@ int codec_adapter_copy(struct comp_dev *dev)
|
|||
uint32_t codec_buff_size = md->mpd.in_buff_size;
|
||||
struct comp_buffer *local_buff = mod->local_buff;
|
||||
struct comp_copy_limits cl;
|
||||
struct input_stream_buffer *input_buffers;
|
||||
struct output_stream_buffer *output_buffers;
|
||||
struct list_item *blist;
|
||||
int i = 0;
|
||||
|
||||
if (!source || !sink) {
|
||||
comp_err(dev, "codec_adapter_copy(): source/sink buffer not found");
|
||||
|
@ -326,6 +344,59 @@ int codec_adapter_copy(struct comp_dev *dev)
|
|||
comp_dbg(dev, "codec_adapter_copy() start: codec_buff_size: %d, local_buff free: %d source avail %d",
|
||||
codec_buff_size, local_buff->stream.free, source->stream.avail);
|
||||
|
||||
/* allocate memory for input buffers */
|
||||
input_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
|
||||
sizeof(*input_buffers) * mod->num_input_buffers);
|
||||
if (!input_buffers) {
|
||||
comp_err(dev, "codec_adapter_copy(): failed to allocate input buffers");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* allocate memory for input buffer data and copy source samples */
|
||||
list_for_item(blist, &dev->bsource_list) {
|
||||
int frames, source_frame_bytes;
|
||||
|
||||
source = container_of(blist, struct comp_buffer, sink_list);
|
||||
|
||||
source = buffer_acquire(source);
|
||||
frames = audio_stream_avail_frames(&source->stream, &sink->stream);
|
||||
source_frame_bytes = audio_stream_frame_bytes(&source->stream);
|
||||
source = buffer_release(source);
|
||||
|
||||
bytes_to_process = frames * source_frame_bytes;
|
||||
|
||||
buffer_stream_invalidate(source, bytes_to_process);
|
||||
input_buffers[i].data = rballoc(0, SOF_MEM_CAPS_RAM, bytes_to_process);
|
||||
if (!input_buffers[i].data) {
|
||||
comp_err(mod->dev, "codec_adapter_copy(): Failed to alloc input buffer data");
|
||||
ret = -ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
input_buffers[i].size = bytes_to_process;
|
||||
ca_copy_from_source_to_module(&source->stream, input_buffers[i].data,
|
||||
input_buffers[i].size, bytes_to_process);
|
||||
i++;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate memory for output buffers. The memory for output buffer data should be
|
||||
* allocated by the module depending on the number of output samples produced
|
||||
*/
|
||||
output_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
|
||||
sizeof(*output_buffers) * mod->num_output_buffers);
|
||||
if (!output_buffers) {
|
||||
comp_err(dev, "codec_adapter_copy(): failed to allocate output buffers");
|
||||
goto free;
|
||||
}
|
||||
|
||||
/*
|
||||
* This should be removed once all codec implementations start using the passed
|
||||
* input/output buffers
|
||||
*/
|
||||
source = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list);
|
||||
bytes_to_process = cl.frames * cl.source_frame_bytes;
|
||||
|
||||
/* Proceed only if we have enough data to fill the lib buffer
|
||||
* completely. If you don't fill whole buffer
|
||||
* the lib won't process it.
|
||||
|
@ -340,9 +411,10 @@ int codec_adapter_copy(struct comp_dev *dev)
|
|||
ca_copy_from_source_to_module(&source->stream, md->mpd.in_buff,
|
||||
md->mpd.in_buff_size, codec_buff_size);
|
||||
md->mpd.avail = codec_buff_size;
|
||||
ret = module_process(dev);
|
||||
ret = module_process(mod, input_buffers, mod->num_input_buffers,
|
||||
output_buffers, mod->num_output_buffers);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_free;
|
||||
|
||||
bytes_to_process -= md->mpd.consumed;
|
||||
processed += md->mpd.consumed;
|
||||
|
@ -355,7 +427,8 @@ int codec_adapter_copy(struct comp_dev *dev)
|
|||
ca_copy_from_source_to_module(&source->stream, md->mpd.in_buff,
|
||||
md->mpd.in_buff_size, codec_buff_size);
|
||||
md->mpd.avail = codec_buff_size;
|
||||
ret = module_process(dev);
|
||||
ret = module_process(mod, input_buffers, mod->num_input_buffers,
|
||||
output_buffers, mod->num_output_buffers);
|
||||
if (ret) {
|
||||
if (ret == -ENOSPC) {
|
||||
ret = 0;
|
||||
|
@ -416,6 +489,18 @@ copy_period:
|
|||
end:
|
||||
comp_dbg(dev, "codec_adapter_copy(): processed %d in this call %d bytes left for next period",
|
||||
processed, bytes_to_process);
|
||||
|
||||
out_free:
|
||||
for (i = 0; i < mod->num_output_buffers; i++)
|
||||
rfree(output_buffers[i].data);
|
||||
|
||||
rfree(output_buffers);
|
||||
|
||||
free:
|
||||
for (i = 0; i < mod->num_input_buffers; i++)
|
||||
rfree(input_buffers[i].data);
|
||||
rfree(input_buffers);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,9 @@ struct module_interface {
|
|||
* samples provided by the codec_adapter and produce/output the processed
|
||||
* ones back to codec_adapter.
|
||||
*/
|
||||
int (*process)(struct comp_dev *dev);
|
||||
int (*process)(struct processing_module *mod, struct input_stream_buffer *input_buffers,
|
||||
int num_input_buffers, struct output_stream_buffer *output_buffers,
|
||||
int num_output_buffers);
|
||||
|
||||
/**
|
||||
* Set module configuration for the given configuration ID
|
||||
|
@ -280,6 +282,8 @@ struct processing_module {
|
|||
struct comp_dev *dev;
|
||||
uint32_t period_bytes; /** pipeline period bytes */
|
||||
uint32_t deep_buff_bytes; /**< copy start threshold */
|
||||
uint32_t num_input_buffers; /**< number of input buffers */
|
||||
uint32_t num_output_buffers; /**< number of output buffers */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -291,7 +295,9 @@ void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint3
|
|||
int module_free_memory(struct processing_module *mod, void *ptr);
|
||||
void module_free_all_memory(struct processing_module *mod);
|
||||
int module_prepare(struct processing_module *mod);
|
||||
int module_process(struct comp_dev *dev);
|
||||
int module_process(struct processing_module *mod, struct input_stream_buffer *input_buffers,
|
||||
int num_input_buffers, struct output_stream_buffer *output_buffers,
|
||||
int num_output_buffers);
|
||||
int module_reset(struct processing_module *mod);
|
||||
int module_free(struct processing_module *mod);
|
||||
int module_set_configuration(struct processing_module *mod,
|
||||
|
|
Loading…
Reference in New Issue