Component API

Component Device “Constructor”

The following call creates a new component device:

struct comp_dev *(*new)(struct sof_ipc_comp *comp);

This framework calls comp_ops::new() to create a new instance of the component, called the component device. All required data objects should be allocated from the run-time heap (RZONE_RUNTIME).

Note that any component-specific private data is allocated separately and the pointer to that one is connected to the common comp_dev structure’s private field by calling the comp_set_drvdata() function. In order to retrieve the private data structure in other component routines, use comp_get_drvdata().

Parameters should be initialized to their default values.

Component Device “Destructor”

This framework calls free(struct comp_dev *dev) to free a component instance. All data structures previously allocated on the run-time heap are freed:

void (*free)(struct comp_dev *dev);

actor host
participant "ipc/ipc" as ipc
participant "audio/<comp_driver>" as drv
host -> ipc : ipc_comp_free(comp_id)
	ipc -> ipc : ipc_get_comp(id)
	ipc -> drv : dev.drv.ops.free()
host <-- ipc

Setting Audio Stream Parameters

The following call configures a dai object attached to the component device:

int (*dai_config)(struct comp_dev *dev,
   struct sof_ipc_dai_config *dai_config);

actor host
participant "ipc/handler" as hdl
participant "<platform>/dai" as dai
participant "ipc/ipc" as ipc
participant "audio/<comp_driver>" as drv

host -> hdl : ipc_dai_config(config)
	== Configure DAI Instance ==
	hdl -> dai : dai_get()
	hdl <-- dai_instance
	hdl -> dai : dai_set_config(dai_instance, config)
	hdl <-- dai
	== Configure DAI Components who use that DAI ==
	hdl -> ipc : ipc_comp_dai_config()
		loop for each SOF_COMP_DAI, SOF_COMP_SG_DAI
			ipc -> drv : dev.drv.ops.dai_config(config)
		end loop

Note

It must be implemented by dai components only.

Setting Parameters & Preparing for Use

The following call sets parameters and prepares the component device:

int (*params)(struct comp_dev *dev);
int (*prepare)(struct comp_dev *dev);

It is called for all pipeline components to configure their audio parameters.

Commands

A handler for the commands coming from the IPC channel:

/* COMP_CMD_SET_VALUE
 * COMP_CMD_GET_VALUE
 * COMP_CMD_SET_DATA
 * COMP_CMD_GET_DATA
 */
int (*cmd)(struct comp_dev *dev, int cmd, void *data);

Triggering State Transition

Trigger:

int (*trigger)(struct comp_dev *dev, int cmd);

Reset

Reset:

int (*reset)(struct comp_dev *dev);

pipeline_reset() resets the components by calling ...upstream()/...downstream() with COMP_OPS_RESET (see Pipelines).

Processing Audio Data

Processing audio data:

int (*copy)(struct comp_dev *dev);

participant "pipeline" as ppl
participant "component" as comp

-> ppl : pipeline_task()
   activate ppl
   ppl -> ppl : pipeline_copy_from_upstream()
      activate ppl
      ppl -> comp : comp_copy()
   ppl <-- ppl
   deactivate ppl
   ppl -> ppl : pipeline_copy_to_downstream()
      activate ppl
      ppl -> comp : comp_copy()
   ppl <-- ppl
   deactivate ppl
<-- ppl
deactivate ppl