2 * Copyright (c) 2011 Jan Vesely
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup libdrv
41 #include "audio_mixer_iface.h"
42 #include "ddf/driver.h"
45 /** Asks for basic mixer info: Mixer name and number of controllable
48 * - ENOTSUP - call not supported
49 * - EOK - call successful, info is valid
52 * - Number of controllable items
54 IPC_M_AUDIO_MIXER_GET_INFO
,
56 /** Asks for item mixer info: Item name and number of controllable
59 * - ENOTSUP - call not supported
60 * - ENOENT - no such item
61 * - EOK - call successful, info is valid
64 * - Number of controllable channels
66 IPC_M_AUDIO_MIXER_GET_ITEM_INFO
,
68 /** Set new control item setting
70 * - ENOTSUP - call not supported
71 * - ENOENT - no such control item
72 * - EOK - call successful, info is valid
74 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL
,
76 /** Get control item setting
78 * - ENOTSUP - call not supported
79 * - ENOENT - no such control item
80 * - EOK - call successful, info is valid
82 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL
,
83 } audio_mixer_iface_funcs_t
;
90 * Query audio mixer for basic info (name and items count).
91 * @param[in] exch IPC exchange connected to the device
92 * @param[out] name Audio mixer string identifier
93 * @param[out] items Number of items controlled by the mixer.
96 errno_t
audio_mixer_get_info(async_exch_t
*exch
, char **name
, unsigned *items
)
100 sysarg_t name_size
, itemc
;
101 const errno_t ret
= async_req_1_2(exch
, DEV_IFACE_ID(AUDIO_MIXER_IFACE
),
102 IPC_M_AUDIO_MIXER_GET_INFO
, &name_size
, &itemc
);
103 if (ret
== EOK
&& name
) {
104 char *name_place
= calloc(1, name_size
);
107 * Make the other side fail
108 * as it waits for read request
110 async_data_read_start(exch
, (void *)-1, 0);
114 async_data_read_start(exch
, name_place
, name_size
);
121 if (ret
== EOK
&& items
)
127 * Query audio mixer for item specific info (name and channels count).
128 * @param[in] exch IPC exchange connected to the device
129 * @param[in] item The control item
130 * @param[out] name Control item string identifier.
131 * @param[out] channles Number of channels associated with this control item.
132 * @return Error code.
134 errno_t
audio_mixer_get_item_info(async_exch_t
*exch
, unsigned item
,
135 char **name
, unsigned *levels
)
139 sysarg_t name_size
, lvls
;
140 const errno_t ret
= async_req_2_2(exch
, DEV_IFACE_ID(AUDIO_MIXER_IFACE
),
141 IPC_M_AUDIO_MIXER_GET_ITEM_INFO
, item
, &name_size
, &lvls
);
142 if (ret
== EOK
&& name
) {
143 char *name_place
= calloc(1, name_size
);
146 * Make the other side fail
147 * as it waits for read request
149 async_data_read_start(exch
, (void *)-1, 0);
153 async_data_read_start(exch
, name_place
, name_size
);
160 if (ret
== EOK
&& levels
)
166 * Set control item to a new level.
167 * @param[in] exch IPC exchange connected to the device.
168 * @param[in] item The control item controlling the channel.
169 * @param[in] level The new value.
170 * @return Error code.
172 errno_t
audio_mixer_set_item_level(async_exch_t
*exch
, unsigned item
,
177 return async_req_3_0(exch
, DEV_IFACE_ID(AUDIO_MIXER_IFACE
),
178 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL
, item
, level
);
182 * Get current level of a control item.
183 * @param[in] exch IPC exchange connected to the device.
184 * @param[in] item The control item controlling the channel.
185 * @param[in] channel The channel index.
186 * @param[out] level Currently set value.
187 * @return Error code.
189 errno_t
audio_mixer_get_item_level(async_exch_t
*exch
, unsigned item
,
195 const errno_t ret
= async_req_2_1(exch
, DEV_IFACE_ID(AUDIO_MIXER_IFACE
),
196 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL
, item
, ¤t
);
197 if (ret
== EOK
&& level
)
205 static void remote_audio_mixer_get_info(ddf_fun_t
*, void *, ipc_call_t
*);
206 static void remote_audio_mixer_get_item_info(ddf_fun_t
*, void *, ipc_call_t
*);
207 static void remote_audio_mixer_get_item_level(ddf_fun_t
*, void *, ipc_call_t
*);
208 static void remote_audio_mixer_set_item_level(ddf_fun_t
*, void *, ipc_call_t
*);
210 /** Remote audio mixer interface operations. */
211 static const remote_iface_func_ptr_t remote_audio_mixer_iface_ops
[] = {
212 [IPC_M_AUDIO_MIXER_GET_INFO
] = remote_audio_mixer_get_info
,
213 [IPC_M_AUDIO_MIXER_GET_ITEM_INFO
] = remote_audio_mixer_get_item_info
,
214 [IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL
] = remote_audio_mixer_get_item_level
,
215 [IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL
] = remote_audio_mixer_set_item_level
,
218 /** Remote audio mixer interface structure. */
219 const remote_iface_t remote_audio_mixer_iface
= {
220 .method_count
= ARRAY_SIZE(remote_audio_mixer_iface_ops
),
221 .methods
= remote_audio_mixer_iface_ops
224 void remote_audio_mixer_get_info(ddf_fun_t
*fun
, void *iface
, ipc_call_t
*icall
)
226 audio_mixer_iface_t
*mixer_iface
= iface
;
228 if (!mixer_iface
->get_info
) {
229 async_answer_0(icall
, ENOTSUP
);
233 const char *name
= NULL
;
235 const errno_t ret
= mixer_iface
->get_info(fun
, &name
, &items
);
236 const size_t name_size
= name
? str_size(name
) + 1 : 0;
237 async_answer_2(icall
, ret
, name_size
, items
);
240 if (ret
== EOK
&& name_size
> 0) {
243 if (!async_data_read_receive(&call
, &size
)) {
244 async_answer_0(&call
, EPARTY
);
248 if (size
!= name_size
) {
249 async_answer_0(&call
, ELIMIT
);
253 async_data_read_finalize(&call
, name
, name_size
);
257 void remote_audio_mixer_get_item_info(ddf_fun_t
*fun
, void *iface
,
260 audio_mixer_iface_t
*mixer_iface
= iface
;
262 if (!mixer_iface
->get_item_info
) {
263 async_answer_0(icall
, ENOTSUP
);
267 const unsigned item
= DEV_IPC_GET_ARG1(*icall
);
268 const char *name
= NULL
;
270 const errno_t ret
= mixer_iface
->get_item_info(fun
, item
, &name
, &values
);
271 const size_t name_size
= name
? str_size(name
) + 1 : 0;
272 async_answer_2(icall
, ret
, name_size
, values
);
275 if (ret
== EOK
&& name_size
> 0) {
278 if (!async_data_read_receive(&call
, &size
)) {
279 async_answer_0(&call
, EPARTY
);
283 if (size
!= name_size
) {
284 async_answer_0(&call
, ELIMIT
);
288 async_data_read_finalize(&call
, name
, name_size
);
292 void remote_audio_mixer_set_item_level(ddf_fun_t
*fun
, void *iface
,
295 audio_mixer_iface_t
*mixer_iface
= iface
;
297 if (!mixer_iface
->set_item_level
) {
298 async_answer_0(icall
, ENOTSUP
);
302 const unsigned item
= DEV_IPC_GET_ARG1(*icall
);
303 const unsigned value
= DEV_IPC_GET_ARG2(*icall
);
304 const errno_t ret
= mixer_iface
->set_item_level(fun
, item
, value
);
305 async_answer_0(icall
, ret
);
308 void remote_audio_mixer_get_item_level(ddf_fun_t
*fun
, void *iface
,
311 audio_mixer_iface_t
*mixer_iface
= iface
;
313 if (!mixer_iface
->get_item_level
) {
314 async_answer_0(icall
, ENOTSUP
);
318 const unsigned item
= DEV_IPC_GET_ARG1(*icall
);
319 unsigned current
= 0;
321 mixer_iface
->get_item_level(fun
, item
, ¤t
);
322 async_answer_1(icall
, ret
, current
);