Skip to content

Commit eac5a0a

Browse files
ranj063kv2019i
authored andcommitted
tplg_parser: Add support for parsing PCM headers
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>
1 parent ccd6949 commit eac5a0a

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

tools/tplg_parser/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_sources(sof_tplg_parser PUBLIC
2121
tokens.c
2222
process.c
2323
control.c
24+
pcm.c
2425
pga.c
2526
mixer.c
2627
pipeline.c

tools/tplg_parser/include/tplg_parser/topology.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct sof_ipc4_available_audio_format {
7979

8080
struct tplg_comp_info {
8181
char *name;
82+
char *stream_name;
8283
int id;
8384
int type;
8485
int pipeline_id;
@@ -93,6 +94,14 @@ struct tplg_route_info {
9394
struct list_item item; /* item in a list */
9495
};
9596

97+
struct tplg_pcm_info {
98+
char *name;
99+
int id;
100+
struct tplg_comp_info *playback_host;
101+
struct tplg_comp_info *capture_host;
102+
struct list_item item; /* item in a list */
103+
};
104+
96105
/*
97106
* Per topology data.
98107
*
@@ -164,6 +173,11 @@ struct tplg_context {
164173
w = (struct snd_soc_tplg_dapm_graph_elem *)(ctx->tplg_base + ctx->tplg_offset); \
165174
ctx->tplg_offset += sizeof(*w); w; })
166175

176+
#define tplg_get_pcm(ctx) \
177+
({struct snd_soc_tplg_pcm *pcm; \
178+
pcm = (struct snd_soc_tplg_pcm *)(ctx->tplg_base + ctx->tplg_offset); \
179+
ctx->tplg_offset += sizeof(*pcm) + pcm->priv.size; pcm; })
180+
167181
static inline int tplg_valid_widget(struct snd_soc_tplg_dapm_widget *widget)
168182
{
169183
if (widget->size == sizeof(struct snd_soc_tplg_dapm_widget))
@@ -261,4 +275,7 @@ int sof_parse_token_sets(void *object, const struct sof_topology_token *tokens,
261275
int tplg_parse_widget_audio_formats(struct tplg_context *ctx);
262276
int tplg_parse_graph(struct tplg_context *ctx, struct list_item *widget_list,
263277
struct list_item *route_list);
278+
int tplg_parse_pcm(struct tplg_context *ctx, struct list_item *widget_list,
279+
struct list_item *pcm_list);
280+
264281
#endif

tools/tplg_parser/pcm.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2023 Intel Corporation. All rights reserved.
4+
//
5+
// Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
6+
7+
/* FE DAI or PCM parser */
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <stdint.h>
12+
#include <stddef.h>
13+
#include <errno.h>
14+
#include <string.h>
15+
#include <ipc/topology.h>
16+
#include <sof/list.h>
17+
#include <sof/ipc/topology.h>
18+
#include <kernel/header.h>
19+
#include <tplg_parser/topology.h>
20+
21+
/* parse and save the PCM information */
22+
int tplg_parse_pcm(struct tplg_context *ctx, struct list_item *widget_list,
23+
struct list_item *pcm_list)
24+
{
25+
struct tplg_pcm_info *pcm_info;
26+
struct snd_soc_tplg_pcm *pcm;
27+
struct list_item *item;
28+
29+
pcm_info = calloc(sizeof(struct tplg_pcm_info), 1);
30+
if (!pcm_info)
31+
return -ENOMEM;
32+
33+
pcm = tplg_get_pcm(ctx);
34+
35+
pcm_info->name = strdup(pcm->pcm_name);
36+
if (!pcm_info->name) {
37+
free(pcm_info);
38+
return -ENOMEM;
39+
}
40+
41+
pcm_info->id = pcm->pcm_id;
42+
43+
/* look up from the widget list and populate the PCM info */
44+
list_for_item(item, widget_list) {
45+
struct tplg_comp_info *comp_info = container_of(item, struct tplg_comp_info, item);
46+
47+
if (!strcmp(pcm->caps[0].name, comp_info->stream_name) &&
48+
(comp_info->type == SND_SOC_TPLG_DAPM_AIF_IN ||
49+
comp_info->type == SND_SOC_TPLG_DAPM_AIF_OUT)) {
50+
pcm_info->playback_host = comp_info;
51+
fprintf(stdout, "PCM: '%s' ID: %d Host name: %s\n", pcm_info->name,
52+
pcm_info->id, comp_info->name);
53+
}
54+
if (!strcmp(pcm->caps[1].name, comp_info->stream_name) &&
55+
(comp_info->type == SND_SOC_TPLG_DAPM_AIF_IN ||
56+
comp_info->type == SND_SOC_TPLG_DAPM_AIF_OUT)) {
57+
pcm_info->capture_host = comp_info;
58+
fprintf(stdout, "PCM: '%s' ID: %d Host name: %s\n", pcm_info->name,
59+
pcm_info->id, comp_info->name);
60+
}
61+
}
62+
63+
list_item_append(&pcm_info->item, pcm_list);
64+
65+
return 0;
66+
}

0 commit comments

Comments
 (0)