source: mainline/uspace/lib/drv/generic/remote_audio_mixer.c@ 1912b45

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1912b45 was 1912b45, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

Make pcm control iface generic

  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[53a7fda]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
29/** @addtogroup libdrv
30 * @{
31 */
32/** @file
33 */
34
35#include <async.h>
36#include <errno.h>
37#include <assert.h>
38#include <str.h>
39
40#include "audio_mixer_iface.h"
41#include "ddf/driver.h"
42
43typedef enum {
44 /** Asks for basic mixer info: Mixer name and number of controllable
45 * items.
46 * Answer:
47 * - ENOTSUP - call not supported
48 * - EOK - call successful, info is valid
49 * Answer arguments:
50 * - Mixer name
51 * - Number of controllable items
52 */
53 IPC_M_AUDIO_MIXER_GET_INFO,
54
55 /** Asks for item mixer info: Item name and number of controllable
56 * channels.
57 * Answer:
58 * - ENOTSUP - call not supported
59 * - ENOENT - no such item
60 * - EOK - call successful, info is valid
61 * Answer arguments:
62 * - Item name
63 * - Number of controllable channels
64 */
65 IPC_M_AUDIO_MIXER_GET_ITEM_INFO,
66
[1912b45]67 /** Set new control item setting
[53a7fda]68 * Answer:
69 * - ENOTSUP - call not supported
[1912b45]70 * - ENOENT - no such control item
[53a7fda]71 * - EOK - call successful, info is valid
72 */
[1912b45]73 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL,
[53a7fda]74
[1912b45]75 /** Get control item setting
[53a7fda]76 * Answer:
77 * - ENOTSUP - call not supported
[1912b45]78 * - ENOENT - no such control item
[53a7fda]79 * - EOK - call successful, info is valid
80 */
[1912b45]81 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL,
[53a7fda]82} audio_mixer_iface_funcs_t;
83
84/*
85 * CLIENT SIDE
86 */
[8a7d78cc]87
88/**
89 * Query audio mixer for basic info (name and items count).
90 * @param[in] exch IPC exchange connected to the device
91 * @param[out] name Audio mixer string identifier
92 * @param[out] items Number of items controlled by the mixer.
93 * @return Error code.
94 */
[53a7fda]95int audio_mixer_get_info(async_exch_t *exch, const char **name, unsigned *items)
96{
97 if (!exch)
98 return EINVAL;
99 sysarg_t name_size, itemc;
100 const int ret = async_req_1_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
101 IPC_M_AUDIO_MIXER_GET_INFO, &name_size, &itemc);
102 if (ret == EOK && name) {
103 char *name_place = calloc(1, name_size);
104 if (!name_place) {
105 /* Make the other side fail
106 * as it waits for read request */
107 async_data_read_start(exch, (void*)-1, 0);
108 return ENOMEM;
109 }
110 const int ret =
111 async_data_read_start(exch, name_place, name_size);
112 if (ret != EOK) {
113 free(name_place);
114 return ret;
115 }
116 *name = name_place;
117 }
118 if (ret == EOK && items)
119 *items = itemc;
120 return ret;
121}
[4bbfb93]122
[8a7d78cc]123/**
124 * Query audio mixer for item specific info (name and channels count).
125 * @param[in] exch IPC exchange connected to the device
126 * @param[in] item The control item
127 * @param[out] name Control item string identifier.
128 * @param[out] channles Number of channels associated with this control item.
129 * @return Error code.
130 */
[53a7fda]131int audio_mixer_get_item_info(async_exch_t *exch, unsigned item,
[1912b45]132 const char **name, unsigned *levels)
[53a7fda]133{
134 if (!exch)
135 return EINVAL;
[1912b45]136 sysarg_t name_size, lvls;
[53a7fda]137 const int ret = async_req_2_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
[1912b45]138 IPC_M_AUDIO_MIXER_GET_ITEM_INFO, item, &name_size, &lvls);
[53a7fda]139 if (ret == EOK && name) {
140 char *name_place = calloc(1, name_size);
141 if (!name_place) {
142 /* Make the other side fail
143 * as it waits for read request */
144 async_data_read_start(exch, (void*)-1, 0);
145 return ENOMEM;
146 }
147 const int ret =
148 async_data_read_start(exch, name_place, name_size);
149 if (ret != EOK) {
150 free(name_place);
151 return ret;
152 }
153 *name = name_place;
154 }
[1912b45]155 if (ret == EOK && levels)
156 *levels = lvls;
[53a7fda]157 return ret;
158}
[4bbfb93]159
[8a7d78cc]160/**
[1912b45]161 * Set control item to a new level.
[8a7d78cc]162 * @param[in] exch IPC exchange connected to the device.
163 * @param[in] item The control item controlling the channel.
[1912b45]164 * @param[in] level The new value.
[8a7d78cc]165 * @return Error code.
166 */
[1912b45]167int audio_mixer_set_item_level(async_exch_t *exch, unsigned item,
168 unsigned level)
[53a7fda]169{
170 if (!exch)
171 return EINVAL;
[1912b45]172 return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
173 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL, item, level);
[53a7fda]174}
[4bbfb93]175
[8a7d78cc]176/**
[1912b45]177 * Get current level of a control item.
[8a7d78cc]178 * @param[in] exch IPC exchange connected to the device.
179 * @param[in] item The control item controlling the channel.
180 * @param[in] channel The channel index.
[1912b45]181 * @param[out] level Currently set value.
[8a7d78cc]182 * @return Error code.
183 */
[1912b45]184int audio_mixer_get_item_level(async_exch_t *exch, unsigned item,
185 unsigned *level)
[53a7fda]186{
187 if (!exch)
188 return EINVAL;
[1912b45]189 sysarg_t current;
190 const int ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
191 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL, item, &current);
192 if (ret == EOK && level)
193 *level = current;
[53a7fda]194 return ret;
195}
196
197/*
198 * SERVER SIDE
199 */
200static void remote_audio_mixer_get_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
201static void remote_audio_mixer_get_item_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[1912b45]202static void remote_audio_mixer_get_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
203static void remote_audio_mixer_set_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[53a7fda]204
205/** Remote audio mixer interface operations. */
206static remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {
207 [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info,
208 [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info,
[1912b45]209 [IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL] = remote_audio_mixer_get_item_level,
210 [IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL] = remote_audio_mixer_set_item_level,
[53a7fda]211};
212
213/** Remote audio mixer interface structure. */
214remote_iface_t remote_audio_mixer_iface = {
215 .method_count = sizeof(remote_audio_mixer_iface_ops) /
216 sizeof(remote_audio_mixer_iface_ops[0]),
217 .methods = remote_audio_mixer_iface_ops
218};
[4bbfb93]219
[53a7fda]220void remote_audio_mixer_get_info(
221 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
222{
223 audio_mixer_iface_t *mixer_iface = iface;
224
225 if (!mixer_iface->get_info) {
226 async_answer_0(callid, ENOTSUP);
227 return;
228 }
229 const char *name = NULL;
230 unsigned items = 0;
231 const int ret = mixer_iface->get_info(fun, &name, &items);
232 const size_t name_size = name ? str_size(name) + 1 : 0;
233 async_answer_2(callid, ret, name_size, items);
234 /* Send the name. */
235 if (ret == EOK && name_size > 0) {
236 size_t size;
237 ipc_callid_t name_id;
238 if (!async_data_read_receive(&name_id, &size)) {
239 async_answer_0(name_id, EPARTY);
240 return;
241 }
242 if (size != name_size) {
243 async_answer_0(name_id, ELIMIT);
244 return;
245 }
246 async_data_read_finalize(name_id, name, name_size);
247 }
248}
[4bbfb93]249
[53a7fda]250void remote_audio_mixer_get_item_info(
251 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
252{
253 audio_mixer_iface_t *mixer_iface = iface;
254
255 if (!mixer_iface->get_item_info) {
256 async_answer_0(callid, ENOTSUP);
257 return;
258 }
259
260 const unsigned item = DEV_IPC_GET_ARG1(*call);
261 const char *name = NULL;
[1912b45]262 unsigned values = 0;
263 const int ret = mixer_iface->get_item_info(fun, item, &name, &values);
[53a7fda]264 const size_t name_size = name ? str_size(name) + 1 : 0;
[1912b45]265 async_answer_2(callid, ret, name_size, values);
[53a7fda]266 /* Send the name. */
267 if (ret == EOK && name_size > 0) {
268 size_t size;
269 ipc_callid_t name_id;
270 if (!async_data_read_receive(&name_id, &size)) {
271 async_answer_0(name_id, EPARTY);
272 return;
273 }
274 if (size != name_size) {
275 async_answer_0(name_id, ELIMIT);
276 return;
277 }
278 async_data_read_finalize(name_id, name, name_size);
279 }
280}
[4bbfb93]281
[1912b45]282void remote_audio_mixer_set_item_level(
[53a7fda]283 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
284{
285 audio_mixer_iface_t *mixer_iface = iface;
286
[1912b45]287 if (!mixer_iface->set_item_level) {
[53a7fda]288 async_answer_0(callid, ENOTSUP);
289 return;
290 }
291 const unsigned item = DEV_IPC_GET_ARG1(*call);
[1912b45]292 const unsigned value = DEV_IPC_GET_ARG2(*call);
293 const int ret = mixer_iface->set_item_level(fun, item, value);
[53a7fda]294 async_answer_0(callid, ret);
295}
[4bbfb93]296
[1912b45]297void remote_audio_mixer_get_item_level(
[53a7fda]298 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
299{
300 audio_mixer_iface_t *mixer_iface = iface;
301
[1912b45]302 if (!mixer_iface->get_item_level) {
[53a7fda]303 async_answer_0(callid, ENOTSUP);
304 return;
305 }
306 const unsigned item = DEV_IPC_GET_ARG1(*call);
[1912b45]307 unsigned current = 0;
[53a7fda]308 const int ret =
[1912b45]309 mixer_iface->get_item_level(fun, item, &current);
310 async_answer_1(callid, ret, current);
[53a7fda]311}
312
313/**
314 * @}
315 */
Note: See TracBrowser for help on using the repository browser.