From f9ec396b8ffe7ce4f72e11dc1f0e92222e6e78f5 Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Thu, 24 Jan 2019 11:09:12 +0200 Subject: [PATCH] pipeline: calculate frame count from stream params Previously frame count was coming as topology pipeline parameter. As the frame count might change because of some components have fixed samplerate, we might as well calculate it from the stream parameters. Component base struct will have new member output_rate, which the component should set if it has fixed output rate (like SRC). Not setting it or 0 means it can be whatever the pipeline decides. Components with 0 output_rate will have frames = (stream) sample_rate / (pipeline) deadline. Components downstream to fixed output rate will obey the fixed rate / period. Signed-off-by: Jaska Uimonen --- src/audio/pipeline.c | 12 +++++++++++- src/audio/src/src.c | 2 ++ src/include/sof/audio/component.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c index 62bd02c46..cb5386d98 100644 --- a/src/audio/pipeline.c +++ b/src/audio/pipeline.c @@ -144,7 +144,6 @@ static int pipeline_comp_complete(struct comp_dev *current, void *data, /* complete component init */ current->pipeline = ppl_data->p; - current->frames = ppl_data->p->ipc_pipe.frames_per_sched; pipeline_for_each_comp(current, &pipeline_comp_complete, data, NULL, dir); @@ -286,6 +285,17 @@ static int pipeline_comp_params(struct comp_dev *current, void *data, int dir) /* send current params to the component */ current->params = ppl_data->params->params; + /* set frames from samplerate/period, but round integer up */ + if (current->output_rate != 0) { + current->frames = (current->output_rate + + current->pipeline->ipc_pipe.period - 1) / + current->pipeline->ipc_pipe.period; + } else { + current->frames = (current->params.rate + + current->pipeline->ipc_pipe.period - 1) / + current->pipeline->ipc_pipe.period; + } + err = comp_params(current); if (err < 0 || err == PPL_STATUS_PATH_STOP) return err; diff --git a/src/audio/src/src.c b/src/audio/src/src.c index 5b090f673..25bd535fd 100644 --- a/src/audio/src/src.c +++ b/src/audio/src/src.c @@ -536,6 +536,8 @@ static struct comp_dev *src_new(struct sof_ipc_comp *comp) cd->polyphase_func = src_polyphase_stage_cir; src_polyphase_reset(&cd->src); + dev->output_rate = ipc_src->sink_rate; + dev->state = COMP_STATE_READY; return dev; } diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index b9c1b85c7..91c894714 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -235,6 +235,7 @@ struct comp_dev { uint16_t is_dma_connected; /**< component is connected to DMA */ uint64_t position; /**< component rendering position */ uint32_t frames; /**< number of frames we copy to sink */ + uint32_t output_rate; /**< 0 means all output rates are fine */ struct pipeline *pipeline; /**< pipeline we belong to */ /** common runtime configuration for downstream/upstream */