Skip to content

Commit

Permalink
tplg_parser: Add support for parsing PCM headers
Browse files Browse the repository at this point in the history
Parse the PCM headers and save the PCM info along with the host
component associated with the PCM.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
  • Loading branch information
ranj063 authored and kv2019i committed Aug 16, 2023
1 parent ccd6949 commit eac5a0a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/tplg_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_sources(sof_tplg_parser PUBLIC
tokens.c
process.c
control.c
pcm.c
pga.c
mixer.c
pipeline.c
Expand Down
17 changes: 17 additions & 0 deletions tools/tplg_parser/include/tplg_parser/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct sof_ipc4_available_audio_format {

struct tplg_comp_info {
char *name;
char *stream_name;
int id;
int type;
int pipeline_id;
Expand All @@ -93,6 +94,14 @@ struct tplg_route_info {
struct list_item item; /* item in a list */
};

struct tplg_pcm_info {
char *name;
int id;
struct tplg_comp_info *playback_host;
struct tplg_comp_info *capture_host;
struct list_item item; /* item in a list */
};

/*
* Per topology data.
*
Expand Down Expand Up @@ -164,6 +173,11 @@ struct tplg_context {
w = (struct snd_soc_tplg_dapm_graph_elem *)(ctx->tplg_base + ctx->tplg_offset); \
ctx->tplg_offset += sizeof(*w); w; })

#define tplg_get_pcm(ctx) \
({struct snd_soc_tplg_pcm *pcm; \
pcm = (struct snd_soc_tplg_pcm *)(ctx->tplg_base + ctx->tplg_offset); \
ctx->tplg_offset += sizeof(*pcm) + pcm->priv.size; pcm; })

static inline int tplg_valid_widget(struct snd_soc_tplg_dapm_widget *widget)
{
if (widget->size == sizeof(struct snd_soc_tplg_dapm_widget))
Expand Down Expand Up @@ -261,4 +275,7 @@ int sof_parse_token_sets(void *object, const struct sof_topology_token *tokens,
int tplg_parse_widget_audio_formats(struct tplg_context *ctx);
int tplg_parse_graph(struct tplg_context *ctx, struct list_item *widget_list,
struct list_item *route_list);
int tplg_parse_pcm(struct tplg_context *ctx, struct list_item *widget_list,
struct list_item *pcm_list);

#endif
66 changes: 66 additions & 0 deletions tools/tplg_parser/pcm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
// Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>

/* FE DAI or PCM parser */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>
#include <ipc/topology.h>
#include <sof/list.h>
#include <sof/ipc/topology.h>
#include <kernel/header.h>
#include <tplg_parser/topology.h>

/* parse and save the PCM information */
int tplg_parse_pcm(struct tplg_context *ctx, struct list_item *widget_list,
struct list_item *pcm_list)
{
struct tplg_pcm_info *pcm_info;
struct snd_soc_tplg_pcm *pcm;
struct list_item *item;

pcm_info = calloc(sizeof(struct tplg_pcm_info), 1);
if (!pcm_info)
return -ENOMEM;

pcm = tplg_get_pcm(ctx);

pcm_info->name = strdup(pcm->pcm_name);
if (!pcm_info->name) {
free(pcm_info);
return -ENOMEM;
}

pcm_info->id = pcm->pcm_id;

/* look up from the widget list and populate the PCM info */
list_for_item(item, widget_list) {
struct tplg_comp_info *comp_info = container_of(item, struct tplg_comp_info, item);

if (!strcmp(pcm->caps[0].name, comp_info->stream_name) &&
(comp_info->type == SND_SOC_TPLG_DAPM_AIF_IN ||
comp_info->type == SND_SOC_TPLG_DAPM_AIF_OUT)) {
pcm_info->playback_host = comp_info;
fprintf(stdout, "PCM: '%s' ID: %d Host name: %s\n", pcm_info->name,
pcm_info->id, comp_info->name);
}
if (!strcmp(pcm->caps[1].name, comp_info->stream_name) &&
(comp_info->type == SND_SOC_TPLG_DAPM_AIF_IN ||
comp_info->type == SND_SOC_TPLG_DAPM_AIF_OUT)) {
pcm_info->capture_host = comp_info;
fprintf(stdout, "PCM: '%s' ID: %d Host name: %s\n", pcm_info->name,
pcm_info->id, comp_info->name);
}
}

list_item_append(&pcm_info->item, pcm_list);

return 0;
}

0 comments on commit eac5a0a

Please sign in to comment.