forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.c
More file actions
135 lines (116 loc) · 3.36 KB
/
buffer.c
File metadata and controls
135 lines (116 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
/* Topology parser */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <ipc/topology.h>
#include <ipc/stream.h>
#include <sof/common.h>
#include <sof/lib/uuid.h>
#include <sof/ipc/topology.h>
#include <tplg_parser/topology.h>
#include <tplg_parser/tokens.h>
/* Buffers */
static const struct sof_topology_token buffer_tokens[] = {
{SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t,
offsetof(struct sof_ipc_buffer, size), 0},
{SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t,
offsetof(struct sof_ipc_buffer, caps), 0},
};
static const struct sof_topology_token buffer_comp_tokens[] = {
{SOF_TKN_COMP_CORE_ID, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_uint32_t,
offsetof(struct sof_ipc_comp, core), 0},
};
/* load buffer DAPM widget */
int tplg_create_buffer(struct tplg_context *ctx,
struct sof_ipc_buffer *buffer)
{
struct snd_soc_tplg_vendor_array *array;
size_t read_size;
size_t parsed_size = 0;
FILE *file = ctx->file;
int size = ctx->widget->priv.size;
int comp_id = ctx->comp_id;
int ret;
/* configure buffer */
buffer->comp.core = 0;
buffer->comp.id = comp_id;
buffer->comp.pipeline_id = ctx->pipeline_id;
buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
buffer->comp.type = SOF_COMP_BUFFER;
buffer->comp.hdr.size = sizeof(struct sof_ipc_buffer);
/* allocate memory for vendor tuple array */
array = (struct snd_soc_tplg_vendor_array *)malloc(size);
if (!array) {
fprintf(stderr, "error: malloc fail during load_buffer\n");
return -errno;
}
/* read vendor tokens */
while (parsed_size < size) {
read_size = sizeof(struct snd_soc_tplg_vendor_array);
ret = fread(array, read_size, 1, file);
if (ret != 1) {
fprintf(stderr,
"error: fread fail during load_buffer\n");
free(array);
return -EINVAL;
}
/* check for array size mismatch */
if (!is_valid_priv_size(parsed_size, size, array)) {
fprintf(stderr, "error: load buffer array size mismatch\n");
free(array);
return -EINVAL;
}
ret = tplg_read_array(array, file);
if (ret) {
fprintf(stderr, "error: read array fail\n");
free(array);
return ret;
}
/* parse buffer comp tokens */
ret = sof_parse_tokens(&buffer->comp, buffer_comp_tokens,
ARRAY_SIZE(buffer_comp_tokens), array,
array->size);
if (ret) {
fprintf(stderr, "error: parse buffer comp tokens %d\n",
size);
free(array);
return -EINVAL;
}
/* parse buffer tokens */
ret = sof_parse_tokens(buffer, buffer_tokens,
ARRAY_SIZE(buffer_tokens), array,
array->size);
if (ret) {
fprintf(stderr, "error: parse buffer tokens %d\n",
size);
free(array);
return -EINVAL;
}
parsed_size += array->size;
}
free(array);
return 0;
}
/* load pipeline dapm widget */
int tplg_new_buffer(struct tplg_context *ctx, struct sof_ipc_buffer *buffer,
struct snd_soc_tplg_ctl_hdr *rctl)
{
int ret;
ret = tplg_create_buffer(ctx, buffer);
if (ret < 0)
return ret;
if (tplg_create_controls(ctx->widget->num_kcontrols, ctx->file, rctl, 0) < 0) {
fprintf(stderr, "error: loading controls\n");
return -EINVAL;
}
return ret;
}